DSCAnalysisTool/src/mainwindow.cpp

841 lines
26 KiB
C++
Raw Normal View History

2025-03-13 09:27:31 +00:00
#include <qmessagebox.h>
2025-06-06 09:17:31 +00:00
#include "lowesssmoother.h"
2025-03-05 09:33:46 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
2025-03-12 09:29:52 +00:00
#include "global.h"
#include "serialport.h"
2025-03-13 09:27:31 +00:00
#include "dataparser.h"
2025-03-17 13:16:16 +00:00
#include "filemanager.h"
2025-04-22 08:59:26 +00:00
#include "logger.h"
#include "xlsxhandler.h"
2025-03-05 09:33:46 +00:00
MainWindow::MainWindow(QWidget *parent)
2025-03-21 09:28:36 +00:00
: QMainWindow(parent),
ui(new Ui::MainWindow),
_centralWidget(new CentralWidget(this)),
_leftWidget(new LeftWidget(this)),
_expertmentSettingForm(new ExperimentSettingForm(this)),
_realTimeDataForm(new RealTimeDataForm(this)),
_rightWidget(new QDockWidget(this))
,_analysisSettingWidget(new AnalysisSettingForm(this))
,_contextMenu(new QMenu(this))
2025-04-03 09:24:29 +00:00
,_specificHeatComparisonMethodForm(new SpecificHeatComparisonMethodForm(this))
2025-04-11 05:51:47 +00:00
,_instrumentCoefficientForm(new InstrumentCoefficientForm(this))
,_degreeOfCureForm(new DegreeOfCureForm(this))
2025-04-11 09:17:37 +00:00
,_OITAutoAnalysisParamForm(new OITAutoAnalysisParamForm(this))
,_degreeOfCrystallinityForm(new DegreeOfCrystallinityForm(this))
2025-04-14 09:11:01 +00:00
,_aboutForm(new AboutForm(this))
2025-04-16 07:38:25 +00:00
,_enthalpyDataCorrectionForm(new EnthalpyDataCorrectionForm(this))
2025-04-18 09:30:35 +00:00
,_coefficientSelectionForm(new CoefficientSelectionForm(this))
2025-04-25 09:20:33 +00:00
,_printPreviewForm(new PrintPreviewForm(this))
2025-04-29 09:29:14 +00:00
,_axisSettingForm(new AxisSettingForm(this))
2025-05-15 09:31:03 +00:00
,_manuallyStopTheExperimentFlag(false)
2025-03-05 09:33:46 +00:00
{
ui->setupUi(this);
2025-06-20 09:28:45 +00:00
ui->actionOITAutoAnalysisMode->setVisible(false);
2025-03-05 09:33:46 +00:00
this->setToolTip(".....");
2025-05-30 05:46:40 +00:00
ui->actionSaveas->setVisible(false);
2025-03-05 09:33:46 +00:00
setCentralWidget(_centralWidget);
2025-03-12 09:29:52 +00:00
addDockWidget(Qt::LeftDockWidgetArea, _leftWidget);
2025-03-21 09:28:36 +00:00
addDockWidget(Qt::RightDockWidgetArea, _rightWidget);
_rightWidget->setWidget(_analysisSettingWidget);
_rightWidget->hide();
2025-03-14 08:58:08 +00:00
//
ui->statusbar->showMessage("showMessage show temp message!");
2025-05-16 09:01:40 +00:00
2025-03-14 08:58:08 +00:00
// permenent show
QLabel *permenentLabel = new QLabel(this);
2025-05-15 01:10:10 +00:00
permenentLabel->setText("Software Ver:" + qApp->applicationVersion());
2025-03-14 08:58:08 +00:00
ui->statusbar->addPermanentWidget(permenentLabel);
2025-04-30 02:59:08 +00:00
ui->actionTimeAxisAnalysisPCTMode->setCheckable(true);
2025-05-16 09:01:40 +00:00
2025-03-14 08:58:08 +00:00
//
2025-04-11 09:17:37 +00:00
setSubWidgetAttribute(_expertmentSettingForm);
setSubWidgetAttribute(_specificHeatComparisonMethodForm);
setSubWidgetAttribute(_realTimeDataForm);
setSubWidgetAttribute(_degreeOfCureForm);
setSubWidgetAttribute(_instrumentCoefficientForm);
setSubWidgetAttribute(_OITAutoAnalysisParamForm);
setSubWidgetAttribute(_degreeOfCrystallinityForm);
2025-04-14 09:11:01 +00:00
setSubWidgetAttribute(_aboutForm);
2025-04-16 07:38:25 +00:00
setSubWidgetAttribute(_enthalpyDataCorrectionForm);
2025-04-18 09:30:35 +00:00
setSubWidgetAttribute(_coefficientSelectionForm);
2025-04-25 09:20:33 +00:00
setSubWidgetAttribute(_printPreviewForm);
2025-04-29 09:29:14 +00:00
setSubWidgetAttribute(_axisSettingForm);
2025-04-11 09:17:37 +00:00
//
2025-03-21 09:28:36 +00:00
setActionEnable(true);
2025-04-10 09:33:38 +00:00
_eventHandler = _centralWidget->getEvnetHandler();
//
connections();
2025-04-22 08:59:26 +00:00
//
// ui->actionStop->setEnabled(false);
2025-04-10 09:33:38 +00:00
2025-03-05 09:33:46 +00:00
}
MainWindow::~MainWindow()
{
delete ui;
2025-03-21 09:28:36 +00:00
}
void MainWindow::slotContextMenuShow(const QPoint point)
{
_contextMenu->exec(point);
2025-03-05 09:33:46 +00:00
}
2025-04-25 09:20:33 +00:00
void MainWindow::slotUpdateStatusbarMsg(const QString msg)
2025-04-24 08:41:20 +00:00
{
2025-04-25 09:20:33 +00:00
ui->statusbar->showMessage(msg);
2025-04-24 08:41:20 +00:00
}
2025-06-20 09:28:45 +00:00
void MainWindow::slotOITAutoAnalysis(const double x1,const double x2)
{
on_actionStop_triggered();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::OIT);
_centralWidget->setVerticalLineRange(x1,x2);
}
2025-04-16 07:38:25 +00:00
void MainWindow::closeEvent(QCloseEvent *event)
{
// 弹出确认对话框
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "确认退出", "你确定要退出吗?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
event->accept(); // 接受关闭事件,关闭窗口
} else {
event->ignore(); // 忽略关闭事件,不关闭窗口
}
}
2025-03-12 09:29:52 +00:00
void MainWindow::connections()
{
2025-03-18 03:43:14 +00:00
// ui
connect(_expertmentSettingForm, &ExperimentSettingForm::sigDeliverData,
SerialPort::instance(), &SerialPort::slotDeliverData);
2025-03-14 08:58:08 +00:00
#if 1
2025-05-15 09:31:03 +00:00
// SerialPort.
2025-03-18 03:43:14 +00:00
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
2025-03-19 07:19:45 +00:00
_centralWidget, &CentralWidget::slotRecvCommonData);
2025-03-18 03:43:14 +00:00
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
connect(SerialPort::instance(), &SerialPort::sigSendCommonDataToRealDataForm,
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
connect(SerialPort::instance(), &SerialPort::sigSendPhaseInfo,
_expertmentSettingForm, &ExperimentSettingForm::slotRecvPhaseInfo);
2025-04-23 07:33:39 +00:00
connect(SerialPort::instance(), &SerialPort::sigAxisModify,
_centralWidget, &CentralWidget::slotAxisModify);
2025-04-25 09:20:33 +00:00
connect(SerialPort::instance(), &SerialPort::sigUpdateStatusbarMsg,
this,&MainWindow::slotUpdateStatusbarMsg);
2025-05-15 09:31:03 +00:00
connect(SerialPort::instance(), &SerialPort::sigSaveExperimentalDataMsgBox,
this,&MainWindow::slotSaveExperimentalDataMsgBox);
2025-03-14 08:58:08 +00:00
#endif
2025-03-18 03:43:14 +00:00
// mode
2025-06-13 07:55:18 +00:00
2025-04-15 08:03:00 +00:00
// connect(Global::instance(), &Global::sigModeModify,
// _centralWidget, &CentralWidget::slotModeModify);
2025-04-23 07:33:39 +00:00
2025-03-19 07:19:45 +00:00
//analysis
connect(_leftWidget,&LeftWidget::sigSendAnalysisFileName,
_centralWidget,&CentralWidget::slotRecvAnalysisFileName);
2025-03-21 09:28:36 +00:00
connect(_centralWidget,&CentralWidget::sigSendLineXCoord,
_analysisSettingWidget,&AnalysisSettingForm::slotRecvLineXCoord);
connect(_analysisSettingWidget,&AnalysisSettingForm::sigApply,
_centralWidget,&CentralWidget::slotAnalysisSettingApply);
2025-03-24 09:30:42 +00:00
connect(_analysisSettingWidget,&AnalysisSettingForm::sigUndo,
_centralWidget,&CentralWidget::slotAnalysisSettingUndo);
2025-04-24 06:35:53 +00:00
connect(_analysisSettingWidget,&AnalysisSettingForm::sigConfirm,
_centralWidget,&CentralWidget::slotAnalysisSettingConfirm);
2025-03-24 09:30:42 +00:00
connect(_analysisSettingWidget,&AnalysisSettingForm::sigCancel,
_centralWidget,&CentralWidget::slotAnalysisSettingCancel);
2025-04-01 09:25:12 +00:00
connect(_centralWidget,&CentralWidget::sigRightDockWidgetHide,
[&](){ _rightWidget->hide(); });
2025-04-10 09:33:38 +00:00
2025-04-27 07:27:07 +00:00
connect(_degreeOfCrystallinityForm,&DegreeOfCrystallinityForm::sigDrawCustomText,
_centralWidget,&CentralWidget::slotDrawCustomText);
2025-04-28 06:16:26 +00:00
connect(_specificHeatComparisonMethodForm,&SpecificHeatComparisonMethodForm::sigDrawCustomText,
_centralWidget,&CentralWidget::slotDrawCustomText);
2025-04-27 07:27:07 +00:00
2025-06-13 07:55:18 +00:00
// SpecificHeatComparisonMethodForm
2025-04-10 09:33:38 +00:00
connect(_eventHandler,&EventHandler::sigSetCurve,
_specificHeatComparisonMethodForm,
&SpecificHeatComparisonMethodForm::slotSetCurve);
2025-04-22 08:59:26 +00:00
2025-04-29 09:29:14 +00:00
// Axis settings.
connect(_axisSettingForm,&AxisSettingForm::sigGetAxisInfo,
_centralWidget,&CentralWidget::slotGetAxisInfo);
connect(_centralWidget,&CentralWidget::sigGetAxisInfoWithData,
_axisSettingForm,&AxisSettingForm::slotGetAxisInfoWithData);
connect(_axisSettingForm,&AxisSettingForm::sigSetAxisSettings,
_centralWidget,&CentralWidget::slotSetAxisSettings);
2025-06-20 09:28:45 +00:00
// OIT
connect(OITAutoAnalysis::getInstance(),&OITAutoAnalysis::sigExperimentStop,
this,&MainWindow::slotOITAutoAnalysis);
2025-03-12 09:29:52 +00:00
}
2025-03-13 09:27:31 +00:00
void MainWindow::setActionEnable(const bool flag)
{
2025-03-18 03:43:14 +00:00
if (flag)
{
2025-03-13 09:27:31 +00:00
ui->actionNew->setEnabled(true);
ui->actionStart->setEnabled(true);
ui->actionStop->setEnabled(true);
ui->actionRealTimeWidget->setEnabled(true);
2025-06-13 07:55:18 +00:00
}else{
2025-03-13 09:27:31 +00:00
ui->actionNew->setEnabled(false);
ui->actionStart->setEnabled(false);
ui->actionStop->setEnabled(false);
ui->actionRealTimeWidget->setEnabled(false);
}
}
2025-04-11 09:17:37 +00:00
void MainWindow::setSubWidgetAttribute(QWidget *widget)
{
widget->setWindowModality(Qt::ApplicationModal);
widget->setWindowFlags(Qt::Dialog);
2025-04-17 09:31:46 +00:00
widget->setFixedSize(widget->geometry().width(),widget->geometry().height());
2025-04-11 09:17:37 +00:00
}
2025-06-13 07:55:18 +00:00
2025-05-13 09:33:40 +00:00
#if 0
2025-04-22 08:59:26 +00:00
bool MainWindow::saveExperimentFile(const QString fileName)
2025-03-13 09:27:31 +00:00
{
2025-04-22 08:59:26 +00:00
QString localFileName = fileName;
if(fileName.isEmpty()){
2025-05-13 09:33:40 +00:00
localFileName = "new";
2025-04-22 08:59:26 +00:00
}
QString xlsxfilePath = Global::SampleDataFloder + "/" + localFileName + ".xlsx";
QString filePath = QFileDialog::getSaveFileName(nullptr, "Save experiment file",
xlsxfilePath, "Excel Files (*.xlsx)");
logde<<"filePath:"<<filePath.toStdString();
if (filePath.isEmpty()) {
qDebug() << "User cancel the operation.";
return false;
}
2025-03-18 09:28:40 +00:00
2025-04-22 08:59:26 +00:00
XlsxHandler::writeFile(filePath);
2025-03-24 09:30:42 +00:00
2025-04-22 08:59:26 +00:00
return true;
}
2025-04-15 08:03:00 +00:00
2025-05-13 09:33:40 +00:00
bool MainWindow::saveAnalysisFile(const QString fileName)
{
QString localFileName = fileName;
if(fileName.isEmpty()){
localFileName = "new";
}
QString xlsxfilePath = Global::AnalysisStateFolder + "/" + localFileName + ".xlsx";
QString filePath = QFileDialog::getSaveFileName(nullptr, "Save experiment file",
xlsxfilePath, "Excel Files (*.xlsx)");
logde<<"filePath:"<<filePath.toStdString();
if (filePath.isEmpty()) {
qDebug() << "User cancel the operation.";
return false;
}
XlsxHandler::writeAnalysisOperation(filePath);
return true;
}
#endif
2025-05-16 09:01:40 +00:00
2025-06-20 09:28:45 +00:00
bool MainWindow::saveFile(const QString fileName,const Global::Mode mode,
QString& finalFileName,const bool autoSaveFlag)
2025-05-13 09:33:40 +00:00
{
2025-06-23 02:42:15 +00:00
logde<<"save file...";
2025-05-13 09:33:40 +00:00
QString localFileName = fileName;
if(fileName.isEmpty()){
localFileName = "new";
}
QString folder;
2025-05-22 09:31:38 +00:00
if(mode == Global::Mode::None){
folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
}else if(mode == Global::Mode::Analysis){
2025-05-13 09:33:40 +00:00
folder = Global::AnalysisStateFolder;
2025-05-15 09:31:03 +00:00
}else if(mode == Global::Mode::Experiment){
2025-05-13 09:33:40 +00:00
folder = Global::SampleDataFloder;
}
2025-06-20 09:28:45 +00:00
QString filePath;
if(autoSaveFlag){
localFileName = _leftWidget->filePathCheck(fileName,folder);
filePath = folder + "/" + localFileName + ".xlsx";
}else{
QString xlsxfilePath = folder + "/" + localFileName + ".xlsx";
filePath = QFileDialog::getSaveFileName(nullptr, "Save experiment file",
xlsxfilePath, "Excel Files (*.xlsx)");
}
//
finalFileName = localFileName + ".xlsx";
2025-05-13 09:33:40 +00:00
logde<<"filePath:"<<filePath.toStdString();
if (filePath.isEmpty()) {
qDebug() << "User cancel the operation.";
return false;
}
2025-06-06 09:17:31 +00:00
// Save file.
2025-05-15 09:31:03 +00:00
if(mode == Global::Mode::Analysis){
2025-05-30 05:46:40 +00:00
if(Global::_curveFileDataVtr.empty()){
2025-06-13 07:55:18 +00:00
// 分析模式下,但是文件数据为空,说明做完实验没有保存数据。
2025-06-06 09:17:31 +00:00
XlsxHandler::writeExperimentFile(filePath);
2025-05-30 05:46:40 +00:00
}else{
2025-06-16 09:25:41 +00:00
// 分析模式下,存在文件数据,将文件数据写入文件。
XlsxHandler::writeXlsxFile(filePath);
#if 0
2025-06-13 07:55:18 +00:00
// 分析模式下,直接保存从文件读取来的数据。
2025-06-06 09:17:31 +00:00
if(Global::_smoothnessFlag){
2025-06-09 05:38:12 +00:00
XlsxHandler::writeSmoothnessFile(filePath);
2025-06-06 09:17:31 +00:00
}else{
2025-06-13 07:55:18 +00:00
// 直接在xlsx文件的基础上添加分析数据。
XlsxHandler::xlsxFileAppendAnalysisOperation(filePath);
2025-06-06 09:17:31 +00:00
}
2025-06-16 09:25:41 +00:00
#endif
2025-05-30 05:46:40 +00:00
}
2025-05-15 09:31:03 +00:00
}else if(mode == Global::Mode::Experiment){
2025-06-06 09:17:31 +00:00
XlsxHandler::writeExperimentFile(filePath);
2025-05-13 09:33:40 +00:00
}
return true;
}
2025-06-06 09:17:31 +00:00
void MainWindow::smoothness(const int level)
{
2025-06-16 09:25:41 +00:00
#if 0
2025-06-06 09:17:31 +00:00
Global::_smoothnessFlag = true;
2025-06-16 09:25:41 +00:00
2025-06-06 09:17:31 +00:00
// process data.
2025-06-13 07:55:18 +00:00
QVector<Global::ExperimentData> smoothDataVtr;
2025-06-06 09:17:31 +00:00
QString objectName;
QCPCurve ** curvePtrPtr;
2025-06-16 09:25:41 +00:00
// 当前数据为实验数据时,需要把所有的当前实验数据都尽心平滑处理。
2025-06-06 09:17:31 +00:00
if(!Global::_curveExperimentDataVtr.empty()){
for(auto & item:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(item.curve)){
2025-06-13 07:55:18 +00:00
smoothDataVtr = smoothnessDetail(level,item.dataVtr);
2025-06-06 09:17:31 +00:00
2025-06-13 07:55:18 +00:00
item.smoothDataVtr = smoothDataVtr;
objectName = Global::ObjectNameExperiemnt;
2025-06-06 09:17:31 +00:00
curvePtrPtr = &item.curve;
}
}
}else{
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
2025-06-13 07:55:18 +00:00
smoothDataVtr = smoothnessDetail(level,pti.dataVtr);
pti.smoothDataVtr = smoothDataVtr;
2025-06-06 09:17:31 +00:00
objectName = cfd.fileName;
curvePtrPtr = &pti.curve;
}
}
}
}
//
_centralWidget->deleteCurrentCurve();
//
2025-06-13 07:55:18 +00:00
QString wholeObjectName = Global::ObjectNameSmooth + Global::Separator + objectName;
_centralWidget->addCurveData(smoothDataVtr,wholeObjectName);
2025-06-06 09:17:31 +00:00
*curvePtrPtr = _centralWidget->getCurrentCurve();
2025-06-16 09:25:41 +00:00
#endif
if(!Global::_curveExperimentDataVtr.empty()){
// 当前数据为实验数据时,需要把所有的当前实验数据都进行平滑处理。
// 删除所有objectName为experiment的curve.
_centralWidget->deleteCurveByObjectName(Global::ObjectNameExperiemnt);
// 添加所有平滑后的curve.
for(auto & item:Global::_curveExperimentDataVtr){
item.smoothDataVtr = smoothnessDetail(level,item.dataVtr);
item.curve = _centralWidget->addCurveData(item.smoothDataVtr,Global::ObjectNameExperiemnt);
}
}else{
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
QString selectedCurveObjectName = _centralWidget->getCurrentCurve()->objectName();
_centralWidget->deleteCurveByObjectName(selectedCurveObjectName);
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
if(selectedCurveObjectName.contains(cfd.filePath)){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
pti.smoothDataVtr = smoothnessDetail(level,pti.dataVtr);
pti.curve = _centralWidget->addCurveData(pti.smoothDataVtr,
cfd.filePath);
}
}
}
}
2025-06-06 09:17:31 +00:00
}
2025-06-13 07:55:18 +00:00
QVector<Global::ExperimentData> MainWindow::smoothnessDetail(const int level,const QVector<Global::ExperimentData>&dataVtr)
2025-06-06 09:17:31 +00:00
{
Lowess::Config config;
2025-06-13 07:55:18 +00:00
config.smoothingFactor = level * 0.01;
2025-06-06 09:17:31 +00:00
config.robustnessIterations = 3;
std::vector<double> x;
std::vector<double> y;
2025-06-13 07:55:18 +00:00
for(const Global::ExperimentData& ed:dataVtr){
2025-06-06 09:17:31 +00:00
if(Global::_axisMode == Global::AxisMode::SingleY){
x.push_back(ed.sampleTemp);
}else{
x.push_back(ed.runTime);
}
y.push_back(ed.dsc);
}
logde<<"smooth start...";
std::vector<double> yest = Lowess::smooth(x, y, config);
logde<<"smooth end...";
2025-06-13 07:55:18 +00:00
// result data vector.
QVector<Global::ExperimentData> resultVtr;
2025-06-06 09:17:31 +00:00
for(int i = 0; i < x.size();i++){
Global::ExperimentData ed;
if(Global::_axisMode == Global::AxisMode::SingleY){
ed.sampleTemp = x.at(i);
ed.runTime = dataVtr.at(i).runTime;
}else{
ed.runTime = x.at(i);
ed.sampleTemp = dataVtr.at(i).sampleTemp;
}
ed.dsc = yest.at(i);
ed.constantTempTime = dataVtr.at(i).constantTempTime;
2025-06-13 07:55:18 +00:00
resultVtr.push_back(ed);
2025-06-06 09:17:31 +00:00
}
2025-06-13 07:55:18 +00:00
return resultVtr;
2025-06-06 09:17:31 +00:00
}
void MainWindow::smoothnessExperimentData(const int level)
{
#if 0
for(int i = 0;i < Global::_curveExperimentDataVtr.size();i++){
Global::CurveExperimentData ced = Global::_curveExperimentDataVtr.at(i);
smoothnessDetail()
}
#endif
for(auto & item:Global::_curveExperimentDataVtr){
smoothnessDetail(level,item.dataVtr);
}
}
2025-04-22 08:59:26 +00:00
void MainWindow::on_actionStop_triggered()
{
2025-05-19 09:29:21 +00:00
logde<<" Stop experiment ...";
2025-06-06 09:17:31 +00:00
2025-04-22 08:59:26 +00:00
if(Global::_mode == Global::Mode::Experiment)
{
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop);
SerialPort::instance()->slotSendData(ba);
2025-06-23 02:42:15 +00:00
// Set software mode to analysis.
_manuallyStopTheExperimentFlag = true;
logde<<"_manuallyStopTheExperimentFlag:"<<_manuallyStopTheExperimentFlag;
Global::_mode = Global::Mode::Analysis;
2025-04-22 08:59:26 +00:00
// Save data.
2025-06-23 02:42:15 +00:00
#if 1
logde<<"on_actionStop_triggered saveFile ...";
2025-06-06 09:17:31 +00:00
2025-06-20 09:28:45 +00:00
QString finalFileName;
if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){
2025-04-22 08:59:26 +00:00
_leftWidget->reloadFileName();
2025-06-20 09:28:45 +00:00
QString str = QString("%1 文件保存成功。").arg(finalFileName);
QMessageBox::information(this, "文件保存", str,QMessageBox::Yes );
2025-04-22 08:59:26 +00:00
}
#endif
}
2025-03-13 09:27:31 +00:00
}
2025-03-12 09:29:52 +00:00
2025-03-13 09:27:31 +00:00
void MainWindow::on_actionNew_triggered()
2025-03-12 09:29:52 +00:00
{
2025-03-13 09:27:31 +00:00
_expertmentSettingForm->show();
}
2025-03-12 09:29:52 +00:00
2025-03-13 09:27:31 +00:00
void MainWindow::on_actionStart_triggered()
{
2025-05-19 09:29:21 +00:00
logde<<"start experiment,set soft into experiment mode.";
2025-05-15 09:31:03 +00:00
on_actionClearAllData_triggered();
2025-03-13 09:27:31 +00:00
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start);
2025-03-14 08:58:08 +00:00
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
qDebug() << "on_actionStart_triggered info (hex):" << hexData;
2025-03-13 09:27:31 +00:00
SerialPort::instance()->slotSendData(ba);
2025-03-24 09:30:42 +00:00
2025-04-22 08:59:26 +00:00
Global::_mode = Global::Mode::Experiment;
2025-05-15 09:31:03 +00:00
_manuallyStopTheExperimentFlag = false;
2025-06-18 09:28:38 +00:00
_centralWidget->startExperiment();
2025-03-13 09:27:31 +00:00
}
void MainWindow::on_actionReadOnly_triggered()
{
2025-04-22 08:59:26 +00:00
Global::_mode = Global::Mode::Experiment;
2025-03-13 09:27:31 +00:00
SerialPort::instance()->openSp();
}
void MainWindow::on_actionRealTimeWidget_triggered()
{
_realTimeDataForm->show();
}
2025-05-15 09:31:03 +00:00
void MainWindow::slotSaveExperimentalDataMsgBox()
{
2025-06-23 02:42:15 +00:00
logde<<"_manuallyStopTheExperimentFlag:"<<_manuallyStopTheExperimentFlag;
2025-05-15 09:31:03 +00:00
if(_manuallyStopTheExperimentFlag){
2025-05-16 09:01:40 +00:00
logde<<"_manuallyStopTheExperimentFlag...";
2025-05-15 09:31:03 +00:00
return;
}
2025-06-20 09:28:45 +00:00
// auto save file.
2025-06-23 02:42:15 +00:00
logde<<"slotSaveExperimentalDataMsgBox saveFile ...";
2025-06-20 09:28:45 +00:00
QString finalFileName;
if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finalFileName,true)){
_leftWidget->reloadFileName();
QString str = QString("%1 文件保存成功。").arg(finalFileName);
QMessageBox::information(this, "文件保存", str,QMessageBox::Yes );
}
#if 0
2025-05-15 09:31:03 +00:00
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "数据保存提示", "是否保存实验数据?",
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
2025-06-20 09:28:45 +00:00
QString finaleFileName;
saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment,finaleFileName);
2025-05-21 08:36:47 +00:00
_leftWidget->reloadFileName();
2025-05-15 09:31:03 +00:00
} else {
on_actionClearAllData_triggered();
}
2025-05-29 09:19:11 +00:00
#endif
2025-05-15 09:31:03 +00:00
}
2025-03-13 09:27:31 +00:00
void MainWindow::on_actionConnectToDev_triggered()
{
2025-05-29 09:19:11 +00:00
if(SerialPort::instance()->isOpen()){
SerialPort::instance()->closeSp();
2025-05-19 09:29:21 +00:00
2025-05-29 09:19:11 +00:00
ui->actionConnectToDev->setIcon(QIcon(":/images/connect.png"));
ui->actionConnectToDev->setText("连接设备");
2025-03-19 03:19:52 +00:00
2025-05-29 09:19:11 +00:00
logde<<"close serial port.";
}else{
if (SerialPort::instance()->openSp())
{
setActionEnable(true);
// Global::instance()->setMode(Global::Mode::ConnectedToDev);
Global::_mode = Global::Mode::ConnectedToDev;
QByteArray ba = DataParser::inquirePhaseInfo();
SerialPort::instance()->sendData(ba);
ui->actionConnectToDev->setIcon(QIcon(":/images/disconnect.png"));
ui->actionConnectToDev->setText("断开连接");
logde<<"open serial port.";
}
else
{
QMessageBox::warning(this, "warnning", "Serial Port open failed.");
}
2025-03-13 09:27:31 +00:00
}
2025-03-12 09:29:52 +00:00
}
2025-03-20 09:28:22 +00:00
void MainWindow::on_actionStartPoint_triggered()
{
2025-03-25 08:45:16 +00:00
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::StartPoint);
2025-03-20 09:28:22 +00:00
}
void MainWindow::on_actionStopPoint_triggered()
{
2025-03-25 08:45:16 +00:00
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::StopPoint);
2025-03-20 09:28:22 +00:00
}
void MainWindow::on_actionNumericalLabel_triggered()
{
2025-03-21 09:28:36 +00:00
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::NumericalLabel);
2025-03-20 09:28:22 +00:00
}
2025-03-24 09:30:42 +00:00
void MainWindow::on_actionPeakSynthesisAnalysis_triggered()
{
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::PeakSynthesisAnalysis);
}
2025-03-25 08:45:16 +00:00
void MainWindow::on_actionClearAllData_triggered()
{
2025-04-09 09:30:32 +00:00
_rightWidget->hide();
2025-03-25 08:45:16 +00:00
_centralWidget->clearAllData();
}
2025-04-03 09:24:29 +00:00
void MainWindow::on_actionGlassTransition_triggered()
{
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::GlassTransition);
}
void MainWindow::on_actionOIT_triggered()
{
2025-06-12 09:27:45 +00:00
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::OIT);
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionSpecificHeatCompMethod_triggered()
{
_specificHeatComparisonMethodForm->show();
}
void MainWindow::on_actionDegreeOfCrystallinity_triggered()
{
2025-04-15 08:03:00 +00:00
// QMessageBox::warning(this, "warnning", "结晶度.");
2025-04-11 09:17:37 +00:00
_degreeOfCrystallinityForm->show();
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionInstrumentParameter_triggered()
{
2025-04-11 05:51:47 +00:00
_instrumentCoefficientForm->show();
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionOITAutoAnalysisParam_triggered()
{
2025-04-11 09:17:37 +00:00
_OITAutoAnalysisParamForm->show();
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionOITAutoAnalysisMode_triggered()
{
2025-06-20 09:28:45 +00:00
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionTimeAxisAnalysisPCTMode_triggered()
{
2025-04-30 02:59:08 +00:00
Global::_displayTimeValue = ui->actionTimeAxisAnalysisPCTMode->isChecked();
2025-04-03 09:24:29 +00:00
}
void MainWindow::on_actionDegreeOfCuring_triggered()
{
2025-04-11 05:51:47 +00:00
//
_degreeOfCureForm->show();
2025-04-03 09:24:29 +00:00
}
2025-04-14 09:11:01 +00:00
void MainWindow::on_actionAbout_triggered()
{
_aboutForm->show();
}
2025-04-16 07:38:25 +00:00
2025-04-18 09:30:35 +00:00
void MainWindow::on_actionEnthalpyCorrectionEdit_triggered()
2025-04-16 07:38:25 +00:00
{
_enthalpyDataCorrectionForm->show();
}
2025-04-18 09:30:35 +00:00
void MainWindow::on_actionEnthalpyCorrectionSelection_triggered()
{
_coefficientSelectionForm->show();
}
2025-04-23 07:33:39 +00:00
2025-04-25 09:20:33 +00:00
void MainWindow::on_actionPrintPreview_triggered()
{
2025-05-22 09:31:38 +00:00
// _printPreviewForm->show();
2025-05-19 05:58:34 +00:00
2025-05-19 09:29:21 +00:00
_printPreviewForm->setPixmap(_centralWidget->getPixMap());
2025-05-19 05:58:34 +00:00
_printPreviewForm->_customPrintPreviewDialog->showMaximized();
2025-04-25 09:20:33 +00:00
}
2025-04-28 06:16:26 +00:00
void MainWindow::on_actionOnsetTemperaturePoint_triggered()
{
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::OnsetTemperaturePoint);
}
void MainWindow::on_actionEndsetTemperaturePoint_triggered()
{
_rightWidget->show();
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::EndsetTemperaturePoint);
}
2025-04-28 09:31:29 +00:00
void MainWindow::on_actionYAxis_triggered()
{
2025-05-13 09:33:40 +00:00
_centralWidget->switchAxisMode();
2025-04-28 09:31:29 +00:00
}
2025-04-29 09:29:14 +00:00
void MainWindow::on_actionAxisSetting_triggered()
{
_axisSettingForm->show();
}
2025-05-13 09:33:40 +00:00
void MainWindow::on_actionSaveData_triggered()
{
2025-06-20 09:28:45 +00:00
QString finaleFileName;
saveFile(Global::_experimentInfo.sampleName,Global::_mode,finaleFileName);
2025-05-16 09:01:40 +00:00
_leftWidget->reloadFileName();
2025-05-13 09:33:40 +00:00
}
2025-05-22 09:31:38 +00:00
void MainWindow::on_actionSaveas_triggered()
{
2025-06-20 09:28:45 +00:00
QString finaleFileName;
saveFile(Global::_experimentInfo.sampleName,Global::Mode::None,finaleFileName);
2025-05-22 09:31:38 +00:00
_leftWidget->reloadFileName();
}
2025-05-26 06:32:01 +00:00
void MainWindow::on_actionLanguage_triggered()
{
if(Global::_languageType == Global::LanguageType::Chinese){
Global::_languageType = Global::LanguageType::English;
ui->actionLanguage->setText(Global::EnglishStr);
}else{
Global::_languageType = Global::LanguageType::Chinese;
ui->actionLanguage->setText(Global::ChineseStr);
}
2025-06-06 09:17:31 +00:00
}
2025-05-26 06:32:01 +00:00
2025-06-06 09:17:31 +00:00
void MainWindow::on_actionSmoothness1_triggered()
{
smoothness(1);
2025-05-26 06:32:01 +00:00
}
2025-06-06 09:17:31 +00:00
void MainWindow::on_actionSmoothness2_triggered()
{
smoothness(2);
}
void MainWindow::on_actionSmoothness3_triggered()
{
smoothness(3);
}
void MainWindow::on_actionSmoothness4_triggered()
{
smoothness(4);
}
void MainWindow::on_actionSmoothness5_triggered()
{
smoothness(5);
}
void MainWindow::on_actionSmoothness6_triggered()
{
smoothness(6);
}
void MainWindow::on_actionSmoothness7_triggered()
{
smoothness(7);
}
void MainWindow::on_actionSmoothness8_triggered()
{
smoothness(8);
}
void MainWindow::on_actionSmoothness9_triggered()
{
smoothness(9);
}
void MainWindow::on_actionSmoothness10_triggered()
{
smoothness(10);
}
2025-06-13 07:55:18 +00:00
void MainWindow::on_actionOriginalData_triggered()
{
2025-06-16 09:25:41 +00:00
if(!Global::_curveExperimentDataVtr.empty()){
// 删除所有objectName为experiment的curve.
_centralWidget->deleteCurveByObjectName(Global::ObjectNameExperiemnt);
for(auto & item:Global::_curveExperimentDataVtr){
item.smoothDataVtr.clear();
item.curve = _centralWidget->addCurveData(item.dataVtr,Global::ObjectNameExperiemnt);
}
}else{
// 当前数据为文件分析数据时,需要把当前文件下的所有数据都进行平滑处理。
QString selectedCurveObjectName = _centralWidget->getCurrentCurve()->objectName();
_centralWidget->deleteCurveByObjectName(selectedCurveObjectName);
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
if(selectedCurveObjectName.contains(cfd.filePath)){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
pti.smoothDataVtr.clear();
pti.curve = _centralWidget->addCurveData(pti.dataVtr,
cfd.filePath);
}
}
}
}
2025-06-13 07:55:18 +00:00
2025-06-16 09:25:41 +00:00
#if 0
2025-06-13 07:55:18 +00:00
// process data.
QVector<Global::ExperimentData> targetDataVtr;
QString objectName;
QCPCurve ** curvePtrPtr;
if(!Global::_curveExperimentDataVtr.empty()){
for(auto & item:Global::_curveExperimentDataVtr){
if(_centralWidget->isCurrentCurve(item.curve)){
targetDataVtr = item.dataVtr;
objectName = Global::ObjectNameExperiemnt;
curvePtrPtr = &item.curve;
}
}
}else{
for(Global::CurveFileData &cfd :Global::_curveFileDataVtr){
for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){
if(_centralWidget->isCurrentCurve(pti.curve)){
targetDataVtr = pti.dataVtr;
2025-06-16 09:25:41 +00:00
objectName = cfd.filePath;
2025-06-13 07:55:18 +00:00
curvePtrPtr = &pti.curve;
}
}
}
}
//
2025-06-16 09:25:41 +00:00
_centralWidget->deleteCurveByObjectName(_centralWidget->getCurrentCurve()->objectName());
2025-06-13 07:55:18 +00:00
_centralWidget->addCurveData(targetDataVtr,objectName);
*curvePtrPtr = _centralWidget->getCurrentCurve();
2025-06-16 09:25:41 +00:00
#endif
2025-06-13 07:55:18 +00:00
}