From 2c73b2ed029ac45a613ec0ce041f2a51341a061e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 4 Oct 2019 18:46:30 +0200 Subject: [PATCH] #4828 Summary Plot Templates : Support ensembles as plot data sources --- .../RicCreatePlotFromSelectionFeature.cpp | 23 ++-- .../RicCreatePlotFromSelectionFeature.h | 3 - ...reatePlotFromTemplateByShortcutFeature.cpp | 10 +- .../RicCreatePlotFromTemplateFeature.cpp | 25 ++--- .../RicCreatePlotFromTemplateFeature.h | 4 +- .../RicSavePlotTemplateFeature.cpp | 48 ++++++-- .../RicSummaryPlotTemplateTools.cpp | 106 +++++++++++++----- .../RicSummaryPlotTemplateTools.h | 9 +- .../RimContextCommandBuilder.cpp | 2 +- 9 files changed, 152 insertions(+), 78 deletions(-) diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp index 46f80f8873..a2705891e9 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.cpp @@ -40,7 +40,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelect //-------------------------------------------------------------------------------------------------- bool RicCreatePlotFromSelectionFeature::isCommandEnabled() { - return !selectedSummaryCases().empty(); + bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty(); + bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty(); + + return ( anySummaryCases || anySummaryCaseCollections ); } //-------------------------------------------------------------------------------------------------- @@ -48,11 +51,12 @@ bool RicCreatePlotFromSelectionFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked ) { - QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath(); - std::vector sumCases = selectedSummaryCases(); + QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath(); + auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases(); + auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections(); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); - RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); + RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections ); } //-------------------------------------------------------------------------------------------------- @@ -63,14 +67,3 @@ void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup actionToSetup->setText( "Create Plot from Template" ); actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RicCreatePlotFromSelectionFeature::selectedSummaryCases() const -{ - std::vector objects; - caf::SelectionManager::instance()->objectsByType( &objects ); - - return objects; -} diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h index 65a18dcfef..b8e17a84b9 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromSelectionFeature.h @@ -33,7 +33,4 @@ protected: bool isCommandEnabled() override; void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; - -private: - std::vector selectedSummaryCases() const; }; diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateByShortcutFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateByShortcutFeature.cpp index 656b3042c9..3fe5c91479 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateByShortcutFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateByShortcutFeature.cpp @@ -40,7 +40,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateByShortcutFeature, "RicCreatePlotF //-------------------------------------------------------------------------------------------------- bool RicCreatePlotFromTemplateByShortcutFeature::isCommandEnabled() { - return !selectedSummaryCases().empty(); + bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty(); + bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty(); + + return ( anySummaryCases || anySummaryCaseCollections ); } //-------------------------------------------------------------------------------------------------- @@ -68,10 +71,11 @@ void RicCreatePlotFromTemplateByShortcutFeature::onActionTriggered( bool isCheck RiaApplication::instance()->preferences()->setDefaultPlotTemplatePath( fileName ); } - std::vector sumCases = selectedSummaryCases(); + auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases(); + auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections(); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); - RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); + RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp index d78f3b9b30..0107fa75bc 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.cpp @@ -20,6 +20,7 @@ #include "RicSummaryPlotTemplateTools.h" #include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" #include "cafSelectionManager.h" @@ -32,7 +33,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateFeature, "RicCreatePlotFromTemplat //-------------------------------------------------------------------------------------------------- bool RicCreatePlotFromTemplateFeature::isCommandEnabled() { - return !selectedSummaryCases().empty(); + bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty(); + bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty(); + + return ( anySummaryCases || anySummaryCaseCollections ); } //-------------------------------------------------------------------------------------------------- @@ -40,11 +44,13 @@ bool RicCreatePlotFromTemplateFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicCreatePlotFromTemplateFeature::onActionTriggered( bool isChecked ) { - QString fileName = userData().toString(); - std::vector sumCases = selectedSummaryCases(); + QString fileName = userData().toString(); + auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases(); + auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections(); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); - RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); + + RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections ); } //-------------------------------------------------------------------------------------------------- @@ -55,14 +61,3 @@ void RicCreatePlotFromTemplateFeature::setupActionLook( QAction* actionToSetup ) actionToSetup->setText( "Create Plot from Template" ); actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector RicCreatePlotFromTemplateFeature::selectedSummaryCases() const -{ - std::vector objects; - caf::SelectionManager::instance()->objectsByType( &objects ); - - return objects; -} diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h index a3194b4412..e06ae25ab8 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicCreatePlotFromTemplateFeature.h @@ -23,6 +23,7 @@ #include class RimSummaryCase; +class RimSummaryCaseCollection; //================================================================================================== /// @@ -35,7 +36,4 @@ protected: bool isCommandEnabled() override; void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; - -private: - std::vector selectedSummaryCases() const; }; diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp index 7e3f28de66..9c1a53717e 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicSavePlotTemplateFeature.cpp @@ -25,6 +25,8 @@ #include "RiaPreferences.h" #include "RiaSummaryTools.h" +#include "RimEnsembleCurveSet.h" +#include "RimEnsembleCurveSetCollection.h" #include "RimProject.h" #include "RimSummaryCurve.h" #include "RimSummaryPlot.h" @@ -140,24 +142,48 @@ QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summar RimSummaryPlot* newSummaryPlot = dynamic_cast( obj ); if ( newSummaryPlot ) { - std::set caseReferenceStrings; - - for ( const auto& curve : newSummaryPlot->summaryCurves() ) { - auto fieldHandle = curve->findField( "SummaryCase" ); - if ( fieldHandle ) + std::set caseReferenceStrings; + + for ( const auto& curve : newSummaryPlot->summaryCurves() ) { - auto reference = fieldHandle->xmlCapability()->referenceString(); - caseReferenceStrings.insert( reference ); + auto fieldHandle = curve->findField( "SummaryCase" ); + if ( fieldHandle ) + { + auto reference = fieldHandle->xmlCapability()->referenceString(); + caseReferenceStrings.insert( reference ); + } + } + + size_t index = 0; + for ( const auto& s : caseReferenceStrings ) + { + QString caseName = QString( "CASE_NAME %1" ).arg( index++ ); + + objectAsText.replace( s, caseName ); } } - size_t index = 0; - for ( const auto& s : caseReferenceStrings ) { - QString caseName = QString( "CASE_NAME %1" ).arg( index++ ); + std::set ensembleReferenceStrings; - objectAsText.replace( s, caseName ); + for ( const auto& curveSet : newSummaryPlot->ensembleCurveSetCollection()->curveSets() ) + { + auto fieldHandle = curveSet->findField( "SummaryGroup" ); + if ( fieldHandle ) + { + auto reference = fieldHandle->xmlCapability()->referenceString(); + ensembleReferenceStrings.insert( reference ); + } + } + + size_t index = 0; + for ( const auto& s : ensembleReferenceStrings ) + { + QString ensembleName = QString( "ENSEMBLE_NAME %1" ).arg( index++ ); + + objectAsText.replace( s, ensembleName ); + } } } diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp index c8dcae501a..d699963711 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp @@ -29,6 +29,8 @@ #include "PlotTemplates/RimPlotTemplateFileItem.h" #include "RimDialogData.h" +#include "RimEnsembleCurveSet.h" +#include "RimEnsembleCurveSetCollection.h" #include "RimMainPlotCollection.h" #include "RimProject.h" #include "RimSummaryCase.h" @@ -40,6 +42,7 @@ #include "cafPdmUiPropertyViewDialog.h" +#include "cafSelectionManager.h" #include //-------------------------------------------------------------------------------------------------- @@ -76,7 +79,9 @@ RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const Q /// //-------------------------------------------------------------------------------------------------- void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( - RimSummaryPlot* summaryPlot, const std::vector& selectedSummaryCases ) + RimSummaryPlot* summaryPlot, + const std::vector& selectedSummaryCases, + const std::vector& selectedEnsembles ) { if ( summaryPlot ) { @@ -87,38 +92,40 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( summaryPlot->resolveReferencesRecursively(); summaryPlot->initAfterReadRecursively(); - auto summaryCurves = summaryPlot->summaryCurves(); - - for ( const auto& curve : summaryCurves ) { - auto fieldHandle = curve->findField( "SummaryCase" ); - if ( fieldHandle ) + auto summaryCurves = summaryPlot->summaryCurves(); + + for ( const auto& curve : summaryCurves ) { - auto referenceString = fieldHandle->xmlCapability()->referenceString(); - auto stringList = referenceString.split( " " ); - if ( stringList.size() == 2 ) + auto fieldHandle = curve->findField( "SummaryCase" ); + if ( fieldHandle ) { - QString indexAsString = stringList[1]; - - bool conversionOk = false; - auto index = indexAsString.toUInt( &conversionOk ); - - if ( conversionOk && index < selectedSummaryCases.size() ) + auto referenceString = fieldHandle->xmlCapability()->referenceString(); + auto stringList = referenceString.split( " " ); + if ( stringList.size() == 2 ) { - auto summaryCaseY = selectedSummaryCases[index]; - curve->setSummaryCaseY( summaryCaseY ); + QString indexAsString = stringList[1]; - auto currentAddressY = curve->summaryAddressY(); - if ( summaryCaseY->summaryReader() && - !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) ) + bool conversionOk = false; + auto index = indexAsString.toUInt( &conversionOk ); + + if ( conversionOk && index < selectedSummaryCases.size() ) { - auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); + auto summaryCaseY = selectedSummaryCases[index]; + curve->setSummaryCaseY( summaryCaseY ); - auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY, - allAddresses ); - if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) + auto currentAddressY = curve->summaryAddressY(); + if ( summaryCaseY->summaryReader() && + !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) ) { - curve->setSummaryAddressY( candidate ); + auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); + + auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY, + allAddresses ); + if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) + { + curve->setSummaryAddressY( candidate ); + } } } } @@ -126,6 +133,33 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( } } + { + auto summaryCurves = summaryPlot->ensembleCurveSetCollection()->curveSets(); + + for ( const auto& curveSet : summaryCurves ) + { + auto fieldHandle = curveSet->findField( "SummaryGroup" ); + if ( fieldHandle ) + { + auto referenceString = fieldHandle->xmlCapability()->referenceString(); + auto stringList = referenceString.split( " " ); + if ( stringList.size() == 2 ) + { + QString indexAsString = stringList[1]; + + bool conversionOk = false; + auto index = indexAsString.toUInt( &conversionOk ); + + if ( conversionOk && index < selectedEnsembles.size() ) + { + auto summaryCaseY = selectedEnsembles[index]; + curveSet->setSummaryCaseCollection( summaryCaseY ); + } + } + } + } + } + // TODO: Create additional curves in selected case count is larger than template count plotColl->updateConnectedEditors(); @@ -255,6 +289,28 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath() return QString(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicSummaryPlotTemplateTools::selectedSummaryCases() +{ + std::vector objects; + caf::SelectionManager::instance()->objectsByType( &objects ); + + return objects; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicSummaryPlotTemplateTools::selectedSummaryCaseCollections() +{ + std::vector objects; + caf::SelectionManager::instance()->objectsByType( &objects ); + + return objects; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h index 9d657ed068..570494c2d5 100644 --- a/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h +++ b/ApplicationCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h @@ -30,6 +30,7 @@ class PdmObject; class RimSummaryPlot; class RimSummaryCase; +class RimSummaryCaseCollection; class RifEclipseSummaryAddress; //================================================================================================== @@ -39,8 +40,9 @@ class RicSummaryPlotTemplateTools { public: static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ); - static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot, - const std::vector& selectedSummaryCases ); + static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot, + const std::vector& selectedSummaryCases, + const std::vector& selectedEnsembles ); static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot, const std::set& selectedSummaryAddresses, @@ -50,6 +52,9 @@ public: static QString selectPlotTemplatePath(); + static std::vector selectedSummaryCases(); + static std::vector selectedSummaryCaseCollections(); + private: static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, const std::set& allAddresses ); diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index af3fb0cc1f..42f9c524af 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -845,7 +845,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicCutReferencesToClipboardFeature"; menuBuilder << "Separator"; - if ( dynamic_cast( uiItem ) ) + if ( dynamic_cast( uiItem ) || dynamic_cast( uiItem ) ) { menuBuilder << "RicCreatePlotFromSelectionFeature"; menuBuilder << "RicCreatePlotFromTemplateByShortcutFeature";