MainAndSecondaryCamerasWnd.cpp 34 KB

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