From 381ff37dfb1e9dc1334bcdc8e9c83831199e525c Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 18 Sep 2023 12:54:32 +0200 Subject: [PATCH] Support cross plot curves in plot templates --- .../RicSaveMultiPlotTemplateFeature.cpp | 22 +++++++++ .../RicSummaryPlotTemplateTools.cpp | 47 +++++++++++++++++-- .../RicSummaryPlotTemplateTools.h | 2 + 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp index 34fb9ffc08..80f0264f9f 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSaveMultiPlotTemplateFeature.cpp @@ -182,6 +182,28 @@ QString RicSaveMultiPlotTemplateFeature::createTextFromObject( RimSummaryMultiPl replaceStrings( sourceStrings, summaryFieldKeyword, RicSummaryPlotTemplateTools::placeholderTextForSummaryCase(), objectAsText ); } + { + std::set sourceStrings; + + const QString summaryFieldKeyword = RicSummaryPlotTemplateTools::summaryCaseXFieldKeyword(); + for ( const auto& curve : summaryPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) ) + { + if ( curve->axisTypeX() != RiaDefines::HorizontalAxisType::SUMMARY_VECTOR ) continue; + + auto fieldHandle = curve->findField( summaryFieldKeyword ); + if ( fieldHandle ) + { + auto reference = caf::PdmReferenceHelper::referenceFromFieldToObject( fieldHandle, curve->summaryCaseX() ); + + sourceStrings.insert( reference ); + } + + addresses.push_back( curve->summaryAddressX() ); + } + + replaceStrings( sourceStrings, summaryFieldKeyword, RicSummaryPlotTemplateTools::placeholderTextForSummaryCaseX(), objectAsText ); + } + { std::set ensembleReferenceStrings; diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp index a712c185bc..d1e042442a 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.cpp @@ -250,13 +250,13 @@ void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryPlot* auto summaryCurves = summaryPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ); for ( const auto& curve : summaryCurves ) { - auto fieldHandle = curve->findField( RicSummaryPlotTemplateTools::summaryCaseFieldKeyword() ); - if ( fieldHandle ) + auto summaryCaseHandle = curve->findField( RicSummaryPlotTemplateTools::summaryCaseFieldKeyword() ); + if ( summaryCaseHandle ) { bool conversionOk = false; const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCase(); - auto referenceString = fieldHandle->xmlCapability()->referenceString(); + auto referenceString = summaryCaseHandle->xmlCapability()->referenceString(); int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk ); if ( conversionOk && indexValue >= 0 && indexValue < static_cast( selectedSummaryCases.size() ) ) @@ -266,12 +266,37 @@ void RicSummaryPlotTemplateTools::setValuesForPlaceholders( RimSummaryPlot* } } + auto summaryCaseXHandle = curve->findField( RicSummaryPlotTemplateTools::summaryCaseXFieldKeyword() ); + if ( summaryCaseXHandle ) + { + bool conversionOk = false; + const QString placeholderString = RicSummaryPlotTemplateTools::placeholderTextForSummaryCaseX(); + + auto referenceString = summaryCaseXHandle->xmlCapability()->referenceString(); + int indexValue = RicSummaryPlotTemplateTools::findValueForKeyword( placeholderString, referenceString, &conversionOk ); + + if ( conversionOk && indexValue >= 0 && indexValue < static_cast( selectedSummaryCases.size() ) ) + { + auto summaryCase = selectedSummaryCases[static_cast( indexValue )]; + curve->setSummaryCaseX( summaryCase ); + } + } + // Replace placeholders with object names from selection auto curveAdr = curve->summaryAddressY(); setPlaceholderWellName( &curveAdr, wellNames ); setPlaceholderGroupName( &curveAdr, groupNames ); setPlaceholderRegion( &curveAdr, regions ); curve->setSummaryAddressY( curveAdr ); + + if ( curve->axisTypeX() == RiaDefines::HorizontalAxisType::SUMMARY_VECTOR ) + { + auto curveAdr = curve->summaryAddressX(); + setPlaceholderWellName( &curveAdr, wellNames ); + setPlaceholderGroupName( &curveAdr, groupNames ); + setPlaceholderRegion( &curveAdr, regions ); + curve->setSummaryAddressX( curveAdr ); + } } for ( const auto& curveSet : summaryPlot->curveSets() ) @@ -493,6 +518,14 @@ QString RicSummaryPlotTemplateTools::summaryCaseFieldKeyword() return "SummaryCase"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicSummaryPlotTemplateTools::summaryCaseXFieldKeyword() +{ + return "SummaryCaseX"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -509,6 +542,14 @@ QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCase() return "__CASE_NAME__"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicSummaryPlotTemplateTools::placeholderTextForSummaryCaseX() +{ + return "__CASE_NAME_X__"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h index 57df90477b..1476d3859d 100644 --- a/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h +++ b/ApplicationLibCode/Commands/PlotTemplateCommands/RicSummaryPlotTemplateTools.h @@ -51,9 +51,11 @@ class RicSummaryPlotTemplateTools static std::vector selectDefaultPlotTemplates( std::vector currentSelection ); static QString summaryCaseFieldKeyword(); + static QString summaryCaseXFieldKeyword(); static QString summaryGroupFieldKeyword(); static QString placeholderTextForSummaryCase(); + static QString placeholderTextForSummaryCaseX(); static QString placeholderTextForSummaryGroup(); static QString placeholderTextForWell(); static QString placeholderTextForGroup();