Compare commits
No commits in common. "5e4d8f943ffccf01716cd12946ee4641cd3a6aae" and "f8f553ccd58c76c6af0207bbdf60090664994c5d" have entirely different histories.
5e4d8f943f
...
f8f553ccd5
|
|
@ -1,156 +0,0 @@
|
|||
#include "ParticleTimeDifferenceView.h"
|
||||
#include "CustomQwtPlot.h"
|
||||
#include "csv.h"
|
||||
#include <GlobalDefine.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QMenu>
|
||||
#include <QwtLegend>
|
||||
#include <QwtPlotCanvas>
|
||||
#include <QwtScaleMap>
|
||||
#include <QwtText>
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QCheckBox>
|
||||
#include <QwtScaleDiv>
|
||||
#include <QFileInfo>
|
||||
#include <QwtPlotHistogram>
|
||||
#include <QwtIntervalSample>
|
||||
#include <QwtLogScaleEngine>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
ParticleTimeDifferenceView::ParticleTimeDifferenceView(QWidget *parent)
|
||||
: MeasureAnalysisView { parent }
|
||||
{
|
||||
this->setViewType(PlotFrame);
|
||||
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
this->_plot = new CustomQwtPlot(this);
|
||||
layout->addWidget(this->_plot);
|
||||
setupPlot();
|
||||
this->_menu = new QMenu(this);
|
||||
setupMenu();
|
||||
}
|
||||
|
||||
ParticleTimeDifferenceView::~ParticleTimeDifferenceView()
|
||||
{
|
||||
LOG_DEBUG(QStringLiteral(u"%1析构.").arg(this->GetViewName()));
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::InitViewWorkspace(const QString &project_name)
|
||||
{
|
||||
Q_UNUSED(project_name);
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::SetAnalyzeDataFilename(const QMap<QString, QVariant> &data_files_set)
|
||||
{
|
||||
if ( !data_files_set.isEmpty() ) {
|
||||
const QString& data_name = data_files_set.firstKey();
|
||||
const QString& data_filename = data_files_set.first().toString();
|
||||
if (QFileInfo(data_filename).exists()) {
|
||||
loadDataFromFile(data_name, data_filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::setupPlot()
|
||||
{
|
||||
_plot->setCanvasBackground(Qt::white);
|
||||
QwtPlotCanvas* canvas = qobject_cast<QwtPlotCanvas*>(_plot->canvas());
|
||||
canvas->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
QFont font = this->font();
|
||||
font.setBold(false);
|
||||
QwtText energy_label = QStringLiteral(u"时间(ns)");
|
||||
energy_label.setFont(font);
|
||||
QwtText count_label = QStringLiteral(u"计数");
|
||||
count_label.setFont(font);
|
||||
_plot->setAxisTitle(QwtPlot::xBottom, energy_label);
|
||||
_plot->setAxisTitle(QwtPlot::yLeft, count_label);
|
||||
|
||||
// set axis auto scale
|
||||
_plot->setAxisAutoScale(QwtPlot::xBottom, true);
|
||||
_plot->setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
|
||||
_plot->enableAxis(QwtPlot::xBottom);
|
||||
_plot->enableAxis(QwtPlot::yLeft);
|
||||
|
||||
_plot->SetXaxisDragScale(true);
|
||||
_data_selector = new CustomQwtPlotXaxisSelector(_plot->canvas());
|
||||
_data_selector->setEnabled(false);
|
||||
|
||||
_histogram = new QwtPlotHistogram("粒子时间差分布");
|
||||
_histogram->setStyle(QwtPlotHistogram::Columns);
|
||||
_histogram->attach(_plot);
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::setupMenu()
|
||||
{
|
||||
this->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, &ParticleTimeDifferenceView::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();
|
||||
QAction* action_plot_config = this->_menu->addAction(QStringLiteral(u"图表配置"));
|
||||
action_plot_config->setObjectName("plot_config");
|
||||
connect(action_plot_config, &QAction::triggered, this, &ParticleTimeDifferenceView::onActionPlotConfigure);
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::loadDataFromFile(const QString &data_name, const QString &filename)
|
||||
{
|
||||
try {
|
||||
std::string board_id_str = QString(QStringLiteral(u"板卡号")).toStdString();
|
||||
std::string channel_id_str = QString(QStringLiteral(u"通道号")).toStdString();
|
||||
std::string address_str = QString(QStringLiteral(u"道址")).toStdString();
|
||||
std::string time_str = QString(QStringLiteral(u"时间计数")).toStdString();
|
||||
|
||||
io::CSVReader<
|
||||
4,
|
||||
io::trim_chars<' ', '\t'>,
|
||||
io::double_quote_escape<',', '"'>,
|
||||
io::throw_on_overflow,
|
||||
io::empty_line_comment>
|
||||
reader(QStrToSysPath(filename));
|
||||
reader.read_header(io::ignore_extra_column, board_id_str, channel_id_str, address_str, time_str);
|
||||
|
||||
QMap<double, unsigned long long> hist_map;
|
||||
uint board_id, channel_id, address;
|
||||
unsigned long long time1 = 0, time2;
|
||||
while (reader.read_row(board_id, channel_id, address, time2)) {
|
||||
if (time1 == 0) {
|
||||
time1 = time2;
|
||||
continue;
|
||||
}
|
||||
unsigned long long d_time = time2 - time1;
|
||||
double bin = floor(d_time / _bin_width) * _bin_width;
|
||||
hist_map[bin]++;
|
||||
time1 = time2;
|
||||
}
|
||||
unsigned long long max_count = 1;
|
||||
QVector<QwtIntervalSample> samples;
|
||||
for (const double& bin : hist_map.keys()) {
|
||||
const unsigned long long& count = hist_map.value(bin);
|
||||
samples.append(QwtIntervalSample(count, bin, bin + _bin_width));
|
||||
if ( max_count < count ) {
|
||||
max_count = count;
|
||||
}
|
||||
}
|
||||
_histogram->setData(new QwtIntervalSeriesData(samples));
|
||||
_plot->replot();
|
||||
const QString& info = QStringLiteral(u"能谱数据处理完成.");
|
||||
LOG_INFO(info);
|
||||
} catch (const std::exception& e) {
|
||||
const QString& e_what = QString::fromStdString(e.what());
|
||||
LOG_WARN(QStringLiteral(u"能谱数据异常:%1").arg(e_what));
|
||||
}
|
||||
}
|
||||
|
||||
void ParticleTimeDifferenceView::onActionPlotConfigure()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef PARTICLETIMEDIFFERENCEVIEW_H
|
||||
#define PARTICLETIMEDIFFERENCEVIEW_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <MeasureAnalysisView.h>
|
||||
|
||||
class QMenu;
|
||||
class CustomQwtPlot;
|
||||
class CustomQwtPlotXaxisSelector;
|
||||
class QwtPlotHistogram;
|
||||
|
||||
class ParticleTimeDifferenceView : public MeasureAnalysisView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ParticleTimeDifferenceView(QWidget *parent = nullptr);
|
||||
virtual ~ParticleTimeDifferenceView();
|
||||
|
||||
virtual void InitViewWorkspace(const QString& project_name) override final;
|
||||
virtual void SetAnalyzeDataFilename(const QMap<QString, QVariant>& data_files_set);
|
||||
|
||||
private:
|
||||
void setupPlot();
|
||||
void setupMenu();
|
||||
void loadDataFromFile(const QString &data_name, const QString& filename);
|
||||
|
||||
private slots:
|
||||
void onActionPlotConfigure();
|
||||
|
||||
private:
|
||||
CustomQwtPlot* _plot = nullptr;
|
||||
QMenu* _menu = nullptr;
|
||||
QDialog* _curve_show_setting_dlg = nullptr;
|
||||
CustomQwtPlotXaxisSelector* _data_selector = nullptr;
|
||||
double _bin_width = 50.0f;
|
||||
QwtPlotHistogram* _histogram = nullptr;
|
||||
};
|
||||
|
||||
#endif // PARTICLETIMEDIFFERENCEVIEW_H
|
||||
Loading…
Reference in New Issue
Block a user