Wafer.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "Wafer.h"
  2. #include <QPainter>
  3. #include <QPaintEvent>
  4. #include <cmath>
  5. Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) {
  6. waferData = {
  7. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  8. {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
  9. {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  10. {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  11. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  12. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  13. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  14. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  15. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  16. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  17. {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0},
  18. {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0},
  19. {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0},
  20. {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0},
  21. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  22. };
  23. // 根据不同窗口设置不同大小 0:小 1:中 2:大
  24. if (flag == 0) {
  25. num = 9;
  26. } else if (flag == 1) {
  27. num = 15;
  28. } else if (flag == 2) {
  29. num = 21;
  30. }
  31. }
  32. void Wafer::paintEvent(QPaintEvent *event) {
  33. QPainter painter(this);
  34. // 抗锯齿效果
  35. painter.setRenderHint(QPainter::Antialiasing);
  36. // 绘制背景
  37. painter.fillRect(this->rect(), Qt::white);
  38. // 定义晶圆的整体圆形
  39. int diameter = qMin(width(), height()) - num; // 确保圆形不会超出窗口边界
  40. int centerX = width() / 2;
  41. int centerY = height() / 2;
  42. QRect waferRect(centerX - diameter / 2, centerY - diameter / 2, diameter, diameter);
  43. // 绘制晶圆圆形边界
  44. painter.setPen(Qt::gray);
  45. painter.drawEllipse(waferRect);
  46. // 绘制二维数组表示的晶圆图案
  47. int rows = waferData.size();
  48. int cols = waferData[0].size();
  49. int cellSize = diameter / qMax(rows, cols); // 根据晶圆大小动态调整单元格大小
  50. int radiusSquared = (diameter / 2) * (diameter / 2);
  51. for (int i = 0; i < rows; ++i) {
  52. for (int j = 0; j < cols; ++j) {
  53. if (waferData[i][j] == 1) { // 如果格点状态为 1,则填充颜色
  54. int x = centerX - diameter / 2 + j * cellSize;
  55. int y = centerY - diameter / 2 + i * cellSize;
  56. QRect cellRect(x, y, cellSize, cellSize);
  57. // 判断是否在圆形范围内
  58. int distanceSquared = pow(x + cellSize / 2 - centerX, 2) + pow(y + cellSize / 2 - centerY, 2);
  59. if (distanceSquared <= radiusSquared) {
  60. painter.fillRect(cellRect, Qt::blue);
  61. // 绘制边框
  62. painter.setPen(Qt::gray);
  63. painter.drawRect(cellRect);
  64. }
  65. }
  66. }
  67. }
  68. }