MainAndSecondaryCamerasWnd.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. #include "MainAndSecondaryCamerasWnd.h"
  2. #include "ui_MainAndSecondaryCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include <QScrollBar>
  8. #include <QDoubleValidator>
  9. #include "CameraDistribute.h"
  10. #include "Src/common/JMessageTip.h"
  11. MainAndSecondaryCamerasWnd::MainAndSecondaryCamerasWnd(QWidget* parent)
  12. : JOriginalMainWnd(parent)
  13. , ui(new Ui::MainAndSecondaryCamerasWnd)
  14. {
  15. ui->setupUi(this);
  16. Init();
  17. }
  18. MainAndSecondaryCamerasWnd::~MainAndSecondaryCamerasWnd()
  19. {
  20. UnCameraBind();
  21. DelMenory();
  22. delete ui;
  23. }
  24. void MainAndSecondaryCamerasWnd::Init()
  25. {
  26. qApp->installEventFilter(this);
  27. ui->control_r->HideOrShowPage(false);
  28. ui->control_L->HideOrShowPage(false);
  29. ui->viewwidgetgroup_L->setBlueBord();
  30. connect(ui->viewwidgetgroup_L, &ControlOperationPage::send_ComboBox_singal,
  31. this, &MainAndSecondaryCamerasWnd::HandleComboxchange_L);
  32. connect(ui->viewwidgetgroup_R, &ControlOperationPage::send_ComboBox_singal,
  33. this, &MainAndSecondaryCamerasWnd::HandleComboxchange_R);
  34. m_veCurrentSelectGroup_R = {};
  35. m_veCurrentSelectGroup_L = {};
  36. m_veCurrentSelectGroup_R.isInitialed = false;
  37. m_veCurrentSelectGroup_L.isInitialed = false;
  38. m_veCurrentSelectGroup_R.isBond = false;
  39. m_veCurrentSelectGroup_L.isBond = false;
  40. m_timerMaterial = new QTimer(this);
  41. connect(m_timerMaterial, &QTimer::timeout, this, &MainAndSecondaryCamerasWnd::UpdateMaterialByTimer);
  42. m_pCViewInterface = ns_module::CViewInterface::GetInstance();
  43. }
  44. void MainAndSecondaryCamerasWnd::InitPage()
  45. {
  46. DelMenory();
  47. QWidget* viewport = ui->scrollArea->viewport();
  48. QWidget* container = new QWidget(viewport);
  49. QHBoxLayout* mainLayout = new QHBoxLayout(container);
  50. mainLayout->setSpacing(28);
  51. mainLayout->setMargin(0);
  52. int nSize = 0;
  53. if (m_pMainCameraBind != nullptr)
  54. {
  55. nSize = m_pMainCameraBind->m_vecCamera.size();
  56. if (nSize == 0) // 针对获取不到的情况
  57. {
  58. nSize = 5;
  59. //JMessageTip::Message_warning("a");
  60. }
  61. QList<int> numbers;
  62. for (int i = 1; i <= nSize; i++)
  63. {
  64. numbers.push_back(i);
  65. }
  66. for (int i = 0; i < numbers.size(); ++i)
  67. {
  68. int num = numbers[i];
  69. CameraImageHandler* manager = nullptr;
  70. if (nSize == 5) // 测试数据
  71. {
  72. CameraInfo test;
  73. test.iCameraId = i;
  74. test.name = ("camera" + QString::number(i)).toStdString();
  75. test.eType = MATERIAL_WAFFLE;
  76. manager = new CameraImageHandler(num, test);
  77. }
  78. else
  79. {
  80. m_pMainCameraBind->m_vecCamera[i].eType = MATERIAL_BOND;
  81. manager = new CameraImageHandler(num, m_pMainCameraBind->m_vecCamera[i]);
  82. }
  83. Group* widget = manager->getGroup();
  84. if (m_pMainCameraBind->m_vecCamera.size() > 0)
  85. {
  86. widget->SetCameaInfo(m_pMainCameraBind->m_vecCamera[i]);
  87. }
  88. CameraConnectUpdateImageFun(i, widget);
  89. connect(widget, &Group::sendUpdateGroupState,
  90. this, &MainAndSecondaryCamerasWnd::checkSettings);
  91. connect(widget, &Group::send_ComboBox_singal,
  92. this, &MainAndSecondaryCamerasWnd::GetGroupComboxChanged);
  93. if (widget != nullptr)
  94. {
  95. mainLayout->addWidget(widget);
  96. m_allGroup.append(widget);
  97. }
  98. if (manager->getWafer())
  99. {
  100. m_mapWaferMap.insert(num, manager->getWafer());
  101. ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(i + 1));
  102. m_allGroup[i]->setWaferWidget(ui->viewwidgetgroup_L->getWafer()->getGlobalPixmap());
  103. }
  104. if (manager->getWaffle()) {
  105. m_mapWaffleMap.insert(num, manager->getWaffle());
  106. ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(i + 1));
  107. m_allGroup[i]->setWaffleWidget(ui->viewwidgetgroup_L->getWaffle()->getGlobalPixmap());
  108. }
  109. if (manager->getMaterialBox()) {
  110. m_mapMaterialBoxMap.insert(num, manager->getMaterialBox());
  111. }
  112. if (manager->getBond()) {
  113. m_mapBondMap.insert(num, manager->getBond());
  114. ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(i + 1));
  115. m_allGroup[i]->setBondWidget(ui->viewwidgetgroup_L->getBond()->getGlobalPixmap());
  116. }
  117. if(!manager->getFileList().isEmpty()){
  118. m_mapFileListMap.insert(num, manager->getFileList());
  119. }
  120. delete manager;
  121. }
  122. //清理ui->viewwidgetgroup_L
  123. //int width = ui->viewwidgetgroup_L->width();
  124. //int height = ui->viewwidgetgroup_L->height();
  125. //QPixmap pixmap(width, height);
  126. //pixmap.fill(Qt::white); // 白色背景
  127. //GetGroupImageShowSignalsTo_L(pixmap);
  128. ui->viewwidgetgroup_L->getOperatewidget()->clearPixmap();
  129. // 设置控件的最小高度和最大宽度
  130. int minHeight = 162;
  131. int maxWidth = 244;
  132. int num = -28;
  133. for (Group* w : m_allGroup)
  134. {
  135. w->setMinimumHeight(minHeight);
  136. w->setMaximumWidth(maxWidth);
  137. num = num + 272;
  138. }
  139. container->setMinimumSize(num, 162);
  140. container->setLayout(mainLayout);
  141. ui->scrollArea->setWidget(container);
  142. ui->scrollArea->resize(1062, 177);
  143. initLeftAndRightWidget();
  144. }
  145. }
  146. void MainAndSecondaryCamerasWnd::DelMenory()
  147. {
  148. TDelMen(m_allGroup);
  149. TDelMen(m_mapWaferMap);
  150. TDelMen(m_mapWaffleMap);
  151. TDelMen(m_mapMaterialBoxMap);
  152. TDelMen(m_mapBondMap);
  153. }
  154. void MainAndSecondaryCamerasWnd::CameraConnectUpdateImageFun(int nIndex, Group* widget, bool isUnCameraBind /*= false*/)
  155. {
  156. auto BinCamerasImage = [&](void (MainAndSecondaryCamerasWnd::* pCamerasImage)(const QPixmap& imageData))
  157. {
  158. if (isUnCameraBind)
  159. {
  160. disconnect(widget, &Group::SetCurrentSelectSig, this, &MainAndSecondaryCamerasWnd::GetCurrentSelectSlots);
  161. disconnect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  162. }
  163. else
  164. {
  165. //共用函数
  166. //connect(widget, &Group::send_button_Signal, this, &MainAndSecondaryCamerasWnd::CheckIs);
  167. // connect(widget, &Group::SetCurrentSelectSig, this, &MainAndSecondaryCamerasWnd::GetCurrentSelectSlots);
  168. connect(this, pCamerasImage, widget, &Group::UpDataImageShowSlots);
  169. }
  170. };
  171. if (nIndex == 0)
  172. {
  173. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals0);
  174. }
  175. else if (nIndex == 1)
  176. {
  177. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals1);
  178. }
  179. else if (nIndex == 2)
  180. {
  181. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals2);
  182. }
  183. else if (nIndex == 3)
  184. {
  185. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals3);
  186. }
  187. else if (nIndex == 4)
  188. {
  189. BinCamerasImage(&MainAndSecondaryCamerasWnd::UpDataImageShowSignals4);
  190. }
  191. }
  192. void MainAndSecondaryCamerasWnd::initLeftAndRightWidget()
  193. {
  194. //初始化当前页面的信息
  195. QSettings settings("YourOrganization", "YourApplication");
  196. m_nLastLastIndex = settings.value("DoubleLastLastIndex", 2).toInt();
  197. m_nLastLastGroupId = settings.value("DoubleLastLastGroupId", 1).toInt();
  198. m_nLastIndex = settings.value("DoubleLastIndex", 1).toInt();
  199. m_nLastGroupId = settings.value("DoubleLastGroupId", 1).toInt();
  200. //处理各种情况的初始化
  201. if (m_pMainCameraBind == nullptr || m_allGroup.size() == 0)
  202. {
  203. return;
  204. }
  205. if (m_allGroup.size() < m_nLastGroupId || m_allGroup.size() < m_nLastLastGroupId)
  206. {
  207. //重置记录
  208. m_nLastGroupId = 1;
  209. m_nLastIndex = 1;
  210. m_nLastLastGroupId = 1;
  211. m_nLastLastIndex = 2;
  212. }
  213. m_veCurrentSelectGroup_R.isInitialed = true;
  214. m_veCurrentSelectGroup_L.isInitialed = true;
  215. if (m_allGroup.size() == 1)
  216. {
  217. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(m_nLastGroupId - 1);
  218. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(m_nLastGroupId - 1);
  219. m_veCurrentSelectGroup_L.pSelectGroup->initBorderStyle(m_nLastLastIndex,0);
  220. m_veCurrentSelectGroup_R.pSelectGroup->initBorderStyle(m_nLastIndex, 1);
  221. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  222. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  223. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  224. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  225. if (m_nLastIndex != m_nLastLastIndex)
  226. {
  227. if (m_nLastIndex == 1)
  228. {
  229. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  230. ui->viewwidgetgroup_R->setEnableControls(true);
  231. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  232. ui->viewwidgetgroup_L->setEnableControls(false);
  233. }
  234. else
  235. {
  236. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  237. ui->viewwidgetgroup_R->setEnableControls(false);
  238. QPixmap pixmap_L = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  239. GetGroupImageShowSignalsTo_L(pixmap_L);
  240. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  241. ui->viewwidgetgroup_L->setEnableControls(true);
  242. }
  243. }
  244. else
  245. {
  246. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  247. ui->viewwidgetgroup_R->setEnableControls(true);
  248. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  249. ui->viewwidgetgroup_L->setEnableControls(false);
  250. }
  251. }
  252. else
  253. {
  254. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(m_nLastLastGroupId - 1);
  255. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(m_nLastGroupId - 1);
  256. m_veCurrentSelectGroup_L.pSelectGroup->initBorderStyle(m_nLastLastIndex, 0);
  257. m_veCurrentSelectGroup_R.pSelectGroup->initBorderStyle(m_nLastIndex, 1);
  258. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  259. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  260. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  261. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  262. if (m_nLastLastIndex == 1)
  263. {
  264. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  265. ui->viewwidgetgroup_L->setEnableControls(true);
  266. QPixmap pixmap_L = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  267. GetGroupImageShowSignalsTo_L(pixmap_L);
  268. }
  269. else
  270. {
  271. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  272. ui->viewwidgetgroup_L->setEnableControls(false);
  273. }
  274. if (m_nLastIndex == 1)
  275. {
  276. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  277. ui->viewwidgetgroup_R->setEnableControls(true);
  278. QPixmap pixmap_R = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(currentRightComboBoxIndex);
  279. GetGroupImageShowSignalsTo_R(pixmap_R);
  280. }
  281. else
  282. {
  283. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  284. ui->viewwidgetgroup_R->setEnableControls(false);
  285. }
  286. }
  287. m_timerMaterial->start(800);
  288. }
  289. void MainAndSecondaryCamerasWnd::BindImageOrMaterial(int location, int index)
  290. {
  291. if (location == m_nLastLeft)
  292. {
  293. if (index == m_nImageIndex)
  294. {
  295. m_veCurrentSelectGroup_L.isBond = true;
  296. connect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  297. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  298. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, true);
  299. }
  300. else
  301. {
  302. //左边更新物料窗口
  303. QSettings settings("YourOrganization", "YourApplication");
  304. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  305. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  306. settings.endGroup();
  307. m_veCurrentSelectGroup_L.isBond = false;
  308. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, false);
  309. updateMaterialWidget(m_nLastLeft, lastMaterialWndType, m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId);
  310. }
  311. }
  312. else
  313. {
  314. if (index == m_nImageIndex)
  315. {
  316. m_veCurrentSelectGroup_R.isBond = true;
  317. connect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  318. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  319. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, true);
  320. }
  321. else
  322. {
  323. //右边更新物料窗口
  324. QSettings settings("YourOrganization", "YourApplication");
  325. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  326. int materialWndType = settings.value("MaterialWndType").toInt();
  327. settings.endGroup();
  328. m_veCurrentSelectGroup_R.isBond = false;
  329. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  330. updateMaterialWidget(m_nCurrentRight, materialWndType, m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId);
  331. }
  332. }
  333. }
  334. void MainAndSecondaryCamerasWnd::checkSettings(int groupId, int index)
  335. {
  336. if (groupId != m_nLastGroupId || index != m_nLastIndex)
  337. {
  338. GetCurrentSelectSlots(groupId, index);
  339. m_nLastLastGroupId = m_nLastGroupId;
  340. m_nLastLastIndex = m_nLastIndex;
  341. m_nLastGroupId = groupId;
  342. m_nLastIndex = index;
  343. saveInfoOfLast();
  344. }
  345. }
  346. void MainAndSecondaryCamerasWnd::saveInfoOfLast()
  347. {
  348. QSettings settings("YourOrganization", "YourApplication");
  349. settings.setValue("DoubleLastIndex", m_nLastIndex);
  350. settings.setValue("DoubleLastGroupId", m_nLastGroupId);
  351. settings.setValue("DoubleLastLastIndex", m_nLastLastIndex);
  352. settings.setValue("DoubleLastLastGroupId", m_nLastLastGroupId);
  353. }
  354. void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side, int materialWndType, int groupId) {
  355. if (side == m_nLastLeft) {
  356. switch (materialWndType) {
  357. case 1: ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(groupId)); break;
  358. case 2: ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(groupId)); break;
  359. case 3: ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  360. case 4: ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(groupId)); break;
  361. }
  362. }
  363. else if (side == m_nCurrentRight) {
  364. switch (materialWndType) {
  365. case 1: ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(groupId)); break;
  366. case 2: ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(groupId)); break;
  367. case 3: ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  368. case 4: ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(groupId)); break;
  369. }
  370. }
  371. }
  372. void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  373. {
  374. m_pMainCameraBind = pCameraBind;
  375. InitPage();
  376. }
  377. void MainAndSecondaryCamerasWnd::UnCameraBind()
  378. {
  379. for (size_t i = 0; i < m_allGroup.size(); i++)
  380. {
  381. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  382. }
  383. }
  384. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  385. {
  386. // TODO: 这里需要改动
  387. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  388. ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(),
  389. ui->viewwidgetgroup_L->getOperatewidget()->pos().y(),
  390. ui->viewwidgetgroup_L->getOperatewidget()->width(),
  391. ui->viewwidgetgroup_L->getOperatewidget()->height());
  392. //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image));
  393. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  394. }
  395. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  396. {
  397. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  398. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  399. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  400. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  401. ui->viewwidgetgroup_R->getOperatewidget()->height());
  402. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  403. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  404. }
  405. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  406. {
  407. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  408. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  409. }
  410. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  411. {
  412. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  413. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  414. }
  415. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  416. {
  417. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  418. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  419. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  420. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  421. ui->viewwidgetgroup_R->getOperatewidget()->height());
  422. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  423. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  424. }
  425. void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide)
  426. {
  427. for (int i = 0; i < layout->count(); ++i)
  428. {
  429. QWidget* widget = layout->itemAt(i)->widget();
  430. if (widget)
  431. {
  432. if (isHide)
  433. {
  434. widget->hide();
  435. }
  436. else
  437. {
  438. widget->show();
  439. }
  440. }
  441. }
  442. }
  443. void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, int index, bool isShow)
  444. {
  445. auto Fun = [&](Group* pGroup, LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  446. {
  447. p->UpdatemPageGroup(pGroup);
  448. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  449. p->HideOrShowPage(bShow);
  450. pContPage->UpdatemPageGroup(pGroup);
  451. if (bShow)
  452. {
  453. pContPage->UpDateCameraBind(m_pMainCameraBind);
  454. }
  455. else
  456. {
  457. pContPage->setSwitchJoystickButEnable(bShow);
  458. }
  459. };
  460. if (index == 1)
  461. {
  462. disconnect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  463. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  464. Group* currGroup = m_allGroup.at(groupId - 1);
  465. Fun(currGroup, ui->control_L, ui->viewwidgetgroup_L, isShow);
  466. connect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  467. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  468. }
  469. else if (index == 2)
  470. {
  471. disconnect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  472. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  473. Group* currGroup = m_allGroup.at(groupId - 1);
  474. Fun(currGroup, ui->control_r, ui->viewwidgetgroup_R, isShow);
  475. connect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  476. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  477. }
  478. }
  479. void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event)
  480. {
  481. int nID = event->timerId();
  482. }
  483. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  484. {
  485. int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择
  486. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  487. {
  488. return;
  489. }
  490. //判断更新前的左窗口是否是绑定相机
  491. if (m_veCurrentSelectGroup_L.isBond == true) {
  492. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  493. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  494. }
  495. //判断更新前的右窗口是否是绑定相机
  496. if (m_veCurrentSelectGroup_R.isBond == true) {
  497. //解绑
  498. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  499. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  500. }
  501. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  502. //判断更新前的右窗口的index是相机还是物料
  503. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  504. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId], currentLeftComboBoxIndex);
  505. if (m_nLastIndex == 1) {
  506. //左窗口绑定
  507. //更新左边的下拉框内容同步小窗口索引
  508. ui->viewwidgetgroup_L->setEnableControls(true);
  509. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  510. QPixmap pixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  511. GetGroupImageShowSignalsTo_L(pixmap);
  512. }
  513. else {
  514. ui->viewwidgetgroup_L->setEnableControls(false);
  515. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  516. }
  517. //右边更新物料窗口
  518. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  519. //判断当前index是相机还是物料
  520. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  521. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId], currentRightComboBoxIndex);
  522. if (nIndex == 2) {
  523. ui->viewwidgetgroup_R->setEnableControls(false);
  524. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  525. }
  526. else if (nIndex == 1) {//当前切换时相机序号
  527. ui->viewwidgetgroup_R->setEnableControls(true);
  528. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  529. QPixmap pixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(currentRightComboBoxIndex);
  530. GetGroupImageShowSignalsTo_R(pixmap);
  531. }
  532. }
  533. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L(const QPixmap& imageData)
  534. {
  535. //QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size();
  536. //
  537. //QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  538. ui->viewwidgetgroup_L->setScaleFactorSize(imageData);
  539. // ui->viewwidgetgroup_L->SetOriginalImage(imageData);
  540. //m_lastRightPixmap = imageData;
  541. }
  542. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R(const QPixmap& imageData)
  543. {
  544. //QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size();
  545. //QPixmap scaledPixmap_right = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  546. ui->viewwidgetgroup_R->setScaleFactorSize(imageData);
  547. //ui->viewwidgetgroup_R->SetOriginalImage(imageData);
  548. // m_lastRightPixmap = imageData;
  549. }
  550. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent* event)
  551. {
  552. //if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  553. // mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos());
  554. // if (event->angleDelta().y() > 0) {
  555. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大
  556. // } else {
  557. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小
  558. // }
  559. //}
  560. //if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  561. // mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos());
  562. // if (event->angleDelta().y() > 0) {
  563. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大
  564. // } else {
  565. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 0.9); // 缩小
  566. // }
  567. //}
  568. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  569. // // 获取 QScrollArea 的横向滚动条
  570. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  571. // // 根据滚轮滚动方向改变滚动条的值
  572. // if (event->angleDelta().y() > 0) {
  573. // scrollBar->setValue(scrollBar->value() - 50);
  574. // } else {
  575. // scrollBar->setValue(scrollBar->value() + 50);
  576. // }
  577. //}
  578. QMainWindow::wheelEvent(event);
  579. }
  580. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent* event)
  581. {
  582. isUpdatingSettings = false;
  583. QMainWindow::showEvent(event);
  584. isUpdatingSettings = false;
  585. }
  586. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent* event)
  587. {
  588. isUpdatingSettings = false;
  589. QMainWindow::hideEvent(event);
  590. }
  591. void MainAndSecondaryCamerasWnd::GetGroupComboxChanged(int groupId,int comboxIndex)
  592. {
  593. //m_allGroup.at(groupId - 1);
  594. //if(comboxIndex == 0)
  595. //{
  596. // CameraConnectUpdateImageFun(ngroupId, m_allGroup.at(ngroupId), false);
  597. //}
  598. //else
  599. //{
  600. // CameraConnectUpdateImageFun(ngroupId, m_allGroup.at(ngroupId), true);
  601. //}
  602. int ngroupId = groupId - 1;
  603. CameraConnectUpdateImageFun(ngroupId, m_allGroup.at(ngroupId), comboxIndex == 0 ? false : true);
  604. m_allGroup.at(ngroupId)->setCurrentCombox(comboxIndex);
  605. if(groupId == m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId && m_nLastLastIndex == 1)
  606. {
  607. if(comboxIndex != 0)
  608. {
  609. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(comboxIndex);
  610. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  611. }
  612. }
  613. else if(groupId == m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId && m_nLastIndex == 1)
  614. {
  615. if(comboxIndex != 0)
  616. {
  617. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(comboxIndex);
  618. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  619. }
  620. }
  621. }
  622. void MainAndSecondaryCamerasWnd::HandleComboxchange_L(int index)
  623. {
  624. if (index == 0)
  625. {
  626. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId-1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), false);
  627. }
  628. else
  629. {
  630. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), true);
  631. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(index);
  632. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  633. }
  634. }
  635. void MainAndSecondaryCamerasWnd::HandleComboxchange_R(int index)
  636. {
  637. if (index == 0)
  638. {
  639. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), false);
  640. }
  641. else
  642. {
  643. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), true);
  644. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(index);
  645. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  646. }
  647. }
  648. void MainAndSecondaryCamerasWnd::UpdateMaterialByTimer()
  649. {
  650. //qDebug() << "Qtimer test";
  651. //判断当前大窗口是否是物料窗口
  652. //判断右窗口是否为物料窗口
  653. if (m_nLastIndex == 2)
  654. {
  655. QSettings settings("YourOrganization", "YourApplication");
  656. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  657. int rightMaterialWndType = settings.value("MaterialWndType").toInt();
  658. settings.endGroup();
  659. switch (rightMaterialWndType)
  660. {
  661. case 1:
  662. {
  663. UpdateWafer(m_nLastGroupId);
  664. ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(m_nLastGroupId));
  665. m_allGroup[m_nLastGroupId-1]->setWaferWidget(ui->viewwidgetgroup_R->getWafer()->getGlobalPixmap());
  666. break;
  667. }
  668. case 2:
  669. {
  670. UpdateWaffle(m_nLastGroupId);
  671. ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(m_nLastGroupId));
  672. m_allGroup[m_nLastGroupId - 1]->setWaffleWidget(ui->viewwidgetgroup_R->getWaffle()->getGlobalPixmap());
  673. break;
  674. }
  675. case 3:
  676. {
  677. UpdateMaterialBox(m_nLastGroupId);
  678. ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(m_nLastGroupId));
  679. m_allGroup[m_nLastGroupId - 1]->MaterialBoxWidget();
  680. break;
  681. }
  682. case 4:
  683. {
  684. UpdateBond(m_nLastGroupId);
  685. ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(m_nLastGroupId));
  686. m_allGroup[m_nLastGroupId - 1]->setBondWidget(ui->viewwidgetgroup_R->getBond()->getGlobalPixmap());
  687. break;
  688. }
  689. }
  690. }
  691. //判断左窗口是否为物料窗口
  692. if (m_nLastLastIndex == 2)
  693. {
  694. QSettings settings("YourOrganization", "YourApplication");
  695. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  696. int leftMaterialWndType = settings.value("MaterialWndType").toInt();
  697. settings.endGroup();
  698. switch (leftMaterialWndType)
  699. {
  700. case 1:
  701. {
  702. UpdateWafer(m_nLastLastGroupId);
  703. ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(m_nLastLastGroupId));
  704. m_allGroup[m_nLastLastGroupId - 1]->setWaferWidget(ui->viewwidgetgroup_L->getWafer()->getGlobalPixmap());
  705. break;
  706. }
  707. case 2:
  708. {
  709. UpdateWaffle(m_nLastLastGroupId);
  710. ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(m_nLastLastGroupId));
  711. m_allGroup[m_nLastLastGroupId - 1]->setWaffleWidget(ui->viewwidgetgroup_L->getWaffle()->getGlobalPixmap());
  712. break;
  713. }
  714. case 3:
  715. {
  716. UpdateMaterialBox(m_nLastLastGroupId);
  717. ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(m_nLastLastGroupId));
  718. m_allGroup[m_nLastLastGroupId - 1]->MaterialBoxWidget();
  719. break;
  720. }
  721. case 4:
  722. {
  723. UpdateBond(m_nLastLastGroupId);
  724. ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(m_nLastLastGroupId));
  725. m_allGroup[m_nLastLastGroupId - 1]->setBondWidget(ui->viewwidgetgroup_L->getBond()->getGlobalPixmap());
  726. break;
  727. }
  728. }
  729. }
  730. }
  731. void MainAndSecondaryCamerasWnd::UpdateWafer(int groupId) {
  732. if (m_pCViewInterface != nullptr)
  733. {
  734. std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT> veWafer;
  735. m_pCViewInterface->GetViewMatrix()->GetWaferAllPointInfo(veWafer);
  736. m_mapWaferMap.value(groupId)->UpdataVal(veWafer);
  737. m_mapWaferMap.value(groupId)->setWaferInfo(m_pCViewInterface);
  738. }
  739. else
  740. {
  741. m_mapWaferMap.value(groupId)->UpdataGenerateTestData();
  742. }
  743. }
  744. void MainAndSecondaryCamerasWnd::UpdateWaffle(int groupId) {
  745. if (m_pCViewInterface != nullptr)
  746. {
  747. std::vector<ns_mat::WAFFLE_MATRIX_POINT_STRUCT> veWaffle;
  748. m_pCViewInterface->GetViewMatrix()->GetWafflePackAllPointInfo(veWaffle);
  749. m_mapWaffleMap.value(groupId)->UpdataVal(veWaffle);
  750. }
  751. else
  752. {
  753. m_mapWaffleMap.value(groupId)->UpdataGenerateTestData();
  754. }
  755. }
  756. void MainAndSecondaryCamerasWnd::UpdateBond(int groupId) {
  757. if (m_pCViewInterface != nullptr)
  758. {
  759. std::vector<ns_mat::POINT_INFO_STRUCT> stPointInfo;
  760. m_pCViewInterface->GetViewMatrix()->GetBondAllPointInfo(stPointInfo);
  761. if (stPointInfo.size() > 0)
  762. {
  763. m_mapBondMap.value(groupId)->UpdataVal(stPointInfo);
  764. m_mapBondMap.value(groupId)->setBondInfo(m_pCViewInterface);
  765. }
  766. }
  767. else
  768. {
  769. m_mapBondMap.value(groupId)->UpdataGenerateTestData();
  770. }
  771. }
  772. void MainAndSecondaryCamerasWnd::UpdateMaterialBox(int groupId) {
  773. if (m_pCViewInterface != nullptr)
  774. {
  775. std::vector<ns_module::MATERIAL_BOX_STRUCT> veMaterial;
  776. m_pCViewInterface->GetViewMatrix()->GetMaterialBoxAllPointInfo(veMaterial);
  777. m_mapMaterialBoxMap.value(groupId)->UpdataVal(veMaterial);
  778. m_mapMaterialBoxMap.value(groupId)->setMaterialBoxInfo(m_pCViewInterface);
  779. }
  780. else
  781. {
  782. m_mapMaterialBoxMap.value(groupId)->UpdataGenerateTestData();
  783. }
  784. }
  785. void MainAndSecondaryCamerasWnd::TimerMaterialStart()
  786. {
  787. if (m_timerMaterial != nullptr)
  788. {
  789. m_timerMaterial->start();
  790. }
  791. }
  792. void MainAndSecondaryCamerasWnd::TimerMaterialStop()
  793. {
  794. if (m_timerMaterial != nullptr)
  795. {
  796. m_timerMaterial->stop();
  797. }
  798. }