diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.cpp index c1ad462415..ffa32e1e06 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.cpp @@ -29,12 +29,37 @@ #include "cafSelectionManagerTools.h" #include +#include #include 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); + } + } } } diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.h b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.h index 2633e24cef..847d091234 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.h @@ -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(); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.cpp b/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.cpp index 8b813d3813..0ca1e24e29 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.cpp @@ -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 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(); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.h b/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.h index 5913cd1d75..6e76f8c019 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimDerivedEnsembleCaseCollection.h @@ -81,5 +81,5 @@ private: caf::PdmPtrField m_ensemble2; caf::PdmField> m_operator; caf::PdmField m_swapEnsemblesButton; - caf::PdmField m_caseCount; + caf::PdmField m_caseCount; };