MainAndSecondaryCamerasWnd.cpp 34 KB

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