mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 15:10:22 -05:00
#8735: Add SummaryPlotCollection multi plot commands and subplots
This commit is contained in:
1 parent
1272ec7bd0
commit
fac5eb5f3b
9 files changed
+308
-22
No files matched your search
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryEnsemble.h"
|
||||
#include "RimSummaryMultiPlot.h"
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RimSummaryPlotCollection.h"
|
||||
|
||||
@@ -37,6 +38,9 @@
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSummaryPlotCollection, RimcSummaryPlotCollection_newSummaryPlot, "NewSummaryPlot" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -49,6 +53,7 @@ RimcSummaryPlotCollection_newSummaryPlot::RimcSummaryPlotCollection_newSummaryPl
|
||||
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_summaryCases, "SummaryCases", "", "", "", "Summary Cases" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_ensemble, "Ensemble", "", "", "", "Ensemble" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_ensembles, "Ensembles", "", "", "", "Ensembles plotted together in the same plot" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_addressString, "Address", "", "", "", "Formatted address string specifying the plot options" );
|
||||
}
|
||||
|
||||
@@ -57,31 +62,74 @@ RimcSummaryPlotCollection_newSummaryPlot::RimcSummaryPlotCollection_newSummaryPl
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcSummaryPlotCollection_newSummaryPlot::execute()
|
||||
{
|
||||
QStringList addressStrings = RiaTextStringTools::splitSkipEmptyParts( m_addressString(), ";" );
|
||||
RimSummaryPlot* newPlot =
|
||||
createSummaryPlot( m_summaryCases.ptrReferencedObjectsByType(), allEnsembles( m_ensemble(), m_ensembles ), m_addressString() );
|
||||
|
||||
// Plots created without an address are already added to a multi plot
|
||||
if ( newPlot && !newPlot->firstAncestorOrThisOfType<RimSummaryMultiPlot>() )
|
||||
{
|
||||
newPlot->loadDataAndUpdate();
|
||||
RiaSummaryPlotTools::createAndAppendSingleSummaryMultiPlot( newPlot );
|
||||
}
|
||||
|
||||
return newPlot;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimSummaryEnsemble*>
|
||||
RimcSummaryPlotCollection_newSummaryPlot::allEnsembles( RimSummaryEnsemble* ensemble,
|
||||
const caf::PdmPtrArrayField<RimSummaryEnsemble*>& ensembleArray )
|
||||
{
|
||||
std::vector<RimSummaryEnsemble*> ensembles = ensembleArray.ptrReferencedObjectsByType();
|
||||
if ( ensemble && std::find( ensembles.begin(), ensembles.end(), ensemble ) == ensembles.end() )
|
||||
{
|
||||
ensembles.insert( ensembles.begin(), ensemble );
|
||||
}
|
||||
return ensembles;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimSummaryPlot* RimcSummaryPlotCollection_newSummaryPlot::createSummaryPlot( const std::vector<RimSummaryCase*>& summaryCases,
|
||||
const std::vector<RimSummaryEnsemble*>& ensembleCandidates,
|
||||
const QString& address )
|
||||
{
|
||||
QStringList addressStrings = RiaTextStringTools::splitSkipEmptyParts( address, ";" );
|
||||
|
||||
// References that cannot be resolved are returned as nullptr
|
||||
std::vector<RimSummaryEnsemble*> ensembles;
|
||||
std::copy_if( ensembleCandidates.begin(),
|
||||
ensembleCandidates.end(),
|
||||
std::back_inserter( ensembles ),
|
||||
[]( auto e ) { return e != nullptr; } );
|
||||
|
||||
RimSummaryPlot* newPlot = nullptr;
|
||||
if ( m_ensemble )
|
||||
|
||||
if ( !ensembles.empty() )
|
||||
{
|
||||
if ( !addressStrings.empty() )
|
||||
{
|
||||
auto summaryCases = m_ensemble->allSummaryCases();
|
||||
|
||||
// Summary addresses are created on demand, make sure they are available before applying address filters
|
||||
for ( auto summaryCase : summaryCases )
|
||||
for ( auto ensemble : ensembles )
|
||||
{
|
||||
if ( auto reader = summaryCase ? summaryCase->summaryReader() : nullptr ) reader->createAddressesIfRequired();
|
||||
for ( auto summaryCase : ensemble->allSummaryCases() )
|
||||
{
|
||||
if ( auto reader = summaryCase ? summaryCase->summaryReader() : nullptr ) reader->createAddressesIfRequired();
|
||||
}
|
||||
}
|
||||
|
||||
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForEnsemble( summaryCases, m_ensemble, addressStrings );
|
||||
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForEnsembles( ensembles, addressStrings );
|
||||
}
|
||||
else
|
||||
{
|
||||
newPlot = RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( { m_ensemble } );
|
||||
newPlot = RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( ensembles );
|
||||
}
|
||||
}
|
||||
if ( !m_summaryCases.empty() )
|
||||
if ( !summaryCases.empty() )
|
||||
{
|
||||
std::vector<RimSummaryCase*> summaryCases = m_summaryCases.ptrReferencedObjectsByType();
|
||||
if ( !addressStrings.empty() )
|
||||
{
|
||||
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForCases( summaryCases, addressStrings );
|
||||
@@ -92,12 +140,6 @@ std::expected<caf::PdmObjectHandle*, QString> RimcSummaryPlotCollection_newSumma
|
||||
}
|
||||
}
|
||||
|
||||
if ( newPlot )
|
||||
{
|
||||
newPlot->loadDataAndUpdate();
|
||||
RiaSummaryPlotTools::createAndAppendSingleSummaryMultiPlot( newPlot );
|
||||
}
|
||||
|
||||
return newPlot;
|
||||
}
|
||||
|
||||
@@ -108,3 +150,57 @@ QString RimcSummaryPlotCollection_newSummaryPlot::classKeywordReturnedType() con
|
||||
{
|
||||
return RimSummaryPlot::classKeywordStatic();
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSummaryPlotCollection, RimcSummaryPlotCollection_newSummaryMultiPlot, "NewSummaryMultiPlot" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimcSummaryPlotCollection_newSummaryMultiPlot::RimcSummaryPlotCollection_newSummaryMultiPlot( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectCreationMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Create Summary Multi Plot", "", "", "Create a new multi plot with one subplot for each address" );
|
||||
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_summaryCases, "SummaryCases", "", "", "", "Summary Cases" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_ensembles, "Ensembles", "", "", "", "Ensembles plotted together in each subplot" );
|
||||
CAF_PDM_InitScriptableFieldNoDefault( &m_addressStrings, "Addresses", "", "", "", "One formatted address string for each subplot" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimcSummaryPlotCollection_newSummaryMultiPlot::execute()
|
||||
{
|
||||
if ( m_addressStrings().empty() ) return std::unexpected( "Specify at least one address." );
|
||||
|
||||
// A subplot without an address is created in a separate multi plot
|
||||
for ( const QString& address : m_addressStrings() )
|
||||
{
|
||||
if ( RiaTextStringTools::splitSkipEmptyParts( address, ";" ).isEmpty() ) return std::unexpected( "Addresses cannot be empty." );
|
||||
}
|
||||
|
||||
std::vector<RimSummaryPlot*> plots;
|
||||
for ( const QString& address : m_addressStrings() )
|
||||
{
|
||||
RimSummaryPlot* plot = RimcSummaryPlotCollection_newSummaryPlot::createSummaryPlot( m_summaryCases.ptrReferencedObjectsByType(),
|
||||
m_ensembles.ptrReferencedObjectsByType(),
|
||||
address );
|
||||
if ( plot )
|
||||
{
|
||||
plot->loadDataAndUpdate();
|
||||
plots.push_back( plot );
|
||||
}
|
||||
}
|
||||
|
||||
if ( plots.empty() ) return std::unexpected( "Unable to create subplots. Specify summary cases or ensembles." );
|
||||
|
||||
return RiaSummaryPlotTools::createAndAppendSummaryMultiPlot( plots );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimcSummaryPlotCollection_newSummaryMultiPlot::classKeywordReturnedType() const
|
||||
{
|
||||
return RimSummaryMultiPlot::classKeywordStatic();
|
||||
}
|
||||
Reference in new issue
Block a user