ChartsAndCamerasWnd.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. #include "ChartsAndCamerasWnd.h"
  2. #include "ui_ChartsAndCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include "chartline.h"
  8. #include <QRandomGenerator>
  9. #include <QScrollBar>
  10. #include <qDebug>
  11. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  12. #include <QPixmap>
  13. #include <QFileDialog>
  14. #include <QDateTime>
  15. #include <QMessageBox>
  16. #include <QPen>
  17. ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget* parent) :
  18. JOriginalMainWnd(parent),
  19. ui(new Ui::ChartsAndCamerasWnd),
  20. chartLine(new ChartLine(this)),
  21. chartLine1(new ChartLine(this)),
  22. chartLine2(new ChartLine(this))
  23. {
  24. ui->setupUi(this);
  25. // 设置 ChartLine 的位置和大小
  26. chartLine->setParent(ui->Leftwidget);
  27. chartLine->setGeometry(0, 0, 560, 280);
  28. chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");
  29. // 设置 ChartLine1 的位置和大小
  30. chartLine1->setParent(ui->Leftwidget);
  31. chartLine1->setGeometry(0, 245, 560, 280);
  32. chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");
  33. // 设置 ChartLine2 的位置和大小
  34. chartLine2->setParent(ui->Leftwidget);
  35. chartLine2->setGeometry(0, 490, 560, 280);
  36. chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");
  37. // 初始化系列信息
  38. initializeSeriesInfo();
  39. // 连接所有复选框的 clicked 信号到通用槽函数
  40. QList<QCheckBox*> checkBoxes = {
  41. ui->GreenDiamondcheckBox,
  42. ui->YellowDiamondcheckBox,
  43. ui->BlackDiamondcheckBox,
  44. ui->BlueDiamondcheckBox,
  45. ui->BlueHorizontalLinecheckBox,
  46. ui->BlueVerticalBarcheckBox,
  47. ui->GreenVerticalBarcheckBox,
  48. ui->PurpleVerticalBarcheckBox,
  49. ui->RedDiamondcheckBox,
  50. ui->RedHorizontalLinecheckBox,
  51. ui->WhiteVerticalBarcheckBox
  52. };
  53. connect(ui->viewwidgetgroup, &ControlOperationPage::send_ComboBox_singal, this, &ChartsAndCamerasWnd::HandleComboxchange);
  54. for (QCheckBox* cb : checkBoxes) {
  55. cb->setCheckable(true);
  56. //connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
  57. }
  58. //isEnable = false;
  59. //initFrom();
  60. isShow = true;
  61. QTimer* timer = new QTimer(this);
  62. connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::setColor);
  63. timer->start(100);
  64. m_timerMaterial = new QTimer(this);
  65. connect(m_timerMaterial, &QTimer::timeout, this, &ChartsAndCamerasWnd::UpdateMaterialByTimer);
  66. m_pCViewInterface = ns_module::CViewInterface::GetInstance();
  67. }
  68. void ChartsAndCamerasWnd::setColor()
  69. {
  70. QSettings settings("YourCompany", "YourApplication_style");
  71. int flag = settings.value("Flag_Style").toInt();
  72. if (flag == 1)
  73. {
  74. chartLine->setChartColors(Qt::white);
  75. chartLine1->setChartColors(Qt::white);
  76. chartLine2->setChartColors(Qt::white);
  77. }
  78. else
  79. {
  80. chartLine->setChartColors(QColor("#29517E"));
  81. chartLine1->setChartColors(QColor("#29517E"));
  82. chartLine2->setChartColors(QColor("#29517E"));
  83. }
  84. }
  85. ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
  86. {
  87. m_pMainCameraBind = nullptr;
  88. UnCameraBind();
  89. delete ui;
  90. }
  91. void ChartsAndCamerasWnd::initializeSeriesInfo()
  92. {
  93. // 初始化系列信息,使用 DataSeries 结构体
  94. m_seriesMap["GreenDiamond"] = DataSeries{
  95. "GreenDiamond",
  96. QColor("#00FF00"), // 绿色
  97. QPixmap(":/images/Participation display/GreenDiamond.png"),
  98. QList<QPointF>() // 初始为空
  99. };
  100. m_seriesMap["YellowDiamond"] = DataSeries{
  101. "YellowDiamond",
  102. QColor("#FFFF00"), // 黄色
  103. QPixmap(":/images/Participation display/YellowDiamond.png"),
  104. QList<QPointF>()
  105. };
  106. m_seriesMap["BlackDiamond"] = DataSeries{
  107. "BlackDiamond",
  108. QColor("#000000"), // 黑色
  109. QPixmap(":/images/Participation display/BlackDiamond.png"),
  110. QList<QPointF>()
  111. };
  112. m_seriesMap["BlueDiamond"] = DataSeries{
  113. "BlueDiamond",
  114. QColor("#0000FF"), // 蓝色
  115. QPixmap(":/images/Participation display/BlueDiamond.png"),
  116. QList<QPointF>()
  117. };
  118. m_seriesMap["BlueHorizontalLine"] = DataSeries{
  119. "BlueHorizontalLine",
  120. QColor("#0000FF"),
  121. QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
  122. QList<QPointF>()
  123. };
  124. m_seriesMap["BlueVerticalBar"] = DataSeries{
  125. "BlueVerticalBar",
  126. QColor("#0000FF"),
  127. QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
  128. QList<QPointF>()
  129. };
  130. m_seriesMap["GreenVerticalBar"] = DataSeries{
  131. "GreenVerticalBar",
  132. QColor("#00FF00"),
  133. QPixmap(":/images/Participation display/Green_vertical_bar.png"),
  134. QList<QPointF>()
  135. };
  136. m_seriesMap["PurpleVerticalBar"] = DataSeries{
  137. "PurpleVerticalBar",
  138. QColor("#800080"),
  139. QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
  140. QList<QPointF>()
  141. };
  142. m_seriesMap["RedDiamond"] = DataSeries{
  143. "RedDiamond",
  144. QColor("#FF0000"), // 红色
  145. QPixmap(":/images/Participation display/RedDiamond.png"),
  146. QList<QPointF>()
  147. };
  148. m_seriesMap["RedHorizontalLine"] = DataSeries{
  149. "RedHorizontalLine",
  150. QColor("#FF0000"),
  151. QPixmap(":/images/Participation display/Red_horizontal_line.png"),
  152. QList<QPointF>()
  153. };
  154. m_seriesMap["WhiteVerticalBar"] = DataSeries{
  155. "WhiteVerticalBar",
  156. QColor("#FFFFFF"), // 白色
  157. QPixmap(":/images/Participation display/White_vertical_bar.png"),
  158. QList<QPointF>()
  159. };
  160. }
  161. #if 0
  162. void ChartsAndCamerasWnd::on_CheckBox_clicked()
  163. {
  164. // 获取发送信号的复选框
  165. QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
  166. if (!checkBox)
  167. return;
  168. QString checkBoxName = checkBox->objectName();
  169. QString seriesName = checkBoxName;
  170. // 移除末尾的 "checkBox"
  171. if (seriesName.endsWith("checkBox")) {
  172. seriesName.chop(QString("checkBox").length());
  173. }
  174. else if (seriesName.endsWith("CheckBox")) {
  175. seriesName.chop(QString("CheckBox").length());
  176. }
  177. qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");
  178. if (!m_seriesMap.contains(seriesName)) {
  179. qDebug() << "No series info for:" << seriesName;
  180. return;
  181. }
  182. DataSeries& seriesInfo = m_seriesMap[seriesName];
  183. if (checkBox->isChecked()) {
  184. // 生成随机数据
  185. QList<QPointF> data;
  186. for (int i = 0; i <= 40; i += 4) {
  187. data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
  188. }
  189. seriesInfo.data = data;
  190. // 添加到 ChartLine 实例
  191. chartLine->addDataSeries(seriesInfo);
  192. chartLine1->addDataSeries(seriesInfo);
  193. chartLine2->addDataSeries(seriesInfo);
  194. qDebug() << "Added series:" << seriesName;
  195. }
  196. else {
  197. // 从 ChartLine 实例中移除
  198. chartLine->removeDataSeries(seriesName);
  199. chartLine1->removeDataSeries(seriesName);
  200. chartLine2->removeDataSeries(seriesName);
  201. qDebug() << "Removed series:" << seriesName;
  202. }
  203. }
  204. #endif
  205. // 初始化静态成员
  206. ChartsAndCamerasWnd* ChartsAndCamerasWnd::m_instance = nullptr;
  207. ChartsAndCamerasWnd* ChartsAndCamerasWnd::GetInstance() {
  208. if (!m_instance) {
  209. m_instance = new ChartsAndCamerasWnd();
  210. }
  211. return m_instance;
  212. }
  213. void ChartsAndCamerasWnd::initFrom()
  214. {
  215. m_allGroup.clear();
  216. waferMap.clear();
  217. waffleMap.clear();
  218. materialBoxMap.clear();
  219. bondMap.clear();
  220. QWidget* viewport = ui->scrollArea->viewport();
  221. QWidget* container = new QWidget(viewport);
  222. QHBoxLayout* layout = new QHBoxLayout(container);
  223. layout->setSpacing(16); // 设置Group之间的间隔距离
  224. layout->setMargin(0);
  225. //QList<int> numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };
  226. int nSize = 0;
  227. if (m_pMainCameraBind != nullptr)
  228. {
  229. nSize = m_pMainCameraBind->m_vecCamera.size();
  230. if (nSize == 0) // 针对获取不到的情况
  231. {
  232. nSize = 5;
  233. //JMessageTip::Message_warning("a");
  234. }
  235. QList<int> numbers;
  236. for (int i = 1; i <= nSize; i++)
  237. {
  238. numbers.push_back(i);
  239. }
  240. for (int i = 0; i < numbers.size(); ++i)
  241. {
  242. int num = numbers[i];
  243. CameraImageHandler* manager = nullptr;
  244. if (nSize == 5) // 测试数据
  245. {
  246. CameraInfo test;
  247. test.iCameraId = i;
  248. test.name = ("camera" + QString::number(i)).toStdString();
  249. test.eType = MATERIAL_WAFFLE;
  250. manager = new CameraImageHandler(num, test);
  251. }
  252. else
  253. {
  254. m_pMainCameraBind->m_vecCamera[i].eType = MATERIAL_BOX;
  255. manager = new CameraImageHandler(num, m_pMainCameraBind->m_vecCamera[i]);
  256. }
  257. Group* widget = manager->getGroup();
  258. if (m_pMainCameraBind->m_vecCamera.size() > 0)
  259. {
  260. widget->SetCameaInfo(m_pMainCameraBind->m_vecCamera[i]);
  261. }
  262. //connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide);
  263. if (widget != nullptr)
  264. {
  265. CameraConnectUpdateImageFun(i, widget);
  266. connect(widget, &Group::sendUpdateGroupState,
  267. this, &ChartsAndCamerasWnd::checkSettings);
  268. connect(widget, &Group::send_ComboBox_singal,
  269. this, &ChartsAndCamerasWnd::GetGroupComboxChanged);
  270. layout->addWidget(widget);
  271. m_allGroup.append(widget);
  272. }
  273. if (manager->getWafer())
  274. {
  275. waferMap.insert(num, manager->getWafer());
  276. ui->viewwidgetgroup->setWafer(waferMap.value(i + 1));
  277. m_allGroup[i]->setWaferWidget(ui->viewwidgetgroup->getWafer()->getGlobalPixmap());
  278. }
  279. if (manager->getWaffle())
  280. {
  281. waffleMap.insert(num, manager->getWaffle());
  282. ui->viewwidgetgroup->setWaffle(waffleMap.value(i + 1));
  283. m_allGroup[i]->setWaffleWidget(ui->viewwidgetgroup->getWaffle()->getGlobalPixmap());
  284. }
  285. if (manager->getMaterialBox())
  286. {
  287. materialBoxMap.insert(num, manager->getMaterialBox());
  288. }
  289. if (manager->getBond()) {
  290. bondMap.insert(num, manager->getBond());
  291. ui->viewwidgetgroup->setBond(bondMap.value(i + 1));
  292. m_allGroup[i]->setBondWidget(ui->viewwidgetgroup->getBond()->getGlobalPixmap());
  293. }
  294. if (!manager->getFileList().isEmpty()) {
  295. m_mapFileListMap.insert(num, manager->getFileList());
  296. }
  297. delete manager;
  298. }
  299. //清理ui->viewwidgetgroup
  300. int width = ui->viewwidgetgroup->width();
  301. int height = ui->viewwidgetgroup->height();
  302. QPixmap pixmap(width, height);
  303. pixmap.fill(Qt::white); // 白色背景
  304. GetGroupImageShowSignals(pixmap);
  305. // 设置控件的最小高度和最大宽度
  306. int minHeight = 162;
  307. int maxWidth = 244;
  308. int num = -16;
  309. for (Group* w : m_allGroup) {
  310. w->setMinimumHeight(minHeight);
  311. w->setMaximumWidth(maxWidth);
  312. num = num + 260;
  313. }
  314. container->setMinimumSize(num, 162);
  315. container->setLayout(layout);
  316. ui->scrollArea->setWidget(container);
  317. ui->scrollArea->resize(508, 177);
  318. initWidget();
  319. }
  320. }
  321. void ChartsAndCamerasWnd::checkSettings(int groupId, int index) {
  322. if (groupId != lastGroupId || index != lastIndex) {
  323. GetCurrentSelectSlots(groupId, index);
  324. lastGroupId = groupId;
  325. lastIndex = index;
  326. saveInfoOfLast();
  327. }
  328. }
  329. void ChartsAndCamerasWnd::updateMaterialWidget(int materialWndType, int groupId) {
  330. switch (materialWndType) {
  331. case 1: ui->viewwidgetgroup->setWafer(waferMap.value(groupId)); break;
  332. case 2: ui->viewwidgetgroup->setWaffle(waffleMap.value(groupId)); break;
  333. case 3: ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(groupId)); break;
  334. case 4: ui->viewwidgetgroup->setBond(bondMap.value(groupId)); break;
  335. }
  336. }
  337. void ChartsAndCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  338. {
  339. m_pMainCameraBind = pCameraBind;
  340. initFrom();
  341. }
  342. void ChartsAndCamerasWnd::UnCameraBind()
  343. {
  344. for (size_t i = 0; i < m_allGroup.size(); i++)
  345. {
  346. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  347. }
  348. //判断退出前的窗口是否是绑定相机
  349. if (m_veCurrentSelectGroup.isBond == true) {
  350. //解绑
  351. disconnect(m_veCurrentSelectGroup.pSelectGroup, &Group::SetUpDataImageShowSig,
  352. this, &ChartsAndCamerasWnd::GetGroupImageShowSignals);
  353. }
  354. }
  355. void ChartsAndCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  356. {
  357. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  358. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  359. }
  360. void ChartsAndCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  361. {
  362. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  363. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  364. }
  365. void ChartsAndCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  366. {
  367. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  368. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  369. }
  370. void ChartsAndCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  371. {
  372. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  373. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  374. }
  375. void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  376. {
  377. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  378. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  379. }
  380. void ChartsAndCamerasWnd::CameraConnectUpdateImageFun(int nIndex, Group* widget, bool isUnCameraBind /*= false*/)
  381. {
  382. auto BinCamerasImage = [&](void (ChartsAndCamerasWnd::* pCamerasImage)(const QPixmap& imageData))
  383. {
  384. if (isUnCameraBind)
  385. {
  386. //disconnect(widget, &Group::SetCurrentSelectSig, this, &ChartsAndCamerasWnd::GetCurrentSelectSlots);
  387. disconnect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  388. }
  389. else
  390. {
  391. //共用函数
  392. //connect(widget, &Group::sendUpdateGroupState, this, &ChartsAndCamerasWnd::checkSettings);
  393. connect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  394. }
  395. };
  396. if (nIndex == 0)
  397. {
  398. BinCamerasImage(&ChartsAndCamerasWnd::UpDataImageShowSignals0);
  399. }
  400. else if (nIndex == 1)
  401. {
  402. BinCamerasImage(&ChartsAndCamerasWnd::UpDataImageShowSignals1);
  403. }
  404. else if (nIndex == 2)
  405. {
  406. BinCamerasImage(&ChartsAndCamerasWnd::UpDataImageShowSignals2);
  407. }
  408. else if (nIndex == 3)
  409. {
  410. BinCamerasImage(&ChartsAndCamerasWnd::UpDataImageShowSignals3);
  411. }
  412. else if (nIndex == 4)
  413. {
  414. BinCamerasImage(&ChartsAndCamerasWnd::UpDataImageShowSignals4);
  415. }
  416. }
  417. void ChartsAndCamerasWnd::wheelEvent(QWheelEvent* event)
  418. {
  419. //mousePos = ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos());
  420. //if (ui->viewwidgetgroup->getOperatewidget()->rect().contains(ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  421. // if (event->angleDelta().y() > 0) {
  422. // ui->viewwidgetgroup->updateScale(scaleFactor * 1.1); // 放大
  423. // } else {
  424. // ui->viewwidgetgroup->updateScale(scaleFactor * 0.9); // 缩小
  425. // }
  426. //}
  427. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  428. // // 获取 QScrollArea 的横向滚动条
  429. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  430. // // 根据滚轮滚动方向改变滚动条的值
  431. // if (event->angleDelta().y() > 0) {
  432. // scrollBar->setValue(scrollBar->value() - 50);
  433. // } else {
  434. // scrollBar->setValue(scrollBar->value() + 50);
  435. // }
  436. //}
  437. QMainWindow::wheelEvent(event);
  438. }
  439. void ChartsAndCamerasWnd::showEvent(QShowEvent* event) {
  440. QMainWindow::showEvent(event);
  441. // loadSettings();
  442. // initFrom();
  443. }
  444. void ChartsAndCamerasWnd::hideEvent(QHideEvent* event) {
  445. QMainWindow::hideEvent(event);
  446. }
  447. void ChartsAndCamerasWnd::GetGroupImageShowSignals(const QPixmap& imageData) {
  448. QSize size = ui->viewwidgetgroup->getOperatewidget()->size();
  449. QPixmap scaledPixmap = imageData.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  450. ui->viewwidgetgroup->setScaleFactorSize(scaledPixmap);
  451. // m_lastRightPixmap = imageData;
  452. }
  453. void ChartsAndCamerasWnd::BindImageOrMaterial(int index) {
  454. if (index == m_nImageIndex) {
  455. m_veCurrentSelectGroup.isBond = true;
  456. connect(m_veCurrentSelectGroup.pSelectGroup, &Group::SetUpDataImageShowSig,
  457. this, &ChartsAndCamerasWnd::GetGroupImageShowSignals);
  458. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId, true);
  459. }
  460. else {
  461. QSettings settings("YourOrganization", "YourApplication");
  462. settings.beginGroup(QString::number(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId));
  463. int materialWndType = settings.value("MaterialWndType").toInt();
  464. settings.endGroup();
  465. m_veCurrentSelectGroup.isBond = false;
  466. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId, false);
  467. updateMaterialWidget(materialWndType, m_veCurrentSelectGroup.pSelectGroup->m_nGroupId);
  468. }
  469. }
  470. void ChartsAndCamerasWnd::initWidget() {
  471. //初始化当前页面的信息
  472. QSettings settings("YourOrganization", "YourApplication");
  473. lastIndex = settings.value("ChartLastIndex", 1).toInt();
  474. lastGroupId = settings.value("ChartLastGroupId", 1).toInt();
  475. //处理各种情况的初始化
  476. if (m_pMainCameraBind == nullptr || m_allGroup.size() == 0)
  477. {
  478. return;
  479. }
  480. //当lastGroupId大于m_allGroup.size()时,初始化lastGroupId为1
  481. if (m_allGroup.size() < lastGroupId) {
  482. lastGroupId = 1;
  483. lastIndex = 1;
  484. m_veCurrentSelectGroup.isInitialed = true;
  485. m_veCurrentSelectGroup.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  486. m_veCurrentSelectGroup.pSelectGroup->initBorderStyle(lastIndex, 1);
  487. //初始化下拉框内容同步小窗口索引
  488. int currentComboBoxIndex = m_veCurrentSelectGroup.pSelectGroup->getCurrentComboBoxIndex();
  489. ui->viewwidgetgroup->setEnableControls(true);
  490. ui->viewwidgetgroup->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup.pSelectGroup->m_nGroupId], currentComboBoxIndex);
  491. BindImageOrMaterial(m_nImageIndex);
  492. BindImageOrMaterial(m_nImageIndex);
  493. }
  494. else {
  495. }
  496. m_veCurrentSelectGroup.isInitialed = true;
  497. m_veCurrentSelectGroup.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  498. m_veCurrentSelectGroup.pSelectGroup->initBorderStyle(lastIndex, 1);
  499. //初始化下拉框内容同步小窗口索引
  500. int currentComboBoxIndex = m_veCurrentSelectGroup.pSelectGroup->getCurrentComboBoxIndex();
  501. ui->viewwidgetgroup->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup.pSelectGroup->m_nGroupId], currentComboBoxIndex);
  502. if (lastIndex == 1) {
  503. ui->viewwidgetgroup->setEnableControls(true);
  504. BindImageOrMaterial(m_nImageIndex);
  505. QPixmap pixmap = ui->viewwidgetgroup->getCurrentComboBoxPixmap(currentComboBoxIndex);
  506. GetGroupImageShowSignals(pixmap);
  507. }
  508. else {
  509. ui->viewwidgetgroup->setEnableControls(false);
  510. BindImageOrMaterial(m_nMaterialIndex);
  511. }
  512. m_timerMaterial->start(10000);
  513. }
  514. void ChartsAndCamerasWnd::saveInfoOfLast() {
  515. QSettings settings("YourOrganization", "YourApplication");
  516. settings.setValue("ChartLastIndex", lastIndex);
  517. settings.setValue("ChartLastGroupId", lastGroupId);
  518. }
  519. void ChartsAndCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex) {
  520. int nOnClickGroupId = groupId - 1;
  521. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  522. {
  523. return;
  524. }
  525. //判断更新前的窗口是否是绑定相机
  526. if (m_veCurrentSelectGroup.isBond == true) {
  527. //解绑
  528. disconnect(m_veCurrentSelectGroup.pSelectGroup, &Group::SetUpDataImageShowSig,
  529. this, &ChartsAndCamerasWnd::GetGroupImageShowSignals);
  530. }
  531. m_veCurrentSelectGroup.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  532. //判断index是相机还是物料
  533. //更新下拉框内容同步小窗口索引
  534. int currentComboBoxIndex = m_veCurrentSelectGroup.pSelectGroup->getCurrentComboBoxIndex();
  535. ui->viewwidgetgroup->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup.pSelectGroup->m_nGroupId], currentComboBoxIndex);
  536. if (nIndex == 2) {
  537. ui->viewwidgetgroup->setEnableControls(false);
  538. BindImageOrMaterial(m_nMaterialIndex);
  539. }
  540. else if (nIndex == 1) {
  541. ui->viewwidgetgroup->setEnableControls(true);
  542. BindImageOrMaterial(m_nImageIndex);
  543. QPixmap pixmap = ui->viewwidgetgroup->getCurrentComboBoxPixmap(currentComboBoxIndex);
  544. GetGroupImageShowSignals(pixmap);
  545. }
  546. }
  547. void ChartsAndCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, bool isShow)
  548. {
  549. auto Fun = [&](Group* pGroup, LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  550. {
  551. p->UpdatemPageGroup(pGroup);
  552. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  553. p->HideOrShowPage(bShow);
  554. if (bShow)
  555. {
  556. pContPage->UpDateCameraBind(m_pMainCameraBind);
  557. }
  558. else
  559. {
  560. pContPage->setSwitchJoystickButEnable(bShow);
  561. }
  562. };
  563. disconnect(ui->viewwidgetgroup, &ControlOperationPage::SendModuleTypeSignals,
  564. ui->control, &LightJoystickSwitchPage::GetModuleTypeSlots);
  565. Group* currGroup = m_allGroup.at(groupId - 1);
  566. Fun(currGroup, ui->control, ui->viewwidgetgroup, isShow);
  567. connect(ui->viewwidgetgroup, &ControlOperationPage::SendModuleTypeSignals,
  568. ui->control, &LightJoystickSwitchPage::GetModuleTypeSlots);
  569. }
  570. void ChartsAndCamerasWnd::GetGroupComboxChanged(int groupId, int comboxIndex) {
  571. m_allGroup.at(groupId - 1);
  572. if (comboxIndex == 0) {
  573. CameraConnectUpdateImageFun(groupId - 1, m_allGroup.at(groupId - 1), false);
  574. }
  575. else {
  576. CameraConnectUpdateImageFun(groupId - 1, m_allGroup.at(groupId - 1), true);
  577. }
  578. m_allGroup.at(groupId - 1)->setCurrentCombox(comboxIndex);
  579. if (groupId == m_veCurrentSelectGroup.pSelectGroup->m_nGroupId && lastIndex == 1) {
  580. if (comboxIndex != 0) {//图片
  581. QPixmap updatePixmap = ui->viewwidgetgroup->getCurrentComboBoxPixmap(comboxIndex);
  582. m_veCurrentSelectGroup.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  583. }
  584. }
  585. }
  586. void ChartsAndCamerasWnd::HandleComboxchange(int index) {
  587. if (index == 0) {
  588. CameraConnectUpdateImageFun(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId - 1), false);
  589. }
  590. else {
  591. CameraConnectUpdateImageFun(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId - 1), true);
  592. QPixmap updatePixmap = ui->viewwidgetgroup->getCurrentComboBoxPixmap(index);
  593. m_veCurrentSelectGroup.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  594. }
  595. }
  596. void ChartsAndCamerasWnd::UpdateMaterialByTimer() {
  597. //判断当前大窗口是否是物料窗口
  598. if (lastIndex == 2) {
  599. QSettings settings("YourOrganization", "YourApplication");
  600. settings.beginGroup(QString::number(m_veCurrentSelectGroup.pSelectGroup->m_nGroupId));
  601. int MaterialWndType = settings.value("MaterialWndType").toInt();
  602. settings.endGroup();
  603. switch (MaterialWndType) {
  604. case 1:
  605. {
  606. UpdateWafer(lastGroupId);
  607. ui->viewwidgetgroup->setWafer(waferMap.value(lastGroupId));
  608. m_allGroup[lastGroupId - 1]->setWaferWidget(ui->viewwidgetgroup->getWafer()->getGlobalPixmap());
  609. break;
  610. }
  611. case 2:
  612. {
  613. UpdateWaffle(lastGroupId);
  614. ui->viewwidgetgroup->setWaffle(waffleMap.value(lastGroupId));
  615. m_allGroup[lastGroupId - 1]->setWaffleWidget(ui->viewwidgetgroup->getWaffle()->getGlobalPixmap());
  616. break;
  617. }
  618. case 3:
  619. {
  620. UpdateMaterialBox(lastGroupId);
  621. ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(lastGroupId));
  622. m_allGroup[lastGroupId - 1]->MaterialBoxWidget();
  623. break;
  624. }
  625. case 4:
  626. {
  627. UpdateBond(lastGroupId);
  628. ui->viewwidgetgroup->setBond(bondMap.value(lastGroupId));
  629. m_allGroup[lastGroupId - 1]->setBondWidget(ui->viewwidgetgroup->getBond()->getGlobalPixmap());
  630. break;
  631. }
  632. }
  633. }
  634. }
  635. void ChartsAndCamerasWnd::UpdateWafer(int groupId) {
  636. if (m_pCViewInterface != nullptr)
  637. {
  638. std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT> veWafer;
  639. m_pCViewInterface->GetViewMatrix()->GetWaferAllPointInfo(veWafer);
  640. waferMap.value(groupId)->UpdataVal(veWafer);
  641. waferMap.value(groupId)->setWaferInfo(m_pCViewInterface);
  642. }
  643. else
  644. {
  645. waferMap.value(groupId)->UpdataGenerateTestData();
  646. }
  647. }
  648. void ChartsAndCamerasWnd::UpdateWaffle(int groupId) {
  649. if (m_pCViewInterface != nullptr)
  650. {
  651. std::vector<ns_mat::WAFFLE_MATRIX_POINT_STRUCT> veWaffle;
  652. m_pCViewInterface->GetViewMatrix()->GetWafflePackAllPointInfo(veWaffle);
  653. waffleMap.value(groupId)->UpdataVal(veWaffle);
  654. }
  655. else
  656. {
  657. waffleMap.value(groupId)->UpdataGenerateTestData();
  658. }
  659. }
  660. void ChartsAndCamerasWnd::UpdateBond(int groupId) {
  661. if (m_pCViewInterface != nullptr)
  662. {
  663. std::vector<ns_mat::POINT_INFO_STRUCT> stPointInfo;
  664. m_pCViewInterface->GetViewMatrix()->GetBondAllPointInfo(stPointInfo);
  665. bondMap.value(groupId)->UpdataVal(stPointInfo);
  666. bondMap.value(groupId)->setBondInfo(m_pCViewInterface);
  667. }
  668. else
  669. {
  670. bondMap.value(groupId)->UpdataGenerateTestData();
  671. }
  672. }
  673. void ChartsAndCamerasWnd::UpdateMaterialBox(int groupId) {
  674. if (m_pCViewInterface != nullptr)
  675. {
  676. std::vector<ns_module::MATERIAL_BOX_STRUCT> veMaterial;
  677. m_pCViewInterface->GetViewMatrix()->GetMaterialBoxAllPointInfo(veMaterial);
  678. materialBoxMap.value(groupId)->UpdataVal(veMaterial);
  679. materialBoxMap.value(groupId)->setMaterialBoxInfo(m_pCViewInterface);
  680. }
  681. else
  682. {
  683. materialBoxMap.value(groupId)->UpdataGenerateTestData();
  684. }
  685. }
  686. void ChartsAndCamerasWnd::TimerMaterialStart() {
  687. if (m_timerMaterial != nullptr) {
  688. m_timerMaterial->start();
  689. }
  690. }
  691. void ChartsAndCamerasWnd::TimerMaterialStop() {
  692. if (m_timerMaterial != nullptr) {
  693. m_timerMaterial->stop();
  694. }
  695. }