ChartsAndCamerasWnd.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. #include "ChartsAndCamerasWnd.h"
  2. #include "ui_ChartsAndCamerasWnd.h"
  3. #include <QSettings>
  4. #include <QCloseEvent>
  5. #include <QVBoxLayout>
  6. #include <QTimer>
  7. #include "chartline.h"
  8. #include <QRandomGenerator>
  9. #include <QScrollBar>
  10. #include <qDebug>
  11. #include "CameraMaterialGroupWnd/CameraImage/CameraImageHandler.h"
  12. ChartsAndCamerasWnd::ChartsAndCamerasWnd(QWidget *parent) :
  13. JOriginalMainWnd(parent),
  14. ui(new Ui::ChartsAndCamerasWnd),
  15. chartLine(new ChartLine(this)),
  16. chartLine1(new ChartLine(this)),
  17. chartLine2(new ChartLine(this))
  18. {
  19. ui->setupUi(this);
  20. // 设置 ChartLine 的位置和大小
  21. chartLine->setParent(ui->Leftwidget);
  22. chartLine->setGeometry(0, 0, 560, 280);
  23. chartLine->setChartLabels("Combined Placement", "Number of Samples", "Device Align");
  24. // 设置 ChartLine1 的位置和大小
  25. chartLine1->setParent(ui->Leftwidget);
  26. chartLine1->setGeometry(0, 245, 560, 280);
  27. chartLine1->setChartLabels("Y placement", "Number of samples", "Y device align");
  28. // 设置 ChartLine2 的位置和大小
  29. chartLine2->setParent(ui->Leftwidget);
  30. chartLine2->setGeometry(0, 490, 560, 280);
  31. chartLine2->setChartLabels("Theta placement", "Number of samples", "Theta device align");
  32. // 初始化系列信息
  33. initializeSeriesInfo();
  34. // 连接所有复选框的 clicked 信号到通用槽函数
  35. QList<QCheckBox*> checkBoxes = {
  36. ui->GreenDiamondcheckBox,
  37. ui->YellowDiamondcheckBox,
  38. ui->BlackDiamondcheckBox,
  39. ui->BlueDiamondcheckBox,
  40. ui->BlueHorizontalLinecheckBox,
  41. ui->BlueVerticalBarcheckBox,
  42. ui->GreenVerticalBarcheckBox,
  43. ui->PurpleVerticalBarcheckBox,
  44. ui->RedDiamondcheckBox,
  45. ui->RedHorizontalLinecheckBox,
  46. ui->WhiteVerticalBarcheckBox
  47. };
  48. for (QCheckBox* cb : checkBoxes) {
  49. cb->setCheckable(true);
  50. //connect(cb, &QCheckBox::clicked, this, &ChartsAndCamerasWnd::on_CheckBox_clicked);
  51. }
  52. //initFrom();
  53. isShow = true;
  54. }
  55. ChartsAndCamerasWnd::~ChartsAndCamerasWnd()
  56. {
  57. m_pMainCameraBind = nullptr;
  58. delete ui;
  59. }
  60. void ChartsAndCamerasWnd::initializeSeriesInfo()
  61. {
  62. // 初始化系列信息,使用 DataSeries 结构体
  63. m_seriesMap["GreenDiamond"] = DataSeries{
  64. "GreenDiamond",
  65. QColor("#00FF00"), // 绿色
  66. QPixmap(":/images/Participation display/GreenDiamond.png"),
  67. QList<QPointF>() // 初始为空
  68. };
  69. m_seriesMap["YellowDiamond"] = DataSeries{
  70. "YellowDiamond",
  71. QColor("#FFFF00"), // 黄色
  72. QPixmap(":/images/Participation display/YellowDiamond.png"),
  73. QList<QPointF>()
  74. };
  75. m_seriesMap["BlackDiamond"] = DataSeries{
  76. "BlackDiamond",
  77. QColor("#000000"), // 黑色
  78. QPixmap(":/images/Participation display/BlackDiamond.png"),
  79. QList<QPointF>()
  80. };
  81. m_seriesMap["BlueDiamond"] = DataSeries{
  82. "BlueDiamond",
  83. QColor("#0000FF"), // 蓝色
  84. QPixmap(":/images/Participation display/BlueDiamond.png"),
  85. QList<QPointF>()
  86. };
  87. m_seriesMap["BlueHorizontalLine"] = DataSeries{
  88. "BlueHorizontalLine",
  89. QColor("#0000FF"),
  90. QPixmap(":/images/Participation display/Blue_horizontal_line.png"),
  91. QList<QPointF>()
  92. };
  93. m_seriesMap["BlueVerticalBar"] = DataSeries{
  94. "BlueVerticalBar",
  95. QColor("#0000FF"),
  96. QPixmap(":/images/Participation display/Blue_vertical_bar.png"),
  97. QList<QPointF>()
  98. };
  99. m_seriesMap["GreenVerticalBar"] = DataSeries{
  100. "GreenVerticalBar",
  101. QColor("#00FF00"),
  102. QPixmap(":/images/Participation display/Green_vertical_bar.png"),
  103. QList<QPointF>()
  104. };
  105. m_seriesMap["PurpleVerticalBar"] = DataSeries{
  106. "PurpleVerticalBar",
  107. QColor("#800080"),
  108. QPixmap(":/images/Participation display/Purple_vertical_bar.png"),
  109. QList<QPointF>()
  110. };
  111. m_seriesMap["RedDiamond"] = DataSeries{
  112. "RedDiamond",
  113. QColor("#FF0000"), // 红色
  114. QPixmap(":/images/Participation display/RedDiamond.png"),
  115. QList<QPointF>()
  116. };
  117. m_seriesMap["RedHorizontalLine"] = DataSeries{
  118. "RedHorizontalLine",
  119. QColor("#FF0000"),
  120. QPixmap(":/images/Participation display/Red_horizontal_line.png"),
  121. QList<QPointF>()
  122. };
  123. m_seriesMap["WhiteVerticalBar"] = DataSeries{
  124. "WhiteVerticalBar",
  125. QColor("#FFFFFF"), // 白色
  126. QPixmap(":/images/Participation display/White_vertical_bar.png"),
  127. QList<QPointF>()
  128. };
  129. }
  130. #if 0
  131. void ChartsAndCamerasWnd::on_CheckBox_clicked()
  132. {
  133. // 获取发送信号的复选框
  134. QCheckBox* checkBox = qobject_cast<QCheckBox*>(sender());
  135. if (!checkBox)
  136. return;
  137. QString checkBoxName = checkBox->objectName();
  138. QString seriesName = checkBoxName;
  139. // 移除末尾的 "checkBox"
  140. if (seriesName.endsWith("checkBox")) {
  141. seriesName.chop(QString("checkBox").length());
  142. } else if (seriesName.endsWith("CheckBox")) {
  143. seriesName.chop(QString("CheckBox").length());
  144. }
  145. qDebug() << "Checkbox clicked:" << seriesName << (checkBox->isChecked() ? "Checked" : "Unchecked");
  146. if (!m_seriesMap.contains(seriesName)) {
  147. qDebug() << "No series info for:" << seriesName;
  148. return;
  149. }
  150. DataSeries &seriesInfo = m_seriesMap[seriesName];
  151. if (checkBox->isChecked()) {
  152. // 生成随机数据
  153. QList<QPointF> data;
  154. for (int i = 0; i <= 40; i += 4) {
  155. data.append(QPointF(i, QRandomGenerator::global()->bounded(-30, 80)));
  156. }
  157. seriesInfo.data = data;
  158. // 添加到 ChartLine 实例
  159. chartLine->addDataSeries(seriesInfo);
  160. chartLine1->addDataSeries(seriesInfo);
  161. chartLine2->addDataSeries(seriesInfo);
  162. qDebug() << "Added series:" << seriesName;
  163. }
  164. else {
  165. // 从 ChartLine 实例中移除
  166. chartLine->removeDataSeries(seriesName);
  167. chartLine1->removeDataSeries(seriesName);
  168. chartLine2->removeDataSeries(seriesName);
  169. qDebug() << "Removed series:" << seriesName;
  170. }
  171. }
  172. #endif
  173. void ChartsAndCamerasWnd::initFrom() {
  174. checkSettings();
  175. QWidget *viewport = ui->scrollArea->viewport();
  176. QWidget *container = new QWidget(viewport);
  177. QHBoxLayout *layout = new QHBoxLayout(container);
  178. layout->setSpacing(16); // 设置Group之间的间隔距离
  179. layout->setMargin(0);
  180. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  181. QList<Group*> widgets;
  182. for (int i = 0; i < numbers.size(); ++i)
  183. {
  184. int num = numbers[i];
  185. CameraImageHandler* manager = new CameraImageHandler(num);
  186. Group* widget = manager->getGroup();
  187. //connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide);
  188. if (widget != nullptr)
  189. {
  190. connect(widget, &Group::sendUpdateGroupState,
  191. this, &ChartsAndCamerasWnd::checkSettings);
  192. layout->addWidget(widget);
  193. widgets.append(widget);
  194. }
  195. if(manager->getWafer())
  196. {
  197. waferMap.insert(num, manager->getWafer());
  198. }
  199. if(manager->getWafer())
  200. {
  201. waffleMap.insert(num, manager->getWaffle());
  202. }
  203. if(manager->getMaterialBox())
  204. {
  205. materialBoxMap.insert(num,manager->getMaterialBox());
  206. }
  207. delete manager;
  208. }
  209. // 设置控件的最小高度和最大宽度
  210. int minHeight = 162;
  211. int maxWidth = 244;
  212. int num = -16;
  213. for (Group* w : widgets) {
  214. w->setMinimumHeight(minHeight);
  215. w->setMaximumWidth(maxWidth);
  216. num = num + 260;
  217. }
  218. container->setMinimumSize(num, 162);
  219. container->setLayout(layout);
  220. ui->scrollArea->setWidget(container);
  221. ui->scrollArea->resize(508, 177);
  222. checkSettings();
  223. }
  224. void ChartsAndCamerasWnd::checkSettings() {
  225. QSettings settings("YourCompany", "YourApplication_");
  226. int groupId = settings.value("GroupId", 0).toInt();
  227. int index = settings.value("Index", 0).toInt();
  228. if (groupId != lastGroupId || index != lastIndex) {
  229. lastGroupId = groupId;
  230. lastIndex = index;
  231. loadSettings();
  232. }
  233. }
  234. void ChartsAndCamerasWnd::loadSettings()
  235. {
  236. QSettings settings("YourCompany", "YourApplication_");
  237. int groupId = settings.value("GroupId", 0).toInt();
  238. int index = settings.value("Index", 0).toInt();
  239. loadGroupSettings(groupId, index);
  240. }
  241. void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
  242. QSettings settings("YourOrganization", "YourApplication");
  243. settings.beginGroup(QString::number(Id));
  244. QString imagePath = settings.value("ImagePath1").toString();
  245. int materialWndType = settings.value("MaterialWndType").toInt();
  246. QStringList textList = settings.value("TextList").toStringList();
  247. settings.endGroup();
  248. QPixmap newPixmap;
  249. // 判断是实时图片还是物料窗口
  250. if (Index == 1) {
  251. newPixmap = QPixmap(imagePath);
  252. ui->viewwidgetgroup->updateOperateWidget(newPixmap);
  253. ui->viewwidgetgroup->setEnableControls(true);
  254. }else if (Index == 2) {
  255. updateMaterialWidget(materialWndType, Id);
  256. ui->viewwidgetgroup->setEnableControls(false);
  257. }
  258. }
  259. void ChartsAndCamerasWnd::updateMaterialWidget( int materialWndType, int groupId){
  260. switch (materialWndType) {
  261. case 1: ui->viewwidgetgroup->setWafer(waferMap.value(lastGroupId)); break;
  262. case 2: ui->viewwidgetgroup->setWaffle(waffleMap.value(lastGroupId)); break;
  263. case 3: ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(lastGroupId)); break;
  264. }
  265. }
  266. void ChartsAndCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  267. {
  268. m_pMainCameraBind = pCameraBind;
  269. initFrom();
  270. }
  271. void ChartsAndCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  272. {
  273. }
  274. void ChartsAndCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  275. {
  276. }
  277. void ChartsAndCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  278. {
  279. }
  280. void ChartsAndCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  281. {
  282. }
  283. void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  284. {
  285. }
  286. //void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  287. //{
  288. //
  289. //}
  290. void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
  291. {
  292. mousePos = ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos());
  293. if (ui->viewwidgetgroup->getOperatewidget()->rect().contains(ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  294. if (event->angleDelta().y() > 0) {
  295. ui->viewwidgetgroup->updateScale(scaleFactor * 1.1); // 放大
  296. } else {
  297. ui->viewwidgetgroup->updateScale(scaleFactor * 0.9); // 缩小
  298. }
  299. }
  300. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  301. // 获取 QScrollArea 的横向滚动条
  302. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  303. // 根据滚轮滚动方向改变滚动条的值
  304. if (event->angleDelta().y() > 0) {
  305. scrollBar->setValue(scrollBar->value() - 50);
  306. } else {
  307. scrollBar->setValue(scrollBar->value() + 50);
  308. }
  309. }
  310. QMainWindow::wheelEvent(event);
  311. }
  312. void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
  313. QMainWindow::showEvent(event);
  314. loadSettings();
  315. // initFrom();
  316. }
  317. void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
  318. QMainWindow::hideEvent(event);
  319. }