add,计划采集15:

优化定时采集:界面和模型
This commit is contained in:
tangchao0503
2026-06-17 11:40:01 +08:00
parent 59abab3f5d
commit 5372a7806c
10 changed files with 102 additions and 57 deletions

1
.gitignore vendored
View File

@ -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.

View File

@ -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("请连接高光谱仪"));
}
}

View File

@ -13,6 +13,7 @@
#include <QChart>
#include <QChartView>
#include <QValueAxis>
#include <QPointer>
#include <QFileDialog>
#include <QNetworkRequest>
@ -296,6 +297,7 @@ private:
RobotArmControl* m_rac;
OneMotorControl* m_omc;
TwoMotorControl* m_tmc;
QPointer<TimedDataCollection> m_tdc;
View3DModelManager* m_view3DModelManager;

View File

@ -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);
}
}

View File

@ -21,6 +21,7 @@ public:
~TaskTreeNode();
void appendChild(TaskTreeNode* child);
void removeChild(int index);
TaskTreeNode* child(int row);
int childCount() const;
int row() const;

View File

@ -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);

View File

@ -4,6 +4,7 @@
#include <QTreeView>
#include <QHeaderView>
#include <QLabel>
#include <QFileDialog>
#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; // 任务树形模型

View File

@ -6,19 +6,23 @@
<rect>
<x>0</x>
<y>0</y>
<width>1008</width>
<width>1182</width>
<height>576</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>定时采集</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QTreeView" name="taskTreeView"/>
</item>
<item row="1" column="0">
<widget class="QLineEdit" name="taskFileSelect_lineEdit"/>
<widget class="QLineEdit" name="taskFileSelect_lineEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="taskFileSelect_btn">
@ -27,13 +31,6 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="refresh_btn">
<property name="text">
<string>刷新</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="start_btn">
<property name="text">

View File

@ -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;
}

View File

@ -34,6 +34,8 @@ public:
bool getMotorsConnectionStatus();
void readRecordLineFile(QString RecordLineFilePath);
void connectMotor(bool isNotification);
private:
ImagerOperationBase* m_Imager;