ResInsight/ApplicationLibCode/Commands/SummaryPlotCommands/RicNewDerivedEnsembleFeature.cpp

117 lines
4.5 KiB
C++
Raw Normal View History

2018-06-25 08:14:47 -05:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
2018-06-25 08:14:47 -05:00
// 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.
//
2018-06-25 08:14:47 -05:00
// 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>
2018-06-25 08:14:47 -05:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicNewDerivedEnsembleFeature.h"
#include "RimDerivedEnsembleCaseCollection.h"
#include "RimProject.h"
#include "RimSummaryCaseMainCollection.h"
#include "RiuPlotMainWindowTools.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
#include <QMessageBox>
2018-06-25 08:14:47 -05:00
#include <memory>
CAF_CMD_SOURCE_INIT( RicNewDerivedEnsembleFeature, "RicNewDerivedEnsembleFeature" );
2018-06-25 08:14:47 -05:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewDerivedEnsembleFeature::showWarningDialog()
{
QMessageBox::warning( nullptr, "Ensemble Matching", "None of the cases in the ensembles match" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewDerivedEnsembleFeature::showWarningDialogWithQuestion()
{
QMessageBox msgBox;
msgBox.setIcon( QMessageBox::Question );
msgBox.setWindowTitle( "Ensemble Matching" );
msgBox.setText( "None of the cases in the ensembles match" );
msgBox.setInformativeText( "Do you want to keep the delta ensemble?" );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
int ret = msgBox.exec();
return ret == QMessageBox::Yes;
}
2018-06-25 08:14:47 -05:00
//--------------------------------------------------------------------------------------------------
///
2018-06-25 08:14:47 -05:00
//--------------------------------------------------------------------------------------------------
bool RicNewDerivedEnsembleFeature::isCommandEnabled()
{
std::vector<RimSummaryCaseMainCollection*> mainColls =
caf::selectedObjectsByTypeStrict<RimSummaryCaseMainCollection*>();
2018-06-25 08:14:47 -05:00
std::vector<RimSummaryCaseCollection*> ensembles = caf::selectedObjectsByTypeStrict<RimSummaryCaseCollection*>();
return mainColls.size() == 1 || ensembles.size() == 1 || ensembles.size() == 2;
}
//--------------------------------------------------------------------------------------------------
///
2018-06-25 08:14:47 -05:00
//--------------------------------------------------------------------------------------------------
void RicNewDerivedEnsembleFeature::onActionTriggered( bool isChecked )
2018-06-25 08:14:47 -05:00
{
if ( isCommandEnabled() )
2018-06-25 08:14:47 -05:00
{
auto project = RimProject::current();
2018-06-25 08:14:47 -05:00
auto mainColl = project->firstSummaryCaseMainCollection();
auto newColl = mainColl->addCaseCollection( {}, "", true, []() { return new RimDerivedEnsembleCaseCollection(); } );
auto newEnsemble = dynamic_cast<RimDerivedEnsembleCaseCollection*>( newColl );
2018-06-25 08:14:47 -05:00
{
std::vector<RimSummaryCaseCollection*> ensembles = caf::selectedObjectsByType<RimSummaryCaseCollection*>();
if ( ensembles.size() >= 1 ) newEnsemble->setEnsemble1( ensembles[0] );
if ( ensembles.size() == 2 )
2018-06-25 08:14:47 -05:00
{
newEnsemble->setEnsemble2( ensembles[1] );
newEnsemble->createDerivedEnsembleCases();
if ( newEnsemble->allSummaryCases().empty() )
{
if ( !showWarningDialogWithQuestion() )
{
mainColl->removeCaseCollection( newEnsemble );
}
}
2018-06-25 08:14:47 -05:00
}
}
2018-06-25 08:14:47 -05:00
mainColl->updateConnectedEditors();
RiuPlotMainWindowTools::selectAsCurrentItem( newEnsemble );
2018-06-25 08:14:47 -05:00
}
}
//--------------------------------------------------------------------------------------------------
///
2018-06-25 08:14:47 -05:00
//--------------------------------------------------------------------------------------------------
void RicNewDerivedEnsembleFeature::setupActionLook( QAction* actionToSetup )
2018-06-25 08:14:47 -05:00
{
actionToSetup->setText( "New Delta Ensemble" );
2020-10-05 07:33:52 -05:00
actionToSetup->setIcon( QIcon( ":/SummaryEnsemble.svg" ) );
2018-06-25 08:14:47 -05:00
}