MainAndSecondaryCamerasWnd.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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_WAFER;
  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. QPixmap pixmap_L = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  259. GetGroupImageShowSignalsTo_L(pixmap_L);
  260. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  261. ui->viewwidgetgroup_L->setEnableControls(true);
  262. }
  263. }
  264. else {
  265. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  266. ui->viewwidgetgroup_R->setEnableControls(true);
  267. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  268. ui->viewwidgetgroup_L->setEnableControls(false);
  269. }
  270. }
  271. else {
  272. m_veCurrentSelectGroup_L.pSelectGroup = m_allGroup.at(lastLastGroupId - 1);
  273. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(lastGroupId - 1);
  274. m_veCurrentSelectGroup_L.pSelectGroup->initBorderStyle(lastLastIndex, 0);
  275. m_veCurrentSelectGroup_R.pSelectGroup->initBorderStyle(lastIndex, 1);
  276. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  277. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId],currentLeftComboBoxIndex);
  278. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  279. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId],currentRightComboBoxIndex);
  280. if (lastLastIndex == 1) {
  281. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  282. ui->viewwidgetgroup_L->setEnableControls(true);
  283. QPixmap pixmap_L = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  284. GetGroupImageShowSignalsTo_L(pixmap_L);
  285. }
  286. else {
  287. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  288. ui->viewwidgetgroup_L->setEnableControls(false);
  289. }
  290. if (lastIndex == 1) {
  291. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  292. ui->viewwidgetgroup_R->setEnableControls(true);
  293. QPixmap pixmap_R = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(currentRightComboBoxIndex);
  294. GetGroupImageShowSignalsTo_R(pixmap_R);
  295. }
  296. else {
  297. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  298. ui->viewwidgetgroup_R->setEnableControls(false);
  299. }
  300. }
  301. m_timerMaterial->start(5000);
  302. }
  303. void MainAndSecondaryCamerasWnd::BindImageOrMaterial(int location, int index)
  304. {
  305. if (location == m_nLastLeft)
  306. {
  307. if (index == m_nImageIndex)
  308. {
  309. m_veCurrentSelectGroup_L.isBond = true;
  310. connect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  311. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  312. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, true);
  313. }
  314. else
  315. {
  316. //左边更新物料窗口
  317. QSettings settings("YourOrganization", "YourApplication");
  318. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  319. int lastMaterialWndType = settings.value("MaterialWndType").toInt();
  320. settings.endGroup();
  321. m_veCurrentSelectGroup_L.isBond = false;
  322. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId, 1, false);
  323. updateMaterialWidget(m_nLastLeft, lastMaterialWndType, m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId);
  324. }
  325. }
  326. else
  327. {
  328. if (index == m_nImageIndex)
  329. {
  330. m_veCurrentSelectGroup_R.isBond = true;
  331. connect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  332. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  333. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, true);
  334. }
  335. else
  336. {
  337. //右边更新物料窗口
  338. QSettings settings("YourOrganization", "YourApplication");
  339. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  340. int materialWndType = settings.value("MaterialWndType").toInt();
  341. settings.endGroup();
  342. m_veCurrentSelectGroup_R.isBond = false;
  343. UpdataLightJoystickSwitchPage(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId, 2, false);
  344. updateMaterialWidget(m_nCurrentRight, materialWndType, m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId);
  345. }
  346. }
  347. }
  348. void MainAndSecondaryCamerasWnd::checkSettings(int groupId, int index) {
  349. if (groupId != lastGroupId || index != lastIndex) {
  350. GetCurrentSelectSlots(groupId, index);
  351. lastLastGroupId = lastGroupId;
  352. lastLastIndex = lastIndex;
  353. lastGroupId = groupId;
  354. lastIndex = index;
  355. saveInfoOfLast();
  356. }
  357. }
  358. void MainAndSecondaryCamerasWnd::saveInfoOfLast() {
  359. QSettings settings("YourOrganization", "YourApplication");
  360. settings.setValue("DoubleLastIndex", lastIndex);
  361. settings.setValue("DoubleLastGroupId", lastGroupId);
  362. settings.setValue("DoubleLastLastIndex", lastLastIndex);
  363. settings.setValue("DoubleLastLastGroupId", lastLastGroupId);
  364. }
  365. void MainAndSecondaryCamerasWnd::updateMaterialWidget(int side, int materialWndType, int groupId) {
  366. if (side == m_nLastLeft) {
  367. switch (materialWndType) {
  368. case 1: ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(groupId)); break;
  369. case 2: ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(groupId)); break;
  370. case 3: ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  371. case 4: ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(groupId)); break;
  372. }
  373. }
  374. else if (side == m_nCurrentRight) {
  375. switch (materialWndType) {
  376. case 1: ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(groupId)); break;
  377. case 2: ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(groupId)); break;
  378. case 3: ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(groupId)); break;
  379. case 4: ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(groupId)); break;
  380. }
  381. }
  382. }
  383. void MainAndSecondaryCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  384. {
  385. m_pMainCameraBind = pCameraBind;
  386. initFrom();
  387. }
  388. void MainAndSecondaryCamerasWnd::UnCameraBind()
  389. {
  390. for (size_t i = 0; i < m_allGroup.size(); i++)
  391. {
  392. CameraConnectUpdateImageFun(i, m_allGroup[i], true);
  393. }
  394. }
  395. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  396. {
  397. // TODO: 这里需要改动
  398. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  399. ui->viewwidgetgroup_L->getOperatewidget()->setGeometry(ui->viewwidgetgroup_L->getOperatewidget()->pos().x(),
  400. ui->viewwidgetgroup_L->getOperatewidget()->pos().y(),
  401. ui->viewwidgetgroup_L->getOperatewidget()->width(),
  402. ui->viewwidgetgroup_L->getOperatewidget()->height());
  403. //ui->LeftOperatewidget->setPixmap(QPixmap::fromImage(image));
  404. emit UpDataImageShowSignals0(QPixmap::fromImage(image));
  405. }
  406. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  407. {
  408. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  409. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  410. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  411. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  412. ui->viewwidgetgroup_R->getOperatewidget()->height());
  413. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  414. emit UpDataImageShowSignals1(QPixmap::fromImage(image));
  415. }
  416. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  417. {
  418. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  419. emit UpDataImageShowSignals2(QPixmap::fromImage(image));
  420. }
  421. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  422. {
  423. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  424. emit UpDataImageShowSignals3(QPixmap::fromImage(image));
  425. }
  426. void MainAndSecondaryCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  427. {
  428. QImage image(imageData.data, imageData.width, imageData.height, QImage::Format_Indexed8);
  429. ui->viewwidgetgroup_R->getOperatewidget()->setGeometry(ui->viewwidgetgroup_R->getOperatewidget()->pos().x(),
  430. ui->viewwidgetgroup_R->getOperatewidget()->pos().y(),
  431. ui->viewwidgetgroup_R->getOperatewidget()->width(),
  432. ui->viewwidgetgroup_R->getOperatewidget()->height());
  433. //ui->RightOperatewidget->setPixmap(QPixmap::fromImage(image));
  434. emit UpDataImageShowSignals4(QPixmap::fromImage(image));
  435. }
  436. void MainAndSecondaryCamerasWnd::HideLayout(QHBoxLayout* layout, bool isHide)
  437. {
  438. for (int i = 0; i < layout->count(); ++i)
  439. {
  440. QWidget* widget = layout->itemAt(i)->widget();
  441. if (widget)
  442. {
  443. if (isHide)
  444. {
  445. widget->hide();
  446. }
  447. else
  448. {
  449. widget->show();
  450. }
  451. }
  452. }
  453. }
  454. void MainAndSecondaryCamerasWnd::UpdataLightJoystickSwitchPage(int groupId, int index, bool isShow)
  455. {
  456. auto Fun = [&](Group* pGroup, LightJoystickSwitchPage* p, ControlOperationPage* pContPage, bool bShow)
  457. {
  458. p->UpdatemPageGroup(pGroup);
  459. p->InitMainCameraBind(m_pMainCameraBind, bShow);
  460. p->HideOrShowPage(bShow);
  461. if (bShow)
  462. {
  463. pContPage->UpDateCameraBind(m_pMainCameraBind);
  464. }
  465. else
  466. {
  467. pContPage->setSwitchJoystickButEnable(bShow);
  468. }
  469. };
  470. if (index == 1)
  471. {
  472. disconnect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  473. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  474. Group* currGroup = m_allGroup.at(groupId - 1);
  475. Fun(currGroup, ui->control_L, ui->viewwidgetgroup_L, isShow);
  476. connect(ui->viewwidgetgroup_L, &ControlOperationPage::SendModuleTypeSignals,
  477. ui->control_L, &LightJoystickSwitchPage::GetModuleTypeSlots);
  478. }
  479. else if (index == 2)
  480. {
  481. disconnect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  482. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  483. Group* currGroup = m_allGroup.at(groupId - 1);
  484. Fun(currGroup, ui->control_r, ui->viewwidgetgroup_R, isShow);
  485. connect(ui->viewwidgetgroup_R, &ControlOperationPage::SendModuleTypeSignals,
  486. ui->control_r, &LightJoystickSwitchPage::GetModuleTypeSlots);
  487. }
  488. }
  489. void MainAndSecondaryCamerasWnd::timerEvent(QTimerEvent* event)
  490. {
  491. int nID = event->timerId();
  492. }
  493. void MainAndSecondaryCamerasWnd::GetCurrentSelectSlots(int groupId, int nIndex)
  494. {
  495. int nOnClickGroupId = groupId - 1; // 这里new 有些是0,有些是1 暂时选择
  496. if (m_pMainCameraBind == nullptr || m_allGroup.size() < groupId)
  497. {
  498. return;
  499. }
  500. //判断更新前的左窗口是否是绑定相机
  501. if (m_veCurrentSelectGroup_L.isBond == true) {
  502. disconnect(m_veCurrentSelectGroup_L.pSelectGroup, &Group::SetUpDataImageShowSig,
  503. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L);
  504. }
  505. //判断更新前的右窗口是否是绑定相机
  506. if (m_veCurrentSelectGroup_R.isBond == true) {
  507. //解绑
  508. disconnect(m_veCurrentSelectGroup_R.pSelectGroup, &Group::SetUpDataImageShowSig,
  509. this, &MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R);
  510. }
  511. m_veCurrentSelectGroup_L = m_veCurrentSelectGroup_R;
  512. //判断更新前的右窗口的index是相机还是物料
  513. int currentLeftComboBoxIndex = m_veCurrentSelectGroup_L.pSelectGroup->getCurrentComboBoxIndex();
  514. ui->viewwidgetgroup_L->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId], currentLeftComboBoxIndex);
  515. if (lastIndex == 1) {
  516. //左窗口绑定
  517. //更新左边的下拉框内容同步小窗口索引
  518. ui->viewwidgetgroup_L->setEnableControls(true);
  519. BindImageOrMaterial(m_nLastLeft, m_nImageIndex);
  520. QPixmap pixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(currentLeftComboBoxIndex);
  521. GetGroupImageShowSignalsTo_L(pixmap);
  522. }
  523. else {
  524. ui->viewwidgetgroup_L->setEnableControls(false);
  525. BindImageOrMaterial(m_nLastLeft, m_nMaterialIndex);
  526. }
  527. //右边更新物料窗口
  528. m_veCurrentSelectGroup_R.pSelectGroup = m_allGroup.at(nOnClickGroupId);
  529. //判断当前index是相机还是物料
  530. int currentRightComboBoxIndex = m_veCurrentSelectGroup_R.pSelectGroup->getCurrentComboBoxIndex();
  531. ui->viewwidgetgroup_R->setComboBox(m_mapFileListMap[m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId], currentRightComboBoxIndex);
  532. if (nIndex == 2) {
  533. ui->viewwidgetgroup_R->setEnableControls(false);
  534. BindImageOrMaterial(m_nCurrentRight, m_nMaterialIndex);
  535. }
  536. else if (nIndex == 1) {//当前切换时相机序号
  537. ui->viewwidgetgroup_R->setEnableControls(true);
  538. BindImageOrMaterial(m_nCurrentRight, m_nImageIndex);
  539. QPixmap pixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(currentRightComboBoxIndex);
  540. GetGroupImageShowSignalsTo_R(pixmap);
  541. }
  542. }
  543. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_L(const QPixmap& imageData)
  544. {
  545. QSize size_left = ui->viewwidgetgroup_L->getOperatewidget()->size();
  546. QPixmap scaledPixmap_left = m_lastRightPixmap.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  547. ui->viewwidgetgroup_L->setScaleFactorSize(scaledPixmap_left);
  548. m_lastRightPixmap = imageData;
  549. }
  550. void MainAndSecondaryCamerasWnd::GetGroupImageShowSignalsTo_R(const QPixmap& imageData)
  551. {
  552. QSize size_left = ui->viewwidgetgroup_R->getOperatewidget()->size();
  553. QPixmap scaledPixmap_right = imageData.scaled(size_left, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  554. ui->viewwidgetgroup_R->setScaleFactorSize(scaledPixmap_right);
  555. m_lastRightPixmap = imageData;
  556. }
  557. void MainAndSecondaryCamerasWnd::wheelEvent(QWheelEvent* event)
  558. {
  559. //if (ui->viewwidgetgroup_L->getOperatewidget()->rect().contains(ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  560. // mousePos = ui->viewwidgetgroup_L->getOperatewidget()->mapFromGlobal(event->globalPos());
  561. // if (event->angleDelta().y() > 0) {
  562. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 1.1); // 放大
  563. // } else {
  564. // ui->viewwidgetgroup_L->updateScale(Left_scaleFactor * 0.9); // 缩小
  565. // }
  566. //}
  567. //if (ui->viewwidgetgroup_R->getOperatewidget()->rect().contains(ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  568. // mousePos = ui->viewwidgetgroup_R->getOperatewidget()->mapFromGlobal(event->globalPos());
  569. // if (event->angleDelta().y() > 0) {
  570. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 1.1); // 放大
  571. // } else {
  572. // ui->viewwidgetgroup_R->updateScale(Right_scaleFactor * 0.9); // 缩小
  573. // }
  574. //}
  575. //if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  576. // // 获取 QScrollArea 的横向滚动条
  577. // QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  578. // // 根据滚轮滚动方向改变滚动条的值
  579. // if (event->angleDelta().y() > 0) {
  580. // scrollBar->setValue(scrollBar->value() - 50);
  581. // } else {
  582. // scrollBar->setValue(scrollBar->value() + 50);
  583. // }
  584. //}
  585. QMainWindow::wheelEvent(event);
  586. }
  587. void MainAndSecondaryCamerasWnd::showEvent(QShowEvent* event) {
  588. isUpdatingSettings = false;
  589. QMainWindow::showEvent(event);
  590. isUpdatingSettings = false;
  591. }
  592. void MainAndSecondaryCamerasWnd::hideEvent(QHideEvent* event) {
  593. isUpdatingSettings = false;
  594. QMainWindow::hideEvent(event);
  595. }
  596. void MainAndSecondaryCamerasWnd::GetGroupComboxChanged(int groupId,int comboxIndex){
  597. m_allGroup.at(groupId - 1);
  598. if(comboxIndex == 0){
  599. CameraConnectUpdateImageFun(groupId - 1,m_allGroup.at(groupId - 1),false);
  600. }else{
  601. CameraConnectUpdateImageFun(groupId - 1,m_allGroup.at(groupId - 1),true);
  602. }
  603. m_allGroup.at(groupId - 1)->setCurrentCombox(comboxIndex);
  604. if(groupId == m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId && lastLastIndex == 1){
  605. if(comboxIndex != 0){//图片
  606. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(comboxIndex);
  607. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  608. }
  609. }else if(groupId == m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId && lastIndex == 1){
  610. if(comboxIndex != 0){//图片
  611. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(comboxIndex);
  612. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  613. }
  614. }
  615. }
  616. void MainAndSecondaryCamerasWnd::HandleComboxchange_L(int index) {
  617. if (index == 0) {
  618. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId-1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), false);
  619. }
  620. else {
  621. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId - 1), true);
  622. QPixmap updatePixmap = ui->viewwidgetgroup_L->getCurrentComboBoxPixmap(index);
  623. m_veCurrentSelectGroup_L.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  624. }
  625. }
  626. void MainAndSecondaryCamerasWnd::HandleComboxchange_R(int index) {
  627. if (index == 0) {
  628. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), false);
  629. }
  630. else {
  631. CameraConnectUpdateImageFun(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1, m_allGroup.at(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId - 1), true);
  632. QPixmap updatePixmap = ui->viewwidgetgroup_R->getCurrentComboBoxPixmap(index);
  633. m_veCurrentSelectGroup_R.pSelectGroup->UpDataImageShowSlots(updatePixmap);
  634. }
  635. }
  636. void MainAndSecondaryCamerasWnd::UpdateMaterialByTimer() {
  637. qDebug() << "Qtimer test";
  638. //判断当前大窗口是否是物料窗口
  639. //判断右窗口是否为物料窗口
  640. if (lastIndex == 2) {
  641. QSettings settings("YourOrganization", "YourApplication");
  642. settings.beginGroup(QString::number(m_veCurrentSelectGroup_R.pSelectGroup->m_nGroupId));
  643. int rightMaterialWndType = settings.value("MaterialWndType").toInt();
  644. settings.endGroup();
  645. switch (rightMaterialWndType) {
  646. case 1:
  647. {
  648. UpdateWafer(lastGroupId);
  649. ui->viewwidgetgroup_R->setWafer(m_mapWaferMap.value(lastGroupId));
  650. m_allGroup[lastGroupId-1]->setWaferWidget(ui->viewwidgetgroup_R->getWafer()->getGlobalPixmap());
  651. break;
  652. }
  653. case 2:
  654. {
  655. UpdateWaffle(lastGroupId);
  656. ui->viewwidgetgroup_R->setWaffle(m_mapWaffleMap.value(lastGroupId));
  657. m_allGroup[lastGroupId - 1]->setWaffleWidget(ui->viewwidgetgroup_R->getWaffle()->getGlobalPixmap());
  658. break;
  659. }
  660. case 3:
  661. {
  662. UpdateMaterialBox(lastGroupId);
  663. ui->viewwidgetgroup_R->setMaterialBox(m_mapMaterialBoxMap.value(lastGroupId));
  664. m_allGroup[lastGroupId - 1]->MaterialBoxWidget();
  665. break;
  666. }
  667. case 4:
  668. {
  669. UpdateBond(lastGroupId);
  670. ui->viewwidgetgroup_R->setBond(m_mapBondMap.value(lastGroupId));
  671. m_allGroup[lastGroupId - 1]->setBondWidget(ui->viewwidgetgroup_R->getBond()->getGlobalPixmap());
  672. break;
  673. }
  674. }
  675. }
  676. //判断左窗口是否为物料窗口
  677. if (lastLastIndex == 2) {
  678. QSettings settings("YourOrganization", "YourApplication");
  679. settings.beginGroup(QString::number(m_veCurrentSelectGroup_L.pSelectGroup->m_nGroupId));
  680. int leftMaterialWndType = settings.value("MaterialWndType").toInt();
  681. settings.endGroup();
  682. switch (leftMaterialWndType) {
  683. case 1:
  684. {
  685. UpdateWafer(lastLastGroupId);
  686. ui->viewwidgetgroup_L->setWafer(m_mapWaferMap.value(lastLastGroupId));
  687. m_allGroup[lastLastGroupId - 1]->setWaferWidget(ui->viewwidgetgroup_L->getWafer()->getGlobalPixmap());
  688. break;
  689. }
  690. case 2:
  691. {
  692. UpdateWaffle(lastLastGroupId);
  693. ui->viewwidgetgroup_L->setWaffle(m_mapWaffleMap.value(lastLastGroupId));
  694. m_allGroup[lastLastGroupId - 1]->setWaffleWidget(ui->viewwidgetgroup_L->getWaffle()->getGlobalPixmap());
  695. break;
  696. }
  697. case 3:
  698. {
  699. UpdateMaterialBox(lastLastGroupId);
  700. ui->viewwidgetgroup_L->setMaterialBox(m_mapMaterialBoxMap.value(lastLastGroupId));
  701. m_allGroup[lastLastGroupId - 1]->MaterialBoxWidget();
  702. break;
  703. }
  704. case 4:
  705. {
  706. UpdateBond(lastLastGroupId);
  707. ui->viewwidgetgroup_L->setBond(m_mapBondMap.value(lastLastGroupId));
  708. m_allGroup[lastLastGroupId - 1]->setBondWidget(ui->viewwidgetgroup_L->getBond()->getGlobalPixmap());
  709. break;
  710. }
  711. }
  712. }
  713. }
  714. void MainAndSecondaryCamerasWnd::UpdateWafer(int groupId) {
  715. if (m_pCViewInterface != nullptr)
  716. {
  717. std::vector<ns_mat::WAFER_MATRIX_POINT_INFO_STRUCT> veWafer;
  718. m_pCViewInterface->GetViewMatrix()->GetWaferAllPointInfo(veWafer);
  719. m_mapWaferMap.value(groupId)->UpdataVal(veWafer);
  720. m_mapWaferMap.value(groupId)->setWaferInfo(m_pCViewInterface);
  721. }
  722. else
  723. {
  724. m_mapWaferMap.value(groupId)->UpdataGenerateTestData();
  725. }
  726. }
  727. void MainAndSecondaryCamerasWnd::UpdateWaffle(int groupId) {
  728. if (m_pCViewInterface != nullptr)
  729. {
  730. std::vector<ns_mat::WAFFLE_MATRIX_POINT_STRUCT> veWaffle;
  731. m_pCViewInterface->GetViewMatrix()->GetWafflePackAllPointInfo(veWaffle);
  732. m_mapWaffleMap.value(groupId)->UpdataVal(veWaffle);
  733. }
  734. else
  735. {
  736. m_mapWaffleMap.value(groupId)->UpdataGenerateTestData();
  737. }
  738. }
  739. void MainAndSecondaryCamerasWnd::UpdateBond(int groupId) {
  740. if (m_pCViewInterface != nullptr)
  741. {
  742. std::vector<ns_mat::POINT_INFO_STRUCT> stPointInfo;
  743. m_pCViewInterface->GetViewMatrix()->GetBondAllPointInfo(stPointInfo);
  744. m_mapBondMap.value(groupId)->UpdataVal(stPointInfo);
  745. m_mapBondMap.value(groupId)->setBondInfo(m_pCViewInterface);
  746. }
  747. else
  748. {
  749. m_mapBondMap.value(groupId)->UpdataGenerateTestData();
  750. }
  751. }
  752. void MainAndSecondaryCamerasWnd::UpdateMaterialBox(int groupId) {
  753. if (m_pCViewInterface != nullptr)
  754. {
  755. std::vector<ns_module::MATERIAL_BOX_STRUCT> veMaterial;
  756. m_pCViewInterface->GetViewMatrix()->GetMaterialBoxAllPointInfo(veMaterial);
  757. m_mapMaterialBoxMap.value(groupId)->UpdataVal(veMaterial);
  758. m_mapMaterialBoxMap.value(groupId)->setMaterialBoxInfo(m_pCViewInterface);
  759. }
  760. else
  761. {
  762. m_mapMaterialBoxMap.value(groupId)->UpdataGenerateTestData();
  763. }
  764. }
  765. void MainAndSecondaryCamerasWnd::TimerMaterialStart() {
  766. if (m_timerMaterial != nullptr) {
  767. m_timerMaterial->start();
  768. }
  769. }
  770. void MainAndSecondaryCamerasWnd::TimerMaterialStop() {
  771. if (m_timerMaterial != nullptr) {
  772. m_timerMaterial->stop();
  773. }
  774. }