Wafer.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "Wafer.h"
  2. #include <QPainter>
  3. #include <QPaintEvent>
  4. #include <cmath>
  5. #include <QDebug>
  6. #include <QPushButton>
  7. #include <QGridLayout>
  8. Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) {
  9. }
  10. void Wafer::UpdataGenerateTestData()
  11. {
  12. Flag = 0;
  13. rows = 51;
  14. cols = 51;
  15. centerX = 25;
  16. centerY = 25;
  17. radius = 25;
  18. // 随机数初始化
  19. std::srand(std::time(nullptr)); // 使用当前时间作为种子
  20. // 遍历矩阵,按行列判断是否在圆形区域内
  21. for (int row = 0; row < rows; ++row) {
  22. for (int col = 0; col < cols; ++col) {
  23. // 计算当前点到中心点的距离
  24. double dx = col - centerX;
  25. double dy = row - centerY;
  26. double distance = std::sqrt(dx * dx + dy * dy);
  27. // 如果点在圆形区域外部,跳过
  28. if (distance > radius) {
  29. continue;
  30. }
  31. // 创建一个新的WAFER_MATRIX_POINT_INFO_STRUCT
  32. ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT point;
  33. point.nDieMatrixId = 1; // 假设所有点属于同一晶圆矩阵
  34. point.nDieRow = row;
  35. point.nDieCol = col;
  36. point.iDieIndex = row * cols + col; // 假设ID为行列号的线性映射
  37. point.bDisable = false; // 默认为可用
  38. point.stPosition.x = col * 10.0;
  39. point.stPosition.y = row * 10.0;
  40. // 判断该点是否在圆形区域的边缘
  41. if (distance > radius - 1 && distance < radius + 1) {
  42. point.eStatus = ns_mat::PICK_DIE_STATUS::EDGE_DIE; // 如果在边缘区域,状态设置为EDGE_DIE
  43. }
  44. else {
  45. // 如果在圆形区域内,随机设置其他状态
  46. int randomStatus = std::rand() % 4; // 随机选取DIE_EXIST, PICK_ING, NO_EXIST, SKIP_DIE
  47. point.eStatus = static_cast<ns_mat::PICK_DIE_STATUS>(randomStatus);
  48. }
  49. // 将点添加到waferData容器中
  50. waferData.append(point);
  51. }
  52. }
  53. }
  54. void Wafer::UpdataVal(const std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT>& veWafer)
  55. {
  56. for (const auto a : veWafer)
  57. {
  58. waferData.append(a);
  59. }
  60. }
  61. QColor Wafer::getColorByStatus(ns_mat::PICK_DIE_STATUS status) {
  62. switch (status) {
  63. case ns_mat::PICK_DIE_STATUS::DIE_EXIST: return QColor(0, 102, 255); // 蓝色
  64. case ns_mat::PICK_DIE_STATUS::NO_EXIST: return QColor(200, 200, 200); // 浅灰
  65. case ns_mat::PICK_DIE_STATUS::PICK_ING: return QColor(255, 255, 0); // 黄色
  66. case ns_mat::PICK_DIE_STATUS::SKIP_DIE: return QColor(128, 128, 128); // 深灰
  67. case ns_mat::PICK_DIE_STATUS::EDGE_DIE: return QColor(255, 165, 0); // 橙色
  68. default: return QColor(0, 0, 0); // 默认黑色
  69. }
  70. }
  71. void Wafer::paintInitFrom(QWidget *parent) {
  72. // 获取当前窗口的宽高
  73. int width = parent->width();
  74. int height = parent->height();
  75. // 根据行列数计算每个晶圆点的大小,选择小的边来决定
  76. int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
  77. // 计算左上角偏移量,居中显示
  78. int offsetX = (width - cellSize * cols) / 2;
  79. int offsetY = (height - cellSize * rows) / 2;
  80. // 创建一个 QPixmap 对象用于保存绘制的图像
  81. globalPixmap = QPixmap(width, height);
  82. globalPixmap.fill(Qt::white); // 填充背景色为白色
  83. // 创建 QPainter 以绘制到 QPixmap 上
  84. QPainter painter(&globalPixmap);
  85. painter.setRenderHint(QPainter::Antialiasing); // 启用抗锯齿
  86. // 设置画笔为无边框
  87. painter.setPen(Qt::NoPen);
  88. // 绘制每个晶圆点
  89. for (int i = 0; i < waferData.size(); ++i) {
  90. int x = offsetX + waferData[i].nDieCol * cellSize;
  91. int y = offsetY + waferData[i].nDieRow * cellSize;
  92. // 根据点的状态设置颜色
  93. painter.setBrush(getColorByStatus(waferData[i].eStatus));
  94. // 绘制晶圆点(每个点是一个矩形)
  95. painter.drawRect(x, y, cellSize, cellSize);
  96. }
  97. // 根据角度绘制黑点
  98. int centerX, centerY;
  99. int angle = 0;
  100. switch (angle) {
  101. case 0: {
  102. centerX = offsetX + (cols / 2) * cellSize;
  103. centerY = offsetY + (rows - 1) * cellSize;
  104. break;
  105. }
  106. case 90: {
  107. centerX = offsetX;
  108. centerY = offsetY + (rows / 2) * cellSize;
  109. break;
  110. }
  111. case 180: {
  112. centerX = offsetX + (cols / 2) * cellSize;
  113. centerY = offsetY;
  114. break;
  115. }
  116. case 270: {
  117. centerX = offsetX + (cols - 1) * cellSize;
  118. centerY = offsetY + (rows / 2) * cellSize;
  119. break;
  120. }
  121. default:
  122. return;
  123. }
  124. painter.setBrush(Qt::black);
  125. painter.drawEllipse(centerX - 3, centerY - 3, 6, 6);
  126. painter.end(); // 结束绘制
  127. }
  128. void Wafer::initFrom(QWidget *parent) {
  129. scene = new QGraphicsScene(parent);
  130. view = new WaferGraphicsView(scene);
  131. // 获取当前窗口的宽高
  132. int width = parent->width();
  133. int height = parent->height();
  134. // 根据行列数计算每个晶圆点的大小,选择小的边来决定
  135. int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
  136. for (int i = 0; i < waferData.size(); ++i) {
  137. DieItem* die = new DieItem(waferData[i].nDieRow, waferData[i].nDieCol, waferData[i].eStatus, cellSize);
  138. die->setPos(waferData[i].nDieCol * cellSize, waferData[i].nDieRow * cellSize);
  139. scene->addItem(die);
  140. }
  141. view->setSceneRect(scene->itemsBoundingRect());
  142. view->resize(width, height);
  143. }
  144. QPixmap Wafer::getGlobalPixmap() const {
  145. return globalPixmap;
  146. }