Waffle.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #include "Waffle.h"
  2. #include <QPainter>
  3. #include <QPaintEvent>
  4. Waffle::Waffle(int flag, QWidget *parent) : QWidget(parent)
  5. {
  6. }
  7. void Waffle::UpdataGenerateTestData()
  8. {
  9. // //根据不同窗口设置不同大小 0:小 1:中 2:大
  10. // if (flag == 0) {
  11. // // 华夫台的参数
  12. // gridSize = 5; // 每个格子的大小
  13. // gap = 3; // 格子之间的间隙
  14. // boxGap = 6; // 华夫台之间的间隙
  15. // } else if (flag == 1) {
  16. // // 华夫台的参数
  17. // gridSize = 20; // 每个格子的大小
  18. // gap = 6; // 格子之间的间隙
  19. // boxGap = 12; // 华夫台之间的间隙
  20. // } else if (flag == 2) {
  21. // // 华夫台的参数
  22. // gridSize = 50; // 每个格子的大小
  23. // gap = 6; // 格子之间的间隙
  24. // boxGap = 12; // 华夫台之间的间隙
  25. // }
  26. rows = 6;
  27. cols = 18;
  28. centerX = 25;
  29. centerY = 25;
  30. // 随机数初始化
  31. std::srand(std::time(nullptr)); // 使用当前时间作为种子
  32. for (int row = 0; row < rows; ++row) {
  33. for (int col = 0; col < cols; ++col) {
  34. ns_mat::WAFFLE_MATRIX_POINT_STRUCT point;
  35. point.nPackMatrixId = 1;
  36. point.nPackRow = 6;
  37. point.nPackCol = 18;
  38. point.nDieRow = row;
  39. point.nDieCol = col;
  40. point.nDieMatrixId = 1;
  41. point.iDieIndex = 1;
  42. point.bDisable = false; // 默认为可用
  43. point.stPosition.x = col * 10.0;
  44. point.stPosition.y = row * 10.0;
  45. int randomStatus = std::rand() % 5; // 随机选取DIE_EXIST, PICK_ING, NO_EXIST, SKIP_DIE
  46. point.eStatus = static_cast<ns_mat::PICK_DIE_STATUS>(randomStatus);
  47. // 将点添加到waferData容器中
  48. m_vWaffleData.append(point);
  49. }
  50. }
  51. }
  52. void Waffle::UpdataVal(const std::vector<ns_mat::WAFFLE_MATRIX_POINT_STRUCT>& veWaffle)
  53. {
  54. maxRow = 0;
  55. maxCol = 0;
  56. waffleMatrixRowNum = 0;
  57. waffleMatrixColNum = 0;
  58. matrixInfo mInfo;
  59. mInfo.maxCol = 0;
  60. mInfo.maxRow = 0;
  61. UINT dieMatrixId = veWaffle[0].nDieMatrixId;
  62. for (const auto a: veWaffle)
  63. {
  64. if (dieMatrixId != a.nDieMatrixId) {
  65. matrixInfoMap.insert(dieMatrixId, mInfo);
  66. dieMatrixId = a.nPackMatrixId;
  67. mInfo.maxCol = 0;
  68. mInfo.maxRow = 0;
  69. }
  70. else {
  71. if (mInfo.maxRow < a.nDieRow)
  72. mInfo.maxRow = a.nDieRow;
  73. if (mInfo.maxCol < a.nDieCol)
  74. mInfo.maxCol = a.nDieCol;
  75. }
  76. m_vWaffleData.append(a);
  77. if (a.nPackRow == 1 && a.nDieRow==1) {
  78. waffleMatrixRowNum++;
  79. }
  80. if (a.nPackCol == 1 && a.nDieCol == 1) {
  81. waffleMatrixColNum++;
  82. }
  83. if (maxRow < a.nPackRow)
  84. maxRow = a.nPackRow;
  85. if (maxCol < a.nPackCol)
  86. maxCol = a.nPackCol;
  87. }
  88. matrixInfoMap.insert(dieMatrixId, mInfo);
  89. qDebug() << maxRow << maxCol << waffleMatrixRowNum << waffleMatrixColNum;
  90. }
  91. void Waffle::paintEvent(QPaintEvent *event) {
  92. QPainter painter(this);
  93. // 设置抗锯齿,使绘图更平滑
  94. painter.setRenderHint(QPainter::Antialiasing);
  95. // 绘制背景
  96. painter.fillRect(this->rect(), Qt::white);
  97. // 计算每个华夫台的总宽度和高度
  98. int totalWidth = cols * gridSize + (cols - 1) * gap;
  99. int totalHeight = rows * gridSize + (rows - 1) * gap;
  100. // 计算华夫盒的总宽度和高度
  101. int boxTotalWidth = boxCols * totalWidth + (boxCols - 1) * boxGap;
  102. int boxTotalHeight = boxRows * totalHeight + (boxRows - 1) * boxGap;
  103. // 确定华夫盒的起始位置,使其居中
  104. int boxStartX = (width() - boxTotalWidth) / 2;
  105. int boxStartY = (height() - boxTotalHeight) / 2;
  106. // 绘制多个华夫台
  107. for (int i = 0; i < boxRows; ++i) {
  108. for (int j = 0; j < boxCols; ++j) {
  109. // 计算每个华夫台的起始位置
  110. int startX = boxStartX + j * (totalWidth + boxGap);
  111. int startY = boxStartY + i * (totalHeight + boxGap);
  112. // 绘制单个华夫台
  113. drawWaffle(painter, startX, startY, rows, cols, gridSize, gap);
  114. }
  115. }
  116. }
  117. void Waffle::drawWaffle(QPainter &painter, int startX, int startY, int rows, int cols, int gridSize, int gap) {
  118. // 绘制网格
  119. for (int i = 0; i < rows; ++i) {
  120. for (int j = 0; j < cols; ++j) {
  121. // 计算每个格子的坐标
  122. int x = startX + j * (gridSize + gap);
  123. int y = startY + i * (gridSize + gap);
  124. QRect cellRect(x, y, gridSize, gridSize);
  125. // 填充颜色
  126. painter.fillRect(cellRect, Qt::yellow);
  127. // 绘制边框
  128. painter.setPen(Qt::black);
  129. painter.drawRect(cellRect);
  130. }
  131. }
  132. }
  133. QColor Waffle::getColorByStatus(ns_mat::PICK_DIE_STATUS status) {
  134. switch (status) {
  135. case ns_mat::PICK_DIE_STATUS::DIE_EXIST: return QColor(0, 102, 255); // 蓝色
  136. case ns_mat::PICK_DIE_STATUS::NO_EXIST: return QColor(200, 200, 200); // 浅灰
  137. case ns_mat::PICK_DIE_STATUS::PICK_ING: return QColor(255, 255, 0); // 黄色
  138. case ns_mat::PICK_DIE_STATUS::SKIP_DIE: return QColor(128, 128, 128); // 深灰
  139. case ns_mat::PICK_DIE_STATUS::EDGE_DIE: return QColor(255, 165, 0); // 橙色
  140. default: return QColor(0, 0, 0); // 默认黑色
  141. }
  142. }
  143. void Waffle::paintInitFrom(QWidget *parent) {
  144. // 获取当前窗口的宽高
  145. int width = parent->width();
  146. int height = parent->height();
  147. // 根据行列数计算每个晶圆点的大小,选择小的边来决定
  148. int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
  149. // 计算左上角偏移量,居中显示
  150. int offsetX = (width - cellSize * cols) / 2;
  151. int offsetY = (height - cellSize * rows) / 2;
  152. // 创建一个 QPixmap 对象用于保存绘制的图像
  153. globalPixmap = QPixmap(width, height);
  154. globalPixmap.fill(Qt::white); // 填充背景色为白色
  155. // 创建 QPainter 以绘制到 QPixmap 上
  156. QPainter painter(&globalPixmap);
  157. painter.setRenderHint(QPainter::Antialiasing); // 启用抗锯齿
  158. // 设置画笔为无边框
  159. painter.setPen(Qt::NoPen);
  160. // 绘制每个晶圆点
  161. for (int i = 0; i < m_vWaffleData.size(); ++i) {
  162. int x = offsetX + m_vWaffleData[i].nDieCol * cellSize;
  163. int y = offsetY + m_vWaffleData[i].nDieRow * cellSize;
  164. // 根据点的状态设置颜色
  165. painter.setBrush(getColorByStatus(m_vWaffleData[i].eStatus));
  166. // 绘制晶圆点(每个点是一个矩形)
  167. painter.drawRect(x, y, cellSize, cellSize);
  168. }
  169. // painter.setBrush(Qt::black);
  170. // painter.drawEllipse(centerX - 3, centerY - 3, 6, 6);
  171. painter.end(); // 结束绘制
  172. }
  173. void Waffle::initFrom(QWidget *parent) {
  174. scene = new QGraphicsScene(parent);
  175. view = new WaffleGraphicsView(scene);
  176. /*
  177. // 获取当前窗口的宽高
  178. int width = parent->width();
  179. int height = parent->height();
  180. // 根据行列数计算每个晶圆点的大小,选择小的边来决定
  181. int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
  182. for (int i = 0; i < m_vWaffleData.size(); ++i) {
  183. DieItem* die = new DieItem(m_vWaffleData[i].nDieRow, m_vWaffleData[i].nDieCol, m_vWaffleData[i].eStatus, cellSize);
  184. die->setPos(m_vWaffleData[i].nDieCol * cellSize, m_vWaffleData[i].nDieRow * cellSize);
  185. scene->addItem(die);
  186. }
  187. view->setSceneRect(scene->itemsBoundingRect());
  188. view->resize(width, height);
  189. */
  190. }
  191. QPixmap Waffle::getGlobalPixmap() const {
  192. return globalPixmap;
  193. }