371 lines
10 KiB
C++
371 lines
10 KiB
C++
#include <qmessagebox.h>
|
|
|
|
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "global.h"
|
|
#include "serialport.h"
|
|
#include "dataparser.h"
|
|
#include "filemanager.h"
|
|
#include "logger.h"
|
|
#include "xlsxhandler.h"
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
: QMainWindow(parent),
|
|
ui(new Ui::MainWindow),
|
|
_centralWidget(new CentralWidget(this)),
|
|
_leftWidget(new LeftWidget(this)),
|
|
_expertmentSettingForm(new ExperimentSettingForm(this)),
|
|
_realTimeDataForm(new RealTimeDataForm(this)),
|
|
_rightWidget(new QDockWidget(this))
|
|
,_analysisSettingWidget(new AnalysisSettingForm(this))
|
|
,_contextMenu(new QMenu(this))
|
|
,_specificHeatComparisonMethodForm(new SpecificHeatComparisonMethodForm(this))
|
|
,_instrumentCoefficientForm(new InstrumentCoefficientForm(this))
|
|
,_degreeOfCureForm(new DegreeOfCureForm(this))
|
|
,_OITAutoAnalysisParamForm(new OITAutoAnalysisParamForm(this))
|
|
,_degreeOfCrystallinityForm(new DegreeOfCrystallinityForm(this))
|
|
,_aboutForm(new AboutForm(this))
|
|
,_enthalpyDataCorrectionForm(new EnthalpyDataCorrectionForm(this))
|
|
,_coefficientSelectionForm(new CoefficientSelectionForm(this))
|
|
{
|
|
ui->setupUi(this);
|
|
this->setToolTip(".....");
|
|
|
|
setCentralWidget(_centralWidget);
|
|
addDockWidget(Qt::LeftDockWidgetArea, _leftWidget);
|
|
addDockWidget(Qt::RightDockWidgetArea, _rightWidget);
|
|
|
|
_rightWidget->setWidget(_analysisSettingWidget);
|
|
_rightWidget->hide();
|
|
//
|
|
ui->statusbar->showMessage("showMessage show temp message!");
|
|
// permenent show
|
|
QLabel *permenentLabel = new QLabel(this);
|
|
permenentLabel->setText("Software Ver:" + Global::ConSoftVersion);
|
|
ui->statusbar->addPermanentWidget(permenentLabel);
|
|
//
|
|
setSubWidgetAttribute(_expertmentSettingForm);
|
|
setSubWidgetAttribute(_specificHeatComparisonMethodForm);
|
|
setSubWidgetAttribute(_realTimeDataForm);
|
|
setSubWidgetAttribute(_degreeOfCureForm);
|
|
setSubWidgetAttribute(_instrumentCoefficientForm);
|
|
setSubWidgetAttribute(_OITAutoAnalysisParamForm);
|
|
setSubWidgetAttribute(_degreeOfCrystallinityForm);
|
|
setSubWidgetAttribute(_aboutForm);
|
|
setSubWidgetAttribute(_enthalpyDataCorrectionForm);
|
|
setSubWidgetAttribute(_coefficientSelectionForm);
|
|
|
|
//
|
|
setActionEnable(true);
|
|
|
|
_eventHandler = _centralWidget->getEvnetHandler();
|
|
//
|
|
connections();
|
|
//
|
|
// ui->actionStop->setEnabled(false);
|
|
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
// 删除非QObject派生类的对象
|
|
// 假设 Ui::MainWindow 不是 QObject 派生类
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::slotContextMenuShow(const QPoint point)
|
|
{
|
|
_contextMenu->exec(point);
|
|
}
|
|
|
|
void MainWindow::slotStatusbarMesg(const QString)
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event)
|
|
{
|
|
// 弹出确认对话框
|
|
QMessageBox::StandardButton reply;
|
|
reply = QMessageBox::question(this, "确认退出", "你确定要退出吗?",
|
|
QMessageBox::Yes | QMessageBox::No);
|
|
if (reply == QMessageBox::Yes) {
|
|
event->accept(); // 接受关闭事件,关闭窗口
|
|
} else {
|
|
event->ignore(); // 忽略关闭事件,不关闭窗口
|
|
}
|
|
}
|
|
|
|
void MainWindow::connections()
|
|
{
|
|
// ui
|
|
connect(_expertmentSettingForm, &ExperimentSettingForm::sigDeliverData,
|
|
SerialPort::instance(), &SerialPort::slotDeliverData);
|
|
#if 1
|
|
// dynamic data
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
|
_centralWidget, &CentralWidget::slotRecvCommonData);
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
|
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonDataToRealDataForm,
|
|
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendPhaseInfo,
|
|
_expertmentSettingForm, &ExperimentSettingForm::slotRecvPhaseInfo);
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigAxisModify,
|
|
_centralWidget, &CentralWidget::slotAxisModify);
|
|
#endif
|
|
|
|
// mode
|
|
// connect(Global::instance(), &Global::sigModeModify,
|
|
// _centralWidget, &CentralWidget::slotModeModify);
|
|
|
|
//analysis
|
|
connect(_leftWidget,&LeftWidget::sigSendAnalysisFileName,
|
|
_centralWidget,&CentralWidget::slotRecvAnalysisFileName);
|
|
connect(_centralWidget,&CentralWidget::sigSendLineXCoord,
|
|
_analysisSettingWidget,&AnalysisSettingForm::slotRecvLineXCoord);
|
|
|
|
connect(_analysisSettingWidget,&AnalysisSettingForm::sigApply,
|
|
_centralWidget,&CentralWidget::slotAnalysisSettingApply);
|
|
connect(_analysisSettingWidget,&AnalysisSettingForm::sigUndo,
|
|
_centralWidget,&CentralWidget::slotAnalysisSettingUndo);
|
|
connect(_analysisSettingWidget,&AnalysisSettingForm::sigConfirm,
|
|
_centralWidget,&CentralWidget::slotAnalysisSettingConfirm);
|
|
connect(_analysisSettingWidget,&AnalysisSettingForm::sigCancel,
|
|
_centralWidget,&CentralWidget::slotAnalysisSettingCancel);
|
|
|
|
connect(_centralWidget,&CentralWidget::sigRightDockWidgetHide,
|
|
[&](){ _rightWidget->hide(); });
|
|
|
|
//SpecificHeatComparisonMethodForm
|
|
connect(_eventHandler,&EventHandler::sigSetCurve,
|
|
_specificHeatComparisonMethodForm,
|
|
&SpecificHeatComparisonMethodForm::slotSetCurve);
|
|
|
|
}
|
|
|
|
void MainWindow::setActionEnable(const bool flag)
|
|
{
|
|
if (flag)
|
|
{
|
|
ui->actionNew->setEnabled(true);
|
|
ui->actionStart->setEnabled(true);
|
|
ui->actionStop->setEnabled(true);
|
|
ui->actionRealTimeWidget->setEnabled(true);
|
|
}
|
|
else
|
|
{
|
|
ui->actionNew->setEnabled(false);
|
|
ui->actionStart->setEnabled(false);
|
|
ui->actionStop->setEnabled(false);
|
|
ui->actionRealTimeWidget->setEnabled(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::setSubWidgetAttribute(QWidget *widget)
|
|
{
|
|
widget->setWindowModality(Qt::ApplicationModal);
|
|
widget->setWindowFlags(Qt::Dialog);
|
|
|
|
widget->setFixedSize(widget->geometry().width(),widget->geometry().height());
|
|
}
|
|
|
|
bool MainWindow::saveExperimentFile(const QString fileName)
|
|
{
|
|
QString localFileName = fileName;
|
|
if(fileName.isEmpty()){
|
|
localFileName = "new";
|
|
}
|
|
QString xlsxfilePath = Global::SampleDataFloder + "/" + localFileName + ".xlsx";
|
|
QString filePath = QFileDialog::getSaveFileName(nullptr, "Save experiment file",
|
|
xlsxfilePath, "Excel Files (*.xlsx)");
|
|
logde<<"filePath:"<<filePath.toStdString();
|
|
|
|
if (filePath.isEmpty()) {
|
|
qDebug() << "User cancel the operation.";
|
|
return false;
|
|
}
|
|
|
|
XlsxHandler::writeFile(filePath);
|
|
|
|
return true;
|
|
}
|
|
|
|
void MainWindow::on_actionStop_triggered()
|
|
{
|
|
if(Global::_mode == Global::Mode::Experiment)
|
|
{
|
|
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop);
|
|
SerialPort::instance()->slotSendData(ba);
|
|
|
|
#if 1
|
|
// Save data.
|
|
if(saveExperimentFile(Global::_experimentInfo.sampleName)){
|
|
_leftWidget->reloadFileName();
|
|
}
|
|
#endif
|
|
|
|
// Set software mode to analysis.
|
|
Global::_mode = Global::Mode::Analysis;
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionNew_triggered()
|
|
{
|
|
_expertmentSettingForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionStart_triggered()
|
|
{
|
|
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start);
|
|
|
|
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
|
qDebug() << "on_actionStart_triggered info (hex):" << hexData;
|
|
|
|
SerialPort::instance()->slotSendData(ba);
|
|
|
|
Global::_mode = Global::Mode::Experiment;
|
|
|
|
logde<<"start experiment,set soft into experiment mode.";
|
|
}
|
|
|
|
void MainWindow::on_actionReadOnly_triggered()
|
|
{
|
|
Global::_mode = Global::Mode::Experiment;
|
|
SerialPort::instance()->openSp();
|
|
}
|
|
|
|
void MainWindow::on_actionRealTimeWidget_triggered()
|
|
{
|
|
_realTimeDataForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionConnectToDev_triggered()
|
|
{
|
|
if (SerialPort::instance()->openSp())
|
|
{
|
|
setActionEnable(true);
|
|
// Global::instance()->setMode(Global::Mode::ConnectedToDev);
|
|
Global::_mode = Global::Mode::ConnectedToDev;
|
|
|
|
QByteArray ba = DataParser::inquirePhaseInfo();
|
|
SerialPort::instance()->sendData(ba);
|
|
}
|
|
else
|
|
{
|
|
QMessageBox::warning(this, "warnning", "Serial Port open failed.");
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_actionStartPoint_triggered()
|
|
{
|
|
_rightWidget->show();
|
|
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::StartPoint);
|
|
}
|
|
|
|
void MainWindow::on_actionStopPoint_triggered()
|
|
{
|
|
_rightWidget->show();
|
|
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::StopPoint);
|
|
}
|
|
|
|
void MainWindow::on_actionNumericalLabel_triggered()
|
|
{
|
|
_rightWidget->show();
|
|
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::NumericalLabel);
|
|
}
|
|
|
|
void MainWindow::on_actionPeakSynthesisAnalysis_triggered()
|
|
{
|
|
_rightWidget->show();
|
|
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::PeakSynthesisAnalysis);
|
|
}
|
|
|
|
void MainWindow::on_actionClearAllData_triggered()
|
|
{
|
|
_rightWidget->hide();
|
|
_centralWidget->clearAllData();
|
|
}
|
|
|
|
void MainWindow::on_actionGlassTransition_triggered()
|
|
{
|
|
_rightWidget->show();
|
|
_centralWidget->setAnalysisMode(CentralWidget::AnalysisMode::GlassTransition);
|
|
}
|
|
|
|
void MainWindow::on_actionOIT_triggered()
|
|
{
|
|
QMessageBox::warning(this, "warnning", "on_actionOIT_triggered.");
|
|
}
|
|
|
|
void MainWindow::on_actionSpecificHeatCompMethod_triggered()
|
|
{
|
|
_specificHeatComparisonMethodForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionDegreeOfCrystallinity_triggered()
|
|
{
|
|
// QMessageBox::warning(this, "warnning", "结晶度.");
|
|
_degreeOfCrystallinityForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionInstrumentParameter_triggered()
|
|
{
|
|
_instrumentCoefficientForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionInitialMeltingPoint_triggered()
|
|
{
|
|
}
|
|
|
|
void MainWindow::on_actionFinalMeltingPoint_triggered()
|
|
{
|
|
}
|
|
|
|
void MainWindow::on_actionOITAutoAnalysisParam_triggered()
|
|
{
|
|
_OITAutoAnalysisParamForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionOITAutoAnalysisMode_triggered()
|
|
{
|
|
//
|
|
}
|
|
|
|
void MainWindow::on_actionTimeAxisAnalysisPCTMode_triggered()
|
|
{
|
|
|
|
}
|
|
|
|
void MainWindow::on_actionDegreeOfCuring_triggered()
|
|
{
|
|
//
|
|
_degreeOfCureForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionAbout_triggered()
|
|
{
|
|
_aboutForm->show();
|
|
}
|
|
|
|
|
|
void MainWindow::on_actionEnthalpyCorrectionEdit_triggered()
|
|
{
|
|
_enthalpyDataCorrectionForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionEnthalpyCorrectionSelection_triggered()
|
|
{
|
|
_coefficientSelectionForm->show();
|
|
}
|
|
|
|
void MainWindow::on_actionSaveExperimentData_triggered()
|
|
{
|
|
if(saveExperimentFile(Global::_experimentInfo.sampleName)){
|
|
_leftWidget->reloadFileName();
|
|
}
|
|
}
|