WaferProgramPage.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. #include "WaferProgramPage.h"
  2. std::unordered_map<int, bool> WaferProgramPage::m_IdIsUsedMap;
  3. WaferProgramPage::WaferProgramPage(QWidget* parent)
  4. : QWidget(parent)
  5. {
  6. ui.setupUi(this);
  7. ui.pushButtonSave->setProperty("type", "save");
  8. ui.pushButtonAdd->setProperty("type", "add");
  9. setStyleSheet(
  10. "QWidget { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F1F4FD, stop: 1 #E5E4F6); }"
  11. "QDoubleSpinBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  12. "QSpinBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  13. "QLineEdit { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  14. "QCheckBox::indicator { width: 20px; height: 20px; }"
  15. "QCheckBox::indicator:unchecked { background-color: #FFFFFF; border-radius: 2px; }"
  16. "QComboBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  17. "QComboBox::drop-down { width: 20px; }"
  18. "QPushButton { background: #D0D0E8; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }" // Button background color
  19. "QPushButton:hover { background-color: #B0B0D8; }" // Lighter color on hover
  20. "QPushButton:pressed { background-color: #A0A0C8; }" // Darker color on press
  21. );
  22. m_manageDB = CManageDB::GetInstance();
  23. if (m_manageDB == nullptr) return;
  24. m_pProduct = m_manageDB->GetCProduct();
  25. if (m_pProduct == nullptr) return;
  26. m_pProgramCViewInterface= ns_module::CViewInterface::GetInstance();
  27. connect(ui.pushButtonSave, &QPushButton::clicked, this, [=]() {
  28. m_pProduct->SetAllWaferMatrix(m_vecWaferMatrix);
  29. CProduct* _Product = m_manageDB->GetCProduct();
  30. CWaferMatrix* pMatrix = CResources::GetInstance()->GetWaferMatrix();
  31. pMatrix->LoadMatrix(MATRIX_SEARCH_DIR::DIR_S);
  32. });
  33. connect(ui.pushButtonAdd, &QPushButton::clicked, this, [=]() {
  34. PROGRAM_WAFER_MATRIX_STRUCT newMatrix;
  35. //排序
  36. std::sort(m_vecWaferMatrix.begin(), m_vecWaferMatrix.end(),
  37. [](const PROGRAM_WAFER_MATRIX_STRUCT& a, const PROGRAM_WAFER_MATRIX_STRUCT& b) {
  38. return a.MatrixId < b.MatrixId;
  39. });
  40. int newId = 0;
  41. UINT maxID = 0;
  42. // 查找最大 MatrixId
  43. for (PROGRAM_WAFER_MATRIX_STRUCT& matrix : m_vecWaferMatrix)
  44. {
  45. if (matrix.MatrixId > maxID)
  46. {
  47. maxID = matrix.MatrixId;
  48. }
  49. }
  50. // 生成新的子矩阵 ID,确保唯一性
  51. newId = ++maxID;
  52. newMatrix.MatrixId = newId;
  53. newMatrix.MatrixRow = 1;
  54. newMatrix.MatrixCol = 1;
  55. int newVectorIndex = m_vecWaferMatrix.size();
  56. m_vecWaferMatrix.push_back(newMatrix);
  57. AddMatrixPage(newVectorIndex, newMatrix);
  58. });
  59. initPage();
  60. }
  61. void WaferProgramPage::initPage()
  62. {
  63. m_vecWaferMatrix = m_pProduct->GetWaferMatrix();
  64. for (int i = 0; i < m_vecWaferMatrix.size(); i++)
  65. {
  66. AddMatrixPage(i, m_vecWaferMatrix[i]);
  67. }
  68. }
  69. XY_DOUBLE_STRUCT WaferProgramPage::WaferGetAxisPosition(std::string ModuleType, XY_DOUBLE_STRUCT& pos)
  70. {
  71. /*CAxis* _Axis;
  72. CAxis::AXIS_TYPE eAxisType = _Axis->GetAxisType();*/
  73. if (m_pProgramCViewInterface == nullptr)
  74. {
  75. XY_DOUBLE_STRUCT errorPt = pos; // 可以根据需要返回一个错误状态
  76. // 弹出消息框显示位置
  77. QString positionString = QString("Unable to retrieve axis position for module type: %1").arg(QString::fromStdString(ModuleType));
  78. QMessageBox::information(this, "Axis Position Error", positionString);
  79. return errorPt;
  80. }
  81. m_pProgramCViewInterface->GetViewMotion()->GetAxisPosition(ModuleType, "X", pos.x);
  82. m_pProgramCViewInterface->GetViewMotion()->GetAxisPosition(ModuleType, "Y", pos.y);
  83. return pos;
  84. }
  85. XY_DOUBLE_STRUCT WaferProgramPage::WaferMoveToXYAxisPosition(std::string ModuleType, XY_DOUBLE_STRUCT& pos)
  86. {
  87. if (m_pProgramCViewInterface == nullptr)
  88. {
  89. XY_DOUBLE_STRUCT errorPt = pos; // 可以根据需要返回一个错误状态
  90. // 弹出消息框显示位置
  91. QString positionString = QString("Unable to retrieve axis position for module type: %1").arg(QString::fromStdString(ModuleType));
  92. QMessageBox::information(this, "Axis Position Error", positionString);
  93. return errorPt;
  94. }
  95. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "X", pos.x);
  96. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "Y", pos.y);
  97. return pos;
  98. }
  99. void WaferProgramPage::AddMatrixPage(int vectorIndex, _PROGRAM_WAFER_MATRIX_STRUCT matrixData) {
  100. int matrixNum = m_vecWaferMatrix.size();
  101. int newMatrixID = ++matrixNum;
  102. QVector<QObject*> vecControls;
  103. QGroupBox* groupBox = new QGroupBox();
  104. QGridLayout* outMatrixGridLayout = new QGridLayout();
  105. outMatrixGridLayout->setSpacing(6);
  106. outMatrixGridLayout->setObjectName(QString::fromUtf8("subGridLayout"));
  107. groupBox->setLayout(outMatrixGridLayout);
  108. QGridLayout* subGridLayout = new QGridLayout();
  109. subGridLayout->setSpacing(6);
  110. subGridLayout->setObjectName(QString::fromUtf8("subGridLayout"));
  111. QLabel* labelTitle = new QLabel(this);
  112. labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
  113. labelTitle->setText(tr("Matrix ") + QString::number(vectorIndex));
  114. subGridLayout->addWidget(labelTitle, 0, 0, 1, 1);
  115. vecControls.push_back(labelTitle);
  116. // 删除按钮
  117. QPushButton* pushButtonDelete = new QPushButton(this);
  118. pushButtonDelete->setObjectName(QString::fromUtf8("buttonDelete"));
  119. pushButtonDelete->setText(tr("Delete"));
  120. //pushButtonDelete->setFixedWidth(30);
  121. subGridLayout->addWidget(pushButtonDelete, 0, 3, 1, 2); // 添加到标题右侧的第四列
  122. vecControls.push_back(pushButtonDelete);
  123. // 删除按钮点击事件
  124. connect(pushButtonDelete, &QPushButton::clicked, this, [=]() {
  125. // 删除当前矩阵页面及控件
  126. auto currentIt = m_mapWaferGroupBoxIndex.find(groupBox);
  127. if (currentIt != m_mapWaferGroupBoxIndex.end()) {
  128. int index = currentIt.value();
  129. m_mapWaferGroupBoxIndex.erase(currentIt);
  130. // 更新索引
  131. for (auto it = m_mapWaferGroupBoxIndex.begin(); it != m_mapWaferGroupBoxIndex.end(); it++) {
  132. if (it.value() > index) {
  133. int newIndex = it.value() - 1;
  134. m_mapWaferGroupBoxIndex.insert(it.key(), newIndex);
  135. }
  136. }
  137. // 删除矩阵数据
  138. m_vecWaferMatrix.erase(m_vecWaferMatrix.begin() + index);
  139. // 删除矩阵控件
  140. delete groupBox;
  141. }
  142. });
  143. QLabel* labelRow = new QLabel(this);
  144. labelRow->setObjectName(QString::fromUtf8("labelRow"));
  145. labelRow->setText(tr("Row & Cow "));
  146. subGridLayout->addWidget(labelRow, 1, 0, 1, 1);
  147. vecControls.push_back(labelRow);
  148. SpinBox* spinBoxRow = new SpinBox(this);
  149. spinBoxRow->setObjectName(QString::fromUtf8("spinBoxRow"));
  150. spinBoxRow->setValue(matrixData.MatrixRow);
  151. subGridLayout->addWidget(spinBoxRow, 1, 1, 1, 1);
  152. vecControls.push_back(spinBoxRow);
  153. /*QLabel* labelCol = new QLabel(this);
  154. labelCol->setObjectName(QString::fromUtf8("labelCol"));
  155. labelCol->setText(tr("Cow "));
  156. subGridLayout->addWidget(labelCol, 2, 0, 1, 1);
  157. vecControls.push_back(labelCol);*/
  158. SpinBox* spinBoxCol = new SpinBox(this);
  159. spinBoxCol->setObjectName(QString::fromUtf8("spinBoxCol"));
  160. spinBoxCol->setValue(matrixData.MatrixCol);
  161. subGridLayout->addWidget(spinBoxCol, 1, 2, 1, 1);
  162. vecControls.push_back(spinBoxCol);
  163. QLabel* labelLeftTop = new QLabel(this);
  164. labelLeftTop->setObjectName(QString::fromUtf8("labelLeftTop"));
  165. labelLeftTop->setText(tr("Left Top Pos "));
  166. subGridLayout->addWidget(labelLeftTop, 4, 0, 1, 1);
  167. vecControls.push_back(labelLeftTop);
  168. // Set all DoubleSpinBox width to 95
  169. DoubleSpinBox* doubleSpinBoxLeftTopX = new DoubleSpinBox(this);
  170. doubleSpinBoxLeftTopX->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopX"));
  171. doubleSpinBoxLeftTopX->setValue(matrixData.LeftTopPoint.x);
  172. doubleSpinBoxLeftTopX->setFixedWidth(95); // Set fixed width to 95
  173. subGridLayout->addWidget(doubleSpinBoxLeftTopX, 4, 1, 1, 1);
  174. vecControls.push_back(doubleSpinBoxLeftTopX);
  175. DoubleSpinBox* doubleSpinBoxLeftTopY = new DoubleSpinBox(this);
  176. doubleSpinBoxLeftTopY->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopY"));
  177. doubleSpinBoxLeftTopY->setValue(matrixData.LeftTopPoint.y);
  178. doubleSpinBoxLeftTopY->setFixedWidth(95); // Set fixed width to 95
  179. subGridLayout->addWidget(doubleSpinBoxLeftTopY, 4, 2, 1, 1);
  180. vecControls.push_back(doubleSpinBoxLeftTopY);
  181. // Adding button to get LeftTop position
  182. QPushButton* buttonLeftTop = new QPushButton("GP", this);
  183. buttonLeftTop->setFixedWidth(30);
  184. subGridLayout->addWidget(buttonLeftTop, 4, 3, 1, 1); // Position the button next to LeftTopPos
  185. /*connect(buttonLeftTop, &QPushButton::clicked, this, [=]() {
  186. QString position = QString("X: %1, Y: %2").arg(doubleSpinBoxLeftTopX->value()).arg(doubleSpinBoxLeftTopY->value());
  187. QMessageBox::information(this, "Left Top Position", position);
  188. });*/
  189. connect(buttonLeftTop, &QPushButton::clicked, this, [=]() {
  190. // 获取+更新位置
  191. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].LeftTopPoint);
  192. // 更新 DoubleSpinBox 的值
  193. doubleSpinBoxLeftTopX->setValue(position.x); // 更新 X 轴
  194. doubleSpinBoxLeftTopY->setValue(position.y); // 更新 Y 轴
  195. });
  196. QPushButton* buttonMoveToLeftTop = new QPushButton("MT", this);
  197. buttonMoveToLeftTop->setFixedWidth(30);
  198. subGridLayout->addWidget(buttonMoveToLeftTop, 4, 4, 1, 1);
  199. connect(buttonMoveToLeftTop, &QPushButton::clicked, this, [=]() {
  200. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].LeftTopPoint);
  201. });
  202. QLabel* labelRightTopPos = new QLabel(this);
  203. labelRightTopPos->setObjectName(QString::fromUtf8("labelRightTopPos"));
  204. labelRightTopPos->setText(tr("Right Top Pos "));
  205. subGridLayout->addWidget(labelRightTopPos, 5, 0, 1, 1);
  206. vecControls.push_back(labelRightTopPos);
  207. DoubleSpinBox* doubleSpinBoxRightTopX = new DoubleSpinBox(this);
  208. doubleSpinBoxRightTopX->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopX"));
  209. doubleSpinBoxRightTopX->setValue(matrixData.RightTopPoint.x);
  210. doubleSpinBoxRightTopX->setFixedWidth(95); // Set fixed width to 95
  211. subGridLayout->addWidget(doubleSpinBoxRightTopX, 5, 1, 1, 1);
  212. vecControls.push_back(doubleSpinBoxRightTopX);
  213. DoubleSpinBox* doubleSpinBoxRightTopY = new DoubleSpinBox(this);
  214. doubleSpinBoxRightTopY->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopY"));
  215. doubleSpinBoxRightTopY->setValue(matrixData.RightTopPoint.y);
  216. doubleSpinBoxRightTopY->setFixedWidth(95); // Set fixed width to 95
  217. subGridLayout->addWidget(doubleSpinBoxRightTopY, 5, 2, 1, 1);
  218. vecControls.push_back(doubleSpinBoxRightTopY);
  219. // Adding button to get RightTop position
  220. QPushButton* buttonRightTop = new QPushButton("GP", this);
  221. buttonRightTop->setFixedWidth(30);
  222. subGridLayout->addWidget(buttonRightTop, 5, 3, 1, 1); // Position the button next to RightTopPos
  223. connect(buttonRightTop, &QPushButton::clicked, this, [=]() {
  224. // 获取+更新位置
  225. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].RightTopPoint);
  226. // 更新 DoubleSpinBox 的值
  227. doubleSpinBoxRightTopX->setValue(position.x); // 更新 X 轴
  228. doubleSpinBoxRightTopY->setValue(position.y); // 更新 Y 轴
  229. });
  230. QPushButton* buttonMoveToRightTop = new QPushButton("MT", this);
  231. buttonMoveToRightTop->setFixedWidth(30);
  232. subGridLayout->addWidget(buttonMoveToRightTop, 5, 4, 1, 1);
  233. connect(buttonMoveToRightTop, &QPushButton::clicked, this, [=]() {
  234. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].RightTopPoint);
  235. });
  236. QLabel* labelRightButtomPos = new QLabel(this);
  237. labelRightButtomPos->setObjectName(QString::fromUtf8("labelRightButtomPos"));
  238. labelRightButtomPos->setText(tr("Right Buttom pos"));
  239. subGridLayout->addWidget(labelRightButtomPos, 6, 0, 1, 1);
  240. vecControls.push_back(labelRightButtomPos);
  241. DoubleSpinBox* doubleSpinBoxRightButtomX = new DoubleSpinBox(this);
  242. doubleSpinBoxRightButtomX->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomX"));
  243. doubleSpinBoxRightButtomX->setValue(matrixData.RightBottomPoint.x);
  244. doubleSpinBoxRightButtomX->setFixedWidth(95); // Set fixed width to 95
  245. subGridLayout->addWidget(doubleSpinBoxRightButtomX, 6, 1, 1, 1);
  246. vecControls.push_back(doubleSpinBoxRightButtomX);
  247. DoubleSpinBox* doubleSpinBoxRightButtomY = new DoubleSpinBox(this);
  248. doubleSpinBoxRightButtomY->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomY"));
  249. doubleSpinBoxRightButtomY->setValue(matrixData.RightBottomPoint.y);
  250. doubleSpinBoxRightButtomY->setFixedWidth(95); // Set fixed width to 95
  251. subGridLayout->addWidget(doubleSpinBoxRightButtomY, 6, 2, 1, 1);
  252. vecControls.push_back(doubleSpinBoxRightButtomY);
  253. // Adding button to get RightBottom position
  254. QPushButton* buttonRightButtom = new QPushButton("GP", this);
  255. buttonRightButtom->setFixedWidth(30);
  256. subGridLayout->addWidget(buttonRightButtom, 6, 3, 1, 1); // Position the button next to RightBottomPos
  257. connect(buttonRightButtom, &QPushButton::clicked, this, [=]() {
  258. // 获取+更新位置
  259. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].RightBottomPoint);
  260. // 更新 DoubleSpinBox 的值
  261. doubleSpinBoxRightButtomX->setValue(position.x); // 更新 X 轴
  262. doubleSpinBoxRightButtomY->setValue(position.y); // 更新 Y 轴
  263. });
  264. QPushButton* buttonMoveToRightButtom = new QPushButton("MT", this);
  265. buttonMoveToRightButtom->setFixedWidth(30);
  266. subGridLayout->addWidget(buttonMoveToRightButtom, 6, 4, 1, 1);
  267. connect(buttonMoveToRightButtom, &QPushButton::clicked, this, [=]() {
  268. XY_DOUBLE_STRUCT position = WaferGetAxisPosition("WaferTable", m_vecWaferMatrix[vectorIndex].RightBottomPoint);
  269. });
  270. QLabel* labelNoBondPts = new QLabel(this);
  271. labelNoBondPts->setObjectName(QString::fromUtf8("labelNoBondPts"));
  272. labelNoBondPts->setText(tr("No Bond Points"));
  273. subGridLayout->addWidget(labelNoBondPts, 7, 0, 1, 1);
  274. vecControls.push_back(labelNoBondPts);
  275. QLineEdit* lineEditNoBondPts = new QLineEdit(this);
  276. lineEditNoBondPts->setObjectName(QString::fromUtf8("lineEditNoBondPts"));
  277. lineEditNoBondPts->setReadOnly(true);
  278. lineEditNoBondPts->setCursor(Qt::PointingHandCursor);
  279. lineEditNoBondPts->setProperty("vectorIndex", vectorIndex); // Store the index
  280. lineEditNoBondPts->installEventFilter(this);
  281. subGridLayout->addWidget(lineEditNoBondPts, 7, 1, 1, 4);
  282. vecControls.push_back(lineEditNoBondPts);
  283. outMatrixGridLayout->addLayout(subGridLayout, 0, 0);
  284. QFrame* line = new QFrame();
  285. line->setFrameShape(QFrame::NoFrame);
  286. line->setFixedHeight(2);
  287. line->setStyleSheet("background-color: #C7CAEB;");
  288. outMatrixGridLayout->addWidget(line);
  289. QSpacerItem* spacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
  290. // 移除弹簧
  291. for (int i = 0; i < ui.verticalLayout->count(); ++i) {
  292. if (ui.verticalLayout->itemAt(i)->spacerItem()) {
  293. // 找到并移除弹簧
  294. ui.verticalLayout->removeItem(ui.verticalLayout->itemAt(i));
  295. break;
  296. }
  297. }
  298. ui.verticalLayout->addWidget(groupBox);
  299. // 重新添加弹簧到布局的最下方
  300. ui.verticalLayout->addItem(spacer);
  301. m_mapWaferGroupBoxIndex.insert(groupBox, vectorIndex);
  302. // 连接信号和槽
  303. connect(spinBoxRow, &SpinBox::editDone, this, [=]() {
  304. m_vecWaferMatrix[vectorIndex].MatrixRow = spinBoxRow->value();
  305. });
  306. connect(spinBoxCol, &SpinBox::editDone, this, [=]() {
  307. m_vecWaferMatrix[vectorIndex].MatrixCol = spinBoxCol->value();
  308. });
  309. connect(doubleSpinBoxLeftTopX, &DoubleSpinBox::editDone, this, [=]() {
  310. m_vecWaferMatrix[vectorIndex].LeftTopPoint.x = doubleSpinBoxLeftTopX->value();
  311. });
  312. connect(doubleSpinBoxLeftTopY, &DoubleSpinBox::editDone, this, [=]() {
  313. m_vecWaferMatrix[vectorIndex].LeftTopPoint.y = doubleSpinBoxLeftTopY->value();
  314. });
  315. connect(doubleSpinBoxRightTopX, &DoubleSpinBox::editDone, this, [=]() {
  316. m_vecWaferMatrix[vectorIndex].RightTopPoint.x = doubleSpinBoxRightTopX->value();
  317. });
  318. connect(doubleSpinBoxRightTopY, &DoubleSpinBox::editDone, this, [=]() {
  319. m_vecWaferMatrix[vectorIndex].RightTopPoint.y = doubleSpinBoxRightTopY->value();
  320. });
  321. connect(doubleSpinBoxRightButtomX, &DoubleSpinBox::editDone, this, [=]() {
  322. m_vecWaferMatrix[vectorIndex].RightBottomPoint.x = doubleSpinBoxRightButtomX->value();
  323. });
  324. connect(doubleSpinBoxRightButtomY, &DoubleSpinBox::editDone, this, [=]() {
  325. m_vecWaferMatrix[vectorIndex].RightBottomPoint.y = doubleSpinBoxRightButtomY->value();
  326. });
  327. connect(lineEditNoBondPts, &QLineEdit::textChanged, this, [=]() {
  328. // Handle NoBondPts logic here
  329. });
  330. }
  331. bool WaferProgramPage::eventFilter(QObject* obj, QEvent* event) {
  332. if (event->type() == QEvent::MouseButtonPress) {
  333. auto* lineEdit = qobject_cast<QLineEdit*>(obj);
  334. if (lineEdit) {
  335. int index = lineEdit->property("vectorIndex").toInt();
  336. if (lineEdit->property("vectorIndex").isValid()) {
  337. // Handle WaffleMatrix
  338. onNoBondPtsClickedWafer(lineEdit, index);
  339. }
  340. return true; // Intercept the event
  341. }
  342. }
  343. return QWidget::eventFilter(obj, event);
  344. }
  345. void WaferProgramPage::onNoBondPtsClickedWafer(QLineEdit* lineEdit, int index) {
  346. if (index < 0 || index >= m_vecWaferMatrix.size()) return;
  347. const auto& wafer = m_vecWaferMatrix[index];
  348. NoBondPtEditDialog dlg(wafer.MatrixRow, wafer.MatrixCol, wafer.VecNoBondPt, this);
  349. if (dlg.exec() == QDialog::Accepted) {
  350. QVector<XY_LONG_STRUCT> selected = dlg.getSelectedPoints();
  351. m_vecWaferMatrix[index].VecNoBondPt = std::vector<XY_LONG_STRUCT>(selected.begin(), selected.end());
  352. QStringList ptList;
  353. for (const auto& pt : selected)
  354. ptList << QString("(%1,%2)").arg(pt.x).arg(pt.y);
  355. lineEdit->setText(ptList.join(" "));
  356. }
  357. }
  358. //QWidget* WaferProgramPage::CreateWaferProgramPage(const CONFIG_BASE_STRUCT& control) {
  359. // return new WaferProgramPage();
  360. //}
  361. //创建下拉列表
  362. //QComboBox* WaferProgramPage::createDieMatrixIdComboBox(int defaultId, int row) {
  363. // QComboBox* comboBox = new QComboBox(m_MergedTable);
  364. //
  365. // // 设置样式,确保在暗色模式下也是白底黑字
  366. // comboBox->setStyleSheet(R"(
  367. // QComboBox {
  368. // background-color: white;
  369. // color: black;
  370. // border: 1px solid #BABBDC;
  371. // border-radius: 4px;
  372. // padding: 2px 5px;
  373. // }
  374. // QComboBox QAbstractItemView {
  375. // background-color: white;
  376. // color: black;
  377. // selection-background-color: #E5E5FF;
  378. // selection-color: black;
  379. // }
  380. // )");
  381. // for (const auto& dieMatrix : m_vecDieMatrixt) {
  382. // /*comboBox->addItem(
  383. // QString("%1 - %2").arg(dieMatrix.MatrixId).arg(QString::fromStdString(dieMatrix.strModuleName)),
  384. // QVariant(dieMatrix.MatrixId)
  385. // );*/
  386. // comboBox->addItem(QString::number(dieMatrix.MatrixId), QVariant(dieMatrix.MatrixId));
  387. // }
  388. //
  389. // int index = comboBox->findData(defaultId);
  390. // if (index >= 0)
  391. // comboBox->setCurrentIndex(index);
  392. //
  393. // return comboBox;
  394. //}
  395. //
  396. //void WaferProgramPage::initMergedData() {
  397. // m_isInitializing = true;
  398. //
  399. // SqlOperation& sqlOp = SqlOperation::GetInstance();
  400. // QList<QJsonObject> directories;
  401. // int userPrivilege = 0;//?
  402. // sqlOp.GetDirectories("Dir_Programme", userPrivilege, directories); // 使用相应的表名和权限加载目录
  403. // m_vecWaferMatrix = m_pProduct->GetWaferMatrix();
  404. //
  405. // for (const PROGRAM_WAFER_MATRIX_STRUCT& wafer : m_vecWaferMatrix) {
  406. // int row = m_MergedTable->rowCount();
  407. // m_MergedTable->insertRow(row);
  408. // PROGRAM_DIE_MATRIX_STRUCT stDieMatrix;
  409. // m_pProduct->GetDieMatrix(wafer.MatrixId, stDieMatrix);
  410. // m_vecDieMatrixt.push_back(stDieMatrix);
  411. //
  412. // // 填充表格数据
  413. // m_MergedTable->setItem(row, 0, new QTableWidgetItem(QString::number(wafer.MatrixId))); // MatrixID
  414. // m_MergedTable->setItem(row, 1, new QTableWidgetItem(QString::number(wafer.MatrixRow))); // MatrixRow
  415. // m_MergedTable->setItem(row, 2, new QTableWidgetItem(QString::number(wafer.MatrixCol))); // MatrixCol
  416. // m_MergedTable->setItem(row, 3, new QTableWidgetItem(QString::number(wafer.LeftTopPoint.y))); // LeftTopPoint_Y
  417. // m_MergedTable->setItem(row, 4, new QTableWidgetItem(QString::number(wafer.LeftTopPoint.x))); // LeftTopPoint_X
  418. // m_MergedTable->setItem(row, 5, new QTableWidgetItem(QString::number(wafer.RightTopPoint.x))); // RightTopPoint_X
  419. // m_MergedTable->setItem(row, 6, new QTableWidgetItem(QString::number(wafer.RightTopPoint.y))); // RightTopPoint_Y
  420. // m_MergedTable->setItem(row, 7, new QTableWidgetItem(QString::number(wafer.RightBottomPoint.x))); // RightBottomPoint_X
  421. // m_MergedTable->setItem(row, 8, new QTableWidgetItem(QString::number(wafer.RightBottomPoint.y))); // RightBottomPoint_Y
  422. // m_MergedTable->setItem(row, 9, new QTableWidgetItem(QString::number(wafer.iDieMatrixId))); // DieMatrixId
  423. //
  424. // // 填充 NoBondPt 数据
  425. // QStringList noBondPts;
  426. // for (const XY_LONG_STRUCT& pt : wafer.VecNoBondPt) {
  427. // noBondPts.append(QString("(%1,%2)").arg(pt.x).arg(pt.y));
  428. // }
  429. // m_MergedTable->setItem(row, 10, new QTableWidgetItem(noBondPts.join(" "))); // NoBondPt
  430. // }
  431. //
  432. // // 调整列宽和行高
  433. // m_MergedTable->resizeColumnsToContents();
  434. // m_MergedTable->resizeRowsToContents();
  435. //
  436. // m_isInitializing = false;// 开启信号处理
  437. //}
  438. //
  439. //void WaferProgramPage::addRow() {
  440. // m_isInitializing = true;
  441. // m_IdIsUsedMap.clear();
  442. // for (const auto& wafer : m_vecWaferMatrix) {
  443. // m_IdIsUsedMap[wafer.MatrixId] = true;
  444. // }
  445. // int row = m_MergedTable->rowCount();
  446. // m_MergedTable->insertRow(row);
  447. //
  448. // int newId = 1;
  449. // bool idUsed = true;
  450. //
  451. // //// 检查当前 MatrixId 是否已存在
  452. // //while (idUsed) {
  453. // // idUsed = false; // 假设 ID 没有被使用
  454. //
  455. // // // 如果 ID 已存在于 map 中,则说明已被使用
  456. // // if (m_IdIsUsedMap.find(newId) != m_IdIsUsedMap.end()) {
  457. // // idUsed = true;
  458. // // }
  459. //
  460. // // if (idUsed) {
  461. // // ++newId; // 如果 ID 被使用,检查下一个 ID
  462. // // }
  463. // //}
  464. // //找出最大的ID值
  465. // UINT maxId = 0;
  466. // for (PROGRAM_WAFER_MATRIX_STRUCT& bondMatrix : m_vecWaferMatrix)
  467. // {
  468. // if (bondMatrix.MatrixId > maxId)
  469. // {
  470. // maxId = bondMatrix.MatrixId;
  471. // }
  472. // }
  473. // newId = ++maxId;
  474. //
  475. // // 为新行添加默认数据
  476. // m_MergedTable->setItem(row, 0, new QTableWidgetItem(QString::number(newId))); // MatrixID 默认值为 0
  477. // m_MergedTable->setItem(row, 1, new QTableWidgetItem("1")); // MatrixRow 默认值为 1
  478. // m_MergedTable->setItem(row, 2, new QTableWidgetItem("1")); // MatrixCol 默认值为 1
  479. // m_MergedTable->setItem(row, 3, new QTableWidgetItem("0")); // LeftTopPoint_Y 默认值为 0
  480. // m_MergedTable->setItem(row, 4, new QTableWidgetItem("0")); // LeftTopPoint_X 默认值为 0
  481. // m_MergedTable->setItem(row, 5, new QTableWidgetItem("0")); // RightTopPoint_X 默认值为 0
  482. // m_MergedTable->setItem(row, 6, new QTableWidgetItem("0")); // RightTopPoint_Y 默认值为 0
  483. // m_MergedTable->setItem(row, 7, new QTableWidgetItem("0")); // RightBottomPoint_X 默认值为 0
  484. // m_MergedTable->setItem(row, 8, new QTableWidgetItem("0")); // RightBottomPoint_Y 默认值为 0
  485. // m_MergedTable->setItem(row, 9, new QTableWidgetItem("0")); // DieMatrixId 默认值为 0
  486. // /*QComboBox* comboBox = createDieMatrixIdComboBox(0, row);
  487. // m_MergedTable->setCellWidget(row, 9, comboBox);*/
  488. //
  489. // m_MergedTable->setItem(row, 10, new QTableWidgetItem("")); // NoBondPt 默认值为空
  490. //
  491. // // 同时更新 PROGRAM_WAFER_MATRIX_STRUCT 数据
  492. // PROGRAM_WAFER_MATRIX_STRUCT newMatrix;
  493. // newMatrix.MatrixId = newId;
  494. // newMatrix.MatrixRow = 1;
  495. // newMatrix.MatrixCol = 1;
  496. // newMatrix.LeftTopPoint = { 0.0, 0.0 };
  497. // newMatrix.RightTopPoint = { 0.0, 0.0 };
  498. // newMatrix.RightBottomPoint = { 0.0, 0.0 };
  499. // newMatrix.iDieMatrixId = 0;
  500. // newMatrix.VecNoBondPt.clear(); // 默认值为空
  501. //
  502. // m_vecWaferMatrix.push_back(newMatrix);
  503. // // 将新矩阵添加到数据结构中
  504. // //m_pProduct->AddWaferMatrix(newMatrix, newId);
  505. // m_isInitializing = false;
  506. //}
  507. //
  508. //void WaferProgramPage::deleteRow() {
  509. // int currentRow = m_MergedTable->currentRow();
  510. //
  511. // if (currentRow >= 0 && currentRow < m_MergedTable->rowCount()) {
  512. // // 获取 MatrixID(假设第0列是 MatrixID)
  513. // QTableWidgetItem* idItem = m_MergedTable->item(currentRow, 0);
  514. // if (!idItem) return;
  515. //
  516. // int matrixID = idItem->text().toInt();
  517. //
  518. // // 从 m_MergedTable 删除行
  519. // m_MergedTable->removeRow(currentRow);
  520. //
  521. // // 从 m_vecWaferMatrix 中移除对应项
  522. // auto it = std::remove_if(m_vecWaferMatrix.begin(), m_vecWaferMatrix.end(),
  523. // [matrixID](const PROGRAM_WAFER_MATRIX_STRUCT& wafer) {
  524. // return wafer.MatrixId == matrixID;
  525. // });
  526. // if (it != m_vecWaferMatrix.end()) {
  527. // m_vecWaferMatrix.erase(it, m_vecWaferMatrix.end());
  528. // }
  529. //
  530. // // 同时通知数据管理类删除
  531. // //m_pProduct->DeleteWaferMatrix(matrixID);
  532. //
  533. // }
  534. // else {
  535. // //QMessageBox::warning(this, "No Row Selected", "Please select a row to delete.");
  536. // QMessageBox box(QMessageBox::Warning, "No Row Selected", "Please select a row to delete.");
  537. // box.setStyleSheet(R"(
  538. // QMessageBox {
  539. // background-color: #eeeeee;
  540. // color: black;
  541. // }
  542. // QPushButton {
  543. // background-color: #dddddd;
  544. // color: black;
  545. // }
  546. // )");
  547. // box.exec();
  548. // }
  549. // currentRow = -1;
  550. //}
  551. //
  552. //void WaferProgramPage::updateData() {
  553. // // 1. 清空原模型中的矩阵
  554. // auto originalData = m_pProduct->GetWaferMatrix();
  555. // for (const auto& matrix : originalData) {
  556. // m_pProduct->DeleteWaferMatrix(matrix.MatrixId);
  557. // }
  558. //
  559. // // 2. 添加当前表格中的数据
  560. // for (auto& matrix : m_vecWaferMatrix) {
  561. // int newId = matrix.MatrixId;
  562. // m_pProduct->AddWaferMatrix(matrix, newId);
  563. // auto originalData1 = m_pProduct->GetWaferMatrix();
  564. // }
  565. //
  566. // //qDebug() << "WaferMatrix 已同步到模型层,共同步:" << m_vecWaferMatrix.size() << "条记录。";
  567. //}
  568. //void WaferProgramPage::onCellChanged(int row, int column)
  569. //{
  570. // if (m_isInitializing) return; // 防止初始化时触发
  571. // if (row >= m_vecWaferMatrix.size()) return;
  572. //
  573. // QTableWidgetItem* item = m_MergedTable->item(row, column);
  574. // if (!item) return;
  575. //
  576. // QString value = item->text();
  577. // PROGRAM_WAFER_MATRIX_STRUCT& wafer = m_vecWaferMatrix[row];
  578. //
  579. // switch (column) {
  580. // case 0: wafer.MatrixId = value.toInt(); break;
  581. // case 1: wafer.MatrixRow = value.toInt(); break;
  582. // case 2: wafer.MatrixCol = value.toInt(); break;
  583. // case 3: wafer.LeftTopPoint.y = value.toDouble(); break;
  584. // case 4: wafer.LeftTopPoint.x = value.toDouble(); break;
  585. // case 5: wafer.RightTopPoint.x = value.toDouble(); break;
  586. // case 6: wafer.RightTopPoint.y = value.toDouble(); break;
  587. // case 7: wafer.RightBottomPoint.x = value.toDouble(); break;
  588. // case 8: wafer.RightBottomPoint.y = value.toDouble(); break;
  589. // ////case 9: wafer.iDieMatrixId = value.toInt(); break;
  590. //
  591. // case 10: {
  592. // wafer.VecNoBondPt.clear();
  593. // QRegularExpression regex(R"(\((\d+),(\d+)\))");
  594. // QRegularExpressionMatchIterator i = regex.globalMatch(value);
  595. // while (i.hasNext()) {
  596. // auto match = i.next();
  597. // XY_LONG_STRUCT pt;
  598. // pt.x = match.captured(1).toInt();
  599. // pt.y = match.captured(2).toInt();
  600. // wafer.VecNoBondPt.push_back(pt);
  601. // }
  602. // break;
  603. // }
  604. // default: break;
  605. // }
  606. //}