260 lines
8.3 KiB
Plaintext
260 lines
8.3 KiB
Plaintext
//
|
|
// Created by Administrator on 2025/12/8.
|
|
//
|
|
|
|
#ifndef MAINWINDOW_H
|
|
#define MAINWINDOW_H
|
|
|
|
#include <QDir>
|
|
#include <QProgressDialog>
|
|
#include <QWidget>
|
|
#include <QTimer>
|
|
#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_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 FirstStepOver();
|
|
// 功能:第二步骤成功
|
|
void SecondStepOver();
|
|
// 功能:第三步骤成功
|
|
void ThirdStepOver();
|
|
|
|
void doGetcutedSpectrumLst(vector<SampleSpectrum> cutedSpectrumLst);
|
|
|
|
private:
|
|
Ui::MainWindow *ui;
|
|
|
|
// 采集参数
|
|
// 积分时间
|
|
int integrationTime = 53; // 单位:us
|
|
// 延时时间
|
|
int delayTime = 0; // 单位:us
|
|
// 采集次数
|
|
int collectionsCount = 1;
|
|
// 当前采集次数
|
|
int currentCollectionsCount = 0;
|
|
// 最大仰角
|
|
double maxElevation = 0.0; // 单位:°
|
|
// 最大俯角
|
|
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;
|
|
// 光谱仪
|
|
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();
|
|
|
|
protected:
|
|
bool event(QEvent *event) override;
|
|
};
|
|
|
|
|
|
#endif //MAINWINDOW_H
|