#3109 Ensemble calculation. Display warning dialog when no cases from the two ensembles match

This commit is contained in:
Bjørn Erik Jensen 2018-06-28 08:34:14 +02:00
parent 33d8655c3a
commit dde88a010e
4 changed files with 54 additions and 4 deletions

View File

@ -29,12 +29,37 @@
#include "cafSelectionManagerTools.h"
#include <QAction>
#include <QMessageBox>
#include <memory>
CAF_CMD_SOURCE_INIT(RicNewDerivedEnsembleFeature, "RicNewDerivedEnsembleFeature");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewDerivedEnsembleFeature::showWarningDialog()
{
QMessageBox::warning(nullptr, "Ensemble Matching", "None of the cases in the ensembles match");
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewDerivedEnsembleFeature::showWarningDialogWithQuestion()
{
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle("Ensemble Matching");
msgBox.setText("None of the cases in the ensembles match");
msgBox.setInformativeText("Do you want to keep the derived ensemble?");
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
int ret = msgBox.exec();
return ret == QMessageBox::Yes;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -67,6 +92,14 @@ void RicNewDerivedEnsembleFeature::onActionTriggered(bool isChecked)
{
newEnsemble->setEnsemble2(ensembles[1]);
newEnsemble->updateDerivedEnsembleCases();
if (newEnsemble->allSummaryCases().empty())
{
if(!showWarningDialogWithQuestion())
{
mainColl->removeCaseCollection(newEnsemble);
}
}
}
}

View File

@ -31,6 +31,10 @@ class RicNewDerivedEnsembleFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
public:
static void showWarningDialog();
static bool showWarningDialogWithQuestion();
protected:
// Overrides
virtual bool isCommandEnabled();

View File

@ -19,6 +19,8 @@
#include "RiaApplication.h"
#include "RiaTimeHistoryCurveMerger.h"
#include "SummaryPlotCommands/RicNewDerivedEnsembleFeature.h"
#include "RimDerivedEnsembleCaseCollection.h"
#include "RimDerivedEnsembleCase.h"
#include "RimProject.h"
@ -66,7 +68,7 @@ RimDerivedEnsembleCaseCollection::RimDerivedEnsembleCaseCollection()
m_swapEnsemblesButton.uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::HIDDEN);
m_swapEnsemblesButton.xmlCapability()->disableIO();
CAF_PDM_InitField(&m_caseCount, "CaseCount", 0, "Number of Cases", "", "", "");
CAF_PDM_InitField(&m_caseCount, "CaseCount", QString(""), "Matching Cases", "", "", "");
m_caseCount.uiCapability()->setUiReadOnly(true);
// Do not show child cases
@ -207,7 +209,10 @@ QList<caf::PdmOptionItemInfo> RimDerivedEnsembleCaseCollection::calculateValueOp
}
else if (fieldNeedingOptions == &m_caseCount)
{
m_caseCount = (int)m_cases.size();
size_t caseCount1 = m_ensemble1 ? m_ensemble1->allSummaryCases().size() : 0;
size_t caseCount2 = m_ensemble2 ? m_ensemble2->allSummaryCases().size() : 0;
m_caseCount = QString("%1 / %2").arg((int)m_cases.size()).arg(std::max(caseCount1, caseCount2));
}
return options;
}
@ -236,16 +241,19 @@ void RimDerivedEnsembleCaseCollection::fieldChangedByUi(const caf::PdmFieldHandl
bool doUpdate = false;
bool doUpdateCases = false;
bool doClearAllData = false;
bool doShowDialog = false;
if (changedField == &m_ensemble1 || changedField == &m_ensemble2)
{
doUpdate = true;
doUpdateCases = true;
doShowDialog = true;
}
else if (changedField == &m_operator)
{
doUpdate = true;
doUpdateCases = true;
doShowDialog = false;
}
else if (changedField == &m_swapEnsemblesButton)
{
@ -256,17 +264,22 @@ void RimDerivedEnsembleCaseCollection::fieldChangedByUi(const caf::PdmFieldHandl
doUpdate = true;
doUpdateCases = true;
doShowDialog = false;
}
if (doUpdate)
{
updateAutoName();
//if (doClearAllData) clearAllData();
if (doUpdateCases)
{
updateDerivedEnsembleCases();
updateConnectedEditors();
if (doShowDialog && m_ensemble1 != nullptr && m_ensemble2 != nullptr && allSummaryCases().empty())
{
RicNewDerivedEnsembleFeature::showWarningDialog();
}
}
updateReferringCurveSets();

View File

@ -81,5 +81,5 @@ private:
caf::PdmPtrField<RimSummaryCaseCollection*> m_ensemble2;
caf::PdmField<caf::AppEnum<DerivedEnsembleOperator>> m_operator;
caf::PdmField<bool> m_swapEnsemblesButton;
caf::PdmField<int> m_caseCount;
caf::PdmField<QString> m_caseCount;
};