Wafer.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. waferData.clear();
  60. int currentDieMatrixId = veWafer[0].nDieMatrixId;
  61. int rowMax = veWafer[0].nDieRow;
  62. int colsMax = veWafer[0].nDieCol;
  63. double minx = veWafer[0].stPosition.x;
  64. double miny = veWafer[0].stPosition.y;
  65. double maxx = veWafer[0].stPosition.x;
  66. double maxy = veWafer[0].stPosition.y;
  67. for (const auto a : veWafer)
  68. {
  69. waferData.append(a);
  70. qDebug() << a.stPosition.x << " " << a.stPosition.y;
  71. if (a.nDieMatrixId != currentDieMatrixId) {
  72. maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
  73. currentDieMatrixId = a.nDieMatrixId;
  74. rowMax = a.nDieRow;
  75. colsMax = a.nDieCol;
  76. minx = a.stPosition.x;
  77. maxx = a.stPosition.x;
  78. miny = a.stPosition.y;
  79. maxy = a.stPosition.y;
  80. }
  81. else {
  82. if (a.nDieRow >= rowMax) rowMax = a.nDieRow;
  83. if (a.nDieCol >= colsMax) colsMax = a.nDieCol;
  84. if (a.stPosition.x >= maxx) maxx = a.stPosition.x;
  85. if (a.stPosition.y >= maxy) maxy = a.stPosition.y;
  86. if (a.stPosition.x <= minx) minx = a.stPosition.x;
  87. if (a.stPosition.y <= miny) miny = a.stPosition.y;
  88. }
  89. }
  90. maxRow_Colmap.insert(currentDieMatrixId, { rowMax ,colsMax,minx,miny,maxx,maxy });
  91. }
  92. QColor Wafer::getColorByStatus(ns_mat::PICK_DIE_STATUS status) {
  93. switch (status) {
  94. case ns_mat::PICK_DIE_STATUS::DIE_EXIST: return QColor(0, 102, 255); // 蓝色
  95. case ns_mat::PICK_DIE_STATUS::NO_EXIST: return QColor(200, 200, 200); // 浅灰
  96. case ns_mat::PICK_DIE_STATUS::PICK_ING: return QColor(255, 255, 0); // 黄色
  97. case ns_mat::PICK_DIE_STATUS::SKIP_DIE: return QColor(128, 128, 128); // 深灰
  98. case ns_mat::PICK_DIE_STATUS::EDGE_DIE: return QColor(255, 165, 0); // 橙色
  99. default: return QColor(0, 0, 0); // 默认黑色
  100. }
  101. }
  102. void Wafer::paintInitFrom(QWidget *parent) {
  103. /*
  104. // 获取当前窗口的宽高
  105. double width, height;
  106. width = 493;
  107. height = 493;
  108. ImageWidget* Operatewidget;
  109. Operatewidget = new ImageWidget();
  110. Operatewidget->setGeometry(QRect(0, 0, 493, 493));
  111. // 创建视图
  112. scene = new QGraphicsScene(Operatewidget);
  113. view = new WaferGraphicsView(scene);
  114. //cene->setSceneRect(0, 0, 493, 493);
  115. view->resize(width, height);
  116. view->setCViewInterface(m_pCViewInterface);
  117. //获取当前角度
  118. double angle;
  119. m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
  120. QPointF center(width / 2.0, height / 2.0);
  121. QPointF pointf(m_centerX, m_centerY);
  122. double radius = width / 2 - 10;
  123. //比例
  124. double ratio = m_radius / radius;
  125. int dieLong = m_dieLong / ratio;
  126. int dieWide = m_dieWide / ratio;
  127. //test 实际使用时需要删除或注释
  128. angle = 0.00;
  129. // 初始化晶圆参数
  130. view->initWafer(center, // 中心坐标
  131. radius, // 半径
  132. dieLong, dieWide, angle); // 固晶点显示尺寸
  133. // 添加固晶点
  134. int currentDieMatrixId = -1;
  135. double referPointX = 0.0;
  136. double referPointY = 0.0;
  137. MaxRow_Col maxRow_Col;
  138. double minx, miny, maxx, maxy, widthMatrix, heightMatrix;
  139. for (int i = 0; i < waferData.size(); ++i) {
  140. //判断是否属于同一个矩阵
  141. if (waferData[i].nDieMatrixId != currentDieMatrixId) {
  142. //重新画矩阵框然后配置新的参考点
  143. currentDieMatrixId = waferData[i].nDieMatrixId;
  144. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / ratio;
  145. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / ratio;
  146. maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
  147. minx = center.x() + (maxRow_Col.minX - m_centerX) / ratio - 20;
  148. miny = center.y() - (maxRow_Col.minY - m_centerY) / ratio + 20;
  149. maxx = center.x() + (maxRow_Col.maxX - m_centerX) / ratio + 20;
  150. maxy = center.y() - (maxRow_Col.maxY - m_centerY) / ratio - 20;
  151. widthMatrix = maxx - minx;
  152. heightMatrix = miny - maxy;
  153. view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
  154. }
  155. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / ratio;
  156. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / ratio;
  157. view->addDiePoint(QPointF(referPointX, referPointY), waferData[i]);
  158. }
  159. scene->setSceneRect(0, 0, view->width(), view->height());
  160. int cur_width, cur_height;
  161. cur_width = parent->width();
  162. cur_height = parent->height();
  163. // 创建一个 QPixmap 对象用于保存绘制的图像
  164. globalPixmap = QPixmap(cur_width, cur_height);
  165. globalPixmap.fill(Qt::white); // 填充背景色为白色
  166. QPixmap originalPixmap = QPixmap::grabWidget(view);
  167. // 设置目标尺寸
  168. QSize targetSize(cur_width, cur_height);
  169. // 不保持比例,直接拉伸到指定尺寸
  170. QPixmap scaledPixmap = originalPixmap.scaled(
  171. targetSize,
  172. Qt::IgnoreAspectRatio,
  173. Qt::SmoothTransformation
  174. );
  175. globalPixmap = scaledPixmap;
  176. */
  177. }
  178. void Wafer::initFrom(QWidget* parent) {
  179. // 获取当前窗口的宽高
  180. double width, height;
  181. if (parent == nullptr) {
  182. width = 493;
  183. height = 493;
  184. }
  185. else {
  186. width = parent->width();
  187. height = parent->height();
  188. }
  189. // 创建视图
  190. scene = new QGraphicsScene(parent);
  191. view = new WaferGraphicsView(scene);
  192. view->resize(width, height);
  193. view->setCViewInterface(m_pCViewInterface);
  194. //获取当前角度
  195. double angle;
  196. m_pCViewInterface->GetViewMatrix()->GetWaferTableAngle(angle);
  197. QPointF center(width / 2.0, height / 2.0);
  198. QPointF pointf(m_centerX, m_centerY);
  199. double radius = width / 2 - 10;
  200. //比例
  201. double ratio = m_radius / radius;
  202. int dieLong = m_dieLong / ratio;
  203. int dieWide = m_dieWide / ratio;
  204. //test 实际使用时需要删除或注释
  205. angle = 90.00;
  206. // 初始化晶圆参数
  207. view->initWafer(center, // 中心坐标
  208. radius, // 半径
  209. dieLong, dieWide,angle); // 固晶点显示尺寸
  210. // 添加固晶点
  211. int currentDieMatrixId = -1;
  212. double referPointX = 0.0;
  213. double referPointY = 0.0;
  214. MaxRow_Col maxRow_Col;
  215. double minx, miny,maxx,maxy, widthMatrix, heightMatrix;
  216. for (int i = 0; i < waferData.size(); ++i) {
  217. //判断是否属于同一个矩阵
  218. if (waferData[i].nDieMatrixId != currentDieMatrixId) {
  219. //重新画矩阵框然后配置新的参考点
  220. currentDieMatrixId = waferData[i].nDieMatrixId;
  221. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / ratio;
  222. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / ratio;
  223. maxRow_Col = maxRow_Colmap.value(currentDieMatrixId);
  224. minx = center.x()+(maxRow_Col.minX - m_centerX) / ratio - 20;
  225. miny = center.y() - (maxRow_Col.minY - m_centerY) / ratio + 20;
  226. maxx = center.x() + (maxRow_Col.maxX - m_centerX) / ratio + 20;
  227. maxy = center.y() - (maxRow_Col.maxY - m_centerY) / ratio - 20;
  228. widthMatrix = maxx - minx;
  229. heightMatrix = miny - maxy;
  230. view->drawDieMatrix(QPointF(minx, maxy), widthMatrix, heightMatrix, currentDieMatrixId);
  231. }
  232. referPointX = center.x() + (waferData[i].stPosition.x - m_centerX) / ratio;
  233. referPointY = center.y() - (waferData[i].stPosition.y - m_centerY) / ratio;
  234. view->addDiePoint(QPointF(referPointX, referPointY),waferData[i]);
  235. }
  236. scene->setSceneRect(0, 0, view->width(), view->height());
  237. // 创建一个 QPixmap 对象用于保存绘制的图像
  238. globalPixmap = QPixmap(width, height);
  239. globalPixmap.fill(Qt::white); // 填充背景色为白色
  240. QPixmap originalPixmap = QPixmap::grabWidget(view);
  241. // 设置目标尺寸(例如:宽度 200,高度 150)
  242. QSize targetSize(width, height);
  243. // 不保持比例,直接拉伸到指定尺寸
  244. QPixmap scaledPixmap = originalPixmap.scaled(
  245. targetSize,
  246. Qt::IgnoreAspectRatio,
  247. Qt::SmoothTransformation
  248. );
  249. globalPixmap = scaledPixmap;
  250. }
  251. QPixmap Wafer::getGlobalPixmap() const {
  252. return globalPixmap;
  253. }
  254. void Wafer::setWaferInfo(ns_module::CViewInterface* CViewInterface) {
  255. m_pCViewInterface = CViewInterface;
  256. long result = m_pCViewInterface->GetViewMatrix()->GetDieSize(m_dieLong,m_dieWide);
  257. m_pCViewInterface->GetViewMatrix()->GetWaferSize(m_centerX, m_centerY,m_radius);
  258. //这里到时候更新接口时替换真实圆心点的数据
  259. /*m_dieLong = 10;
  260. m_dieWide = 10;*/
  261. m_radius = 10000;
  262. m_centerX = 0;
  263. m_centerY = 0;
  264. }