添加项目文件。
This commit is contained in:
+337
@@ -0,0 +1,337 @@
|
||||
//
|
||||
// Created by Administrator on 2025/12/8.
|
||||
//
|
||||
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QProgressDialog>
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QListWidget>
|
||||
#include <functional>
|
||||
#include <deque>
|
||||
#include <qwt_plot.h>
|
||||
#include <qwt_scale_draw.h>
|
||||
#include <qwt_plot_curve.h>
|
||||
#include <qwt_plot_layout.h>
|
||||
#include <qwt_scale_engine.h>
|
||||
#include <qwt_scale_widget.h>
|
||||
#include <qwt_plot_barchart.h>
|
||||
#include <qwt_plot_histogram.h>
|
||||
#include <qwt_column_symbol.h>
|
||||
#include <qwt_plot_marker.h>
|
||||
#include <qwt_legend.h>
|
||||
#include <qwt_plot_canvas.h>
|
||||
#include <qwt_plot_magnifier.h> // 用于 QwtPlotMagnifier
|
||||
#include <qwt_plot_panner.h> // 用于 QwtPlotPanner
|
||||
#include <qwt_plot_marker.h> // 用于 QwtPlotMarker (DraggableMarker应该继承自此)
|
||||
#include <qwt_legend_label.h>
|
||||
#include <QGesture> // 添加手势支持
|
||||
#include <QGestureEvent> // 添加手势事件支持
|
||||
#include <QPinchGesture> // 添加捏合手势支持
|
||||
#include "probe_tube.h"
|
||||
#include "PeakSearching/peakfinder.h"
|
||||
#include "Spectrometer/devicemanager.h"
|
||||
#include "Spectrometer/spectrumalgorithm.h"
|
||||
#include "Public/sqliteutil.h"
|
||||
|
||||
// 样品光谱数据
|
||||
struct SampleSpectrum {
|
||||
// 波长
|
||||
double wavelength;
|
||||
// 强度
|
||||
double intensity;
|
||||
// 光谱仪sn
|
||||
string spectrometerNo;
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class MainWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow() override;
|
||||
|
||||
public slots:
|
||||
// 开始测量按钮触发
|
||||
void on_but_start_measurement_clicked();
|
||||
// 导出数据按钮触发
|
||||
void on_but_export_data_clicked();
|
||||
// 右侧测试文件列表:导出选中
|
||||
void on_but_testfile_export_clicked();
|
||||
// 右侧测试文件列表:删除选中
|
||||
void on_but_testfile_delete_clicked();
|
||||
// 右侧测试文件列表:选中某条记录时在图表中预览该文件的光谱
|
||||
void previewTestFile(QListWidgetItem *item);
|
||||
// 采集次数增加按钮触发
|
||||
void on_but_collections_number_add_clicked();
|
||||
// 采集次数减少按钮触发
|
||||
void on_but_collections_number_sub_clicked();
|
||||
// 关闭设备按钮触发
|
||||
void on_but_close_device_clicked();
|
||||
// 角度减少0.1按钮触发
|
||||
void on_but_angle_sub_1_clicked();
|
||||
// 角度增加0.1按钮触发
|
||||
void on_but_angle_add_1_clicked();
|
||||
// 角度减少1按钮触发
|
||||
void on_but_angle_sub_2_clicked();
|
||||
// 角度增加1按钮触发
|
||||
void on_but_angle_add_2_clicked();
|
||||
// 角度重置按钮触发
|
||||
void on_but_angle_restoration_clicked();
|
||||
// 光谱放大按钮触发
|
||||
void on_but_spectral_amplification_clicked();
|
||||
// 光谱缩小按钮触发
|
||||
void on_but_spectral_reduction_clicked();
|
||||
// 光谱重置按钮触发
|
||||
void on_but_spectral_reset_clicked();
|
||||
// 光谱校准按钮触发
|
||||
// void on_but_spectral_calibration_clicked();
|
||||
|
||||
void on_but_test_clicked();
|
||||
|
||||
// 功能:接收光谱数据
|
||||
void onReceiveSpecData(QString currentSerialNumber, const QVector<float>& wavelengths, const QVector<float>& spectrum);
|
||||
|
||||
signals:
|
||||
// 功能:归零
|
||||
void onBakeZero();
|
||||
// 功能:控制模式选择A
|
||||
void onControlModeSelectionA();
|
||||
// 功能:控制模式选择B
|
||||
void onControlModeSelectionB();
|
||||
// 功能:获取绝对位置
|
||||
void onGetAbsolutePosition();
|
||||
// 功能:目标速度
|
||||
void onTargetSpeed(int speed);
|
||||
// 功能:加速度
|
||||
void onAcceleratedSpeed(int speed);
|
||||
// 功能:减速度
|
||||
void onDecelerationSpeed(int speed);
|
||||
// 功能:移动目标位置A
|
||||
void onMoveTargetPositionA();
|
||||
// 功能:移动目标位置B
|
||||
void onMoveTargetPositionB();
|
||||
// 功能:设置目标位置
|
||||
void onSetTargetPosition(int position);
|
||||
// 功能:测量完成
|
||||
void MeasureFinished(vector<SampleSpectrum> cutedSpectrumLst);
|
||||
|
||||
private slots:
|
||||
// 功能:归零
|
||||
void BakeZero();
|
||||
// 功能:控制模式选择A
|
||||
void ControlModeSelectionA();
|
||||
// 功能:控制模式选择B
|
||||
void ControlModeSelectionB();
|
||||
// 功能:获取绝对位置
|
||||
void GetAbsolutePosition();
|
||||
// 功能:目标速度
|
||||
void TargetSpeed();
|
||||
// 功能:加速度
|
||||
void AcceleratedSpeed();
|
||||
// 功能:减速度
|
||||
void DecelerationSpeed();
|
||||
// 功能:移动目标位置A
|
||||
void MoveTargetPositionA();
|
||||
// 功能:移动目标位置B
|
||||
void MoveTargetPositionB();
|
||||
// 功能:设置目标位置
|
||||
void SetTargetPosition(int position);
|
||||
|
||||
|
||||
|
||||
|
||||
void doGetcutedSpectrumLst(vector<SampleSpectrum> cutedSpectrumLst);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// 镜头运动 / 测量流程状态
|
||||
// ------------------------------------------------------------------
|
||||
// 一次电机运动(设置目标位置 + 移动到位置A + 移动到位置B)的用途,
|
||||
// 用于在机构到位后决定接下来做什么
|
||||
enum class MotionPurpose {
|
||||
None, // 没有待处理的运动
|
||||
InitToZero, // 摆正:从最下向上 15° 到 0°
|
||||
MeasureStart, // 测量:转到最大俯角(起测点)
|
||||
MeasureStep // 测量:步进到下一个角度
|
||||
};
|
||||
// 本次运动的用途
|
||||
MotionPurpose motionPurpose = MotionPurpose::None;
|
||||
// 本次运动的目标角度(机构到位后写入 currentAngle)
|
||||
double targetAngle = 0.0;
|
||||
// 启动时的“镜头摆正初始化”是否已完成
|
||||
bool instrumentReady = false;
|
||||
// 是否正在执行一次完整的测量流程
|
||||
bool isMeasuring = false;
|
||||
|
||||
// 采集参数
|
||||
// 积分时间
|
||||
int integrationTime = 53; // 单位:us
|
||||
// 延时时间
|
||||
int delayTime = 0; // 单位:us
|
||||
// 采集次数
|
||||
int collectionsCount = 1;
|
||||
// 当前采集次数
|
||||
int currentCollectionsCount = 0;
|
||||
// 最大仰角(终止角)—— 第 9 步用它与“当前角度 + 步进”比较,超过即结束
|
||||
double maxElevation = 0.0; // 单位:°
|
||||
// 最大俯角(起测角)—— 第 6 步镜头先转到这个角度
|
||||
double maxAngleDepression = 0.0; // 单位:°
|
||||
// 转动角度(每次步进的值)
|
||||
double steppingAngle = 0.0; // 单位:°
|
||||
// 当前角度
|
||||
double currentAngle = 0.0; // 单位:°
|
||||
|
||||
// 目标速度
|
||||
int speed = 20;
|
||||
// 加速度
|
||||
int acceleration = 100;
|
||||
// 减速度
|
||||
int deceleration = 100;
|
||||
// 目标位置
|
||||
int position = 0;
|
||||
// 接收次数
|
||||
int receiveTimes = 0;
|
||||
// 测量状态
|
||||
bool measureStatus = false;
|
||||
// 选择的控件是什么
|
||||
QString selectedLineEdit = "";
|
||||
// 是否需要回零
|
||||
bool isAngleRestoration = false;
|
||||
// 寻峰参数
|
||||
QString peakFinderParam = "Al:394.40,396.15";
|
||||
|
||||
QTimer* measurementTimer;
|
||||
// 指令队列:每条指令发送后固定等待(默认认为成功),再执行下一条
|
||||
struct CommandStep {
|
||||
std::function<void()> action; // 要发送的指令
|
||||
int delayMs = 0; // 发送后等待多久再执行下一条
|
||||
};
|
||||
std::deque<CommandStep> commandQueue;
|
||||
// 指令节拍定时器(单次触发)
|
||||
QTimer *commandTimer = nullptr;
|
||||
|
||||
// 光谱仪
|
||||
DeviceManager *m_pDeviceManager = nullptr;
|
||||
// 探针管
|
||||
ProbeTube *m_pProbeTube = nullptr;
|
||||
|
||||
// 光谱图
|
||||
QwtPlot* qwtPlot = nullptr;
|
||||
static const int MAX_SPECTRUM_COUNT = 10;
|
||||
vector<vector<double>> historicalWaveLengths; // 历次测量的波长数据
|
||||
vector<vector<double>> historicalIntensities; // 历次测量的强度数据
|
||||
vector<Spectrometer*> specDeviceList;
|
||||
vector<vector<double>> spectrumList;
|
||||
vector<map<int,vector<SampleSpectrum>>> spectrumMap;
|
||||
vector<double> m_pLambda;
|
||||
vector<double> m_pSpectrum;
|
||||
map<int,double*> lamdaMap;
|
||||
map<int, int> deviceStartPositions;
|
||||
map<int,vector<SampleSpectrum>> ospectrumMap;
|
||||
vector<double> vecWaveLength;
|
||||
vector<double> vecIntensity;
|
||||
|
||||
|
||||
// 检查设备连接状态
|
||||
void checkStatusDevice(DeviceManager* m_pDeviceManager, ProbeTube* m_pProbeTube);
|
||||
// 开机预处理执行
|
||||
bool PreprocessingExecutionInstruction();
|
||||
// 初始化检测参数
|
||||
void initializeDetectionParameters();
|
||||
// 采集参数配置
|
||||
bool CollectionParameterConfiguration();
|
||||
// 开始测量
|
||||
void startMeasure();
|
||||
// 处理数据
|
||||
void onGetData();
|
||||
vector<map<int, vector<std::pair<double, double>>>> convertSpectrumMap(vector<map<int,vector<SampleSpectrum>>> spectrumMap);
|
||||
vector<SampleSpectrum> convertToChannelData(const vector<std::pair<double, double>>& data);
|
||||
// 功能:分解数据,将每个样本的光谱数据分解为波长和强度
|
||||
void DecomposeData(vector<SampleSpectrum> cutedSpectrumList);
|
||||
// 功能:获取光谱数据的极值
|
||||
void getExtremum(int &minX, int &maxX, int &minY, int &maxY);
|
||||
// 功能:绘制光谱曲线
|
||||
void draw_spectral_curve(int minX, int maxX, int minY, int maxY);
|
||||
// 功能:保存基本数据到数据库
|
||||
void saveBasicDataToDatabase();
|
||||
// 功能:保存光谱数据到数据库
|
||||
void saveSpectraToDatabase();
|
||||
// 功能:导出数据
|
||||
void save_local_storage();
|
||||
// 功能:定时器超时处理函数
|
||||
void onMeasurementTimeout();
|
||||
// 辅助函数:配置峰寻找参数
|
||||
void configurationPeakFinderParam(QVector<PeakFinder::ElementTarget> &targets);
|
||||
// 辅助函数:将double数据转换为float数据
|
||||
QVector<float> doubleToFloat(vector<double> vecDoubleData);
|
||||
// 递归复制相关辅助函数, 用于计算文件数量和复制文件
|
||||
int countFilesRecursively(const QDir &dir);
|
||||
// 递归复制相关辅助函数, 用于复制文件
|
||||
bool copyRecursively(const QDir &sourceDir, const QDir &destDir, QProgressDialog &progress, int &copiedCount, int totalFiles);
|
||||
// 添加处理缩放的手册函数
|
||||
void handlePinchGesture(QPinchGesture *pinch);
|
||||
// 测试代码:绘制光谱曲线
|
||||
void test_draw_spectral_curve();
|
||||
// 测试代码:获取光谱数据
|
||||
void test_get_spectrum_data();
|
||||
|
||||
// ---- 镜头运动 / 测量流程 ------------------------------------------
|
||||
// 角度 -> 电机目标位置(position = angle * 10 + 150)
|
||||
static int angleToTargetPosition(double angle);
|
||||
// 运动用途的中文名(日志用)
|
||||
static QString motionPurposeName(MotionPurpose purpose);
|
||||
// 启动镜头摆正初始化:回零(等 2 秒到最下)-> 各控制指令(0.5 秒)-> 向上 15° 摆正到 0°
|
||||
void startInstrumentInitialization();
|
||||
// 指令队列:把一条“执行动作 + 等待”加入队列
|
||||
void enqueueCommand(std::function<void()> action, int delayMs);
|
||||
// 执行队列中的下一条指令(由 commandTimer 驱动)
|
||||
void runNextCommand();
|
||||
// 指令序列执行完毕(默认成功):按 purpose 决定后续动作
|
||||
void onLensArrived(MotionPurpose purpose);
|
||||
// 确保“当前要调整的角度输入框”已选中;没选中时按焦点推断,仍没有则提示用户
|
||||
bool ensureAngleTargetSelected();
|
||||
// 角度按钮的统一实现:以界面当前值为基准加减 step
|
||||
void adjustSelectedAngle(double step);
|
||||
// 解析带 "°" 的角度文本(QString::toDouble 遇到 "°" 会失败返回 0)
|
||||
double parseAngleText(const QString &text) const;
|
||||
// 给当前选中的角度输入框加底色,提示操作员 + / - 会调哪一个
|
||||
void markSelectedAngleField();
|
||||
// CSV 数据目录(程序目录下的 csv)
|
||||
QString csvDirectory() const;
|
||||
// 刷新右侧“测试文件记录”列表
|
||||
void refreshTestFileList();
|
||||
// 读取一个 CSV 测试文件到 vecWaveLength / vecIntensity(用于预览),angleOut 返回该帧角度
|
||||
bool loadCsvForPreview(const QString &filePath, double *angleOut);
|
||||
// 当前测量流程里的步进序号(1 开始,每个采集角度 +1)
|
||||
int measureStepIndex = 0;
|
||||
// 三个角度输入框的原始样式(选中高亮时在此基础上叠加,避免冲掉字号)
|
||||
QString m_styleMaxElevation;
|
||||
QString m_styleMaxDepression;
|
||||
QString m_styleStepAngle;
|
||||
// 摆正/复位完成的收尾处理(manualRestore 为真时额外弹提示)
|
||||
void finishInstrumentInitialization(bool manualRestore = false);
|
||||
// 把镜头转到指定角度,并记录本次运动的用途
|
||||
void moveLensToAngle(double angle, MotionPurpose purpose);
|
||||
// 在当前角度开始一轮采集(collectionsCount 次)
|
||||
void beginCollectionAtCurrentAngle();
|
||||
// 结束整个测量流程
|
||||
void finishMeasurement(const QString &reason = QString());
|
||||
// 刷新界面上的“当前角度”
|
||||
void updateCurrentAngleDisplay();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //MAINWINDOW_H
|
||||
Reference in New Issue
Block a user