diff --git a/HPPA/AppSettings.cpp b/HPPA/AppSettings.cpp index 390584a..d70eb0a 100644 --- a/HPPA/AppSettings.cpp +++ b/HPPA/AppSettings.cpp @@ -10,6 +10,7 @@ const QString AppSettings::kDefaultSLRDataFolder = QString(); const QString AppSettings::kDefaultDepthCameraDataFolder = QString(); const double AppSettings::kDefaultScanSpeed = 1.0; const double AppSettings::kDefaultReturnSpeed = 5.0; +const int AppSettings::kDefaultGonggaShanRecordPort = 666; AppSettings::AppSettings() : m_settings(QSettings::IniFormat, QSettings::UserScope, @@ -137,3 +138,13 @@ void AppSettings::setReturnSpeed(double value) { m_settings.setValue("OneMotorControl/ReturnSpeed", value); } + +int AppSettings::gonggaShanRecordPort() const +{ + return m_settings.value("GonggaShanRecordCtl/Port", kDefaultGonggaShanRecordPort).toInt(); +} + +void AppSettings::setGonggaShanRecordPort(int value) +{ + m_settings.setValue("GonggaShanRecordCtl/Port", value); +} diff --git a/HPPA/AppSettings.h b/HPPA/AppSettings.h index b0be810..f3bcdb0 100644 --- a/HPPA/AppSettings.h +++ b/HPPA/AppSettings.h @@ -45,6 +45,10 @@ public: // 返回速度 double returnSpeed() const; void setReturnSpeed(double value); + + // 贡嘎山记录端口 + int gonggaShanRecordPort() const; + void setGonggaShanRecordPort(int value); // 在此处添加更多参数的 getter/setter ... private: @@ -64,4 +68,5 @@ private: static const QString kDefaultDepthCameraDataFolder; static const double kDefaultScanSpeed; static const double kDefaultReturnSpeed; + static const int kDefaultGonggaShanRecordPort; }; diff --git a/HPPA/FocusDialog.ui b/HPPA/FocusDialog.ui index de6158b..22f5736 100644 --- a/HPPA/FocusDialog.ui +++ b/HPPA/FocusDialog.ui @@ -6,8 +6,8 @@ 0 0 - 557 - 432 + 650 + 530 @@ -154,7 +154,7 @@ QSlider::handle:horizontal:pressed { border: 1px solid #2f6bff; } - + 0 @@ -168,7 +168,7 @@ QSlider::handle:horizontal:pressed { 0 - 10 + 6 @@ -242,23 +242,11 @@ QSlider::handle:horizontal:pressed { - - - 10 - - - 10 - - - 10 - - - 10 - + - 10 + 9 - + QWidget #connectFocusModule_widget @@ -274,85 +262,120 @@ QRadioButton - 9 + 0 - 9 + 0 - 9 + 0 - 9 + 0 - - - - - 0 - 0 - - - + + 0 + + + + 连接调焦模块 - - - - - - true - - - 线性平台 - - - Qt::AlignCenter - - - - - - - - - - 超声 - - - - - - - false - - - - - - - 新版 - - - - - - - Qt::Horizontal - - - - 107 - 20 - - - - - - - - 连接线性平台 - + + + + + 连接线性平台 + + + + + + + Qt::Horizontal + + + + 107 + 20 + + + + + + + + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + true + + + 线性平台 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + + + 超声 + + + + + + + false + + + + + + + + + + + 新版 + + + true + + + true + + + false + + + + @@ -368,151 +391,147 @@ QRadioButton } - - - - 移动至 - - - - - - - LogicZero - - - - - - - - 88 - 30 - - - - 10 - - - Qt::AlignCenter - - - - - - - + - - - - - - - - 88 - 30 - - - - 10 - - - Qt::AlignCenter - - - - - - - - 0 - 0 - - - - - 0 - 34 - - - - 更新实时位置 - - - - - - - - 88 - 30 - - - - 10 - - - Qt::AlignCenter - - - - - - - 量程测量 - - - - - - - - 88 - 30 - - - - null - - - Qt::AlignCenter - - - true - - - - - - - - - - - - - - - max - - - - - - - - 0 - 0 - - - + + + 调整线性平台 + + + + + + 0 + 0 + + + + + 0 + 34 + + + + 更新实时位置 + + + + + + + - + + + + + + + + + + + + + + + LogicZero + + + + + + + + 88 + 30 + + + + 10 + + + Qt::AlignCenter + + + + + + + + 88 + 30 + + + + 10 + + + Qt::AlignCenter + + + + + + + 移动至 + + + + + + + + 88 + 30 + + + + null + + + Qt::AlignCenter + + + true + + + + + + + max + + + + + + + 量程测量 + + + + + + + + 88 + 30 + + + + 10 + + + Qt::AlignCenter + + + + - + QWidget #controlFocus_widget @@ -521,53 +540,53 @@ QRadioButton border-radius: 5px 5px 5px 5px; } - - - - - - 0 - 0 - + + + + + 自动调焦 - - 调焦 - - - - - - - true - - - 采样率 - - - Qt::AlignCenter - - - - - - - - 88 - 30 - - - - 20 - - - Qt::AlignCenter - - - - - - - QProgressBar { + + + + + true + + + 采样数 + + + Qt::AlignCenter + + + + + + + + 88 + 30 + + + + 20 + + + Qt::AlignCenter + + + + + + + 自动调焦 + + + + + + + QProgressBar { border: 2px solid #08FACE; /* 边框颜色和宽度 */ border-radius: 8px; /* 圆角 */ background-color: #eee; /* 未完成部分颜色 */ @@ -579,37 +598,29 @@ QRadioButton background-color: #08FACE; /* 渐变色进度块 */ border-radius: 8px; /* 保持和整体圆角一致 */ } - - - 24 - + + + 24 + + + + - - - - 自动调焦 - - - - - - - Qt::Horizontal - - - - 171 - 20 - - - - - - - + + + 手动调焦 + + + + + 手动调焦 + + + + diff --git a/HPPA/FodisWindow.cpp b/HPPA/FodisWindow.cpp index 6697c0c..de07731 100644 --- a/HPPA/FodisWindow.cpp +++ b/HPPA/FodisWindow.cpp @@ -9,6 +9,7 @@ FodisWindow::FodisWindow(QWidget* parent) m_FiberImagerThread = new QThread(); m_JinspFiberImagerOperation = new JinspFiberImager(false, JinspFiberImagerConfig::instance().portName().toStdString(), "JINSP"); connect(m_JinspFiberImagerOperation, &JinspFiberImager::spectalCaptured, this, &FodisWindow::spectalCaptured); + connect(m_JinspFiberImagerOperation, &JinspFiberImager::startExposureSignal, this, &FodisWindow::startExposureSignal); connect(m_JinspFiberImagerOperation, &JinspFiberImager::exposureCompleteSignal, this, &FodisWindow::exposureCompleteSignal); m_JinspFiberImagerOperation->moveToThread(m_FiberImagerThread); m_FiberImagerThread->start(); diff --git a/HPPA/FodisWindow.h b/HPPA/FodisWindow.h index 9f99557..8c75735 100644 --- a/HPPA/FodisWindow.h +++ b/HPPA/FodisWindow.h @@ -44,7 +44,8 @@ signals: void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame); - void exposureCompleteSignal(); + void startExposureSignal(); + void exposureCompleteSignal(int exposureTime); private: Ui::FodisWindow ui; diff --git a/HPPA/GonggaShanRecordCtl.cpp b/HPPA/GonggaShanRecordCtl.cpp index 93b0722..e0cae19 100644 --- a/HPPA/GonggaShanRecordCtl.cpp +++ b/HPPA/GonggaShanRecordCtl.cpp @@ -1,24 +1,82 @@ -#include "GonggaShanRecordCtl.h" +#include "GonggaShanRecordCtl.h" + +GonggashanTaskScheduler::GonggashanTaskScheduler(QObject* parent) + : QObject(parent) + , m_taskState(TaskState::Idle) +{ +} + +GonggashanTaskScheduler::~GonggashanTaskScheduler() +{ +} + +bool GonggashanTaskScheduler::isTaskRunning() const +{ + return m_taskState == TaskState::Running; +} + +void GonggashanTaskScheduler::setTaskRunning(bool running) +{ + m_taskState = running ? TaskState::Running : TaskState::Idle; + Q_EMIT taskStateChanged(m_taskState); +} + +void GonggaShanRecordCtl::logStatus(const QString& message) +{ + QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); + ui.status_textEdit->append(QString("[%1] %2").arg(timestamp, message)); + + if (m_logStream.device()) { + m_logStream << "[" << timestamp << "] " << message << "\n"; + m_logStream.flush(); + m_logFile.flush(); + } +} GonggaShanRecordCtl::GonggaShanRecordCtl(QWidget* parent) : QDialog(parent) + , m_taskScheduler(new GonggashanTaskScheduler(this)) { ui.setupUi(this); + AppSettings& settings = AppSettings::instance(); + ui.spinbox_Port->setValue(settings.gonggaShanRecordPort()); + connect(ui.btnListen, &QPushButton::clicked, this, &GonggaShanRecordCtl::startListen); connect(ui.btnDisListen, &QPushButton::clicked, this, &GonggaShanRecordCtl::stopListen); + connect(ui.spinbox_Port, QOverload::of(&QSpinBox::valueChanged), [this](int value) { + AppSettings::instance().setGonggaShanRecordPort(value); + }); } GonggaShanRecordCtl::~GonggaShanRecordCtl() { + if (m_logFile.isOpen()) { + m_logStream.flush(); + m_logFile.close(); + } tcpServer6005->deleteLater(); } void GonggaShanRecordCtl::startListen() { + if (m_logFile.isOpen()) { + m_logStream.flush(); + m_logFile.close(); + } + + QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss"); + QString logFileName = QString("log%1.txt").arg(timestamp); + m_logFilePath = AppSettings::instance().dataFolder() + QDir::separator() + logFileName; + m_logFile.setFileName(m_logFilePath); + m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); + m_logStream.setDevice(&m_logFile); + + logStatus("Start listen...."); + MotorParams::TCPConnectionParams tcpConnectionParams6005; tcpConnectionParams6005.port = ui.spinbox_Port->text().toInt(); - tcpConnectionParams6005.serverIP = "192.168.1.2"; + tcpConnectionParams6005.serverIP = "192.168.1.2";//此ip地址没有使用,可以随便填入 tcpServer6005 = new MotorParams::CommunicationViaTCP(tcpConnectionParams6005, this); connect(tcpServer6005, &MotorParams::CommunicationViaTCP::positionReceived, this, &GonggaShanRecordCtl::startRecord); @@ -26,15 +84,43 @@ void GonggaShanRecordCtl::startListen() void GonggaShanRecordCtl::stopListen() { + logStatus("Stop listen"); + disconnect(tcpServer6005, &MotorParams::CommunicationViaTCP::positionReceived, this, &GonggaShanRecordCtl::startRecord); - + tcpServer6005->deleteLater(); } void GonggaShanRecordCtl::startRecord(int position) { - //¼λ + if (m_taskScheduler->isTaskRunning()) + { + logStatus("Data collection has begun...."); - //ź + return; + } + + logStatus("Reach pos: " + QString::number(position)); + + m_taskScheduler->setTaskRunning(true); emit startRcordSignal(); } + +void GonggaShanRecordCtl::onFiberImagerStartExposureSignal() +{ + logStatus("FiberImager: start exposure..."); +} + +void GonggaShanRecordCtl::onFiberImagerExposureCompleteSignal(int exposureTime) +{ + logStatus(QString("FiberImager: exposure finished, %1").arg(exposureTime)); + + logStatus("Start recording..."); +} + +void GonggaShanRecordCtl::onRcordFinished() +{ + m_taskScheduler->setTaskRunning(false); + + logStatus("Record Finished."); +} diff --git a/HPPA/GonggaShanRecordCtl.h b/HPPA/GonggaShanRecordCtl.h index 7c6abf9..3005e49 100644 --- a/HPPA/GonggaShanRecordCtl.h +++ b/HPPA/GonggaShanRecordCtl.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include #include #include @@ -6,9 +6,39 @@ #include #include +#include +#include +#include +#include + #include "ui_gonggashanCtl.h" #include "CommunicationViaTCP.h" +#include "AppSettings.h" + +class GonggashanTaskScheduler : public QObject +{ + Q_OBJECT + +public: + enum class TaskState + { + Idle, + Running + }; + + explicit GonggashanTaskScheduler(QObject* parent = nullptr); + ~GonggashanTaskScheduler(); + + bool isTaskRunning() const; + void setTaskRunning(bool running); + +Q_SIGNALS: + void taskStateChanged(TaskState state); + +private: + TaskState m_taskState; +}; class GonggaShanRecordCtl : public QDialog { @@ -20,6 +50,9 @@ public: public Q_SLOTS: + void onFiberImagerStartExposureSignal(); + void onRcordFinished(); + void onFiberImagerExposureCompleteSignal(int exposureTime); Q_SIGNALS: // Emitted when user changes any of the R/G/B wavelength values @@ -32,6 +65,12 @@ private Q_SLOTS: void startRecord(int position); private: + void logStatus(const QString& message); + Ui::gongga_control ui; QPointer tcpServer6005; + GonggashanTaskScheduler* m_taskScheduler; + QString m_logFilePath; + QFile m_logFile; + QTextStream m_logStream; }; diff --git a/HPPA/HPPA.cpp b/HPPA/HPPA.cpp index 4320bc9..9d31c70 100644 --- a/HPPA/HPPA.cpp +++ b/HPPA/HPPA.cpp @@ -1079,8 +1079,13 @@ void HPPA::initControlTabwidget() void HPPA::setupGonggashanAutoRecordConnection() { connect(m_gonggaShanRecordCtl, &GonggaShanRecordCtl::startRcordSignal, this, &HPPA::onGonggashanRecord); + + connect(m_fodisWindow, &FodisWindow::startExposureSignal, m_gonggaShanRecordCtl, &GonggaShanRecordCtl::onFiberImagerStartExposureSignal); connect(m_fodisWindow, &FodisWindow::exposureCompleteSignal, this, &HPPA::onStartRecordStep1); + connect(m_fodisWindow, &FodisWindow::exposureCompleteSignal, m_gonggaShanRecordCtl, &GonggaShanRecordCtl::onFiberImagerExposureCompleteSignal); + connect(m_omc, &OneMotorControl::sequenceComplete, m_fodisWindow, &FodisWindow::closeFiberImager); + connect(m_omc, &OneMotorControl::sequenceComplete, m_gonggaShanRecordCtl, &GonggaShanRecordCtl::onRcordFinished); } void HPPA::onGonggashanRecord() @@ -2010,6 +2015,10 @@ void HPPA::onTabWidgetCurrentChanged(int index)//代码新建一个tab,会调 //获取绘图控件 QWidget* currentWidget = m_imageViewerTabWidget->widget(index); QList currentImageViewer = currentWidget->findChildren(); + if (currentImageViewer.size() == 0) + { + return; + } // Re-apply the current active map tool to the new canvas Mapcavas* canvas = currentImageViewer[0]; @@ -2784,6 +2793,10 @@ void HPPA::onPlotHyperspectralImageRgbImage(int fileNumber, int frameNumber, QSt //QWidget* currentWidget = m_imageViewerTabWidget->widget(fileNumber); QList currentImageViewer = currentWidget->findChildren(); + if (currentImageViewer.size() == 0) + { + return; + } currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFrameCounter());//界面中显示已经采集的帧数 cv::Mat rgbImage(*m_Imager->getMatRgbImage(), cv::Range(0, m_Imager->getFrameCounter()), cv::Range::all()); @@ -2843,6 +2856,10 @@ void HPPA::onStretchedImageReady(int fileNumber, const QString& filePath, QPixma QWidget* currentWidget = m_MapLayerStore->widgetForLayer(filePath); if (!currentWidget) return; QList currentImageViewer = currentWidget->findChildren(); + if (currentImageViewer.size() == 0) + { + return; + } if (currentImageViewer.isEmpty()) return; // 在界面中显示拉伸后的图像 currentImageViewer[0]->SetImage(&pixmap); @@ -2864,6 +2881,10 @@ void HPPA::focusPlotSpectralImg(int state) //显示影像 QWidget* currentWidget = m_imageViewerTabWidget->currentWidget(); QList currentImageViewer = currentWidget->findChildren(); + if (currentImageViewer.size() == 0) + { + return; + } currentImageViewer[0]->DisplayFrameNumber(m_Imager->getFocusFrameCounter());//界面中显示已经采集的帧数 ImageProcessor imageProcessor; @@ -3047,6 +3068,10 @@ void HPPA::newImage(RasterLayer* ml, RasterImageLayer::RendererType type, LayerT QWidget* mapcavasContainer = onCreateTab(ml->name()); RasterImageLayer* rasterImageLayer = new RasterImageLayer(ml, type); QList mapcavas = mapcavasContainer->findChildren(); + if (mapcavas.size() == 0) + { + return; + } mapcavas[0]->setImageLayer(rasterImageLayer); QString title = ml->name(); diff --git a/HPPA/JinspFiberImager.cpp b/HPPA/JinspFiberImager.cpp index d969c29..0e8f123 100644 --- a/HPPA/JinspFiberImager.cpp +++ b/HPPA/JinspFiberImager.cpp @@ -291,6 +291,8 @@ void JinspFiberImager::autoExpose() std::cout << "自动曝光达到最大迭代次数,最终曝光时间:" << exposureTime << "ms, 最大值:" << maxValue << std::endl; } + + m_iExposureTime = exposureTime; } ZZ_S32 JinspFiberImager::GetMaxValue(ZZ_S32 * dark, int number) @@ -326,8 +328,9 @@ void JinspFiberImager::OpenFiberImagerAndRecord() connectFiberSpectrometer(SN, pixelCount, wavelengthInfo); //曝光 + emit startExposureSignal(); autoExpose(); - emit exposureCompleteSignal(); + emit exposureCompleteSignal(m_iExposureTime); //采集 m_record = true; diff --git a/HPPA/JinspFiberImager.h b/HPPA/JinspFiberImager.h index 2d57e41..561b96a 100644 --- a/HPPA/JinspFiberImager.h +++ b/HPPA/JinspFiberImager.h @@ -53,6 +53,8 @@ private: bool m_record; int m_captureIntervalMilliseconds; + int m_iExposureTime; + // ZZ_U32 m_MaxValueOfFiberSpectrometer; public slots: @@ -66,5 +68,6 @@ signals: void sendExposureTimeSignal(int exposureTime); void spectalCaptured(DeviceAttribute attribute, DataFrame dataFrame); - void exposureCompleteSignal(); + void exposureCompleteSignal(int exposureTime); + void startExposureSignal(); }; diff --git a/HPPA/about.ui b/HPPA/about.ui index e13f72e..94009e6 100644 --- a/HPPA/about.ui +++ b/HPPA/about.ui @@ -288,7 +288,7 @@ QPushButton:pressed } - 版本:3.1.0 + 版本:3.1.1 diff --git a/HPPA/focusWindow.cpp b/HPPA/focusWindow.cpp index e5a1121..693462c 100644 --- a/HPPA/focusWindow.cpp +++ b/HPPA/focusWindow.cpp @@ -53,6 +53,10 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager) connect(this->ui.rangeMeasurement_btn, SIGNAL(pressed()), this, SLOT(onx_rangeMeasurement())); connect(this->ui.closeBtn, SIGNAL(released()), this, SLOT(onExit())); + connect(this->ui.is_new_version_radioButton, &QRadioButton::toggled, this, [this](bool checked) { + ui.stackedWidget_connetcParm->setCurrentIndex(checked ? 0 : 1); + }); + //查找可用串口,并显示 foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { @@ -72,7 +76,6 @@ focusWindow::focusWindow(QWidget *parent, ImagerOperationBase* imager) ui.autoFocusProgress_progressBar->reset(); m_dSpeed = 1.0; - } focusWindow::~focusWindow() diff --git a/HPPA/gonggashanCtl.ui b/HPPA/gonggashanCtl.ui index 32999b8..d13bf1d 100644 --- a/HPPA/gonggashanCtl.ui +++ b/HPPA/gonggashanCtl.ui @@ -6,8 +6,8 @@ 0 0 - 535 - 229 + 572 + 384 @@ -24,6 +24,22 @@ color: #ACCDFF; } +QSpinBox +{ + font: 10pt "新宋体"; + background-color: #142D7F; + color: white; + border: none; +} + +QTextEdit +{ + font: 10pt "新宋体"; + background-color: #142D7F; + color: white; + border: none; +} + QPushButton { /*width: 172px; @@ -117,7 +133,7 @@ QSlider::handle:horizontal:pressed { background: #1f4fff; } - + @@ -135,46 +151,30 @@ QSlider::handle:horizontal:pressed { 16 - - - - Qt::Horizontal + + + + Qt::AlignCenter - - - 40 - 20 - + + 65535 - + + 666 + + + + + + + 端口 + + + Qt::AlignCenter + + - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - Qt::Horizontal @@ -187,48 +187,18 @@ QSlider::handle:horizontal:pressed { - - - - 192.168.1.2 + + + + Qt::Horizontal - - Qt::AlignCenter + + + 40 + 20 + - - - - - - ip - - - Qt::AlignCenter - - - - - - - 端口 - - - Qt::AlignCenter - - - - - - - Qt::AlignCenter - - - 65535 - - - 666 - - + @@ -280,6 +250,18 @@ QSlider::handle:horizontal:pressed { + + + + 系统状态 + + + + + + + +