From 77c789a179cb59c12f813680cfeacf71559e5ab7 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Sun, 20 Oct 2024 14:24:22 +0200 Subject: [PATCH] Improve performance when creating multiple plots --- .../RiaPlotWindowRedrawScheduler.cpp | 22 ++++++++++++++ .../RiaPlotWindowRedrawScheduler.h | 4 +++ ...RicAppendSummaryPlotsForObjectsFeature.cpp | 29 +++++++++++++++++-- 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp b/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp index 1f4e955dba..5133e6f579 100644 --- a/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp +++ b/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.cpp @@ -146,11 +146,33 @@ void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots() } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::blockScheduledUpdatesAndReplots() +{ + m_blockScheduledUpdatesAndReplots = true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::unblockScheduledUpdatesAndReplots() +{ + m_blockScheduledUpdatesAndReplots = false; + startTimer( 0 ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiaPlotWindowRedrawScheduler::slotUpdateAndReplotScheduledItemsWhenReady() { + if ( m_blockScheduledUpdatesAndReplots ) + { + return; + } + if ( caf::ProgressState::isActive() ) { startTimer( 100 ); diff --git a/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.h b/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.h index e07a6c8d2d..0b540c261f 100644 --- a/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.h +++ b/ApplicationLibCode/Application/RiaPlotWindowRedrawScheduler.h @@ -48,6 +48,9 @@ public: void clearAllScheduledUpdates(); void performScheduledUpdatesAndReplots(); + void blockScheduledUpdatesAndReplots(); + void unblockScheduledUpdatesAndReplots(); + private slots: void slotUpdateAndReplotScheduledItemsWhenReady(); @@ -64,4 +67,5 @@ private: std::set> m_plotWidgetsToReplot; QScopedPointer m_plotWindowUpdateTimer; + bool m_blockScheduledUpdatesAndReplots = false; }; diff --git a/ApplicationLibCode/Commands/PlotBuilderCommands/RicAppendSummaryPlotsForObjectsFeature.cpp b/ApplicationLibCode/Commands/PlotBuilderCommands/RicAppendSummaryPlotsForObjectsFeature.cpp index 6baa1de7bd..9139b82ca0 100644 --- a/ApplicationLibCode/Commands/PlotBuilderCommands/RicAppendSummaryPlotsForObjectsFeature.cpp +++ b/ApplicationLibCode/Commands/PlotBuilderCommands/RicAppendSummaryPlotsForObjectsFeature.cpp @@ -20,6 +20,7 @@ #include "RiaGuiApplication.h" #include "RiaLogging.h" +#include "RiaPlotWindowRedrawScheduler.h" #include "RiaStdStringTools.h" #include "RiaSummaryAddressAnalyzer.h" #include "RiaSummaryTools.h" @@ -68,6 +69,9 @@ void RicAppendSummaryPlotsForObjectsFeature::appendPlots( RimSummaryMultiPlot* caf::ProgressInfo info( sumAddressCollections.size(), "Appending plots..." ); + summaryMultiPlot->startBatchAddOperation(); + RiaPlotWindowRedrawScheduler::instance()->blockScheduledUpdatesAndReplots(); + for ( auto summaryAdrCollection : sumAddressCollections ) { auto duplicatedPlots = RicSummaryPlotBuilder::duplicateSummaryPlots( plotsForOneInstance ); @@ -108,11 +112,16 @@ void RicAppendSummaryPlotsForObjectsFeature::appendPlots( RimSummaryMultiPlot* summaryMultiPlot->addPlot( duplicatedPlot ); duplicatedPlot->resolveReferencesRecursively(); } - - duplicatedPlot->loadDataAndUpdate(); } + info.incrementProgress(); } + summaryMultiPlot->endBatchAddOperation(); + + RiaPlotWindowRedrawScheduler::instance()->clearAllScheduledUpdates(); + RiaPlotWindowRedrawScheduler::instance()->unblockScheduledUpdatesAndReplots(); + + summaryMultiPlot->loadDataAndUpdate(); summaryMultiPlot->updatePlotTitles(); } @@ -273,6 +282,13 @@ bool RicAppendSummaryPlotsForObjectsFeature::isSelectionCompatibleWithPlot( cons errorText = "Source plot must contain at least one region to be able to duplicate a selection of regions"; } } + else if ( selectionType == RimSummaryAddressCollection::CollectionContentType::NETWORK ) + { + if ( analyzer.networkNames().empty() ) + { + errorText = "Source plot must contain at least one network to be able to duplicate a selection of networks"; + } + } if ( !errorText.isEmpty() ) { @@ -294,6 +310,7 @@ std::vector std::string wellNameToMatch; std::string groupNameToMatch; + std::string networkNameToMatch; int regionToMatch = -1; int caseIdToMatch = -1; int ensembleIdToMatch = -1; @@ -317,6 +334,10 @@ std::vector { if ( !myAnalyser.regionNumbers().empty() ) regionToMatch = *( myAnalyser.regionNumbers().begin() ); } + else if ( objectType == RimSummaryAddressCollection::CollectionContentType::NETWORK ) + { + if ( !myAnalyser.networkNames().empty() ) networkNameToMatch = *( myAnalyser.networkNames().begin() ); + } else if ( objectType == RimSummaryAddressCollection::CollectionContentType::SUMMARY_CASE ) { if ( !sourcePlots.empty() ) @@ -368,6 +389,10 @@ std::vector { isMatching = true; } + else if ( !networkNameToMatch.empty() && a.networkName() == networkNameToMatch ) + { + isMatching = true; + } else if ( regionToMatch != -1 && a.regionNumber() == regionToMatch ) { isMatching = true;