Files
ResInsight/ApplicationLibCode/ProjectDataModelCommands/RimcSummaryPlotCollection.cpp
T

216 lines
9.5 KiB
C++
Raw Normal View History

2020-03-13 08:34:05 +01:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- Equinor ASA
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
2020-03-13 08:34:05 +01:00
#include "RimcSummaryPlotCollection.h"
2025-02-12 13:06:58 +01:00
#include "Summary/RiaSummaryPlotTools.h"
#include "SummaryPlotCommands/RicNewDefaultSummaryPlotFeature.h"
2020-03-13 08:34:05 +01:00
#include "SummaryPlotCommands/RicNewSummaryEnsembleCurveSetFeature.h"
#include "SummaryPlotCommands/RicSummaryPlotFeatureImpl.h"
2022-03-11 13:24:01 +01:00
#include "RiaTextStringTools.h"
2020-03-13 08:34:05 +01:00
#include "RimSummaryCase.h"
#include "RimSummaryEnsemble.h"
#include "RimSummaryMultiPlot.h"
2020-03-13 08:34:05 +01:00
#include "RimSummaryPlot.h"
#include "RimSummaryPlotCollection.h"
#include "RifSummaryReaderInterface.h"
2020-08-21 11:13:07 +02:00
#include "cafPdmAbstractFieldScriptingCapability.h"
#include "cafPdmFieldScriptingCapability.h"
2020-03-13 08:34:05 +01:00
#include <QStringList>
#include <algorithm>
#include <iterator>
2020-03-13 08:34:05 +01:00
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimSummaryPlotCollection, RimcSummaryPlotCollection_newSummaryPlot, "NewSummaryPlot" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimcSummaryPlotCollection_newSummaryPlot::RimcSummaryPlotCollection_newSummaryPlot( caf::PdmObjectHandle* self )
: caf::PdmObjectCreationMethod( self )
2020-03-13 08:34:05 +01:00
{
CAF_PDM_InitObject( "Create Summary Plot", "", "", "Create a new Summary Plot" );
2020-08-21 11:13:07 +02:00
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" );
2023-02-26 10:48:40 +01:00
CAF_PDM_InitScriptableFieldNoDefault( &m_addressString, "Address", "", "", "", "Formatted address string specifying the plot options" );
2020-03-13 08:34:05 +01:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2025-05-07 11:34:59 +02:00
std::expected<caf::PdmObjectHandle*, QString> RimcSummaryPlotCollection_newSummaryPlot::execute()
2020-03-13 08:34:05 +01:00
{
2026-10-16 08:53:06 +02:00
auto ensembles = allEnsembles( m_ensemble(), m_ensembles );
if ( !m_summaryCases().empty() && !ensembles.empty() )
{
return std::unexpected( "Specify either summary cases or ensembles, not both." );
}
RimSummaryPlot* newPlot = createSummaryPlot( m_summaryCases.ptrReferencedObjectsByType(), 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; } );
2020-03-13 08:34:05 +01:00
RimSummaryPlot* newPlot = nullptr;
if ( !ensembles.empty() )
2020-03-13 08:34:05 +01:00
{
if ( !addressStrings.empty() )
{
// Summary addresses are created on demand, make sure they are available before applying address filters
for ( auto ensemble : ensembles )
{
for ( auto summaryCase : ensemble->allSummaryCases() )
{
if ( auto reader = summaryCase ? summaryCase->summaryReader() : nullptr ) reader->createAddressesIfRequired();
}
}
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForEnsembles( ensembles, addressStrings );
2020-03-13 08:34:05 +01:00
}
else
{
newPlot = RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( ensembles );
2020-03-13 08:34:05 +01:00
}
}
if ( !summaryCases.empty() )
2020-03-13 08:34:05 +01:00
{
if ( !addressStrings.empty() )
{
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForCases( summaryCases, addressStrings );
2020-03-13 08:34:05 +01:00
}
else
{
newPlot = RicNewDefaultSummaryPlotFeature::createFromSummaryCases( summaryCases );
2020-03-13 08:34:05 +01:00
}
}
return newPlot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimcSummaryPlotCollection_newSummaryPlot::classKeywordReturnedType() const
2020-03-13 08:34:05 +01:00
{
return RimSummaryPlot::classKeywordStatic();
2020-03-13 08:34:05 +01:00
}
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." );
2026-10-16 08:53:06 +02:00
if ( !m_summaryCases().empty() && !m_ensembles().empty() )
{
return std::unexpected( "Specify either summary cases or ensembles, not both." );
}
// 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();
}