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.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2021-02-19 15:11:15 +01:00
|
|
|
|
2020-03-13 08:34:05 +01:00
|
|
|
#include "RimcSummaryPlotCollection.h"
|
|
|
|
|
|
2025-02-12 13:06:58 +01:00
|
|
|
#include "Summary/RiaSummaryPlotTools.h"
|
2021-02-19 15:11:15 +01:00
|
|
|
#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"
|
2024-07-29 15:38:17 +02:00
|
|
|
#include "RimSummaryEnsemble.h"
|
2026-10-14 15:22:20 +02:00
|
|
|
#include "RimSummaryMultiPlot.h"
|
2020-03-13 08:34:05 +01:00
|
|
|
#include "RimSummaryPlot.h"
|
|
|
|
|
#include "RimSummaryPlotCollection.h"
|
|
|
|
|
|
2026-09-04 11:37:40 +02:00
|
|
|
#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>
|
|
|
|
|
|
2026-10-14 15:22:20 +02:00
|
|
|
#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 )
|
2025-06-16 11:05:00 +02:00
|
|
|
: caf::PdmObjectCreationMethod( self )
|
2020-03-13 08:34:05 +01:00
|
|
|
{
|
|
|
|
|
CAF_PDM_InitObject( "Create Summary Plot", "", "", "Create a new Summary Plot" );
|
2025-06-16 11:05:00 +02:00
|
|
|
|
2020-08-21 11:13:07 +02:00
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_summaryCases, "SummaryCases", "", "", "", "Summary Cases" );
|
|
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_ensemble, "Ensemble", "", "", "", "Ensemble" );
|
2026-10-14 15:22:20 +02:00
|
|
|
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() );
|
2026-10-14 15:22:20 +02:00
|
|
|
|
|
|
|
|
// 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;
|
2026-10-14 15:22:20 +02:00
|
|
|
|
|
|
|
|
if ( !ensembles.empty() )
|
2020-03-13 08:34:05 +01:00
|
|
|
{
|
|
|
|
|
if ( !addressStrings.empty() )
|
|
|
|
|
{
|
2026-09-04 11:37:40 +02:00
|
|
|
// Summary addresses are created on demand, make sure they are available before applying address filters
|
2026-10-14 15:22:20 +02:00
|
|
|
for ( auto ensemble : ensembles )
|
2026-09-04 11:37:40 +02:00
|
|
|
{
|
2026-10-14 15:22:20 +02:00
|
|
|
for ( auto summaryCase : ensemble->allSummaryCases() )
|
|
|
|
|
{
|
|
|
|
|
if ( auto reader = summaryCase ? summaryCase->summaryReader() : nullptr ) reader->createAddressesIfRequired();
|
|
|
|
|
}
|
2026-09-04 11:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-14 15:22:20 +02:00
|
|
|
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForEnsembles( ensembles, addressStrings );
|
2020-03-13 08:34:05 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-10-14 15:22:20 +02:00
|
|
|
newPlot = RicNewSummaryEnsembleCurveSetFeature::createPlotForCurveSetsAndUpdate( ensembles );
|
2020-03-13 08:34:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-10-14 15:22:20 +02:00
|
|
|
if ( !summaryCases.empty() )
|
2020-03-13 08:34:05 +01:00
|
|
|
{
|
|
|
|
|
if ( !addressStrings.empty() )
|
|
|
|
|
{
|
2022-04-06 17:39:07 +02:00
|
|
|
newPlot = RicSummaryPlotFeatureImpl::createSummaryPlotForCases( summaryCases, addressStrings );
|
2020-03-13 08:34:05 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-04-06 17:39:07 +02:00
|
|
|
newPlot = RicNewDefaultSummaryPlotFeature::createFromSummaryCases( summaryCases );
|
2020-03-13 08:34:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return newPlot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2025-06-16 11:05:00 +02:00
|
|
|
QString RimcSummaryPlotCollection_newSummaryPlot::classKeywordReturnedType() const
|
2020-03-13 08:34:05 +01:00
|
|
|
{
|
2025-06-16 11:05:00 +02:00
|
|
|
return RimSummaryPlot::classKeywordStatic();
|
2020-03-13 08:34:05 +01:00
|
|
|
}
|
2026-10-14 15:22:20 +02: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." );
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-14 15:22:20 +02:00
|
|
|
// 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();
|
|
|
|
|
}
|