Wafer.cpp 11 KB

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