ChartsAndCamerasWnd.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. QTimer *timer = new QTimer(this);
  175. connect(timer, &QTimer::timeout, this, &ChartsAndCamerasWnd::checkSettings);
  176. timer->start(100);
  177. QWidget *viewport = ui->scrollArea->viewport();
  178. QWidget *container = new QWidget(viewport);
  179. QHBoxLayout *layout = new QHBoxLayout(container);
  180. layout->setSpacing(16); // 设置Group之间的间隔距离
  181. layout->setMargin(0);
  182. QList<int> numbers = {1, 2, 3, 4, 5, 6, 7, 8};
  183. QList<Group*> widgets;
  184. for (int i = 0; i < numbers.size(); ++i)
  185. {
  186. int num = numbers[i];
  187. CameraImageHandler* manager = new CameraImageHandler(num);
  188. Group* widget = manager->getGroup();
  189. //connect(widget,&Group::send_button_Signal,this,&ChartsAndCamerasWnd::showAndHide);
  190. if (widget != nullptr)
  191. {
  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. }
  223. void ChartsAndCamerasWnd::checkSettings() {
  224. QSettings settings("YourCompany", "YourApplication_");
  225. int groupId = settings.value("GroupId", 0).toInt();
  226. int index = settings.value("Index", 0).toInt();
  227. if (groupId != lastGroupId || index != lastIndex) {
  228. lastGroupId = groupId;
  229. lastIndex = index;
  230. loadSettings();
  231. }
  232. }
  233. void ChartsAndCamerasWnd::loadSettings()
  234. {
  235. QSettings settings("YourCompany", "YourApplication_");
  236. int groupId = settings.value("GroupId", 0).toInt();
  237. int index = settings.value("Index", 0).toInt();
  238. loadGroupSettings(groupId, index);
  239. }
  240. void ChartsAndCamerasWnd::loadGroupSettings(int Id, int Index) {
  241. QSettings settings("YourOrganization", "YourApplication");
  242. settings.beginGroup(QString::number(Id));
  243. QString imagePath = settings.value("ImagePath1").toString();
  244. int materialWndType = settings.value("MaterialWndType").toInt();
  245. QStringList textList = settings.value("TextList").toStringList();
  246. settings.endGroup();
  247. QPixmap newPixmap;
  248. // 判断是实时图片还是物料窗口
  249. if (Index == 1) {
  250. newPixmap = QPixmap(imagePath);
  251. QStringList test = { "1","2" };
  252. ui->viewwidgetgroup->updateOperateWidget(newPixmap, test);
  253. }else if (Index == 2) {
  254. updateMaterialWidget(materialWndType, Id);
  255. }
  256. }
  257. void ChartsAndCamerasWnd::updateMaterialWidget( int materialWndType, int groupId){
  258. switch (materialWndType) {
  259. case 1: ui->viewwidgetgroup->setWafer(waferMap.value(lastGroupId)); break;
  260. case 2: ui->viewwidgetgroup->setWaffle(waffleMap.value(lastGroupId)); break;
  261. case 3: ui->viewwidgetgroup->setMaterialBox(materialBoxMap.value(lastGroupId)); break;
  262. }
  263. }
  264. void ChartsAndCamerasWnd::InitMainCameraBind(CameraBind* pCameraBind)
  265. {
  266. m_pMainCameraBind = pCameraBind;
  267. initFrom();
  268. }
  269. void ChartsAndCamerasWnd::UpdateCameraDisplay0(int iCameraId, JVision::ImageInfo imageData)
  270. {
  271. }
  272. void ChartsAndCamerasWnd::UpdateCameraDisplay1(int iCameraId, JVision::ImageInfo imageData)
  273. {
  274. }
  275. void ChartsAndCamerasWnd::UpdateCameraDisplay2(int iCameraId, JVision::ImageInfo imageData)
  276. {
  277. }
  278. void ChartsAndCamerasWnd::UpdateCameraDisplay3(int iCameraId, JVision::ImageInfo imageData)
  279. {
  280. }
  281. void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  282. {
  283. }
  284. //void ChartsAndCamerasWnd::UpdateCameraDisplay4(int iCameraId, JVision::ImageInfo imageData)
  285. //{
  286. //
  287. //}
  288. void ChartsAndCamerasWnd::wheelEvent(QWheelEvent *event)
  289. {
  290. mousePos = ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos());
  291. if (ui->viewwidgetgroup->getOperatewidget()->rect().contains(ui->viewwidgetgroup->getOperatewidget()->mapFromGlobal(event->globalPos()))) {
  292. if (event->angleDelta().y() > 0) {
  293. ui->viewwidgetgroup->updateScale(scaleFactor * 1.1); // 放大
  294. } else {
  295. ui->viewwidgetgroup->updateScale(scaleFactor * 0.9); // 缩小
  296. }
  297. }
  298. if (ui->scrollArea->rect().contains(ui->scrollArea->mapFromGlobal(event->globalPos()))) {
  299. // 获取 QScrollArea 的横向滚动条
  300. QScrollBar *scrollBar = ui->scrollArea->horizontalScrollBar();
  301. // 根据滚轮滚动方向改变滚动条的值
  302. if (event->angleDelta().y() > 0) {
  303. scrollBar->setValue(scrollBar->value() - 50);
  304. } else {
  305. scrollBar->setValue(scrollBar->value() + 50);
  306. }
  307. }
  308. QMainWindow::wheelEvent(event);
  309. }
  310. void ChartsAndCamerasWnd::showEvent(QShowEvent *event) {
  311. QMainWindow::showEvent(event);
  312. loadSettings();
  313. // initFrom();
  314. }
  315. void ChartsAndCamerasWnd::hideEvent(QHideEvent *event) {
  316. QMainWindow::hideEvent(event);
  317. }