///////////////////////////////////////////////////////////////////////////////// // // 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 // 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 "RimSummaryEnsembleTools.h" #include "cafPdmObject.h" #include "cafSelectionManager.h" #include CAF_CMD_SOURCE_INIT( RicReloadSummaryCaseFeature, "RicReloadSummaryCaseFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicReloadSummaryCaseFeature::isCommandEnabled() const { const auto& [caseSelection, ensembleSelection] = selectedSummarySources(); return !caseSelection.empty() || !ensembleSelection.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::pair, std::vector> RicReloadSummaryCaseFeature::selectedSummarySources() { std::vector caseSelection; std::vector ensembleSelection; auto ensembles = caf::SelectionManager::instance()->objectsByType(); for ( RimSummaryEnsemble* ensemble : ensembles ) { ensembleSelection.push_back( ensemble ); } std::vector selectionManagerCases = caf::SelectionManager::instance()->objectsByType(); for ( RimSummaryCase* summaryCase : selectionManagerCases ) { caseSelection.push_back( summaryCase ); } for ( auto collection : caf::SelectionManager::instance()->objectsByType() ) { std::vector observedCases = collection->allObservedSummaryData(); caseSelection.insert( caseSelection.end(), observedCases.begin(), observedCases.end() ); } if ( ensembleSelection.empty() && caseSelection.empty() ) { const auto sumCaseColl = caf::SelectionManager::instance()->objectsByType(); if ( !sumCaseColl.empty() ) { ensembleSelection = sumCaseColl.front()->summaryEnsembles(); // Make sure to select top-level cases only, not cases part of ensembles caseSelection = sumCaseColl.front()->topLevelSummaryCases(); } } return { caseSelection, ensembleSelection }; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicReloadSummaryCaseFeature::reloadTaggedSummaryCasesAndUpdate() { auto proj = RimProject::current(); for ( auto summaryCase : proj->allSummaryCases() ) { if ( summaryCase->includeInAutoReload() ) { RiaSummaryTools::reloadSummaryCaseAndUpdateConnectedPlots( summaryCase ); summaryCase->updateConnectedEditors(); } } for ( RimSummaryEnsemble* ensemble : proj->summaryEnsembles() ) { if ( ensemble->includeInAutoReload() ) { ensemble->reloadCases(); ensemble->updateConnectedEditors(); RimSummaryEnsembleTools::updateDependentDeltaEnsembles( ensemble ); } } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicReloadSummaryCaseFeature::reloadSelectedCasesAndUpdate() { const auto& [caseSelection, ensembleSelection] = selectedSummarySources(); for ( RimSummaryEnsemble* ensemble : ensembleSelection ) { ensemble->reloadCases(); RimSummaryEnsembleTools::updateDependentDeltaEnsembles( ensemble ); } for ( RimSummaryCase* summaryCase : caseSelection ) { RiaSummaryTools::reloadSummaryCaseAndUpdateConnectedPlots( summaryCase ); summaryCase->updateConnectedEditors(); RiaLogging::info( QString( "Reloaded data for %1" ).arg( summaryCase->summaryHeaderFilename() ) ); } }