ResInsight/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDerivedSummaryFeature.cpp
Magne Sjaastad 91762aaeb1
RC3 adjustments
* Update icons for summary and ensemble templates

* Icons for regression and decline

* #10374 LineEditor: Hide the placeholder widget when not used

* #10376 Assign a case ID to delta summary case

* Do not show decline range text in plot
2023-06-10 16:30:34 +02:00

129 lines
4.3 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicNewDerivedSummaryFeature.h"
#include "RimDerivedSummaryCase.h"
#include "RimProject.h"
#include "RimSummaryCaseMainCollection.h"
#include "RiuPlotMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
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<RimSummaryCaseMainCollection*> mainColls = caf::selectedObjectsByTypeStrict<RimSummaryCaseMainCollection*>();
if ( mainColls.size() == 1 ) return mainColls.front();
auto sumCases = twoSelectedSummaryCases();
if ( !sumCases.empty() )
{
return sumCases.front()->firstAncestorOfType<RimSummaryCaseMainCollection>();
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicNewDerivedSummaryFeature::twoSelectedSummaryCases()
{
auto sumCases = caf::selectedObjectsByTypeStrict<RimSummaryCase*>();
if ( sumCases.size() == 2 ) return sumCases;
return {};
}