123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #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 point;
- point.nDieMatrixId = 1;
- point.nDieRow = row;
- point.nDieCol = col;
- point.iDieIndex = row * cols + col;
- 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;
- } else {
-
- int randomStatus = std::rand() % 4;
- point.eStatus = static_cast<PICK_DIE_STATUS>(randomStatus);
- }
-
- 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;
-
- globalPixmap = QPixmap(width, height);
- globalPixmap.fill(Qt::white);
-
- 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;
- }
|