优化粒子入射时间数据加载及交互

This commit is contained in:
徐海 2026-03-30 13:37:14 +08:00
parent 829b22d74e
commit 4ba9703c4d
5 changed files with 134 additions and 325 deletions

View File

@ -9,6 +9,9 @@ BusyIndicator::BusyIndicator(QWidget* parent)
setAttribute(Qt::WA_TransparentForMouseEvents); setAttribute(Qt::WA_TransparentForMouseEvents);
QLabel* icon = new QLabel; QLabel* icon = new QLabel;
icon->resize(80, 80);
QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
icon->setSizePolicy(sizePolicy);
_busy_movie = new QMovie(":gif/BusyIndicator.gif"); // 转圈 GIF _busy_movie = new QMovie(":gif/BusyIndicator.gif"); // 转圈 GIF
icon->setMovie(_busy_movie); icon->setMovie(_busy_movie);
_busy_movie->start(); _busy_movie->start();

View File

@ -1,5 +1,4 @@
#include "ParticleInjectTimeAnalysisView.h" #include "ParticleInjectTimeAnalysisView.h"
#include "ui_ParticleInjectTimeAnalysisView.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QPushButton> #include <QPushButton>
#include <QMessageBox> #include <QMessageBox>
@ -12,22 +11,61 @@
#include <cmath> #include <cmath>
#include <QtMath> #include <QtMath>
#include "CustomQwtPlot.h" #include "CustomQwtPlot.h"
#include <QDebug>
#include <GlobalDefine.h> #include <GlobalDefine.h>
#include "csv.h"
#include <QFileInfo>
#include <QThread>
#include "BusyIndicator.h"
#include <QMenu>
#include <QAction>
ParticleInjectTimeAnalysisView::ParticleInjectTimeAnalysisView(QWidget *parent) : ParticleInjectTimeAnalysisView::ParticleInjectTimeAnalysisView(QWidget *parent) :
MeasureAnalysisView(parent), MeasureAnalysisView(parent)
ui(new Ui::ParticleInjectTimeAnalysisView)
{ {
this->setViewType(PlotFrame); this->setViewType(PlotFrame);
ui->setupUi(this);
InitUi();
_plot = new CustomQwtPlot();
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(_plot);
_plot->setCanvasBackground(Qt::white);
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
canvas->setFrameStyle(QFrame::NoFrame);
QFont font = this->font();
font.setBold(false);
QwtText particle_num_label = QStringLiteral(u"粒子序号");
particle_num_label.setFont(font);
QwtText time_label = QStringLiteral(u"粒子时间(ns)");
time_label.setFont(font);
_plot->setAxisTitle(QwtPlot::xBottom, particle_num_label);
_plot->setAxisTitle(QwtPlot::yLeft, time_label);
// set axis auto scale
_plot->setAxisAutoScale(QwtPlot::xBottom, true);
_plot->setAxisAutoScale(QwtPlot::yLeft, true);
// 启用网格线
_plot->enableAxis(QwtPlot::xBottom);
_plot->enableAxis(QwtPlot::yLeft);
_plot->SetAxisDragScale(QwtPlot::xBottom, true);
// // 设置QWT图例
// QwtLegend* legend = new QwtLegend();
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
// _plot->insertLegend(legend, QwtPlot::RightLegend);
_curve = new QwtPlotCurve();
_plot->AddCurve(_curve);
this->_menu = new QMenu(this);
setupMenu();
_busy_indicator = new BusyIndicator(this);
} }
ParticleInjectTimeAnalysisView::~ParticleInjectTimeAnalysisView() ParticleInjectTimeAnalysisView::~ParticleInjectTimeAnalysisView()
{ {
delete ui;
} }
void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_name) void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_name)
@ -37,153 +75,83 @@ void ParticleInjectTimeAnalysisView::InitViewWorkspace(const QString &project_na
void ParticleInjectTimeAnalysisView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set) void ParticleInjectTimeAnalysisView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
{ {
int energyStart = ui->label_energyStart->text().toInt(); const QString& data_filename = data_files_set.first().toString();
int energyEnd = ui->label_energyEnd->text().toInt(); if ( !data_filename.isEmpty() ) {
if(!data_files_set.isEmpty()) if (QFileInfo(data_filename).exists()) {
{ this->_data_filename = data_filename;
io::CSVReader<4> in(QStrToSysPath(data_files_set.first().toString())); this->updateData(true);
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数"); }
}
}
int board, channel; void ParticleInjectTimeAnalysisView::setupMenu()
double energy, time_count; {
int lineNumber = 0; this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &ParticleInjectTimeAnalysisView::customContextMenuRequested, [this](const QPoint& pos) {
this->_menu->exec(this->mapToGlobal(pos));
});
QAction* action_plot_reset = this->_menu->addAction(QStringLiteral(u"还原"));
action_plot_reset->setObjectName("plot_reset");
connect(action_plot_reset, &QAction::triggered, [this]() {
this->_plot->ResetPlot();
});
this->_menu->addSeparator();
this->_menu->addSeparator();
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
action_plot_config->setObjectName("plot_config");
connect(action_plot_config, &QAction::triggered, this, &ParticleInjectTimeAnalysisView::onActionPlotConfigure);
}
void ParticleInjectTimeAnalysisView::updateData(bool b_init_update)
{
auto functionToRun = [this, b_init_update](){
if(!_data_filename.isEmpty()) {
_busy_indicator->Start();
std::string board_id_str = QString(QStringLiteral(u"板卡号")).toStdString();
std::string channel_id_str = QString(QStringLiteral(u"通道号")).toStdString();
std::string energy_str = QString(QStringLiteral(u"能量(KeV)")).toStdString();
std::string time_str = QString(QStringLiteral(u"时间计数")).toStdString();
io::CSVReader<4> in(QStrToSysPath(_data_filename));
in.read_header(io::ignore_extra_column, board_id_str, channel_id_str, energy_str, time_str);
int particle_num = 0;
QVector<double> x; QVector<double> x;
QVector<double> y; QVector<double> y;
double minValue = 0;
double maxValue = 0; int board, channel;
// 逐行读取 double energy;
while (in.read_row(board, channel, energy, time_count)) unsigned long long time_count;
{ while (in.read_row(board, channel, energy, time_count)) {
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count; if ( !b_init_update && (energy <= _begin_enery || energy >= _end_energy)) {
int detector = board + channel * 8;
lineNumber++;
if(detector > 32)
{
continue; continue;
} }
if(energy <= energyStart || energy >= energyEnd) particle_num++;
{ x.append(particle_num);
continue;
}
x.append(lineNumber);
y.append(time_count); y.append(time_count);
minValue = qMin(minValue, time_count);
maxValue = qMax(maxValue, time_count);
} }
// 创建曲线并设置数据 _curve->setSamples(x, y);
QwtPlotCurve *curve = new QwtPlotCurve(); _plot->replot();
curve->setSamples(x, y); LOG_INFO(QStringLiteral(u"%1数据更新完毕.").arg(this->GetViewName()));
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色) _busy_indicator->Stop();
plot->AddCurve(curve);
// 设置坐标轴范围和标题
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
// 刷新绘图
plot->replot();
// m_AllData = getParticleInjectTimeData(data_files_set.first().toString());
// setData(m_AllData);
} }
};
QThread* load_data_thread = QThread::create(functionToRun);
load_data_thread->start();
} }
void ParticleInjectTimeAnalysisView::setData(QVector<ParticleInjectTime *> data) void ParticleInjectTimeAnalysisView::onActionPlotConfigure()
{ {
int energyStart = ui->label_energyStart->text().toInt();
int energyEnd = ui->label_energyEnd->text().toInt();
QVector<double> x; }
QVector<double> y;
double minValue = 0; void ParticleInjectTimeAnalysisView::showEvent(QShowEvent *e)
double maxValue = 0;
for(auto info : data)
{ {
if(info->dEnergy <= energyStart || info->dEnergy >= energyEnd) Q_UNUSED(e);
{ if (_busy_indicator) {
continue; _busy_indicator->setGeometry(this->rect());
this->update();
} }
x.append(info->index);
y.append(info->dTime);
minValue = qMin(minValue, info->dTime);
maxValue = qMax(maxValue, info->dTime);
} }
// 创建曲线并设置数据
QwtPlotCurve *curve = new QwtPlotCurve();
// curve->setRawSamples(x.data(),y.data(),x.size());
curve->setSamples(x, y);
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
plot->AddCurve(curve);
// 设置坐标轴范围和标题
// plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
// plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
LOG_INFO(QStringLiteral(u"%1数据读取完毕.").arg(this->GetViewName()));
// 刷新绘图
plot->replot();
}
QVector<ParticleInjectTime *> ParticleInjectTimeAnalysisView::getParticleInjectTimeData(QString path)
{
QVector<ParticleInjectTime *> records;
io::CSVReader<4> in(QStrToSysPath(path));
in.read_header(io::ignore_extra_column, "板卡号", "通道号", "能量(KeV)", "时间计数");
int board, channel;
double energy, time_count;
int lineNumber = 0;
// 逐行读取
while (in.read_row(board, channel, energy, time_count))
{
// qDebug()<<QStringLiteral(u"板卡号:")<<board<<QStringLiteral(u"通道号")<<channel<<QStringLiteral(u"能量(KeV)")<<energy<<QStringLiteral(u"时间计数")<<time_count;
int detector = board + channel * 8;
lineNumber++;
if(detector > 32)
{
continue;
}
ParticleInjectTime *rec = new ParticleInjectTime;
rec->index = lineNumber;
rec->dEnergy = energy;
rec->dTime = time_count;
records.append(rec);
}
return records;
}
void ParticleInjectTimeAnalysisView::InitUi()
{
plot = new CustomQwtPlot();
setupPlot();
ui->verticalLayout_2->addWidget(plot);
}
void ParticleInjectTimeAnalysisView::setupPlot()
{
plot->setCanvasBackground(Qt::white);
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(plot->canvas());
canvas->setFrameStyle(QFrame::NoFrame);
plot->setAxisTitle(QwtPlot::xBottom, QStringLiteral(u"粒子序号"));
plot->setAxisTitle(QwtPlot::yLeft, QStringLiteral(u"粒子时间"));
// set axis auto scale
plot->setAxisAutoScale(QwtPlot::xBottom, true);
plot->setAxisAutoScale(QwtPlot::yLeft, true);
// 启用网格线
plot->enableAxis(QwtPlot::xBottom);
plot->enableAxis(QwtPlot::yLeft);
// // 设置QWT图例
// QwtLegend* legend = new QwtLegend();
// legend->setDefaultItemMode(QwtLegendData::ReadOnly);
// plot->insertLegend(legend, QwtPlot::RightLegend);
plot->SetAxisDragScale(QwtPlot::xBottom, true);
}

View File

@ -1,43 +1,39 @@
#ifndef PARTICLEINJECTTIMEANALYSISVIEW_H #ifndef PARTICLEINJECTTIMEANALYSISVIEW_H
#define PARTICLEINJECTTIMEANALYSISVIEW_H #define PARTICLEINJECTTIMEANALYSISVIEW_H
#include <QWidget>
#include "qwt.h"
#include "CustomQwtPlot.h"
#include <QFile>
#include <QTextStream>
#include "MeasureAnalysisView.h" #include "MeasureAnalysisView.h"
#include "csv.h"
class CustomQwtPlot;
class QwtPlotCurve;
namespace Ui { class BusyIndicator;
class ParticleInjectTimeAnalysisView; class QMenu;
}
class ParticleInjectTimeAnalysisView : public MeasureAnalysisView class ParticleInjectTimeAnalysisView : public MeasureAnalysisView
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ParticleInjectTimeAnalysisView(QWidget *parent = nullptr); explicit ParticleInjectTimeAnalysisView(QWidget *parent = nullptr);
virtual ~ParticleInjectTimeAnalysisView(); virtual ~ParticleInjectTimeAnalysisView();
virtual void InitViewWorkspace(const QString& project_name) override final; virtual void InitViewWorkspace(const QString& project_name) override final;
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set); virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
void setData(QVector<ParticleInjectTime *> data);
//获取数据
QVector<ParticleInjectTime *> getParticleInjectTimeData(QString path);
private: private:
void InitUi(); void setupMenu();
void setupPlot(); void updateData(bool b_init_update);
private slots:
void onActionPlotConfigure();
protected:
virtual void showEvent(QShowEvent* e) override final;
private: private:
Ui::ParticleInjectTimeAnalysisView *ui; BusyIndicator* _busy_indicator = nullptr;
CustomQwtPlot *plot; CustomQwtPlot *_plot = nullptr;
QVector<ParticleInjectTime *> m_AllData;//存储的所有的粒子入射时间数据 QwtPlotCurve *_curve = nullptr;
QMenu* _menu = nullptr;
double _begin_enery = 0.0f;
double _end_energy = 0.0f;
QString _data_filename;
}; };
#endif // PARTICLEINJECTTIMEANALYSIS_H #endif // PARTICLEINJECTTIMEANALYSIS_H

View File

@ -1,157 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticleInjectTimeAnalysisView</class>
<widget class="QWidget" name="ParticleInjectTimeAnalysisView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>997</width>
<height>307</height>
</rect>
</property>
<property name="windowTitle">
<string>ParticleInjectTimeAnalysis</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>粒子入射设置</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>起始能量:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_energyStart">
<property name="text">
<string>50</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>KeV</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>~</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>终止能量:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_energyEnd">
<property name="text">
<string>100</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>KeV</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>感兴趣区域(ROI)选择</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

View File

@ -149,7 +149,6 @@ FORMS += \
ParticleCountPlotView/BatchEnergyScaleDialog.ui \ ParticleCountPlotView/BatchEnergyScaleDialog.ui \
MeasureDeviceParamsCfgForm.ui \ MeasureDeviceParamsCfgForm.ui \
NewMeasureAnalysisDlg.ui \ NewMeasureAnalysisDlg.ui \
ParticleInjectTimeView/ParticleInjectTimeAnalysisView.ui\
ThreeDimensionalConformityAnalysisView/DetectorStatusSummary.ui \ ThreeDimensionalConformityAnalysisView/DetectorStatusSummary.ui \
ThreeDimensionalConformityAnalysisView/ParticleDataStatistics.ui \ ThreeDimensionalConformityAnalysisView/ParticleDataStatistics.ui \
ThreeDimensionalConformityAnalysisView/ThreeDDisplay.ui \ ThreeDimensionalConformityAnalysisView/ThreeDDisplay.ui \