添加粒子入射时间视图类文件
This commit is contained in:
parent
c558e12697
commit
a61e8d8263
140
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp
Normal file
140
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#include "ParticleInjectTimeAnalysis.h"
|
||||
#include "ui_ParticleInjectTimeAnalysis.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QwtPlotCurve>
|
||||
#include <QwtPlotMarker>
|
||||
#include <QwtPlotZoneItem>
|
||||
#include <QwtText>
|
||||
#include <cmath>
|
||||
#include <QtMath>
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QDebug>
|
||||
ParticleInjectTimeAnalysis::ParticleInjectTimeAnalysis(QWidget *parent) :
|
||||
MeasureAnalysisView(parent),
|
||||
ui(new Ui::ParticleInjectTimeAnalysis)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
InitUi();
|
||||
// 获取当前可执行文件的路径
|
||||
QString Path = QCoreApplication::applicationDirPath();
|
||||
m_AllData = getParticleInjectTimeData(Path + "/data.csv");
|
||||
setData(m_AllData);
|
||||
}
|
||||
|
||||
ParticleInjectTimeAnalysis::~ParticleInjectTimeAnalysis()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::InitViewWorkspace(const QString &project_name)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::setData(QVector<ParticleInjectTime> data)
|
||||
{
|
||||
int energyStart = ui->label_energyStart->text().toInt();
|
||||
int energyEnd = ui->label_energyEnd->text().toInt();
|
||||
|
||||
QVector<double> x;
|
||||
QVector<double> y;
|
||||
|
||||
double minValue = 0;
|
||||
double maxValue = 0;
|
||||
for(auto info : data)
|
||||
{
|
||||
if(info.dEnergy <= energyStart || info.dEnergy >= energyEnd)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x.append(info.index);
|
||||
y.append(info.dTime);
|
||||
minValue = qMin(minValue, info.dTime);
|
||||
maxValue = qMax(maxValue, info.dTime);
|
||||
}
|
||||
|
||||
// 创建曲线并设置数据
|
||||
QwtPlotCurve *curve = new QwtPlotCurve("正弦曲线");
|
||||
curve->setSamples(x, y);
|
||||
|
||||
// 将曲线添加到 CustomQwtPlot 中(会自动分配颜色)
|
||||
plot->AddCurve(curve);
|
||||
// 设置坐标轴范围和标题
|
||||
plot->setAxisScale(QwtPlot::xBottom, 0, x.last());
|
||||
plot->setAxisScale(QwtPlot::yLeft,minValue , maxValue);
|
||||
plot->setAxisTitle(QwtPlot::xBottom, "粒子序号");
|
||||
plot->setAxisTitle(QwtPlot::yLeft, "粒子时间");
|
||||
|
||||
// 刷新绘图
|
||||
plot->replot();
|
||||
|
||||
}
|
||||
|
||||
QVector<ParticleInjectTime> ParticleInjectTimeAnalysis::getParticleInjectTimeData(QString path)
|
||||
{
|
||||
QVector<ParticleInjectTime> records;
|
||||
QFile file(path);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qWarning() << "无法打开文件:" << file.errorString();
|
||||
return records;
|
||||
}
|
||||
QTextStream stream(&file);
|
||||
stream.setCodec("UTF-8");
|
||||
int lineNumber = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
QString line = stream.readLine().trimmed();
|
||||
lineNumber++;
|
||||
|
||||
// 跳过空行
|
||||
if (line.isEmpty())
|
||||
continue;
|
||||
|
||||
// 按逗号分割
|
||||
QStringList fields = line.split(',');
|
||||
|
||||
// 检查字段数量是否正确(应该为4)
|
||||
if (fields.size() != 4) {
|
||||
qWarning() << "行" << lineNumber << "字段数量不正确,跳过:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取板卡号通道号
|
||||
int bd = fields[0].toInt();
|
||||
int ch = fields[1].toInt();
|
||||
int detector = bd + ch * 8;
|
||||
if(detector >= 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
ParticleInjectTime rec;
|
||||
rec.index = lineNumber;
|
||||
rec.dEnergy = fields[2].toDouble(&ok);
|
||||
if (!ok) { qWarning() << "道址格式错误,行" << rec.dEnergy << lineNumber; continue; }
|
||||
rec.dTime = fields[3].toLongLong(&ok);
|
||||
|
||||
if (!ok) { qWarning() << "时间计数格式错误,行" << fields[3] << rec.dTime <<lineNumber; continue; }
|
||||
|
||||
records.append(rec);
|
||||
}
|
||||
|
||||
file.close();
|
||||
return records;
|
||||
}
|
||||
|
||||
void ParticleInjectTimeAnalysis::InitUi()
|
||||
{
|
||||
plot = new CustomQwtPlot();
|
||||
plot->SetXaxisDragScale(true);
|
||||
ui->verticalLayout->addWidget(plot);
|
||||
}
|
||||
48
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h
Normal file
48
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#ifndef PARTICLEINJECTTIMEANALYSIS_H
|
||||
#define PARTICLEINJECTTIMEANALYSIS_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qwt.h"
|
||||
#include "CustomQwtPlot.h"
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "MeasureAnalysisView.h"
|
||||
|
||||
typedef struct ParticleInjectTime
|
||||
{
|
||||
int bd;
|
||||
int ch;
|
||||
double dTime;
|
||||
int index;
|
||||
double dEnergy;
|
||||
} PARTICLEINJECTTIME;
|
||||
|
||||
namespace Ui {
|
||||
class ParticleInjectTimeAnalysis;
|
||||
}
|
||||
|
||||
class ParticleInjectTimeAnalysis : public MeasureAnalysisView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ParticleInjectTimeAnalysis(QWidget *parent = nullptr);
|
||||
virtual ~ParticleInjectTimeAnalysis();
|
||||
|
||||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
void setData(QVector<ParticleInjectTime> data);
|
||||
|
||||
//获取数据
|
||||
QVector<ParticleInjectTime> getParticleInjectTimeData(QString path);
|
||||
private:
|
||||
void InitUi();
|
||||
|
||||
private:
|
||||
Ui::ParticleInjectTimeAnalysis *ui;
|
||||
CustomQwtPlot *plot;
|
||||
QVector<ParticleInjectTime> m_AllData;//存储的所有的粒子入射时间数据
|
||||
};
|
||||
|
||||
#endif // PARTICLEINJECTTIMEANALYSIS_H
|
||||
151
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui
Normal file
151
src/ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ParticleInjectTimeAnalysis</class>
|
||||
<widget class="QWidget" name="ParticleInjectTimeAnalysis">
|
||||
<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" stretch="0,100">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<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">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<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"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
10
src/src.pro
10
src/src.pro
|
|
@ -32,9 +32,11 @@ UI_DIR = $${BUILD_UI}/$${TARGET}/ui
|
|||
|
||||
INCLUDEPATH += \
|
||||
$${PWD}/MeasureAnalysisParticleCountPlotView
|
||||
$${PWD}/ParticleInjectTimeView
|
||||
|
||||
DEPENDPATH += \
|
||||
$${PWD}/MeasureAnalysisParticleCountPlotView
|
||||
$${PWD}/ParticleInjectTimeView
|
||||
|
||||
SOURCES += \
|
||||
AboutDlg.cpp \
|
||||
|
|
@ -57,6 +59,7 @@ SOURCES += \
|
|||
VirtualTable/SampleDataSource.cpp \
|
||||
VirtualTable/VirtualTableModel.cpp \
|
||||
VirtualTable/VirtualTableView.cpp \
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysis.cpp\
|
||||
main.cpp
|
||||
|
||||
HEADERS += \
|
||||
|
|
@ -82,7 +85,8 @@ HEADERS += \
|
|||
VirtualTable/DataSource.h \
|
||||
VirtualTable/SampleDataSource.h \
|
||||
VirtualTable/VirtualTableModel.h \
|
||||
VirtualTable/VirtualTableView.h
|
||||
VirtualTable/VirtualTableView.h \
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysis.h
|
||||
|
||||
FORMS += \
|
||||
AboutDlg.ui \
|
||||
|
|
@ -91,5 +95,7 @@ FORMS += \
|
|||
MeasureAnalysisHistoryForm.ui \
|
||||
MeasureAnalysisParticleCountPlotView/BatchEnergyScaleDialog.ui \
|
||||
MeasureDeviceParamsCfgForm.ui \
|
||||
NewMeasureAnalysisDlg.ui
|
||||
NewMeasureAnalysisDlg.ui\
|
||||
ParticleInjectTimeView/ParticleInjectTimeAnalysis.ui
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user