diff --git a/experiment_data/sample_data/experiment-2-new.xlsx b/experiment_data/sample_data/experiment-2-new.xlsx new file mode 100644 index 0000000..aa09a92 Binary files /dev/null and b/experiment_data/sample_data/experiment-2-new.xlsx differ diff --git a/experiment_data/sample_data/experment-new.xlsx b/experiment_data/sample_data/experment-new.xlsx new file mode 100644 index 0000000..7ec2c00 Binary files /dev/null and b/experiment_data/sample_data/experment-new.xlsx differ diff --git a/experiment_data/sample_data/new.xlsx b/experiment_data/sample_data/new.xlsx index 0c573b0..209350b 100644 Binary files a/experiment_data/sample_data/new.xlsx and b/experiment_data/sample_data/new.xlsx differ diff --git a/src/AnalysisTool.pro b/src/AnalysisTool.pro index 007e5c8..48a86ab 100644 --- a/src/AnalysisTool.pro +++ b/src/AnalysisTool.pro @@ -8,7 +8,7 @@ CONFIG+=precompile_header PRECOMPILED_HEADER=stable.h # -VERSION = 0.9.7.3 +VERSION = 0.9.7.4 # 设置目标文件名,包含版本号 TARGET = AnalysisTool_$${VERSION} @@ -39,6 +39,7 @@ SOURCES += \ ui/enthalpydatacorrectionform.cpp \ ui/itemmanager.cpp \ ui/localcustomplot.cpp \ + ui/printereditform.cpp \ ui/printpreviewform.cpp \ ui/rightwidget.cpp \ thirdparty/easylogging/easylogging++.cc \ @@ -75,6 +76,7 @@ HEADERS += \ ui/enthalpydatacorrectionform.h \ ui/itemmanager.h \ ui/localcustomplot.h \ + ui/printereditform.h \ ui/printpreviewform.h \ ui/rightwidget.h \ thirdparty/easylogging/easylogging++.h \ @@ -107,6 +109,7 @@ FORMS += \ ui/experimentsettingform.ui \ ui/instrumentcoefficientform.ui \ ui/oitautoanalysisparamform.ui \ + ui/printereditform.ui \ ui/printpreviewform.ui \ ui/realtimedataform.ui \ ui/specificheatcomparisonmethodform.ui diff --git a/src/data/xlsxhandler.cpp b/src/data/xlsxhandler.cpp index 5d52585..1bbbec9 100644 --- a/src/data/xlsxhandler.cpp +++ b/src/data/xlsxhandler.cpp @@ -116,6 +116,11 @@ void XlsxHandler::readPhaseData(QXlsx::Worksheet *workSheet, int &startLineIndex void XlsxHandler::writeFile(const QString filePath) { + if(Global::_curveExperimentDataVtr.empty()){ + logde<<"_curveExperimentDataVtr empty..."; + return; + } + Global::ExperimentInfo& ei = Global::_experimentInfo; QXlsx::Document xlsx; @@ -230,6 +235,8 @@ void XlsxHandler::writeFile(const QString filePath) row++; // phase data. + logde<<"Global::_curveExperimentDataVtr size:" + <& edVtr = Global::_curveExperimentDataVtr.at(i).dataVtr; @@ -257,6 +264,9 @@ void XlsxHandler::writeFile(const QString filePath) xlsx.write(phaseSizeRow , 1, ConPhaseSize); xlsx.write(phaseSizeRow , 2, phaseCount); + // Clear data. + Global::clearExperimentData(); + // logde<<"before xlsx save as..."; if (!xlsx.saveAs(filePath)) { @@ -348,31 +358,6 @@ void XlsxHandler::writeAnalysisOperation(const QString filePath) } #endif -#if 0 - if (!xlsx->saveAs(filePath)) { - qDebug() << "Failed to save xlsx file:" << filePath; - // 检查和创建目录 - QDir dir(filePath); - if (!dir.exists()) { - qDebug() << "Directory does not exist. Creating directory..."; - dir.mkpath("."); - } - // 检查权限 - QFile file(filePath); - if (!file.open(QIODevice::WriteOnly)) { - qDebug() << "Permission denied:" << file.errorString(); - } - // 检查磁盘空间 - QStorageInfo storageInfo(QDir::rootPath()); - if (storageInfo.bytesFree() < 1024 * 1024 * 10) { // 假设文件大小至少为10MB - qDebug() << "Disk space is insufficient."; - } - // 尝试重新保存 - if (!xlsx->saveAs(filePath)) { - qDebug() << "Save xlsx failed after retrying."; - } - } -#endif // delete xlsx; logde<<"Save xlsx succ."; diff --git a/src/global.cpp b/src/global.cpp index 914f7b4..7e92d2b 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -123,6 +123,12 @@ double findNegativeStartPoint(double m, double b, double start, double end) { return std::numeric_limits::infinity(); } +void clearExperimentData() +{ + _curveExperimentDataVtr.clear(); + _currentCurveExperimentDataPtr = nullptr; +} + } diff --git a/src/global.h b/src/global.h index e30a9b3..bd33d04 100644 --- a/src/global.h +++ b/src/global.h @@ -121,6 +121,8 @@ extern ExperimentInfo _experimentInfo; extern QVector _curveExperimentDataVtr; extern CurveExperimentData* _currentCurveExperimentDataPtr; +void clearExperimentData(); + // Instrument coefficient. extern bool _enthalpyCoefficientEnableFlag; ///abc diff --git a/src/main.cpp b/src/main.cpp index 0b852a7..9ddeee0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,8 +59,6 @@ int main(int argc, char *argv[]) w.show(); #endif - qDebug() << "Application version:" << qApp->applicationVersion(); - // EnthalpyDataCorrectionForm edf; // edf.show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 179ca0d..38f0f0d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent) ,_coefficientSelectionForm(new CoefficientSelectionForm(this)) ,_printPreviewForm(new PrintPreviewForm(this)) ,_axisSettingForm(new AxisSettingForm(this)) + ,_manuallyStopTheExperimentFlag(false) { ui->setupUi(this); this->setToolTip("....."); @@ -106,7 +107,7 @@ void MainWindow::connections() connect(_expertmentSettingForm, &ExperimentSettingForm::sigDeliverData, SerialPort::instance(), &SerialPort::slotDeliverData); #if 1 - // dynamic data + // SerialPort. connect(SerialPort::instance(), &SerialPort::sigSendCommonData, _centralWidget, &CentralWidget::slotRecvCommonData); connect(SerialPort::instance(), &SerialPort::sigSendCommonData, @@ -124,6 +125,8 @@ void MainWindow::connections() connect(SerialPort::instance(), &SerialPort::sigUpdateStatusbarMsg, this,&MainWindow::slotUpdateStatusbarMsg); + connect(SerialPort::instance(), &SerialPort::sigSaveExperimentalDataMsgBox, + this,&MainWindow::slotSaveExperimentalDataMsgBox); #endif // mode @@ -235,7 +238,7 @@ bool MainWindow::saveAnalysisFile(const QString fileName) return true; } #endif -bool MainWindow::saveFile(const QString fileName) +bool MainWindow::saveFile(const QString fileName,const Global::Mode mode) { QString localFileName = fileName; if(fileName.isEmpty()){ @@ -243,9 +246,9 @@ bool MainWindow::saveFile(const QString fileName) } QString folder; - if(Global::_mode == Global::Mode::Analysis){ + if(mode == Global::Mode::Analysis){ folder = Global::AnalysisStateFolder; - }else if(Global::_mode == Global::Mode::Experiment){ + }else if(mode == Global::Mode::Experiment){ folder = Global::SampleDataFloder; } @@ -259,9 +262,9 @@ bool MainWindow::saveFile(const QString fileName) return false; } - if(Global::_mode == Global::Mode::Analysis){ + if(mode == Global::Mode::Analysis){ XlsxHandler::writeAnalysisOperation(filePath); - }else if(Global::_mode == Global::Mode::Experiment){ + }else if(mode == Global::Mode::Experiment){ XlsxHandler::writeFile(filePath); } @@ -280,13 +283,15 @@ void MainWindow::on_actionStop_triggered() // if(saveExperimentFile(Global::_experimentInfo.sampleName)){ // _leftWidget->reloadFileName(); // } - if(saveFile(Global::_experimentInfo.sampleName)){ + if(saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment)){ _leftWidget->reloadFileName(); } #endif // Set software mode to analysis. Global::_mode = Global::Mode::Analysis; + + _manuallyStopTheExperimentFlag = true; } } @@ -297,6 +302,8 @@ void MainWindow::on_actionNew_triggered() void MainWindow::on_actionStart_triggered() { + on_actionClearAllData_triggered(); + QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start); QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 @@ -307,6 +314,8 @@ void MainWindow::on_actionStart_triggered() Global::_mode = Global::Mode::Experiment; logde<<"start experiment,set soft into experiment mode."; + + _manuallyStopTheExperimentFlag = false; } void MainWindow::on_actionReadOnly_triggered() @@ -320,6 +329,24 @@ void MainWindow::on_actionRealTimeWidget_triggered() _realTimeDataForm->show(); } +void MainWindow::slotSaveExperimentalDataMsgBox() +{ + if(_manuallyStopTheExperimentFlag){ + return; + } + + QMessageBox::StandardButton reply; + reply = QMessageBox::question(this, "数据保存提示", "是否保存实验数据?", + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) { + saveFile(Global::_experimentInfo.sampleName,Global::Mode::Experiment); + } else { + on_actionClearAllData_triggered(); + // Clear data. + Global::clearExperimentData(); + } +} + void MainWindow::on_actionConnectToDev_triggered() { if (SerialPort::instance()->openSp()) @@ -462,5 +489,5 @@ void MainWindow::on_actionAxisSetting_triggered() void MainWindow::on_actionSaveData_triggered() { - saveFile(Global::_experimentInfo.sampleName); + saveFile(Global::_experimentInfo.sampleName,Global::_mode); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 0838e2e..4f55603 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -49,6 +49,8 @@ private slots: void on_actionReadOnly_triggered(); void on_actionRealTimeWidget_triggered(); + void slotSaveExperimentalDataMsgBox(); + //analysis void on_actionNumericalLabel_triggered(); void on_actionStartPoint_triggered(); @@ -101,8 +103,9 @@ private: bool saveAnalysisFile(const QString fileName); #endif - bool saveFile(const QString fileName); + bool saveFile(const QString fileName,const Global::Mode); private: + bool _manuallyStopTheExperimentFlag; Ui::MainWindow *ui; CentralWidget *_centralWidget; EventHandler *_eventHandler; diff --git a/src/serialport/dataparser.cpp b/src/serialport/dataparser.cpp index bc9ddc5..015bca1 100644 --- a/src/serialport/dataparser.cpp +++ b/src/serialport/dataparser.cpp @@ -39,7 +39,7 @@ bool commonDataParser(const QByteArray &ba, CommonData &cd) -QByteArray connectToDevice(const QVector &vtr) +QByteArray setExperimentInfo(const QVector &vtr) { // const int phaseLength = sizeof(Phase); const int phaseLength = PHASE_BYTE_SIZE; @@ -168,9 +168,11 @@ void experimentalStateSwitching(const CommonData &cd) #endif } - // logde<<"phase:"<<(int)cd.current_phase; - // logde<<"run type:"<<(int)cd.run_type; - // logde<<"software mode:"<&); + +QByteArray setExperimentInfo(const QVector&); QByteArray inquirePhaseInfo(); QByteArray setDeviceStartStop(const DeviceStartMode); diff --git a/src/serialport/serialport.cpp b/src/serialport/serialport.cpp index 857ac17..84053cd 100644 --- a/src/serialport/serialport.cpp +++ b/src/serialport/serialport.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include "protocol.h" @@ -98,10 +99,12 @@ void SerialPort::slotReadData() if(ba.size() == 0){ return; } -#if 1 + +#if 0 QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 - qDebug() << "receive info (hex):" << hexData; + logde << "receive info (hex):" << hexData.toStdString(); #endif + SerialPortProtocol *spp = (SerialPortProtocol *)ba.data(); if (FRANE_HEAD != spp->head) { @@ -128,8 +131,7 @@ void SerialPort::slotReadData() else if (READ_CMD == spp->cmd) { DataParser::experimentalStateSwitching(cd); - setAxis(); - updateStatusbarMsg(cd); + updateStatus(cd); if (spp->addr == 0) { @@ -137,19 +139,23 @@ void SerialPort::slotReadData() { emit sigSendCommonData(cd); } - // emit sigSendCommonDataToRealDataForm(cd); + // emit sigSendCommonDataToRealDataForm(cd); } } } -void SerialPort::updateStatusbarMsg(const CommonData &cd) +void SerialPort::updateStatus(const CommonData &cd) { #if 1 - logde<<"phase:"<<(int)cd.current_phase; - logde<<"run type:"<<(int)cd.run_type; +// logde<<"phase:"<<(int)cd.current_phase; +// logde<<"run type:"<<(int)cd.run_type; logde<<"software mode:"<isOpen()) diff --git a/src/serialport/serialport.h b/src/serialport/serialport.h index 972aadc..2749258 100644 --- a/src/serialport/serialport.h +++ b/src/serialport/serialport.h @@ -36,6 +36,7 @@ signals: void sigSendPhaseInfo(const QByteArray &); void sigAxisModify(const float temp); void sigUpdateStatusbarMsg(const QString &); + void sigSaveExperimentalDataMsgBox(); public slots: void slotDeliverData(const QByteArray &); // void slotConnectToDevice(const QByteArray&); @@ -45,11 +46,11 @@ private slots: void slotReadData(); private: - void updateStatusbarMsg(const CommonData &cd); + void updateStatus(const CommonData &cd); + void updateAxis(); void commonDataParser(const int dataLength, const u16 addr, const CommonData &cd); void to_hex(char *in_char, int char_length, char *out_char); void displayPortInfo(); - void setAxis(); private: SerialPort(QObject *parent = nullptr); QSerialPort *_sp; diff --git a/src/ui/centralwidget.cpp b/src/ui/centralwidget.cpp index 03e46e0..cb88328 100644 --- a/src/ui/centralwidget.cpp +++ b/src/ui/centralwidget.cpp @@ -211,8 +211,6 @@ void CentralWidget::slotModeModify(const Global::Mode mode) void CentralWidget::slotRecvCommonData(const CommonData &cd) { - // logde<<"slotRecvCommonData..."; - static double index = 0.0; if(!_currentCurve){ @@ -220,7 +218,7 @@ void CentralWidget::slotRecvCommonData(const CommonData &cd) _currentCurve = new QCPCurve(_customPlot->xAxis, _customPlot->yAxis); } - // logde<<"temp:"<addData(index++,cd.sample_temp, cd.dsc); diff --git a/src/ui/experimentsettingform.cpp b/src/ui/experimentsettingform.cpp index eba777c..066ee08 100644 --- a/src/ui/experimentsettingform.cpp +++ b/src/ui/experimentsettingform.cpp @@ -425,8 +425,10 @@ void ExperimentSettingForm::on_pushButton_deliverData_clicked() ei.initialAtmosPhere = (GasType)(ui->comboBox_phase_1_atmosphere->currentIndex()); #endif + // - QByteArray ba = DataParser::connectToDevice(phaseVtr); + QByteArray ba = DataParser::setExperimentInfo(phaseVtr); + qDebug() << "ba size:" << ba.size(); emit sigDeliverData(ba); hide(); @@ -493,7 +495,7 @@ void ExperimentSettingForm::slotPhaseCheck() void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba) { - logde<<"-----------------------"; + logde<<"----------------------- recv"; QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数 qDebug() << "slotRecvPhaseInfo hex:" << hexData; diff --git a/src/ui/printereditform.cpp b/src/ui/printereditform.cpp new file mode 100644 index 0000000..256bcca --- /dev/null +++ b/src/ui/printereditform.cpp @@ -0,0 +1,14 @@ +#include "printereditform.h" +#include "ui_printereditform.h" + +PrinterEditForm::PrinterEditForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::PrinterEditForm) +{ + ui->setupUi(this); +} + +PrinterEditForm::~PrinterEditForm() +{ + delete ui; +} diff --git a/src/ui/printereditform.h b/src/ui/printereditform.h new file mode 100644 index 0000000..9e0c4da --- /dev/null +++ b/src/ui/printereditform.h @@ -0,0 +1,22 @@ +#ifndef PRINTEREDITFORM_H +#define PRINTEREDITFORM_H + +#include + +namespace Ui { +class PrinterEditForm; +} + +class PrinterEditForm : public QWidget +{ + Q_OBJECT + +public: + explicit PrinterEditForm(QWidget *parent = nullptr); + ~PrinterEditForm(); + +private: + Ui::PrinterEditForm *ui; +}; + +#endif // PRINTEREDITFORM_H diff --git a/src/ui/printereditform.ui b/src/ui/printereditform.ui new file mode 100644 index 0000000..7c8121f --- /dev/null +++ b/src/ui/printereditform.ui @@ -0,0 +1,661 @@ + + + PrinterEditForm + + + + 0 + 0 + 790 + 366 + + + + Form + + + + + 10 + 10 + 281 + 181 + + + + GroupBox + + + + + 20 + 30 + 241 + 121 + + + + + + + 样品名称: + + + + + + + + + + 样品质量: + + + + + + + + + + 实验日期: + + + + + + + + + + 操作员: + + + + + + + + + + + + + 300 + 10 + 481 + 301 + + + + GroupBox + + + + + 5 + 37 + 471 + 251 + + + + + QLayout::SetDefaultConstraint + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 2 + + + + + + + + 0 + 0 + + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 0 + 0 + + + + 4 + + + + + + + 初始气氛: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 100 + 0 + + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + 3 + + + + + + + 截止温度 + + + Qt::AlignCenter + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 0 + 0 + + + + 阶段 + + + Qt::AlignCenter + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + 气氛 + + + Qt::AlignCenter + + + + + + + 非OIT + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 0 + 0 + + + + 5 + + + + + + + OIT + + + + + + + + 0 + 0 + + + + + + + + 测试类型: + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + 1 + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + 100 + 0 + + + + + + + + + 0 + 0 + + + + + + + + + 100 + 0 + + + + + + + + 恒温时间 + + + Qt::AlignCenter + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 0 + 0 + + + + 6 + + + + + + + + 100 + 0 + + + + + + + + 扫描速率 + + + Qt::AlignCenter + + + + + + + + NC + + + + + N2 + + + + + O2 + + + + + + + + + 100 + 0 + + + + + + + + + + + 10 + 190 + 281 + 121 + + + + GroupBox + + + + + 70 + 30 + 141 + 61 + + + + + + + X: + + + + + + + + + + Y: + + + + + + + + + + + + + 380 + 330 + 80 + 20 + + + + 确定 + + + + + + 500 + 330 + 80 + 20 + + + + 取消 + + + + + +