diff --git a/experiment_data/sample_data/new_2025_09_28_08_41_26.xlsx b/experiment_data/sample_data/new_2025_09_28_08_41_26.xlsx new file mode 100644 index 0000000..e6fcc7b Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_41_26.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_49_55.xlsx b/experiment_data/sample_data/new_2025_09_28_08_49_55.xlsx new file mode 100644 index 0000000..f5b66df Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_49_55.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_51_43.xlsx b/experiment_data/sample_data/new_2025_09_28_08_51_43.xlsx new file mode 100644 index 0000000..673c764 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_51_43.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_51_58.xlsx b/experiment_data/sample_data/new_2025_09_28_08_51_58.xlsx new file mode 100644 index 0000000..1c87aad Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_51_58.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_52_02.xlsx b/experiment_data/sample_data/new_2025_09_28_08_52_02.xlsx new file mode 100644 index 0000000..260ac6a Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_52_02.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_52_48.xlsx b/experiment_data/sample_data/new_2025_09_28_08_52_48.xlsx new file mode 100644 index 0000000..e3c4bf9 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_52_48.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_54_03.xlsx b/experiment_data/sample_data/new_2025_09_28_08_54_03.xlsx new file mode 100644 index 0000000..bf142e9 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_54_03.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_08_57_26.xlsx b/experiment_data/sample_data/new_2025_09_28_08_57_26.xlsx new file mode 100644 index 0000000..40f438e Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_08_57_26.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_09_30_38.xlsx b/experiment_data/sample_data/new_2025_09_28_09_30_38.xlsx new file mode 100644 index 0000000..b8a990d Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_09_30_38.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_10_01_26.xlsx b/experiment_data/sample_data/new_2025_09_28_10_01_26.xlsx new file mode 100644 index 0000000..b1c8784 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_10_01_26.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_10_29_10.xlsx b/experiment_data/sample_data/new_2025_09_28_10_29_10.xlsx new file mode 100644 index 0000000..85dd97d Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_10_29_10.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_12_10.xlsx b/experiment_data/sample_data/new_2025_09_28_11_12_10.xlsx new file mode 100644 index 0000000..b8b7209 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_12_10.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_16_53.xlsx b/experiment_data/sample_data/new_2025_09_28_11_16_53.xlsx new file mode 100644 index 0000000..854b16e Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_16_53.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_25_00.xlsx b/experiment_data/sample_data/new_2025_09_28_11_25_00.xlsx new file mode 100644 index 0000000..127b8ba Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_25_00.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_28_02.xlsx b/experiment_data/sample_data/new_2025_09_28_11_28_02.xlsx new file mode 100644 index 0000000..1adf791 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_28_02.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_40_25.xlsx b/experiment_data/sample_data/new_2025_09_28_11_40_25.xlsx new file mode 100644 index 0000000..5602705 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_40_25.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_40_47.xlsx b/experiment_data/sample_data/new_2025_09_28_11_40_47.xlsx new file mode 100644 index 0000000..be8f370 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_40_47.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_41_10.xlsx b/experiment_data/sample_data/new_2025_09_28_11_41_10.xlsx new file mode 100644 index 0000000..0c37b2c Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_41_10.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_11_45_16.xlsx b/experiment_data/sample_data/new_2025_09_28_11_45_16.xlsx new file mode 100644 index 0000000..be94d3c Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_11_45_16.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_08_30.xlsx b/experiment_data/sample_data/new_2025_09_28_13_08_30.xlsx new file mode 100644 index 0000000..f09efea Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_08_30.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_09_25.xlsx b/experiment_data/sample_data/new_2025_09_28_13_09_25.xlsx new file mode 100644 index 0000000..f651b1d Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_09_25.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_10_25.xlsx b/experiment_data/sample_data/new_2025_09_28_13_10_25.xlsx new file mode 100644 index 0000000..432c050 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_10_25.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_11_14.xlsx b/experiment_data/sample_data/new_2025_09_28_13_11_14.xlsx new file mode 100644 index 0000000..5020fcf Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_11_14.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_11_27.xlsx b/experiment_data/sample_data/new_2025_09_28_13_11_27.xlsx new file mode 100644 index 0000000..d4d525d Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_11_27.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_11_50.xlsx b/experiment_data/sample_data/new_2025_09_28_13_11_50.xlsx new file mode 100644 index 0000000..362a417 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_11_50.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_12_52.xlsx b/experiment_data/sample_data/new_2025_09_28_13_12_52.xlsx new file mode 100644 index 0000000..819f3aa Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_12_52.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_13_09.xlsx b/experiment_data/sample_data/new_2025_09_28_13_13_09.xlsx new file mode 100644 index 0000000..fdf4dd8 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_13_09.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_13_26.xlsx b/experiment_data/sample_data/new_2025_09_28_13_13_26.xlsx new file mode 100644 index 0000000..cc4c6cb Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_13_26.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_36_16.xlsx b/experiment_data/sample_data/new_2025_09_28_13_36_16.xlsx new file mode 100644 index 0000000..baf9975 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_36_16.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_36_29.xlsx b/experiment_data/sample_data/new_2025_09_28_13_36_29.xlsx new file mode 100644 index 0000000..046a3a7 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_36_29.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_40_31.xlsx b/experiment_data/sample_data/new_2025_09_28_13_40_31.xlsx new file mode 100644 index 0000000..b7f2a8e Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_40_31.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_13_59_00.xlsx b/experiment_data/sample_data/new_2025_09_28_13_59_00.xlsx new file mode 100644 index 0000000..0a90b20 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_13_59_00.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_02_51.xlsx b/experiment_data/sample_data/new_2025_09_28_14_02_51.xlsx new file mode 100644 index 0000000..721d915 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_02_51.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_04_38.xlsx b/experiment_data/sample_data/new_2025_09_28_14_04_38.xlsx new file mode 100644 index 0000000..c38b2f1 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_04_38.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_09_15.xlsx b/experiment_data/sample_data/new_2025_09_28_14_09_15.xlsx new file mode 100644 index 0000000..1565ce9 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_09_15.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_20_10.xlsx b/experiment_data/sample_data/new_2025_09_28_14_20_10.xlsx new file mode 100644 index 0000000..9f0a57c Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_20_10.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_23_52.xlsx b/experiment_data/sample_data/new_2025_09_28_14_23_52.xlsx new file mode 100644 index 0000000..93224a6 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_23_52.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_24_47.xlsx b/experiment_data/sample_data/new_2025_09_28_14_24_47.xlsx new file mode 100644 index 0000000..a9e4ee1 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_24_47.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_25_04.xlsx b/experiment_data/sample_data/new_2025_09_28_14_25_04.xlsx new file mode 100644 index 0000000..870ce45 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_25_04.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_14_27_53.xlsx b/experiment_data/sample_data/new_2025_09_28_14_27_53.xlsx new file mode 100644 index 0000000..517f2b5 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_14_27_53.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_26_27.xlsx b/experiment_data/sample_data/new_2025_09_28_15_26_27.xlsx new file mode 100644 index 0000000..65a3e6e Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_26_27.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_27_08.xlsx b/experiment_data/sample_data/new_2025_09_28_15_27_08.xlsx new file mode 100644 index 0000000..de2bddb Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_27_08.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_27_41.xlsx b/experiment_data/sample_data/new_2025_09_28_15_27_41.xlsx new file mode 100644 index 0000000..ecc977e Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_27_41.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_28_04.xlsx b/experiment_data/sample_data/new_2025_09_28_15_28_04.xlsx new file mode 100644 index 0000000..25289f4 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_28_04.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_28_30.xlsx b/experiment_data/sample_data/new_2025_09_28_15_28_30.xlsx new file mode 100644 index 0000000..b1ad3c5 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_28_30.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_28_53.xlsx b/experiment_data/sample_data/new_2025_09_28_15_28_53.xlsx new file mode 100644 index 0000000..1b3a190 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_28_53.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_29_50.xlsx b/experiment_data/sample_data/new_2025_09_28_15_29_50.xlsx new file mode 100644 index 0000000..bf65c27 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_29_50.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_30_27.xlsx b/experiment_data/sample_data/new_2025_09_28_15_30_27.xlsx new file mode 100644 index 0000000..5ffba0c Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_30_27.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_31_15.xlsx b/experiment_data/sample_data/new_2025_09_28_15_31_15.xlsx new file mode 100644 index 0000000..3cba62a Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_31_15.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_31_41.xlsx b/experiment_data/sample_data/new_2025_09_28_15_31_41.xlsx new file mode 100644 index 0000000..2ab8088 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_31_41.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_32_29.xlsx b/experiment_data/sample_data/new_2025_09_28_15_32_29.xlsx new file mode 100644 index 0000000..cd3ddbf Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_32_29.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_33_16.xlsx b/experiment_data/sample_data/new_2025_09_28_15_33_16.xlsx new file mode 100644 index 0000000..5fdf8d3 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_33_16.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_37_58.xlsx b/experiment_data/sample_data/new_2025_09_28_15_37_58.xlsx new file mode 100644 index 0000000..1c64ee4 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_37_58.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_52_33.xlsx b/experiment_data/sample_data/new_2025_09_28_15_52_33.xlsx new file mode 100644 index 0000000..c8cd5d6 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_52_33.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_53_08.xlsx b/experiment_data/sample_data/new_2025_09_28_15_53_08.xlsx new file mode 100644 index 0000000..d9cddc3 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_53_08.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_15_53_25.xlsx b/experiment_data/sample_data/new_2025_09_28_15_53_25.xlsx new file mode 100644 index 0000000..d7b2e9c Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_15_53_25.xlsx differ diff --git a/experiment_data/sample_data/new_2025_09_28_16_03_50.xlsx b/experiment_data/sample_data/new_2025_09_28_16_03_50.xlsx new file mode 100644 index 0000000..aa57b33 Binary files /dev/null and b/experiment_data/sample_data/new_2025_09_28_16_03_50.xlsx differ diff --git a/experiment_data/analysis_state/~$peak.xlsx b/experiment_data/sample_data/~$new_2025_09_28_14_04_38.xlsx similarity index 100% rename from experiment_data/analysis_state/~$peak.xlsx rename to experiment_data/sample_data/~$new_2025_09_28_14_04_38.xlsx diff --git a/experiment_data/analysis_state/~$样品.xlsx b/experiment_data/sample_data/~$new_2025_09_28_14_09_15.xlsx similarity index 100% rename from experiment_data/analysis_state/~$样品.xlsx rename to experiment_data/sample_data/~$new_2025_09_28_14_09_15.xlsx diff --git a/experiment_data/sample_data/~$new_2025_09_28_15_29_50.xlsx b/experiment_data/sample_data/~$new_2025_09_28_15_29_50.xlsx new file mode 100644 index 0000000..d4a5841 Binary files /dev/null and b/experiment_data/sample_data/~$new_2025_09_28_15_29_50.xlsx differ diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp index 0d1eb44..8d43e5a 100644 --- a/src/data/xlsxhandler.cpp +++ b/src/data/xlsxhandler.cpp @@ -147,7 +147,7 @@ void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex } void XlsxHandler::writeExperimentFile(const QString filePath) { - logde << "write file..."; + logde << "writeExperimentFile..."; #if 0 if(Global::_curveExperimentDataVtr.empty()){ @@ -293,9 +293,12 @@ void XlsxHandler::writeExperimentFile(const QString filePath) { // logde<<"edVtr size:"<slotSendData(ba); - Global::_mode = Global::Mode::Experiment; + Global::_mode = Global::Mode::Experiment; _manuallyStopTheExperimentFlag = false; _centralWidget->startExperiment(); } -void MainWindow::startExperimentByDeviceInfo() -{ - Global::_mode = Global::Mode::Experiment; +void MainWindow::startExperimentByDeviceInfo() { + Global::_mode = Global::Mode::Experiment; _manuallyStopTheExperimentFlag = false; _centralWidget->startExperiment(); + + // 实验开始,清除上一个实验所有数据。 + Global::clearExperimentData(); } void MainWindow::on_actionStop_triggered() { @@ -468,7 +470,7 @@ void MainWindow::on_actionNew_triggered() { void MainWindow::on_actionStart_triggered() { logde << "start experiment,set soft into experiment mode."; - logde<<"```````````````````````````````"; + logde << "```````````````````````````````"; if (!SerialPort::instance()->isOpen()) { showMesgBox("设备未连接,请先连接设备。"); @@ -500,7 +502,10 @@ void MainWindow::slotSaveExperimentalDataMsgBox() { // auto save file. logde << "slotSaveExperimentalDataMsgBox saveFile ..."; QString finalFileName; - if (saveFile(Global::_experimentInfo.sampleName, Global::Mode::Experiment, finalFileName, true)) { + if (saveFile(Global::_experimentInfo.sampleName, + Global::Mode::Experiment, + finalFileName, + true)) { _leftWidget->reloadFileName(); QString str = QString("%1 文件保存成功。").arg(finalFileName); @@ -526,6 +531,8 @@ void MainWindow::on_actionConnectToDev_triggered() { logde << "connect to device..."; if (SerialPort::instance()->isOpen()) { + logde << "close device."; + SerialPort::instance()->closeSp(); ui->actionConnectToDev->setIcon(QIcon(":/images/connect.png")); @@ -537,29 +544,25 @@ void MainWindow::on_actionConnectToDev_triggered() { slotUpdateStatusbarMsg(str); showMesgBox(str); } else { + logde << "open device."; + if (SerialPort::instance()->openSp()) { - - logde << "open serial port success. 1"; - setActionEnable(true); // Global::instance()->setMode(Global::Mode::ConnectedToDev); Global::_mode = Global::Mode::ConnectedToDev; - logde << "open serial port success. 2"; - QByteArray ba = DataParser::inquirePhaseInfo(); SerialPort::instance()->sendData(ba); ui->actionConnectToDev->setIcon(QIcon(":/images/disconnect.png")); ui->actionConnectToDev->setText("断开连接"); - logde << "open serial port."; // - logde << "open serial port success. 3"; - QString str("设备已连接。"); slotUpdateStatusbarMsg(str); showMesgBox(str); + + logde << "open serial port success. "; } else { // QMessageBox::warning(this, "warnning", "Serial Port open failed."); showMesgBox("设备打开失败。"); @@ -568,7 +571,7 @@ void MainWindow::on_actionConnectToDev_triggered() { } void MainWindow::on_actionStartPoint_triggered() { - logde<<"start experiment..."; + logde << "start experiment..."; _rightWidget->show(); _centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::StartPoint); @@ -590,6 +593,11 @@ void MainWindow::on_actionPeakSynthesisAnalysis_triggered() { } void MainWindow::on_actionClearAllData_triggered() { + // 实验过程中,不允许清除数据。 + if(Global::_mode == Global::Mode::Experiment) { + return; + } + slotUpdateStatusbarMsg(""); _rightWidget->hide(); diff --git a/src/serialport/serialport.cpp b/src/serialport/serialport.cpp index 98f0ad2..7d2ddce 100644 --- a/src/serialport/serialport.cpp +++ b/src/serialport/serialport.cpp @@ -77,33 +77,28 @@ SerialPort *SerialPort::instance() { } SerialPort::~SerialPort() { - logde<<"serialport destructor."; + logde << "serialport destructor."; + + closeSp(); - if (_sp && _sp->isOpen()) { - _sp->clear(); - _sp->close(); - } delete _sp; _sp = nullptr; } -void SerialPort::timerEvent(QTimerEvent *event) { -} - void SerialPort::slotReadData() { QByteArray ba = _sp->readAll(); if (ba.size() == 0) { return; } -#if 0 +#if 1 QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 logde << "receive info (hex):" << hexData.toStdString(); #endif SerialPortProtocol *spp = (SerialPortProtocol *)ba.data(); if (FRANE_HEAD != spp->head) { - qDebug() << "Data header error."; + logde << "Data header error."; return; } @@ -146,20 +141,40 @@ void SerialPort::updateStatus(const CommonData &cd) { // Switch the software mode accord to the serial port data. switch (cd.run_type) { - case DeviceRunStatus::Heat: - case DeviceRunStatus::ConstantTemp: - if (Global::_mode != Global::Mode::Experiment) { - Global::_mode = Global::Mode::Experiment; + case DeviceRunStatus::Heat: + case DeviceRunStatus::ConstantTemp: + if (Global::_mode != Global::Mode::Experiment) { + Global::_mode = Global::Mode::Experiment; + } + break; + case DeviceRunStatus::Idle: + case DeviceRunStatus::Cooling: + if (Global::_mode != Global::Mode::Analysis) { + Global::_mode = Global::Mode::Analysis; + } + break; + default: + break; + } + + // 判断是否根据下位机数据,切换软件实验模式。 + static Global::Mode preMode = Global::Mode::Analysis; + bool sendSaveSignalFlag = false; + if (Global::_mode != preMode) { + if (preMode == Global::Mode::Experiment + && Global::_mode == Global::Mode::Analysis) { + sendSaveSignalFlag = true; + } else if (preMode == Global::Mode::Analysis + && Global::_mode == Global::Mode::Experiment) { + + // 根据下位机数据,软件进入实验模式,开始实验。 + logde << "start experiment, accord to device data..."; + logde << "---------------------"; + + emit sigStartExperiment(); } - break; - case DeviceRunStatus::Idle: - case DeviceRunStatus::Cooling: - if (Global::_mode != Global::Mode::Analysis) { - Global::_mode = Global::Mode::Analysis; - } - break; - default: - break; + + preMode = Global::_mode; } // If phase update, add new phase data to the global param. @@ -174,11 +189,12 @@ void SerialPort::updateStatus(const CommonData &cd) { ced.phaseIndex = cd.current_phase; Global::_curveExperimentDataVtr.push_back(ced); + Global::_currentCurveExperimentDataPtr = - &Global::_curveExperimentDataVtr.last(); + &Global::_curveExperimentDataVtr.last(); Global::_currentCurveExperimentDataPtr->fileName = - Global::_experimentInfo.sampleName; + Global::_experimentInfo.sampleName; } } @@ -192,22 +208,22 @@ void SerialPort::updateStatus(const CommonData &cd) { bool experimentEnded = false; QString devRunModeStr; switch (cd.run_type) { - case DeviceRunStatus::Heat: - devRunModeStr = "升温"; - experimentEnded = true; - break; - case DeviceRunStatus::ConstantTemp: - devRunModeStr = "实验"; - experimentEnded = true; - break; - case DeviceRunStatus::Idle: - case DeviceRunStatus::Cooling: - devRunModeStr = "冷却"; - experimentEnded = false; - break; - break; - default: - break; + case DeviceRunStatus::Heat: + devRunModeStr = "升温"; + experimentEnded = true; + break; + case DeviceRunStatus::ConstantTemp: + devRunModeStr = "实验"; + experimentEnded = true; + break; + case DeviceRunStatus::Idle: + case DeviceRunStatus::Cooling: + devRunModeStr = "冷却"; + experimentEnded = false; + break; + break; + default: + break; } QString msg; @@ -219,28 +235,32 @@ void SerialPort::updateStatus(const CommonData &cd) { emit sigUpdateStatusbarMsg(msg); -#if 1 +#if 0 // If save experiment data. static Global::Mode preMode = Global::Mode::Analysis; bool sendSaveSignalFlag = false; if (Global::_mode != preMode) { if (preMode == Global::Mode::Experiment - && Global::_mode == Global::Mode::Analysis) { + && Global::_mode == Global::Mode::Analysis) { sendSaveSignalFlag = true; } else if (preMode == Global::Mode::Analysis && Global::_mode == Global::Mode::Experiment) { - logde<<"update status accord to device data..."; - logde<<"--------------------------------------"; + + // 根据下位机数据,软件进入实验模式,开始实验。 + logde << "start experiment, accord to device data..."; + logde << "---------------------"; + emit sigStartExperiment(); } preMode = Global::_mode; } +#endif + // 弹出保存数据对话框。 if (sendSaveSignalFlag && !Global::_OITAutoAnalysisModeFlag) { emit sigSaveExperimentalDataMsgBox(); } -#endif } void SerialPort::commonDataParser(const int dataLength, const u16 addr, @@ -256,7 +276,7 @@ void SerialPort::commonDataParser(const int dataLength, const u16 addr, phase.temp_flow = cd.phase_data[index].temp_flow; phase.cutoff_temp = cd.phase_data[index].cutoff_temp; phase.constant_temp_time_min = - cd.phase_data[index].constant_temp_time_min; + cd.phase_data[index].constant_temp_time_min; localLength -= phaseByteSize; localAddr += phaseByteSize; @@ -265,82 +285,88 @@ void SerialPort::commonDataParser(const int dataLength, const u16 addr, while (localLength) { logde << "localLength:" << localLength; switch (localAddr) { - case offsetof(CommonData, run_type): // 运行状态 - { - switch (cd.run_type) { - case DeviceRunStatus::Cooling: - // Global::instance()->setMode(Global::Mode::Analysis); - Global::_mode = Global::Mode::Analysis; - logde << "set global mode analysis.common data parser."; - break; - default: + case offsetof(CommonData, run_type): // 运行状态 + { + switch (cd.run_type) { + case DeviceRunStatus::Cooling: + // Global::instance()->setMode(Global::Mode::Analysis); + Global::_mode = Global::Mode::Analysis; + logde << "set global mode analysis.common data parser."; + break; + default: + break; + } + + localAddr += 1; + localLength -= 1; + break; } - - localAddr += 1; - localLength -= 1; - - break; - } - case offsetof(CommonData, current_gas): // 当前气氛 - // gas_type_set(dev->temp, msg_data.current_gas); - localAddr += 1; - localLength -= 1; - break; - case offsetof(CommonData, auto_pid_temp_flow): // 自整定升温速率 - localAddr += 4; - localLength -= 4; - break; - case offsetof(CommonData, run_mode): { - DeviceStartMode mode = (DeviceStartMode)cd.run_mode; - - switch (mode) { - case DeviceStartMode::Stop: - Global::_mode = Global::Mode::Analysis; - logde << "set global mode analysis."; + case offsetof(CommonData, current_gas): // 当前气氛 + // gas_type_set(dev->temp, msg_data.current_gas); + localAddr += 1; + localLength -= 1; break; - case DeviceStartMode::Start: - Global::_mode = Global::Mode::Experiment; + case offsetof(CommonData, auto_pid_temp_flow): // 自整定升温速率 + localAddr += 4; + localLength -= 4; break; - default: + case offsetof(CommonData, run_mode): { + DeviceStartMode mode = (DeviceStartMode)cd.run_mode; + + switch (mode) { + case DeviceStartMode::Stop: + Global::_mode = Global::Mode::Analysis; + logde << "set global mode analysis."; + break; + case DeviceStartMode::Start: + Global::_mode = Global::Mode::Experiment; + break; + default: + break; + } + // + localLength--; + localAddr++; + break; } - // - localLength--; - localAddr++; - - break; - } - case offsetof(CommonData, phase_data[0].onoff): - phaseParserFunc(0); - break; - case offsetof(CommonData, phase_data[1].onoff): - phaseParserFunc(1); - break; - case offsetof(CommonData, phase_data[2].onoff): - phaseParserFunc(2); - break; - case offsetof(CommonData, phase_data[3].onoff): - phaseParserFunc(3); - break; - case offsetof(CommonData, phase_data[4].onoff): - phaseParserFunc(4); - break; - case offsetof(CommonData, phase_data[5].onoff): - phaseParserFunc(5); - break; - default: - localLength--; - break; + case offsetof(CommonData, phase_data[0].onoff): + phaseParserFunc(0); + break; + case offsetof(CommonData, phase_data[1].onoff): + phaseParserFunc(1); + break; + case offsetof(CommonData, phase_data[2].onoff): + phaseParserFunc(2); + break; + case offsetof(CommonData, phase_data[3].onoff): + phaseParserFunc(3); + break; + case offsetof(CommonData, phase_data[4].onoff): + phaseParserFunc(4); + break; + case offsetof(CommonData, phase_data[5].onoff): + phaseParserFunc(5); + break; + default: + localLength--; + break; }; } } bool SerialPort::openSp() { logde << "openSp 1"; + closeSp(); + QThread::msleep(100); + +#if 0 if (_sp != nullptr && _sp->isOpen()) { return true; } +#endif + logde << "openSp 2"; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { u16 pid = info.productIdentifier(); @@ -376,7 +402,7 @@ bool SerialPort::openSp() { return false; } else { // qDebug() << "open succ."; - logde<<"openSp 5."; + logde << "openSp 5."; // 设置 DTR 信号为就绪状态(true 表示低电平) _sp->setDataTerminalReady(true); } diff --git a/src/serialport/serialport.h b/src/serialport/serialport.h index 2797c66..c64d9dd 100644 --- a/src/serialport/serialport.h +++ b/src/serialport/serialport.h @@ -28,8 +28,6 @@ public: bool openSp(); bool isOpen(){return _sp->isOpen();} bool closeSp(); -protected: - void timerEvent(QTimerEvent *event); signals: void sigSendCommonData(const CommonData &); void sigSendCommonDataToRealDataForm(const CommonData &); diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index b5d9afc..fc40796 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -14,17 +14,15 @@ #include "xlsxhandler.h" #include "itemmanager.h" -namespace AnaOpRecorder = AnalysisOperationRecorder; +namespace AnaOpRecorder = AnalysisOperationRecorder; using AnaOpRecorderOperation = AnalysisOperationRecorder::AnalysisOperation; using namespace Global; CentralWidget::CentralWidget(QWidget *parent) - : QWidget(parent) - ,_customPlot(new LocalCustomPlot(this)) - // ,_customPlot(new QCustomPlot(this)) - ,_analysisMode(AnalysisMode::Null) - ,_currentCurve(nullptr) -{ + : QWidget(parent), _customPlot(new LocalCustomPlot(this)) + // ,_customPlot(new QCustomPlot(this)) + , + _analysisMode(AnalysisMode::Null), _currentCurve(nullptr) { setMouseTracking(true); setStyleSheet("background-color: lightgray;"); @@ -60,13 +58,13 @@ CentralWidget::CentralWidget(QWidget *parent) // _customPlot->setInteractions( QCP::iRangeZoom | QCP::iSelectPlottables); // _customPlot->setInteractions(QCP::iSelectPlottables); - connect(_eventHandler,&EventHandler::sigSendLineXCoord, - this,&CentralWidget::sigSendLineXCoord); - connect(_eventHandler,&EventHandler::sigDelCurve, - this,&CentralWidget::slotDelCurve); + connect(_eventHandler, &EventHandler::sigSendLineXCoord, + this, &CentralWidget::sigSendLineXCoord); + connect(_eventHandler, &EventHandler::sigDelCurve, + this, &CentralWidget::slotDelCurve); connect(_customPlot, &QCustomPlot::selectionChangedByUser, - this,&CentralWidget::slotSelectionChangedByUser); + this, &CentralWidget::slotSelectionChangedByUser); setEventHandlerEnable(false); // @@ -93,25 +91,23 @@ CentralWidget::CentralWidget(QWidget *parent) _customPlot->yAxis->setLabel(AxisDSC); // 设置坐标轴范围,以便我们可以看到全部数据 - _customPlot->xAxis->setRange(0,100); - _customPlot->yAxis->setRange(0,20); + _customPlot->xAxis->setRange(0, 100); + _customPlot->yAxis->setRange(0, 20); // startTimer(300); } -CentralWidget::~CentralWidget() -{ +CentralWidget::~CentralWidget() { } -void CentralWidget::switchAxisMode() -{ - if(Global::_mode != Global::Mode::Analysis){ +void CentralWidget::switchAxisMode() { + if (Global::_mode != Global::Mode::Analysis) { return; } - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { _axisMode = AxisMode::DoubleY; - }else{ + } else { _axisMode = AxisMode::SingleY; } @@ -120,8 +116,7 @@ void CentralWidget::switchAxisMode() uiLoadXlsxFileData(); } -bool CentralWidget::isCurrentCurve(QCPCurve *curve) -{ +bool CentralWidget::isCurrentCurve(QCPCurve *curve) { return _currentCurve == curve; } @@ -137,23 +132,21 @@ void CentralWidget::deleteAllExperimentCurve() } #endif -QCPCurve* CentralWidget::addCurveData( - const QVector &dataVtr,const QString objectName) -{ - logde<<"addCurveData..."; - logde<<"data vtr size:"< &dataVtr, const QString objectName) { + logde << "addCurveData..."; + logde << "data vtr size:" << dataVtr.size(); PointCalculate::setAnalysisData(dataVtr); // Load data. - QVector tVtr,xVtr, yVtr; - int index = 0; - for (const Global::ExperimentData &ed : dataVtr) - { + QVector tVtr, xVtr, yVtr; + int index = 0; + for (const Global::ExperimentData &ed : dataVtr) { tVtr.push_back(index++); - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { xVtr.push_back(ed.sampleTemp); - }else{ + } else { xVtr.push_back(ed.runTime); } yVtr.push_back(ed.dsc); @@ -161,30 +154,30 @@ QCPCurve* CentralWidget::addCurveData( _currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis); _currentCurve->setData(tVtr, xVtr, yVtr); - _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 - _currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 + _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 + _currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 _currentCurve->setVisible(true); _currentCurve->setObjectName(objectName); // Set axis range. QPair minMaxXAxisPair; - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { // Axis x is temperature value. minMaxXAxisPair = PointCalculate::getMinAndMaxOfSampleTemp(); - }else{ + } else { // Axis x is time value. minMaxXAxisPair = PointCalculate::getMinAndMaxOfRunTime(); } #if 1 - QPairnewXAxisPair = PointCalculate::getMinAndMaxOfAxis( - minMaxXAxisPair.first,minMaxXAxisPair.second); + QPair newXAxisPair = PointCalculate::getMinAndMaxOfAxis( + minMaxXAxisPair.first, minMaxXAxisPair.second); _customPlot->xAxis->setRange(newXAxisPair.first, newXAxisPair.second); QPair minMaxYAxisPair = PointCalculate::getMinAndMaxOfDSC(); - QPairnewYAxisPair = PointCalculate::getMinAndMaxOfAxis( - minMaxYAxisPair.first,minMaxYAxisPair.second); - _customPlot->yAxis->setRange(newYAxisPair.first , + QPair newYAxisPair = PointCalculate::getMinAndMaxOfAxis( + minMaxYAxisPair.first, minMaxYAxisPair.second); + _customPlot->yAxis->setRange(newYAxisPair.first, newYAxisPair.second); #endif @@ -205,15 +198,14 @@ QCPCurve* CentralWidget::addCurveData( return _currentCurve; } -void CentralWidget::startExperiment() -{ - if(Global::_experimentOITFlag){ +void CentralWidget::startExperiment() { + if (Global::_experimentOITFlag) { setAxisMode(Global::AxisMode::DoubleY); - }else{ + } else { setAxisMode(Global::AxisMode::SingleY); } - if(_yAxis2Curve != nullptr){ + if (_yAxis2Curve != nullptr) { _yAxis2Curve = nullptr; } _customPlot->xAxis->setRange(-5, 60); @@ -223,24 +215,22 @@ void CentralWidget::startExperiment() _customPlot->replot(); } -void CentralWidget::setVerticalLineRange(const double x1, const double x2) -{ - _line1->point1->setCoords(x1,_line1->point1->coords().y()); - _line1->point2->setCoords(x1,_line1->point2->coords().y()); +void CentralWidget::setVerticalLineRange(const double x1, const double x2) { + _line1->point1->setCoords(x1, _line1->point1->coords().y()); + _line1->point2->setCoords(x1, _line1->point2->coords().y()); - _line2->point1->setCoords(x2,_line2->point1->coords().y()); - _line2->point2->setCoords(x2,_line2->point2->coords().y()); + _line2->point1->setCoords(x2, _line2->point1->coords().y()); + _line2->point2->setCoords(x2, _line2->point2->coords().y()); slotAnalysisSettingConfirm(); } -void CentralWidget::setAnalysisMode(const AnalysisMode mode) -{ +void CentralWidget::setAnalysisMode(const AnalysisMode mode) { _analysisMode = mode; - if(mode == AnalysisMode::Null){ + if (mode == AnalysisMode::Null) { _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); - }else{ + } else { _customPlot->setInteractions(QCP::iSelectPlottables); setEventHandlerEnable(true); } @@ -267,10 +257,8 @@ void CentralWidget::setAnalysisMode(const AnalysisMode mode) #endif } -void CentralWidget::slotModeModify(const Global::Mode mode) -{ - if (Global::Mode::Experiment == mode) - { +void CentralWidget::slotModeModify(const Global::Mode mode) { + if (Global::Mode::Experiment == mode) { #if 0 if (_customPlot->graphCount() > 0 && _currentGraph) { @@ -288,28 +276,33 @@ void CentralWidget::slotModeModify(const Global::Mode mode) // 设置坐标轴范围,以便我们可以看到全部数据 _customPlot->xAxis->setRange(0, 400); _customPlot->yAxis->setRange(-20, 20); - } - else if (Global::Mode::Analysis == mode) - { + } else if (Global::Mode::Analysis == mode) { qDebug() << "file close..."; } } -void CentralWidget::slotRecvCommonData(const CommonData &cd) -{ +void CentralWidget::slotRecvCommonData(const CommonData &cd) { + logde << "slotRecvCommonData, cd:" << cd.add_run_time; + // Record data. - if(!Global::_currentCurveExperimentDataPtr){ - loger<<"_currentCurveExperimentDataPtr is nullptr.Soft exit."; + if (!Global::_currentCurveExperimentDataPtr) { + loger << "_currentCurveExperimentDataPtr is nullptr.Soft exit."; exit(0); - }else{ + } else { + // 跳过运行时间为0 的数据 + if (cd.add_run_time == 0) { + return; + } + // Global::ExperimentData ed; - ed.dsc = cd .dsc; + ed.dsc = cd.dsc; ed.sampleTemp = cd.sample_temp; ed.runTime = cd.add_run_time; ed.constantTempTime = cd.add_constan_temp_time; - if(Global::_currentCurveExperimentDataPtr->dataVtr.empty()){ - logde<<"change phase, index:"<phaseIndex; + if (Global::_currentCurveExperimentDataPtr->dataVtr.empty()) { + logde << "change phase, index:" + << Global::_currentCurveExperimentDataPtr->phaseIndex; _currentCurve = nullptr; } @@ -323,8 +316,8 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd) // Update ui. static double index = 0.0; - if(!_currentCurve){ - logde<<"_currentCurve is nullptr"; + if (!_currentCurve) { + logde << "_currentCurve is nullptr"; _currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis); _currentCurve->setObjectName(Global::ObjectNameExperiemnt + Global::Separator @@ -333,42 +326,41 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd) Global::_currentCurveExperimentDataPtr->curve = _currentCurve; } - if(!Global::_experimentOITFlag){ - _currentCurve->addData(index++,cd.sample_temp, cd.dsc); - }else{ - if(_yAxis2Curve == nullptr){ + if (!Global::_experimentOITFlag) { + _currentCurve->addData(index++, cd.sample_temp, cd.dsc); + } else { + if (_yAxis2Curve == nullptr) { _yAxis2Curve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis2); - _yAxis2Curve->setSelectable(QCP::stWhole); // 设置曲线可选 - _yAxis2Curve->setLineStyle(QCPCurve::lsLine); // 线性连接 + _yAxis2Curve->setSelectable(QCP::stWhole); // 设置曲线可选 + _yAxis2Curve->setLineStyle(QCPCurve::lsLine); // 线性连接 _yAxis2Curve->setObjectName(Global::ObjectNameExperiemnt); // 设置曲线颜色 - QPen pen(Qt::red); // 创建一个红色的画笔 - pen.setWidth(1); // 设置画笔宽度 - _yAxis2Curve->setPen(pen); // 将画笔应用到曲线 + QPen pen(Qt::red); // 创建一个红色的画笔 + pen.setWidth(1); // 设置画笔宽度 + _yAxis2Curve->setPen(pen); // 将画笔应用到曲线 } - _yAxis2Curve->addData(index++,cd.add_run_time, cd.sample_temp); + _yAxis2Curve->addData(index++, cd.add_run_time, cd.sample_temp); - _currentCurve->addData(index++,cd.add_run_time, cd.dsc); + _currentCurve->addData(index++, cd.add_run_time, cd.dsc); } // _customPlot->replot(); } -void CentralWidget::slotRecvAnalysisFileName(const QString &filePath) -{ - if(_analysisFilePathVtr.contains(filePath)){ +void CentralWidget::slotRecvAnalysisFileName(const QString &filePath) { + if (_analysisFilePathVtr.contains(filePath)) { return; - }else{ + } else { _analysisFilePathVtr.push_back(filePath); } // Read xlsx file. Global::CurveFileData cfd; - if(XlsxHandler::readFile(filePath,cfd) != 0){ - QMessageBox::warning((QWidget*)this->parent(), "warnning", "File parse error."); + if (XlsxHandler::readFile(filePath, cfd) != 0) { + QMessageBox::warning((QWidget *)this->parent(), "warnning", "File parse error."); return; } // Add data to global parameter. @@ -378,31 +370,30 @@ void CentralWidget::slotRecvAnalysisFileName(const QString &filePath) uiLoadXlsxFileData(); } -void CentralWidget::slotAnalysisSettingApply() -{ - //Set the analysis data corresponding current curve. - if(!_currentCurve){ - logde<<"failed. current curve is nullptr."; +void CentralWidget::slotAnalysisSettingApply() { + // Set the analysis data corresponding current curve. + if (!_currentCurve) { + logde << "failed. current curve is nullptr."; return; } QString selectedCurveObjectName = _currentCurve->objectName(); - logde<<"slotAnalysisSettingApply objectName:"< totalDataVtr; - if(Global::_curveFileDataVtr.empty()){ + if (Global::_curveFileDataVtr.empty()) { // Load experiment data. - logde<<"experiment vtr size:"<point1->coords().x(); double x2 = _line2->point1->coords().x(); - if(_x1Record == x1 && _x2Record == x2){ + if (_x1Record == x1 && _x2Record == x2) { return; - }else{ + } else { _x1Record = x1; _x2Record = x2; } // - calculateAnalysisResult(_analysisMode,x1,x2,_currentCurve->objectName()); + calculateAnalysisResult(_analysisMode, x1, x2, _currentCurve->objectName()); - if(Global::_mode == Global::Mode::Analysis){ + if (Global::_mode == Global::Mode::Analysis) { AnalysisOperation ao; ao.mode = _analysisMode; - ao.x1 = x1; - ao.x2 = x2; + ao.x1 = x1; + ao.x2 = x2; AnaOpRecorder::_analysisOperationVtr.push_back(ao); } } -void CentralWidget::slotAnalysisSettingConfirm() -{ +void CentralWidget::slotAnalysisSettingConfirm() { ItemManager::confirm(); slotAnalysisSettingApply(); @@ -486,16 +476,14 @@ void CentralWidget::slotAnalysisSettingConfirm() emit sigRightDockWidgetHide(); } -void CentralWidget::slotAnalysisSettingUndo() -{ +void CentralWidget::slotAnalysisSettingUndo() { clearData(ClearDataMode::Undo); _x1Record = 0.0; _x2Record = 0.0; } -void CentralWidget::slotAnalysisSettingCancel() -{ +void CentralWidget::slotAnalysisSettingCancel() { clearData(ClearDataMode::Undo); setAnalysisMode(AnalysisMode::Null); @@ -506,17 +494,14 @@ void CentralWidget::slotAnalysisSettingCancel() emit sigRightDockWidgetHide(); } -void CentralWidget::slotAnalysisSettingLineXPoint(const int index, const double) -{ - +void CentralWidget::slotAnalysisSettingLineXPoint(const int index, const double) { } -void CentralWidget::slotDrawCustomText(const QString str) -{ - QCPItemText* customLegendItem = new QCPItemText(_customPlot); +void CentralWidget::slotDrawCustomText(const QString str) { + QCPItemText *customLegendItem = new QCPItemText(_customPlot); customLegendItem->position->setTypeX(QCPItemPosition::ptAbsolute); customLegendItem->position->setTypeY(QCPItemPosition::ptAbsolute); - customLegendItem->position->setCoords(150, 50); // 稍微向下移动 + customLegendItem->position->setCoords(150, 50); // 稍微向下移动 customLegendItem->setText(str); QFont font("Arial", 10); @@ -533,27 +518,25 @@ void CentralWidget::slotDrawCustomText(const QString str) _customPlot->replot(); } -void CentralWidget::slotDelCurve(QCPCurve *curve) -{ - if(!curve){ - logde<<"current curve is nullptr."; +void CentralWidget::slotDelCurve(QCPCurve *curve) { + if (!curve) { + logde << "current curve is nullptr."; return; } - logde<<"deltel curve object name:"<objectName().toStdString(); + logde << "deltel curve object name:" << curve->objectName().toStdString(); deleteCurveByObjectName(curve->objectName()); } -void CentralWidget::slotGetAxisInfo() -{ +void CentralWidget::slotGetAxisInfo() { QVector vtr; - auto func = [&](QCPAxis* axis){ + auto func = [&](QCPAxis *axis) { AxisInfo ai; ai.visiable = axis->visible(); - ai.lower = axis->range().lower; - ai.upper = axis->range().upper; + ai.lower = axis->range().lower; + ai.upper = axis->range().upper; vtr.push_back(ai); }; @@ -565,20 +548,18 @@ void CentralWidget::slotGetAxisInfo() emit sigGetAxisInfoWithData(vtr); } -void CentralWidget::slotSetAxisSettings(const QVectorvtr) -{ - _customPlot->xAxis->setRange(vtr.at(0),vtr.at(1)); - _customPlot->yAxis->setRange(vtr.at(2),vtr.at(3)); +void CentralWidget::slotSetAxisSettings(const QVector vtr) { + _customPlot->xAxis->setRange(vtr.at(0), vtr.at(1)); + _customPlot->yAxis->setRange(vtr.at(2), vtr.at(3)); - if(_customPlot->yAxis2->visible()){ - _customPlot->yAxis2->setRange(vtr.at(4),vtr.at(5)); + if (_customPlot->yAxis2->visible()) { + _customPlot->yAxis2->setRange(vtr.at(4), vtr.at(5)); } _customPlot->replot(); } -void CentralWidget::timerEvent(QTimerEvent *event) -{ +void CentralWidget::timerEvent(QTimerEvent *event) { _customPlot->replot(); #if 0 @@ -607,33 +588,31 @@ void CentralWidget::timerEvent(QTimerEvent *event) #endif } -void CentralWidget::slotSelectionChangedByUser() -{ +void CentralWidget::slotSelectionChangedByUser() { // 获取所有被选中的绘图对象 - QList selectedPlottables = _customPlot->selectedPlottables(); + QList selectedPlottables = _customPlot->selectedPlottables(); // 遍历选中的绘图对象 - for (QCPAbstractPlottable* plottable : selectedPlottables) { + for (QCPAbstractPlottable *plottable : selectedPlottables) { // 检查是否是 QCPCurve - if (QCPCurve* curve = dynamic_cast(plottable)) { + if (QCPCurve *curve = dynamic_cast(plottable)) { logde << "selected Curve:" << curve->objectName().toStdString(); - _currentCurve = curve; // 更新当前选中的曲线 + _currentCurve = curve; // 更新当前选中的曲线 } } } -void CentralWidget::uiLoadXlsxFileData() -{ +void CentralWidget::uiLoadXlsxFileData() { #if 1 // Set axis. _customPlot->yAxis->setVisible(true); _customPlot->yAxis->setLabel(AxisDSC); - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { _customPlot->xAxis->setLabel(AxisTemperature); _customPlot->yAxis2->setVisible(false); - }else{ + } else { _customPlot->xAxis->setLabel(AxisTime); _customPlot->yAxis2->setVisible(true); @@ -644,22 +623,21 @@ void CentralWidget::uiLoadXlsxFileData() #endif #if 1 - if(Global::_curveFileDataVtr.empty()){ + if (Global::_curveFileDataVtr.empty()) { return; } // Load xlsx file data. QVector allDataVtr; - for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ - for(int i = 0;i < cfd.phaseTotalVtr.size();i++){ - Global::PhaseTotalInfo& pti = cfd.phaseTotalVtr[i]; + for (Global::CurveFileData &cfd : Global::_curveFileDataVtr) { + for (int i = 0; i < cfd.phaseTotalVtr.size(); i++) { + Global::PhaseTotalInfo &pti = cfd.phaseTotalVtr[i]; allDataVtr.append(pti.dataVtr); // Load data. - QVector tVtr,tempVtr,timeVtr,dscVtr; - int index = 0; - for (Global::ExperimentData &ed : pti.dataVtr) - { + QVector tVtr, tempVtr, timeVtr, dscVtr; + int index = 0; + for (Global::ExperimentData &ed : pti.dataVtr) { tVtr.push_back(index++); #if 0 if(_axisMode == AxisMode::SingleY){ @@ -675,28 +653,28 @@ void CentralWidget::uiLoadXlsxFileData() } _currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis); - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { _currentCurve->setData(tVtr, tempVtr, dscVtr); - }else{ + } else { _currentCurve->setData(tVtr, timeVtr, dscVtr); } - _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 - _currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 + _currentCurve->setSelectable(QCP::stWhole); // 设置曲线可选 + _currentCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 _currentCurve->setObjectName(cfd.filePath); // add the second axis y curve data. - if(_axisMode == AxisMode::DoubleY){ + if (_axisMode == AxisMode::DoubleY) { QCPCurve *secondCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis2); secondCurve->setData(tVtr, timeVtr, tempVtr); - secondCurve->setSelectable(QCP::stWhole); // 设置曲线可选 - secondCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 + secondCurve->setSelectable(QCP::stWhole); // 设置曲线可选 + secondCurve->setLineStyle(QCPCurve::lsLine); // 线性连接 secondCurve->setObjectName(cfd.filePath); // 设置曲线颜色 - QPen pen(Qt::red); // 创建一个红色的画笔 - pen.setWidth(1); // 设置画笔宽度 - secondCurve->setPen(pen); // 将画笔应用到曲线 + QPen pen(Qt::red); // 创建一个红色的画笔 + pen.setWidth(1); // 设置画笔宽度 + secondCurve->setPen(pen); // 将画笔应用到曲线 } #if 0 // Set axis range. @@ -726,38 +704,37 @@ void CentralWidget::uiLoadXlsxFileData() PointCalculate::setAnalysisData(allDataVtr); // Set axis range. QPair minMaxXAxisPair; - if(_axisMode == AxisMode::SingleY){ + if (_axisMode == AxisMode::SingleY) { // Axis x is temperature value. minMaxXAxisPair = PointCalculate::getMinAndMaxOfSampleTemp(); - }else{ + } else { // Axis x is time value. minMaxXAxisPair = PointCalculate::getMinAndMaxOfRunTime(); // Set yAxis2 range. QPair minAndMaxPair = PointCalculate::getMinAndMaxOfSampleTemp(); - QPairy2AxisPair = PointCalculate::getMinAndMaxOfAxis( - minAndMaxPair.first,minAndMaxPair.second); + QPair y2AxisPair = PointCalculate::getMinAndMaxOfAxis( + minAndMaxPair.first, minAndMaxPair.second); - _customPlot->yAxis2->setRange(y2AxisPair.first,y2AxisPair.second); + _customPlot->yAxis2->setRange(y2AxisPair.first, y2AxisPair.second); } - QPairnewXAxisPair = PointCalculate::getMinAndMaxOfAxis( - minMaxXAxisPair.first,minMaxXAxisPair.second); + QPair newXAxisPair = PointCalculate::getMinAndMaxOfAxis( + minMaxXAxisPair.first, minMaxXAxisPair.second); _customPlot->xAxis->setRange(newXAxisPair.first, newXAxisPair.second); QPair minMaxYAxisPair = PointCalculate::getMinAndMaxOfDSC(); - QPairnewYAxisPair = PointCalculate::getMinAndMaxOfAxis( - minMaxYAxisPair.first,minMaxYAxisPair.second); - _customPlot->yAxis->setRange(newYAxisPair.first , + QPair newYAxisPair = PointCalculate::getMinAndMaxOfAxis( + minMaxYAxisPair.first, minMaxYAxisPair.second); + _customPlot->yAxis->setRange(newYAxisPair.first, newYAxisPair.second); // Add analysis operation data. - logde<<"analysis operation vtr size:" - < tickPositions = _customPlot->xAxis->tickVector(); - double step = tickPositions.at(1) - tickPositions.at(0); - logde<<"glassTransitionHandle step:"< point1Vtr = PointCalculate::getNearbyPointGroupByX(point1.x()); QVector point2Vtr = PointCalculate::getNearbyPointGroupByX(point2.x()); - QVector xVtr,yVtr; - for(QPointF &p:point1Vtr){ + QVector xVtr, yVtr; + for (QPointF &p : point1Vtr) { xVtr.append(p.x()); yVtr.append(p.y()); } - PointCalculate::Line line1 = calculateLinearRegression(xVtr,yVtr); + PointCalculate::Line line1 = calculateLinearRegression(xVtr, yVtr); #if 1 - //line1 + // line1 xVtr.clear(); yVtr.clear(); @@ -807,22 +783,22 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const QCPGraph *lineGraph1 = _customPlot->addGraph(); lineGraph1->setData(xVtr, yVtr); - ItemManager::addTemporaryQCPGraph(lineGraph1,objectName); + ItemManager::addTemporaryQCPGraph(lineGraph1, objectName); QPen pen; pen.setColor(Qt::darkGreen); lineGraph1->setPen(pen); #endif - //line2 + // line2 xVtr.clear(); yVtr.clear(); - for(QPointF &p:point2Vtr){ + for (QPointF &p : point2Vtr) { xVtr.append(p.x()); yVtr.append(p.y()); } - PointCalculate::Line line2 = calculateLinearRegression(xVtr,yVtr); + PointCalculate::Line line2 = calculateLinearRegression(xVtr, yVtr); #if 0 QVector xVtr2,yVtr2; @@ -843,53 +819,52 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const #endif // inflection point. - QVector originalPointVtr = PointCalculate::getPointVtrInXRange(point1.x(),point2.x()); + QVector originalPointVtr = PointCalculate::getPointVtrInXRange(point1.x(), point2.x()); QVector pointVtr = originalPointVtr; xVtr.clear(); yVtr.clear(); - for(QPointF& p:pointVtr){ + for (QPointF &p : pointVtr) { xVtr.append(p.x()); yVtr.append(p.y()); } - QMap tangentLines = - PointCalculate::calculateTangentLine(xVtr,yVtr); + QMap tangentLines = + PointCalculate::calculateTangentLine(xVtr, yVtr); - double targetX = 0.0; + double targetX = 0.0; PointCalculate::Line targetLine; - double maxSlopeAbs = 0.0; // 初始化最大斜率绝对值为0 + double maxSlopeAbs = 0.0; // 初始化最大斜率绝对值为0 // for (auto it = tangentLines.begin(); it != tangentLines.end(); ++it) { if (std::fabs(it.value().slope) > maxSlopeAbs) { - maxSlopeAbs = std::fabs(it.value().slope); // 更新最大斜率绝对值 + maxSlopeAbs = std::fabs(it.value().slope); // 更新最大斜率绝对值 - targetX = it.key(); + targetX = it.key(); targetLine = it.value(); - } } - int index = 0; - QPointF prePoint,currentPoint,lastPoint; - for (int i = 0;i < pointVtr.size();i++) { + int index = 0; + QPointF prePoint, currentPoint, lastPoint; + for (int i = 0; i < pointVtr.size(); i++) { currentPoint = pointVtr[i]; - if(currentPoint.x() == targetX){ + if (currentPoint.x() == targetX) { index = i; break; } } - prePoint = pointVtr[index - 1]; + prePoint = pointVtr[index - 1]; lastPoint = pointVtr[index + 1]; - targetLine.slope = PointCalculate::calculateSlope(lastPoint.x(),lastPoint.y(),prePoint.x(),prePoint.y()); - targetLine.intercept = currentPoint.y() - targetLine.slope * currentPoint.x(); + targetLine.slope = PointCalculate::calculateSlope(lastPoint.x(), lastPoint.y(), prePoint.x(), prePoint.y()); + targetLine.intercept = currentPoint.y() - targetLine.slope * currentPoint.x(); // - QPointF intersection1 = PointCalculate::getIntersection(targetLine,line1); - QPointF intersection2 = PointCalculate::getIntersection(targetLine,line2); + QPointF intersection1 = PointCalculate::getIntersection(targetLine, line1); + QPointF intersection2 = PointCalculate::getIntersection(targetLine, line2); // line 3 xVtr.clear(); @@ -907,12 +882,12 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const lineGraph3->setData(xVtr, yVtr); lineGraph3->setPen(pen); - ItemManager::addTemporaryQCPGraph(lineGraph3,objectName); + ItemManager::addTemporaryQCPGraph(lineGraph3, objectName); _customPlot->replot(); // draw line 2 - QVector xVtr2,yVtr2; + QVector xVtr2, yVtr2; xVtr2.push_back(point2.x()); yVtr2.push_back(point2.y()); @@ -922,13 +897,13 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const yVtr2.push_back(y2); #endif - double minDistance = PointCalculate::calculateDistance(point2,intersection2); + double minDistance = PointCalculate::calculateDistance(point2, intersection2); // 计算延长线另一个端点,使线长度超过minDistance. - double halfOfExtendedLineStep = extendedLineStep /2; - double distance = 0.0; - int power = 0; + double halfOfExtendedLineStep = extendedLineStep / 2; + double distance = 0.0; + int power = 0; QPointF line2Endpoint; - while(distance < minDistance){ + while (distance < minDistance) { power++; line2Endpoint.setX(point2.x() - halfOfExtendedLineStep * power); @@ -936,7 +911,7 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const + line2.intercept); distance = PointCalculate::calculateDistance( - point2,line2Endpoint); + point2, line2Endpoint); } xVtr2.push_back(line2Endpoint.x()); @@ -946,41 +921,41 @@ void CentralWidget::glassTransitionHandle(const double x1,const double x2,const lineGraph2->setData(xVtr2, yVtr2); lineGraph2->setPen(pen); - ItemManager::addTemporaryQCPGraph(lineGraph2,objectName); + ItemManager::addTemporaryQCPGraph(lineGraph2, objectName); _customPlot->replot(); // point value double averageY = (intersection1.y() + intersection2.y()) / 2; - QPointF averagePoint = PointCalculate::getClosestPointByY(point1.x(),point2.x(),averageY); + QPointF averagePoint = PointCalculate::getClosestPointByY(point1.x(), point2.x(), averageY); QString str = PointCalculate::textFormatGlassTranstion(intersection1.x(), averagePoint.x(), intersection2.x()); - if(Global::_axisMode == Global::AxisMode::DoubleY){ + if (Global::_axisMode == Global::AxisMode::DoubleY) { Global::ExperimentData intersection1Ed = - PointCalculate::getClosestDataByTemperature(intersection1.x()); + PointCalculate::getClosestDataByTemperature(intersection1.x()); Global::ExperimentData averageEd = - PointCalculate::getClosestDataByTemperature(averagePoint.x()); + PointCalculate::getClosestDataByTemperature(averagePoint.x()); Global::ExperimentData intersection2Ed = - PointCalculate::getClosestDataByTemperature(intersection2.x()); + PointCalculate::getClosestDataByTemperature(intersection2.x()); - averagePoint = QPointF(averageEd.runTime,averageEd.dsc); + averagePoint = QPointF(averageEd.runTime, averageEd.dsc); str = PointCalculate::textFormatGlassTranstionWithTime( - intersection1Ed.runTime, - averageEd.runTime, - intersection2Ed.runTime); + intersection1Ed.runTime, + averageEd.runTime, + intersection2Ed.runTime); } - drawText(averagePoint,str); + drawText(averagePoint, str); } // 使用最小二乘法计算线性回归 -PointCalculate::Line CentralWidget::calculateLinearRegression(const QVector& x, const QVector& y) { +PointCalculate::Line CentralWidget::calculateLinearRegression(const QVector &x, const QVector &y) { PointCalculate::Line line; - double sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0; - size_t n = x.size(); + double sum_x = 0, sum_y = 0, sum_xy = 0, sum_xx = 0; + size_t n = x.size(); // 计算所需的总和 for (size_t i = 0; i < n; ++i) { @@ -991,47 +966,45 @@ PointCalculate::Line CentralWidget::calculateLinearRegression(const QVector& points, double& a, double& b, double& c) { +void CentralWidget::quadraticFit(const QVector &points, double &a, double &b, double &c) { int n = points.size(); if (n < 3) { throw std::invalid_argument("At least three points are required for quadratic fit."); } double sumX = 0, sumY = 0, sumXX = 0, sumXY = 0, sumX2Y = 0; - for (const QPointF& p : points) { + for (const QPointF &p : points) { sumX += p.x(); sumY += p.y(); sumXX += p.x() * p.x(); @@ -1040,9 +1013,9 @@ void CentralWidget::quadraticFit(const QVector& points, double& a, doub } double det = n * (sumXX * sumY - sumX * sumXY) - sumX * sumX * sumY + sumX * sumX2Y; - a = (sumXX * sumY - sumX * sumXY) / det; - b = (sumX2Y - n * sumXY) / det; - c = (sumY - a * sumX - b * sumX) / n; + a = (sumXX * sumY - sumX * sumXY) / det; + b = (sumX2Y - n * sumXY) / det; + c = (sumY - a * sumX - b * sumX) / n; } // 计算二次多项式拟合曲线的导数(切线斜率) @@ -1051,12 +1024,11 @@ double CentralWidget::derivativeAt(const double a, const double b, const double } -void CentralWidget::setEventHandlerEnable(const bool flag) -{ - logde<<"setEventHandlerEnable..."<setSelected(flag); line->setVisible(flag); }; @@ -1075,88 +1047,85 @@ void CentralWidget::setEventHandlerEnable(const bool flag) // int numTicks = ticks.size(); // logde<<"ticks:"<point1->setCoords(xLeft,_line1->point1->coords().y()); - _line1->point2->setCoords(xLeft,_line1->point2->coords().y()); + _line1->point1->setCoords(xLeft, _line1->point1->coords().y()); + _line1->point2->setCoords(xLeft, _line1->point2->coords().y()); - _line2->point1->setCoords(xRight,_line2->point1->coords().y()); - _line2->point2->setCoords(xRight,_line2->point2->coords().y()); + _line2->point1->setCoords(xRight, _line2->point1->coords().y()); + _line2->point2->setCoords(xRight, _line2->point2->coords().y()); #endif lineVisiableFunc(_line1); - if(AnalysisMode::NumericalLabel != _analysisMode){ + if (AnalysisMode::NumericalLabel != _analysisMode) { lineVisiableFunc(_line2); } // _customPlot->replot(); } -QPointF CentralWidget::getTheCoordinatesOfTheTextBox(const QPointF point) -{ +QPointF CentralWidget::getTheCoordinatesOfTheTextBox(const QPointF point) { double xMax = _customPlot->xAxis->range().upper; double xMin = _customPlot->xAxis->range().lower; - logde<<"xMax:"< ticks = _customPlot->xAxis->tickVector(); - int numTicks = ticks.size(); + QVector ticks = _customPlot->xAxis->tickVector(); + int numTicks = ticks.size(); // logde<<"ticks:"<setPositionAlignment(Qt::AlignCenter); // 对齐方式 - textLabel->position->setType(QCPItemPosition::ptPlotCoords); // 使用数据坐标 - textLabel->position->setCoords(textBoxPoint.x(),textBoxPoint.y()); // 设置文本位置在指定点上方 + textLabel->setPositionAlignment(Qt::AlignCenter); // 对齐方式 + textLabel->position->setType(QCPItemPosition::ptPlotCoords); // 使用数据坐标 + textLabel->position->setCoords(textBoxPoint.x(), textBoxPoint.y()); // 设置文本位置在指定点上方 - textLabel->setText(text); // 设置文本内容 + textLabel->setText(text); // 设置文本内容 QFont font(QFont("Arial", 10)); textLabel->setFont(font); textLabel->setSelectedFont(font); - textLabel->setSelectable(true); // 设置为可选 + textLabel->setSelectable(true); // 设置为可选 // 设置文本项的位置类型为屏幕坐标比例 textLabel->position->setTypeX(QCPItemPosition::ptAxisRectRatio); textLabel->position->setTypeY(QCPItemPosition::ptAxisRectRatio); - ItemManager::addTemporaryQCPItemText(textLabel,objectName); + ItemManager::addTemporaryQCPItemText(textLabel, objectName); // 创建指向点的线段(QCPItemLine) QCPItemLine *arrow = new QCPItemLine(_customPlot); - arrow->start->setParentAnchor(textLabel->left); // 线段起点绑定到标注文字底部 - arrow->end->setCoords(point.x(),point.y()); // 线段终点设置为指定的点 - arrow->setHead(QCPLineEnding::esSpikeArrow); // 添加箭头 + arrow->start->setParentAnchor(textLabel->left); // 线段起点绑定到标注文字底部 + arrow->end->setCoords(point.x(), point.y()); // 线段终点设置为指定的点 + arrow->setHead(QCPLineEnding::esSpikeArrow); // 添加箭头 arrow->setPen(QPen(Qt::red, 1)); - ItemManager::addTemporaryQCPItemLine(arrow,objectName); + ItemManager::addTemporaryQCPItemLine(arrow, objectName); // 重绘图表以显示文本标签和箭头 _customPlot->replot(); } -void CentralWidget::fillGraph(const double x1, const double x2,const QString objectName) -{ +void CentralWidget::fillGraph(const double x1, const double x2, const QString objectName) { Global::ExperimentData x1Ed = PointCalculate::getClosestDataByTemperature(x1); Global::ExperimentData x2Ed = PointCalculate::getClosestDataByTemperature(x2); - QVector xVtr,yVtr; + QVector xVtr, yVtr; xVtr.push_back(x1Ed.sampleTemp); xVtr.push_back(x2Ed.sampleTemp); yVtr.push_back(x1Ed.dsc); yVtr.push_back(x2Ed.dsc); - if(_axisMode == AxisMode::DoubleY){ + if (_axisMode == AxisMode::DoubleY) { x1Ed = PointCalculate::getClosestDataByTime(x1); x2Ed = PointCalculate::getClosestDataByTime(x2); @@ -1176,22 +1145,22 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj // QVector curveDataVtr = - PointCalculate::getDataInXRange(x1,x2); - if(_axisMode == AxisMode::DoubleY){ - curveDataVtr = PointCalculate::getDataInXRangeByTime(x1,x2); + PointCalculate::getDataInXRange(x1, x2); + if (_axisMode == AxisMode::DoubleY) { + curveDataVtr = PointCalculate::getDataInXRangeByTime(x1, x2); } - QCPGraph *fillGraph = _customPlot->addGraph(); + QCPGraph *fillGraph = _customPlot->addGraph(); QVector fillX, fillY; - for(int i = 0;i < curveDataVtr.size();i++){ + for (int i = 0; i < curveDataVtr.size(); i++) { Global::ExperimentData &ed = curveDataVtr[i]; - if(_axisMode == AxisMode::DoubleY){ - fillX<setData(fillX, fillY); @@ -1200,93 +1169,90 @@ void CentralWidget::fillGraph(const double x1, const double x2,const QString obj fillGraph->setChannelFillGraph(mainGraph); // - ItemManager::addTemporaryQCPGraph(mainGraph,objectName); - ItemManager::addTemporaryQCPGraph(fillGraph,objectName); + ItemManager::addTemporaryQCPGraph(mainGraph, objectName); + ItemManager::addTemporaryQCPGraph(fillGraph, objectName); _customPlot->replot(); } -void CentralWidget::clearData(const CentralWidget::ClearDataMode mode) -{ +void CentralWidget::clearData(const CentralWidget::ClearDataMode mode) { switch (mode) { - case ClearDataMode::All: - _analysisFilePathVtr.clear(); - // Clear data. - logde<<"clearExperimentData..."; - Global::clearExperimentData(); + case ClearDataMode::All: + _analysisFilePathVtr.clear(); + // Clear data. + logde << "clearExperimentData..."; + Global::clearExperimentData(); - Global::_curveFileDataVtr.clear(); + Global::_curveFileDataVtr.clear(); - AnalysisOperationRecorder::_analysisOperationVtr.clear(); + AnalysisOperationRecorder::_analysisOperationVtr.clear(); - // Set lines visiable false. - _line1->setVisible(false); - _line2->setVisible(false); + // Set lines visiable false. + _line1->setVisible(false); + _line2->setVisible(false); - _currentCurve = nullptr; + _currentCurve = nullptr; - setAxisMode(Global::AxisMode::SingleY); - case ClearDataMode::JustUi: - //ui - clearAllUiData(); - break; - case ClearDataMode::Undo: - { - // Clear the data of graph. - for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { - QCPAbstractPlottable* plottable = _customPlot->plottable(i); - if (auto curve = dynamic_cast(plottable)) { - logde<<"clear data,curve object Name:"<objectName().toStdString(); - if(curve->objectName().contains( ItemManager::TemporaryStr)){ - _customPlot->removePlottable(curve); + setAxisMode(Global::AxisMode::SingleY); + case ClearDataMode::JustUi: + // ui + clearAllUiData(); + break; + case ClearDataMode::Undo: { + // Clear the data of graph. + for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { + QCPAbstractPlottable *plottable = _customPlot->plottable(i); + if (auto curve = dynamic_cast(plottable)) { + logde << "clear data,curve object Name:" << curve->objectName().toStdString(); + if (curve->objectName().contains(ItemManager::TemporaryStr)) { + _customPlot->removePlottable(curve); - ItemManager::removeItem(curve); + ItemManager::removeItem(curve); + } } } - } - // Clear graph on plot. - for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { - QCPGraph *graph = _customPlot->graph(i); - logde<<"clear data,graph object Name:"<objectName().toStdString(); - if(graph && graph->objectName().contains(ItemManager::TemporaryStr)){ - _customPlot->removeGraph(graph); + // Clear graph on plot. + for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { + QCPGraph *graph = _customPlot->graph(i); + logde << "clear data,graph object Name:" << graph->objectName().toStdString(); + if (graph && graph->objectName().contains(ItemManager::TemporaryStr)) { + _customPlot->removeGraph(graph); - ItemManager::removeItem(graph); + ItemManager::removeItem(graph); + } } - } - // Delete items. - QList itemsToKeep; - itemsToKeep << _line1 << _line2; + // Delete items. + QList itemsToKeep; + itemsToKeep << _line1 << _line2; - for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { - QCPAbstractItem *item = _customPlot->item(i); - logde<<"item data,graph object Name:"<objectName().toStdString(); - if(item && !itemsToKeep.contains(item) - && item->objectName().contains(ItemManager::TemporaryStr)){ - _customPlot->removeItem(item); + for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { + QCPAbstractItem *item = _customPlot->item(i); + logde << "item data,graph object Name:" << item->objectName().toStdString(); + if (item && !itemsToKeep.contains(item) + && item->objectName().contains(ItemManager::TemporaryStr)) { + _customPlot->removeItem(item); - ItemManager::removeItem(item); + ItemManager::removeItem(item); + } } - } - // - AnalysisOperationRecorder::removeTheLastAnalysisOperation(); - } - break; - default:break; + // + AnalysisOperationRecorder::removeTheLastAnalysisOperation(); + } break; + default: + break; } _customPlot->replot(); } -void CentralWidget::clearAllUiData() -{ +void CentralWidget::clearAllUiData() { // Clear the data of graph. for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { - QCPAbstractPlottable* plottable = _customPlot->plottable(i); - if (auto curve = dynamic_cast(plottable)) { + QCPAbstractPlottable *plottable = _customPlot->plottable(i); + if (auto curve = dynamic_cast(plottable)) { _customPlot->removePlottable(curve); ItemManager::removeItem(curve); @@ -1303,7 +1269,7 @@ void CentralWidget::clearAllUiData() // Delete items. QList itemsToKeep; - itemsToKeep << _line1 << _line2; + itemsToKeep << _line1 << _line2; for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { QCPAbstractItem *item = _customPlot->item(i); @@ -1315,11 +1281,10 @@ void CentralWidget::clearAllUiData() } } -void CentralWidget::deleteCurveByObjectName(const QString objectName) -{ +void CentralWidget::deleteCurveByObjectName(const QString objectName) { for (int i = _analysisFilePathVtr.size() - 1; i >= 0; --i) { if (_analysisFilePathVtr[i].startsWith(objectName)) { - _analysisFilePathVtr.removeAt(i); // 从后往前删除避免索引错乱 + _analysisFilePathVtr.removeAt(i); // 从后往前删除避免索引错乱 } } @@ -1329,10 +1294,10 @@ void CentralWidget::deleteCurveByObjectName(const QString objectName) // Clear the data of graph. for (int i = _customPlot->plottableCount() - 1; i >= 0; --i) { - QCPAbstractPlottable* plottable = _customPlot->plottable(i); - if (auto curve = dynamic_cast(plottable)) { - logde<<"clear data,curve object Name:"<objectName().toStdString(); - if(curve->objectName().contains(objectName)){ + QCPAbstractPlottable *plottable = _customPlot->plottable(i); + if (auto curve = dynamic_cast(plottable)) { + logde << "clear data,curve object Name:" << curve->objectName().toStdString(); + if (curve->objectName().contains(objectName)) { _customPlot->removePlottable(curve); ItemManager::removeItem(curve); @@ -1343,8 +1308,8 @@ void CentralWidget::deleteCurveByObjectName(const QString objectName) // Clear graph on plot. for (int i = _customPlot->graphCount() - 1; i >= 0; --i) { QCPGraph *graph = _customPlot->graph(i); - logde<<"clear data,graph object Name:"<objectName().toStdString(); - if(graph && graph->objectName().contains(objectName)){ + logde << "clear data,graph object Name:" << graph->objectName().toStdString(); + if (graph && graph->objectName().contains(objectName)) { _customPlot->removeGraph(graph); ItemManager::removeItem(graph); @@ -1353,13 +1318,13 @@ void CentralWidget::deleteCurveByObjectName(const QString objectName) // Delete items. QList itemsToKeep; - itemsToKeep << _line1 << _line2; + itemsToKeep << _line1 << _line2; for (int i = _customPlot->itemCount() - 1; i >= 0; --i) { QCPAbstractItem *item = _customPlot->item(i); - logde<<"item data,graph object Name:"<objectName().toStdString(); - if(item && !itemsToKeep.contains(item) - && item->objectName().contains(objectName)){ + logde << "item data,graph object Name:" << item->objectName().toStdString(); + if (item && !itemsToKeep.contains(item) + && item->objectName().contains(objectName)) { _customPlot->removeItem(item); ItemManager::removeItem(item); @@ -1370,187 +1335,182 @@ void CentralWidget::deleteCurveByObjectName(const QString objectName) } void CentralWidget::calculateAnalysisResult( - const AnalysisMode mode,const double x1,const double x2,const QString objectName) -{ - logde<<"calculateAnalysisResult..."; - logde<<"x1,x2:"<parent(), "warnning", "曲线选择错误."); - return; + if (Global::isZero(ed.dsc)) { + QMessageBox::warning((QWidget *)this->parent(), "warnning", "曲线选择错误."); + return; + } + + selectPoint = QPointF(ed.sampleTemp, ed.dsc); + str = PointCalculate::textFormatNumbericalLabel(selectPoint); + } else { + Global::ExperimentData ed = PointCalculate::getClosestDataByTime(x1); + + if (Global::isZero(ed.dsc)) { + QMessageBox::warning((QWidget *)this->parent(), "warnning", "曲线选择错误."); + return; + } + selectPoint = QPointF(ed.runTime, ed.dsc); + str = PointCalculate::textFormatNumbericalLabelWithTime(selectPoint); } - selectPoint = QPointF(ed.sampleTemp,ed.dsc); - str = PointCalculate::textFormatNumbericalLabel(selectPoint); - }else{ - Global::ExperimentData ed = PointCalculate::getClosestDataByTime(x1); + drawText(selectPoint, str, objectName); - if(Global::isZero(ed.dsc)){ - QMessageBox::warning((QWidget*)this->parent(), "warnning", "曲线选择错误."); - return; - } - selectPoint = QPointF(ed.runTime,ed.dsc); - str = PointCalculate::textFormatNumbericalLabelWithTime(selectPoint); + break; } + case AnalysisMode::StartPoint: + case AnalysisMode::StopPoint: { + PointCalculate::setRegionPointX(x1, x2); - drawText(selectPoint,str,objectName); + // QPair startEndPointPair = + // PointCalculate::calculateStartAndEndPoint(); - break; - } - case AnalysisMode::StartPoint: - case AnalysisMode::StopPoint:{ - PointCalculate::setRegionPointX(x1,x2); + QPair + startEndDataPair = PointCalculate::calculateStartAndEndData(); - // QPair startEndPointPair = - // PointCalculate::calculateStartAndEndPoint(); + // + QPointF point; + QString str; - QPair - startEndDataPair = PointCalculate::calculateStartAndEndData(); - - // - QPointF point; - QString str; - - if(mode == AnalysisMode::StartPoint){ - if(_axisMode == AxisMode::SingleY){ - point = QPointF(startEndDataPair.first.sampleTemp,startEndDataPair.first.dsc); - str = PointCalculate::textFormatStartPoint(point); - }else{ - point = QPointF(startEndDataPair.first.runTime,startEndDataPair.first.dsc); - str = PointCalculate::textFormatStartPointWithTime(point); - } - }else{ - if(_axisMode == AxisMode::SingleY){ - point = QPointF(startEndDataPair.second.sampleTemp,startEndDataPair.second.dsc); - str = PointCalculate::textFormatEndPoint(point); - }else{ - point = QPointF(startEndDataPair.second.runTime,startEndDataPair.second.dsc); - str = PointCalculate::textFormatEndPointWithTime(point); + if (mode == AnalysisMode::StartPoint) { + if (_axisMode == AxisMode::SingleY) { + point = QPointF(startEndDataPair.first.sampleTemp, startEndDataPair.first.dsc); + str = PointCalculate::textFormatStartPoint(point); + } else { + point = QPointF(startEndDataPair.first.runTime, startEndDataPair.first.dsc); + str = PointCalculate::textFormatStartPointWithTime(point); + } + } else { + if (_axisMode == AxisMode::SingleY) { + point = QPointF(startEndDataPair.second.sampleTemp, startEndDataPair.second.dsc); + str = PointCalculate::textFormatEndPoint(point); + } else { + point = QPointF(startEndDataPair.second.runTime, startEndDataPair.second.dsc); + str = PointCalculate::textFormatEndPointWithTime(point); + } } + + drawText(point, str, objectName); + + // + break; } + case AnalysisMode::PeakSynthesisAnalysis: { + logde << "PeakSynthesisAnalysis..."; - drawText(point,str,objectName); + fillGraph(x1, x2, objectName); - // - break; - } - case AnalysisMode::PeakSynthesisAnalysis: - { - logde<<"PeakSynthesisAnalysis..."; + PointCalculate::setRegionPointX(x1, x2); - fillGraph(x1,x2,objectName); - - PointCalculate::setRegionPointX(x1,x2); - - //enthalpy - double sampleWeight = 1.0f; - if(Global::_curveFileDataVtr.empty()){ - sampleWeight = Global::converStrToDouble(Global::_experimentInfo.sampleWeight); - }else{ - for(Global::CurveFileData& cfd:Global::_curveFileDataVtr){ - for(Global::PhaseTotalInfo& pti:cfd.phaseTotalVtr){ - if(_currentCurve){ - if(_currentCurve == pti.curve){ - sampleWeight = cfd.ei.sampleWeight.toDouble(); + // enthalpy + double sampleWeight = 1.0f; + if (Global::_curveFileDataVtr.empty()) { + sampleWeight = Global::converStrToDouble(Global::_experimentInfo.sampleWeight); + } else { + for (Global::CurveFileData &cfd : Global::_curveFileDataVtr) { + for (Global::PhaseTotalInfo &pti : cfd.phaseTotalVtr) { + if (_currentCurve) { + if (_currentCurve == pti.curve) { + sampleWeight = cfd.ei.sampleWeight.toDouble(); + } } } } } - } - if(sampleWeight <= 0){ - logde<<"sample weight set value 1,"< startEndPointPair = + // start point and end point + QPair startEndPointPair = PointCalculate::calculateStartAndEndPoint(); - logde<<"start,end:"< selectedPointsPair = PointCalculate::getSelectedPoints(); + QString str; + if (_axisMode == AxisMode::DoubleY) { + QPair selectedPointsPair = PointCalculate::getSelectedPoints(); - str = PointCalculate::textFormatPeakPointWithTime( - enthalpyValue, - peakPoint.x(), - selectedPointsPair.first.x(), - selectedPointsPair.second.x()); + str = PointCalculate::textFormatPeakPointWithTime( + enthalpyValue, + peakPoint.x(), + selectedPointsPair.first.x(), + selectedPointsPair.second.x()); - drawText(peakPoint,str,objectName); + drawText(peakPoint, str, objectName); + } else if (Global::_displayTimeValue) { + double peakPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(peakPoint.x()); + double startPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.first.x()); + double endPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.second.x()); + + str = PointCalculate::textFormatPeakPointWithTime( + enthalpyValue, + peakPointTime, + startPointTime, + endPointTime); + + drawText(peakPoint, str, objectName); + + } else { + str = PointCalculate::textFormatPeakPoint( + enthalpyValue, + peakPoint.x(), + startEndPointPair.first.x(), + startEndPointPair.second.x()); + drawText(peakPoint, str, objectName); + } + + // + break; } - else if(Global::_displayTimeValue){ - double peakPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(peakPoint.x()); - double startPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.first.x()); - double endPointTime = PointCalculate::obtainTimeValueBasedOnTemperatureValue(startEndPointPair.second.x()); + case AnalysisMode::GlassTransition: { + glassTransitionHandle(x1, x2, objectName); - str = PointCalculate::textFormatPeakPointWithTime( - enthalpyValue, - peakPointTime, - startPointTime, - endPointTime); - - drawText(peakPoint,str,objectName); - - }else{ - str = PointCalculate::textFormatPeakPoint( - enthalpyValue, - peakPoint.x(), - startEndPointPair.first.x(), - startEndPointPair.second.x()); - drawText(peakPoint,str,objectName); + break; } + case AnalysisMode::OnsetTemperaturePoint: { + QPointF point = onsetTemperaturePointHandle(x1, x2); + logde << "onset point:" << point.x() << "," << point.y(); - // - break; - } - case AnalysisMode::GlassTransition: - { - glassTransitionHandle(x1,x2,objectName); + QString str = QString::number(point.x(), 'f', 3); + drawText(point, str, objectName); - break; - } - case AnalysisMode::OnsetTemperaturePoint:{ - QPointF point = onsetTemperaturePointHandle(x1,x2); - logde<<"onset point:"< tickPositions = _customPlot->yAxis->tickVector(); - double step = tickPositions.at(1) - tickPositions.at(0); + QVector tickPositions = _customPlot->yAxis->tickVector(); + double step = tickPositions.at(1) - tickPositions.at(0); - QPairstartEndPointPair = - PointCalculate::calculateOITStartAndEndDataByTime(x1,x2); + QPair startEndPointPair = + PointCalculate::calculateOITStartAndEndDataByTime(x1, x2); - Global::ExperimentData startData; - startData.runTime = startEndPointPair.first.x(); - startData.dsc = startEndPointPair.first.y(); + Global::ExperimentData startData; + startData.runTime = startEndPointPair.first.x(); + startData.dsc = startEndPointPair.first.y(); - Global::ExperimentData endData; - endData.runTime = startEndPointPair.second.x(); - endData.dsc = startEndPointPair.second.y(); + Global::ExperimentData endData; + endData.runTime = startEndPointPair.second.x(); + endData.dsc = startEndPointPair.second.y(); - logde<<"start runtime:"<(step) / 5 / 2; - double startOffset = localStep ; - double endOffset = localStep * 2; + double startOffset = localStep; + double endOffset = localStep * 2; - logde<<"start/end offset:" - <start->setCoords(startData.runTime,verticalLineStartY); - startLine->end->setCoords(startData.runTime,verticalLineEndY); + startLine->start->setCoords(startData.runTime, verticalLineStartY); + startLine->end->setCoords(startData.runTime, verticalLineEndY); startLine->setPen(QPen(Qt::red, 1)); - ItemManager::addTemporaryQCPItemLine(startLine,objectName); + ItemManager::addTemporaryQCPItemLine(startLine, objectName); // Draw end line. QCPItemLine *endLine = new QCPItemLine(_customPlot); - endLine->start->setCoords(endData.runTime,verticalLineStartY); - endLine->end->setCoords(endData.runTime,verticalLineEndY); + endLine->start->setCoords(endData.runTime, verticalLineStartY); + endLine->end->setCoords(endData.runTime, verticalLineEndY); endLine->setPen(QPen(Qt::red, 1)); - ItemManager::addTemporaryQCPItemLine(endLine,objectName); + ItemManager::addTemporaryQCPItemLine(endLine, objectName); // Draw total line. QCPItemLine *totalLine = new QCPItemLine(_customPlot); - totalLine->start->setCoords(startData.runTime,totalLineDsc); - totalLine->end->setCoords(endData.runTime,totalLineDsc); + totalLine->start->setCoords(startData.runTime, totalLineDsc); + totalLine->end->setCoords(endData.runTime, totalLineDsc); totalLine->setPen(QPen(Qt::red, 1)); - ItemManager::addTemporaryQCPItemLine(totalLine,objectName); + ItemManager::addTemporaryQCPItemLine(totalLine, objectName); // Draw title. double textX = (endData.runTime - startData.runTime) / 3 + startData.runTime; double textY = verticalLineEndY; QCPItemText *textLabel = new QCPItemText(_customPlot); - textLabel->setPositionAlignment(Qt::AlignLeft); // 对齐方式 - textLabel->position->setType(QCPItemPosition::ptPlotCoords); // 使用数据坐标 - textLabel->position->setCoords(textX,textY); // 设置文本位置在指定点上方 + textLabel->setPositionAlignment(Qt::AlignLeft); // 对齐方式 + textLabel->position->setType(QCPItemPosition::ptPlotCoords); // 使用数据坐标 + textLabel->position->setCoords(textX, textY); // 设置文本位置在指定点上方 - double elapseMin = endData.runTime - startData.runTime; + double elapseMin = endData.runTime - startData.runTime; QString elapseMinStr = QString("OIT: ") + Global::converDoubleToStr(elapseMin) - + QString(" min"); - textLabel->setText(elapseMinStr); // 设置文本内容 + + QString(" min"); + textLabel->setText(elapseMinStr); // 设置文本内容 QFont font(QFont("Arial", 10)); textLabel->setFont(font); textLabel->setSelectedFont(font); - textLabel->setSelectable(true); // 设置为可选 - ItemManager::addTemporaryQCPItemText(textLabel,objectName); + textLabel->setSelectable(true); // 设置为可选 + ItemManager::addTemporaryQCPItemText(textLabel, objectName); _customPlot->replot(); } -void CentralWidget::setAxisMode(AxisMode mode) -{ - if(_axisMode != mode){ +void CentralWidget::setAxisMode(AxisMode mode) { + if (_axisMode != mode) { _axisMode = mode; #if 0 @@ -1786,32 +1744,26 @@ void CentralWidget::peakSynthesisSingleAxisY(const double x1, const double x2,co } #endif -void CentralWidget::clearAllData() -{ +void CentralWidget::clearAllData() { _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); Global::_mode = Global::Mode::Analysis; clearData(ClearDataMode::All); } -QPixmap CentralWidget::getPixMap() -{ +QPixmap CentralWidget::getPixMap() { _customPlot->replot(); QApplication::processEvents(); return _customPlot->toPixmap(); } -void CentralWidget::slotAxisModify(const float temp) -{ - logde<<"slotAxisModify..."; +void CentralWidget::slotAxisModify(const float temp) { + logde << "slotAxisModify..."; _customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); float value = temp + 20; - _customPlot->xAxis->setRange(0,value); - _customPlot->yAxis->setRange(-5,5); + _customPlot->xAxis->setRange(0, value); + _customPlot->yAxis->setRange(-5, 5); } - - - diff --git a/src/ui/experimentsettingform.cpp b/src/ui/experimentsettingform.cpp index e040365..024cee1 100644 --- a/src/ui/experimentsettingform.cpp +++ b/src/ui/experimentsettingform.cpp @@ -661,9 +661,9 @@ void ExperimentSettingForm::slotPhaseCheck() { } void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba) { - logde << "----------------------- recv"; + logde << "recv phase info ----------------------- "; -#if 0 +#if 1 QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 qDebug() << "slotRecvPhaseInfo hex:" << hexData; #endif