DSCAnalysisTool/src/ui/experimentsettingform.cpp

372 lines
12 KiB
C++
Raw Normal View History

2025-03-10 09:35:07 +00:00
#include <QtDebug>
#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-03-10 09:35:07 +00:00
2025-03-18 03:43:14 +00:00
ExperimentSettingForm::ExperimentSettingForm(QWidget *parent) : QWidget(parent),
ui(new Ui::ExperimentSettingForm)
2025-03-10 09:35:07 +00:00
{
ui->setupUi(this);
uiReset();
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-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
ui->checkBox_phase_1->setChecked(true);
ui->checkBox_phase_1->setEnabled(false);
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-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);
}
void ExperimentSettingForm::uiUpdatePhase(QVector<Phase> &vtr)
{
for(int i = 0; i< vtr.size(); i++){
const Phase &phase = vtr[i];
if(phase.onoff == 0){
return;
}
QString checkBoxName = QString("checkBox_phase_%1").arg(i);
QCheckBox *checkBox = ui->findChild<QCheckBox*>(checkBoxName);
if (checkBox) {
checkBox->setTristate(false);
}
}
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
{
if (ui->checkBox_phase_3->isChecked())
{
2025-03-10 09:35:07 +00:00
ui->checkBox_phase_2->setCheckState(Qt::Checked);
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-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::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
{
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);
}
}
void ExperimentSettingForm::slotPhase6StateChanged(int state)
{
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-03-10 09:35:07 +00:00
void ExperimentSettingForm::slotConnectToDevice()
{
QVector<Phase> phaseVtr;
2025-03-18 03:43:14 +00:00
if (ui->checkBox_phase_1->checkState())
{
2025-03-10 09:35:07 +00:00
Phase phase;
phase.onoff = 1;
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();
// phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex();
phase.gas = GasType::N2;
phaseVtr.push_back(phase);
}
2025-03-18 03:43:14 +00:00
if (ui->checkBox_phase_2->checkState())
{
2025-03-10 09:35:07 +00:00
Phase phase;
phase.onoff = 1;
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();
// phase.gas = ui->comboBox_phase_1_atmosphere->currentIndex();
phase.gas = GasType::N2;
phaseVtr.push_back(phase);
}
2025-03-11 09:31:15 +00:00
QByteArray ba = DataParser::connectToDevice(phaseVtr);
2025-03-18 03:43:14 +00:00
qDebug() << "ba size:" << ba.size();
2025-03-17 09:30:54 +00:00
emit sigDeliverData(ba);
2025-03-12 09:29:52 +00:00
2025-03-17 13:16:16 +00:00
// Global::instance()->setMode(Global::Mode::ConnectedToDev);
2025-03-12 09:29:52 +00:00
#if 0
QByteArray startBa = DataParser::setDeviceStartStop(DeviceStartMode::Start);
emit sigConnectToDevice(startBa);
#endif
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
}
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-17 09:30:54 +00:00
void ExperimentSettingForm::on_pushButton_deliverData_clicked()
2025-03-13 09:27:31 +00:00
{
slotConnectToDevice();
2025-03-17 13:16:16 +00:00
2025-03-18 03:43:14 +00:00
FileManager::_expeInfo.sampleName = ui->sampleNameLineEdit->text();
FileManager::_expeInfo.sampleWeight = ui->sampleWeightLineEdit->text().toInt(nullptr, 16);
2025-03-17 13:16:16 +00:00
FileManager::_expeInfo.date = ui->dateTimeLineEdit->text();
2025-03-18 03:43:14 +00:00
FileManager::_expeInfo.userName = ui->userLineEdit->text();
}
void ExperimentSettingForm::slotRecvPhaseInfo(const QByteArray &ba)
{
QByteArray localba = ba;
SerialPortProtocol *spp = localba.data();
u8 *data = spp->data_buf;
vector<Phase> phaseVtr;
for (int i = 0; i < 6; i++)
{
Phase *phase = (Phase *)(data + i * sizeof(Phase));
phaseVtr.push_back(*phase);
}
2025-03-13 09:27:31 +00:00
}