123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- #include "Wafer.h"
- #include <QPainter>
- #include <QPaintEvent>
- #include <cmath>
- #include <QDebug>
- #include <QPushButton>
- #include <QGridLayout>
- #include "ImageWidget.h"
- Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) {
-
- }
- void Wafer::UpdataGenerateTestData()
- {
- /*
- Flag = 0;
- 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
- ns_mat::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 = ns_mat::PICK_DIE_STATUS::EDGE_DIE; // 如果在边缘区域,状态设置为EDGE_DIE
- }
- else {
- // 如果在圆形区域内,随机设置其他状态
- int randomStatus = std::rand() % 4; // 随机选取DIE_EXIST, PICK_ING, NO_EXIST, SKIP_DIE
- point.eStatus = static_cast<ns_mat::PICK_DIE_STATUS>(randomStatus);
- }
- // 将点添加到waferData容器中
- waferData.append(point);
- }
- }
- */
- }
- void Wafer::UpdataVal(const std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT>& veWafer)
- {
- int currentDieMatrixId = veWafer[0].nDieMatrixId;
- int rowMax = veWafer[0].nDieRow;
- int colsMax = veWafer[0].nDieCol;
- double minx = veWafer[0].stPosition.x;
- double miny = veWafer[0].stPosition.y;
- double maxx = veWafer[0].stPosition.x;
- double maxy = veWafer[0].stPosition.y;
- for (const auto a : veWafer)
- {
- waferData.append(a);
- qDebug() << a.stPosition.x << " " << a.stPosition.y;
- if (a.nDieMatrixId != currentDieMatrixId) {
- maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
- currentDieMatrixId = a.nDieMatrixId;
- rowMax = a.nDieRow;
- colsMax = a.nDieCol;
- minx = a.stPosition.x;
- maxx = a.stPosition.x;
- miny = a.stPosition.y;
- maxy = a.stPosition.y;
- }
- else {
- if (a.nDieRow >= rowMax) rowMax = a.nDieRow;
- if (a.nDieCol >= colsMax) colsMax = a.nDieCol;
- if (a.stPosition.x >= maxx) maxx = a.stPosition.x;
- if (a.stPosition.y >= maxy) maxy = a.stPosition.y;
- if (a.stPosition.x <= minx) minx = a.stPosition.x;
- if (a.stPosition.y <= miny) miny = a.stPosition.y;
- }
- }
- maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
- }
- QColor Wafer::getColorByStatus(ns_mat::PICK_DIE_STATUS status) {
- switch (status) {
- case ns_mat::PICK_DIE_STATUS::DIE_EXIST: return QColor(0, 102, 255); // 蓝色
- case ns_mat::PICK_DIE_STATUS::NO_EXIST: return QColor(200, 200, 200); // 浅灰
- case ns_mat::PICK_DIE_STATUS::PICK_ING: return QColor(255, 255, 0); // 黄色
- case ns_mat::PICK_DIE_STATUS::SKIP_DIE: return QColor(128, 128, 128); // 深灰
- case ns_mat::PICK_DIE_STATUS::EDGE_DIE: return QColor(255, 165, 0); // 橙色
- default: return QColor(0, 0, 0); // 默认黑色
- }
- }
- void Wafer::paintInitFrom(QWidget *parent) {
- /*
- // 获取当前窗口的宽高
- double width, height;
- width = 493;
- height = 493;
- ImageWidget* Operatewidget;
- Operatewidget = new ImageWidget();
-
- Operatewidget->setGeometry(QRect(0, 0, 493, 493));
- // 创建视图
- scene = new QGraphicsScene(Operatewidget);
- view = new WaferGraphicsView(scene);
- //cene->setSceneRect(0, 0, 493, 493);
- view->resize(width, height);
- view->setCViewInterface(m_pCViewInterface);
- //获取当前角度
- double angle;
- m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
- QPointF center(width / 2.0, height / 2.0);
- QPointF pointf(m_centerX, m_centerY);
- double radius = width / 2 - 10;
- //比例
- double radio = m_radius / radius;
- int dieLong = m_dieLong / radio;
- int dieWide = m_dieWide / radio;
- //test 实际使用时需要删除或注释
- angle = 0.00;
- // 初始化晶圆参数
- view->initWafer(center, // 中心坐标
- radius, // 半径
- dieLong, dieWide, angle); // 固晶点显示尺寸
- // 添加固晶点
- int currentDieMatrixId = -1;
- double referPointX = 0.0;
- double referPointY = 0.0;
- MaxRow_Col maxRow_Col;
- double minx, miny, maxx, maxy, widthMatrix, heightMatrix;
- for (int i = 0; i < waferData.size(); ++i) {
- //判断是否属于同一个矩阵
- if (waferData[i].nDieMatrixId != currentDieMatrixId) {
- //重新画矩阵框然后配置新的参考点
- currentDieMatrixId = waferData[i].nDieMatrixId;
- referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
- referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
- maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
- minx = center.x() + (maxRow_Col.minX - m_centerX) / radio - 20;
- miny = center.y() - (maxRow_Col.minY - m_centerY) / radio + 20;
- maxx = center.x() + (maxRow_Col.maxX - m_centerX) / radio + 20;
- maxy = center.y() - (maxRow_Col.maxY - m_centerY) / radio - 20;
- widthMatrix = maxx - minx;
- heightMatrix = miny - maxy;
- view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
- }
- referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
- referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
- view->addDiePoint(QPointF(referPointX, referPointY), waferData[i]);
- }
- scene->setSceneRect(0, 0, view->width(), view->height());
- int cur_width, cur_height;
- cur_width = parent->width();
- cur_height = parent->height();
- // 创建一个 QPixmap 对象用于保存绘制的图像
- globalPixmap = QPixmap(cur_width, cur_height);
- globalPixmap.fill(Qt::white); // 填充背景色为白色
- QPixmap originalPixmap = QPixmap::grabWidget(view);
- // 设置目标尺寸
- QSize targetSize(cur_width, cur_height);
- // 不保持比例,直接拉伸到指定尺寸
- QPixmap scaledPixmap = originalPixmap.scaled(
- targetSize,
- Qt::IgnoreAspectRatio,
- Qt::SmoothTransformation
- );
- globalPixmap = scaledPixmap;
- */
- }
- void Wafer::initFrom(QWidget* parent) {
- // 获取当前窗口的宽高
- double width, height;
- if (parent == nullptr) {
- width = 493;
- height = 493;
- }
- else {
- width = parent->width();
- height = parent->height();
- }
-
- // 创建视图
- scene = new QGraphicsScene(parent);
- view = new WaferGraphicsView(scene);
- view->resize(width, height);
- view->setCViewInterface(m_pCViewInterface);
- //获取当前角度
- double angle;
- m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
- QPointF center(width / 2.0, height / 2.0);
- QPointF pointf(m_centerX, m_centerY);
- double radius = width / 2 - 10;
- //比例
- double radio = m_radius / radius;
- int dieLong = m_dieLong / radio;
- int dieWide = m_dieWide / radio;
- //test 实际使用时需要删除或注释
- angle = 0.00;
- // 初始化晶圆参数
- view->initWafer(center, // 中心坐标
- radius, // 半径
- dieLong, dieWide,angle); // 固晶点显示尺寸
- // 添加固晶点
- int currentDieMatrixId = -1;
- double referPointX = 0.0;
- double referPointY = 0.0;
- MaxRow_Col maxRow_Col;
- double minx, miny,maxx,maxy, widthMatrix, heightMatrix;
- for (int i = 0; i < waferData.size(); ++i) {
- //判断是否属于同一个矩阵
- if (waferData[i].nDieMatrixId != currentDieMatrixId) {
- //重新画矩阵框然后配置新的参考点
- currentDieMatrixId = waferData[i].nDieMatrixId;
- referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
- referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
- maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
- minx = center.x()+(maxRow_Col.minX - m_centerX) / radio - 20;
- miny = center.y() - (maxRow_Col.minY - m_centerY) / radio + 20;
- maxx = center.x() + (maxRow_Col.maxX - m_centerX) / radio + 20;
- maxy = center.y() - (maxRow_Col.maxY - m_centerY) / radio - 20;
- widthMatrix = maxx - minx;
- heightMatrix = miny - maxy;
- view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
- }
- referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
- referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
- view->addDiePoint(QPointF(referPointX, referPointY),waferData[i]);
- }
- scene->setSceneRect(0, 0, view->width(), view->height());
- // 创建一个 QPixmap 对象用于保存绘制的图像
- globalPixmap = QPixmap(width, height);
- globalPixmap.fill(Qt::white); // 填充背景色为白色
- QPixmap originalPixmap = QPixmap::grabWidget(view);
- // 设置目标尺寸(例如:宽度 200,高度 150)
- QSize targetSize(width, height);
- // 不保持比例,直接拉伸到指定尺寸
- QPixmap scaledPixmap = originalPixmap.scaled(
- targetSize,
- Qt::IgnoreAspectRatio,
- Qt::SmoothTransformation
- );
- globalPixmap = scaledPixmap;
-
-
- }
- QPixmap Wafer::getGlobalPixmap() const {
- return globalPixmap;
- }
- void Wafer::setWaferInfo(ns_module::CViewInterface* CViewInterface) {
- m_pCViewInterface = CViewInterface;
- long result = m_pCViewInterface->GetViewMatrix()->GetDieSize(m_dieLong,m_dieWide);
- m_pCViewInterface->GetViewMatrix()->GetWaferSize(m_centerX, m_centerY,m_radius);
- //这里到时候更新接口时替换真实圆心点的数据
- /*m_dieLong = 10;
- m_dieWide = 10;*/
- m_radius = 10000;
- m_centerX = 0;
- m_centerY = 0;
- }
|