#4828 Summary Plot Templates : Support ensembles as plot data sources

This commit is contained in:
Magne Sjaastad 2019-10-04 18:46:30 +02:00
parent 3d3ad421dd
commit 2c73b2ed02
9 changed files with 152 additions and 78 deletions

View File

@ -40,7 +40,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromSelectionFeature, "RicCreatePlotFromSelect
//--------------------------------------------------------------------------------------------------
bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
{
return !selectedSummaryCases().empty();
bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty();
bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty();
return ( anySummaryCases || anySummaryCaseCollections );
}
//--------------------------------------------------------------------------------------------------
@ -49,10 +52,11 @@ bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
{
QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath();
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections );
}
//--------------------------------------------------------------------------------------------------
@ -63,14 +67,3 @@ void RicCreatePlotFromSelectionFeature::setupActionLook( QAction* actionToSetup
actionToSetup->setText( "Create Plot from Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicCreatePlotFromSelectionFeature::selectedSummaryCases() const
{
std::vector<RimSummaryCase*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}

View File

@ -33,7 +33,4 @@ protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
std::vector<RimSummaryCase*> selectedSummaryCases() const;
};

View File

@ -40,7 +40,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateByShortcutFeature, "RicCreatePlotF
//--------------------------------------------------------------------------------------------------
bool RicCreatePlotFromTemplateByShortcutFeature::isCommandEnabled()
{
return !selectedSummaryCases().empty();
bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty();
bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty();
return ( anySummaryCases || anySummaryCaseCollections );
}
//--------------------------------------------------------------------------------------------------
@ -68,10 +71,11 @@ void RicCreatePlotFromTemplateByShortcutFeature::onActionTriggered( bool isCheck
RiaApplication::instance()->preferences()->setDefaultPlotTemplatePath( fileName );
}
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections );
}
//--------------------------------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
#include "RicSummaryPlotTemplateTools.h"
#include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "cafSelectionManager.h"
@ -32,7 +33,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateFeature, "RicCreatePlotFromTemplat
//--------------------------------------------------------------------------------------------------
bool RicCreatePlotFromTemplateFeature::isCommandEnabled()
{
return !selectedSummaryCases().empty();
bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty();
bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty();
return ( anySummaryCases || anySummaryCaseCollections );
}
//--------------------------------------------------------------------------------------------------
@ -41,10 +45,12 @@ bool RicCreatePlotFromTemplateFeature::isCommandEnabled()
void RicCreatePlotFromTemplateFeature::onActionTriggered( bool isChecked )
{
QString fileName = userData().toString();
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases();
auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections );
}
//--------------------------------------------------------------------------------------------------
@ -55,14 +61,3 @@ void RicCreatePlotFromTemplateFeature::setupActionLook( QAction* actionToSetup )
actionToSetup->setText( "Create Plot from Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicCreatePlotFromTemplateFeature::selectedSummaryCases() const
{
std::vector<RimSummaryCase*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}

View File

@ -23,6 +23,7 @@
#include <vector>
class RimSummaryCase;
class RimSummaryCaseCollection;
//==================================================================================================
///
@ -35,7 +36,4 @@ protected:
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
private:
std::vector<RimSummaryCase*> selectedSummaryCases() const;
};

View File

@ -25,6 +25,8 @@
#include "RiaPreferences.h"
#include "RiaSummaryTools.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimProject.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
@ -139,6 +141,7 @@ QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summar
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot )
{
{
std::set<QString> caseReferenceStrings;
@ -161,6 +164,29 @@ QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summar
}
}
{
std::set<QString> ensembleReferenceStrings;
for ( const auto& curveSet : newSummaryPlot->ensembleCurveSetCollection()->curveSets() )
{
auto fieldHandle = curveSet->findField( "SummaryGroup" );
if ( fieldHandle )
{
auto reference = fieldHandle->xmlCapability()->referenceString();
ensembleReferenceStrings.insert( reference );
}
}
size_t index = 0;
for ( const auto& s : ensembleReferenceStrings )
{
QString ensembleName = QString( "ENSEMBLE_NAME %1" ).arg( index++ );
objectAsText.replace( s, ensembleName );
}
}
}
delete obj;
return objectAsText;

View File

@ -29,6 +29,8 @@
#include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "RimDialogData.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimSummaryCase.h"
@ -40,6 +42,7 @@
#include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include <QFile>
//--------------------------------------------------------------------------------------------------
@ -76,7 +79,9 @@ RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const Q
///
//--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
RimSummaryPlot* summaryPlot, const std::vector<RimSummaryCase*>& selectedSummaryCases )
RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles )
{
if ( summaryPlot )
{
@ -87,6 +92,7 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
summaryPlot->resolveReferencesRecursively();
summaryPlot->initAfterReadRecursively();
{
auto summaryCurves = summaryPlot->summaryCurves();
for ( const auto& curve : summaryCurves )
@ -125,6 +131,34 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
}
}
}
}
{
auto summaryCurves = summaryPlot->ensembleCurveSetCollection()->curveSets();
for ( const auto& curveSet : summaryCurves )
{
auto fieldHandle = curveSet->findField( "SummaryGroup" );
if ( fieldHandle )
{
auto referenceString = fieldHandle->xmlCapability()->referenceString();
auto stringList = referenceString.split( " " );
if ( stringList.size() == 2 )
{
QString indexAsString = stringList[1];
bool conversionOk = false;
auto index = indexAsString.toUInt( &conversionOk );
if ( conversionOk && index < selectedEnsembles.size() )
{
auto summaryCaseY = selectedEnsembles[index];
curveSet->setSummaryCaseCollection( summaryCaseY );
}
}
}
}
}
// TODO: Create additional curves in selected case count is larger than template count
@ -255,6 +289,28 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
return QString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCase*> RicSummaryPlotTemplateTools::selectedSummaryCases()
{
std::vector<RimSummaryCase*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimSummaryCaseCollection*> RicSummaryPlotTemplateTools::selectedSummaryCaseCollections()
{
std::vector<RimSummaryCaseCollection*> objects;
caf::SelectionManager::instance()->objectsByType( &objects );
return objects;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -30,6 +30,7 @@ class PdmObject;
class RimSummaryPlot;
class RimSummaryCase;
class RimSummaryCaseCollection;
class RifEclipseSummaryAddress;
//==================================================================================================
@ -40,7 +41,8 @@ class RicSummaryPlotTemplateTools
public:
static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName );
static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases );
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles );
static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot,
const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses,
@ -50,6 +52,9 @@ public:
static QString selectPlotTemplatePath();
static std::vector<RimSummaryCase*> selectedSummaryCases();
static std::vector<RimSummaryCaseCollection*> selectedSummaryCaseCollections();
private:
static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
const std::set<RifEclipseSummaryAddress>& allAddresses );

View File

@ -845,7 +845,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection()
menuBuilder << "RicCutReferencesToClipboardFeature";
menuBuilder << "Separator";
if ( dynamic_cast<RimSummaryCase*>( uiItem ) )
if ( dynamic_cast<RimSummaryCase*>( uiItem ) || dynamic_cast<RimSummaryCaseCollection*>( uiItem ) )
{
menuBuilder << "RicCreatePlotFromSelectionFeature";
menuBuilder << "RicCreatePlotFromTemplateByShortcutFeature";