871 lines
37 KiB
C++
871 lines
37 KiB
C++
#include "MainWindow.h"
|
|
#include "ui_MainWindow.h"
|
|
|
|
#include <QAction>
|
|
#include <QDateTime>
|
|
#include <QDir>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QMenu>
|
|
#include <QPlainTextEdit>
|
|
#include <QScrollBar>
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
#include "DockAreaWidget.h"
|
|
#include "DockComponentsFactory.h"
|
|
#include "DockManager.h"
|
|
#include "DockWidget.h"
|
|
#include "FloatingDockContainer.h"
|
|
#include "AboutDlg.h"
|
|
#include "DataProcessWorkPool.h"
|
|
#include "EnergyScaleForm.h"
|
|
#include "MeasureAnalysisHistoryForm.h"
|
|
#include "NewMeasureAnalysisDlg.h"
|
|
#include "MeasureAnalysisView.h"
|
|
#include "MeasureAnalysisTreeView.h"
|
|
#include "GlobalDefine.h"
|
|
#include "DeviceParamsManagerDlg.h"
|
|
#include "NuclideLib.h"
|
|
#include "BackgroundTaskListView.h"
|
|
#include <QDesktopWidget>
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include "MeasureClient.h"
|
|
#include "MeasureAnalysisDataTableView.h"
|
|
#include "DataCalcProcess/GaussPolyCoe.h"
|
|
#include "EnergyScaleDataModel.h"
|
|
#include "EnergyCountPlotView.h"
|
|
#include "ParticleCountPlotView.h"
|
|
#include <array>
|
|
#include "csv.h"
|
|
#include <fstream>
|
|
|
|
using namespace io;
|
|
using namespace ads;
|
|
|
|
MainWindow* MainWindow::_s_main_win = nullptr;
|
|
|
|
void MainWindow::OutputInfo(OutputInfoType out_type, const QString& ouput_info)
|
|
{
|
|
QMetaObject::invokeMethod(_s_main_win, "onOutputInfo", Qt::QueuedConnection, Q_ARG(int, int(out_type)), Q_ARG(QString, ouput_info));
|
|
}
|
|
|
|
void MainWindow::ShowStatusBarMsg(const QString& msg)
|
|
{
|
|
QMetaObject::invokeMethod(_s_main_win, "onShowStatusBarMsg", Qt::QueuedConnection, Q_ARG(QString, msg));
|
|
}
|
|
|
|
void MainWindow::onOutputInfo(int out_type, const QString &ouput_info)
|
|
{
|
|
if (!ouput_info.isEmpty()) {
|
|
QStringList list_str_out_type = {
|
|
QStringLiteral(u"信息"),
|
|
QStringLiteral(u"警告"),
|
|
QStringLiteral(u"错误"),
|
|
QStringLiteral(u"调试")
|
|
};
|
|
QList<QColor> list_color_out_type = {
|
|
Qt::black,
|
|
Qt::darkYellow,
|
|
Qt::red,
|
|
Qt::darkBlue
|
|
};
|
|
const QString& ouput_text = QString("%1 [%2] : %3")
|
|
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"))
|
|
.arg(list_str_out_type.at(int(out_type)))
|
|
.arg(ouput_info);
|
|
QTextCharFormat cur_fmt, fmt;
|
|
fmt.setForeground(QBrush(list_color_out_type.at(out_type)));
|
|
_mutex_info_output.lock();
|
|
cur_fmt = _plain_edit_info_output->currentCharFormat();
|
|
_plain_edit_info_output->mergeCurrentCharFormat(fmt);
|
|
_plain_edit_info_output->appendPlainText(ouput_text);
|
|
_plain_edit_info_output->setCurrentCharFormat(cur_fmt);
|
|
QScrollBar* scrollbar = _plain_edit_info_output->verticalScrollBar();
|
|
if (scrollbar) {
|
|
scrollbar->setSliderPosition(scrollbar->maximum());
|
|
}
|
|
_plain_edit_info_output->update();
|
|
_mutex_info_output.unlock();
|
|
}
|
|
}
|
|
|
|
void MainWindow::onShowStatusBarMsg(const QString &msg)
|
|
{
|
|
_status_bar->showMessage(msg);
|
|
}
|
|
|
|
MainWindow::MainWindow(QWidget* parent)
|
|
: QMainWindow(parent)
|
|
, ui(new Ui::MainWindow)
|
|
{
|
|
ui->setupUi(this);
|
|
_status_bar = ui->statusbar;
|
|
_gvfToCsv = new GvfToCsv;
|
|
_measure_client = new MeasureClient;
|
|
m_deviceMgr = new DeviceConnectManagement(_measure_client, this);
|
|
|
|
m_AddressCountTimer = new QTimer(this);
|
|
m_AddressCountTimer->setInterval(10000);//10秒刷新一次
|
|
m_EnergyCountTimer = new QTimer(this);
|
|
m_EnergyCountTimer->setInterval(10000);//10秒刷新一次
|
|
connect(m_AddressCountTimer, &QTimer::timeout, this, &MainWindow::on_AddressCountTimer);
|
|
connect(m_EnergyCountTimer, &QTimer::timeout, this, &MainWindow::on_EnergyCountTimer);
|
|
connect(_measure_client, &MeasureClient::gvfData, this, &MainWindow::onGvfData);
|
|
|
|
//接受设备管理传过来的信号
|
|
connect(m_deviceMgr,&DeviceConnectManagement::emitStartMeasure,this,&MainWindow::onUpdateParticleDataTreeStatus);
|
|
connect(m_deviceMgr, &DeviceConnectManagement::measureStarted, this, &MainWindow::onMeasureStarted);
|
|
connect(m_deviceMgr, &DeviceConnectManagement::measureStopped, this, &MainWindow::onMeasureStopped);
|
|
connect(m_deviceMgr, &DeviceConnectManagement::statusMessage, this, &MainWindow::onDeviceStatusMessage);
|
|
initMainWindow();
|
|
initAction();
|
|
initStatusBar();
|
|
|
|
// 初始化实时GVF数据处理线程
|
|
_gvfProcessThread = new QThread(this);
|
|
_gvfWorker = new DataProcessWorkPool::RealtimeGvfDataWorker;
|
|
_gvfWorker->setGvfParser(_gvfToCsv);
|
|
_gvfWorker->moveToThread(_gvfProcessThread);
|
|
|
|
|
|
// 连接UI更新信号
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::particleDataWritten,
|
|
this, &MainWindow::onParticleDatarefresh);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::addressCountViewNeedRefresh,
|
|
this, &MainWindow::onAddressCountViewNeedRefresh);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::energyCountViewNeedRefresh,
|
|
this, &MainWindow::onEnergyCountViewNeedRefresh);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::newAddressCountChannelFile,
|
|
this, &MainWindow::onNewAddressCountChannelFile);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::newEnergyCountChannelFile,
|
|
this, &MainWindow::onNewEnergyCountChannelFile);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::allChannelEnergyCountFileUpdated,
|
|
this, &MainWindow::onAllChannelEnergyCountFileUpdated);
|
|
connect(_gvfWorker, &DataProcessWorkPool::RealtimeGvfDataWorker::particleEnergyDataUpdated,
|
|
this, &MainWindow::onParticleEnergyDataUpdated);
|
|
_gvfProcessThread->start();
|
|
|
|
this->applyStyleSheet();
|
|
_s_main_win = this;
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::onMeasureStarted(bool success, const QString& message)
|
|
{
|
|
// Q_UNUSED(message);
|
|
// if (success) {
|
|
// ui->action_start_measure->setEnabled(false);
|
|
// ui->action_stop_measure->setEnabled(true);
|
|
// }
|
|
}
|
|
|
|
void MainWindow::onMeasureStopped(bool success, const QString& message)
|
|
{
|
|
Q_UNUSED(message);
|
|
if (success) {
|
|
// ui->action_start_measure->setEnabled(true);
|
|
// ui->action_stop_measure->setEnabled(false);
|
|
m_AddressCountTimer->stop();
|
|
m_EnergyCountTimer->stop();
|
|
// // 更新树节点状态:把"测量中"改回"已停止"
|
|
// if (!nodeMap.isEmpty()) {
|
|
// MeasureAnalysisProjectModel* models = ProjectList::Instance()->GetCurrentProjectModel();
|
|
// if (models) {
|
|
// QStandardItem* nodeItem = nodeMap[models->GetProjectName()];
|
|
// if (nodeItem) {
|
|
// ProjectList::Instance()->SetNodeStatus(nodeItem, "已停止", false);
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
|
|
void MainWindow::onDeviceStatusMessage(const QString& msg)
|
|
{
|
|
ShowStatusBarMsg(msg);
|
|
}
|
|
|
|
void MainWindow::initMainWindow()
|
|
{
|
|
ads::CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::DockAreaHasCloseButton, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::AllTabsHaveCloseButton, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::DockAreaHasUndockButton, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::DockAreaDynamicTabsMenuButtonVisibility, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::DisableTabTextEliding, true);
|
|
ads::CDockManager::setConfigFlag(ads::CDockManager::DoubleClickUndocksWidget, false);
|
|
ads::CDockManager::setAutoHideConfigFlags({ CDockManager::DefaultAutoHideConfig });
|
|
|
|
_dock_manager = new CDockManager(this);
|
|
_dock_manager->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
|
_dock_manager->setLineWidth(1);
|
|
|
|
// Set central widget
|
|
MeasureAnalysisHistoryForm* measure_analysis_history_form = new MeasureAnalysisHistoryForm;
|
|
connect(this, &MainWindow::newProject, measure_analysis_history_form, &MeasureAnalysisHistoryForm::onUpdateNewHistoryProject);
|
|
CDockWidget* central_dock_widget = _dock_manager->createDockWidget(QStringLiteral(u"测量分析记录"));
|
|
central_dock_widget->setWidget(measure_analysis_history_form);
|
|
// central_dock_widget->setFeature(ads::CDockWidget::AllDockWidgetFeatures, true);
|
|
_central_dock_area = _dock_manager->setCentralWidget(central_dock_widget);
|
|
_action_central_dock_widget = central_dock_widget->toggleViewAction();
|
|
// _action_central_dock_widget->setCheckable(false);
|
|
ui->menu_view->addAction(_action_central_dock_widget);
|
|
|
|
// 构建测量分析工程树视图
|
|
_tree_measure_analysis = new MeasureAnalysisTreeView;
|
|
_dockw_measure_analysis_tree = new ads::CDockWidget(QStringLiteral(u"测量分析工作空间"));
|
|
_dockw_measure_analysis_tree->setWidget(_tree_measure_analysis);
|
|
_dockw_measure_analysis_tree->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent);
|
|
_dock_manager->addDockWidget(ads::DockWidgetArea::LeftDockWidgetArea, _dockw_measure_analysis_tree);
|
|
ui->menu_view->addAction(_dockw_measure_analysis_tree->toggleViewAction());
|
|
|
|
_menu_view_data_table_list = ui->menu_view->addMenu(QStringLiteral(u"查看数据列表"));
|
|
_menu_view_analysis_view_list = ui->menu_view->addMenu(QStringLiteral(u"分析视图列表"));
|
|
|
|
// 构建日志输出视图
|
|
_plain_edit_info_output = new QPlainTextEdit;
|
|
_plain_edit_info_output->setReadOnly(true);
|
|
_plain_edit_info_output->setFrameShape(QFrame::NoFrame);
|
|
_plain_edit_info_output->setLineWidth(0);
|
|
ads::CDockWidget* dockw_info_output = new ads::CDockWidget(QStringLiteral(u"信息输出"));
|
|
dockw_info_output->setWidget(_plain_edit_info_output);
|
|
dockw_info_output->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent);
|
|
_dock_manager->addDockWidget(ads::DockWidgetArea::BottomDockWidgetArea, dockw_info_output);
|
|
ui->menu_view->addAction(dockw_info_output->toggleViewAction());
|
|
}
|
|
|
|
void MainWindow::initAction()
|
|
{
|
|
auto new_measurement_analysis_handler = [this]() {
|
|
NewMeasureAnalysisDlg new_measure_analysis_dlg;
|
|
if (QDialog::Accepted == new_measure_analysis_dlg.exec()) {
|
|
ProjectList* project_list_model = ProjectList::Instance();
|
|
auto project_model = project_list_model->GetCurrentProjectModel();
|
|
emit newProject(project_model->GetProjectName());
|
|
|
|
if (project_model->GetIsMeasureComplete()) {
|
|
const QString& all_channel_particle_data_filename = project_model->GetAllChannelParticleDataFilename();
|
|
if (!all_channel_particle_data_filename.isEmpty()) {
|
|
const QString& all_ch_count_dir = project_model->GetProjectDir();
|
|
const QString& every_ch_count_dir = QDir(project_model->GetProjectDir()).filePath(QStringLiteral(u"通道道址计数"));
|
|
auto count_task = new DataProcessWorkPool::EveryChannelParticleCountDataTask;
|
|
count_task->SetAllChannelParticleDataFilename(all_channel_particle_data_filename);
|
|
count_task->SetAllChannelCountResultDir(all_ch_count_dir);
|
|
count_task->SetEveryChannelCountResultDir(every_ch_count_dir);
|
|
count_task->SetFinishedNotifier(project_list_model, "onChannelAddressCountProcessFinished", project_model->GetProjectName());
|
|
count_task->StartTask();
|
|
auto coincidence_process_task = new DataProcessWorkPool::CoincidenceEventAnalysisTask;
|
|
coincidence_process_task->SetFinishedNotifier(project_list_model, "onCoincidenceProcessFinished", project_model->GetProjectName());
|
|
coincidence_process_task->StartTask();
|
|
}
|
|
} else {
|
|
|
|
}
|
|
}
|
|
};
|
|
connect(ui->action_new_measurement_analysis, &QAction::triggered, new_measurement_analysis_handler);
|
|
connect(ui->action_open_measurement_analysis, &QAction::triggered, [this](){
|
|
const QString& filename = QFileDialog::getOpenFileName(this, QStringLiteral(u"选择测量分析项目文件"), QString(), QStringLiteral(u"测量分析项目 (*.msproject)"));
|
|
if (filename.isEmpty()) {
|
|
return;
|
|
}
|
|
QFileInfo file_info(filename);
|
|
if (file_info.size() == 0) {
|
|
QMessageBox::warning(this, QStringLiteral(u"警告"), QStringLiteral(u"选择的测量分析项目文件为空文件!"));
|
|
return;
|
|
}
|
|
MeasureAnalysisProjectModel* model = new MeasureAnalysisProjectModel;
|
|
if (model->LoadProjectModel(filename)) {
|
|
ProjectList::Instance()->AddProjectModel(model);
|
|
}
|
|
});
|
|
connect(ui->action_save_measurement_analysis, &QAction::triggered, [](){
|
|
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (project_model) {
|
|
const QString& project_name = project_model->GetProjectName();
|
|
if ( project_model->SaveProjectModel() ){
|
|
const QString& info_text = QStringLiteral(u"保存测量分析项目\"%1\"完成.").arg(project_name);
|
|
LOG_INFO(info_text);
|
|
} else {
|
|
const QString& warn_text = QStringLiteral(u"保存测量分析项目\"%1\"失败!").arg(project_name);
|
|
LOG_WARN(warn_text);
|
|
}
|
|
}
|
|
});
|
|
connect(ui->action_close_measurement_analysis, &QAction::triggered, [this](){
|
|
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (project_model) {
|
|
const QString& project_name = project_model->GetProjectName();
|
|
const QString& title = QStringLiteral(u"关闭测量分析项目");
|
|
const QString& text = QStringLiteral(u"是否关闭测量分析项目\"%1\"").arg(project_name);
|
|
auto result = QMessageBox::question(this, title, text, QMessageBox::Yes | QMessageBox::No);
|
|
if (QMessageBox::Yes == result) {
|
|
this->closeProject(project_name);
|
|
}
|
|
}
|
|
});
|
|
connect(ui->action_manage_measurement_analysis, &QAction::triggered, [this](){
|
|
this->_action_central_dock_widget->triggered(true);
|
|
});
|
|
connect(ui->action_device_config_mrg, &QAction::triggered, []() {
|
|
DeviceParamsManagerDlg().exec();
|
|
});
|
|
connect(ui->action_energy_scale_mrg, &QAction::triggered, []() {
|
|
QDialog energy_scale_mrg_dlg;
|
|
energy_scale_mrg_dlg.setObjectName("EnergyScaleFormDlg");
|
|
energy_scale_mrg_dlg.setWindowTitle(QStringLiteral(u"能量刻度管理"));
|
|
energy_scale_mrg_dlg.setWindowFlags(energy_scale_mrg_dlg.windowFlags() | Qt::WindowMaximizeButtonHint);
|
|
EnergyScaleForm* energy_scale_mrg_form = new EnergyScaleForm(&energy_scale_mrg_dlg);
|
|
QHBoxLayout* hlayout = new QHBoxLayout;
|
|
hlayout->addWidget(energy_scale_mrg_form);
|
|
energy_scale_mrg_dlg.setLayout(hlayout);
|
|
energy_scale_mrg_dlg.exec();
|
|
});
|
|
connect(ui->action_about_info, &QAction::triggered, []() {
|
|
AboutDlg about_dlg;
|
|
about_dlg.exec();
|
|
});
|
|
connect(_tree_measure_analysis, &MeasureAnalysisTreeView::currentItemView, [this](MeasureAnalysisView* view) {
|
|
if (view && this->_dock_manager) {
|
|
bool view_exist = false;
|
|
QList<CDockWidget*> dock_widget_list = this->_dock_manager->dockWidgetsMap().values();
|
|
for (auto it = dock_widget_list.constBegin(); it != dock_widget_list.constEnd(); ++it) {
|
|
CDockWidget* dock_widget = *it;
|
|
if (dock_widget) {
|
|
MeasureAnalysisView* dock_view = dynamic_cast<MeasureAnalysisView*>(dock_widget->widget());
|
|
if ( dock_view ) {
|
|
if (dock_view->GetViewName() == view->GetViewName()) {
|
|
dock_widget->toggleView();
|
|
dock_widget->raise();
|
|
view_exist = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ( !view_exist ) {
|
|
ads::CDockWidget* dock_widget = new ads::CDockWidget(view->GetViewName());
|
|
view->setMinimumSize(320, 280);
|
|
dock_widget->setWidget(view);
|
|
dock_widget->setMinimumSizeHintMode(ads::CDockWidget::MinimumSizeHintFromContent);
|
|
if (view->IsDeleteOnClose()) {
|
|
// dock_widget->setFeatures(dock_widget->features() | ads::CDockWidget::DockWidgetDeleteOnClose);
|
|
dock_widget->setFeatures(dock_widget->features() | ads::CDockWidget::CustomCloseHandling);
|
|
connect(dock_widget, &CDockWidget::closeRequested, [this, dock_widget, view](){
|
|
MeasureAnalysisView* dock_view = dynamic_cast<MeasureAnalysisView*>(dock_widget->widget());
|
|
if ( dock_view ) {
|
|
const QString& view_name = view->GetViewName();
|
|
if (dock_view->GetViewName() == view_name) {
|
|
_tree_measure_analysis->RemoveItemView(view_name);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if ( view->GetViewType() == MeasureAnalysisView::DataTable ) {
|
|
_menu_view_data_table_list->addAction(dock_widget->toggleViewAction());
|
|
}
|
|
if ( view->GetViewType() == MeasureAnalysisView::PlotFrame ) {
|
|
_menu_view_analysis_view_list->addAction(dock_widget->toggleViewAction());
|
|
}
|
|
auto central_area = _dock_manager->centralWidget()->dockAreaWidget();
|
|
_dock_manager->addDockWidget(ads::DockWidgetArea::CenterDockWidgetArea, dock_widget, central_area);
|
|
}
|
|
}
|
|
});
|
|
connect(_tree_measure_analysis, &MeasureAnalysisTreeView::removeItemView, [this](MeasureAnalysisView* view) {
|
|
if (this->_dock_manager) {
|
|
QList<CDockWidget*> dock_widget_list = this->_dock_manager->dockWidgetsMap().values();
|
|
for (auto it = dock_widget_list.constBegin(); it != dock_widget_list.constEnd(); ++it) {
|
|
CDockWidget* dock_widget = *it;
|
|
if (dock_widget) {
|
|
if ( dock_widget->widget() == view ) {
|
|
dock_widget->deleteDockWidget();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void MainWindow::initStatusBar()
|
|
{
|
|
_w_watcher_task_list = new BackgroundTaskListView(this);
|
|
|
|
_btn_task_watcher = new QPushButton(QStringLiteral(u"后台任务监视"), _status_bar);
|
|
_status_bar->addPermanentWidget(_btn_task_watcher);
|
|
connect(_btn_task_watcher, &QPushButton::clicked, this, [this](){
|
|
if ( _w_watcher_task_list->isVisible() ) {
|
|
_w_watcher_task_list->hide();
|
|
} else {
|
|
this->onShowBackgroundTaskList();
|
|
}
|
|
});
|
|
}
|
|
|
|
void MainWindow::applyStyleSheet()
|
|
{
|
|
// #ifdef ENABLE_DEBUG
|
|
// QString style_file_path = "D:/Workspace/EnergySpectrumAnalyerProject/EnergySpectrumAnalyer/style/stylesheet/";
|
|
// #else
|
|
QString style_file_path = ":/stylesheet/";
|
|
// #endif
|
|
QFile file_stylesheet_default(style_file_path + "default.qss");
|
|
if (file_stylesheet_default.open(QFile::ReadOnly)) {
|
|
const QString& str_stylesheet_default = file_stylesheet_default.readAll();
|
|
qApp->setStyleSheet(str_stylesheet_default);
|
|
}
|
|
QFile file_stylesheet_dock(style_file_path + "dock.qss");
|
|
if (file_stylesheet_dock.open(QFile::ReadOnly)) {
|
|
const QString& str_stylesheet_dock = file_stylesheet_dock.readAll();
|
|
_dock_manager->setStyleSheet(_dock_manager->styleSheet() + str_stylesheet_dock);
|
|
}
|
|
}
|
|
|
|
void MainWindow::closeProject(const QString& project_name)
|
|
{
|
|
auto closeAnalysisView = [this](const QString& project_name){
|
|
if (this->_dock_manager) {
|
|
QList<CDockWidget*> dock_widget_list = this->_dock_manager->dockWidgetsMap().values();
|
|
for (auto it = dock_widget_list.constBegin(); it != dock_widget_list.constEnd(); ++it) {
|
|
CDockWidget* dock_widget = *it;
|
|
if (dock_widget) {
|
|
MeasureAnalysisView* view = dynamic_cast<MeasureAnalysisView*>(dock_widget->widget());
|
|
if (view ) {
|
|
if ( view->GetProjectName() == project_name ) {
|
|
dock_widget->deleteDockWidget();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetProjectModel(project_name);
|
|
if (project_model) {
|
|
closeAnalysisView(project_name);
|
|
project_model->SaveProjectModel();
|
|
if(ProjectList::Instance()->RmProjectModel(project_name)) {
|
|
const QString& info_text = QStringLiteral(u"测试分析项\"%1\"已关闭.").arg(project_name);
|
|
LOG_INFO(info_text);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::showEvent(QShowEvent *event)
|
|
{
|
|
QMainWindow::showEvent(event);
|
|
this->applyStyleSheet();
|
|
}
|
|
|
|
void MainWindow::closeEvent(QCloseEvent* event)
|
|
{
|
|
QList<MeasureAnalysisProjectModel *> models = ProjectList::Instance()->GetProjectModels();
|
|
for (auto model : models) {
|
|
if (model) {
|
|
closeProject(model->GetProjectName());
|
|
}
|
|
}
|
|
QMainWindow::closeEvent(event);
|
|
}
|
|
|
|
void MainWindow::moveEvent(QMoveEvent *event)
|
|
{
|
|
QMainWindow::moveEvent(event);
|
|
if (this->_w_watcher_task_list->isVisible()) {
|
|
onShowBackgroundTaskList();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_action_nuclideLib_triggered()
|
|
{
|
|
NuclideLibManage *nuclidelib = new NuclideLibManage();
|
|
nuclidelib->show();
|
|
}
|
|
|
|
void MainWindow::onShowBackgroundTaskList()
|
|
{
|
|
this->updateGeometry();
|
|
this->_btn_task_watcher->updateGeometry();
|
|
|
|
this->_w_watcher_task_list->adjustSize();
|
|
QSize pop_size = this->_w_watcher_task_list->size();
|
|
|
|
QPoint btn_top_teft = this->_btn_task_watcher->mapToGlobal(QPoint(0, 0));
|
|
int btn_width = this->_btn_task_watcher->width();
|
|
// int btn_height = this->_btn_task_watcher->height();
|
|
|
|
int x = btn_top_teft.x() + btn_width - pop_size.width() - 2;
|
|
int y = btn_top_teft.y() - pop_size.height() - 6;
|
|
|
|
// QRect screen_rect = QApplication::desktop()->availableGeometry(this);
|
|
// if (x < screen_rect.left() + 6)
|
|
// x = screen_rect.left();
|
|
// if (x + pop_size.width() > screen_rect.right())
|
|
// x = screen_rect.right() - pop_size.width();
|
|
// if (y < screen_rect.top())
|
|
// y = btn_top_teft.y() + btn_height + 6;
|
|
|
|
this->_w_watcher_task_list->move(x, y);
|
|
this->_w_watcher_task_list->show();
|
|
}
|
|
|
|
|
|
void MainWindow::resizeEvent(QResizeEvent *event)
|
|
{
|
|
QMainWindow::resizeEvent(event);
|
|
if (this->_w_watcher_task_list->isVisible()) {
|
|
onShowBackgroundTaskList();
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::on_action_start_measure_triggered()
|
|
{
|
|
m_deviceMgr->startMeasure();
|
|
}
|
|
|
|
//更新粒子数据树形节点状态
|
|
void MainWindow::onUpdateParticleDataTreeStatus()
|
|
{
|
|
MeasureAnalysisProjectModel* models = ProjectList::Instance()->GetCurrentProjectModel();
|
|
QMap<QString, QMap<QString, QStandardItem *> > project_node_items = ProjectList::Instance()->getProjectNodeItems();
|
|
nodeMap = project_node_items[models->GetProjectName()];
|
|
QStandardItem *nodeItem = nodeMap[models->GetProjectName()];
|
|
ProjectList::Instance()->SetNodeStatus(nodeItem,"测量中",true);
|
|
|
|
QString dir = ProjectList::Instance()->GetCurrentProjectModel()->GetProjectDir();
|
|
QString csvPath = QStringLiteral(u"%1/%2").arg(dir).arg("粒子数据.csv");
|
|
models->SetAllChannelParticleDataFilename(csvPath);
|
|
bool status_ok = !models->GetAllChannelParticleDataFilename().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QVariant analys_type = QVariant::fromValue(AnalysisType::ParticleData);
|
|
QString item_name = QStringLiteral(u"测量粒子数据");
|
|
QStandardItem * particleData = nodeMap[item_name];
|
|
if (particleData) {
|
|
ProjectList::Instance()->SetNodeStatus(particleData,status,true);
|
|
}
|
|
}
|
|
|
|
void MainWindow::onGvfData(const QByteArray &data)
|
|
{
|
|
MeasureAnalysisProjectModel *project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!project_model) return;
|
|
|
|
QMetaObject::invokeMethod(_gvfWorker, "processGvfData", Qt::QueuedConnection,
|
|
Q_ARG(QByteArray, data),
|
|
Q_ARG(QString, project_model->GetProjectDir()),
|
|
Q_ARG(QString, project_model->GetEnergyScaleFilename()),
|
|
Q_ARG(QString, project_model->GetProjectName()));
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::updataTable()
|
|
{
|
|
auto dockList = _dock_manager->dockWidgetsMap().values();
|
|
for(auto dock : dockList)
|
|
{
|
|
MeasureAnalysisView* view = dynamic_cast<MeasureAnalysisView*>(dock->widget());
|
|
if(!view) continue;
|
|
if(view->GetViewType() == MeasureAnalysisView::DataTable)
|
|
{
|
|
switch(view->GetAnalyzeType())
|
|
{
|
|
case AnalysisType::ParticleData:{
|
|
MeasureAnalysisDataTableView* table = dynamic_cast<MeasureAnalysisDataTableView*>(view);
|
|
table->AppendRow();
|
|
};break;
|
|
// case AnalysisType::AddressCountData:
|
|
// {
|
|
// MeasureAnalysisDataTableView* table = dynamic_cast<MeasureAnalysisDataTableView*>(view);
|
|
// table->AppendRow();
|
|
// };break;
|
|
case AnalysisType::ParticleEnergyData:
|
|
{
|
|
MeasureAnalysisDataTableView* table = dynamic_cast<MeasureAnalysisDataTableView*>(view);
|
|
table->AppendRow();
|
|
};break;
|
|
// case AnalysisType::EnergyCountData:
|
|
// {
|
|
// MeasureAnalysisDataTableView* table = dynamic_cast<MeasureAnalysisDataTableView*>(view);
|
|
// table->AppendRow();
|
|
// };break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::changeAddressCountView(QList<ParticleData> &dataList)
|
|
{
|
|
if (dataList.isEmpty()) {
|
|
return;
|
|
}
|
|
MeasureAnalysisProjectModel* pro_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!pro_model) {
|
|
LOG_ERROR(QStringLiteral(u"当前没有打开的测量项目,无法处理能谱数据"));
|
|
return;
|
|
}
|
|
|
|
bool status_ok = !pro_model->GetChannelAddressCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QString item_name = QStringLiteral(u"道址计数谱");
|
|
QStandardItem * particleData = nodeMap[item_name];
|
|
//获取道址计数谱状态
|
|
bool bStatus = ProjectList::Instance()->GetNodeStatus(particleData);
|
|
if(!bStatus)
|
|
{
|
|
ProjectList::Instance()->SetNodeStatus(particleData,status,true);
|
|
m_AddressCountTimer->start();
|
|
}
|
|
}
|
|
|
|
void MainWindow::changeEnergyCountView(QList<ParticleData> &dataList)
|
|
{
|
|
if (dataList.isEmpty()) {
|
|
return;
|
|
}
|
|
MeasureAnalysisProjectModel* pro_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!pro_model) {
|
|
LOG_ERROR(QStringLiteral(u"当前没有打开的测量项目,无法处理能谱数据"));
|
|
return;
|
|
}
|
|
|
|
bool status_ok = !pro_model->GetChannelAddressCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QString item_name = QStringLiteral(u"能量计数谱");
|
|
QStandardItem * particleData = nodeMap[item_name];
|
|
//获取能量计数谱状态
|
|
bool bStatus = ProjectList::Instance()->GetNodeStatus(particleData);
|
|
if(!bStatus)
|
|
{
|
|
ProjectList::Instance()->SetNodeStatus(particleData,status,true);
|
|
m_EnergyCountTimer->start();
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_AddressCountTimer()
|
|
{
|
|
//获取道址计数谱
|
|
auto dockList = _dock_manager->dockWidgetsMap().values();
|
|
for(auto dock : dockList)
|
|
{
|
|
ParticleCountPlotView* view = dynamic_cast<ParticleCountPlotView*>(dock->widget());
|
|
if(!view) continue;
|
|
if(view->GetAnalyzeType() == AnalysisType::AddressCountSpectrumView)
|
|
{
|
|
QMap<QString, QVariant> data_files_set;
|
|
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (project_model) {
|
|
auto file_name_list = project_model->GetChannelAddressCountDataFilenameList();
|
|
if ( !file_name_list.isEmpty() ) {
|
|
auto ch_num_list = file_name_list.keys();
|
|
for(auto ch_num : ch_num_list) {
|
|
auto file_name = file_name_list[ch_num];
|
|
if ( !file_name.isEmpty()) {
|
|
data_files_set[QStringLiteral(u"通道%1").arg(ch_num)] = file_name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
view->updateView(data_files_set);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_EnergyCountTimer()
|
|
{
|
|
//获取道址计数谱
|
|
auto dockList = _dock_manager->dockWidgetsMap().values();
|
|
for(auto dock : dockList)
|
|
{
|
|
EnergyCountPlotView* view = dynamic_cast<EnergyCountPlotView*>(dock->widget());
|
|
if(!view) continue;
|
|
|
|
if(view->GetAnalyzeType() == AnalysisType::EnergyCountSpectrumView)
|
|
{
|
|
QMap<QString, QVariant> data_files_set;
|
|
MeasureAnalysisProjectModel* project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (project_model) {
|
|
auto all_ch_energy_count_file_name = project_model->GetAllChannelEnergyTotalCountDataFilename();
|
|
if (!all_ch_energy_count_file_name.isEmpty()) {
|
|
data_files_set[QStringLiteral(u"全通道")] = all_ch_energy_count_file_name;
|
|
}
|
|
auto file_name_list = project_model->GetChannelEnergyCountDataFilenameList();
|
|
if ( !file_name_list.isEmpty() ) {
|
|
auto ch_num_list = file_name_list.keys();
|
|
for(auto ch_num : ch_num_list) {
|
|
auto file_name = file_name_list[ch_num];
|
|
if ( !file_name.isEmpty()) {
|
|
data_files_set[QStringLiteral(u"通道%1").arg(ch_num)] = file_name;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
view->updateView(data_files_set);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::on_action_stop_measure_triggered()
|
|
{
|
|
m_deviceMgr->stopMeasure();
|
|
m_AddressCountTimer->stop();
|
|
m_EnergyCountTimer->stop();
|
|
}
|
|
|
|
void MainWindow::on_action_device_connect_cfg_triggered()
|
|
{
|
|
MeasureAnalysisProjectModel* projectModel = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!projectModel) {
|
|
QMessageBox::information(this, "提示", "请先新建项目", "确认", "取消");
|
|
return;
|
|
}
|
|
m_deviceMgr->loadConfig();
|
|
m_deviceMgr->exec();
|
|
}
|
|
|
|
void MainWindow::onParticleDatarefresh()
|
|
{
|
|
MeasureAnalysisProjectModel *pro_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!pro_model) return;
|
|
bool status_ok = !pro_model->GetAllChannelParticleDataFilename().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QVariant analys_type = QVariant::fromValue(AnalysisType::ParticleData);
|
|
QString item_name = QStringLiteral(u"测量粒子数据");
|
|
QStandardItem * particleData = nodeMap[item_name];
|
|
ProjectList::Instance()->SetNodeStatus(particleData,status,true);
|
|
updataTable();
|
|
}
|
|
void MainWindow::onAddressCountViewNeedRefresh()
|
|
{
|
|
MeasureAnalysisProjectModel *pro_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!pro_model) return;
|
|
|
|
bool status_ok = !pro_model->GetChannelAddressCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QString item_name = QStringLiteral(u"道址计数谱");
|
|
QStandardItem *particleData = nodeMap[item_name];
|
|
|
|
if (particleData) {
|
|
bool bStatus = ProjectList::Instance()->GetNodeStatus(particleData);
|
|
if (!bStatus) {
|
|
ProjectList::Instance()->SetNodeStatus(particleData, status, true);
|
|
m_AddressCountTimer->start();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::onEnergyCountViewNeedRefresh()
|
|
{
|
|
MeasureAnalysisProjectModel *pro_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!pro_model) return;
|
|
|
|
bool status_ok = !pro_model->GetChannelEnergyCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
QString item_name = QStringLiteral(u"能量计数谱");
|
|
QStandardItem *particleData = nodeMap[item_name];
|
|
|
|
if (particleData) {
|
|
bool bStatus = ProjectList::Instance()->GetNodeStatus(particleData);
|
|
if (!bStatus) {
|
|
ProjectList::Instance()->SetNodeStatus(particleData, status, true);
|
|
m_EnergyCountTimer->start();
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::onNewAddressCountChannelFile(uint channelNum, const QString &filename)
|
|
{
|
|
MeasureAnalysisProjectModel *project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!project_model) return;
|
|
|
|
project_model->SetChannelAddressCountDataFilename(channelNum, filename);
|
|
project_model->SaveProjectModel();
|
|
|
|
// 更新项目树节点
|
|
const QString &adrr_count_item_name = QStringLiteral(u"道址计数");
|
|
if (nodeMap.contains(adrr_count_item_name)) {
|
|
QStandardItem *adrr_count_item = nodeMap[adrr_count_item_name];
|
|
bool status_ok = !project_model->GetChannelAddressCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
ProjectList::Instance()->SetNodeStatus(adrr_count_item, status, status_ok);
|
|
|
|
QString item_name = QStringLiteral(u"通道%1道址计数").arg(channelNum);
|
|
if (!nodeMap.contains(item_name)) {
|
|
const QVariant &analys_type = QVariant::fromValue(AnalysisType::AddressCountData);
|
|
QStandardItem *node_item = ProjectList::Instance()->AddChildNode(
|
|
adrr_count_item, item_name, status, analys_type, true, status_ok);
|
|
node_item->setData(project_model->GetProjectName(), Qt::UserRole + 2);
|
|
node_item->setData(channelNum, Qt::UserRole + 3);
|
|
nodeMap[item_name] = node_item;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::onNewEnergyCountChannelFile(uint channelNum, const QString &filename)
|
|
{
|
|
MeasureAnalysisProjectModel *project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!project_model) return;
|
|
|
|
project_model->SetChannelEnergyCountDataFilename(channelNum, filename);
|
|
project_model->SaveProjectModel();
|
|
|
|
// 更新项目树节点
|
|
const QString &energy_count_item_name = QStringLiteral(u"能量计数");
|
|
QMap<QString, QMap<QString, QStandardItem *>> all_nodes = ProjectList::Instance()->getProjectNodeItems();
|
|
QMap<QString, QStandardItem *> project_nodes = all_nodes[project_model->GetProjectName()];
|
|
|
|
if (project_nodes.contains(energy_count_item_name)) {
|
|
QStandardItem *energy_count_item = project_nodes[energy_count_item_name];
|
|
bool status_ok = !project_model->GetChannelEnergyCountDataFilenameList().isEmpty();
|
|
QString status = status_ok ? QStringLiteral(u"有效") : QStringLiteral(u"无效");
|
|
ProjectList::Instance()->SetNodeStatus(energy_count_item, status, status_ok);
|
|
|
|
QString item_name = QStringLiteral(u"通道%1能量计数").arg(channelNum);
|
|
if (!project_nodes.contains(item_name)) {
|
|
const QVariant &analys_type = QVariant::fromValue(AnalysisType::EnergyCountData);
|
|
QStandardItem *node_item = ProjectList::Instance()->AddChildNode(
|
|
energy_count_item, item_name, status, analys_type, true, status_ok);
|
|
node_item->setData(project_model->GetProjectName(), Qt::UserRole + 2);
|
|
node_item->setData(channelNum, Qt::UserRole + 3);
|
|
project_nodes[item_name] = node_item;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::onAllChannelEnergyCountFileUpdated(const QString &filename)
|
|
{
|
|
MeasureAnalysisProjectModel *project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!project_model) return;
|
|
|
|
project_model->SetAllChannelEnergyTotalCountDataFilename(filename);
|
|
project_model->SaveProjectModel();
|
|
}
|
|
|
|
void MainWindow::onParticleEnergyDataUpdated(const QString &energySpectrumFilename)
|
|
{
|
|
MeasureAnalysisProjectModel *project_model = ProjectList::Instance()->GetCurrentProjectModel();
|
|
if (!project_model) return;
|
|
|
|
// 更新项目模型
|
|
project_model->SetParticleEnergyDataFilename(energySpectrumFilename);
|
|
project_model->SaveProjectModel();
|
|
|
|
// 更新节点状态
|
|
const QString &energy_node_name = QStringLiteral(u"粒子能量数据");
|
|
if (nodeMap.contains(energy_node_name)) {
|
|
QStandardItem *energy_node = nodeMap[energy_node_name];
|
|
ProjectList::Instance()->SetNodeStatus(energy_node, QStringLiteral(u"有效"), true);
|
|
}
|
|
|
|
// 更新数据表格
|
|
// updataTable();
|
|
} |