From 0cf7a1f4bcb5c6539992f37c9cb1148d285193d9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 18 Mar 2025 08:57:19 +0100 Subject: [PATCH] Fix performance issue for replace ensemble Make sure that update of connected ensemble curve sets and plots happens only once. wip --- .../RicReplaceSummaryEnsembleFeature.cpp | 19 +++-------- .../Summary/RimSummaryEnsemble.cpp | 33 +++++++++++++++++++ .../Summary/RimSummaryEnsemble.h | 6 ++-- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp index 01c780ae7a..8056e35268 100644 --- a/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp +++ b/ApplicationLibCode/Commands/SummaryPlotCommands/RicReplaceSummaryEnsembleFeature.cpp @@ -18,6 +18,7 @@ #include "RicReplaceSummaryEnsembleFeature.h" +#include "RiaLogging.h" #include "Summary/RiaSummaryTools.h" #include "RicImportSummaryCasesFeature.h" @@ -60,20 +61,13 @@ void RicReplaceSummaryEnsembleFeature::onActionTriggered( bool isChecked ) RicImportSummaryCasesFeature::CreateConfig createConfig{ .fileType = fileType, .ensembleOrGroup = false, .allowDialogs = false }; auto [isOk, newCases] = RicImportSummaryCasesFeature::createSummaryCasesFromFiles( fileNames, createConfig ); - if ( !isOk ) return; - - // Remove cases first, delegate delete to a separate thread - auto casesToBeDeleted = summaryEnsemble->allSummaryCases(); - for ( auto summaryCase : casesToBeDeleted ) + if ( !isOk || newCases.empty() ) { - summaryEnsemble->removeCase( summaryCase ); + RiaLogging::warning( "No new cases are created." ); + return; } - // Add the summary case - for ( auto summaryCase : newCases ) - { - summaryEnsemble->addCase( summaryCase ); - } + summaryEnsemble->replaceCases( newCases ); // Update name of cases and ensemble after all cases are added for ( auto summaryCase : newCases ) @@ -87,9 +81,6 @@ void RicReplaceSummaryEnsembleFeature::onActionTriggered( bool isChecked ) { sumCaseMainColl->updateAllRequiredEditors(); } - - // Delete previous cases in a separate thread, as this operation can be time-consuming - caf::AsyncPdmObjectVectorDeleter summaryCaseDeleter( casesToBeDeleted ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp index e02b7e7664..94305c368d 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.cpp @@ -186,6 +186,37 @@ RimSummaryCase* RimSummaryEnsemble::firstSummaryCase() const return nullptr; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimSummaryEnsemble::replaceCases( const std::vector& summaryCases ) +{ + m_cases.deleteChildrenAsync(); + + if ( summaryCases.empty() ) return; + + auto lastCase = summaryCases.back(); + + for ( auto summaryCase : summaryCases ) + { + if ( summaryCase == lastCase ) continue; + + // Do what is required to add the case, avoid updates until all cases are added + summaryCase->nameChanged.connect( this, &RimSummaryEnsemble::onCaseNameChanged ); + if ( m_cases.empty() ) + { + summaryCase->setShowVectorItemsInProjectTree( true ); + } + m_cases.push_back( summaryCase ); + } + + if ( lastCase ) + { + // Add the last case, and update connected plots + addCase( lastCase ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -697,6 +728,8 @@ void RimSummaryEnsemble::updateReferringCurveSets( bool doZoomAll ) { if ( auto parentPlot = curveSet->firstAncestorOrThisOfType() ) { + // If the ensemble name has changed, make sure the name in the project tree is updated + parentPlot->updateConnectedEditors(); parentPlot->zoomAll(); } } diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h index 21c36b0003..1bd07a1bbf 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryEnsemble.h @@ -56,8 +56,10 @@ public: RimSummaryEnsemble(); ~RimSummaryEnsemble() override; - void removeCase( RimSummaryCase* summaryCase, bool notifyChange = true ); - void addCase( RimSummaryCase* summaryCase ); + void removeCase( RimSummaryCase* summaryCase, bool notifyChange = true ); + void addCase( RimSummaryCase* summaryCase ); + void replaceCases( const std::vector& summaryCases ); + virtual std::vector allSummaryCases() const; RimSummaryCase* firstSummaryCase() const;