MainAndSecondaryCamerasWnd.cpp 28 KB

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