MainAndSecondaryCamerasWnd.cpp 33 KB

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