mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5084 Rework RicNewSummaryPlotFeature to create ensemble plots when that makes sense
This commit is contained in:
parent
e199182e2f
commit
a629a957cc
@ -83,7 +83,7 @@ void RicImportEnsembleFeature::onActionTriggered( bool isChecked )
|
|||||||
|
|
||||||
if ( ensemble )
|
if ( ensemble )
|
||||||
{
|
{
|
||||||
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate( ensemble );
|
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( {ensemble} );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<RimCase*> allCases;
|
std::vector<RimCase*> allCases;
|
||||||
|
@ -75,7 +75,7 @@ RimEnsembleCurveSet* RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet( R
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate( RimSummaryCaseCollection* ensemble )
|
void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles )
|
||||||
{
|
{
|
||||||
RiaGuiApplication* app = RiaGuiApplication::instance();
|
RiaGuiApplication* app = RiaGuiApplication::instance();
|
||||||
RimProject* proj = app->project();
|
RimProject* proj = app->project();
|
||||||
@ -83,14 +83,20 @@ void RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetAndUpdate( RimSu
|
|||||||
RimSummaryPlotCollection* summaryPlotCollection = proj->mainPlotCollection->summaryPlotCollection();
|
RimSummaryPlotCollection* summaryPlotCollection = proj->mainPlotCollection->summaryPlotCollection();
|
||||||
RimSummaryPlot* plot = summaryPlotCollection->createSummaryPlotWithAutoTitle();
|
RimSummaryPlot* plot = summaryPlotCollection->createSummaryPlotWithAutoTitle();
|
||||||
|
|
||||||
RimEnsembleCurveSet* curveSet = RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet( plot, ensemble );
|
RimEnsembleCurveSet* firstCurveSetCreated = nullptr;
|
||||||
|
for ( RimSummaryCaseCollection* ensemble : ensembles )
|
||||||
|
{
|
||||||
|
RimEnsembleCurveSet* curveSet = RicNewSummaryEnsembleCurveSetFeature::addDefaultCurveSet( plot, ensemble );
|
||||||
|
if ( !firstCurveSetCreated ) firstCurveSetCreated = curveSet;
|
||||||
|
}
|
||||||
|
|
||||||
plot->loadDataAndUpdate();
|
plot->loadDataAndUpdate();
|
||||||
summaryPlotCollection->updateConnectedEditors();
|
summaryPlotCollection->updateConnectedEditors();
|
||||||
|
|
||||||
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
|
RiuPlotMainWindow* mainPlotWindow = app->getOrCreateAndShowMainPlotWindow();
|
||||||
if ( mainPlotWindow )
|
if ( mainPlotWindow )
|
||||||
{
|
{
|
||||||
mainPlotWindow->selectAsCurrentItem( curveSet );
|
mainPlotWindow->selectAsCurrentItem( firstCurveSetCreated );
|
||||||
mainPlotWindow->updateSummaryPlotToolBar();
|
mainPlotWindow->updateSummaryPlotToolBar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class RicNewSummaryEnsembleCurveSetFeature : public caf::CmdFeature
|
|||||||
CAF_CMD_HEADER_INIT;
|
CAF_CMD_HEADER_INIT;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void createPlotForCurveSetAndUpdate( RimSummaryCaseCollection* ensemble );
|
static void createPlotForCurveSetsAndUpdate( std::vector<RimSummaryCaseCollection*> ensembles );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Overrides
|
// Overrides
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "RiaSummaryTools.h"
|
#include "RiaSummaryTools.h"
|
||||||
|
|
||||||
#include "RicEditSummaryPlotFeature.h"
|
#include "RicEditSummaryPlotFeature.h"
|
||||||
|
#include "RicNewSummaryEnsembleCurveSetFeature.h"
|
||||||
#include "RicSummaryCurveCreator.h"
|
#include "RicSummaryCurveCreator.h"
|
||||||
#include "RicSummaryCurveCreatorDialog.h"
|
#include "RicSummaryCurveCreatorDialog.h"
|
||||||
|
|
||||||
@ -155,26 +156,56 @@ void RicNewSummaryPlotFeature::setupActionLook( QAction* actionToSetup )
|
|||||||
|
|
||||||
CAF_CMD_SOURCE_INIT( RicNewDefaultSummaryPlotFeature, "RicNewDefaultSummaryPlotFeature" );
|
CAF_CMD_SOURCE_INIT( RicNewDefaultSummaryPlotFeature, "RicNewDefaultSummaryPlotFeature" );
|
||||||
|
|
||||||
std::pair<RimSummaryPlotCollection*, std::vector<RimSummaryCase*>> extractSumPlotCollectionOrSelectedSumCasesFromSelection()
|
void extractPlotObjectsFromSelection( std::vector<RimSummaryCase*>* selectedIndividualSummaryCases,
|
||||||
|
std::vector<RimSummaryCaseCollection*>* selectedEnsembles )
|
||||||
{
|
{
|
||||||
std::vector<RimSummaryCase*> selectedSumCases;
|
CAF_ASSERT( selectedIndividualSummaryCases && selectedEnsembles );
|
||||||
RimSummaryPlotCollection* sumPlotColl = nullptr;
|
|
||||||
|
|
||||||
std::vector<caf::PdmUiItem*> selectedItems;
|
// First try selected ensembles
|
||||||
caf::SelectionManager::instance()->selectedItems( selectedItems );
|
caf::SelectionManager::instance()->objectsByTypeStrict( selectedEnsembles );
|
||||||
|
if ( !selectedEnsembles->empty() )
|
||||||
if ( selectedItems.size() )
|
|
||||||
{
|
{
|
||||||
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( selectedItems[0] );
|
return;
|
||||||
sumPlotColl = RiaSummaryTools::parentSummaryPlotCollection( selObj );
|
}
|
||||||
|
// Second try selected summary cases
|
||||||
|
caf::SelectionManager::instance()->objectsByTypeStrict( selectedIndividualSummaryCases );
|
||||||
|
if ( !selectedIndividualSummaryCases->empty() )
|
||||||
|
{
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !sumPlotColl )
|
RimSummaryPlotCollection* sumPlotColl =
|
||||||
{
|
caf::SelectionManager::instance()->selectedItemAncestorOfType<RimSummaryPlotCollection>();
|
||||||
caf::SelectionManager::instance()->objectsByTypeStrict( &selectedSumCases );
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::make_pair( sumPlotColl, selectedSumCases );
|
if ( sumPlotColl )
|
||||||
|
{
|
||||||
|
RimSummaryCase* firstIndividualSummaryCase = nullptr;
|
||||||
|
RimSummaryCaseCollection* firstEnsemble = nullptr;
|
||||||
|
|
||||||
|
auto sumCaseVector = RiaApplication::instance()->project()->allSummaryCases();
|
||||||
|
for ( RimSummaryCase* summaryCase : sumCaseVector )
|
||||||
|
{
|
||||||
|
RimSummaryCaseCollection* parentEnsemble = nullptr;
|
||||||
|
summaryCase->firstAncestorOrThisOfType( parentEnsemble );
|
||||||
|
if ( !parentEnsemble && !firstIndividualSummaryCase )
|
||||||
|
{
|
||||||
|
firstIndividualSummaryCase = summaryCase;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if ( parentEnsemble && !firstEnsemble )
|
||||||
|
{
|
||||||
|
firstEnsemble = parentEnsemble;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( firstIndividualSummaryCase )
|
||||||
|
{
|
||||||
|
selectedIndividualSummaryCases->push_back( firstIndividualSummaryCase );
|
||||||
|
}
|
||||||
|
else if ( firstEnsemble )
|
||||||
|
{
|
||||||
|
selectedEnsembles->push_back( firstEnsemble );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -182,9 +213,12 @@ std::pair<RimSummaryPlotCollection*, std::vector<RimSummaryCase*>> extractSumPlo
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
bool RicNewDefaultSummaryPlotFeature::isCommandEnabled()
|
bool RicNewDefaultSummaryPlotFeature::isCommandEnabled()
|
||||||
{
|
{
|
||||||
auto sumPlotSumCasesPair = extractSumPlotCollectionOrSelectedSumCasesFromSelection();
|
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
|
||||||
|
std::vector<RimSummaryCaseCollection*> selectedEnsembles;
|
||||||
|
|
||||||
return sumPlotSumCasesPair.first || sumPlotSumCasesPair.second.size();
|
extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles );
|
||||||
|
|
||||||
|
return !( selectedIndividualSummaryCases.empty() && selectedEnsembles.empty() );
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -192,31 +226,17 @@ bool RicNewDefaultSummaryPlotFeature::isCommandEnabled()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked )
|
void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked )
|
||||||
{
|
{
|
||||||
auto sumPlotSumCasesPair = extractSumPlotCollectionOrSelectedSumCasesFromSelection();
|
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
|
||||||
|
std::vector<RimSummaryCaseCollection*> selectedEnsembles;
|
||||||
|
extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles );
|
||||||
|
|
||||||
std::vector<RimSummaryCase*> summaryCasesToUse;
|
if ( !selectedIndividualSummaryCases.empty() )
|
||||||
|
|
||||||
if ( sumPlotSumCasesPair.first )
|
|
||||||
{
|
|
||||||
auto sumCaseVector = RiaApplication::instance()->project()->allSummaryCases();
|
|
||||||
|
|
||||||
if ( sumCaseVector.size() )
|
|
||||||
{
|
|
||||||
summaryCasesToUse.push_back( sumCaseVector[0] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( sumPlotSumCasesPair.second.size() )
|
|
||||||
{
|
|
||||||
summaryCasesToUse = sumPlotSumCasesPair.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( summaryCasesToUse.size() )
|
|
||||||
{
|
{
|
||||||
RimSummaryPlotCollection* sumPlotColl =
|
RimSummaryPlotCollection* sumPlotColl =
|
||||||
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
RiaApplication::instance()->project()->mainPlotCollection()->summaryPlotCollection();
|
||||||
RimSummaryPlot* newPlot = sumPlotColl->createSummaryPlotWithAutoTitle();
|
RimSummaryPlot* newPlot = sumPlotColl->createSummaryPlotWithAutoTitle();
|
||||||
|
|
||||||
for ( RimSummaryCase* sumCase : summaryCasesToUse )
|
for ( RimSummaryCase* sumCase : selectedIndividualSummaryCases )
|
||||||
{
|
{
|
||||||
RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase );
|
RicSummaryPlotFeatureImpl::addDefaultCurvesToPlot( newPlot, sumCase );
|
||||||
}
|
}
|
||||||
@ -229,6 +249,11 @@ void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked )
|
|||||||
RiuPlotMainWindowTools::setExpanded( newPlot );
|
RiuPlotMainWindowTools::setExpanded( newPlot );
|
||||||
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
|
RiuPlotMainWindowTools::selectAsCurrentItem( newPlot );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CAF_ASSERT( !selectedEnsembles.empty() );
|
||||||
|
RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( selectedEnsembles );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -236,6 +261,18 @@ void RicNewDefaultSummaryPlotFeature::onActionTriggered( bool isChecked )
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup )
|
void RicNewDefaultSummaryPlotFeature::setupActionLook( QAction* actionToSetup )
|
||||||
{
|
{
|
||||||
actionToSetup->setText( "New Summary Plot" );
|
std::vector<RimSummaryCase*> selectedIndividualSummaryCases;
|
||||||
|
std::vector<RimSummaryCaseCollection*> selectedEnsembles;
|
||||||
|
|
||||||
|
extractPlotObjectsFromSelection( &selectedIndividualSummaryCases, &selectedEnsembles );
|
||||||
|
|
||||||
|
if ( !selectedIndividualSummaryCases.empty() )
|
||||||
|
{
|
||||||
|
actionToSetup->setText( "New Summary Plot" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
actionToSetup->setText( "New Ensemble Summary Plot" );
|
||||||
|
}
|
||||||
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
|
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user