WaffleProgramPage.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  1. #include "WaffleProgramPage.h"
  2. #include <QGroupBox>
  3. #include <QLineEdit>
  4. #include "Src/RewriteControl/Controls/SpinBox.h"
  5. #include "Src/RewriteControl/Controls/DoubleSpinBox.h"
  6. #include <View/die-bonder-ui/Src/MatrixDialogs/NoBondPtEditDialog.h>
  7. #include <QLabel>
  8. #include <QPushButton>
  9. #include <QHBoxLayout>
  10. #include <QVBoxLayout>
  11. #include <algorithm>
  12. WaffleProgramPage::WaffleProgramPage(QWidget* parent)
  13. :QWidget(parent)
  14. {
  15. ui.setupUi(this);
  16. ui.pushButtonSave->setProperty("type", "save");
  17. ui.pushButtonAddOutMatrix->setProperty("type", "addOutMatrix");
  18. setStyleSheet(
  19. "QWidget { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F1F4FD, stop: 1 #E5E4F6); }"
  20. "QDoubleSpinBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  21. "QSpinBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  22. "QLineEdit { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  23. "QCheckBox::indicator { width: 20px; height: 20px; }"
  24. "QCheckBox::indicator:unchecked { background-color: #FFFFFF; border-radius: 2px; }"
  25. "QComboBox { background: #FFFFFF; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }"
  26. "QComboBox::drop-down { width: 20px; }"
  27. "QPushButton { background: #D0D0E8; border: 1px solid #BABBDC; border-radius: 6px; padding: 2px 5px; }" // Button background color
  28. "QPushButton:hover { background-color: #B0B0D8; }" // Lighter color on hover
  29. "QPushButton:pressed { background-color: #A0A0C8; }" // Darker color on press
  30. );
  31. m_manageDB = CManageDB::GetInstance();
  32. if (m_manageDB == nullptr) return;
  33. m_pProduct = m_manageDB->GetCProduct();
  34. if (m_pProduct == nullptr) return;
  35. m_pProgramCViewInterface = ns_module::CViewInterface::GetInstance();
  36. initPage();
  37. connect(ui.pushButtonSave, &QPushButton::clicked, this, [=]() {
  38. m_pProduct->SetAllWaffleMatrix(m_vecWaffleMatrix);
  39. m_pProduct->SetAllWaffleDieMatrix(m_vecSubWaffleMatrix);
  40. CWafflePackMatrix* pMatrix = CResources::GetInstance()->GetWafflePackMatrix();
  41. pMatrix->LoadMatrix(MATRIX_SEARCH_DIR::DIR_S);
  42. CProduct* _Product = m_manageDB->GetCProduct();
  43. });
  44. connect(ui.pushButtonAddOutMatrix, &QPushButton::clicked, this, [=]() {
  45. PROGRAM_WAFFLE_MATRIX_STRUCT newMatrix;
  46. //排序
  47. std::sort(m_vecWaffleMatrix.begin(), m_vecWaffleMatrix.end(),
  48. [](const PROGRAM_WAFFLE_MATRIX_STRUCT& a, const PROGRAM_WAFFLE_MATRIX_STRUCT& b) {
  49. return a.MatrixId < b.MatrixId;
  50. });
  51. int newId = 0;
  52. UINT maxID = 0;
  53. // 查找最大 MatrixId
  54. for (PROGRAM_WAFFLE_MATRIX_STRUCT& waffleMatrix : m_vecWaffleMatrix)
  55. {
  56. if (waffleMatrix.MatrixId > maxID)
  57. {
  58. maxID = waffleMatrix.MatrixId;
  59. }
  60. }
  61. // 生成新的子矩阵 ID,确保唯一性
  62. newId = ++maxID;
  63. while (std::any_of(m_vecWaffleMatrix.begin(), m_vecWaffleMatrix.end(),
  64. [newId](const PROGRAM_WAFFLE_MATRIX_STRUCT& waffleMatrix) {
  65. return waffleMatrix.MatrixId == newId;
  66. }))
  67. {
  68. newId++; // 如果生成的 ID 已经存在,递增直到找到唯一的 ID
  69. }
  70. newMatrix.MatrixId = newId;
  71. /*newMatrix.PackRow = 0;
  72. newMatrix.PackCol = 0;*/
  73. int newVectorIndex = m_vecWaffleMatrix.size();
  74. //std::vector<PROGRAM_DIE_MATRIX_STRUCT> newVecSubMatrix;
  75. m_vecWaffleMatrix.push_back(newMatrix);
  76. AddMatrixPage(newVectorIndex, newMatrix, m_vecSubWaffleMatrix);
  77. });
  78. }
  79. WaffleProgramPage::~WaffleProgramPage()
  80. {
  81. }
  82. XY_DOUBLE_STRUCT WaffleProgramPage::WaffleGetAxisPosition(std::string ModuleType, XY_DOUBLE_STRUCT& pos)
  83. {
  84. /*CAxis* _Axis;
  85. CAxis::AXIS_TYPE eAxisType = _Axis->GetAxisType();*/
  86. if (m_pProgramCViewInterface == nullptr)
  87. {
  88. XY_DOUBLE_STRUCT errorPt = pos; // 可以根据需要返回一个错误状态
  89. // 弹出消息框显示位置
  90. QString positionString = QString("Unable to retrieve axis position for module type: %1").arg(QString::fromStdString(ModuleType));
  91. QMessageBox::information(this, "Axis Position Error", positionString);
  92. return errorPt;
  93. }
  94. m_pProgramCViewInterface->GetViewMotion()->GetAxisPosition(ModuleType, "X", pos.x);
  95. m_pProgramCViewInterface->GetViewMotion()->GetAxisPosition(ModuleType, "Y", pos.y);
  96. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "X", pos.x);
  97. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "Y", pos.y);
  98. return pos;
  99. }
  100. XY_DOUBLE_STRUCT WaffleProgramPage::WaffleMoveToXYAxisPosition(std::string ModuleType, XY_DOUBLE_STRUCT& pos)
  101. {
  102. if (m_pProgramCViewInterface == nullptr)
  103. {
  104. XY_DOUBLE_STRUCT errorPt = pos; // 可以根据需要返回一个错误状态
  105. // 弹出消息框显示位置
  106. QString positionString = QString("Unable to retrieve axis position for module type: %1").arg(QString::fromStdString(ModuleType));
  107. QMessageBox::information(this, "Axis Position Error", positionString);
  108. return errorPt;
  109. }
  110. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "X", pos.x);
  111. m_pProgramCViewInterface->GetViewMotion()->ModuleMoveTo(ModuleType, "Y", pos.y);
  112. return pos;
  113. }
  114. void WaffleProgramPage::AddMatrixPage(int vectorIndex, PROGRAM_WAFFLE_MATRIX_STRUCT matrixData, std::vector<PROGRAM_DIE_MATRIX_STRUCT> vecSubMatrix)
  115. {
  116. int matrixNum = m_mapSubMatrixControls.size();
  117. int newMatrixID = ++matrixNum;
  118. QVector<QObject*> vecControls;
  119. QWidget* outWidget = new QWidget();
  120. QGridLayout* outMatrixGridLayout = new QGridLayout();
  121. outMatrixGridLayout->setSpacing(4);
  122. outMatrixGridLayout->setObjectName(QString::fromUtf8("Out GridLayout"));
  123. outMatrixGridLayout->setContentsMargins(0, 0, 0, 0); // 设置布局的边距为0
  124. QGridLayout* boxGridLayout = new QGridLayout();
  125. boxGridLayout->setSpacing(6);
  126. boxGridLayout->setObjectName(QString::fromUtf8("Box GridLayout"));
  127. QHBoxLayout* buttonLayout = new QHBoxLayout();
  128. /*QSpacerItem* item = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
  129. buttonLayout->addSpacerItem(item);*/
  130. //QPushButton* pushButtonAddOutMatrix = new QPushButton();
  131. //pushButtonAddOutMatrix->setObjectName(QString::fromUtf8("button Add"));
  132. //pushButtonAddOutMatrix->setText(tr("add out Matrix"));
  133. //buttonLayout->addWidget(pushButtonAddOutMatrix);
  134. //ui.verticalLayout->addLayout(buttonLayout);
  135. QGroupBox* groupBox = new QGroupBox(outWidget);
  136. groupBox->setLayout(boxGridLayout);
  137. QGridLayout* matrixGridLayout = new QGridLayout();
  138. matrixGridLayout->setSpacing(6);
  139. matrixGridLayout->setObjectName(QString::fromUtf8("matrixGridLayout"));
  140. QLabel* labelTitle = new QLabel(outWidget);
  141. labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
  142. labelTitle->setText(tr("Matrix ") + QString::number(vectorIndex+1));
  143. labelTitle->setStyleSheet("color: #6A78FF;height: 30px");
  144. matrixGridLayout->addWidget(labelTitle, 0, 0, 1, 1);
  145. vecControls.push_back(labelTitle);
  146. QPushButton* pushButtonAdd = new QPushButton(outWidget);
  147. pushButtonAdd->setObjectName(QString::fromUtf8("button Add"));
  148. pushButtonAdd->setText(tr("Add sub Matrix"));
  149. matrixGridLayout->addWidget(pushButtonAdd, 0, 2, 1, 3);
  150. pushButtonAdd->setProperty("type", "default");
  151. connect(pushButtonAdd, &QPushButton::clicked, this, [=]() {
  152. int newIndex = m_vecSubWaffleMatrix.size();
  153. PROGRAM_DIE_MATRIX_STRUCT dieMatrix;
  154. //排序
  155. std::sort(m_vecSubWaffleMatrix.begin(), m_vecSubWaffleMatrix.end(),
  156. [](const PROGRAM_DIE_MATRIX_STRUCT& a, const PROGRAM_DIE_MATRIX_STRUCT& b) {
  157. return a.MatrixId < b.MatrixId;
  158. });
  159. int newSubMatrixID = 0;
  160. UINT maxID = 0;
  161. // 查找最大 MatrixId
  162. for (PROGRAM_DIE_MATRIX_STRUCT& subMatrix : m_vecSubWaffleMatrix)
  163. {
  164. if (subMatrix.MatrixId > maxID)
  165. {
  166. maxID = subMatrix.MatrixId;
  167. }
  168. }
  169. // 生成新的子矩阵 ID,确保唯一性
  170. newSubMatrixID = ++maxID;
  171. while (std::any_of(m_vecSubWaffleMatrix.begin(), m_vecSubWaffleMatrix.end(),
  172. [newSubMatrixID](const PROGRAM_DIE_MATRIX_STRUCT& subMatrix) {
  173. return subMatrix.MatrixId == newSubMatrixID;
  174. }))
  175. {
  176. newSubMatrixID++; // 如果生成的 ID 已经存在,递增直到找到唯一的 ID
  177. }
  178. dieMatrix.MatrixId = newSubMatrixID;
  179. /*dieMatrix.strModuleName = "WaffleHead";
  180. dieMatrix.iModuleId = MODULE_LIST::WaffleHead;
  181. dieMatrix.MatrixRow = 0;
  182. dieMatrix.MatrixCol = 0;*/
  183. m_vecSubWaffleMatrix.push_back(dieMatrix);
  184. //找大矩阵ID/Index
  185. auto currentIt = m_mapOutWidgetIndex.find(outWidget);
  186. int index = currentIt.value(); //迭代器 erase后currentIt被删除了
  187. m_vecWaffleMatrix[index].VecDieMatrixId.push_back(newSubMatrixID);
  188. AddSubMatrixPage(vectorIndex,newIndex, dieMatrix, boxGridLayout);
  189. });
  190. QPushButton* pushButtonDelete = new QPushButton(outWidget);
  191. pushButtonDelete->setObjectName(QString::fromUtf8("button delete"));
  192. pushButtonDelete->setText(tr("Delete"));
  193. matrixGridLayout->addWidget(pushButtonDelete, 0, 1, 1, 1);
  194. connect(pushButtonDelete, &QPushButton::clicked, this, [=]() {
  195. //处理index
  196. auto currentIt = m_mapOutWidgetIndex.find(outWidget);
  197. int index = currentIt.value(); //迭代器 erase后currentIt被删除了
  198. m_mapOutWidgetIndex.erase(currentIt);
  199. for (auto it = m_mapOutWidgetIndex.begin(); it != m_mapOutWidgetIndex.end(); it++)
  200. {
  201. if (it.value() > index)
  202. {
  203. int newIndex = it.value() - 1;
  204. m_mapOutWidgetIndex.insert(it.key(), newIndex);
  205. }
  206. }
  207. //删除缓存数据
  208. m_vecWaffleMatrix.erase(m_vecWaffleMatrix.begin() + index);
  209. delete outWidget;
  210. });
  211. QLabel* labelRow = new QLabel(outWidget);
  212. labelRow->setObjectName(QString::fromUtf8("labelRow"));
  213. labelRow->setText(tr("Row & Cow"));
  214. matrixGridLayout->addWidget(labelRow, 2, 0, 1, 1);
  215. vecControls.push_back(labelRow);
  216. SpinBox* spinBoxRow = new SpinBox(outWidget);
  217. spinBoxRow->setObjectName(QString::fromUtf8("spinBoxRow"));
  218. spinBoxRow->setFixedWidth(95); // Set fixed width to 95
  219. matrixGridLayout->addWidget(spinBoxRow, 2, 1, 1, 1);
  220. vecControls.push_back(spinBoxRow);
  221. /*QLabel* labelCol = new QLabel(outWidget);
  222. labelCol->setObjectName(QString::fromUtf8("labelCol"));
  223. labelCol->setText(tr("Cow "));
  224. matrixGridLayout->addWidget(labelCol, 3, 0, 1, 1);
  225. vecControls.push_back(labelCol);*/
  226. SpinBox* spinBoxCol = new SpinBox(outWidget);
  227. spinBoxCol->setObjectName(QString::fromUtf8("spinBoxCol"));
  228. spinBoxCol->setFixedWidth(95); // Set fixed width to 95
  229. matrixGridLayout->addWidget(spinBoxCol, 2, 2, 1, 1);
  230. vecControls.push_back(spinBoxCol);
  231. QLabel* labelLeftTop = new QLabel(outWidget);
  232. labelLeftTop->setObjectName(QString::fromUtf8("labelLeftTop"));
  233. labelLeftTop->setText(tr("Left Top Pos "));
  234. matrixGridLayout->addWidget(labelLeftTop, 4, 0, 1, 1);
  235. vecControls.push_back(labelLeftTop);
  236. DoubleSpinBox* doubleSpinBoxLeftTopX = new DoubleSpinBox(outWidget);
  237. doubleSpinBoxLeftTopX->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopX"));
  238. doubleSpinBoxLeftTopX->setFixedWidth(95); // Set fixed width to 95
  239. matrixGridLayout->addWidget(doubleSpinBoxLeftTopX, 4, 1, 1, 1);
  240. vecControls.push_back(doubleSpinBoxLeftTopX);
  241. DoubleSpinBox* doubleSpinBoxLeftTopY = new DoubleSpinBox(outWidget);
  242. doubleSpinBoxLeftTopY->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopY"));
  243. doubleSpinBoxLeftTopY->setFixedWidth(95); // Set fixed width to 95
  244. matrixGridLayout->addWidget(doubleSpinBoxLeftTopY, 4, 2, 1, 1);
  245. vecControls.push_back(doubleSpinBoxLeftTopY);
  246. QPushButton* buttonLeftTop = new QPushButton("GP", this);
  247. buttonLeftTop->setFixedWidth(30); // Set the same width for the button
  248. matrixGridLayout->addWidget(buttonLeftTop, 4, 3, 1, 1); // Position the button next to LeftTopPos
  249. connect(buttonLeftTop, &QPushButton::clicked, this, [=]() {
  250. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].LeftTopPoint);
  251. doubleSpinBoxLeftTopX->setValue(position.x); // Update X axis
  252. doubleSpinBoxLeftTopY->setValue(position.y); // Update Y axis
  253. });
  254. //MoveTo
  255. QPushButton* buttonMoveToLeftTop = new QPushButton("MT", this);
  256. buttonMoveToLeftTop->setFixedWidth(30); // Set the same width for the button
  257. matrixGridLayout->addWidget(buttonMoveToLeftTop, 4, 4, 1, 1); // Position the button next to LeftTopPos
  258. connect(buttonMoveToLeftTop, &QPushButton::clicked, this, [=]() {
  259. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].LeftTopPoint);
  260. //doubleSpinBoxLeftTopX->setValue(position.x); // Update X axis
  261. //doubleSpinBoxLeftTopY->setValue(position.y); // Update Y axis
  262. });
  263. QLabel* labelRightTopPos = new QLabel(outWidget);
  264. labelRightTopPos->setObjectName(QString::fromUtf8("labelRightTopPos"));
  265. labelRightTopPos->setText(tr("Right Top Pos "));
  266. matrixGridLayout->addWidget(labelRightTopPos, 5, 0, 1, 1);
  267. vecControls.push_back(labelRightTopPos);
  268. DoubleSpinBox* doubleSpinBoxRightTopX = new DoubleSpinBox(outWidget);
  269. doubleSpinBoxRightTopX->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopX"));
  270. doubleSpinBoxRightTopX->setFixedWidth(95); // Set fixed width to 95
  271. matrixGridLayout->addWidget(doubleSpinBoxRightTopX, 5, 1, 1, 1);
  272. vecControls.push_back(doubleSpinBoxRightTopX);
  273. DoubleSpinBox* doubleSpinBoxRightTopY = new DoubleSpinBox(outWidget);
  274. doubleSpinBoxRightTopY->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopY"));
  275. doubleSpinBoxRightTopY->setFixedWidth(95); // Set fixed width to 95
  276. matrixGridLayout->addWidget(doubleSpinBoxRightTopY, 5, 2, 1, 1);
  277. vecControls.push_back(doubleSpinBoxRightTopY);
  278. QPushButton* buttonRightTop = new QPushButton("GP", this);
  279. buttonRightTop->setFixedWidth(30); // Set the same width for the button
  280. matrixGridLayout->addWidget(buttonRightTop, 5, 3, 1, 1); // Position the button next to RightTopPos
  281. connect(buttonRightTop, &QPushButton::clicked, this, [=]() {
  282. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].RightTopPoint);
  283. doubleSpinBoxRightTopX->setValue(position.x); // Update X axis
  284. doubleSpinBoxRightTopY->setValue(position.y); // Update Y axis
  285. });
  286. //MoveTo
  287. QPushButton* buttonMoveRightTop = new QPushButton("MT", this);
  288. buttonMoveRightTop->setFixedWidth(30); // Set the same width for the button
  289. matrixGridLayout->addWidget(buttonMoveRightTop, 5, 4, 1, 1); // Position the button next to LeftTopPos
  290. connect(buttonMoveRightTop, &QPushButton::clicked, this, [=]() {
  291. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].RightTopPoint);
  292. });
  293. QLabel* labelRightButtomPos = new QLabel(outWidget);
  294. labelRightButtomPos->setObjectName(QString::fromUtf8("labelRightButtomPos"));
  295. labelRightButtomPos->setText(tr("Right Buttom pos"));
  296. matrixGridLayout->addWidget(labelRightButtomPos, 6, 0, 1, 1);
  297. vecControls.push_back(labelRightButtomPos);
  298. DoubleSpinBox* doubleSpinBoxRightButtomX = new DoubleSpinBox(outWidget);
  299. doubleSpinBoxRightButtomX->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomX"));
  300. doubleSpinBoxRightButtomX->setFixedWidth(95); // Set fixed width to 95
  301. matrixGridLayout->addWidget(doubleSpinBoxRightButtomX, 6, 1, 1, 1);
  302. vecControls.push_back(doubleSpinBoxRightButtomX);
  303. DoubleSpinBox* doubleSpinBoxRightButtomY = new DoubleSpinBox(outWidget);
  304. doubleSpinBoxRightButtomY->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomY"));
  305. doubleSpinBoxRightButtomY->setFixedWidth(95); // Set fixed width to 95
  306. matrixGridLayout->addWidget(doubleSpinBoxRightButtomY, 6, 2, 1, 1);
  307. vecControls.push_back(doubleSpinBoxRightTopX);
  308. QPushButton* buttonRightButtom = new QPushButton("GP", this);
  309. buttonRightButtom->setFixedWidth(30); // Set the same width for the button
  310. matrixGridLayout->addWidget(buttonRightButtom, 6, 3, 1, 1); // Position the button next to RightBottomPos
  311. connect(buttonRightButtom, &QPushButton::clicked, this, [=]() {
  312. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].RightBottomPoint);
  313. doubleSpinBoxRightButtomX->setValue(position.x); // Update X axis
  314. doubleSpinBoxRightButtomY->setValue(position.y); // Update Y axis
  315. });
  316. //MoveTo
  317. QPushButton* buttonMoveRightButtom = new QPushButton("MT", this);
  318. buttonMoveRightButtom->setFixedWidth(30); // Set the same width for the button
  319. matrixGridLayout->addWidget(buttonMoveRightButtom, 6, 4, 1, 1); // Position the button next to LeftTopPos
  320. connect(buttonMoveRightButtom, &QPushButton::clicked, this, [=]() {
  321. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[vectorIndex].RightBottomPoint);
  322. });
  323. QLabel* labelNoBondPts = new QLabel(outWidget);
  324. labelNoBondPts->setObjectName(QString::fromUtf8("labelNoBondPts"));
  325. labelNoBondPts->setText(tr("No Bond Points"));
  326. matrixGridLayout->addWidget(labelNoBondPts, 7, 0, 1, 1);
  327. vecControls.push_back(labelNoBondPts);
  328. QLineEdit* lineEditNoBondPts = new QLineEdit(outWidget);
  329. lineEditNoBondPts->setObjectName(QString::fromUtf8("lineEditNoBondPts"));
  330. matrixGridLayout->addWidget(lineEditNoBondPts, 7, 1, 1, 4);
  331. vecControls.push_back(lineEditNoBondPts);
  332. lineEditNoBondPts->setReadOnly(true);
  333. lineEditNoBondPts->setCursor(Qt::PointingHandCursor);
  334. lineEditNoBondPts->setProperty("vectorIndex", vectorIndex); // 存储索引
  335. lineEditNoBondPts->setProperty("parentMatrixIndex", -1); // 存储大矩阵的索引(即父矩阵)
  336. lineEditNoBondPts->installEventFilter(this);
  337. QFrame* line = new QFrame(outWidget);
  338. line->setFrameShape(QFrame::NoFrame); // 移除默认框架
  339. line->setFixedHeight(2); // 设置固定高度
  340. line->setStyleSheet("background-color: #C7CAEB;");
  341. boxGridLayout->addLayout(matrixGridLayout, 2, 0);
  342. boxGridLayout->addWidget(line);
  343. outMatrixGridLayout->addLayout(buttonLayout, 1, 0);
  344. outMatrixGridLayout->addWidget(groupBox);
  345. outWidget->setLayout(outMatrixGridLayout);
  346. QSpacerItem* spacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
  347. // 移除弹簧
  348. for (int i = 0; i < ui.verticalLayout->count(); ++i) {
  349. if (ui.verticalLayout->itemAt(i)->spacerItem()) {
  350. // 找到并移除弹簧
  351. ui.verticalLayout->removeItem(ui.verticalLayout->itemAt(i));
  352. break;
  353. }
  354. }
  355. ui.verticalLayout->addWidget(outWidget);
  356. // 重新添加弹簧到布局的最下方
  357. ui.verticalLayout->addItem(spacer);
  358. m_mapOutWidgetIndex.insert(outWidget, vectorIndex);
  359. for (int j = 0; j < matrixData.VecDieMatrixId.size(); j++)
  360. {
  361. for (int i = 0; i < m_vecSubWaffleMatrix.size(); i++)
  362. {
  363. if (matrixData.VecDieMatrixId[j] == m_vecSubWaffleMatrix[i].MatrixId)
  364. {
  365. AddSubMatrixPage(j,i, m_vecSubWaffleMatrix[i], boxGridLayout);
  366. }
  367. }
  368. }
  369. //for (int i = 0; i = vecSubMatrix.size(); i++)
  370. //{
  371. // AddSubMatrixPage(i, vecSubMatrix[i], outMatrixGridLayout);
  372. //}
  373. spinBoxRow->setValue(matrixData.PackRow);
  374. spinBoxCol->setValue(matrixData.PackCol);
  375. doubleSpinBoxLeftTopX->setValue(matrixData.LeftTopPoint.x);
  376. doubleSpinBoxLeftTopY->setValue(matrixData.LeftTopPoint.y);
  377. doubleSpinBoxRightTopX->setValue(matrixData.RightTopPoint.x);
  378. doubleSpinBoxRightTopY->setValue(matrixData.RightTopPoint.y);
  379. doubleSpinBoxRightButtomX->setValue(matrixData.RightBottomPoint.x);
  380. doubleSpinBoxRightButtomY->setValue(matrixData.RightBottomPoint.y);
  381. connect(spinBoxRow, &SpinBox::editDone, this, [=]() {
  382. m_vecWaffleMatrix[vectorIndex].PackRow = spinBoxRow->value();
  383. });
  384. connect(spinBoxCol, &SpinBox::editDone, this, [=]() {
  385. m_vecWaffleMatrix[vectorIndex].PackCol = spinBoxCol->value();
  386. });
  387. connect(doubleSpinBoxLeftTopX, &DoubleSpinBox::editDone, this, [=]() {
  388. m_vecWaffleMatrix[vectorIndex].LeftTopPoint.x = doubleSpinBoxLeftTopX->value();
  389. });
  390. connect(doubleSpinBoxLeftTopY, &DoubleSpinBox::editDone, this, [=]() {
  391. m_vecWaffleMatrix[vectorIndex].LeftTopPoint.y = doubleSpinBoxLeftTopY->value();
  392. });
  393. connect(doubleSpinBoxRightTopX, &DoubleSpinBox::editDone, this, [=]() {
  394. m_vecWaffleMatrix[vectorIndex].RightTopPoint.x = doubleSpinBoxRightTopX->value();
  395. });
  396. connect(doubleSpinBoxRightTopY, &DoubleSpinBox::editDone, this, [=]() {
  397. m_vecWaffleMatrix[vectorIndex].RightTopPoint.y = doubleSpinBoxRightTopY->value();
  398. });
  399. connect(doubleSpinBoxRightButtomX, &DoubleSpinBox::editDone, this, [=]() {
  400. m_vecWaffleMatrix[vectorIndex].RightBottomPoint.x = doubleSpinBoxRightButtomX->value();
  401. });
  402. connect(doubleSpinBoxRightButtomY, &DoubleSpinBox::editDone, this, [=]() {
  403. m_vecWaffleMatrix[vectorIndex].RightBottomPoint.y = doubleSpinBoxRightButtomY->value();
  404. });
  405. connect(lineEditNoBondPts, &QLineEdit::textChanged, this, [=]() {
  406. });
  407. }
  408. void WaffleProgramPage::AddSubMatrixPage(int vectorIndex, int subVectorIndex, PROGRAM_DIE_MATRIX_STRUCT subMatrix, QGridLayout* layout)
  409. {
  410. QVector<QObject*> vecControls;
  411. QWidget* subWidget = new QWidget();
  412. QGridLayout* subGridLayout = new QGridLayout(subWidget);
  413. subGridLayout->setSpacing(4);
  414. subGridLayout->setObjectName(QString::fromUtf8("subGridLayout"));
  415. //groupBox->setLayout(subGridLayout);
  416. subGridLayout->setContentsMargins(0, 0, 0, 0); // 设置布局的边距为0
  417. subGridLayout->setAlignment(Qt::AlignCenter);
  418. QLabel* labelTitle = new QLabel(subWidget);
  419. labelTitle->setObjectName(QString::fromUtf8("labelTitle"));
  420. labelTitle->setText(tr("Sub Matrix ") + QString::number(subVectorIndex));
  421. labelTitle->setStyleSheet("color: #808BFF;height: 30px");
  422. subGridLayout->addWidget(labelTitle, 0, 1, 1, 1);
  423. vecControls.push_back(labelTitle);
  424. QPushButton* pushButtonDelete = new QPushButton(subWidget);
  425. pushButtonDelete->setObjectName(QString::fromUtf8("button delete"));
  426. pushButtonDelete->setText(tr("Delete"));
  427. subGridLayout->addWidget(pushButtonDelete, 0, 3, 1, 2);
  428. connect(pushButtonDelete, &QPushButton::clicked, this, [=]() {
  429. //处理index
  430. auto currentIt = m_mapSubWidgetIndex.find(subWidget);
  431. int index = currentIt.value(); //迭代器 erase后currentIt被删除了
  432. m_mapSubWidgetIndex.erase(currentIt);
  433. for (auto it = m_mapSubWidgetIndex.begin(); it != m_mapSubWidgetIndex.end(); ++it)
  434. {
  435. if (it.value() > index)
  436. {
  437. //value() 返回的是副本不是引用
  438. int newIndex = it.value() - 1;
  439. m_mapSubWidgetIndex.insert(it.key(), newIndex);
  440. }
  441. }
  442. // 子矩阵ID
  443. int subMatrixId = m_vecSubWaffleMatrix[index].MatrixId;
  444. //删除缓存
  445. m_vecSubWaffleMatrix.erase(m_vecSubWaffleMatrix.begin() + index);
  446. //删除大矩阵子ID数据(遍历删除)
  447. for (PROGRAM_WAFFLE_MATRIX_STRUCT& matrix : m_vecWaffleMatrix)
  448. {
  449. auto it = std::find(matrix.VecDieMatrixId.begin(), matrix.VecDieMatrixId.end(), subMatrixId);
  450. if (it != matrix.VecDieMatrixId.end())
  451. {
  452. matrix.VecDieMatrixId.erase(it);
  453. }
  454. }
  455. delete subWidget;
  456. });
  457. QLabel* labelRow = new QLabel(subWidget);
  458. labelRow->setObjectName(QString::fromUtf8("labelRow"));
  459. labelRow->setText(tr("Row & Cow"));
  460. subGridLayout->addWidget(labelRow, 2, 0, 1, 1);
  461. vecControls.push_back(labelRow);
  462. SpinBox* spinBoxRow = new SpinBox(subWidget);
  463. spinBoxRow->setObjectName(QString::fromUtf8("spinBoxRow"));
  464. subGridLayout->addWidget(spinBoxRow, 2, 1, 1, 1);
  465. vecControls.push_back(spinBoxRow);
  466. /*QLabel* labelCol = new QLabel(subWidget);
  467. labelCol->setObjectName(QString::fromUtf8("labelCol"));
  468. labelCol->setText(tr("Cow "));
  469. subGridLayout->addWidget(labelCol, 3, 0, 1, 1);
  470. vecControls.push_back(labelCol);*/
  471. SpinBox* spinBoxCol = new SpinBox(subWidget);
  472. spinBoxCol->setObjectName(QString::fromUtf8("spinBoxCol"));
  473. subGridLayout->addWidget(spinBoxCol, 2, 2, 1, 1);
  474. vecControls.push_back(spinBoxCol);
  475. QLabel* labelLeftTop = new QLabel(subWidget);
  476. labelLeftTop->setObjectName(QString::fromUtf8("labelLeftTop"));
  477. labelLeftTop->setText(tr("Left Top Pos "));
  478. subGridLayout->addWidget(labelLeftTop, 4, 0, 1, 1);
  479. vecControls.push_back(labelLeftTop);
  480. DoubleSpinBox* doubleSpinBoxLeftTopX = new DoubleSpinBox(subWidget);
  481. doubleSpinBoxLeftTopX->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopX"));
  482. doubleSpinBoxLeftTopX->setFixedWidth(95); // Set fixed width to 95
  483. doubleSpinBoxLeftTopX->setFixedWidth(95); // Set fixed width to 95
  484. subGridLayout->addWidget(doubleSpinBoxLeftTopX, 4, 1, 1, 1);
  485. vecControls.push_back(doubleSpinBoxLeftTopX);
  486. DoubleSpinBox* doubleSpinBoxLeftTopY = new DoubleSpinBox(subWidget);
  487. doubleSpinBoxLeftTopY->setObjectName(QString::fromUtf8("doubleSpinBoxLeftTopY"));
  488. doubleSpinBoxLeftTopY->setFixedWidth(95); // Set fixed width to 95
  489. doubleSpinBoxLeftTopY->setFixedWidth(95); // Set fixed width to 95
  490. subGridLayout->addWidget(doubleSpinBoxLeftTopY, 4, 2, 1, 1);
  491. vecControls.push_back(doubleSpinBoxLeftTopY);
  492. QLabel* labelRightTopPos = new QLabel(subWidget);
  493. labelRightTopPos->setObjectName(QString::fromUtf8("labelRightTopPos"));
  494. labelRightTopPos->setText(tr("Right Top Pos "));
  495. subGridLayout->addWidget(labelRightTopPos, 5, 0, 1, 1);
  496. vecControls.push_back(labelRightTopPos);
  497. DoubleSpinBox* doubleSpinBoxRightTopX = new DoubleSpinBox(subWidget);
  498. doubleSpinBoxRightTopX->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopX"));
  499. doubleSpinBoxRightTopX->setFixedWidth(95); // Set fixed width to 95
  500. subGridLayout->addWidget(doubleSpinBoxRightTopX, 5, 1, 1, 1);
  501. vecControls.push_back(doubleSpinBoxRightTopX);
  502. DoubleSpinBox* doubleSpinBoxRightTopY = new DoubleSpinBox(subWidget);
  503. doubleSpinBoxRightTopY->setObjectName(QString::fromUtf8("doubleSpinBoxRightTopY"));
  504. doubleSpinBoxRightTopY->setFixedWidth(95); // Set fixed width to 95
  505. subGridLayout->addWidget(doubleSpinBoxRightTopY, 5, 2, 1, 1);
  506. vecControls.push_back(doubleSpinBoxRightTopY);
  507. QLabel* labelRightButtomPos = new QLabel(subWidget);
  508. labelRightButtomPos->setObjectName(QString::fromUtf8("labelRightButtomPos"));
  509. labelRightButtomPos->setText(tr("Right Buttom pos"));
  510. subGridLayout->addWidget(labelRightButtomPos, 6, 0, 1, 1);
  511. vecControls.push_back(labelRightButtomPos);
  512. DoubleSpinBox* doubleSpinBoxRightButtomX = new DoubleSpinBox(subWidget);
  513. doubleSpinBoxRightButtomX->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomX"));
  514. doubleSpinBoxRightButtomX->setFixedWidth(95); // Set fixed width to 95
  515. subGridLayout->addWidget(doubleSpinBoxRightButtomX, 6, 1, 1, 1);
  516. vecControls.push_back(doubleSpinBoxRightButtomX);
  517. DoubleSpinBox* doubleSpinBoxRightButtomY = new DoubleSpinBox(subWidget);
  518. doubleSpinBoxRightButtomY->setObjectName(QString::fromUtf8("doubleSpinBoxRightButtomY"));
  519. doubleSpinBoxRightButtomY->setFixedWidth(95); // Set fixed width to 95
  520. subGridLayout->addWidget(doubleSpinBoxRightButtomY, 6, 2, 1, 1);
  521. vecControls.push_back(doubleSpinBoxRightTopX);
  522. QLabel* labelNoBondPts = new QLabel(subWidget);
  523. labelNoBondPts->setObjectName(QString::fromUtf8("labelNoBondPts"));
  524. labelNoBondPts->setText(tr("No Bond Points"));
  525. subGridLayout->addWidget(labelNoBondPts, 7, 0, 1, 1);
  526. vecControls.push_back(labelNoBondPts);
  527. QLineEdit* lineEditNoBondPts = new QLineEdit(subWidget);
  528. lineEditNoBondPts->setObjectName(QString::fromUtf8("lineEditNoBondPts"));
  529. lineEditNoBondPts->setReadOnly(true);
  530. lineEditNoBondPts->setCursor(Qt::PointingHandCursor);
  531. //lineEditNoBondPts->setProperty("matrixType", "SubMatrix"); // 设置为子矩阵
  532. lineEditNoBondPts->setProperty("vectorIndex", subVectorIndex); // 子矩阵索引
  533. lineEditNoBondPts->setProperty("parentMatrixIndex", vectorIndex); // 设置父矩阵的索引
  534. lineEditNoBondPts->installEventFilter(this);
  535. subGridLayout->addWidget(lineEditNoBondPts, 7, 1, 1, 3);
  536. vecControls.push_back(lineEditNoBondPts);
  537. // Left Top Position X and Y
  538. QPushButton* buttonLeftTop = new QPushButton("GP", subWidget);
  539. buttonLeftTop->setFixedWidth(30); // 设置固定宽度
  540. subGridLayout->addWidget(buttonLeftTop, 4, 3, 1, 1); // 添加按钮到4行3列
  541. connect(buttonLeftTop, &QPushButton::clicked, this, [=]() {
  542. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecSubWaffleMatrix[subVectorIndex].LeftTopPoint);
  543. doubleSpinBoxLeftTopX->setValue(position.x); // 更新 X 轴
  544. doubleSpinBoxLeftTopY->setValue(position.y); // 更新 Y 轴
  545. });
  546. //MoveTo
  547. QPushButton* buttonMoveLeftTop = new QPushButton("MT", subWidget);
  548. buttonMoveLeftTop->setFixedWidth(30); // Set the same width for the button
  549. subGridLayout->addWidget(buttonMoveLeftTop, 4, 4, 1, 1); // Position the button next to LeftTopPos
  550. connect(buttonMoveLeftTop, &QPushButton::clicked, this, [=]() {
  551. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[subVectorIndex].LeftTopPoint);
  552. });
  553. // Right Top Position X and Y
  554. QPushButton* buttonRightTop = new QPushButton("GP", subWidget);
  555. buttonRightTop->setFixedWidth(30); // 设置固定宽度
  556. subGridLayout->addWidget(buttonRightTop, 5, 3, 1, 1); // 添加按钮到5行3列
  557. connect(buttonRightTop, &QPushButton::clicked, this, [=]() {
  558. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecSubWaffleMatrix[subVectorIndex].RightTopPoint);
  559. doubleSpinBoxRightTopX->setValue(position.x); // 更新 X 轴
  560. doubleSpinBoxRightTopY->setValue(position.y); // 更新 Y 轴
  561. });
  562. //MoveTo
  563. QPushButton* buttonMoveRightTop = new QPushButton("MT", subWidget);
  564. buttonMoveRightTop->setFixedWidth(30); // Set the same width for the button
  565. subGridLayout->addWidget(buttonMoveRightTop, 5, 4, 1, 1); // Position the button next to LeftTopPos
  566. connect(buttonMoveRightTop, &QPushButton::clicked, this, [=]() {
  567. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[subVectorIndex].RightTopPoint);
  568. });
  569. // Right Bottom Position X and Y
  570. QPushButton* buttonRightButtom = new QPushButton("GP", subWidget);
  571. buttonRightButtom->setFixedWidth(30); // 设置固定宽度
  572. subGridLayout->addWidget(buttonRightButtom, 6, 3, 1, 1); // 添加按钮到6行3列
  573. connect(buttonRightButtom, &QPushButton::clicked, this, [=]() {
  574. XY_DOUBLE_STRUCT position = WaffleGetAxisPosition("WaffleHead", m_vecSubWaffleMatrix[subVectorIndex].RightBottomPoint);
  575. doubleSpinBoxRightButtomX->setValue(position.x); // 更新 X 轴
  576. doubleSpinBoxRightButtomY->setValue(position.y); // 更新 Y 轴
  577. });
  578. //MoveTo
  579. QPushButton* buttonMoveRightButtom = new QPushButton("MT", subWidget);
  580. buttonMoveRightButtom->setFixedWidth(30); // Set the same width for the button
  581. subGridLayout->addWidget(buttonMoveRightButtom, 6, 4, 1, 1); // Position the button next to LeftTopPos
  582. connect(buttonMoveRightButtom, &QPushButton::clicked, this, [=]() {
  583. XY_DOUBLE_STRUCT position = WaffleMoveToXYAxisPosition("WaffleHead", m_vecWaffleMatrix[subVectorIndex].RightBottomPoint);
  584. });
  585. //layout->addLayout(subGridLayout, 11, 0);
  586. QFrame* line = new QFrame(subWidget);
  587. line->setFrameShape(QFrame::NoFrame); // 移除默认框架
  588. line->setFixedHeight(2); // 设置固定高度
  589. line->setStyleSheet("background-color: #C7CAEB;");
  590. subGridLayout->addWidget(line, 10, 0, 1, 3);
  591. layout->addWidget(subWidget);
  592. m_mapSubWidgetIndex.insert(subWidget, subVectorIndex);
  593. spinBoxRow->setValue(subMatrix.MatrixRow);
  594. spinBoxCol->setValue(subMatrix.MatrixCol);
  595. doubleSpinBoxLeftTopX->setValue(subMatrix.LeftTopPoint.x);
  596. doubleSpinBoxLeftTopY->setValue(subMatrix.LeftTopPoint.y);
  597. doubleSpinBoxRightTopX->setValue(subMatrix.RightTopPoint.x);
  598. doubleSpinBoxRightTopY->setValue(subMatrix.RightTopPoint.y);
  599. doubleSpinBoxRightButtomX->setValue(subMatrix.RightBottomPoint.x);
  600. doubleSpinBoxRightButtomY->setValue(subMatrix.RightBottomPoint.y);
  601. connect(spinBoxRow, &SpinBox::editDone, this, [=]() {
  602. auto it = m_mapSubWidgetIndex.find(subWidget);
  603. m_vecSubWaffleMatrix[it.value()].MatrixRow = spinBoxRow->value();
  604. });
  605. connect(spinBoxCol, &SpinBox::editDone, this, [=]() {
  606. auto it = m_mapSubWidgetIndex.find(subWidget);
  607. m_vecSubWaffleMatrix[it.value()].MatrixCol = spinBoxCol->value();
  608. });
  609. connect(doubleSpinBoxLeftTopX, &DoubleSpinBox::editDone, this, [=]() {
  610. auto it = m_mapSubWidgetIndex.find(subWidget);
  611. m_vecSubWaffleMatrix[it.value()].LeftTopPoint.x = doubleSpinBoxLeftTopX->value();
  612. });
  613. connect(doubleSpinBoxLeftTopY, &DoubleSpinBox::editDone, this, [=]() {
  614. auto it = m_mapSubWidgetIndex.find(subWidget);
  615. m_vecSubWaffleMatrix[it.value()].LeftTopPoint.y = doubleSpinBoxLeftTopY->value();
  616. });
  617. connect(doubleSpinBoxRightTopX, &DoubleSpinBox::editDone, this, [=]() {
  618. auto it = m_mapSubWidgetIndex.find(subWidget);
  619. m_vecSubWaffleMatrix[it.value()].RightTopPoint.x = doubleSpinBoxRightTopX->value();
  620. });
  621. connect(doubleSpinBoxRightTopY, &DoubleSpinBox::editDone, this, [=]() {
  622. auto it = m_mapSubWidgetIndex.find(subWidget);
  623. m_vecSubWaffleMatrix[it.value()].RightTopPoint.y = doubleSpinBoxRightTopY->value();
  624. });
  625. connect(doubleSpinBoxRightButtomX, &DoubleSpinBox::editDone, this, [=]() {
  626. auto it = m_mapSubWidgetIndex.find(subWidget);
  627. m_vecSubWaffleMatrix[it.value()].RightBottomPoint.x = doubleSpinBoxRightButtomX->value();
  628. });
  629. connect(doubleSpinBoxRightButtomY, &DoubleSpinBox::editDone, this, [=]() {
  630. auto it = m_mapSubWidgetIndex.find(subWidget);
  631. m_vecSubWaffleMatrix[it.value()].RightBottomPoint.y = doubleSpinBoxRightButtomY->value();
  632. });
  633. connect(lineEditNoBondPts, &QLineEdit::textChanged, this, [=]() {
  634. auto it = m_mapSubWidgetIndex.find(subWidget);
  635. });
  636. }
  637. bool WaffleProgramPage::eventFilter(QObject* obj, QEvent* event) {
  638. if (event->type() == QEvent::MouseButtonPress)
  639. {
  640. auto* lineEdit = qobject_cast<QLineEdit*>(obj);
  641. if (lineEdit)
  642. {
  643. int index = lineEdit->property("vectorIndex").toInt(); // 当前矩阵索引
  644. int parentIndex = lineEdit->property("parentMatrixIndex").toInt(); // 父矩阵索引
  645. onNoBondPtsClicked(lineEdit, index, parentIndex); // 传递父矩阵索引
  646. return true; // 拦截事件
  647. }
  648. }
  649. return QWidget::eventFilter(obj, event);
  650. }
  651. void WaffleProgramPage::onNoBondPtsClicked(QLineEdit* lineEdit, int index, int parentIndex) {
  652. if (parentIndex != -1)
  653. {
  654. // 处理子矩阵的操作
  655. if (index < 0 || index >= m_vecSubWaffleMatrix.size()) return;
  656. const auto& subMatrix = m_vecSubWaffleMatrix[index];
  657. NoBondPtEditDialog dlg(subMatrix.MatrixRow, subMatrix.MatrixCol, subMatrix.VecNoBondPt, this);
  658. if (dlg.exec() == QDialog::Accepted)
  659. {
  660. QVector<XY_LONG_STRUCT> selected = dlg.getSelectedPoints();
  661. m_vecSubWaffleMatrix[index].VecNoBondPt = std::vector<XY_LONG_STRUCT>(selected.begin(), selected.end());
  662. QStringList ptList;
  663. for (const auto& pt : selected)
  664. ptList << QString("(%1,%2)").arg(pt.x).arg(pt.y);
  665. lineEdit->setText(ptList.join(" "));
  666. }
  667. // 这里可以用 parentIndex 来关联父矩阵(即大矩阵)做相应的操作
  668. }
  669. else
  670. {
  671. // 处理大矩阵的操作
  672. if (index < 0 || index >= m_vecWaffleMatrix.size()) return;
  673. const auto& waffleMatrix = m_vecWaffleMatrix[index];
  674. NoBondPtEditDialog dlg(waffleMatrix.PackRow, waffleMatrix.PackCol, waffleMatrix.VecNoBondDie, this);
  675. if (dlg.exec() == QDialog::Accepted)
  676. {
  677. QVector<XY_LONG_STRUCT> selected = dlg.getSelectedPoints();
  678. m_vecWaffleMatrix[index].VecNoBondDie = std::vector<XY_LONG_STRUCT>(selected.begin(), selected.end());
  679. QStringList ptList;
  680. for (const auto& pt : selected)
  681. ptList << QString("(%1,%2)").arg(pt.x).arg(pt.y);
  682. lineEdit->setText(ptList.join(" "));
  683. }
  684. // 这里也可以用 parentIndex 来关联父矩阵(即大矩阵)做相应的操作
  685. }
  686. }
  687. void WaffleProgramPage::SaveAllParam()
  688. {
  689. }
  690. void WaffleProgramPage::MatrixChangeEvent()
  691. {
  692. for (PROGRAM_WAFFLE_MATRIX_STRUCT& waffleMatrix : m_vecWaffleMatrix)
  693. {
  694. m_pProduct->SetWaffleMatrix(waffleMatrix.MatrixId, waffleMatrix);
  695. }
  696. m_pProduct->SetDieMatrix(m_vecSubWaffleMatrix, true);
  697. //for (PROGRAM_BOND_MATRIX_STRUCT& bondMatrix : m_vecWaffleMatrix)
  698. //{
  699. // m_manageDB->GetCProduct()->SetBondMatrix(bondMatrix.BondMatrixId, bondMatrix);
  700. //}
  701. //for (PROGRAM_POINT_MATRIX_STRUCT& pointMatrix : m_vecSubMatrixs)
  702. //{
  703. // m_manageDB->GetCProduct()->SetPointMatrix(pointMatrix.MatrixId, pointMatrix);
  704. //}
  705. }
  706. void WaffleProgramPage::initPage()
  707. {
  708. m_vecWaffleMatrix = m_pProduct->GetWaffleMatrix();
  709. m_pProduct->GetAllDieMatrix(m_vecSubWaffleMatrix);
  710. for (int i = 0; i < m_vecWaffleMatrix.size(); i++)
  711. {
  712. //for (int j = 0; j < m_vecWaffleMatrix[i].VecDieMatrixId.size(); j++)
  713. //{
  714. // PROGRAM_DIE_MATRIX_STRUCT subMatrix;
  715. // m_pProduct->GetDieMatrix(m_vecWaffleMatrix[i].VecDieMatrixId[j], subMatrix);
  716. // m_vecSubWaffleMatrix.push_back(subMatrix);
  717. // //AddMatrixPage(i, j, subMatrix);
  718. //}
  719. AddMatrixPage(i, m_vecWaffleMatrix[i], m_vecSubWaffleMatrix);
  720. }
  721. }