2025-03-13 09:27:31 +00:00
|
|
|
#include <qmessagebox.h>
|
|
|
|
|
|
2025-03-05 09:33:46 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
2025-03-12 09:29:52 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "serialport.h"
|
2025-03-13 09:27:31 +00:00
|
|
|
#include "dataparser.h"
|
2025-03-17 13:16:16 +00:00
|
|
|
#include "filemanager.h"
|
2025-03-05 09:33:46 +00:00
|
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
2025-03-18 03:43:14 +00:00
|
|
|
: QMainWindow(parent), ui(new Ui::MainWindow), _centralWidget(new CentralWidget), _leftWidget(new LeftWidget), _expertmentSettingForm(new ExperimentSettingForm), _realTimeDataForm(new RealTimeDataForm)
|
2025-03-05 09:33:46 +00:00
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
setActionEnable(false);
|
|
|
|
|
|
2025-03-05 09:33:46 +00:00
|
|
|
this->setToolTip(".....");
|
|
|
|
|
|
|
|
|
|
setCentralWidget(_centralWidget);
|
2025-03-12 09:29:52 +00:00
|
|
|
addDockWidget(Qt::LeftDockWidgetArea, _leftWidget);
|
2025-03-14 08:58:08 +00:00
|
|
|
//
|
|
|
|
|
ui->statusbar->showMessage("showMessage show temp message!");
|
|
|
|
|
// permenent show
|
|
|
|
|
QLabel *permenentLabel = new QLabel(this);
|
|
|
|
|
permenentLabel->setText("Permanent show!");
|
|
|
|
|
ui->statusbar->addPermanentWidget(permenentLabel);
|
|
|
|
|
//
|
2025-03-12 09:29:52 +00:00
|
|
|
connections();
|
2025-03-14 08:58:08 +00:00
|
|
|
//
|
|
|
|
|
_realTimeDataForm->show();
|
2025-03-05 09:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-12 09:29:52 +00:00
|
|
|
void MainWindow::connections()
|
|
|
|
|
{
|
2025-03-18 03:43:14 +00:00
|
|
|
// ui
|
|
|
|
|
connect(_expertmentSettingForm, &ExperimentSettingForm::sigDeliverData,
|
|
|
|
|
SerialPort::instance(), &SerialPort::slotDeliverData);
|
2025-03-14 08:58:08 +00:00
|
|
|
#if 1
|
2025-03-18 03:43:14 +00:00
|
|
|
// dynamic data
|
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
|
|
|
|
_centralWidget, &CentralWidget::slotRevCommonData);
|
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonData,
|
|
|
|
|
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
|
|
|
|
|
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendCommonDataToRealDataForm,
|
|
|
|
|
_realTimeDataForm, &RealTimeDataForm::slotRevCommonData);
|
|
|
|
|
|
|
|
|
|
connect(SerialPort::instance(), &SerialPort::sigSendPhaseInfo,
|
|
|
|
|
_expertmentSettingForm, &ExperimentSettingForm::slotRecvPhaseInfo);
|
|
|
|
|
|
2025-03-14 08:58:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
2025-03-18 03:43:14 +00:00
|
|
|
// mode
|
|
|
|
|
connect(Global::instance(), &Global::sigModeModify,
|
|
|
|
|
_centralWidget, &CentralWidget::slotModeModify);
|
2025-03-12 09:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
void MainWindow::setActionEnable(const bool flag)
|
|
|
|
|
{
|
2025-03-18 03:43:14 +00:00
|
|
|
if (flag)
|
|
|
|
|
{
|
2025-03-13 09:27:31 +00:00
|
|
|
ui->actionNew->setEnabled(true);
|
|
|
|
|
ui->actionStart->setEnabled(true);
|
|
|
|
|
ui->actionStop->setEnabled(true);
|
|
|
|
|
ui->actionRealTimeWidget->setEnabled(true);
|
2025-03-18 03:43:14 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-03-13 09:27:31 +00:00
|
|
|
ui->actionNew->setEnabled(false);
|
|
|
|
|
ui->actionStart->setEnabled(false);
|
|
|
|
|
ui->actionStop->setEnabled(false);
|
|
|
|
|
ui->actionRealTimeWidget->setEnabled(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionStop_triggered()
|
|
|
|
|
{
|
|
|
|
|
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Stop);
|
|
|
|
|
SerialPort::instance()->slotSendData(ba);
|
2025-03-14 08:58:08 +00:00
|
|
|
// SerialPort::instance()->slotCloseSp();
|
2025-03-18 09:28:40 +00:00
|
|
|
|
|
|
|
|
FileManager::fileClose();
|
2025-03-13 09:27:31 +00:00
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
void MainWindow::on_actionNew_triggered()
|
2025-03-12 09:29:52 +00:00
|
|
|
{
|
2025-03-13 09:27:31 +00:00
|
|
|
_expertmentSettingForm->show();
|
|
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
void MainWindow::on_actionStart_triggered()
|
|
|
|
|
{
|
|
|
|
|
QByteArray ba = DataParser::setDeviceStartStop(DeviceStartMode::Start);
|
2025-03-14 08:58:08 +00:00
|
|
|
|
|
|
|
|
QString hexData = ba.toHex(' '); // ' ' 作为分隔符,可选参数
|
|
|
|
|
qDebug() << "on_actionStart_triggered info (hex):" << hexData;
|
|
|
|
|
|
2025-03-13 09:27:31 +00:00
|
|
|
SerialPort::instance()->slotSendData(ba);
|
2025-03-17 13:16:16 +00:00
|
|
|
//
|
|
|
|
|
FileManager::createExperimentFile();
|
2025-03-13 09:27:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionReadOnly_triggered()
|
|
|
|
|
{
|
|
|
|
|
Global::instance()->setMode(Global::Mode::ExperimentStart);
|
|
|
|
|
SerialPort::instance()->openSp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionRealTimeWidget_triggered()
|
|
|
|
|
{
|
|
|
|
|
_realTimeDataForm->show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_actionConnectToDev_triggered()
|
|
|
|
|
{
|
2025-03-18 03:43:14 +00:00
|
|
|
if (SerialPort::instance()->openSp())
|
|
|
|
|
{
|
2025-03-18 09:28:40 +00:00
|
|
|
setActionEnable(true);
|
2025-03-13 09:27:31 +00:00
|
|
|
Global::instance()->setMode(Global::Mode::ConnectedToDev);
|
2025-03-18 09:28:40 +00:00
|
|
|
QByteArray ba = DataParser::inquirePhaseInfo();
|
|
|
|
|
SerialPort::instance()->sendData(ba);
|
2025-03-18 03:43:14 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-03-13 09:27:31 +00:00
|
|
|
QMessageBox::warning(this, "warnning", "Serial Port open failed.");
|
|
|
|
|
}
|
2025-03-12 09:29:52 +00:00
|
|
|
}
|