Wafer.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #include "Wafer.h"
  2. #include <QPainter>
  3. #include <QPaintEvent>
  4. #include <cmath>
  5. #include <QDebug>
  6. #include <QPushButton>
  7. #include <QGridLayout>
  8. #include "ImageWidget.h"
  9. Wafer::Wafer(int flag, QWidget *parent) : QWidget(parent) {
  10. }
  11. void Wafer::UpdataGenerateTestData()
  12. {
  13. /*
  14. Flag = 0;
  15. rows = 51;
  16. cols = 51;
  17. centerX = 25;
  18. centerY = 25;
  19. radius = 25;
  20. // 随机数初始化
  21. std::srand(std::time(nullptr)); // 使用当前时间作为种子
  22. // 遍历矩阵,按行列判断是否在圆形区域内
  23. for (int row = 0; row < rows; ++row) {
  24. for (int col = 0; col < cols; ++col) {
  25. // 计算当前点到中心点的距离
  26. double dx = col - centerX;
  27. double dy = row - centerY;
  28. double distance = std::sqrt(dx * dx + dy * dy);
  29. // 如果点在圆形区域外部,跳过
  30. if (distance > radius) {
  31. continue;
  32. }
  33. // 创建一个新的WAFER_MATRIX_POINT_INFO_STRUCT
  34. ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT point;
  35. point.nDieMatrixId = 1; // 假设所有点属于同一晶圆矩阵
  36. point.nDieRow = row;
  37. point.nDieCol = col;
  38. point.iDieIndex = row * cols + col; // 假设ID为行列号的线性映射
  39. point.bDisable = false; // 默认为可用
  40. point.stPosition.x = col * 10.0;
  41. point.stPosition.y = row * 10.0;
  42. // 判断该点是否在圆形区域的边缘
  43. if (distance > radius - 1 && distance < radius + 1) {
  44. point.eStatus = ns_mat::PICK_DIE_STATUS::EDGE_DIE; // 如果在边缘区域,状态设置为EDGE_DIE
  45. }
  46. else {
  47. // 如果在圆形区域内,随机设置其他状态
  48. int randomStatus = std::rand() % 4; // 随机选取DIE_EXIST, PICK_ING, NO_EXIST, SKIP_DIE
  49. point.eStatus = static_cast<ns_mat::PICK_DIE_STATUS>(randomStatus);
  50. }
  51. // 将点添加到waferData容器中
  52. waferData.append(point);
  53. }
  54. }
  55. */
  56. }
  57. void Wafer::UpdataVal(const std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT>& veWafer)
  58. {
  59. int currentDieMatrixId = veWafer[0].nDieMatrixId;
  60. int rowMax = veWafer[0].nDieRow;
  61. int colsMax = veWafer[0].nDieCol;
  62. double minx = veWafer[0].stPosition.x;
  63. double miny = veWafer[0].stPosition.y;
  64. double maxx = veWafer[0].stPosition.x;
  65. double maxy = veWafer[0].stPosition.y;
  66. for (const auto a : veWafer)
  67. {
  68. waferData.append(a);
  69. qDebug() << a.stPosition.x << " " << a.stPosition.y;
  70. if (a.nDieMatrixId != currentDieMatrixId) {
  71. maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
  72. currentDieMatrixId = a.nDieMatrixId;
  73. rowMax = a.nDieRow;
  74. colsMax = a.nDieCol;
  75. minx = a.stPosition.x;
  76. maxx = a.stPosition.x;
  77. miny = a.stPosition.y;
  78. maxy = a.stPosition.y;
  79. }
  80. else {
  81. if (a.nDieRow >= rowMax) rowMax = a.nDieRow;
  82. if (a.nDieCol >= colsMax) colsMax = a.nDieCol;
  83. if (a.stPosition.x >= maxx) maxx = a.stPosition.x;
  84. if (a.stPosition.y >= maxy) maxy = a.stPosition.y;
  85. if (a.stPosition.x <= minx) minx = a.stPosition.x;
  86. if (a.stPosition.y <= miny) miny = a.stPosition.y;
  87. }
  88. }
  89. maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
  90. }
  91. QColor Wafer::getColorByStatus(ns_mat::PICK_DIE_STATUS status) {
  92. switch (status) {
  93. case ns_mat::PICK_DIE_STATUS::DIE_EXIST: return QColor(0, 102, 255); // 蓝色
  94. case ns_mat::PICK_DIE_STATUS::NO_EXIST: return QColor(200, 200, 200); // 浅灰
  95. case ns_mat::PICK_DIE_STATUS::PICK_ING: return QColor(255, 255, 0); // 黄色
  96. case ns_mat::PICK_DIE_STATUS::SKIP_DIE: return QColor(128, 128, 128); // 深灰
  97. case ns_mat::PICK_DIE_STATUS::EDGE_DIE: return QColor(255, 165, 0); // 橙色
  98. default: return QColor(0, 0, 0); // 默认黑色
  99. }
  100. }
  101. void Wafer::paintInitFrom(QWidget *parent) {
  102. /*
  103. // 获取当前窗口的宽高
  104. double width, height;
  105. width = 493;
  106. height = 493;
  107. ImageWidget* Operatewidget;
  108. Operatewidget = new ImageWidget();
  109. Operatewidget->setGeometry(QRect(0, 0, 493, 493));
  110. // 创建视图
  111. scene = new QGraphicsScene(Operatewidget);
  112. view = new WaferGraphicsView(scene);
  113. //cene->setSceneRect(0, 0, 493, 493);
  114. view->resize(width, height);
  115. view->setCViewInterface(m_pCViewInterface);
  116. //获取当前角度
  117. double angle;
  118. m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
  119. QPointF center(width / 2.0, height / 2.0);
  120. QPointF pointf(m_centerX, m_centerY);
  121. double radius = width / 2 - 10;
  122. //比例
  123. double radio = m_radius / radius;
  124. int dieLong = m_dieLong / radio;
  125. int dieWide = m_dieWide / radio;
  126. //test 实际使用时需要删除或注释
  127. angle = 0.00;
  128. // 初始化晶圆参数
  129. view->initWafer(center, // 中心坐标
  130. radius, // 半径
  131. dieLong, dieWide, angle); // 固晶点显示尺寸
  132. // 添加固晶点
  133. int currentDieMatrixId = -1;
  134. double referPointX = 0.0;
  135. double referPointY = 0.0;
  136. MaxRow_Col maxRow_Col;
  137. double minx, miny, maxx, maxy, widthMatrix, heightMatrix;
  138. for (int i = 0; i < waferData.size(); ++i) {
  139. //判断是否属于同一个矩阵
  140. if (waferData[i].nDieMatrixId != currentDieMatrixId) {
  141. //重新画矩阵框然后配置新的参考点
  142. currentDieMatrixId = waferData[i].nDieMatrixId;
  143. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
  144. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
  145. maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
  146. minx = center.x() + (maxRow_Col.minX - m_centerX) / radio - 20;
  147. miny = center.y() - (maxRow_Col.minY - m_centerY) / radio + 20;
  148. maxx = center.x() + (maxRow_Col.maxX - m_centerX) / radio + 20;
  149. maxy = center.y() - (maxRow_Col.maxY - m_centerY) / radio - 20;
  150. widthMatrix = maxx - minx;
  151. heightMatrix = miny - maxy;
  152. view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
  153. }
  154. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
  155. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
  156. view->addDiePoint(QPointF(referPointX, referPointY), waferData[i]);
  157. }
  158. scene->setSceneRect(0, 0, view->width(), view->height());
  159. int cur_width, cur_height;
  160. cur_width = parent->width();
  161. cur_height = parent->height();
  162. // 创建一个 QPixmap 对象用于保存绘制的图像
  163. globalPixmap = QPixmap(cur_width, cur_height);
  164. globalPixmap.fill(Qt::white); // 填充背景色为白色
  165. QPixmap originalPixmap = QPixmap::grabWidget(view);
  166. // 设置目标尺寸
  167. QSize targetSize(cur_width, cur_height);
  168. // 不保持比例,直接拉伸到指定尺寸
  169. QPixmap scaledPixmap = originalPixmap.scaled(
  170. targetSize,
  171. Qt::IgnoreAspectRatio,
  172. Qt::SmoothTransformation
  173. );
  174. globalPixmap = scaledPixmap;
  175. */
  176. }
  177. void Wafer::initFrom(QWidget* parent) {
  178. // 获取当前窗口的宽高
  179. double width, height;
  180. if (parent == nullptr) {
  181. width = 493;
  182. height = 493;
  183. }
  184. else {
  185. width = parent->width();
  186. height = parent->height();
  187. }
  188. // 创建视图
  189. scene = new QGraphicsScene(parent);
  190. view = new WaferGraphicsView(scene);
  191. view->resize(width, height);
  192. view->setCViewInterface(m_pCViewInterface);
  193. //获取当前角度
  194. double angle;
  195. m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
  196. QPointF center(width / 2.0, height / 2.0);
  197. QPointF pointf(m_centerX, m_centerY);
  198. double radius = width / 2 - 10;
  199. //比例
  200. double radio = m_radius / radius;
  201. int dieLong = m_dieLong / radio;
  202. int dieWide = m_dieWide / radio;
  203. //test 实际使用时需要删除或注释
  204. angle = 0.00;
  205. // 初始化晶圆参数
  206. view->initWafer(center, // 中心坐标
  207. radius, // 半径
  208. dieLong, dieWide,angle); // 固晶点显示尺寸
  209. // 添加固晶点
  210. int currentDieMatrixId = -1;
  211. double referPointX = 0.0;
  212. double referPointY = 0.0;
  213. MaxRow_Col maxRow_Col;
  214. double minx, miny,maxx,maxy, widthMatrix, heightMatrix;
  215. for (int i = 0; i < waferData.size(); ++i) {
  216. //判断是否属于同一个矩阵
  217. if (waferData[i].nDieMatrixId != currentDieMatrixId) {
  218. //重新画矩阵框然后配置新的参考点
  219. currentDieMatrixId = waferData[i].nDieMatrixId;
  220. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
  221. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
  222. maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
  223. minx = center.x()+(maxRow_Col.minX - m_centerX) / radio - 20;
  224. miny = center.y() - (maxRow_Col.minY - m_centerY) / radio + 20;
  225. maxx = center.x() + (maxRow_Col.maxX - m_centerX) / radio + 20;
  226. maxy = center.y() - (maxRow_Col.maxY - m_centerY) / radio - 20;
  227. widthMatrix = maxx - minx;
  228. heightMatrix = miny - maxy;
  229. view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
  230. }
  231. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / radio;
  232. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / radio;
  233. view->addDiePoint(QPointF(referPointX, referPointY),waferData[i]);
  234. }
  235. scene->setSceneRect(0, 0, view->width(), view->height());
  236. // 创建一个 QPixmap 对象用于保存绘制的图像
  237. globalPixmap = QPixmap(width, height);
  238. globalPixmap.fill(Qt::white); // 填充背景色为白色
  239. QPixmap originalPixmap = QPixmap::grabWidget(view);
  240. // 设置目标尺寸(例如:宽度 200,高度 150)
  241. QSize targetSize(width, height);
  242. // 不保持比例,直接拉伸到指定尺寸
  243. QPixmap scaledPixmap = originalPixmap.scaled(
  244. targetSize,
  245. Qt::IgnoreAspectRatio,
  246. Qt::SmoothTransformation
  247. );
  248. globalPixmap = scaledPixmap;
  249. }
  250. QPixmap Wafer::getGlobalPixmap() const {
  251. return globalPixmap;
  252. }
  253. void Wafer::setWaferInfo(ns_module::CViewInterface* CViewInterface) {
  254. m_pCViewInterface = CViewInterface;
  255. long result = m_pCViewInterface->GetViewMatrix()->GetDieSize(m_dieLong,m_dieWide);
  256. m_pCViewInterface->GetViewMatrix()->GetWaferSize(m_centerX, m_centerY,m_radius);
  257. //这里到时候更新接口时替换真实圆心点的数据
  258. /*m_dieLong = 10;
  259. m_dieWide = 10;*/
  260. m_radius = 10000;
  261. m_centerX = 0;
  262. m_centerY = 0;
  263. }