From 5372a7806c7d4d3612802d8f823756771866f5d9 Mon Sep 17 00:00:00 2001 From: tangchao0503 <735056338@qq.com> Date: Wed, 17 Jun 2026 11:40:01 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=8C=E8=AE=A1=E5=88=92=E9=87=87?= =?UTF-8?q?=E9=9B=8615=EF=BC=9A=20=E4=BC=98=E5=8C=96=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E9=87=87=E9=9B=86=EF=BC=9A=E7=95=8C=E9=9D=A2=E5=92=8C=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + HPPA/HPPA.cpp | 45 ++++++++++++++---------- HPPA/HPPA.h | 2 ++ HPPA/TaskTreeModel.cpp | 11 +++++- HPPA/TaskTreeModel.h | 1 + HPPA/TimedDataCollection.cpp | 62 ++++++++++++++++++++-------------- HPPA/TimedDataCollection.h | 3 ++ HPPA/TimedDataCollection_ui.ui | 17 ++++------ HPPA/TwoMotorControl.cpp | 15 ++++++-- HPPA/TwoMotorControl.h | 2 ++ 10 files changed, 102 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index cf9ac81..159d626 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ HPPA - 副本.ui icon ignore_* resources +*.bkp ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. diff --git a/HPPA/HPPA.cpp b/HPPA/HPPA.cpp index a1c78b5..68eda71 100644 --- a/HPPA/HPPA.cpp +++ b/HPPA/HPPA.cpp @@ -593,26 +593,35 @@ HPPA::HPPA(QWidget* parent) void HPPA::initTimedDataCollection() { - TimedDataCollection mTimedDataCollectionWindow; + if (m_tdc) + { + m_tdc->show(); + m_tdc->activateWindow(); + return; + } - m_tmc->onConnectMotor(); + m_tdc = new TimedDataCollection(this); + + m_tdc->setWindowFlags(m_tdc->windowFlags() | Qt::Tool); + m_tdc->setAttribute(Qt::WA_DeleteOnClose); + + m_tmc->connectMotor(false); // 定时采集控制器 → 相机/马达 - connect(&mTimedDataCollectionWindow, &TimedDataCollection::hyperCamParm, this, &HPPA::setTimedDataCollectionHyperCamParm); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::camParm, this, &HPPA::setTimedDataCollectionCamParm); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::motorParm, this, &HPPA::setTimedDataCollectionMotorParm); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::startRecordSignal, this, &HPPA::onStartTimedDataCollection); + connect(m_tdc, &TimedDataCollection::hyperCamParm, this, &HPPA::setTimedDataCollectionHyperCamParm); + connect(m_tdc, &TimedDataCollection::camParm, this, &HPPA::setTimedDataCollectionCamParm); + connect(m_tdc, &TimedDataCollection::motorParm, this, &HPPA::setTimedDataCollectionMotorParm); + connect(m_tdc, &TimedDataCollection::startRecordSignal, this, &HPPA::onStartTimedDataCollection); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::switchHalogenLampSignal, m_pc3D, &PowerControl3D::switchHalogenLampPower); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::switchD65LampSignal, m_pc3D, &PowerControl3D::switchD65LampPower); - connect(&mTimedDataCollectionWindow, &TimedDataCollection::switchSlrSignal, m_pc3D, &PowerControl3D::switchSlrPower); + connect(m_tdc, &TimedDataCollection::switchHalogenLampSignal, m_pc3D, &PowerControl3D::switchHalogenLampPower); + connect(m_tdc, &TimedDataCollection::switchD65LampSignal, m_pc3D, &PowerControl3D::switchD65LampPower); + connect(m_tdc, &TimedDataCollection::switchSlrSignal, m_pc3D, &PowerControl3D::switchSlrPower); // 相机/马达 → 定时采集控制器 - connect(m_tmc, &TwoMotorControl::sequenceComplete, &mTimedDataCollectionWindow, &TimedDataCollection::subTaskCompleted); - connect(m_tmc, &TwoMotorControl::back2OriginSignal_TimedDataCollection, &mTimedDataCollectionWindow, &TimedDataCollection::onBack2Origin); + connect(m_tmc, &TwoMotorControl::sequenceComplete, m_tdc, &TimedDataCollection::subTaskCompleted); + connect(m_tmc, &TwoMotorControl::back2OriginSignal_TimedDataCollection, m_tdc, &TimedDataCollection::onBack2Origin); - mTimedDataCollectionWindow.show(); - mTimedDataCollectionWindow.exec(); + m_tdc->show(); } void HPPA::setTimedDataCollectionHyperCamParm(int camType, double f, double e, QString filePath, QString fileName) @@ -1709,7 +1718,7 @@ void HPPA::onStartRecordStep1() //判断光谱仪 if(!testImagerVality()) { - showMessageBox(QString::fromLocal8Bit("找不到光谱仪!")); + showMessageBox(QString::fromLocal8Bit("找不到高光谱仪!")); return; } @@ -2275,7 +2284,7 @@ void HPPA::onconnect() } else { - bool res = showResultMessageBox(QString::fromLocal8Bit("相机连接"), QString::fromLocal8Bit("确定要重连相机吗?")); + bool res = showResultMessageBox(QString::fromLocal8Bit("高光谱仪连接"), QString::fromLocal8Bit("确定要重连高光谱仪吗?")); if (res) { disconnectImagerAndCleanup(); @@ -2311,7 +2320,7 @@ void HPPA::onconnect() } else { - showMessageBox(QString::fromLocal8Bit("请选择相机类型!")); + showMessageBox(QString::fromLocal8Bit("请选择高光谱仪类型!")); return; } @@ -2392,7 +2401,7 @@ void HPPA::onconnect() delete m_Imager; m_Imager = nullptr; - showMessageBox(QString::fromLocal8Bit("请连接相机!")); + showMessageBox(QString::fromLocal8Bit("请连接高光谱仪!")); } catch (int e)//ximea相机异常 { @@ -2401,7 +2410,7 @@ void HPPA::onconnect() delete m_Imager; m_Imager = nullptr; - showMessageBox(QString::fromLocal8Bit("请连接相机!")); + showMessageBox(QString::fromLocal8Bit("请连接高光谱仪!")); } } diff --git a/HPPA/HPPA.h b/HPPA/HPPA.h index 90a24c7..88c03be 100644 --- a/HPPA/HPPA.h +++ b/HPPA/HPPA.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -296,6 +297,7 @@ private: RobotArmControl* m_rac; OneMotorControl* m_omc; TwoMotorControl* m_tmc; + QPointer m_tdc; View3DModelManager* m_view3DModelManager; diff --git a/HPPA/TaskTreeModel.cpp b/HPPA/TaskTreeModel.cpp index bdf3d57..a175444 100644 --- a/HPPA/TaskTreeModel.cpp +++ b/HPPA/TaskTreeModel.cpp @@ -13,6 +13,7 @@ TaskTreeNode::TaskTreeNode(TaskTreeNode* parent) TaskTreeNode::~TaskTreeNode() { qDeleteAll(m_children); + m_children.clear(); } void TaskTreeNode::appendChild(TaskTreeNode* child) @@ -20,6 +21,13 @@ void TaskTreeNode::appendChild(TaskTreeNode* child) m_children.append(child); } +void TaskTreeNode::removeChild(int index) +{ + if (index < 0 || index >= m_children.size()) + return; + delete m_children.takeAt(index); +} + TaskTreeNode* TaskTreeNode::child(int row) { if (row < 0 || row >= m_children.size()) @@ -352,7 +360,8 @@ void TaskTreeModel::clearTree() { // 删除所有子节点 while (m_rootNode->childCount() > 0) { - delete m_rootNode->child(0); + //delete m_rootNode->child(0); + m_rootNode->removeChild(0); } } diff --git a/HPPA/TaskTreeModel.h b/HPPA/TaskTreeModel.h index b9576eb..9ea3691 100644 --- a/HPPA/TaskTreeModel.h +++ b/HPPA/TaskTreeModel.h @@ -21,6 +21,7 @@ public: ~TaskTreeNode(); void appendChild(TaskTreeNode* child); + void removeChild(int index); TaskTreeNode* child(int row); int childCount() const; int row() const; diff --git a/HPPA/TimedDataCollection.cpp b/HPPA/TimedDataCollection.cpp index ae4c154..3e8154a 100644 --- a/HPPA/TimedDataCollection.cpp +++ b/HPPA/TimedDataCollection.cpp @@ -17,8 +17,22 @@ TimedDataCollection::TimedDataCollection(QWidget* parent) setupConnections(); - // 读取任务文件 - readTimedTaskFromFile("D:/0tmp/3Dtest/task.json"); + // 连接按钮信号 + connect(ui.start_btn, &QPushButton::clicked, this, &TimedDataCollection::startScheduler); + connect(ui.stop_btn, &QPushButton::clicked, this, &TimedDataCollection::stopScheduler); + + connect(ui.expandAll_btn, &QPushButton::clicked, ui.taskTreeView, &QTreeView::expandAll); + connect(ui.collapseAll_btn, &QPushButton::clicked, ui.taskTreeView, &QTreeView::collapseAll); + + connect(ui.taskFileSelect_btn, &QPushButton::clicked, this, &TimedDataCollection::onSelectTaskFile); + + // 树视图交互信号 + connect(ui.taskTreeView, &QTreeView::clicked, + this, &TimedDataCollection::onTreeItemClicked); + connect(ui.taskTreeView, &QTreeView::doubleClicked, + this, &TimedDataCollection::onTreeItemDoubleClicked); + connect(ui.taskTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, + this, &TimedDataCollection::onTreeSelectionChanged); } void TimedDataCollection::setupUI() @@ -70,23 +84,6 @@ void TimedDataCollection::setupUI() " font-size: 12px;" "}" ); - - // 连接按钮信号 - connect(ui.start_btn, &QPushButton::clicked, this, &TimedDataCollection::startScheduler); - connect(ui.stop_btn, &QPushButton::clicked, this, &TimedDataCollection::stopScheduler); - connect(ui.refresh_btn, &QPushButton::clicked, this, [this]() { - readTimedTaskFromFile("D:/0tmp/3Dtest/task.json"); - }); - connect(ui.expandAll_btn, &QPushButton::clicked, ui.taskTreeView, &QTreeView::expandAll); - connect(ui.collapseAll_btn, &QPushButton::clicked, ui.taskTreeView, &QTreeView::collapseAll); - - // 树视图交互信号 - connect(ui.taskTreeView, &QTreeView::clicked, - this, &TimedDataCollection::onTreeItemClicked); - connect(ui.taskTreeView, &QTreeView::doubleClicked, - this, &TimedDataCollection::onTreeItemDoubleClicked); - connect(ui.taskTreeView->selectionModel(), &QItemSelectionModel::selectionChanged, - this, &TimedDataCollection::onTreeSelectionChanged); } void TimedDataCollection::setupConnections() @@ -135,6 +132,26 @@ TimedDataCollection::~TimedDataCollection() } } +void TimedDataCollection::onSelectTaskFile() +{ + if (m_scheduler->isRunning()) + { + return; + } + + QString filePath = QFileDialog::getOpenFileName(this, + tr("Select Task File"), + QString(), + tr("JSON Files (*.json);;All Files (*)")); + + if (filePath.isEmpty()) { + return; + } + + ui.taskFileSelect_lineEdit->setText(filePath); + readTimedTaskFromFile(filePath); +} + // ==================== 任务状态更新槽实现 ==================== void TimedDataCollection::onTaskStarted(int taskId) @@ -142,8 +159,6 @@ void TimedDataCollection::onTaskStarted(int taskId) m_currentTaskId = taskId; m_currentSubTaskIndex = -1; - m_taskModel->updateTaskStatus(taskId, TaskStatus::Running); - // 展开当前运行的任务 expandRunningTask(); @@ -153,9 +168,6 @@ void TimedDataCollection::onTaskStarted(int taskId) void TimedDataCollection::onTaskFinished(int taskId, bool success) { - TaskStatus status = success ? TaskStatus::Finished : TaskStatus::Skiped; - m_taskModel->updateTaskStatus(taskId, status); - if (m_currentTaskId == taskId) { m_currentTaskId = -1; m_currentSubTaskIndex = -1; @@ -169,7 +181,7 @@ void TimedDataCollection::onSubTaskStarted(int taskId, int subTaskIndex) { m_currentSubTaskIndex = subTaskIndex; - m_taskModel->updateSubTaskStatusAndProgress(taskId, subTaskIndex, TaskStatus::Running); + m_taskModel->updateProgress(taskId); // 滚动到当前子任务 QModelIndex subTaskIndex_model = m_taskModel->getSubTaskIndex(taskId, subTaskIndex); diff --git a/HPPA/TimedDataCollection.h b/HPPA/TimedDataCollection.h index 7b45c98..93c6d2f 100644 --- a/HPPA/TimedDataCollection.h +++ b/HPPA/TimedDataCollection.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "ui_TimedDataCollection_ui.h" #include "TimedDataCollectionDataStructures.h" #include "TaskTreeModel.h" @@ -64,6 +65,8 @@ private: void updateStatusBar(); void expandRunningTask(); + void onSelectTaskFile(); + Ui::TimedDataCollection_ui ui; TaskTreeModel* m_taskModel; // 任务树形模型 diff --git a/HPPA/TimedDataCollection_ui.ui b/HPPA/TimedDataCollection_ui.ui index 9258d0a..de894ba 100644 --- a/HPPA/TimedDataCollection_ui.ui +++ b/HPPA/TimedDataCollection_ui.ui @@ -6,19 +6,23 @@ 0 0 - 1008 + 1182 576 - Dialog + 定时采集 - + + + true + + @@ -27,13 +31,6 @@ - - - - 刷新 - - - diff --git a/HPPA/TwoMotorControl.cpp b/HPPA/TwoMotorControl.cpp index 9a060ee..6c0689c 100644 --- a/HPPA/TwoMotorControl.cpp +++ b/HPPA/TwoMotorControl.cpp @@ -292,12 +292,21 @@ TwoMotorControl::~TwoMotorControl() } void TwoMotorControl::onConnectMotor() +{ + connectMotor(true); +} + +void TwoMotorControl::connectMotor(bool isNotification) { if (getMotorsConnectionStatus()) { - QMessageBox msgBox; - msgBox.setText(QString::fromLocal8Bit("马达已连接!")); - msgBox.exec(); + if (isNotification) + { + QMessageBox msgBox; + msgBox.setText(QString::fromLocal8Bit("马达已连接!")); + msgBox.exec(); + } + return; } diff --git a/HPPA/TwoMotorControl.h b/HPPA/TwoMotorControl.h index cb6167e..06e16dc 100644 --- a/HPPA/TwoMotorControl.h +++ b/HPPA/TwoMotorControl.h @@ -34,6 +34,8 @@ public: bool getMotorsConnectionStatus(); void readRecordLineFile(QString RecordLineFilePath); + + void connectMotor(bool isNotification); private: ImagerOperationBase* m_Imager;