Wafer.cpp 5.2 KB

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