Files
ResInsight/ApplicationLibCode/Commands/RicReloadSummaryCaseFeature.cpp
T
JJ 453562082d Summary case refresh update. (#13123)
Use improved opm-common reader with less throws.
Add reload selected cases button
Add timer for auto-reload of cases
Add include in auto update option for cases and ensembles
Do not enable auto reload option for cases in an ensemble
2025-11-03 18:41:55 +01:00

132 lines
5.0 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 "RicReloadSummaryCaseFeature.h"
#include "RiaLogging.h"
#include "Summary/RiaSummaryTools.h"
#include "RimObservedDataCollection.h"
#include "RimObservedSummaryData.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseMainCollection.h"
#include "RimSummaryEnsemble.h"
#include "cafPdmObject.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicReloadSummaryCaseFeature, "RicReloadSummaryCaseFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicReloadSummaryCaseFeature::isCommandEnabled() const
{
auto ensembles = caf::SelectionManager::instance()->objectsByType<RimSummaryEnsemble>();
if ( !ensembles.empty() ) return true;
std::vector<RimSummaryCase*> caseSelection = selectedSummaryCases();
return !caseSelection.empty();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadSummaryCaseFeature::onActionTriggered( bool isChecked )
{
reloadSelectedCasesAndUpdate();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Reload" );
actionToSetup->setToolTip( "Reload selected summary and/or ensemble cases" );
actionToSetup->setIcon( QIcon( ":/Refresh.svg" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicReloadSummaryCaseFeature::selectedSummaryCases()
{
const auto mainCollectionSelection = caf::SelectionManager::instance()->objectsByType<RimSummaryCaseMainCollection>();
if ( !mainCollectionSelection.empty() )
{
return mainCollectionSelection[0]->allSummaryCases();
}
std::vector<RimSummaryCase*> caseSelection = caf::SelectionManager::instance()->objectsByType<RimSummaryCase>();
{
for ( auto collection : caf::SelectionManager::instance()->objectsByType<RimObservedDataCollection>() )
{
std::vector<RimObservedSummaryData*> observedCases = collection->allObservedSummaryData();
caseSelection.insert( caseSelection.end(), observedCases.begin(), observedCases.end() );
}
}
return caseSelection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadSummaryCaseFeature::reloadTaggedSummaryCasesAndUpdate()
{
auto proj = RimProject::current();
for ( auto summaryCase : proj->allSummaryCases() )
{
if ( summaryCase->includeInAutoReload() ) RiaSummaryTools::reloadSummaryCaseAndUpdateConnectedPlots( summaryCase );
}
for ( RimSummaryEnsemble* ensemble : proj->summaryEnsembles() )
{
if ( ensemble->includeInAutoReload() ) ensemble->reloadCases();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadSummaryCaseFeature::reloadSelectedCasesAndUpdate()
{
auto ensembles = caf::SelectionManager::instance()->objectsByType<RimSummaryEnsemble>();
if ( !ensembles.empty() )
{
for ( RimSummaryEnsemble* ensemble : ensembles )
{
ensemble->reloadCases();
}
return;
}
std::vector<RimSummaryCase*> caseSelection = selectedSummaryCases();
for ( RimSummaryCase* summaryCase : caseSelection )
{
RiaSummaryTools::reloadSummaryCaseAndUpdateConnectedPlots( summaryCase );
RiaLogging::info( QString( "Reloaded data for %1" ).arg( summaryCase->summaryHeaderFilename() ) );
}
}