#include "Wafer.h" #include #include #include Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) { waferData = { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}, {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0}, {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0}, {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }; // 根据不同窗口设置不同大小 0:小 1:中 2:大 if (flag == 0) { num = 9; } else if (flag == 1) { num = 15; } else if (flag == 2) { num = 21; } } void Wafer::paintEvent(QPaintEvent *event) { QPainter painter(this); // 抗锯齿效果 painter.setRenderHint(QPainter::Antialiasing); // 绘制背景 painter.fillRect(this->rect(), Qt::white); // 定义晶圆的整体圆形 int diameter = qMin(width(), height()) - num; // 确保圆形不会超出窗口边界 int centerX = width() / 2; int centerY = height() / 2; QRect waferRect(centerX - diameter / 2, centerY - diameter / 2, diameter, diameter); // 绘制晶圆圆形边界 painter.setPen(Qt::gray); painter.drawEllipse(waferRect); // 绘制二维数组表示的晶圆图案 int rows = waferData.size(); int cols = waferData[0].size(); int cellSize = diameter / qMax(rows, cols); // 根据晶圆大小动态调整单元格大小 int radiusSquared = (diameter / 2) * (diameter / 2); for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { if (waferData[i][j] == 1) { // 如果格点状态为 1,则填充颜色 int x = centerX - diameter / 2 + j * cellSize; int y = centerY - diameter / 2 + i * cellSize; QRect cellRect(x, y, cellSize, cellSize); // 判断是否在圆形范围内 int distanceSquared = pow(x + cellSize / 2 - centerX, 2) + pow(y + cellSize / 2 - centerY, 2); if (distanceSquared <= radiusSquared) { painter.fillRect(cellRect, Qt::blue); // 绘制边框 painter.setPen(Qt::gray); painter.drawRect(cellRect); } } } } }