123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- #include "Wafer.h"
- #include <QPainter>
- #include <QPaintEvent>
- #include <cmath>
- #include <QDebug>
- #include <QPushButton>
- #include <QGridLayout>
- Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) {
- Flag = flag;
- rows = 51;
- cols = 51;
- centerX = 25;
- centerY = 25;
- radius = 25;
- // 随机数初始化
- std::srand(std::time(nullptr)); // 使用当前时间作为种子
- // 遍历矩阵,按行列判断是否在圆形区域内
- for (int row = 0; row < rows; ++row) {
- for (int col = 0; col < cols; ++col) {
- // 计算当前点到中心点的距离
- double dx = col - centerX;
- double dy = row - centerY;
- double distance = std::sqrt(dx * dx + dy * dy);
- // 如果点在圆形区域外部,跳过
- if (distance > radius) {
- continue;
- }
- // 创建一个新的WAFER_MATRIX_POINT_INFO_STRUCT
- WAFER_MATRIX_POINT_INFO_STRUCT point;
- point.nDieMatrixId = 1; // 假设所有点属于同一晶圆矩阵
- point.nDieRow = row;
- point.nDieCol = col;
- point.iDieIndex = row * cols + col; // 假设ID为行列号的线性映射
- point.bDisable = false; // 默认为可用
- point.stPosition.x = col * 10.0;
- point.stPosition.y = row * 10.0;
- // 判断该点是否在圆形区域的边缘
- if (distance > radius - 1 && distance < radius + 1) {
- point.eStatus = EDGE_DIE; // 如果在边缘区域,状态设置为EDGE_DIE
- } else {
- // 如果在圆形区域内,随机设置其他状态
- int randomStatus = std::rand() % 4; // 随机选取DIE_EXIST, PICK_ING, NO_EXIST, SKIP_DIE
- point.eStatus = static_cast<PICK_DIE_STATUS>(randomStatus);
- }
- // 将点添加到waferData容器中
- waferData.append(point);
- }
- }
- }
- QColor Wafer::getColorByStatus(PICK_DIE_STATUS status) {
- switch (status) {
- case DIE_EXIST: return QColor(0, 102, 255); // 蓝色
- case NO_EXIST: return QColor(200, 200, 200); // 浅灰
- case PICK_ING: return QColor(255, 255, 0); // 黄色
- case SKIP_DIE: return QColor(128, 128, 128); // 深灰
- case EDGE_DIE: return QColor(255, 165, 0); // 橙色
- default: return QColor(0, 0, 0); // 默认黑色
- }
- }
- void Wafer::paintInitFrom(QWidget *parent) {
- // 获取当前窗口的宽高
- int width = parent->width();
- int height = parent->height();
- // 根据行列数计算每个晶圆点的大小,选择小的边来决定
- int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
- // 计算左上角偏移量,居中显示
- int offsetX = (width - cellSize * cols) / 2;
- int offsetY = (height - cellSize * rows) / 2;
- // 创建一个 QPixmap 对象用于保存绘制的图像
- globalPixmap = QPixmap(width, height);
- globalPixmap.fill(Qt::white); // 填充背景色为白色
- // 创建 QPainter 以绘制到 QPixmap 上
- QPainter painter(&globalPixmap);
- painter.setRenderHint(QPainter::Antialiasing); // 启用抗锯齿
- // 设置画笔为无边框
- painter.setPen(Qt::NoPen);
- // 绘制每个晶圆点
- for (int i = 0; i < waferData.size(); ++i) {
- int x = offsetX + waferData[i].nDieCol * cellSize;
- int y = offsetY + waferData[i].nDieRow * cellSize;
- // 根据点的状态设置颜色
- painter.setBrush(getColorByStatus(waferData[i].eStatus));
- // 绘制晶圆点(每个点是一个矩形)
- painter.drawRect(x, y, cellSize, cellSize);
- }
- // 根据角度绘制黑点
- int centerX, centerY;
- int angle = 0;
- switch (angle) {
- case 0: {
- centerX = offsetX + (cols / 2) * cellSize;
- centerY = offsetY + (rows - 1) * cellSize;
- break;
- }
- case 90: {
- centerX = offsetX;
- centerY = offsetY + (rows / 2) * cellSize;
- break;
- }
- case 180: {
- centerX = offsetX + (cols / 2) * cellSize;
- centerY = offsetY;
- break;
- }
- case 270: {
- centerX = offsetX + (cols - 1) * cellSize;
- centerY = offsetY + (rows / 2) * cellSize;
- break;
- }
- default:
- return;
- }
- painter.setBrush(Qt::black);
- painter.drawEllipse(centerX - 3, centerY - 3, 6, 6);
- painter.end(); // 结束绘制
- }
- void Wafer::initFrom(QWidget *parent) {
- scene = new QGraphicsScene(parent);
- view = new WaferGraphicsView(scene);
- // 获取当前窗口的宽高
- int width = parent->width();
- int height = parent->height();
- // 根据行列数计算每个晶圆点的大小,选择小的边来决定
- int cellSize = qMin(width, height) / qMax(rows, cols); // 固定大小为正方形,按最小边计算
- for (int i = 0; i < waferData.size(); ++i) {
- DieItem* die = new DieItem(waferData[i].nDieRow, waferData[i].nDieCol, waferData[i].eStatus, cellSize);
- die->setPos(waferData[i].nDieCol * cellSize, waferData[i].nDieRow * cellSize);
- scene->addItem(die);
- }
- view->setSceneRect(scene->itemsBoundingRect());
- view->resize(width, height);
- }
- QPixmap Wafer::getGlobalPixmap() const {
- return globalPixmap;
- }
- void Wafer::showContextMenu(const QPoint &pos) {
- if (!contextMenu) {
- contextMenu = new QMenu(this);
- // 创建菜单项
- QAction *action1 = new QAction("菜单项 1", this);
- QAction *action2 = new QAction("菜单项 2", this);
- // 将菜单项添加到菜单
- contextMenu->addAction(action1);
- contextMenu->addAction(action2);
- // 连接菜单项的信号到槽函数
- connect(action1, &QAction::triggered, this, &Wafer::handleAction1);
- connect(action2, &QAction::triggered, this, &Wafer::handleAction2);
- }
- // 显示菜单
- contextMenu->exec(QCursor::pos());
- }
- void Wafer::handleAction1() {
- // 处理菜单项 1 的逻辑
- qDebug() << "菜单项 1 被点击";
- }
- void Wafer::handleAction2() {
- // 处理菜单项 2 的逻辑
- qDebug() << "菜单项 2 被点击";
- }
|