From 9ef51a5e98b7adb0a1c4f5afeaef1910d2832814 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 19 Mar 2020 11:46:24 +0100 Subject: [PATCH] #5621 Delta case : Create delta case from two selected cases --- .../RicNewDerivedSummaryFeature.cpp | 52 ++++++++++++++++--- .../RicNewDerivedSummaryFeature.h | 7 +++ .../RimContextCommandBuilder.cpp | 1 + .../Summary/RimDerivedSummaryCase.cpp | 4 +- .../Summary/RimDerivedSummaryCase.h | 3 +- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.cpp b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.cpp index 50adab2d4a..ba11f636ca 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.cpp +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.cpp @@ -37,10 +37,9 @@ CAF_CMD_SOURCE_INIT( RicNewDerivedSummaryFeature, "RicNewDerivedSummaryFeature" //-------------------------------------------------------------------------------------------------- bool RicNewDerivedSummaryFeature::isCommandEnabled() { - std::vector mainColls = - caf::selectedObjectsByTypeStrict(); + if ( mainCollection() ) return true; - return mainColls.size() == 1; + return false; } //-------------------------------------------------------------------------------------------------- @@ -48,13 +47,20 @@ bool RicNewDerivedSummaryFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicNewDerivedSummaryFeature::onActionTriggered( bool isChecked ) { - if ( isCommandEnabled() ) + auto mainColl = mainCollection(); + if ( mainColl ) { - auto project = RiaApplication::instance()->project(); - auto mainColl = project->firstSummaryCaseMainCollection(); - auto derivedCase = new RimDerivedSummaryCase; + + auto selectedCases = twoSelectedSummaryCases(); + if ( !selectedCases.empty() ) + { + derivedCase->setSummaryCases( selectedCases[0], selectedCases[1] ); + derivedCase->createSummaryReaderInterface(); + } + mainColl->addCase( derivedCase ); + derivedCase->updateDisplayNameFromCases(); mainColl->updateConnectedEditors(); RiuPlotMainWindowTools::selectAsCurrentItem( derivedCase ); @@ -69,3 +75,35 @@ void RicNewDerivedSummaryFeature::setupActionLook( QAction* actionToSetup ) actionToSetup->setText( "New Delta Summary Case" ); // actionToSetup->setIcon( QIcon( ":/SummaryEnsemble16x16.png" ) ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryCaseMainCollection* RicNewDerivedSummaryFeature::mainCollection() +{ + std::vector mainColls = + caf::selectedObjectsByTypeStrict(); + + if ( mainColls.size() == 1 ) return mainColls.front(); + + auto sumCases = twoSelectedSummaryCases(); + if ( !sumCases.empty() ) + { + RimSummaryCaseMainCollection* mainColl = nullptr; + sumCases.front()->firstAncestorOfType( mainColl ); + return mainColl; + } + + return nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RicNewDerivedSummaryFeature::twoSelectedSummaryCases() +{ + auto sumCases = caf::selectedObjectsByTypeStrict(); + if ( sumCases.size() == 2 ) return sumCases; + + return {}; +} diff --git a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.h b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.h index b5b867429a..bd2be3a77a 100644 --- a/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.h +++ b/ApplicationCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.h @@ -20,6 +20,9 @@ #include "cafCmdFeature.h" +class RimSummaryCase; +class RimSummaryCaseMainCollection; + //================================================================================================== /// //================================================================================================== @@ -32,4 +35,8 @@ protected: bool isCommandEnabled() override; void onActionTriggered( bool isChecked ) override; void setupActionLook( QAction* actionToSetup ) override; + +private: + static RimSummaryCaseMainCollection* mainCollection(); + static std::vector twoSelectedSummaryCases(); }; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 4d478a6974..c06554db34 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -876,6 +876,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicNewDefaultSummaryPlotFeature"; menuBuilder << "RicNewSummaryCrossPlotFeature"; menuBuilder << "RicSummaryCurveSwitchAxisFeature"; + menuBuilder << "RicNewDerivedSummaryFeature"; menuBuilder.addSeparator(); menuBuilder << "RicConvertGroupToEnsembleFeature"; menuBuilder.addSeparator(); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.cpp b/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.cpp index 16081b8cbe..0f15396169 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.cpp @@ -283,7 +283,7 @@ void RimDerivedSummaryCase::clearData( const RifEclipseSummaryAddress& address ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimDerivedSummaryCase::updateNameFromInputCases() +void RimDerivedSummaryCase::updateDisplayNameFromCases() { QString case1Name = "None"; QString case2Name = "None"; @@ -370,7 +370,7 @@ void RimDerivedSummaryCase::fieldChangedByUi( const caf::PdmFieldHandle* changed if ( reloadData ) { - updateNameFromInputCases(); + updateDisplayNameFromCases(); m_dataCache.clear(); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.h b/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.h index bae05dfbf0..e9372f1853 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimDerivedSummaryCase.h @@ -64,6 +64,8 @@ public: RifSummaryReaderInterface* summaryReader() override; void updateFilePathsFromProjectPath( const QString& newProjectPath, const QString& oldProjectPath ) override; + void updateDisplayNameFromCases(); + protected: QString caseName() const override; @@ -75,7 +77,6 @@ private: void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void clearData( const RifEclipseSummaryAddress& address ); - void updateNameFromInputCases(); private: caf::PdmPtrField m_summaryCase1;