Files

122 lines
5.0 KiB
C++
Raw Permalink Normal View History

2021-12-23 09:30:36 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
2022-03-04 10:52:17 +01:00
// Copyright (C) 2022 Equinor ASA
2021-12-23 09:30:36 +01: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.
//
// 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 "RicNewSummaryMultiPlotFeature.h"
2025-02-12 13:06:58 +01:00
#include "Summary/RiaSummaryPlotTools.h"
2022-06-30 18:23:45 +02:00
#include "RimProject.h"
#include "RimSummaryCase.h"
#include "RimSummaryEnsemble.h"
2021-12-23 09:30:36 +01:00
#include "RimSummaryMultiPlot.h"
#include "RimSummaryMultiPlotCollection.h"
2022-03-04 10:52:17 +01:00
#include "RimSummaryPlot.h"
2021-12-23 09:30:36 +01:00
#include "cafSelectionManager.h"
#include "cvfAssert.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicNewSummaryMultiPlotFeature, "RicNewSummaryMultiPlotFeature" );
2021-12-23 09:30:36 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-06-26 14:28:46 +02:00
bool RicNewSummaryMultiPlotFeature::isCommandEnabled() const
2021-12-23 09:30:36 +01:00
{
const auto selectedItems = caf::SelectionManager::instance()->selectedItems();
2022-03-04 10:52:17 +01:00
if ( selectedCollection( selectedItems ) ) return true;
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
std::vector<RimSummaryEnsemble*> selectedEnsembles;
2023-06-26 13:12:41 +02:00
return selectedCases( &selectedIndividualSummaryCases, &selectedEnsembles );
2021-12-23 09:30:36 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2022-03-04 10:52:17 +01:00
void RicNewSummaryMultiPlotFeature::onActionTriggered( bool isChecked )
2021-12-23 09:30:36 +01:00
{
const auto selectedItems = caf::SelectionManager::instance()->selectedItems();
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
std::vector<RimSummaryEnsemble*> selectedEnsembles;
2022-06-30 18:23:45 +02:00
RimSummaryMultiPlotCollection* coll = selectedCollection( selectedItems );
if ( coll )
{
2025-04-25 11:06:02 +02:00
auto ensembles = RimProject::current()->summaryEnsembles();
2022-06-30 18:23:45 +02:00
if ( !ensembles.empty() )
selectedEnsembles.push_back( ensembles.front() );
else
{
auto summaryCases = RimProject::current()->allSummaryCases();
if ( !summaryCases.empty() ) selectedIndividualSummaryCases.push_back( summaryCases.front() );
}
}
2022-06-30 18:23:45 +02:00
else
2021-12-23 09:30:36 +01:00
{
2022-06-30 18:23:45 +02:00
selectedCases( &selectedIndividualSummaryCases, &selectedEnsembles );
2021-12-23 09:30:36 +01:00
}
2022-06-30 18:23:45 +02:00
bool skipCreationOfPlotBasedOnPreferences = false;
2025-02-12 13:06:58 +01:00
RiaSummaryPlotTools::createAndAppendDefaultSummaryMultiPlot( selectedIndividualSummaryCases,
selectedEnsembles,
skipCreationOfPlotBasedOnPreferences );
2022-03-04 10:52:17 +01:00
}
2021-12-23 09:30:36 +01:00
2022-03-04 10:52:17 +01:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryMultiPlotFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "New Summary Plot" );
2022-03-04 10:52:17 +01:00
actionToSetup->setIcon( QIcon( ":/MultiPlot16x16.png" ) );
2021-12-23 09:30:36 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryMultiPlotCollection* RicNewSummaryMultiPlotFeature::selectedCollection( const std::vector<caf::PdmUiItem*>& items )
2021-12-23 09:30:36 +01:00
{
for ( caf::PdmUiItem* uiItem : items )
2022-03-04 10:52:17 +01:00
{
RimSummaryMultiPlotCollection* coll = dynamic_cast<RimSummaryMultiPlotCollection*>( uiItem );
if ( coll ) return coll;
2022-03-04 10:52:17 +01:00
}
return nullptr;
2021-12-23 09:30:36 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewSummaryMultiPlotFeature::selectedCases( std::vector<RimSummaryCase*>* selectedIndividualSummaryCases,
std::vector<RimSummaryEnsemble*>* selectedEnsembles )
2021-12-23 09:30:36 +01:00
{
CAF_ASSERT( selectedIndividualSummaryCases && selectedEnsembles );
2022-03-04 10:52:17 +01:00
*selectedIndividualSummaryCases = caf::SelectionManager::instance()->objectsByTypeStrict<RimSummaryCase>();
if ( !selectedEnsembles->empty() )
{
return true;
}
// Second try selected summary cases
*selectedEnsembles = caf::SelectionManager::instance()->objectsByTypeStrict<RimSummaryEnsemble>();
2023-06-26 13:12:41 +02:00
return !selectedIndividualSummaryCases->empty();
2021-12-23 09:30:36 +01:00
}