Files
ResInsight/ApplicationLibCode/Commands/RicCloseObservedDataFeature.cpp
T
Magne Sjaastad 1660e333ff #14493 Delete curves for all cases in one pass when deleting a summary ensemble
deleteSummaryCaseCollection() looped over every case in the ensemble, and for each case scanned every summary plot and called updateConnectedEditors() on every multi plot. For an ensemble with many realizations this scanned each plot once per realization, and updated the connected editors once per realization and multi plot. This showed up as a hot spot in the profiler.

Replace deleteCurvesAssosiatedWithCase() with deleteCurvesAssosiatedWithCases(), which takes a set of cases and returns whether anything was deleted. Each plot is now scanned once, and the connected editors of a multi plot are updated only when that multi plot actually lost a curve.

RicCloseSummaryCaseFeature and RicCloseObservedDataFeature are updated to the new signature. RicCloseSummaryCaseFeature also scans each plot once instead of once per case.
2026-08-10 12:38:41 +02:00

133 lines
5.1 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicCloseObservedDataFeature.h"
#include "Summary/RiaSummaryTools.h"
#include "RimMainPlotCollection.h"
#include "RimObservedDataCollection.h"
#include "RimObservedFmuRftData.h"
#include "RimObservedSummaryData.h"
#include "RimRftPlotCollection.h"
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
#include "RimSummaryPlot.h"
#include "RimWellRftPlot.h"
#include "cafSelectionManager.h"
#include "cafAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicCloseObservedDataFeature, "RicCloseObservedDataFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseObservedDataFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Close" );
actionToSetup->setIcon( QIcon( ":/Close.svg" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseObservedDataFeature::deleteObservedSummaryData( const std::vector<RimObservedSummaryData*>& data )
{
RimSummaryMultiPlotCollection* summaryPlotColl = RiaSummaryTools::summaryMultiPlotCollection();
for ( RimObservedSummaryData* observedData : data )
{
for ( RimSummaryMultiPlot* multiPlot : summaryPlotColl->multiPlots() )
{
for ( RimSummaryPlot* summaryPlot : multiPlot->summaryPlots() )
{
summaryPlot->deleteCurvesAssosiatedWithCases( { observedData } );
}
multiPlot->updateConnectedEditors();
}
RimObservedDataCollection* observedDataCollection = observedData->firstAncestorOrThisOfTypeAsserted<RimObservedDataCollection>();
observedDataCollection->removeObservedSummaryData( observedData );
delete observedData;
observedDataCollection->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseObservedDataFeature::deleteObservedRmuRftData( const std::vector<RimObservedFmuRftData*>& data )
{
RimRftPlotCollection* rftPlotColl = RimMainPlotCollection::current()->rftPlotCollection();
for ( RimObservedFmuRftData* observedData : data )
{
RimObservedDataCollection* observedDataCollection = observedData->firstAncestorOrThisOfTypeAsserted<RimObservedDataCollection>();
for ( RimWellRftPlot* plot : rftPlotColl->rftPlots() )
{
plot->deleteCurvesAssosicatedWithObservedData( observedData );
}
observedDataCollection->removeObservedFmuRftData( observedData );
delete observedData;
observedDataCollection->updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicCloseObservedDataFeature::isCommandEnabled() const
{
const auto summarySelection = caf::SelectionManager::instance()->objectsByType<RimObservedSummaryData>();
const auto fmuRftSelection = caf::SelectionManager::instance()->objectsByType<RimObservedFmuRftData>();
if ( summarySelection.empty() && fmuRftSelection.empty() )
{
return false;
}
for ( RimObservedSummaryData* data : summarySelection )
{
if ( !data->isObservedData() )
{
return false;
}
}
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicCloseObservedDataFeature::onActionTriggered( bool isChecked )
{
const auto summarySelection = caf::SelectionManager::instance()->objectsByType<RimObservedSummaryData>();
const auto fmuRftSelection = caf::SelectionManager::instance()->objectsByType<RimObservedFmuRftData>();
CAF_ASSERT( !( summarySelection.empty() && fmuRftSelection.empty() ) );
RicCloseObservedDataFeature::deleteObservedSummaryData( summarySelection );
RicCloseObservedDataFeature::deleteObservedRmuRftData( fmuRftSelection );
}