#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() bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
{ {
return !selectedSummaryCases().empty(); bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty();
bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty();
return ( anySummaryCases || anySummaryCaseCollections );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -48,11 +51,12 @@ bool RicCreatePlotFromSelectionFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked ) void RicCreatePlotFromSelectionFeature::onActionTriggered( bool isChecked )
{ {
QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath(); QString fileName = RicSummaryPlotTemplateTools::selectPlotTemplatePath();
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases(); auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); 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->setText( "Create Plot from Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); 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; bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) 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() 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 ); RiaApplication::instance()->preferences()->setDefaultPlotTemplatePath( fileName );
} }
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases(); auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName );
RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases ); RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( newSummaryPlot, sumCases, sumCaseCollections );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -20,6 +20,7 @@
#include "RicSummaryPlotTemplateTools.h" #include "RicSummaryPlotTemplateTools.h"
#include "RimSummaryCase.h" #include "RimSummaryCase.h"
#include "RimSummaryCaseCollection.h"
#include "cafSelectionManager.h" #include "cafSelectionManager.h"
@ -32,7 +33,10 @@ CAF_CMD_SOURCE_INIT( RicCreatePlotFromTemplateFeature, "RicCreatePlotFromTemplat
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool RicCreatePlotFromTemplateFeature::isCommandEnabled() bool RicCreatePlotFromTemplateFeature::isCommandEnabled()
{ {
return !selectedSummaryCases().empty(); bool anySummaryCases = !RicSummaryPlotTemplateTools::selectedSummaryCases().empty();
bool anySummaryCaseCollections = !RicSummaryPlotTemplateTools::selectedSummaryCaseCollections().empty();
return ( anySummaryCases || anySummaryCaseCollections );
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -40,11 +44,13 @@ bool RicCreatePlotFromTemplateFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicCreatePlotFromTemplateFeature::onActionTriggered( bool isChecked ) void RicCreatePlotFromTemplateFeature::onActionTriggered( bool isChecked )
{ {
QString fileName = userData().toString(); QString fileName = userData().toString();
std::vector<RimSummaryCase*> sumCases = selectedSummaryCases(); auto sumCases = RicSummaryPlotTemplateTools::selectedSummaryCases();
auto sumCaseCollections = RicSummaryPlotTemplateTools::selectedSummaryCaseCollections();
RimSummaryPlot* newSummaryPlot = RicSummaryPlotTemplateTools::createPlotFromTemplateFile( fileName ); 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->setText( "Create Plot from Template" );
actionToSetup->setIcon( QIcon( ":/SummaryTemplate16x16.png" ) ); 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> #include <vector>
class RimSummaryCase; class RimSummaryCase;
class RimSummaryCaseCollection;
//================================================================================================== //==================================================================================================
/// ///
@ -35,7 +36,4 @@ protected:
bool isCommandEnabled() override; bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
private:
std::vector<RimSummaryCase*> selectedSummaryCases() const;
}; };

View File

@ -25,6 +25,8 @@
#include "RiaPreferences.h" #include "RiaPreferences.h"
#include "RiaSummaryTools.h" #include "RiaSummaryTools.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCurve.h" #include "RimSummaryCurve.h"
#include "RimSummaryPlot.h" #include "RimSummaryPlot.h"
@ -140,24 +142,48 @@ QString RicSavePlotTemplateFeature::createTextFromObject( RimSummaryPlot* summar
RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj ); RimSummaryPlot* newSummaryPlot = dynamic_cast<RimSummaryPlot*>( obj );
if ( newSummaryPlot ) if ( newSummaryPlot )
{ {
std::set<QString> caseReferenceStrings;
for ( const auto& curve : newSummaryPlot->summaryCurves() )
{ {
auto fieldHandle = curve->findField( "SummaryCase" ); std::set<QString> caseReferenceStrings;
if ( fieldHandle )
for ( const auto& curve : newSummaryPlot->summaryCurves() )
{ {
auto reference = fieldHandle->xmlCapability()->referenceString(); auto fieldHandle = curve->findField( "SummaryCase" );
caseReferenceStrings.insert( reference ); if ( fieldHandle )
{
auto reference = fieldHandle->xmlCapability()->referenceString();
caseReferenceStrings.insert( reference );
}
}
size_t index = 0;
for ( const auto& s : caseReferenceStrings )
{
QString caseName = QString( "CASE_NAME %1" ).arg( index++ );
objectAsText.replace( s, caseName );
} }
} }
size_t index = 0;
for ( const auto& s : caseReferenceStrings )
{ {
QString caseName = QString( "CASE_NAME %1" ).arg( index++ ); std::set<QString> ensembleReferenceStrings;
objectAsText.replace( s, caseName ); 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 );
}
} }
} }

View File

@ -29,6 +29,8 @@
#include "PlotTemplates/RimPlotTemplateFileItem.h" #include "PlotTemplates/RimPlotTemplateFileItem.h"
#include "RimDialogData.h" #include "RimDialogData.h"
#include "RimEnsembleCurveSet.h"
#include "RimEnsembleCurveSetCollection.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCase.h" #include "RimSummaryCase.h"
@ -40,6 +42,7 @@
#include "cafPdmUiPropertyViewDialog.h" #include "cafPdmUiPropertyViewDialog.h"
#include "cafSelectionManager.h"
#include <QFile> #include <QFile>
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -76,7 +79,9 @@ RimSummaryPlot* RicSummaryPlotTemplateTools::createPlotFromTemplateFile( const Q
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection( void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
RimSummaryPlot* summaryPlot, const std::vector<RimSummaryCase*>& selectedSummaryCases ) RimSummaryPlot* summaryPlot,
const std::vector<RimSummaryCase*>& selectedSummaryCases,
const std::vector<RimSummaryCaseCollection*>& selectedEnsembles )
{ {
if ( summaryPlot ) if ( summaryPlot )
{ {
@ -87,38 +92,40 @@ void RicSummaryPlotTemplateTools::appendSummaryPlotToPlotCollection(
summaryPlot->resolveReferencesRecursively(); summaryPlot->resolveReferencesRecursively();
summaryPlot->initAfterReadRecursively(); summaryPlot->initAfterReadRecursively();
auto summaryCurves = summaryPlot->summaryCurves();
for ( const auto& curve : summaryCurves )
{ {
auto fieldHandle = curve->findField( "SummaryCase" ); auto summaryCurves = summaryPlot->summaryCurves();
if ( fieldHandle )
for ( const auto& curve : summaryCurves )
{ {
auto referenceString = fieldHandle->xmlCapability()->referenceString(); auto fieldHandle = curve->findField( "SummaryCase" );
auto stringList = referenceString.split( " " ); if ( fieldHandle )
if ( stringList.size() == 2 )
{ {
QString indexAsString = stringList[1]; auto referenceString = fieldHandle->xmlCapability()->referenceString();
auto stringList = referenceString.split( " " );
bool conversionOk = false; if ( stringList.size() == 2 )
auto index = indexAsString.toUInt( &conversionOk );
if ( conversionOk && index < selectedSummaryCases.size() )
{ {
auto summaryCaseY = selectedSummaryCases[index]; QString indexAsString = stringList[1];
curve->setSummaryCaseY( summaryCaseY );
auto currentAddressY = curve->summaryAddressY(); bool conversionOk = false;
if ( summaryCaseY->summaryReader() && auto index = indexAsString.toUInt( &conversionOk );
!summaryCaseY->summaryReader()->hasAddress( currentAddressY ) )
if ( conversionOk && index < selectedSummaryCases.size() )
{ {
auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses(); auto summaryCaseY = selectedSummaryCases[index];
curve->setSummaryCaseY( summaryCaseY );
auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY, auto currentAddressY = curve->summaryAddressY();
allAddresses ); if ( summaryCaseY->summaryReader() &&
if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID ) !summaryCaseY->summaryReader()->hasAddress( currentAddressY ) )
{ {
curve->setSummaryAddressY( candidate ); auto allAddresses = summaryCaseY->summaryReader()->allResultAddresses();
auto candidate = RicSummaryPlotTemplateTools::firstAddressByQuantity( currentAddressY,
allAddresses );
if ( candidate.category() != RifEclipseSummaryAddress::SUMMARY_INVALID )
{
curve->setSummaryAddressY( candidate );
}
} }
} }
} }
@ -126,6 +133,33 @@ 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 // TODO: Create additional curves in selected case count is larger than template count
plotColl->updateConnectedEditors(); plotColl->updateConnectedEditors();
@ -255,6 +289,28 @@ QString RicSummaryPlotTemplateTools::selectPlotTemplatePath()
return QString(); 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 RimSummaryPlot;
class RimSummaryCase; class RimSummaryCase;
class RimSummaryCaseCollection;
class RifEclipseSummaryAddress; class RifEclipseSummaryAddress;
//================================================================================================== //==================================================================================================
@ -39,8 +40,9 @@ class RicSummaryPlotTemplateTools
{ {
public: public:
static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName ); static RimSummaryPlot* createPlotFromTemplateFile( const QString& fileName );
static void appendSummaryPlotToPlotCollection( RimSummaryPlot* summaryPlot, 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, static QString htmlTextFromPlotAndSelection( const RimSummaryPlot* templatePlot,
const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses, const std::set<RifEclipseSummaryAddress>& selectedSummaryAddresses,
@ -50,6 +52,9 @@ public:
static QString selectPlotTemplatePath(); static QString selectPlotTemplatePath();
static std::vector<RimSummaryCase*> selectedSummaryCases();
static std::vector<RimSummaryCaseCollection*> selectedSummaryCaseCollections();
private: private:
static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress, static RifEclipseSummaryAddress firstAddressByQuantity( const RifEclipseSummaryAddress& sourceAddress,
const std::set<RifEclipseSummaryAddress>& allAddresses ); const std::set<RifEclipseSummaryAddress>& allAddresses );

View File

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