MainAndSecondaryCamerasWnd.cpp 35 KB

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