WaferProgramPage.cpp 30 KB

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