From c2a933880c2e8c7adce7c548bab31da7f029f736 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 23 Feb 2024 17:07:41 +0100 Subject: [PATCH] Move meta data updates to summarycalculationcollection --- .../RimSummaryCalculation.cpp | 49 +------------------ .../RimSummaryCalculationCollection.cpp | 49 +++++++++++++++++++ .../RimSummaryCalculationCollection.h | 1 + .../RimUserDefinedCalculationCollection.cpp | 4 +- .../RimCalculatedSummaryCurveReader.cpp | 4 +- 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculation.cpp b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculation.cpp index 72a8fb0804d..c83a240de36 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculation.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculation.cpp @@ -27,26 +27,17 @@ #include "RifSummaryReaderInterface.h" #include "RimDataSourceSteppingTools.h" -#include "RimObservedDataCollection.h" -#include "RimObservedSummaryData.h" #include "RimProject.h" #include "RimSummaryAddress.h" #include "RimSummaryCalculationCollection.h" #include "RimSummaryCalculationVariable.h" #include "RimSummaryCase.h" -#include "RimSummaryCaseCollection.h" -#include "RimSummaryCaseMainCollection.h" #include "RimSummaryCurve.h" #include "RimSummaryMultiPlot.h" #include "RimSummaryMultiPlotCollection.h" #include "RimSummaryPlot.h" -#include "RiuExpressionContextMenuManager.h" - #include "cafPdmUiCheckBoxEditor.h" -#include "cafPdmUiLineEditor.h" -#include "cafPdmUiTableViewEditor.h" -#include "cafPdmUiTextEditor.h" #include "expressionparser/ExpressionParser.h" @@ -402,43 +393,6 @@ std::optional, std::vector>> //-------------------------------------------------------------------------------------------------- void RimSummaryCalculation::updateDependentObjects() { - auto calcColl = firstAncestorOrThisOfTypeAsserted(); - calcColl->rebuildCaseMetaData(); - - // Refresh data sources tree - // Refresh meta data for all summary cases and rebuild AddressNodes in the summary tree - RimSummaryCaseMainCollection* summaryCaseCollection = RiaSummaryTools::summaryCaseMainCollection(); - auto summaryCases = summaryCaseCollection->allSummaryCases(); - for ( RimSummaryCase* summaryCase : summaryCases ) - { - if ( !summaryCase ) continue; - - if ( auto reader = summaryCase->summaryReader() ) - { - reader->rebuildMetaData(); - summaryCase->onCalculationUpdated(); - } - } - - RimObservedDataCollection* observedDataCollection = RiaSummaryTools::observedDataCollection(); - auto observedData = observedDataCollection->allObservedSummaryData(); - for ( auto obs : observedData ) - { - if ( !obs ) continue; - - if ( auto reader = obs->summaryReader() ) - { - reader->rebuildMetaData(); - obs->onCalculationUpdated(); - } - } - - auto summaryCaseCollections = summaryCaseCollection->summaryCaseCollections(); - for ( RimSummaryCaseCollection* summaryCaseCollection : summaryCaseCollections ) - { - summaryCaseCollection->onCalculationUpdated(); - } - RimSummaryMultiPlotCollection* summaryPlotCollection = RiaSummaryTools::summaryMultiPlotCollection(); for ( auto multiPlot : summaryPlotCollection->multiPlots() ) { @@ -446,7 +400,7 @@ void RimSummaryCalculation::updateDependentObjects() { bool plotContainsCalculatedCurves = false; - for ( RimSummaryCurve* sumCurve : sumPlot->summaryCurves() ) + for ( RimSummaryCurve* sumCurve : sumPlot->summaryAndEnsembleCurves() ) { if ( sumCurve->summaryAddressY().isCalculated() ) { @@ -469,6 +423,7 @@ void RimSummaryCalculation::updateDependentObjects() //-------------------------------------------------------------------------------------------------- void RimSummaryCalculation::removeDependentObjects() { + updateDependentObjects(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp index e8e8cf5edae..3d8be32f7c6 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.cpp @@ -18,7 +18,15 @@ #include "RimSummaryCalculationCollection.h" +#include "RiaSummaryTools.h" + +#include "RifSummaryReaderInterface.h" + +#include "RimObservedSummaryData.h" #include "RimSummaryCalculation.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryCaseMainCollection.h" CAF_PDM_SOURCE_INIT( RimSummaryCalculationCollection, "RimSummaryCalculationCollection" ); //-------------------------------------------------------------------------------------------------- @@ -37,12 +45,53 @@ RimSummaryCalculation* RimSummaryCalculationCollection::createCalculation() cons return new RimSummaryCalculation; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryCalculationCollection::updateDataDependingOnCalculations() +{ + // Refresh data sources tree + // Refresh meta data for all summary cases and rebuild AddressNodes in the summary tree + RimSummaryCaseMainCollection* summaryCaseCollection = RiaSummaryTools::summaryCaseMainCollection(); + auto summaryCases = summaryCaseCollection->allSummaryCases(); + for ( RimSummaryCase* summaryCase : summaryCases ) + { + if ( !summaryCase ) continue; + + if ( auto reader = summaryCase->summaryReader() ) + { + reader->rebuildMetaData(); + summaryCase->onCalculationUpdated(); + } + } + + RimObservedDataCollection* observedDataCollection = RiaSummaryTools::observedDataCollection(); + auto observedData = observedDataCollection->allObservedSummaryData(); + for ( auto obs : observedData ) + { + if ( !obs ) continue; + + if ( auto reader = obs->summaryReader() ) + { + reader->rebuildMetaData(); + obs->onCalculationUpdated(); + } + } + + auto summaryCaseCollections = summaryCaseCollection->summaryCaseCollections(); + for ( RimSummaryCaseCollection* summaryCaseCollection : summaryCaseCollections ) + { + summaryCaseCollection->onCalculationUpdated(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimSummaryCalculationCollection::rebuildCaseMetaData() { ensureValidCalculationIds(); + updateDataDependingOnCalculations(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h index 8d7f21d06c9..e4953189baf 100644 --- a/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h +++ b/ApplicationLibCode/ProjectDataModel/RimSummaryCalculationCollection.h @@ -42,5 +42,6 @@ class RimSummaryCalculationCollection : public RimUserDefinedCalculationCollecti RimSummaryCalculation* createCalculation() const override; private: + void updateDataDependingOnCalculations(); void initAfterRead() override; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimUserDefinedCalculationCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimUserDefinedCalculationCollection.cpp index b30dcf0ec43..b8572c84b11 100644 --- a/ApplicationLibCode/ProjectDataModel/RimUserDefinedCalculationCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimUserDefinedCalculationCollection.cpp @@ -103,9 +103,11 @@ RimUserDefinedCalculation* RimUserDefinedCalculationCollection::addCalculationCo //-------------------------------------------------------------------------------------------------- void RimUserDefinedCalculationCollection::deleteCalculation( RimUserDefinedCalculation* calculation ) { - calculation->removeDependentObjects(); m_calculations.removeChild( calculation ); + // Call this function after the object is removed from the collection + calculation->removeDependentObjects(); + rebuildCaseMetaData(); delete calculation; diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimCalculatedSummaryCurveReader.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimCalculatedSummaryCurveReader.cpp index d1902a9553f..e0da1ecc653 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimCalculatedSummaryCurveReader.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimCalculatedSummaryCurveReader.cpp @@ -87,11 +87,11 @@ void RifCalculatedSummaryCurveReader::rebuildMetaData() for ( RimUserDefinedCalculation* calc : m_calculationCollection->calculations() ) { - RimSummaryCalculation* sumCalc = dynamic_cast( calc ); + auto* sumCalc = dynamic_cast( calc ); CAF_ASSERT( sumCalc ); const auto& allAddresses = sumCalc->allAddressesForSummaryCase( m_summaryCase ); - for ( auto calculationAddress : allAddresses ) + for ( const auto& calculationAddress : allAddresses ) { if ( calculationAddress.address().isValid() ) {