Files
ResInsight/ApplicationLibCode/Commands/RicReloadSummaryCaseFeature.cpp
T
Magne Sjaastad 957adc3c4c Adjustments for ensemble file sets
* Add support for reload of ensemble file set
* Fix Replace for ensemble file sets
* Workaround for update of connected plots
* Use summary icon for ensemble data sources
2025-05-19 12:51:52 +02:00

106 lines
3.9 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 "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 )
{
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() ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicReloadSummaryCaseFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Reload" );
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;
}