#include "MeasureAnalysisProjectModel.h" #include "AnalysisTypeDefine.h" #include "GlobalDefine.h" void MeasureAnalysisProjectModel::SetProjectDir(const QString& project_dir) { this->_project_dir = project_dir; } void MeasureAnalysisProjectModel::SetProjectName(const QString& project_name) { this->_project_name = project_name; } void MeasureAnalysisProjectModel::SetSpectrumType(MeasureAnalysisProjectModel::SpectrumType spec_type) { this->_spec_type = spec_type; } void MeasureAnalysisProjectModel::SetIsStdSource(bool is_std_source) { this->_is_std_source = is_std_source; } void MeasureAnalysisProjectModel::SetDescriptionInfo(const QString& description_info) { this->_description_info = description_info; } void MeasureAnalysisProjectModel::SetMeasurePresetTime(ulong measure_preset_time) { this->_measure_preset_time = measure_preset_time; } void MeasureAnalysisProjectModel::SetConformTimeWin(uint conform_time_win) { this->_conform_time_win = conform_time_win; } void MeasureAnalysisProjectModel::SetIsMeasureComplete(bool is_measure_complete) { this->_is_measure_complete = is_measure_complete; } void MeasureAnalysisProjectModel::SetMeasureDeviceParamsCfgFilename(const QString& filename) { this->_measure_device_params_cfg_filename = filename; } void MeasureAnalysisProjectModel::SetEneryScaleFilename(const QString& filename) { this->_enery_scale_filename = filename; } void MeasureAnalysisProjectModel::SetEfficiencyScaleFilename(const QString& filename) { this->_efficiency_scale_filename = filename; } void MeasureAnalysisProjectModel::SetAllChannelParticleDataFilename(const QString& filename) { this->_all_channel_particle_data_filename = filename; } void MeasureAnalysisProjectModel::SetSortedParticleDataFilename(const QString& filename) { this->_sorted_particle_data_filename = filename; } // void MeasureAnalysisProjectModel::SetChannelParticleDataFilename(uint channel, const QString& filename) // { // this->_channel_particle_data_filename_list[channel] = filename; // } void MeasureAnalysisProjectModel::SetChannelAddressCountDataFilename(uint channel, const QString& filename) { this->_channel_address_count_data_filename_list[channel] = filename; } // void MeasureAnalysisProjectModel::SetAllChannelParticleTotalCountDataFilename(const QString& filename) // { // this->_all_channel_particle_total_count_data_filename = filename; // } void MeasureAnalysisProjectModel::SetChannelEneryCountDataFilename(uint channel, const QString& filename) { this->_channel_every_count_data_filename_list[channel] = filename; } void MeasureAnalysisProjectModel::SetAllChannelEneryTotalCountDataFilename(const QString& filename) { this->_all_channel_enery_total_count_data_filename = filename; } void MeasureAnalysisProjectModel::SetTimeWinConformParticleData(uint time_win, uint conform_particle_count, const QString& filename) { this->_time_win_conform_particle_data[time_win][conform_particle_count] = filename; } const QString& MeasureAnalysisProjectModel::GetProjectDir() const { return this->_project_dir; } const QString& MeasureAnalysisProjectModel::GetProjectName() const { return this->_project_name; } MeasureAnalysisProjectModel::SpectrumType MeasureAnalysisProjectModel::GetSpectrumType() const { return this->_spec_type; } bool MeasureAnalysisProjectModel::GetIsStdSource() const { return this->_is_std_source; } const QString& MeasureAnalysisProjectModel::GetDescriptionInfo() const { return this->_description_info; } ulong MeasureAnalysisProjectModel::GetMeasurePresetTime() const { return this->_measure_preset_time; } uint MeasureAnalysisProjectModel::GetConformTimeWin() const { return this->_conform_time_win; } bool MeasureAnalysisProjectModel::GetIsMeasureComplete() const { return this->_is_measure_complete; } const QString& MeasureAnalysisProjectModel::GetMeasureDeviceParamsCfgFilename() const { return this->_measure_device_params_cfg_filename; } const QString& MeasureAnalysisProjectModel::GetEneryScaleFilename() const { return this->_enery_scale_filename; } const QString& MeasureAnalysisProjectModel::GetEfficiencyScaleFilename() const { return this->_efficiency_scale_filename; } const QString& MeasureAnalysisProjectModel::GetAllChannelParticleDataFilename() const { return this->_all_channel_particle_data_filename; } const QString& MeasureAnalysisProjectModel::GetSortAllChannelParticleDataFilename() const { return this->_sorted_particle_data_filename; } // const QMap& MeasureAnalysisProjectModel::GetChannelParticleDataFilenameList() const // { // return this->_channel_particle_data_filename_list; // } // const QString& MeasureAnalysisProjectModel::GetChannelParticleDataFilename(uint channel) const // { // return QString(this->_channel_particle_data_filename_list[channel]); // } const QMap& MeasureAnalysisProjectModel::GetChannelAddressCountDataFilenameList() const { return this->_channel_address_count_data_filename_list; } const QString& MeasureAnalysisProjectModel::GetChannelAddressCountDataFilename(uint channel) const { QString file_name; if ( this->_channel_address_count_data_filename_list.contains(channel) ) { file_name = this->_channel_address_count_data_filename_list[channel]; } return file_name; } // const QString& MeasureAnalysisProjectModel::GetAllChannelParticleTotalCountDataFilename() const // { // return this->_all_channel_particle_total_count_data_filename; // } const QMap& MeasureAnalysisProjectModel::GetChannelEneryCountDataFilenameList() const { return this->_channel_every_count_data_filename_list; } const QString& MeasureAnalysisProjectModel::GetChannelEneryCountDataFilename(uint channel) const { QString file_name; if ( this->_channel_every_count_data_filename_list.contains(channel) ) { file_name = this->_channel_every_count_data_filename_list[channel]; } return file_name; } const QString& MeasureAnalysisProjectModel::GetAllChannelEneryTotalCountDataFilename() const { return this->_all_channel_enery_total_count_data_filename; } const QMap& MeasureAnalysisProjectModel::GetTimeWinConformParticleDataFilenameList(uint time_win) const { QMap conform_particle_data; if ( this->_time_win_conform_particle_data.contains(time_win) ) { conform_particle_data = this->_time_win_conform_particle_data[time_win]; } return conform_particle_data; } ////////////////////////////////////////////////////////////////////////////////////////// /* MeasureAnalysisProjectModelList */ ////////////////////////////////////////////////////////////////////////////////////////// enum ColumnType { NameColumn, StatusColumn }; MeasureAnalysisProjectModelList* MeasureAnalysisProjectModelList::_s_instance { nullptr }; MeasureAnalysisProjectModelList* MeasureAnalysisProjectModelList::Instance() { if (!_s_instance) { _s_instance = new MeasureAnalysisProjectModelList(); } return _s_instance; } void MeasureAnalysisProjectModelList::AddProjectModel(MeasureAnalysisProjectModel* model) { const QString& project_name = model->GetProjectName(); _project_models[project_name] = model; SetCurrentProjectModel(project_name); intiProjectNodeStruce(); } void MeasureAnalysisProjectModelList::RmProjectModel(const QString& project_name) { if (_project_models.contains(project_name)) { delete _project_models[project_name]; _project_models.remove(project_name); } } MeasureAnalysisProjectModel* MeasureAnalysisProjectModelList::GetProjectModel(const QString& project_name) { if (_project_models.contains(project_name)) { return _project_models[project_name]; } return nullptr; } MeasureAnalysisProjectModel* MeasureAnalysisProjectModelList::GetCurrentProjectModel() { return _current_project_model; } void MeasureAnalysisProjectModelList::SetCurrentProjectModel(const QString& project_name) { if (_project_models.contains(project_name)) { _current_project_model = _project_models[project_name]; } } MeasureAnalysisProjectModelList::MeasureAnalysisProjectModelList(QObject* parent) : QStandardItemModel(parent) , _current_project_model(nullptr) { setColumnCount(2); setHeaderData(NameColumn, Qt::Horizontal, QStringLiteral(u"项名")); setHeaderData(StatusColumn, Qt::Horizontal, QStringLiteral(u"状态")); } QStandardItem* MeasureAnalysisProjectModelList::GetItemFromIndex(const QModelIndex& index) const { QModelIndex nameIndex = index.sibling(index.row(), NameColumn); return itemFromIndex(nameIndex); } QStandardItem* MeasureAnalysisProjectModelList::AddChildNode( QStandardItem* parent_item, const QString& node_name, const QString& status, const QVariant& user_data, bool is_fixed) { if (!parent_item) return nullptr; QStandardItem* name_item = new QStandardItem(node_name); name_item->setData(user_data, NodeType); name_item->setData(is_fixed, Fixed); QStandardItem* status_item = new QStandardItem(status); QList row_items; row_items << name_item << status_item; parent_item->appendRow(row_items); return name_item; } bool MeasureAnalysisProjectModelList::RemoveNode(QStandardItem* item) { if (!item) return false; if (item->column() == NameColumn && item->data(Fixed).toBool()) return false; QStandardItem* parent_item = item->parent(); if (!parent_item) { return false; } parent_item->removeRow(item->row()); const QString& project_name = item->data(ProjectName).toString(); if (AnalysisType::Project == item->data(NodeType).value()) { _project_node_items.remove(project_name); return true; } else { const QString& node_name = item->text(); if (_project_node_items.contains(project_name)) { if (_project_node_items[project_name].contains(node_name)) { _project_node_items[project_name].remove(node_name); } } } return true; } void MeasureAnalysisProjectModelList::SetNodeUserData(QStandardItem* item, const QVariant& data) { if (item && item->column() == NameColumn) item->setData(data, NodeType); } QVariant MeasureAnalysisProjectModelList::GetNodeUserData(QStandardItem* item, UserDataType data_type) const { return (item && item->column() == NameColumn) ? item->data(data_type) : QVariant(); } void MeasureAnalysisProjectModelList::SetNodeStatus(QStandardItem* item, const QString& status) { if (!item || item->column() != NameColumn) return; QStandardItem* status_item = item->parent() ? item->parent()->child(item->row(), StatusColumn) : invisibleRootItem()->child(item->row(), StatusColumn); if (status_item) { status_item->setText(status); } } QString MeasureAnalysisProjectModelList::GetNodeStatus(QStandardItem* item) const { if (!item || item->column() != NameColumn) return QString(); QStandardItem* status_item = item->parent() ? item->parent()->child(item->row(), StatusColumn) : invisibleRootItem()->child(item->row(), StatusColumn); return status_item ? status_item->text() : QString(); } void MeasureAnalysisProjectModelList::onChannelAddressCountProcessFinished(const QString& project_name) { if (this->_project_models.contains(project_name)) { auto pro_model = this->_project_models[project_name]; const QMap& filename_list = pro_model->GetChannelAddressCountDataFilenameList(); QString status = QStringLiteral(u"无效"); if (!filename_list.isEmpty()) { status = QStringLiteral(u"有效"); } auto& node_map = this->_project_node_items[project_name]; const QString& adrr_count_item_name = QStringLiteral(u"道址计数"); if (node_map.contains(adrr_count_item_name)) { auto adrr_count_item = node_map[adrr_count_item_name]; this->SetNodeStatus(adrr_count_item, status); for (auto it = filename_list.begin(); it != filename_list.end(); ++it) { uint ch_num = it.key(); QString item_name = QStringLiteral(u"通道%1道址计数").arg(ch_num); const QVariant& analys_type = QVariant::fromValue(AnalysisType::AddressCountData); QStandardItem* node_item = AddChildNode(adrr_count_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_item->setData(ch_num, ChannelNum); node_map[item_name] = node_item; } } const QString& adrr_count_spec_item_name = QStringLiteral(u"道址计数谱"); if (node_map.contains(adrr_count_spec_item_name)) { auto adrr_count_spec_item = node_map[adrr_count_spec_item_name]; this->SetNodeStatus(adrr_count_spec_item, status); } } } void MeasureAnalysisProjectModelList::intiProjectNodeStruce() { MeasureAnalysisProjectModel* cur_pro_model = GetCurrentProjectModel(); if (!cur_pro_model) { return; } QMap node_map; QStandardItem* root_item = invisibleRootItem(); const QString& project_name = cur_pro_model->GetProjectName(); QString status = cur_pro_model->GetIsMeasureComplete() ? QStringLiteral(u"测量完成") : QStringLiteral(u"未测量"); QVariant analys_type = QVariant::fromValue(AnalysisType::Project); QStandardItem* project_item = AddChildNode(root_item, project_name, status, analys_type, false); project_item->setData(project_name, ProjectName); // 测量控制 QString item_name = QStringLiteral(u"测量控制"); QStandardItem* measure_ctrl_item = AddChildNode(project_item, item_name, QString(), QVariant(), true); measure_ctrl_item->setData(project_name, ProjectName); node_map[item_name] = measure_ctrl_item; if (!cur_pro_model->GetIsMeasureComplete()) { const QString& measure_device_params_cfg_filename = cur_pro_model->GetMeasureDeviceParamsCfgFilename(); status = measure_device_params_cfg_filename.isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置"); analys_type = QVariant::fromValue(AnalysisType::DeviceParamsCfg); item_name = QStringLiteral(u"设备配置参数"); QStandardItem* node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; } status = cur_pro_model->GetEneryScaleFilename().isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置"); analys_type = QVariant::fromValue(AnalysisType::EnergyScale); item_name = QStringLiteral(u"能量刻度"); QStandardItem* node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetEfficiencyScaleFilename().isEmpty() ? QStringLiteral(u"未配置") : QStringLiteral(u"已配置"); analys_type = QVariant::fromValue(AnalysisType::EfficiencyScale); item_name = QStringLiteral(u"效率刻度"); node_item = AddChildNode(measure_ctrl_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; // 分析数据 item_name = QStringLiteral(u"分析数据"); QStandardItem* analysis_data_item = AddChildNode(project_item, item_name, QString(), QVariant(), true); analysis_data_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::ParticleData); item_name = QStringLiteral(u"测量粒子数据"); node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; item_name = QStringLiteral(u"道址计数"); status = cur_pro_model->GetChannelAddressCountDataFilenameList().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); node_item = AddChildNode(analysis_data_item, item_name, status, QVariant(), true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; item_name = QStringLiteral(u"能量计数"); status = cur_pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::EnergyCountData); node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; uint conform_time_win = cur_pro_model->GetConformTimeWin(); status = cur_pro_model->GetTimeWinConformParticleDataFilenameList(conform_time_win).isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergyData); item_name = QStringLiteral(u"符合粒子数据[%1ns]").arg(conform_time_win); node_item = AddChildNode(analysis_data_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; // 交互分析 item_name = QStringLiteral(u"交互分析"); QStandardItem* interactive_analysis_item = AddChildNode(project_item, item_name, QString(), QVariant(), true); interactive_analysis_item->setData(project_name, ProjectName); node_map[item_name] = interactive_analysis_item; status = cur_pro_model->GetChannelAddressCountDataFilenameList().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::AddressCountSpectrumView); item_name = QStringLiteral(u"道址计数谱"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetChannelEneryCountDataFilenameList().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::EneryCountSpectrumView); item_name = QStringLiteral(u"通道能量计数谱"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::EneryCountSpectrumView); item_name = QStringLiteral(u"能量计数谱"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::CountingRateView); item_name = QStringLiteral(u"计数率分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::EnergyPeakFitView); item_name = QStringLiteral(u"峰拟合分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetAllChannelEneryTotalCountDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::NuclideAnalysisView); item_name = QStringLiteral(u"核素分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::ParticleInTimeView); item_name = QStringLiteral(u"粒子入射时间分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetSortAllChannelParticleDataFilename().isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::ParticleTimeDiffView); item_name = QStringLiteral(u"粒子时间差分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; status = cur_pro_model->GetTimeWinConformParticleDataFilenameList(conform_time_win).isEmpty() ? QStringLiteral(u"无效") : QStringLiteral(u"有效"); analys_type = QVariant::fromValue(AnalysisType::CoincidenceEventTimeView); item_name = QStringLiteral(u"符合事件时间分析"); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrumView); item_name = QStringLiteral(u"符合能谱[%1ns]").arg(conform_time_win); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; analys_type = QVariant::fromValue(AnalysisType::AntiCoincidenceSpectrumView); item_name = QStringLiteral(u"反符合能谱[%1ns]").arg(conform_time_win); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrum2DView); item_name = QStringLiteral(u"二维符合能谱[%1ns]").arg(conform_time_win); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; analys_type = QVariant::fromValue(AnalysisType::CoincidenceParticleEnergySpectrum3DView); item_name = QStringLiteral(u"三维符合能谱[%1ns]").arg(conform_time_win); node_item = AddChildNode(interactive_analysis_item, item_name, status, analys_type, true); node_item->setData(project_name, ProjectName); node_map[item_name] = node_item; _project_node_items[project_name] = node_map; LOG_INFO(QStringLiteral(u"测量分析项目\"%1\"创建成功.").arg(project_name)); if (!cur_pro_model->GetIsMeasureComplete()) { if (cur_pro_model->GetMeasureDeviceParamsCfgFilename().isEmpty()) { LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"测量设备参数未配置!").arg(project_name)); } } if (cur_pro_model->GetEneryScaleFilename().isEmpty()) { LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"能量刻度未配置!").arg(project_name)); } if (cur_pro_model->GetEfficiencyScaleFilename().isEmpty()) { LOG_WARN(QStringLiteral(u"测量分析项目\"%1\"效率刻度未配置!").arg(project_name)); } }