|
|
|
|
@ -26,6 +26,8 @@
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QTableWidget>
|
|
|
|
|
#include <QTableView>
|
|
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QAbstractScrollArea>
|
|
|
|
|
#include <QScrollBar>
|
|
|
|
|
#include <QWheelEvent>
|
|
|
|
|
@ -168,6 +170,109 @@ bool validSamplingValue(const QString& name, double& value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ========= 已完成批次的连续结果列表 =========
|
|
|
|
|
class SensitivityResultsModel : public QAbstractTableModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit SensitivityResultsModel(QObject* parent) : QAbstractTableModel(parent) {}
|
|
|
|
|
|
|
|
|
|
void setResults(const QSharedPointer<nmDataSensitive::BatchResult>& results)
|
|
|
|
|
{
|
|
|
|
|
// 同一批次可能在其他结果列表中改变可见性,同步勾选而不重置滚动位置。
|
|
|
|
|
if(m_results == results) {
|
|
|
|
|
if(rowCount() > 0) emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_results = results;
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex& parent = QModelIndex()) const override
|
|
|
|
|
{
|
|
|
|
|
// QTableView 按需读取行,结果列表连续滚动,不一次性创建全部表格项。
|
|
|
|
|
return parent.isValid() || m_results.isNull() ? 0 : int(m_results->m_runs.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int columnCount(const QModelIndex& parent = QModelIndex()) const override
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
|
|
|
|
|
{
|
|
|
|
|
// 表格显示运行编号、冻结参数与实际计算状态。
|
|
|
|
|
if(orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant();
|
|
|
|
|
const QStringList titles = QStringList() << nmWxSensitive::tr("Show") << "#"
|
|
|
|
|
<< nmWxSensitive::tr("Parameters") << nmWxSensitive::tr("Status");
|
|
|
|
|
return titles.value(section);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override
|
|
|
|
|
{
|
|
|
|
|
// 参数显示使用冻结配置中的单位和三位有效数字,不修改原始采样值。
|
|
|
|
|
if(!index.isValid() || index.row() >= rowCount()) return QVariant();
|
|
|
|
|
const nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(role == Qt::CheckStateRole && index.column() == 0)
|
|
|
|
|
return run.m_bSucceeded && !run.m_bCancelled && run.m_bVisible ? Qt::Checked : Qt::Unchecked;
|
|
|
|
|
if(role == Qt::DecorationRole && index.column() == 0)
|
|
|
|
|
return QColor::fromHsv(int((run.m_nRunIndex % 360) * 137 % 360), 190, 190);
|
|
|
|
|
if(role == Qt::TextAlignmentRole && index.column() == 1)
|
|
|
|
|
return int(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
|
if(role == Qt::ToolTipRole && index.column() == 3) return run.m_sFailureReason;
|
|
|
|
|
if(role != Qt::DisplayRole && role != Qt::ToolTipRole) return QVariant();
|
|
|
|
|
if(index.column() == 1) return QString::number(run.m_nRunIndex + 1);
|
|
|
|
|
if(index.column() == 3) return run.m_bCancelled ? nmWxSensitive::tr("Stopped")
|
|
|
|
|
: run.m_bSucceeded ? nmWxSensitive::tr("Succeeded") : nmWxSensitive::tr("Failed");
|
|
|
|
|
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(" + ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const override
|
|
|
|
|
{
|
|
|
|
|
// 失败和取消组只能查看,不能勾选不存在的计算曲线。
|
|
|
|
|
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)
|
|
|
|
|
result |= Qt::ItemIsUserCheckable;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool setData(const QModelIndex& index, const QVariant& value, int role) override
|
|
|
|
|
{
|
|
|
|
|
// 可见性只在结果发布后的界面线程改变,不触发再次求解。
|
|
|
|
|
if(!index.isValid() || index.column() != 0 || role != Qt::CheckStateRole) return false;
|
|
|
|
|
nmDataSensitive::RunResult& run = m_results->m_runs[index.row()];
|
|
|
|
|
if(!run.m_bSucceeded || run.m_bCancelled) return false;
|
|
|
|
|
run.m_bVisible = value.toInt() == Qt::Checked;
|
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setAllVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
// 批量切换后只发送一次通知,整批曲线也只重新绘制一次。
|
|
|
|
|
if(m_results.isNull() || m_results->m_runs.empty()) return;
|
|
|
|
|
for(size_t i = 0; i < m_results->m_runs.size(); ++i)
|
|
|
|
|
m_results->m_runs[i].m_bVisible = visible;
|
|
|
|
|
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> m_results;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ========= 右对齐委托:保证显示和编辑时都是右对齐 =========
|
|
|
|
|
class RightAlignDelegate : public QStyledItemDelegate
|
|
|
|
|
{
|
|
|
|
|
@ -470,7 +575,7 @@ private:
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
nmWxSensitive::nmWxSensitive(QWidget *parent, nmDataAnalyzeManager* manager)
|
|
|
|
|
: iDlgBase(parent), m_selectedValueIndex(0), m_loading(true),
|
|
|
|
|
: iDlgBase(parent), m_refreshingResults(false), m_selectedValueIndex(0), m_loading(true),
|
|
|
|
|
m_pDataManager(manager ? manager : nmDataAnalyzeManager::getCurrentInstance()),
|
|
|
|
|
m_previewView(nullptr), m_pSensitivityTask(nullptr), m_calculationRunning(false)
|
|
|
|
|
{
|
|
|
|
|
@ -485,6 +590,10 @@ nmWxSensitive::nmWxSensitive(QWidget *parent, nmDataAnalyzeManager* manager)
|
|
|
|
|
loadDataToUI();
|
|
|
|
|
m_loading = false;
|
|
|
|
|
onTreeItemChanged(nullptr, 0);
|
|
|
|
|
// 已有批次可直接重新打开,结果发布后同步入口与列表。
|
|
|
|
|
if(m_pDataManager)
|
|
|
|
|
connect(m_pDataManager, SIGNAL(sigSensitiveResultsChanged()), this, SLOT(onResultsChanged()));
|
|
|
|
|
onResultsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nmWxSensitive::~nmWxSensitive()
|
|
|
|
|
@ -917,9 +1026,11 @@ void nmWxSensitive::setupUI()
|
|
|
|
|
bottomLayout->addWidget(previewButton);
|
|
|
|
|
bottomLayout->addStretch();
|
|
|
|
|
|
|
|
|
|
resultsButton = new QPushButton(tr("Results"), this);
|
|
|
|
|
generateButton = new QPushButton(tr("Generate"), this);
|
|
|
|
|
cancelButton = new QPushButton(tr("Cancel"), this);
|
|
|
|
|
|
|
|
|
|
bottomLayout->addWidget(resultsButton);
|
|
|
|
|
bottomLayout->addWidget(generateButton);
|
|
|
|
|
bottomLayout->addWidget(cancelButton);
|
|
|
|
|
|
|
|
|
|
@ -934,6 +1045,7 @@ void nmWxSensitive::createConnections()
|
|
|
|
|
connect(cancelButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(onCancelClicked()));
|
|
|
|
|
connect(previewButton, SIGNAL(clicked()), this, SLOT(onPreviewClicked()));
|
|
|
|
|
connect(resultsButton, SIGNAL(clicked()), this, SLOT(onResultsClicked()));
|
|
|
|
|
|
|
|
|
|
connect(calculationTypeCombo, SIGNAL(currentIndexChanged(int)),
|
|
|
|
|
this, SLOT(onCalculationTypeChanged(int)));
|
|
|
|
|
@ -1510,17 +1622,21 @@ void nmWxSensitive::onSensitivityFinished()
|
|
|
|
|
{
|
|
|
|
|
if(sender() != m_pSensitivityTask) return;
|
|
|
|
|
m_pSensitivityTask->wait();
|
|
|
|
|
// 线程结束后保留结果并恢复编辑,正常完成或停止不再弹出统计提示。
|
|
|
|
|
// 数据层接管曲线后释放计算任务及网格输入,结果窗口不依赖任务存活。
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> batch = m_pSensitivityTask->getSensitivityBatchResult();
|
|
|
|
|
delete m_pSensitivityTask;
|
|
|
|
|
m_pSensitivityTask = nullptr;
|
|
|
|
|
setCalculationRunning(false);
|
|
|
|
|
const std::vector<nmCalculationDllPebiSolverTask::SensitivityRunResult>& results =
|
|
|
|
|
m_pSensitivityTask->getSensitivityResults();
|
|
|
|
|
m_sensitiveData.setResults(batch);
|
|
|
|
|
m_pDataManager->publishSensitiveResults(m_sensitiveData);
|
|
|
|
|
const std::vector<nmDataSensitive::RunResult>& results = batch->m_runs;
|
|
|
|
|
QStringList errors;
|
|
|
|
|
for(size_t i = 0; i < results.size() && errors.size() < 5; ++i) {
|
|
|
|
|
const nmCalculationDllPebiSolverTask::SensitivityRunResult& result = results[i];
|
|
|
|
|
const nmDataSensitive::RunResult& result = results[i];
|
|
|
|
|
if(!result.m_bSucceeded && !result.m_bCancelled)
|
|
|
|
|
errors.append(tr("Run %1: %2").arg(result.m_nRunIndex + 1).arg(result.m_sFailureReason));
|
|
|
|
|
}
|
|
|
|
|
const QString fatalError = m_pSensitivityTask->getFailureReason();
|
|
|
|
|
const QString fatalError = batch->m_sFailureReason;
|
|
|
|
|
// 实际计算错误仍需提示原因,取消组不作为错误报告。
|
|
|
|
|
if(fatalError.isEmpty() && errors.isEmpty()) return;
|
|
|
|
|
QString message = fatalError;
|
|
|
|
|
@ -1532,6 +1648,93 @@ void nmWxSensitive::onSensitivityFinished()
|
|
|
|
|
QMessageBox::warning(ownerWindow, tr("Sensitivity"), message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onResultsClicked()
|
|
|
|
|
{
|
|
|
|
|
// 绘图窗口仍由主界面创建;本窗口只提供运行列表与显示选择。
|
|
|
|
|
onResultsChanged();
|
|
|
|
|
if(!resultsButton->isEnabled()) return;
|
|
|
|
|
emit sigSensitiveResultsRequested();
|
|
|
|
|
if(m_resultsDialog.isNull()) {
|
|
|
|
|
m_resultsDialog = new QDialog(this);
|
|
|
|
|
m_resultsDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
m_resultsDialog->setWindowTitle(tr("Sensitivity Results"));
|
|
|
|
|
m_resultsDialog->resize(700, 380);
|
|
|
|
|
QVBoxLayout* layout = new QVBoxLayout(m_resultsDialog.data());
|
|
|
|
|
QTableView* table = new QTableView(m_resultsDialog.data());
|
|
|
|
|
m_resultsModel = new SensitivityResultsModel(m_resultsDialog.data());
|
|
|
|
|
m_resultsModel->setResults(m_pDataManager->getSensitiveData()->getResults());
|
|
|
|
|
table->setModel(m_resultsModel.data());
|
|
|
|
|
table->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
table->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
table->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
table->setWordWrap(false);
|
|
|
|
|
table->verticalHeader()->setVisible(false);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(2, QHeaderView::Stretch);
|
|
|
|
|
table->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
|
|
|
|
|
layout->addWidget(table);
|
|
|
|
|
QHBoxLayout* buttons = new QHBoxLayout();
|
|
|
|
|
QPushButton* showAll = new QPushButton(tr("Show all"), m_resultsDialog.data());
|
|
|
|
|
QPushButton* hideAll = new QPushButton(tr("Hide all"), m_resultsDialog.data());
|
|
|
|
|
QPushButton* close = new QPushButton(tr("Close"), m_resultsDialog.data());
|
|
|
|
|
buttons->addWidget(showAll);
|
|
|
|
|
buttons->addWidget(hideAll);
|
|
|
|
|
buttons->addStretch();
|
|
|
|
|
buttons->addWidget(close);
|
|
|
|
|
layout->addLayout(buttons);
|
|
|
|
|
connect(m_resultsModel.data(), SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
|
|
|
|
this, SLOT(onResultsVisibilityChanged()));
|
|
|
|
|
connect(showAll, SIGNAL(clicked()), this, SLOT(onShowAllResults()));
|
|
|
|
|
connect(hideAll, SIGNAL(clicked()), this, SLOT(onHideAllResults()));
|
|
|
|
|
connect(close, SIGNAL(clicked()), m_resultsDialog.data(), SLOT(close()));
|
|
|
|
|
}
|
|
|
|
|
onResultsChanged();
|
|
|
|
|
hide();
|
|
|
|
|
m_resultsDialog->show();
|
|
|
|
|
m_resultsDialog->raise();
|
|
|
|
|
m_resultsDialog->activateWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onResultsChanged()
|
|
|
|
|
{
|
|
|
|
|
// 新结果替换旧批次时,已经打开的列表也切到同一份结果。
|
|
|
|
|
QSharedPointer<nmDataSensitive::BatchResult> results;
|
|
|
|
|
if(m_pDataManager && m_pDataManager->getSensitiveData())
|
|
|
|
|
results = m_pDataManager->getSensitiveData()->getResults();
|
|
|
|
|
resultsButton->setEnabled(!results.isNull());
|
|
|
|
|
m_sensitiveData.setResults(results);
|
|
|
|
|
// 同步其他列表的勾选只刷新显示,不能再次发布结果造成循环通知。
|
|
|
|
|
m_refreshingResults = true;
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setResults(results);
|
|
|
|
|
m_refreshingResults = false;
|
|
|
|
|
if(!m_resultsDialog.isNull()) {
|
|
|
|
|
const QString status = results.isNull() ? QString() : results->m_bStopped ? tr("Stopped")
|
|
|
|
|
: results->m_bCompleted ? tr("Completed") : tr("Failed");
|
|
|
|
|
m_resultsDialog->setWindowTitle(tr("Sensitivity Results")
|
|
|
|
|
+ (status.isEmpty() ? QString() : " - " + status));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onResultsVisibilityChanged()
|
|
|
|
|
{
|
|
|
|
|
// 结果选择与项目保存共用数据,通知主界面刷新图形而不重新计算。
|
|
|
|
|
if(m_pDataManager && !m_refreshingResults)
|
|
|
|
|
m_pDataManager->publishSensitiveResults(m_pDataManager->getSensitiveDataCopy());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onShowAllResults()
|
|
|
|
|
{
|
|
|
|
|
// 恢复所有成功组的叠加曲线。
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setAllVisible(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onHideAllResults()
|
|
|
|
|
{
|
|
|
|
|
// 隐藏所有计算组,保留测量曲线作为参考。
|
|
|
|
|
if(!m_resultsModel.isNull()) m_resultsModel->setAllVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void nmWxSensitive::onCalculationTypeChanged(int index)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(index);
|
|
|
|
|
|