|
|
|
|
@ -32,6 +32,13 @@
|
|
|
|
|
#include "iGuiPlot.h"
|
|
|
|
|
#include "ZxPlot.h"
|
|
|
|
|
#include "ZxObjCurve.h"
|
|
|
|
|
#include "ZxSubAxisX.h"
|
|
|
|
|
#include "ZxSubAxisY.h"
|
|
|
|
|
#include "tCurvePlotView.h"
|
|
|
|
|
#include "iCurveDesc.h"
|
|
|
|
|
#include <QMenu>
|
|
|
|
|
#include <QHelpEvent>
|
|
|
|
|
#include <QToolTip>
|
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
#include <QAbstractScrollArea>
|
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
@ -175,13 +182,37 @@ bool validSamplingValue(const QString& name, double& value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
bool hasSensitivityError(const nmDataSensitive::RunResult& run)
|
|
|
|
|
{
|
|
|
|
|
// 统计只使用成功且误差有效的运行,与曲线显示勾选无关。
|
|
|
|
|
return run.m_bSucceeded && !run.m_bCancelled && qIsFinite(run.m_dPressureRmse) && run.m_dPressureRmse >= 0.0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString sensitivityRunParameters(const nmDataSensitive::BatchResult& results, const nmDataSensitive::RunResult& run)
|
|
|
|
|
{
|
|
|
|
|
// 表格和散点提示共用冻结参数的单位换算。
|
|
|
|
|
QStringList descriptions;
|
|
|
|
|
for(int i = 0; i < results.m_variables.size() && i < run.m_vecParameters.size(); ++i) {
|
|
|
|
|
const nmDataSensitive::VariableSampling& variable = results.m_variables[i];
|
|
|
|
|
if(!variable.m_enabled) continue;
|
|
|
|
|
double value = run.m_vecParameters[i];
|
|
|
|
|
const QString unit = variable.m_modelValue.getUnit();
|
|
|
|
|
convertSamplingValue(variable.m_varName, value, samplingBaseUnit(variable.m_varName), unit, value);
|
|
|
|
|
descriptions << variable.m_varName + " = " + formatSamplingValue(value, 3)
|
|
|
|
|
+ (unit.isEmpty() ? QString() : " " + unit);
|
|
|
|
|
}
|
|
|
|
|
return descriptions.join(" + ");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========= 已完成批次的连续结果列表 =========
|
|
|
|
|
class SensitivityResultsModel : public QAbstractTableModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SensitivityResultsModel(const QSharedPointer<nmDataSensitive::BatchResult>& results,
|
|
|
|
|
iGuiPlot* plot, QObject* parent)
|
|
|
|
|
: QAbstractTableModel(parent), m_results(results), m_plot(plot) {}
|
|
|
|
|
iGuiPlot* plot, QObject* parent, bool statistics = false)
|
|
|
|
|
: QAbstractTableModel(parent), m_results(results), m_plot(plot), m_statistics(statistics) {}
|
|
|
|
|
|
|
|
|
|
QList<ZxObjCurve*> runCurves(int row) const
|
|
|
|
|
{
|
|
|
|
|
@ -220,6 +251,8 @@ public:
|
|
|
|
|
{
|
|
|
|
|
// 表格仅保留显示选择、运行编号与冻结参数。
|
|
|
|
|
if(orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant();
|
|
|
|
|
if(m_statistics) return (QStringList() << "#" << nmWxSensitive::tr("Realization")
|
|
|
|
|
<< nmWxSensitive::tr("Goodness of fit [MPa]")).value(section);
|
|
|
|
|
const QStringList titles = QStringList() << nmWxSensitive::tr("Show") << "#"
|
|
|
|
|
<< nmWxSensitive::tr("Parameters");
|
|
|
|
|
return titles.value(section);
|
|
|
|
|
@ -230,6 +263,15 @@ public:
|
|
|
|
|
// 参数显示使用冻结配置中的单位和三位有效数字,不修改原始采样值。
|
|
|
|
|
if(!index.isValid() || index.row() >= rowCount()) return QVariant();
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(m_statistics) {
|
|
|
|
|
if(role == Qt::ToolTipRole && !run.m_sFailureReason.isEmpty()) return run.m_sFailureReason;
|
|
|
|
|
if(role != Qt::DisplayRole && role != Qt::ToolTipRole) return QVariant();
|
|
|
|
|
if(index.column() == 0) return QString::number(run.m_nRunIndex + 1);
|
|
|
|
|
if(index.column() == 1) return sensitivityRunParameters(*m_results, run);
|
|
|
|
|
return hasSensitivityError(run) ? QString::number(run.m_dPressureRmse, 'g', 6)
|
|
|
|
|
: run.m_bCancelled ? nmWxSensitive::tr("Cancelled")
|
|
|
|
|
: !run.m_bSucceeded ? nmWxSensitive::tr("Failed") : nmWxSensitive::tr("N/A");
|
|
|
|
|
}
|
|
|
|
|
if(role == Qt::CheckStateRole && index.column() == 0)
|
|
|
|
|
return run.m_bSucceeded && !run.m_bCancelled &&
|
|
|
|
|
m_pendingVisibility.value(index.row(), isRunVisible(index.row())) ? Qt::Checked : Qt::Unchecked;
|
|
|
|
|
@ -239,17 +281,7 @@ public:
|
|
|
|
|
if(role != Qt::DisplayRole && role != Qt::ToolTipRole) return QVariant();
|
|
|
|
|
if(index.column() == 1) return QString::number(run.m_nRunIndex + 1);
|
|
|
|
|
if(index.column() != 2) return QVariant();
|
|
|
|
|
QStringList descriptions;
|
|
|
|
|
for(int i = 0; i < m_results->m_variables.size() && i < run.m_vecParameters.size(); ++i) {
|
|
|
|
|
const nmDataSensitive::VariableSampling& variable = m_results->m_variables[i];
|
|
|
|
|
if(!variable.m_enabled) continue;
|
|
|
|
|
double value = run.m_vecParameters[i];
|
|
|
|
|
const QString unit = variable.m_modelValue.getUnit();
|
|
|
|
|
convertSamplingValue(variable.m_varName, value, samplingBaseUnit(variable.m_varName), unit, value);
|
|
|
|
|
descriptions << variable.m_varName + " = " + formatSamplingValue(value, 3)
|
|
|
|
|
+ (unit.isEmpty() ? QString() : " " + unit);
|
|
|
|
|
}
|
|
|
|
|
return descriptions.join(" + ");
|
|
|
|
|
return sensitivityRunParameters(*m_results, run);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const override
|
|
|
|
|
@ -258,7 +290,7 @@ public:
|
|
|
|
|
if(!index.isValid()) return Qt::NoItemFlags;
|
|
|
|
|
Qt::ItemFlags result = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(index.column() == 0 && run.m_bSucceeded && !run.m_bCancelled && !runCurves(index.row()).isEmpty())
|
|
|
|
|
if(!m_statistics && index.column() == 0 && run.m_bSucceeded && !run.m_bCancelled && !runCurves(index.row()).isEmpty())
|
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
@ -266,7 +298,7 @@ public:
|
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role) override
|
|
|
|
|
{
|
|
|
|
|
// 勾选只记在本窗口,点击 Apply 或 OK 后才改变所属图的显示。
|
|
|
|
|
if(!index.isValid() || index.column() != 0 || role != Qt::CheckStateRole) return false;
|
|
|
|
|
if(m_statistics || !index.isValid() || index.column() != 0 || role != Qt::CheckStateRole) return false;
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled || runCurves(index.row()).isEmpty()) return false;
|
|
|
|
|
const bool visible = value.toInt() == Qt::Checked;
|
|
|
|
|
@ -308,6 +340,7 @@ private:
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> m_results;
|
|
|
|
|
QMap<int, bool> m_pendingVisibility;
|
|
|
|
|
QPointer<iGuiPlot> m_plot;
|
|
|
|
|
bool m_statistics;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nmWxSensitivityShow::nmWxSensitivityShow(
|
|
|
|
|
@ -381,6 +414,304 @@ void nmWxSensitivityShow::onHideAll()
|
|
|
|
|
m_model->setAllVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmWxSensitivityHistogramOptions::nmWxSensitivityHistogramOptions(
|
|
|
|
|
const QSharedPointer<nmDataSensitive::BatchResult>& results, int bins, QWidget* parent)
|
|
|
|
|
: iDlgBase(parent)
|
|
|
|
|
{
|
|
|
|
|
// 复用运行表格的参数展示,普通 Monte-Carlo 的统计变量只有误差。
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
setObjectName("nmHistogramOptions");
|
|
|
|
|
setWindowTitle(tr("Histogram options"));
|
|
|
|
|
resize(720, 400);
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
|
QHBoxLayout* options = new QHBoxLayout;
|
|
|
|
|
options->addWidget(new QLabel(tr("Number of bins:"), this));
|
|
|
|
|
m_bins = new QSpinBox(this);
|
|
|
|
|
m_bins->setRange(1, 1000);
|
|
|
|
|
m_bins->setValue(bins);
|
|
|
|
|
options->addWidget(m_bins);
|
|
|
|
|
options->addStretch();
|
|
|
|
|
options->addWidget(new QLabel(tr("Variable:"), this));
|
|
|
|
|
QComboBox* variable = new QComboBox(this);
|
|
|
|
|
variable->addItem(tr("Goodness of fit"));
|
|
|
|
|
options->addWidget(variable);
|
|
|
|
|
layout->addLayout(options);
|
|
|
|
|
QTableView* table = new QTableView(this);
|
|
|
|
|
table->setStyleSheet("QTableView { background-color: white; }");
|
|
|
|
|
table->setModel(new SensitivityResultsModel(results, nullptr, table, true));
|
|
|
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
table->setWordWrap(false);
|
|
|
|
|
table->verticalHeader()->hide();
|
|
|
|
|
table->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(2, QHeaderView::ResizeToContents);
|
|
|
|
|
layout->addWidget(table);
|
|
|
|
|
QHBoxLayout* buttons = new QHBoxLayout;
|
|
|
|
|
buttons->addStretch();
|
|
|
|
|
QPushButton* apply = new QPushButton(tr("Apply"), this);
|
|
|
|
|
QPushButton* ok = new QPushButton(tr("OK"), this);
|
|
|
|
|
QPushButton* cancel = new QPushButton(tr("Cancel"), this);
|
|
|
|
|
buttons->addWidget(apply);
|
|
|
|
|
buttons->addWidget(ok);
|
|
|
|
|
buttons->addWidget(cancel);
|
|
|
|
|
layout->addLayout(buttons);
|
|
|
|
|
connect(apply, SIGNAL(clicked()), this, SLOT(onApply()));
|
|
|
|
|
connect(ok, SIGNAL(clicked()), this, SLOT(onAccept()));
|
|
|
|
|
connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityHistogramOptions::onApply()
|
|
|
|
|
{
|
|
|
|
|
// 只提交分箱数,取消不会撤销已经应用的设置。
|
|
|
|
|
emit binsChanged(m_bins->value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityHistogramOptions::onAccept()
|
|
|
|
|
{
|
|
|
|
|
// 与 Show 表格保持相同的确认行为。
|
|
|
|
|
onApply();
|
|
|
|
|
accept();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmWxSensitivityScatter::nmWxSensitivityScatter(
|
|
|
|
|
const QSharedPointer<nmDataSensitive::BatchResult>& results, double baseError, QWidget* parent)
|
|
|
|
|
: iDlgBase(parent), m_results(results), m_baseError(baseError),
|
|
|
|
|
m_defaultThreshold(0.0), m_draggingThreshold(false)
|
|
|
|
|
{
|
|
|
|
|
// 散点与基准均来自同一批次快照,不读取后来编辑的模型参数。
|
|
|
|
|
setObjectName("nmSensitivityScatterPlot");
|
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
setWindowTitle(tr("Scatter plot"));
|
|
|
|
|
resize(850, 550);
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setContentsMargins(8, 8, 8, 8);
|
|
|
|
|
QHBoxLayout* options = new QHBoxLayout;
|
|
|
|
|
options->addWidget(new QLabel(tr("X Axis:"), this));
|
|
|
|
|
m_parameter = new QComboBox(this);
|
|
|
|
|
for(int i = 0; i < results->m_variables.size(); ++i)
|
|
|
|
|
if(results->m_variables[i].m_enabled) m_parameter->addItem(results->m_variables[i].m_varName, i);
|
|
|
|
|
options->addWidget(m_parameter, 1);
|
|
|
|
|
options->addSpacing(20);
|
|
|
|
|
options->addWidget(new QLabel(tr("Y Axis:"), this));
|
|
|
|
|
QComboBox* ordinate = new QComboBox(this);
|
|
|
|
|
ordinate->addItem(tr("Goodness of fit"));
|
|
|
|
|
options->addWidget(ordinate, 1);
|
|
|
|
|
for(size_t i = 0; i < results->m_runs.size(); ++i)
|
|
|
|
|
if(hasSensitivityError(results->m_runs[i])) m_defaultThreshold = qMax(m_defaultThreshold, results->m_runs[i].m_dPressureRmse);
|
|
|
|
|
if(qIsFinite(baseError) && baseError >= 0.0) m_defaultThreshold = baseError;
|
|
|
|
|
m_threshold = m_defaultThreshold;
|
|
|
|
|
layout->addLayout(options);
|
|
|
|
|
m_plot = new iGuiPlot(true, this);
|
|
|
|
|
m_plot->initUI(tr("Sensitivity scatter plot"));
|
|
|
|
|
m_plot->setDropEnabled(false);
|
|
|
|
|
m_plot->setAxisY(tr("Goodness of fit"), "MPa");
|
|
|
|
|
m_plot->setAxisXYLog(false, 0);
|
|
|
|
|
m_plot->setAxisXYLog(false, 1);
|
|
|
|
|
m_plot->getAxisOf(2)->setVisible(false);
|
|
|
|
|
// 给纵轴标题与刻度留出间距。
|
|
|
|
|
m_plot->getAxisOf(1)->setSpan(20.0);
|
|
|
|
|
m_plot->m_pPlot->setBKColor(Qt::white);
|
|
|
|
|
m_plot->m_pPlot->setLegendVisible(false);
|
|
|
|
|
layout->addWidget(m_plot);
|
|
|
|
|
// 两项固定图例不使用框架的分组标题,覆盖在绘图区左上角。
|
|
|
|
|
m_legend = new QLabel(m_plot->m_pPlotView->viewport());
|
|
|
|
|
m_legend->setText("<table cellspacing='2'><tr><td>□</td><td>" + tr("sensitivity data")
|
|
|
|
|
+ "</td></tr><tr><td style='color:blue'>■</td><td>" + tr("reference") + "</td></tr></table>");
|
|
|
|
|
m_legend->setStyleSheet("QLabel { background: white; color: black; border: 1px solid #cccccc; }");
|
|
|
|
|
m_legend->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
|
m_legend->adjustSize();
|
|
|
|
|
m_plot->m_pPlotView->viewport()->installEventFilter(this);
|
|
|
|
|
connect(m_parameter, SIGNAL(currentIndexChanged(int)), this, SLOT(updateParameter()));
|
|
|
|
|
connect(m_plot->m_pPlotView, SIGNAL(sigAdjustContextMenu(QMenu*)), this, SLOT(adjustContextMenu(QMenu*)));
|
|
|
|
|
updateParameter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityScatter::updateParameter()
|
|
|
|
|
{
|
|
|
|
|
// 切换横轴时重建参数坐标,阈值在各参数之间共用。
|
|
|
|
|
m_points.clear();
|
|
|
|
|
m_runRows.clear();
|
|
|
|
|
if(m_parameter->currentIndex() < 0) {
|
|
|
|
|
m_plot->setToolTip(tr("No sampled parameters"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const int index = m_parameter->itemData(m_parameter->currentIndex()).toInt();
|
|
|
|
|
const nmDataSensitive::VariableSampling& variable = m_results->m_variables[index];
|
|
|
|
|
const QString unit = variable.m_modelValue.getUnit();
|
|
|
|
|
m_plot->setAxisX(variable.m_varName, unit);
|
|
|
|
|
double modelValue = variable.m_modelValue.getValue().toDouble();
|
|
|
|
|
const bool hasModel = convertSamplingValue(variable.m_varName, modelValue,
|
|
|
|
|
samplingBaseUnit(variable.m_varName), unit, modelValue) && m_baseError >= 0.0 && qIsFinite(m_baseError);
|
|
|
|
|
for(size_t i = 0; i < m_results->m_runs.size(); ++i) {
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[i];
|
|
|
|
|
if(!hasSensitivityError(run) || index >= run.m_vecParameters.size()) continue;
|
|
|
|
|
double value = run.m_vecParameters[index];
|
|
|
|
|
if(!convertSamplingValue(variable.m_varName, value, samplingBaseUnit(variable.m_varName), unit, value)) continue;
|
|
|
|
|
m_points.append(QPointF(value, run.m_dPressureRmse));
|
|
|
|
|
m_runRows.append(int(i));
|
|
|
|
|
}
|
|
|
|
|
QVector<iCurveDesc> curves;
|
|
|
|
|
for(int i = 0; i < 4; ++i) {
|
|
|
|
|
iCurveDesc curve;
|
|
|
|
|
curve.m_sCurveName = i == 0 ? tr("sensitivity data") : i == 1 ? tr("Below threshold")
|
|
|
|
|
: i == 2 ? tr("reference") : tr("Threshold");
|
|
|
|
|
curve.m_oCurveType = POT_CurveDiscrete;
|
|
|
|
|
curve.m_bLineVisible = false;
|
|
|
|
|
curve.m_bPointVisible = true;
|
|
|
|
|
curve.m_oDot = ZxDot(DTS_Square, i == 2 ? Qt::blue : Qt::black, 1.0, i != 0);
|
|
|
|
|
if(i < 2) for(int j = 0; j < m_points.size(); ++j) {
|
|
|
|
|
if(i == 1 && m_points[j].y() >= m_threshold) continue;
|
|
|
|
|
curve.m_vecX.append(m_points[j].x());
|
|
|
|
|
curve.m_vecY.append(m_points[j].y());
|
|
|
|
|
}
|
|
|
|
|
if(i == 2 && hasModel) {
|
|
|
|
|
curve.m_vecX.append(modelValue);
|
|
|
|
|
curve.m_vecY.append(m_baseError);
|
|
|
|
|
}
|
|
|
|
|
if(i == 3) {
|
|
|
|
|
curve.m_bLineVisible = true;
|
|
|
|
|
curve.m_bPointVisible = false;
|
|
|
|
|
curve.m_oPen = QPen(Qt::red, 0.35);
|
|
|
|
|
curve.m_vecX << 0.0 << 1.0;
|
|
|
|
|
curve.m_vecY << m_threshold << m_threshold;
|
|
|
|
|
}
|
|
|
|
|
curves.append(curve);
|
|
|
|
|
}
|
|
|
|
|
// 固定图层名称,参数切换不叠加上一参数的点,也不让旧阈值影响自动范围。
|
|
|
|
|
for(int i = m_plot->m_pPlot->getObjCount() - 1; i >= 0; --i)
|
|
|
|
|
if(qobject_cast<ZxObjCurve*>(m_plot->m_pPlot->getObjByIndex(i))) m_plot->m_pPlot->removeObjByIndex(i);
|
|
|
|
|
m_plot->clearUndoStack();
|
|
|
|
|
m_plot->setCurveData(curves);
|
|
|
|
|
m_plot->runUpdate();
|
|
|
|
|
m_plot->setReadOnly(true);
|
|
|
|
|
double left = hasModel ? modelValue : m_points.isEmpty() ? 0.0 : m_points.first().x();
|
|
|
|
|
double right = left, top = hasModel ? m_baseError : 0.0;
|
|
|
|
|
for(int i = 0; i < m_points.size(); ++i) {
|
|
|
|
|
left = qMin(left, m_points[i].x());
|
|
|
|
|
right = qMax(right, m_points[i].x());
|
|
|
|
|
top = qMax(top, m_points[i].y());
|
|
|
|
|
}
|
|
|
|
|
const double padding = qMax(1e-6, (right > left ? right - left : qMax(1.0, qAbs(left))) * 0.05);
|
|
|
|
|
left -= padding;
|
|
|
|
|
right += padding;
|
|
|
|
|
top = qMax(1e-6, qMax(top, m_threshold) * 1.1);
|
|
|
|
|
VecDouble ticksX, ticksY;
|
|
|
|
|
for(int i = 0; i <= 5; ++i) {
|
|
|
|
|
ticksX.append(left + i * (right - left) / 5.0);
|
|
|
|
|
ticksY.append(i * top / 5.0);
|
|
|
|
|
}
|
|
|
|
|
m_plot->setAxisScaleX(left, right, ticksX);
|
|
|
|
|
m_plot->setAxisScaleY(0.0, top, ticksY);
|
|
|
|
|
updateThreshold();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityScatter::updateThreshold()
|
|
|
|
|
{
|
|
|
|
|
// 阈值以下的点填黑,范围使用这些采样点的参数值,不包含蓝色基准点。
|
|
|
|
|
if(m_parameter->currentIndex() < 0) return;
|
|
|
|
|
QVector<QPointF> accepted;
|
|
|
|
|
double lower = 0.0, upper = 0.0;
|
|
|
|
|
for(int i = 0; i < m_points.size(); ++i) if(m_points[i].y() < m_threshold) {
|
|
|
|
|
if(accepted.isEmpty()) lower = upper = m_points[i].x();
|
|
|
|
|
lower = qMin(lower, m_points[i].x());
|
|
|
|
|
upper = qMax(upper, m_points[i].x());
|
|
|
|
|
accepted.append(m_points[i]);
|
|
|
|
|
}
|
|
|
|
|
const int index = m_parameter->itemData(m_parameter->currentIndex()).toInt();
|
|
|
|
|
const nmDataSensitive::VariableSampling& variable = m_results->m_variables[index];
|
|
|
|
|
m_plot->setToolTip(tr("Threshold: %1 MPa\n").arg(m_threshold, 0, 'g', 6)
|
|
|
|
|
+ tr("Below threshold: %1 / %2; %3 range: %4").arg(accepted.size()).arg(m_points.size())
|
|
|
|
|
.arg(variable.m_varName).arg(accepted.isEmpty() ? tr("N/A")
|
|
|
|
|
: QString::number(lower, 'g', 6) + " - " + QString::number(upper, 'g', 6) + " " + variable.m_modelValue.getUnit()));
|
|
|
|
|
if(m_threshold > m_plot->getAxisOf(1)->getRangeMax()) {
|
|
|
|
|
VecDouble ticks;
|
|
|
|
|
const double top = m_threshold * 1.1;
|
|
|
|
|
for(int i = 0; i <= 5; ++i) ticks.append(i * top / 5.0);
|
|
|
|
|
m_plot->setAxisScaleY(0.0, top, ticks);
|
|
|
|
|
}
|
|
|
|
|
QVector<QPointF> line;
|
|
|
|
|
line << QPointF(m_plot->getAxisOf(0)->getRangeMin(), m_threshold)
|
|
|
|
|
<< QPointF(m_plot->getAxisOf(0)->getRangeMax(), m_threshold);
|
|
|
|
|
QVector<iCurveDesc> curves = m_plot->getCurveData();
|
|
|
|
|
// 原位更新图元及导出数据,不触发框架重新缩放,拖动时坐标轴保持稳定。
|
|
|
|
|
for(int i = 0; i < curves.size(); ++i) {
|
|
|
|
|
const QString name = curves[i].m_sCurveName;
|
|
|
|
|
if(name != tr("Below threshold") && name != tr("Threshold")) continue;
|
|
|
|
|
const QVector<QPointF>& points = name == tr("Threshold") ? line : accepted;
|
|
|
|
|
curves[i].m_vecX.clear();
|
|
|
|
|
curves[i].m_vecY.clear();
|
|
|
|
|
for(int j = 0; j < points.size(); ++j) {
|
|
|
|
|
curves[i].m_vecX.append(points[j].x());
|
|
|
|
|
curves[i].m_vecY.append(points[j].y());
|
|
|
|
|
}
|
|
|
|
|
ZxObjCurve* curve = m_plot->getCurve(name);
|
|
|
|
|
if(curve) curve->setAllValues(points);
|
|
|
|
|
else if(!points.isEmpty()) {
|
|
|
|
|
curve = m_plot->appendSeriesD(curves[i].m_vecX, curves[i].m_vecY, name);
|
|
|
|
|
if(curve) curve->setCurvePty(curves[i].m_oPen, curves[i].m_oDot,
|
|
|
|
|
curves[i].m_bLineVisible, curves[i].m_bPointVisible);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
m_plot->setCurveData(curves);
|
|
|
|
|
// 基准点始终置顶,包括首次出现阈值以下的点时。
|
|
|
|
|
ZxObjCurve* reference = m_plot->getCurve(tr("reference"));
|
|
|
|
|
if(reference) m_plot->m_pPlot->bringToFront(reference);
|
|
|
|
|
m_plot->m_pPlot->update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityScatter::resetThreshold()
|
|
|
|
|
{
|
|
|
|
|
// 有基准误差时恢复至基准值,无实测数据时使用本批最大有效误差。
|
|
|
|
|
m_threshold = m_defaultThreshold;
|
|
|
|
|
updateThreshold();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitivityScatter::adjustContextMenu(QMenu* menu)
|
|
|
|
|
{
|
|
|
|
|
// 复用绘图右键菜单,保留框架的缩放、复制与导出入口。
|
|
|
|
|
menu->addAction(tr("Reset line"), this, SLOT(resetThreshold()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nmWxSensitivityScatter::eventFilter(QObject* object, QEvent* event)
|
|
|
|
|
{
|
|
|
|
|
if(object != m_plot->m_pPlotView->viewport()) return iDlgBase::eventFilter(object, event);
|
|
|
|
|
tCurvePlotView* view = m_plot->m_pPlotView;
|
|
|
|
|
ZxSubAxisBase* axisY = m_plot->getAxisOf(1);
|
|
|
|
|
// 位置跟随实际绘图区,窗口缩放后仍贴在坐标轴内侧。
|
|
|
|
|
if(event->type() == QEvent::Paint)
|
|
|
|
|
m_legend->move(view->mapFromScene(m_plot->m_pPlot->getInnerRectF().topLeft()).toPoint() + QPoint(8, 8));
|
|
|
|
|
// 只接管阈值线附近的左键拖动,其余缩放、右键及导出仍由框架处理。
|
|
|
|
|
if(event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonRelease) {
|
|
|
|
|
QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
|
|
|
|
|
const QPointF scene = view->mapToScene(QPointF(mouse->pos()));
|
|
|
|
|
const double lineY = view->mapFromScene(QPointF(scene.x(), axisY->getPosForValue(m_threshold))).y();
|
|
|
|
|
if(event->type() == QEvent::MouseButtonPress && mouse->button() == Qt::LeftButton &&
|
|
|
|
|
m_plot->m_pPlot->getInnerRectF().contains(scene) && qAbs(mouse->pos().y() - lineY) <= 6.0) m_draggingThreshold = true;
|
|
|
|
|
if(m_draggingThreshold) {
|
|
|
|
|
m_threshold = qBound(0.0, axisY->getValueForPos(scene.y()), axisY->getRangeMax());
|
|
|
|
|
updateThreshold();
|
|
|
|
|
if(event->type() == QEvent::MouseButtonRelease) m_draggingThreshold = false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(event->type() == QEvent::ToolTip) {
|
|
|
|
|
// 点提示显示对应运行的完整参数组合;不以排序后的点号代替运行编号。
|
|
|
|
|
QHelpEvent* help = static_cast<QHelpEvent*>(event);
|
|
|
|
|
for(int i = 0; i < m_points.size(); ++i) {
|
|
|
|
|
const QPointF position = view->mapFromScene(QPointF(m_plot->getAxisOf(0)->getPosForValue(m_points[i].x()), axisY->getPosForValue(m_points[i].y())));
|
|
|
|
|
if(qAbs(position.x() - help->pos().x()) > 6.0 || qAbs(position.y() - help->pos().y()) > 6.0) continue;
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[m_runRows[i]];
|
|
|
|
|
QToolTip::showText(help->globalPos(), tr("Run %1\n%2\nGoodness of fit: %3 MPa")
|
|
|
|
|
.arg(run.m_nRunIndex + 1).arg(sensitivityRunParameters(*m_results, run))
|
|
|
|
|
.arg(run.m_dPressureRmse, 0, 'g', 6), view->viewport());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
QToolTip::showText(help->globalPos(), m_plot->toolTip(), view->viewport());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return iDlgBase::eventFilter(object, event);
|
|
|
|
|
}
|
|
|
|
|
class SensitivityDistributionPlot : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|