///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2020 Equinor 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 "RicNewDerivedSummaryFeature.h" #include "RimDerivedSummaryCase.h" #include "RimProject.h" #include "RimSummaryCaseMainCollection.h" #include "RiuPlotMainWindowTools.h" #include "cafSelectionManagerTools.h" #include CAF_CMD_SOURCE_INIT( RicNewDerivedSummaryFeature, "RicNewDerivedSummaryFeature" ); //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool RicNewDerivedSummaryFeature::isCommandEnabled() { if ( mainCollection() ) return true; return false; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicNewDerivedSummaryFeature::onActionTriggered( bool isChecked ) { auto mainColl = mainCollection(); if ( mainColl ) { auto derivedCase = new RimDerivedSummaryCase; auto selectedCases = twoSelectedSummaryCases(); if ( selectedCases.empty() ) { auto allCases = mainColl->allSummaryCases(); if ( allCases.size() > 0 ) { selectedCases.push_back( allCases[0] ); } if ( allCases.size() > 1 ) { selectedCases.push_back( allCases[1] ); } } if ( !selectedCases.empty() ) { RimSummaryCase* sumCase1 = selectedCases[0]; RimSummaryCase* sumCase2 = nullptr; if ( selectedCases.size() > 1 ) { sumCase2 = selectedCases[1]; } derivedCase->setSummaryCases( sumCase1, sumCase2 ); derivedCase->createSummaryReaderInterface(); } RimProject::current()->assignCaseIdToSummaryCase( derivedCase ); mainColl->addCase( derivedCase ); derivedCase->updateDisplayNameFromCases(); mainColl->updateConnectedEditors(); RiuPlotMainWindowTools::selectAsCurrentItem( derivedCase ); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicNewDerivedSummaryFeature::setupActionLook( QAction* actionToSetup ) { actionToSetup->setText( "New Delta Summary Case" ); actionToSetup->setIcon( QIcon( ":/SummaryCase.svg" ) ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- RimSummaryCaseMainCollection* RicNewDerivedSummaryFeature::mainCollection() { std::vector mainColls = caf::selectedObjectsByTypeStrict(); if ( mainColls.size() == 1 ) return mainColls.front(); auto sumCases = twoSelectedSummaryCases(); if ( !sumCases.empty() ) { return sumCases.front()->firstAncestorOfType(); } return nullptr; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- std::vector RicNewDerivedSummaryFeature::twoSelectedSummaryCases() { auto sumCases = caf::selectedObjectsByTypeStrict(); if ( sumCases.size() == 2 ) return sumCases; return {}; }