qt/ledset/expertsmartpointsetwin.cpp
2023-06-06 12:13:33 +08:00

902 lines
36 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "expertsmartpointsetwin.h"
#include "gutil/qgui.h"
#include "globalfunc.h"
#include "crc.h"
#include "waitingdlg.h"
#include <QStackedLayout>
#include <QLabel>
#include <QRadioButton>
#include <QPushButton>
#include <QButtonGroup>
#include <QHeaderView>
#include <QMessageBox>
#include <QLineEdit>
#include <QApplication>
#include <QFileDialog>
#include <QJsonArray>
#include <QJsonDocument>
#include <QDialogButtonBox>
struct ModUnitMap {
byte UUID{ie(16)};
byte type{ipp(4)};
byte len{ipp(4)};
byte w{ipp(2)};
byte h{ipp(2)};
byte ex1{ipp(4)};
byte chipType{ipp(2)};
byte decodeMode{ipp(2)};
byte ex3{ipp(4)};
byte smartset{ipp(4)};
byte smartset2{ipp(4)};
byte len{ipp(4)};
byte endFlag{ipp(4)};
byte end{fi};
} modUnitMap;
struct ModMap {
byte start{ie(4)};
byte {ipp(2)};
byte len{ipp(2)};
byte {ipp(2)};
byte {ipp(2)};
byte OE宽度{ipp(2)};
byte {ipp(2)};
byte GLK占空比{fi++};
byte {fi++};
byte {fi++};
byte {fi++};
byte {fi++};
byte {fi++};
byte {fi++};
byte {fi++};
byte {ipp(3)};
byte {ipp()};
byte Unit{ipp(modUnitMap.end)};
byte 2{ipp(4)};
byte check{ipp(4)};
byte end{fi};
} modMap;
ExpertSmartPointSetWin::ExpertSmartPointSetWin(ExpertWin *expertWin) : BaseWin{expertWin}, expertWin(expertWin) {
setWindowModality(Qt::WindowModal);
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(tr("智能走点参数配置"));
resize(900, 600);
ModuleWidth = expertWin->mModule["ModuleWidth"].toInt();
ModuleHeight = expertWin->mModule["ModuleHeight"].toInt();
GroupNum = expertWin->mModule["GroupNum"].toInt();
ScanNum = expertWin->mModule["ScanNum"].toInt();
ChipType = expertWin->mModule["ChipType"].toString();
DecodeMode = expertWin->mModule["DecodeMode"].toString();
GroupMode = expertWin->mModule["GroupMode"].toString();
auto vBox = new VBox(center);
vBox->setContentsMargins(0,0,0,0);
vBox->setSpacing(3);
vBox->addLayout(addBtns(new QHBoxLayout()));
auto stack = new QStackedLayout(vBox);
auto vv = new VBox(stack);
vv->setContentsMargins(50, 50, 6, 6);
auto lb = new QLabel(tr("基本参数"));
gFont(lb, 16);
auto bkBlue = lb->palette();
bkBlue.setColor(QPalette::WindowText, QColor(0x5599ff));
lb->setPalette(bkBlue);
vv->addWidget(lb);
vv->addSpacing(50);
auto grid = new Grid(vv);
grid->setVerticalSpacing(30);
grid->setColumnStretch(0, 1);
grid->setColumnStretch(3, 1);
grid->setColumnStretch(6, 1);
lb = new QLabel(tr("模组宽度: "));
grid->addWidget(lb, 0, 1);
fdModuleWidth = new QSpinBox;
fdModuleWidth->setRange(0, 9999);
fdModuleWidth->setValue(ModuleWidth);
grid->addWidget(fdModuleWidth, 0, 2);
lb = new QLabel(tr("模组高度: "));
grid->addWidget(lb, 1, 1);
fdModuleHeight = new QSpinBox;
fdModuleHeight->setRange(0, 9999);
fdModuleHeight->setValue(ModuleHeight);
grid->addWidget(fdModuleHeight, 1, 2);
lb = new QLabel(tr("数据组数: "));
grid->addWidget(lb, 2, 1);
fdGroupNum = new QSpinBox;
fdGroupNum->setRange(0, 9999);
fdGroupNum->setValue(GroupNum);
grid->addWidget(fdGroupNum, 2, 2);
{
dlgChipType = new QDialog(this);
dlgChipType->setWindowFlag(Qt::WindowMaximizeButtonHint);
dlgChipType->setWindowTitle("选择芯片类型");
dlgChipType->resize(800, 600);
auto vBox = new VBox(dlgChipType);
vBox->setContentsMargins(0,0,0,0);
tableChipType = new Table(24, 10);
tableChipType->setColFit();
tableChipType->setRowFit();
tableChipType->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableChipType->setAlternatingRowColors(true);
tableChipType->setSelectionMode(QAbstractItemView::SingleSelection);
int rr = 0, cc = 0;
tableChipType->setHeaderText(cc, "ICN系列");
tableChipType->setText(rr++, cc, "ICN2026");
tableChipType->setText(rr++, cc, "ICN2027");
tableChipType->setText(rr++, cc, "ICN2028");
tableChipType->setText(rr++, cc, "ICN2037");
tableChipType->setText(rr++, cc, "ICN2038");
tableChipType->setText(rr++, cc, "ICN2038S");
tableChipType->setText(rr++, cc, "ICN2053");
tableChipType->setText(rr++, cc, "ICN2058");
tableChipType->setText(rr++, cc, "ICN2088");
tableChipType->setText(rr++, cc, "ICND2045");
tableChipType->setText(rr++, cc, "ICND2046");
tableChipType->setText(rr++, cc, "ICND2047");
tableChipType->setText(rr++, cc, "ICND2049");
tableChipType->setText(rr++, cc, "ICND2055");
tableChipType->setText(rr++, cc, "ICND2059");
tableChipType->setText(rr++, cc, "ICND2065");
tableChipType->setText(rr++, cc, "ICND2069");
tableChipType->setText(rr++, cc, "ICND2076");
tableChipType->setText(rr++, cc, "ICND2110");
tableChipType->setText(rr++, cc, "ICND2112");
tableChipType->setText(rr++, cc, "ICND2153");
tableChipType->setText(rr++, cc, "ICND2153_three");
tableChipType->setText(rr++, cc, "ICND2163");
tableChipType->setText(rr++, cc, "ICND2200");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "SM系列");
tableChipType->setText(rr++, cc, "SM16017_NEW");
tableChipType->setText(rr++, cc, "SM16017S");
tableChipType->setText(rr++, cc, "SM16159S");
tableChipType->setText(rr++, cc, "SM16169S");
tableChipType->setText(rr++, cc, "SM16207S");
tableChipType->setText(rr++, cc, "SM16218");
tableChipType->setText(rr++, cc, "SM16227S");
tableChipType->setText(rr++, cc, "SM16237DS");
tableChipType->setText(rr++, cc, "SM16237S");
tableChipType->setText(rr++, cc, "SM16259S");
tableChipType->setText(rr++, cc, "SM16259S");
tableChipType->setText(rr++, cc, "SM16369");
tableChipType->setText(rr++, cc, "SM16380");
tableChipType->setText(rr++, cc, "SM16388");
tableChipType->setText(rr++, cc, "SM16389");
tableChipType->setText(rr++, cc, "SM16509/16399");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "LS系列");
tableChipType->setText(rr++, cc, "LS9918S");
tableChipType->setText(rr++, cc, "LS9919S");
tableChipType->setText(rr++, cc, "LS9926S");
tableChipType->setText(rr++, cc, "LS9929C");
tableChipType->setText(rr++, cc, "LS9929S");
tableChipType->setText(rr++, cc, "LS9930S");
tableChipType->setText(rr++, cc, "LS9931S");
tableChipType->setText(rr++, cc, "LS9935B");
tableChipType->setText(rr++, cc, "LS9935S");
tableChipType->setText(rr++, cc, "LS9936S");
tableChipType->setText(rr++, cc, "LS9961S");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "MBI系列");
tableChipType->setText(rr++, cc, "MBI5041/5042");
tableChipType->setText(rr++, cc, "MBI5051");
tableChipType->setText(rr++, cc, "MBI5124");
tableChipType->setText(rr++, cc, "MBI5151");
tableChipType->setText(rr++, cc, "MBI5153");
tableChipType->setText(rr++, cc, "MBI5155");
tableChipType->setText(rr++, cc, "MBI5158");
tableChipType->setText(rr++, cc, "MBI5252");
tableChipType->setText(rr++, cc, "MBI5253");
tableChipType->setText(rr++, cc, "MBI5253B");
tableChipType->setText(rr++, cc, "MBI5254");
tableChipType->setText(rr++, cc, "MBI5264");
tableChipType->setText(rr++, cc, "MBI5268");
tableChipType->setText(rr++, cc, "MBI5353");
tableChipType->setText(rr++, cc, "MBI5353B");
tableChipType->setText(rr++, cc, "MBI6322");
tableChipType->setText(rr++, cc, "MBI6328");
tableChipType->setText(rr++, cc, "MBI6334");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "SUM系列");
tableChipType->setText(rr++, cc, "SUM2017");
tableChipType->setText(rr++, cc, "SUM2017T");
tableChipType->setText(rr++, cc, "SUM2017TD");
tableChipType->setText(rr++, cc, "SUM2028");
tableChipType->setText(rr++, cc, "SUM2030");
tableChipType->setText(rr++, cc, "SUM2030T");
tableChipType->setText(rr++, cc, "SUM2032");
tableChipType->setText(rr++, cc, "SUM2033");
tableChipType->setText(rr++, cc, "SUM2035");
tableChipType->setText(rr++, cc, "SUM2036");
tableChipType->setText(rr++, cc, "SUM2037");
tableChipType->setText(rr++, cc, "SUM2117");
tableChipType->setText(rr++, cc, "SUM2130");
tableChipType->setText(rr++, cc, "SUM2131");
tableChipType->setText(rr++, cc, "SUM2135");
tableChipType->setText(rr++, cc, "SUM6086");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "FM系列");
tableChipType->setText(rr++, cc, "FM6128");
tableChipType->setText(rr++, cc, "FM6129");
tableChipType->setText(rr++, cc, "FM6153");
tableChipType->setText(rr++, cc, "FM6182");
tableChipType->setText(rr++, cc, "FM6253");
tableChipType->setText(rr++, cc, "FM6353");
tableChipType->setText(rr++, cc, "FM6356");
tableChipType->setText(rr++, cc, "FM6363");
tableChipType->setText(rr++, cc, "FM6555");
tableChipType->setText(rr++, cc, "FM6565/6569");
tableChipType->setText(rr++, cc, "FM6565CE");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "DP系列");
tableChipType->setText(rr++, cc, "DP5135");
tableChipType->setText(rr++, cc, "DP5220X");
tableChipType->setText(rr++, cc, "DP5525");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "MY系列");
tableChipType->setText(rr++, cc, "MY9758");
tableChipType->setText(rr++, cc, "MY9862");
tableChipType->setText(rr++, cc, "MY9866");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "LYD系列");
tableChipType->setText(rr++, cc, "LYD6168B");
tableChipType->setText(rr++, cc, "LYD6168C");
tableChipType->setText(rr++, cc, "LYD6168D");
tableChipType->setText(rr++, cc, "LYD6168E");
tableChipType->setText(rr++, cc, "LYD6188");
tableChipType->setText(rr++, cc, "LYD6188PC");
rr = 0; cc++;
tableChipType->setHeaderText(cc, "其他系列");
tableChipType->setText(rr++, cc, "通用");
tableChipType->setText(rr++, cc, "A5065");
tableChipType->setText(rr++, cc, "AXS6018");
tableChipType->setText(rr++, cc, "CFD135A");
tableChipType->setText(rr++, cc, "CFD455A");
tableChipType->setText(rr++, cc, "CNS7153");
tableChipType->setText(rr++, cc, "CNS7253");
tableChipType->setText(rr++, cc, "CNS7263");
tableChipType->setText(rr++, cc, "CS2017");
tableChipType->setText(rr++, cc, "CS2033");
tableChipType->setText(rr++, cc, "D26188");
tableChipType->setText(rr++, cc, "HX8055");
tableChipType->setText(rr++, cc, "HX8864");
tableChipType->setText(rr++, cc, "HX8896");
tableChipType->setText(rr++, cc, "RT5965");
tableChipType->setText(rr++, cc, "RT5967");
tableChipType->setText(rr++, cc, "SCL8081A");
tableChipType->setText(rr++, cc, "XM11202G");
connect(tableChipType, &Table::cellDoubleClicked, dlgChipType, [=](int row, int column) {
auto text = tableChipType->text(row, column);
if(text.isEmpty()) return;
fdChipType->setText(text);
ChipTypeCode = (column<<8) | row;
dlgChipType->accept();
});
vBox->addWidget(tableChipType);
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
connect(btnBox, &QDialogButtonBox::rejected, dlgChipType, &QDialog::reject);
connect(btnBox, &QDialogButtonBox::accepted, dlgChipType, [=] {
auto items = tableChipType->selectedItems();
if(items.isEmpty()) {
QMessageBox::warning(dlgChipType, "Warning", "请选择芯片类型");
return;
}
fdChipType->setText(items[0]->text());
auto ranges = tableChipType->selectedRanges();
ChipTypeCode = (ranges[0].leftColumn()<<8) | ranges[0].topRow();
dlgChipType->accept();
});
vBox->addWidget(btnBox);
}
{
dlgDecodeMode = new QDialog(this);
dlgDecodeMode->setWindowFlag(Qt::WindowMaximizeButtonHint);
dlgDecodeMode->setWindowTitle("选择译码方式");
dlgDecodeMode->resize(600, 400);
auto vBox = new VBox(dlgDecodeMode);
vBox->setContentsMargins(0,0,0,0);
tableDecodeMode = new Table(9, 7);
tableDecodeMode->setColFit();
tableDecodeMode->setRowFit();
tableDecodeMode->setEditTriggers(QAbstractItemView::NoEditTriggers);
tableDecodeMode->setAlternatingRowColors(true);
tableDecodeMode->setSelectionMode(QAbstractItemView::SingleSelection);
int rr = 0, cc = 0;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "138译码");
tableDecodeMode->setText(rr++, cc, "ICN2012");
tableDecodeMode->setText(rr++, cc, "MW4958");
tableDecodeMode->setText(rr++, cc, "SM5166P");
tableDecodeMode->setText(rr++, cc, "TC7260");
tableDecodeMode->setText(rr++, cc, "TC7258E");
tableDecodeMode->setText(rr++, cc, "TC7258EN");
tableDecodeMode->setText(rr++, cc, "HX6012");
tableDecodeMode->setText(rr++, cc, "ICN2016");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "595译码");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "5958译码");
tableDecodeMode->setText(rr++, cc, "5960译码");
tableDecodeMode->setText(rr++, cc, "TC7558");
tableDecodeMode->setText(rr++, cc, "RT5957");
tableDecodeMode->setText(rr++, cc, "HX6058");
tableDecodeMode->setText(rr++, cc, "HX6158H");
tableDecodeMode->setText(rr++, cc, "MBI5988");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "直接输出 (低)");
tableDecodeMode->setText(rr++, cc, "直接输出 (高)");
tableDecodeMode->setText(rr++, cc, "静态无译码");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "ICND2018");
tableDecodeMode->setText(rr++, cc, "ICND3018");
tableDecodeMode->setText(rr++, cc, "ICND2019");
tableDecodeMode->setText(rr++, cc, "TC7559");
tableDecodeMode->setText(rr++, cc, "TC7519");
tableDecodeMode->setText(rr++, cc, "SM5366");
tableDecodeMode->setText(rr++, cc, "DP32020");
tableDecodeMode->setText(rr++, cc, "DP7298A");
tableDecodeMode->setText(rr++, cc, "SM5368");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "ICND2013");
tableDecodeMode->setText(rr++, cc, "TC7262");
tableDecodeMode->setText(rr++, cc, "ICND2017");
tableDecodeMode->setText(rr++, cc, "DP7268E");
tableDecodeMode->setText(rr++, cc, "DP32019");
tableDecodeMode->setText(rr++, cc, "HX6013");
rr = 0; cc++;
tableDecodeMode->setHeaderText(cc, "系列"+QString::number(cc+1));
tableDecodeMode->setText(rr++, cc, "SM5266P");
tableDecodeMode->setText(rr++, cc, "FM7239");
tableDecodeMode->setText(rr++, cc, "LS9736");
tableDecodeMode->setText(rr++, cc, "D7266");
tableDecodeMode->setText(rr++, cc, "CFD21338SPC");
tableDecodeMode->setText(rr++, cc, "LS9737_1");
connect(tableDecodeMode, &Table::cellDoubleClicked, dlgDecodeMode, [=](int row, int column) {
auto text = tableDecodeMode->text(row, column);
if(text.isEmpty()) return;
fdDecodeMode->setText(text);
DecodeModeCode = (column<<8) | row;
dlgDecodeMode->accept();
});
vBox->addWidget(tableDecodeMode);
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close);
connect(btnBox, &QDialogButtonBox::rejected, dlgDecodeMode, &QDialog::reject);
connect(btnBox, &QDialogButtonBox::accepted, dlgDecodeMode, [=] {
auto items = tableDecodeMode->selectedItems();
if(items.isEmpty()) {
QMessageBox::warning(dlgDecodeMode, "Warning", "请选择译码方式");
return;
}
fdDecodeMode->setText(items[0]->text());
auto ranges = tableDecodeMode->selectedRanges();
DecodeModeCode = (ranges[0].leftColumn()<<8) | ranges[0].topRow();
dlgDecodeMode->accept();
});
vBox->addWidget(btnBox);
}
lb = new QLabel(tr("驱动芯片: "));
grid->addWidget(lb, 0, 4);
auto hhhh = new HBox;
hhhh->setSpacing(0);
fdChipType = new QLineEdit("ICND2153");
fdChipType->setMinimumWidth(150);
fdChipType->setReadOnly(true);
hhhh->addWidget(fdChipType);
auto def = fdChipType->text();
QTableWidgetItem *item;
if(! def.isEmpty()) for(int r=0; r<tableChipType->rowCount(); r++) for(int c=0; c<tableChipType->columnCount(); c++) if((item = tableChipType->item(r, c)) && item->text()==def) item->setSelected(true);
auto btn = new QPushButton("...");
btn->setMaximumWidth(30);
connect(btn, &QPushButton::clicked, dlgChipType, &QDialog::exec);
hhhh->addWidget(btn);
grid->addLayout(hhhh, 0, 5);
lb = new QLabel(tr("译码方式: "));
grid->addWidget(lb, 1, 4);
hhhh = new HBox;
hhhh->setSpacing(0);
fdDecodeMode = new QLineEdit(tr("138译码"));
fdDecodeMode->setReadOnly(true);
hhhh->addWidget(fdDecodeMode);
def = fdDecodeMode->text();
if(! def.isEmpty()) for(int r=0; r<tableDecodeMode->rowCount(); r++) for(int c=0; c<tableDecodeMode->columnCount(); c++) if((item = tableDecodeMode->item(r, c)) && item->text()==def) item->setSelected(true);
btn = new QPushButton("...");
btn->setMaximumWidth(30);
connect(btn, &QPushButton::clicked, dlgDecodeMode, &QDialog::exec);
hhhh->addWidget(btn);
grid->addLayout(hhhh, 1, 5);
lb = new QLabel(tr("分组方式: "));
grid->addWidget(lb, 2, 4);
fdGroupMode = new QComboBox;
fdGroupMode->addItem(tr("三线并行"));
fdGroupMode->addItem(tr("三色1点串"));
fdGroupMode->addItem(tr("三色8点串"));
fdGroupMode->addItem(tr("三色16点串"));
grid->addWidget(fdGroupMode, 2, 5);
vv->addStretch();
{
auto vBox = new VBox(stack);
vBox->setContentsMargins(50, 50, 6, 6);
auto lb = new QLabel(tr("扫描行数"));
gFont(lb, 16);
lb->setPalette(bkBlue);
vBox->addWidget(lb);
vBox->addSpacing(50);
auto hBox = new QHBoxLayout;
vBox->addLayout(hBox);
hBox->addStretch();
auto vvv = new QVBoxLayout;
hBox->addLayout(vvv);
lb = new QLabel(tr("根据亮线的行/列数确定扫描行/列数: "));
vvv->addWidget(lb);
vvv->addSpacing(30);
auto hhhh = new QHBoxLayout;
hhhh->addStretch();
auto fdRow = new QRadioButton(tr(""));
hhhh->addWidget(fdRow);
hhhh->addStretch();
auto fdCol = new QRadioButton(tr(""));
hhhh->addWidget(fdCol);
hhhh->addStretch();
vvv->addLayout(hhhh);
vvv->addSpacing(20);
hhhh = new QHBoxLayout;
hhhh->addStretch();
lb = new QLabel(tr("亮线的行/列数: "));
hhhh->addWidget(lb);
auto fdNum = new QSpinBox;
fdNum->setRange(0, 9999);
fdNum->setValue(1);
hhhh->addWidget(fdNum);
hhhh->addStretch();
vvv->addLayout(hhhh);
vvv->addStretch();
hBox->addStretch();
vvv = new QVBoxLayout;
hBox->addLayout(vvv);
lb = new QLabel(tr("芯片245版本: "));
vvv->addWidget(lb);
vvv->addSpacing(30);
hhhh = new QHBoxLayout;
hhhh->addStretch();
auto fdA = new QRadioButton("A");
hhhh->addWidget(fdA);
hhhh->addStretch();
auto fdD = new QRadioButton("D");
hhhh->addWidget(fdD);
hhhh->addStretch();
vvv->addLayout(hhhh);
vvv->addStretch();
hBox->addStretch();
}
{
auto vBox = new VBox(stack);
vBox->setContentsMargins(50, 50, 6, 6);
auto lb = new QLabel(tr("数据线颜色"));
gFont(lb, 16);
lb->setPalette(bkBlue);
vBox->addWidget(lb);
vBox->addSpacing(50);
lb = new QLabel(tr("依次点击以下状态, 根据模组颜色选择对应颜色"));
vBox->addWidget(lb, 0, Qt::AlignCenter);
vBox->addSpacing(30);
auto hhhh = new QHBoxLayout;
hhhh->addStretch();
auto fdSta1 = new QRadioButton(tr("状态1"));
fdSta1->setChecked(true);
hhhh->addWidget(fdSta1);
hhhh->addStretch();
auto fdR1 = new QRadioButton(tr(""));
fdR1->setChecked(true);
hhhh->addWidget(fdR1);
hhhh->addSpacing(20);
auto fdG1 = new QRadioButton(tr("绿"));
hhhh->addWidget(fdG1);
hhhh->addSpacing(20);
auto fdB1 = new QRadioButton(tr(""));
hhhh->addWidget(fdB1);
hhhh->addSpacing(20);
auto fdNo1 = new QRadioButton(tr(""));
hhhh->addWidget(fdNo1);
hhhh->addStretch();
vBox->addLayout(hhhh);
vBox->addSpacing(20);
hhhh = new QHBoxLayout;
hhhh->addStretch();
auto fdSta2 = new QRadioButton(tr("状态2"));
hhhh->addWidget(fdSta2);
hhhh->addStretch();
auto fdR2 = new QRadioButton(tr(""));
hhhh->addWidget(fdR2);
hhhh->addSpacing(20);
auto fdG2 = new QRadioButton(tr("绿"));
fdG2->setChecked(true);
hhhh->addWidget(fdG2);
hhhh->addSpacing(20);
auto fdB2 = new QRadioButton(tr(""));
hhhh->addWidget(fdB2);
hhhh->addSpacing(20);
auto fdNo2 = new QRadioButton(tr(""));
hhhh->addWidget(fdNo2);
hhhh->addStretch();
vBox->addLayout(hhhh);
vBox->addSpacing(20);
hhhh = new QHBoxLayout;
hhhh->addStretch();
auto fdSta3 = new QRadioButton(tr("状态3"));
hhhh->addWidget(fdSta3);
hhhh->addStretch();
auto fdR3 = new QRadioButton(tr(""));
hhhh->addWidget(fdR3);
hhhh->addSpacing(20);
auto fdG3 = new QRadioButton(tr("绿"));
hhhh->addWidget(fdG3);
hhhh->addSpacing(20);
auto fdB3 = new QRadioButton(tr(""));
fdB3->setChecked(true);
hhhh->addWidget(fdB3);
hhhh->addSpacing(20);
auto fdNo3 = new QRadioButton(tr(""));
hhhh->addWidget(fdNo3);
hhhh->addStretch();
vBox->addLayout(hhhh);
vBox->addStretch();
auto btnGrp = new QButtonGroup(fdNo1);
btnGrp->addButton(fdR1);
btnGrp->addButton(fdG1);
btnGrp->addButton(fdB1);
btnGrp->addButton(fdNo1);
btnGrp = new QButtonGroup(fdNo2);
btnGrp->addButton(fdR2);
btnGrp->addButton(fdG2);
btnGrp->addButton(fdB2);
btnGrp->addButton(fdNo2);
btnGrp = new QButtonGroup(fdNo3);
btnGrp->addButton(fdR3);
btnGrp->addButton(fdG3);
btnGrp->addButton(fdB3);
btnGrp->addButton(fdNo3);
}
{
auto vBox = new VBox(stack);
vBox->setContentsMargins(0,0,0,0);
auto hhh = new QHBoxLayout;
auto btnUndo = new QPushButton("回撤");
btnUndo->setMinimumSize(90, 30);
connect(btnUndo, &QPushButton::clicked, this, [this] {
auto lastIdx = tableRow->columnCount()-1;
if(lastIdx==-1) return;
auto last = tableRow->item(1, lastIdx);
if(last->text()=="×") virtualCnt--;
else {
auto point = last->data(Qt::UserRole).toPoint();
table->setText(point.y(), point.x(), "");
if(lastIdx==virtualCnt) table->selectionModel()->clearCurrentIndex();
else {
for(int i=lastIdx-1; i>-1; i--) {
if(tableRow->text(1, i)=="×") continue;
auto point = tableRow->data(1, i).toPoint();
table->setCurrentCell(point.y(), point.x());
break;
}
}
}
tableRow->setColumnCount(lastIdx);
});
hhh->addWidget(btnUndo);
auto btnAddVoid = new QPushButton(tr("插入虚点"));
btnAddVoid->setMinimumSize(90, 30);
connect(btnAddVoid, &QPushButton::clicked, this, [this] {
virtualCnt++;
auto cnt = tableRow->columnCount();
tableRow->setColumnCount(cnt+1);
tableRow->setText(0, cnt, QString::number(cnt+1))->setTextAlignment(Qt::AlignCenter);
tableRow->setText(1, cnt, "×")->setTextAlignment(Qt::AlignCenter);
});
hhh->addWidget(btnAddVoid);
auto btnReset = new QPushButton(tr("重新走点"));
btnReset->setMinimumSize(90, 30);
connect(btnReset, &QPushButton::clicked, this, [this] {
table->clearContents();
tableRow->setColumnCount(0);
virtualCnt = 0;
});
hhh->addWidget(btnReset);
auto btnOK = new QPushButton(tr("完成"));
btnOK->setMinimumSize(90, 30);
connect(btnOK, &QPushButton::clicked, this, &ExpertSmartPointSetWin::save);
hhh->addWidget(btnOK);
hhh->addStretch();
vBox->addLayout(hhh);
table = new Table;
table->setNoEdit();
table->setSelectionMode(QTableWidget::SingleSelection);
table->setColWidth(40);
table->horizontalHeader()->setDefaultAlignment(Qt::AlignCenter);
table->verticalHeader()->setMinimumWidth(40);
table->verticalHeader()->setDefaultAlignment(Qt::AlignCenter);
connect(table, &QTableWidget::currentCellChanged, this, [=](int row, int col) {
if(row < 0) return;
auto text = table->text(row, col);
if(! text.isEmpty()) return;
if(scans.isEmpty()) {
auto cnt = tableRow->columnCount() + 1;
tableRow->setColumnCount(cnt);
tableRow->setText(0, cnt-1, QString::number(cnt))->setTextAlignment(Qt::AlignCenter);
tableRow->setText(1, cnt-1, "")->setTextAlignment(Qt::AlignCenter);
tableRow->setData(1, cnt-1, QPoint{col, row});
auto realCnt = cnt - virtualCnt;
table->setText(row, col, QString::number(realCnt))->setTextAlignment(Qt::AlignCenter);
if(realCnt==ModuleWidth) {
scans.append({col, row});
QMessageBox::information(this, tr("提示"), tr("列走完"));
}
} else if(scans.size() < ScanNum) {
scans.append({col, row});
auto size = scans.size();
table->setText(row, col, "S"+QString::number(size))->setTextAlignment(Qt::AlignCenter);
if(size==ScanNum) {
QMessageBox::information(this, tr("提示"), tr("行走完"));
save();
}
}
});
vBox->addWidget(table);
tableRow = new Table(2, 0);
tableRow->setNoEdit();
tableRow->setSelectionMode(QTableWidget::NoSelection);
tableRow->horizontalHeader()->setDefaultSectionSize(40);
tableRow->horizontalHeader()->setVisible(false);
tableRow->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
tableRow->verticalHeader()->setMinimumWidth(120);
tableRow->setMaximumHeight(80);
auto item = tableRow->verticalHeaderItem(0);
if(item==0) tableRow->setVerticalHeaderItem(0, item = new QTableWidgetItem());
item->setText(tr("第一扫灯数:"));
item = tableRow->verticalHeaderItem(1);
if(item==0) tableRow->setVerticalHeaderItem(1, item = new QTableWidgetItem());
item->setText(tr("实: 虚:"));
vBox->addWidget(tableRow);
}
auto hBox = new HBox(vBox);
hBox->addStretch();
auto btnPrev = new QPushButton(tr("上一步"));
btnPrev->setMinimumSize(90, 30);
hBox->addWidget(btnPrev);
auto btnNext = new QPushButton(tr("下一步"));
btnNext->setMinimumSize(90, 30);
hBox->addWidget(btnNext);
connect(btnPrev, &QPushButton::clicked, this, [stack, btnPrev, btnNext] {
auto idx = stack->currentIndex();
stack->setCurrentIndex(--idx);
btnPrev->setEnabled(idx > 0);
btnNext->setEnabled(idx < stack->count()-1);
});
connect(btnNext, &QPushButton::clicked, this, [=] {
auto idx = stack->currentIndex();
if(idx==0) {
ModuleWidth = fdModuleWidth->value();
ModuleHeight = fdModuleHeight->value();
GroupNum = fdGroupNum->value();
ScanNum = (ModuleHeight + 1) / GroupNum;
ChipType = fdChipType->text();
DecodeMode = fdDecodeMode->text();
GroupMode = fdGroupMode->currentText();
// 开始标识 保留 长度 换行间/刻 OE宽 放电间 芯片通道数 模组类型数
auto msg = QByteArray::fromHex("5555 01 AD 0062 FFFFFFFF 0000ABCD B1000000 0000 415F94A7 AD000000 005C AA55AA55 0000 0036 1770 0000 0280 0000 32 10 00 00 0A 01 00 00 001000 01 "
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 00000000 00000008 00400020 00001400 FF00FF00 3C000000 00000000 1B022020 00000040 55AA55AA 00000000 39F424F6 351B0E53");
// UUID type len w h ex1 chip/decode ex3 smartset smartset2 走点len endFlag
auto unitptr = msg.data()+headMap.end+modMap.Unit;
auto w = (quint16_be*)(unitptr+modUnitMap.w);
qDebug()<<"w"<<QString::number(*w, 16);
*w = ModuleWidth;
auto h = (quint16_be*)(unitptr+modUnitMap.h);
qDebug()<<"h"<<QString::number(*h, 16);
*h = ModuleHeight;
auto groupNum = unitptr+modUnitMap.smartset2 + 1;
qDebug()<<"groupNum"<<QString::number(*groupNum, 16);
*groupNum = GroupNum;
auto chipType = (quint16_be*)(unitptr+modUnitMap.chipType);
qDebug()<<"chipType"<<QString::number(*chipType, 16);
*chipType = ChipTypeCode;
auto decodeMode = (quint16_be*)(unitptr+modUnitMap.decodeMode);
qDebug()<<"decodeMode"<<QString::number(*decodeMode, 16);
*decodeMode = DecodeModeCode;
auto check = (quint32_be*)(msg.data()+headMap.end+modMap.check);
*check = crc32_calc((byte*)msg.data()+headMap.end+modMap., modMap.check - modMap.);
qDebug()<<"check"<<QString::number(*check, 16);
check = (quint32_be*)(msg.data()+headMap.end+modMap.end);
*check = crc32_calc((byte*)msg.data()+headMap.body, modMap.end+6);
qDebug()<<"check"<<QString::number(*check, 16);
auto waitingDlg = new WaitingDlg(this, tr("Setting")+" ...");
auto res = sendMsg(msg, 0x1EA, 10000, [=](int code, const QByteArray data) {
if(code==5) {
waitingDlg->close();
QMessageBox::critical(this, "Error", tr("请求超时"));
return;
}
waitingDlg->close();
auto iii = idx+1;
stack->setCurrentIndex(iii);
btnPrev->setEnabled(iii > 0);
btnNext->setEnabled(iii < stack->count()-1);
}, waitingDlg);
if(res) QMessageBox::critical(this, "Error", QString(tr("发送失败: "))+QString::fromLocal8Bit(pcap_geterr(pcapSend)));
} else if(idx==2) {
table->setColumnCount(ModuleWidth);
table->setRowCount(ModuleHeight);
QColor altColor(0x445566);
for(int r=0; r<ModuleHeight; r++) {
if((r&7)!=7) for(int c=7; c<ModuleWidth; c+=8) table->itemValid(r, c)->setBackground(altColor);
else for(int c=0; c<ModuleWidth; c++) table->itemValid(r, c)->setBackground(altColor);
}
stack->setCurrentIndex(++idx);
btnPrev->setEnabled(idx > 0);
btnNext->setEnabled(idx < stack->count()-1);
}
});
auto btnCcl = new QPushButton("取消");
btnCcl->setMinimumSize(90, 30);
hBox->addWidget(btnCcl);
hBox->addSpacing(30);
}
void ExpertSmartPointSetWin::save() {
auto file = QApplication::applicationDirPath()+"/temp.module";
QFile qFile(file);
if(! qFile.open(QFile::WriteOnly)) {
QMessageBox::critical(this, tr("失败"), QString(tr("准备写入 %1 文件失败")).arg(file));
return;
}
QJsonObject obj;
obj.insert("ModuleWidth", ModuleWidth);
obj.insert("ModuleHeight", ModuleHeight);
obj.insert("GroupNum", GroupNum);
obj.insert("ScanNum", ScanNum);
obj.insert("ChipType", ChipType);
obj.insert("DecodeMode", DecodeMode);
obj.insert("GroupMode", GroupMode);
QJsonArray points;
auto cnt = tableRow->columnCount();
if(cnt > ModuleWidth) {
auto add = (cnt+ModuleWidth-1) / ModuleWidth * ModuleWidth - cnt;
for(int i=0; i<add; i++) points.append(-1);
}
for(int i=cnt-1; i>=0; i--) {
auto data = tableRow->data(1, i);
points.append(data.isValid() ? data.toPoint().x() : -1);
}
obj.insert("Points", points);
QJsonArray Scans;
foreach(QPoint scan, scans) Scans.append(scan.y());
obj.insert("Scans", Scans);
auto data = QJsonDocument(obj).toJson(QJsonDocument::Indented);
auto res = qFile.write(data);
qFile.close();
if(res < 0) {
QMessageBox::critical(this, tr("失败"), QString(tr("写入 %1 文件失败")).arg(file));
return;
}
expertWin->mModule = obj;
expertWin->fdModuleWidth->setText(QString::number(ModuleWidth));
expertWin->fdModuleHeight->setText(QString::number(ModuleHeight));
expertWin->fdGroupNum->setText(QString::number(GroupNum));
expertWin->fdScanNum->setText(QString::number(ScanNum));
expertWin->fdChipType->setText(ChipType);
expertWin->fdDecodeMode->setText(DecodeMode);
expertWin->fdCardWidth->setValue(ModuleWidth);
expertWin->fdCardHeight->setValue(ModuleHeight);
auto appDir = QApplication::applicationDirPath();
QDir(appDir).mkdir("ModuleFiles");
file = QFileDialog::getSaveFileName(this, tr("保存文件"), appDir+QString("/ModuleFiles/%1X%2_%3扫.module").arg(ModuleWidth).arg(ModuleHeight).arg(ScanNum), tr("Module file (*.module)"));
if(file.isEmpty()) return;
QFile qFile2(file);
if(! qFile2.open(QFile::WriteOnly)) {
QMessageBox::critical(this, tr("失败"), QString(tr("准备写入 %1 文件失败")).arg(file));
return;
}
res = qFile2.write(data);
qFile2.close();
if(res < 0) {
QMessageBox::critical(this, tr("失败"), QString(tr("写入 %1 文件失败")).arg(file));
return;
}
QMessageBox::information(this, tr("保存成功"), tr("保存成功"));
close();
}