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