From 6f50201e3a44c4c7100dd9d13da032003e4194c8 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 30 Jul 2020 10:50:44 +0200 Subject: [PATCH] #6189 Add check box on ensemble level in summary vector dialog --- .../AnalysisPlots/RimAnalysisPlot.cpp | 1 - .../RiuSummaryVectorSelectionUi.cpp | 133 ++++++++++++++++-- .../RiuSummaryVectorSelectionUi.h | 4 + 3 files changed, 129 insertions(+), 9 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp b/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp index 2b73c296a5..aa83c7e0f8 100644 --- a/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp +++ b/ApplicationCode/ProjectDataModel/AnalysisPlots/RimAnalysisPlot.cpp @@ -415,7 +415,6 @@ void RimAnalysisPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField, dlg.enableMultiSelect( true ); dlg.enableIndividualEnsembleCaseSelection( true ); - dlg.setCurveSelection( this->curveDefinitionsWithoutEnsembleReference() ); if ( dlg.exec() == QDialog::Accepted ) diff --git a/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.cpp b/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.cpp index e7d5f84d8b..f1a6df1ad1 100644 --- a/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.cpp +++ b/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.cpp @@ -43,6 +43,8 @@ #include "cafPdmUiFieldHandle.h" #include "cafPdmUiTreeSelectionEditor.h" +#include + #include CAF_PDM_SOURCE_INIT( RiuSummaryVectorSelectionUi, "RicSummaryAddressSelection" ); @@ -644,6 +646,7 @@ void RiuSummaryVectorSelectionUi::setSelectedCurveDefinitions( const std::vector if ( summaryCase != calculatedSummaryCase() ) { m_selectedSources.push_back( summSource ); + handleAddedSource( summSource ); } } @@ -684,6 +687,8 @@ void RiuSummaryVectorSelectionUi::setSelectedCurveDefinitions( const std::vector RifEclipseSummaryAddress::SummaryVarCategory cat = *( categories.begin() ); m_currentSummaryCategory.setValue( cat ); } + + m_previouslySelectedSources = m_selectedSources.ptrReferencedObjects(); } //-------------------------------------------------------------------------------------------------- @@ -714,6 +719,35 @@ void RiuSummaryVectorSelectionUi::fieldChangedByUi( const caf::PdmFieldHandle* c const QVariant& oldValue, const QVariant& newValue ) { + if ( changedField == &m_selectedSources ) + { + caf::PdmObject* objectAdded = nullptr; + for ( caf::PdmObject* selectedObject : m_selectedSources() ) + { + auto it = std::find( m_previouslySelectedSources.begin(), m_previouslySelectedSources.end(), selectedObject ); + if ( it == m_previouslySelectedSources.end() ) + { + objectAdded = selectedObject; + handleAddedSource( objectAdded ); + break; + } + } + if ( !objectAdded ) + { + caf::PdmObject* objectRemoved = nullptr; + for ( caf::PdmObject* previouslySelectedObject : m_previouslySelectedSources ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), previouslySelectedObject ); + if ( it == m_selectedSources.end() ) + { + objectRemoved = previouslySelectedObject; + handleRemovedSource( objectRemoved ); + break; + } + } + } + m_previouslySelectedSources = m_selectedSources.ptrReferencedObjects(); + } if ( changedField != &m_selectedSources && changedField != &m_selectedSummaryCategories && changedField != &m_currentSummaryCategory ) { @@ -1262,6 +1296,7 @@ void RiuSummaryVectorSelectionUi::defineEditorAttribute( const caf::PdmFieldHand void RiuSummaryVectorSelectionUi::resetAllFields() { m_selectedSources.clear(); + m_previouslySelectedSources.clear(); m_selectedSummaryCategories = std::vector>(); // clear all state in fields @@ -1349,20 +1384,14 @@ void RiuSummaryVectorSelectionUi::appendOptionItemsForSources( QListname(), sumCaseColl ); optionItem.setLevel( 1 ); options.push_back( optionItem ); } - else + if ( m_showIndividualEnsembleCases ) { - caf::PdmOptionItemInfo ensembleOpt = - caf::PdmOptionItemInfo::createHeader( sumCaseColl->name(), true ); - ensembleOpt.setLevel( 1 ); - options.push_back( ensembleOpt ); - for ( const auto& sumCase : sumCaseColl->allSummaryCases() ) { auto optionItem = caf::PdmOptionItemInfo( sumCase->displayCaseName(), sumCase ); @@ -1577,3 +1606,91 @@ void RiuSummaryVectorSelectionUi::appendOptionItemsForSubCategoriesAndVectors( Q } } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuSummaryVectorSelectionUi::handleAddedSource( SummarySource* sourceAdded ) +{ + CAF_ASSERT( sourceAdded ); + auto caseCollection = dynamic_cast( sourceAdded ); + if ( caseCollection ) + { + // Select all children + for ( auto summaryCase : caseCollection->allSummaryCases() ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), summaryCase ); + if ( it == m_selectedSources.end() ) + { + m_selectedSources.push_back( summaryCase ); + } + } + } + else + { + auto summaryCase = dynamic_cast( sourceAdded ); + if ( summaryCase ) + { + auto caseCollection = summaryCase->ensemble(); + if ( caseCollection ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), caseCollection ); + if ( it == m_selectedSources.end() ) + { + // Check if all children have been selected. + bool allChildrenSelected = true; + for ( auto summaryChild : caseCollection->allSummaryCases() ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), summaryChild ); + if ( it == m_selectedSources.end() ) + { + allChildrenSelected = false; + break; + } + } + if ( allChildrenSelected ) // Add collection if all children have been selected + { + m_selectedSources.push_back( caseCollection ); + } + } + } + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuSummaryVectorSelectionUi::handleRemovedSource( SummarySource* sourceRemoved ) +{ + CAF_ASSERT( sourceRemoved ); + auto caseCollection = dynamic_cast( sourceRemoved ); + if ( caseCollection ) + { + // Select all children + for ( auto summaryCase : caseCollection->allSummaryCases() ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), summaryCase ); + if ( it != m_selectedSources.end() ) + { + m_selectedSources.removePtr( *it ); + } + } + } + else + { + auto summaryCase = dynamic_cast( sourceRemoved ); + if ( summaryCase ) + { + auto caseCollection = summaryCase->ensemble(); + if ( caseCollection ) + { + auto it = std::find( m_selectedSources.begin(), m_selectedSources.end(), caseCollection ); + if ( it != m_selectedSources.end() ) + { + m_selectedSources.removePtr( *it ); + } + } + } + } +} diff --git a/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.h b/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.h index 06d5b5a819..ab18be2bb6 100644 --- a/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.h +++ b/ApplicationCode/UserInterface/RiuSummaryVectorSelectionUi.h @@ -111,8 +111,12 @@ private: void appendOptionItemsForSubCategoriesAndVectors( QList& options, SummaryIdentifierAndField* identifierAndField ) const; + void handleAddedSource( SummarySource* sourceAdded ); + void handleRemovedSource( SummarySource* sourceRemoved ); + private: caf::PdmPtrArrayField m_selectedSources; + std::vector m_previouslySelectedSources; caf::PdmField>> m_selectedSummaryCategories; caf::PdmField> m_currentSummaryCategory;