DSCAnalysisTool/src/ui/experimentsettingform.cpp

929 lines
30 KiB
C++
Raw Normal View History

2025-03-10 09:35:07 +00:00
#include <QtDebug>
2025-05-21 08:36:47 +00:00
#include <QDateTime>
2025-03-10 09:35:07 +00:00
#include "experimentsettingform.h"
#include "ui_experimentsettingform.h"
#include "protocol.h"
2025-03-11 09:31:15 +00:00
#include "dataparser.h"
#include "serialport.h"
2025-03-12 09:29:52 +00:00
#include "global.h"
2025-03-17 13:16:16 +00:00
#include "filemanager.h"
2025-04-24 06:35:53 +00:00
#include "logger.h"
2025-03-10 09:35:07 +00:00
2025-03-18 09:28:40 +00:00
QString extractObjectName(const QString& fullObjectName) {
return fullObjectName.mid(4); // 去掉前 4 个字符("ui->"
}
#define SET_OBJECT_NAME(WIDGET) \
WIDGET->setObjectName(extractObjectName(#WIDGET))
2025-03-18 03:43:14 +00:00
ExperimentSettingForm::ExperimentSettingForm(QWidget *parent) : QWidget(parent),
2025-03-18 09:28:40 +00:00
ui(new Ui::ExperimentSettingForm)
2025-03-10 09:35:07 +00:00
{
ui->setupUi(this);
2025-06-20 09:28:45 +00:00
ui->sampleNameLineEdit->setText("new");
ui->sampleWeightLineEdit->setText("0");
ui->userLineEdit->setText("user");
2025-03-10 09:35:07 +00:00
uiReset();
2025-05-21 08:36:47 +00:00
ui->checkBox_phase_1->setTristate(false);
ui->checkBox_phase_2->setTristate(false);
ui->checkBox_phase_3->setTristate(false);
ui->checkBox_phase_4->setTristate(false);
ui->checkBox_phase_5->setTristate(false);
ui->checkBox_phase_6->setTristate(false);
2025-03-18 03:43:14 +00:00
connect(ui->checkBox_phase_2, &QCheckBox::clicked,
this, &ExperimentSettingForm::slotPhase2StateChanged);
connect(ui->checkBox_phase_3, &QCheckBox::clicked,
this, &ExperimentSettingForm::slotPhase3StateChanged);
connect(ui->checkBox_phase_4, &QCheckBox::clicked,
this, &ExperimentSettingForm::slotPhase4StateChanged);
connect(ui->checkBox_phase_5, &QCheckBox::clicked,
this, &ExperimentSettingForm::slotPhase5StateChanged);
connect(ui->checkBox_phase_6, &QCheckBox::clicked,
this, &ExperimentSettingForm::slotPhase6StateChanged);
2025-03-10 09:35:07 +00:00
2025-03-17 13:16:16 +00:00
// connect(ui->pushButton_connect_to_device,&QPushButton::clicked,
// this,&ExperimentSettingForm::slotConnectToDevice);
2025-04-15 08:03:00 +00:00
2025-03-18 03:43:14 +00:00
connect(ui->pushButton_cancel, &QPushButton::clicked,
this, &ExperimentSettingForm::slotCancel);
2025-03-10 09:35:07 +00:00
}
ExperimentSettingForm::~ExperimentSettingForm()
{
delete ui;
}
void ExperimentSettingForm::uiReset()
{
2025-03-18 03:43:14 +00:00
// init data and status.
2025-03-10 09:35:07 +00:00
2025-04-24 06:35:53 +00:00
// default value
2025-03-10 09:35:07 +00:00
ui->phase_1_cutoff_temp->setText("0");
ui->phase_2_cutoff_temp->setText("0");
ui->phase_3_cutoff_temp->setText("0");
ui->phase_4_cutoff_temp->setText("0");
2025-03-18 03:43:14 +00:00
ui->phase_5_cutoff_temp->setText("0");
ui->phase_6_cutoff_temp->setText("0");
2025-03-10 09:35:07 +00:00
ui->phase_1_scan_rate->setText("0");
ui->phase_2_scan_rate->setText("0");
ui->phase_3_scan_rate->setText("0");
ui->phase_4_scan_rate->setText("0");
2025-03-18 03:43:14 +00:00
ui->phase_5_scan_rate->setText("0");
ui->phase_6_scan_rate->setText("0");
2025-03-10 09:35:07 +00:00
ui->phase_1_constant_temp->setText("0");
ui->phase_2_constant_temp->setText("0");
ui->phase_3_constant_temp->setText("0");
ui->phase_4_constant_temp->setText("0");
2025-03-18 03:43:14 +00:00
ui->phase_5_constant_temp->setText("0");
ui->phase_6_constant_temp->setText("0");
2025-04-24 06:35:53 +00:00
ui->comboBox_phase_1_atmosphere->setCurrentIndex(0);
ui->comboBox_phase_2_atmosphere->setCurrentIndex(0);
ui->comboBox_phase_3_atmosphere->setCurrentIndex(0);
ui->comboBox_phase_4_atmosphere->setCurrentIndex(0);
ui->comboBox_phase_5_atmosphere->setCurrentIndex(0);
ui->comboBox_phase_6_atmosphere->setCurrentIndex(0);
// default enable
ui->checkBox_phase_1->setChecked(true);
ui->checkBox_phase_1->setEnabled(false);
2025-03-10 09:35:07 +00:00
ui->phase_2_cutoff_temp->setEnabled(false);
ui->phase_3_cutoff_temp->setEnabled(false);
ui->phase_4_cutoff_temp->setEnabled(false);
2025-03-18 03:43:14 +00:00
ui->phase_5_cutoff_temp->setEnabled(false);
ui->phase_6_cutoff_temp->setEnabled(false);
2025-03-10 09:35:07 +00:00
ui->phase_2_scan_rate->setEnabled(false);
ui->phase_3_scan_rate->setEnabled(false);
ui->phase_4_scan_rate->setEnabled(false);
2025-03-18 03:43:14 +00:00
ui->phase_5_scan_rate->setEnabled(false);
ui->phase_6_scan_rate->setEnabled(false);
2025-03-10 09:35:07 +00:00
ui->phase_2_constant_temp->setEnabled(false);
ui->phase_3_constant_temp->setEnabled(false);
ui->phase_4_constant_temp->setEnabled(false);
2025-03-18 03:43:14 +00:00
ui->phase_5_constant_temp->setEnabled(false);
ui->phase_6_constant_temp->setEnabled(false);
2025-03-10 09:35:07 +00:00
ui->comboBox_phase_2_atmosphere->setEnabled(false);
ui->comboBox_phase_3_atmosphere->setEnabled(false);
ui->comboBox_phase_4_atmosphere->setEnabled(false);
2025-03-18 03:43:14 +00:00
ui->comboBox_phase_5_atmosphere->setEnabled(false);
ui->comboBox_phase_6_atmosphere->setEnabled(false);
2025-03-10 09:35:07 +00:00
ui->radioButton_OIT_not->setChecked(true);
ui->checkBox_phase_2->setTristate(false);
ui->checkBox_phase_3->setTristate(false);
ui->checkBox_phase_4->setTristate(false);
2025-03-18 03:43:14 +00:00
ui->checkBox_phase_5->setTristate(false);
ui->checkBox_phase_6->setTristate(false);
2025-03-18 09:28:40 +00:00
//set objectName
SET_OBJECT_NAME(ui->checkBox_phase_1);
SET_OBJECT_NAME(ui->checkBox_phase_2);
SET_OBJECT_NAME(ui->checkBox_phase_3);
SET_OBJECT_NAME(ui->checkBox_phase_4);
SET_OBJECT_NAME(ui->checkBox_phase_5);
SET_OBJECT_NAME(ui->checkBox_phase_6);
SET_OBJECT_NAME(ui->phase_1_cutoff_temp);
SET_OBJECT_NAME(ui->phase_2_cutoff_temp);
SET_OBJECT_NAME(ui->phase_3_cutoff_temp);
SET_OBJECT_NAME(ui->phase_4_cutoff_temp);
SET_OBJECT_NAME(ui->phase_5_cutoff_temp);
SET_OBJECT_NAME(ui->phase_6_cutoff_temp);
SET_OBJECT_NAME(ui->phase_1_scan_rate);
SET_OBJECT_NAME(ui->phase_2_scan_rate);
SET_OBJECT_NAME(ui->phase_3_scan_rate);
SET_OBJECT_NAME(ui->phase_4_scan_rate);
SET_OBJECT_NAME(ui->phase_5_scan_rate);
SET_OBJECT_NAME(ui->phase_6_scan_rate);
SET_OBJECT_NAME(ui->phase_1_constant_temp);
SET_OBJECT_NAME(ui->phase_2_constant_temp);
SET_OBJECT_NAME(ui->phase_3_constant_temp);
SET_OBJECT_NAME(ui->phase_4_constant_temp);
SET_OBJECT_NAME(ui->phase_5_constant_temp);
SET_OBJECT_NAME(ui->phase_6_constant_temp);
SET_OBJECT_NAME(ui->comboBox_phase_1_atmosphere);
SET_OBJECT_NAME(ui->comboBox_phase_2_atmosphere);
SET_OBJECT_NAME(ui->comboBox_phase_3_atmosphere);
SET_OBJECT_NAME(ui->comboBox_phase_4_atmosphere);
SET_OBJECT_NAME(ui->comboBox_phase_5_atmosphere);
SET_OBJECT_NAME(ui->comboBox_phase_6_atmosphere);
SET_OBJECT_NAME(ui->radioButton_OIT_not);
SET_OBJECT_NAME(ui->comboBox_initial_atmosphere);
2025-03-18 03:43:14 +00:00
}
2025-03-18 09:28:40 +00:00
void ExperimentSettingForm::uiSetPhaseEnable(const int index)
{
switch (index) {
case 1:
ui->checkBox_phase_1->setTristate(true);
ui->phase_1_cutoff_temp->setEnabled(true);
ui->phase_1_scan_rate->setEnabled(true);
ui->phase_1_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
case 2:
ui->checkBox_phase_2->setTristate(true);
ui->phase_2_cutoff_temp->setEnabled(true);
ui->phase_2_scan_rate->setEnabled(true);
ui->phase_3_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
case 3:
ui->checkBox_phase_1->setTristate(true);
ui->phase_1_cutoff_temp->setEnabled(true);
ui->phase_1_scan_rate->setEnabled(true);
ui->phase_1_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
case 4:
ui->checkBox_phase_1->setTristate(true);
ui->phase_1_cutoff_temp->setEnabled(true);
ui->phase_1_scan_rate->setEnabled(true);
ui->phase_1_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
case 5:
ui->checkBox_phase_1->setTristate(true);
ui->phase_1_cutoff_temp->setEnabled(true);
ui->phase_1_scan_rate->setEnabled(true);
ui->phase_1_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
case 6:
ui->checkBox_phase_1->setTristate(true);
ui->phase_1_cutoff_temp->setEnabled(true);
ui->phase_1_scan_rate->setEnabled(true);
ui->phase_1_constant_temp->setEnabled(true);
ui->comboBox_phase_1_atmosphere->setEnabled(true);
break;
default:
break;
2025-03-18 03:43:14 +00:00
}
2025-03-10 09:35:07 +00:00
}
2025-03-18 09:28:40 +00:00
2025-06-18 09:28:38 +00:00
GasType ExperimentSettingForm::conver2GasType(const int index)
{
switch (index) {
case 0: return GasType::NC; break; // 假设 GAS_AIR 是 gas_type 的枚举值
case 1: return GasType::N2; break;
case 2: return GasType::O2; break;
default: return GasType::NC; break; // 处理未知情况
}
return GasType::NC;
}
bool ExperimentSettingForm::phaseCufoffTempAndTempFlowCheck(const int phaseIndex,
const float prePhaseCufoffTemp,
const float currentPhaseCufoffTemp,
const float tempFlow)
{
if(tempFlow < 0){
phaseScanRateErrorMesgBox(phaseIndex);
return false;
}
if(prePhaseCufoffTemp != currentPhaseCufoffTemp
&& tempFlow == 0){
phaseScanRateErrorMesgBox(phaseIndex);
return false;
}
return true;
}
2025-03-10 09:35:07 +00:00
void ExperimentSettingForm::slotPhase2StateChanged(int state)
{
2025-03-18 03:43:14 +00:00
qDebug() << "slotPhase2StateChanged:" << state;
2025-03-10 09:35:07 +00:00
2025-03-18 03:43:14 +00:00
if (state == Qt::PartiallyChecked)
{
2025-03-10 09:35:07 +00:00
ui->phase_2_cutoff_temp->setEnabled(true);
ui->phase_2_scan_rate->setEnabled(true);
ui->phase_2_constant_temp->setEnabled(true);
ui->comboBox_phase_2_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-05-21 08:36:47 +00:00
// unchecked
2025-03-18 03:43:14 +00:00
if (ui->checkBox_phase_3->isChecked())
{
2025-05-21 08:36:47 +00:00
ui->checkBox_phase_2->setChecked(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->phase_2_cutoff_temp->setEnabled(false);
ui->phase_2_scan_rate->setEnabled(false);
ui->phase_2_constant_temp->setEnabled(false);
ui->comboBox_phase_2_atmosphere->setEnabled(false);
}
}
}
void ExperimentSettingForm::slotPhase3StateChanged(int state)
{
2025-03-18 03:43:14 +00:00
if (state == Qt::PartiallyChecked)
{
if (ui->checkBox_phase_2->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->phase_3_cutoff_temp->setEnabled(true);
ui->phase_3_scan_rate->setEnabled(true);
ui->phase_3_constant_temp->setEnabled(true);
ui->comboBox_phase_3_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->checkBox_phase_3->setChecked(false);
}
2025-03-18 03:43:14 +00:00
}
else
{
if (ui->checkBox_phase_4->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->checkBox_phase_3->setChecked(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->phase_3_cutoff_temp->setEnabled(false);
ui->phase_3_scan_rate->setEnabled(false);
ui->phase_3_constant_temp->setEnabled(false);
ui->comboBox_phase_3_atmosphere->setEnabled(false);
}
}
}
void ExperimentSettingForm::slotPhase4StateChanged(int state)
{
2025-03-18 03:43:14 +00:00
if (state == Qt::PartiallyChecked)
{
if (ui->checkBox_phase_3->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->phase_4_cutoff_temp->setEnabled(true);
ui->phase_4_scan_rate->setEnabled(true);
ui->phase_4_constant_temp->setEnabled(true);
ui->comboBox_phase_4_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->checkBox_phase_4->setChecked(false);
}
2025-03-18 03:43:14 +00:00
}
else
{
2025-05-21 08:36:47 +00:00
if (ui->checkBox_phase_5->isChecked())
{
ui->checkBox_phase_4->setChecked(true);
}
else
{
ui->phase_4_cutoff_temp->setEnabled(false);
ui->phase_4_scan_rate->setEnabled(false);
ui->phase_4_constant_temp->setEnabled(false);
ui->comboBox_phase_4_atmosphere->setEnabled(false);
}
2025-03-10 09:35:07 +00:00
}
}
2025-03-18 03:43:14 +00:00
void ExperimentSettingForm::slotPhase5StateChanged(int state)
{
if (state == Qt::PartiallyChecked)
{
if (ui->checkBox_phase_4->isChecked())
{
ui->phase_5_cutoff_temp->setEnabled(true);
ui->phase_5_scan_rate->setEnabled(true);
ui->phase_5_constant_temp->setEnabled(true);
ui->comboBox_phase_5_atmosphere->setEnabled(true);
}
else
{
ui->checkBox_phase_5->setChecked(false);
}
}
else
{
2025-05-21 08:36:47 +00:00
if (ui->checkBox_phase_6->isChecked())
{
ui->checkBox_phase_5->setChecked(true);
}
else
{
ui->phase_5_cutoff_temp->setEnabled(false);
ui->phase_5_scan_rate->setEnabled(false);
ui->phase_5_constant_temp->setEnabled(false);
ui->comboBox_phase_5_atmosphere->setEnabled(false);
}
2025-03-18 03:43:14 +00:00
}
}
void ExperimentSettingForm::slotPhase6StateChanged(int state)
{
2025-05-21 08:36:47 +00:00
qDebug() << "slotPhase2StateChanged:" << state;
2025-03-18 03:43:14 +00:00
if (state == Qt::PartiallyChecked)
{
if (ui->checkBox_phase_5->isChecked())
{
ui->phase_6_cutoff_temp->setEnabled(true);
ui->phase_6_scan_rate->setEnabled(true);
ui->phase_6_constant_temp->setEnabled(true);
ui->comboBox_phase_6_atmosphere->setEnabled(true);
}
else
{
ui->checkBox_phase_6->setChecked(false);
}
}
else
{
ui->phase_6_cutoff_temp->setEnabled(false);
ui->phase_6_scan_rate->setEnabled(false);
ui->phase_6_constant_temp->setEnabled(false);
ui->comboBox_phase_6_atmosphere->setEnabled(false);
}
}
2025-04-15 08:03:00 +00:00
void ExperimentSettingForm::on_pushButton_deliverData_clicked()
2025-03-10 09:35:07 +00:00
{
2025-05-21 08:36:47 +00:00
float phase1CutoffTemp = 0.0;
float phase2CutoffTemp = 0.0;
float phase3CutoffTemp = 0.0;
float phase4CutoffTemp = 0.0;
float phase5CutoffTemp = 0.0;
float phase6CutoffTemp = 0.0;
2025-03-10 09:35:07 +00:00
QVector<Phase> phaseVtr;
2025-03-18 03:43:14 +00:00
{
2025-03-10 09:35:07 +00:00
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_1->checkState()?1:0;
2025-03-10 09:35:07 +00:00
phase.cutoff_temp = ui->phase_1_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_1_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_1_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_1_atmosphere->currentIndex());
2025-03-10 09:35:07 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
phase1CutoffTemp = phase.cutoff_temp;
//
if(phase.temp_flow <= 0){
phaseScanRateErrorMesgBox(1);
return;
}
2025-06-18 09:28:38 +00:00
2025-03-10 09:35:07 +00:00
}
2025-05-29 09:19:11 +00:00
2025-03-18 03:43:14 +00:00
{
2025-03-10 09:35:07 +00:00
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_2->checkState()?1:0;
2025-03-10 09:35:07 +00:00
phase.cutoff_temp = ui->phase_2_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_2_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_2_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_2_atmosphere->currentIndex());
2025-03-10 09:35:07 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
2025-05-29 09:19:11 +00:00
if(phase.onoff){
logde<<"phase 2 enable.";
phase2CutoffTemp = phase.cutoff_temp;
if(phase2CutoffTemp < phase1CutoffTemp){
phaseCufoffTempErrorMesgBox(2);
return;
}
2025-06-18 09:28:38 +00:00
//
#if 0
if(phase.temp_flow < 0){
phaseScanRateErrorMesgBox(2);
return;
}
if(phase2CutoffTemp != phase1CutoffTemp
&& phase.temp_flow == 0){
2025-05-29 09:19:11 +00:00
phaseScanRateErrorMesgBox(2);
return;
}
2025-06-18 09:28:38 +00:00
#endif
if(!phaseCufoffTempAndTempFlowCheck(2,
phase1CutoffTemp,
phase2CutoffTemp,
phase.temp_flow)){
return;
}
2025-05-21 08:36:47 +00:00
}
2025-03-10 09:35:07 +00:00
}
2025-03-19 03:19:52 +00:00
{
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_3->checkState()?1:0;
2025-03-19 03:19:52 +00:00
phase.cutoff_temp = ui->phase_3_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_3_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_3_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_3_atmosphere->currentIndex());
2025-03-19 03:19:52 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
2025-05-29 09:19:11 +00:00
if(phase.onoff){
logde<<"phase 3 enable.";
phase3CutoffTemp = phase.cutoff_temp;
if(phase3CutoffTemp < phase2CutoffTemp){
phaseCufoffTempErrorMesgBox(3);
return;
}
2025-06-18 09:28:38 +00:00
#if 0
2025-05-29 09:19:11 +00:00
if(phase.temp_flow <= 0){
phaseScanRateErrorMesgBox(3);
return;
}
2025-06-18 09:28:38 +00:00
#endif
if(!phaseCufoffTempAndTempFlowCheck(3,
phase2CutoffTemp,
phase3CutoffTemp,
phase.temp_flow)){
return;
}
2025-05-21 08:36:47 +00:00
}
2025-03-19 03:19:52 +00:00
}
2025-04-24 06:35:53 +00:00
2025-03-19 03:19:52 +00:00
{
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_4->checkState()?1:0;
2025-03-19 03:19:52 +00:00
phase.cutoff_temp = ui->phase_4_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_4_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_4_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_4_atmosphere->currentIndex());
2025-03-19 03:19:52 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
2025-05-29 09:19:11 +00:00
if(phase.onoff){
logde<<"phase 4 enable.";
phase4CutoffTemp = phase.cutoff_temp;
if(phase4CutoffTemp < phase3CutoffTemp){
phaseCufoffTempErrorMesgBox(4);
return;
}
2025-06-18 09:28:38 +00:00
#if 0
2025-05-29 09:19:11 +00:00
if(phase.temp_flow <= 0){
phaseScanRateErrorMesgBox(4);
return;
}
2025-06-18 09:28:38 +00:00
#endif
if(!phaseCufoffTempAndTempFlowCheck(4,
phase3CutoffTemp,
phase4CutoffTemp,
phase.temp_flow)){
return;
}
2025-05-21 08:36:47 +00:00
}
2025-03-19 03:19:52 +00:00
}
2025-04-24 06:35:53 +00:00
2025-03-19 03:19:52 +00:00
{
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_5->checkState()?1:0;
2025-03-19 03:19:52 +00:00
phase.cutoff_temp = ui->phase_5_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_5_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_5_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_5_atmosphere->currentIndex());
2025-03-19 03:19:52 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
2025-05-29 09:19:11 +00:00
if(phase.onoff){
logde<<"phase 5 enable.";
phase5CutoffTemp = phase.cutoff_temp;
if(phase5CutoffTemp < phase4CutoffTemp){
phaseCufoffTempErrorMesgBox(5);
return;
}
2025-06-18 09:28:38 +00:00
#if 0
2025-05-29 09:19:11 +00:00
if(phase.temp_flow <= 0){
phaseScanRateErrorMesgBox(5);
return;
}
2025-06-18 09:28:38 +00:00
#endif
if(!phaseCufoffTempAndTempFlowCheck(5,
phase4CutoffTemp,
phase5CutoffTemp,
phase.temp_flow)){
return;
}
2025-05-21 08:36:47 +00:00
}
2025-03-19 03:19:52 +00:00
}
2025-04-24 06:35:53 +00:00
2025-03-19 03:19:52 +00:00
{
Phase phase;
2025-04-24 06:35:53 +00:00
phase.onoff = ui->checkBox_phase_6->checkState()?1:0;
2025-03-19 03:19:52 +00:00
phase.cutoff_temp = ui->phase_6_cutoff_temp->text().toFloat();
phase.temp_flow = ui->phase_6_scan_rate->text().toFloat();
phase.constant_temp_time_min = (uint16_t)ui->phase_6_constant_temp->text().toInt();
2025-06-18 09:28:38 +00:00
phase.gas = conver2GasType(ui->comboBox_phase_6_atmosphere->currentIndex());
2025-03-19 03:19:52 +00:00
phaseVtr.push_back(phase);
2025-05-21 08:36:47 +00:00
//
2025-05-29 09:19:11 +00:00
if(phase.onoff){
logde<<"phase 6 enable.";
phase6CutoffTemp = phase.cutoff_temp;
if(phase6CutoffTemp < phase5CutoffTemp){
phaseCufoffTempErrorMesgBox(6);
return;
}
2025-06-18 09:28:38 +00:00
#if 0
2025-05-29 09:19:11 +00:00
if(phase.temp_flow <= 0){
phaseScanRateErrorMesgBox(6);
return;
}
2025-06-18 09:28:38 +00:00
#endif
if(!phaseCufoffTempAndTempFlowCheck(6,
phase5CutoffTemp,
phase6CutoffTemp,
phase.temp_flow)){
return;
}
2025-05-21 08:36:47 +00:00
}
2025-03-19 03:19:52 +00:00
}
2025-04-14 09:11:01 +00:00
//
Global::ExperimentInfo& ei = Global::_experimentInfo;
ei.sampleName = ui->sampleNameLineEdit->text();
ei.sampleWeight = ui->sampleWeightLineEdit->text();
ei.date = ui->dateTimeLineEdit->text();
ei.experimentor = ui->userLineEdit->text();
2025-05-19 09:29:21 +00:00
2025-04-23 07:33:39 +00:00
#if 0
ei.phaseVtr = phaseVtr;
2025-04-14 09:11:01 +00:00
if(ui->radioButton_OIT->isChecked()){
ei.testType = Global::TestType::OIT;
} else if(ui->radioButton_OIT_not->isChecked()){
ei.testType = Global::TestType::NoneOIT;
}
2025-03-12 09:29:52 +00:00
2025-04-14 09:11:01 +00:00
ei.initialAtmosPhere = (GasType)(ui->comboBox_phase_1_atmosphere->currentIndex());
2025-04-23 07:33:39 +00:00
#endif
2025-05-15 09:31:03 +00:00
2025-05-19 09:29:21 +00:00
// initial data.
QByteArray initialBa;
if(ui->radioButton_OIT->isChecked()){
initialBa.append((char)0);
2025-06-18 09:28:38 +00:00
Global::_experimentOITFlag = true;
logde<<"Global::_experimentOITFlag = true;";
2025-05-19 09:29:21 +00:00
}else{
initialBa.append((char)1);
2025-06-18 09:28:38 +00:00
Global::_experimentOITFlag = false;
logde<<"Global::_experimentOITFlag = false;";
2025-05-19 09:29:21 +00:00
}
char index = ui->comboBox_initial_atmosphere->currentIndex();
initialBa.append(index);
2025-04-15 08:03:00 +00:00
//
2025-05-19 09:29:21 +00:00
QByteArray ba = DataParser::setExperimentInfo(phaseVtr,initialBa);
2025-05-15 09:31:03 +00:00
2025-04-15 08:03:00 +00:00
qDebug() << "ba size:" << ba.size();
2025-05-19 09:29:21 +00:00
2025-04-15 08:03:00 +00:00
emit sigDeliverData(ba);
2025-03-12 09:29:52 +00:00
hide();
2025-03-10 09:35:07 +00:00
}
void ExperimentSettingForm::slotCancel()
{
2025-03-13 09:27:31 +00:00
hide();
2025-03-10 09:35:07 +00:00
}
2025-05-21 08:36:47 +00:00
void ExperimentSettingForm::phaseCufoffTempErrorMesgBox(const int phaseNum)
{
QString title = QString("阶段%1截止温度错误").arg(QString::number(phaseNum));
QString text = QString("阶段%1截止温度不能小于上一阶段截止温度! ").arg(QString::number(phaseNum));
QMessageBox::question(this, title, text,
QMessageBox::Yes);
}
void ExperimentSettingForm::phaseScanRateErrorMesgBox(const int phaseNum)
{
QString title = QString("阶段%1扫描速率错误").arg(QString::number(phaseNum));
QString text = QString("阶段%1扫描速率必须大于0! ").arg(QString::number(phaseNum));
QMessageBox::question(this, title, text,
QMessageBox::Yes);
}
2025-03-10 09:35:07 +00:00
void ExperimentSettingForm::slotPhaseCheck()
{
2025-03-18 03:43:14 +00:00
if (sender() == ui->checkBox_phase_2)
{
if (ui->checkBox_phase_2->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->phase_2_cutoff_temp->setEnabled(true);
ui->phase_2_scan_rate->setEnabled(true);
ui->phase_2_constant_temp->setEnabled(true);
ui->comboBox_phase_2_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->phase_2_cutoff_temp->setEnabled(false);
ui->phase_2_scan_rate->setEnabled(false);
ui->phase_2_constant_temp->setEnabled(false);
ui->comboBox_phase_2_atmosphere->setEnabled(false);
}
2025-03-18 03:43:14 +00:00
}
else if (sender() == ui->checkBox_phase_3)
{
if (ui->checkBox_phase_3->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->phase_3_cutoff_temp->setEnabled(true);
ui->phase_3_scan_rate->setEnabled(true);
ui->phase_3_constant_temp->setEnabled(true);
ui->comboBox_phase_3_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->phase_3_cutoff_temp->setEnabled(false);
ui->phase_3_scan_rate->setEnabled(false);
ui->phase_3_constant_temp->setEnabled(false);
ui->comboBox_phase_3_atmosphere->setEnabled(false);
}
2025-03-18 03:43:14 +00:00
}
else if (sender() == ui->checkBox_phase_4)
{
if (ui->checkBox_phase_4->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->phase_4_cutoff_temp->setEnabled(true);
ui->phase_4_scan_rate->setEnabled(true);
ui->phase_4_constant_temp->setEnabled(true);
ui->comboBox_phase_4_atmosphere->setEnabled(true);
2025-03-18 03:43:14 +00:00
}
else
{
2025-03-10 09:35:07 +00:00
ui->phase_4_cutoff_temp->setEnabled(false);
ui->phase_4_scan_rate->setEnabled(false);
ui->phase_4_constant_temp->setEnabled(false);
ui->comboBox_phase_4_atmosphere->setEnabled(false);
}
}
}
2025-03-18 03:43:14 +00:00
void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba)
{
2025-05-15 09:31:03 +00:00
logde<<"----------------------- recv";
2025-04-24 06:35:53 +00:00
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
qDebug() << "slotRecvPhaseInfo hex:" << hexData;
2025-03-18 03:43:14 +00:00
QByteArray localba = ba;
2025-03-18 09:28:40 +00:00
SerialPortProtocol *spp = (SerialPortProtocol *)localba.data();
2025-03-18 03:43:14 +00:00
u8 *data = spp->data_buf;
2025-04-24 06:35:53 +00:00
int phaseSize = spp->len / PHASE_BYTE_SIZE;
2025-03-18 09:28:40 +00:00
QVector<Phase> phaseVtr;
2025-04-24 06:35:53 +00:00
for (int i = 0; i < phaseSize; i++)
2025-03-18 03:43:14 +00:00
{
2025-04-24 06:35:53 +00:00
#if 0
2025-03-18 09:28:40 +00:00
Phase *phase = (Phase *)(data + i * PHASE_BYTE_SIZE);
2025-03-18 03:43:14 +00:00
phaseVtr.push_back(*phase);
2025-04-24 06:35:53 +00:00
#endif
2025-06-16 09:25:41 +00:00
2025-04-24 06:35:53 +00:00
#if 0
u8* localData = data + i * PHASE_BYTE_SIZE;
int index = 0;
Phase phase;
phase.onoff = *(localData + index);
index += 1;
phase.cutoff_temp = (float)*(localData + index);
index += 4;
phase.temp_flow = (float)*(localData + index);
index += 4;
phase.constant_temp_time_min = (u16)*(localData + index);
index += 2;
// phase.gas = (int)*(localData + index);
int gasType= (u8)*(localData + index);
switch(gasType){
case GasType::NC:
phase.gas = GasType::NC;
break;
case GasType::N2:
phase.gas = GasType::N2;
break;
case GasType::O2:
phase.gas = GasType::O2;
break;
default:
break;
}
phaseVtr.push_back(phase);
#endif
uint8_t* localData = data + i * PHASE_BYTE_SIZE;
int index = 0;
Phase phase;
// 解析 onoff
// phase.onoff = *(localData + index);
memcpy(&phase.onoff, localData + index, sizeof(uint8_t));
index += sizeof(uint8_t);
// 解析 cutoff_temp
memcpy(&phase.cutoff_temp, localData + index, sizeof(float));
index += sizeof(float);
// 解析 temp_flow
memcpy(&phase.temp_flow, localData + index, sizeof(float));
index += sizeof(float);
// 解析 constant_temp_time_min
memcpy(&phase.constant_temp_time_min, localData + index, sizeof(uint16_t));
index += sizeof(uint16_t);
// 解析 gas
uint8_t gasType = *(localData + index);
switch (gasType) {
case NC:
phase.gas = NC;
break;
case N2:
phase.gas = N2;
break;
case O2:
phase.gas = O2;
break;
default:
phase.gas = NC; // 默认值,表示未知类型
break;
}
phaseVtr.push_back(phase);
2025-03-18 03:43:14 +00:00
}
2025-04-24 06:35:53 +00:00
2025-04-23 07:33:39 +00:00
Global::_experimentInfo.phaseVtr = phaseVtr;
2025-03-18 09:28:40 +00:00
//ui update
2025-05-21 08:36:47 +00:00
// logde<<"phaseVtr size:"<<phaseVtr.size();
2025-04-24 06:35:53 +00:00
uiReset();
2025-03-18 09:28:40 +00:00
for(int i = 0; i< phaseVtr.size();){
const Phase &phase = phaseVtr[i];
if(phase.onoff == 0){
break;
}
i++;
2025-05-21 08:36:47 +00:00
// qDebug()<<"index :"<<i;
2025-03-18 09:28:40 +00:00
QString checkBoxName = QString("checkBox_phase_%1").arg(i);
QCheckBox *checkBox_phase = qobject_cast<QCheckBox*>(this->findChild<QObject*>(checkBoxName));
if (checkBox_phase) {
2025-03-19 03:19:52 +00:00
checkBox_phase->setChecked(true);
2025-05-21 08:36:47 +00:00
// qDebug()<<"found...";
2025-03-18 09:28:40 +00:00
}else{
2025-05-21 08:36:47 +00:00
// qDebug()<<"not found...";
2025-03-18 09:28:40 +00:00
}
QString cutOffTempLineEditName = QString("phase_%1_cutoff_temp").arg(i);
QLineEdit *cutOffTempLineEdit = qobject_cast<QLineEdit*>(this->findChild<QObject*>(cutOffTempLineEditName));
if(cutOffTempLineEdit){
cutOffTempLineEdit->setText(QString::number(phase.cutoff_temp,'f',3));
cutOffTempLineEdit->setEnabled(true);
}
QString scanRateLineEditName = QString("phase_%1_scan_rate").arg(i);
QLineEdit *scanRateLineEdit =
qobject_cast<QLineEdit*>(this->findChild<QObject*>(scanRateLineEditName));
if(scanRateLineEdit){
scanRateLineEdit->setText(QString::number(phase.temp_flow,'f',3));
scanRateLineEdit->setEnabled(true);
}
QString constantTempLineEditName = QString("phase_%1_constant_temp").arg(i);
QLineEdit *constantTempLineEdit =
qobject_cast<QLineEdit*>(this->findChild<QObject*>(constantTempLineEditName));
if(constantTempLineEdit){
constantTempLineEdit->setText(QString::number(phase.constant_temp_time_min));
constantTempLineEdit->setEnabled(true);
}
QString atmoshpereComboBoxName = QString("comboBox_phase_%1_atmosphere").arg(i);
QComboBox *atmoshpereComboBox =
qobject_cast<QComboBox*>(this->findChild<QObject*>(atmoshpereComboBoxName));
if(atmoshpereComboBox){
atmoshpereComboBox->setCurrentIndex(phase.gas % 256);
atmoshpereComboBox->setEnabled(true);
}
}
//
// radioButton_OIT_not
// radioButton_OIT
// comboBox_initial_atmosphere
2025-05-19 09:29:21 +00:00
u8 *oitValue = (data + 72);
logde<<"oit value:"<<(int)*oitValue;
2025-03-18 09:28:40 +00:00
if(*oitValue){
2025-05-19 09:29:21 +00:00
ui->radioButton_OIT->setChecked(false);
ui->radioButton_OIT_not->setChecked(true);
#if 0
2025-03-18 09:28:40 +00:00
QString oitRadioButtonName("radioButton_OIT");
QRadioButton *oitRadioButton =
qobject_cast<QRadioButton*>(this->findChild<QObject*>(oitRadioButtonName));
if(oitRadioButton){
oitRadioButton->setChecked(true);
}
2025-05-19 09:29:21 +00:00
#endif
2025-03-18 09:28:40 +00:00
}else{
2025-05-19 09:29:21 +00:00
ui->radioButton_OIT->setChecked(true);
ui->radioButton_OIT_not->setChecked(false);
2025-06-18 09:28:38 +00:00
Global::_experimentOITFlag = true;
logde<<"Global::_experimentOITFlag = true;";
2025-05-19 09:29:21 +00:00
#if 0
2025-03-18 09:28:40 +00:00
QString oitNotRadioButtonName("radioButton_OIT_not");
QRadioButton *oitNotRadioButton =
qobject_cast<QRadioButton*>(this->findChild<QObject*>(oitNotRadioButtonName));
if(oitNotRadioButton){
oitNotRadioButton->setChecked(true);
}
2025-05-19 09:29:21 +00:00
#endif
2025-03-18 09:28:40 +00:00
}
2025-05-19 09:29:21 +00:00
u8 *initAtmosphereValue = (data + 73);
logde<<"initAtmosphereValue:"<< (int)(*initAtmosphereValue);
ui->comboBox_initial_atmosphere->setCurrentIndex((int)*initAtmosphereValue);
#if 0
2025-03-18 09:28:40 +00:00
QString initialAtmosphereComboBoxObjectName("comboBox_initial_atmosphere");
QComboBox *initialAtmosphereComboBox =
qobject_cast<QComboBox*>(this->findChild<QObject*>(initialAtmosphereComboBoxObjectName));
if(initialAtmosphereComboBox){
initialAtmosphereComboBox->setCurrentIndex(*initAtmosphereValue);
}
2025-05-19 09:29:21 +00:00
#endif
2025-03-18 09:28:40 +00:00
2025-03-13 09:27:31 +00:00
}
2025-05-21 08:36:47 +00:00
void ExperimentSettingForm::showEvent(QShowEvent *event)
{
QDateTime currentDateTime = QDateTime::currentDateTime();
QString internationalFormat = currentDateTime.toString("yyyy/MM/dd hh:mm:ss");
ui->dateTimeLineEdit->setText(internationalFormat);
}