From 62712997e805d09bd1bc55dd1bc9f5e6078a764a Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Mon, 10 Aug 2026 14:34:38 +0200 Subject: [PATCH] #14216 Assign created valve template back to the valve event and reuse it on re-apply If a valve event already has a valve template assigned, applying the event now reuses that template for the created well path valve instead of creating a new one. When no template is assigned, the template created from the event parameters is assigned back to the event, so the event UI shows the template in use and repeated applies no longer accumulate duplicate templates. --- .../WellEvents/RimWellEventTimeline.cpp | 55 +++++++++++-------- .../WellEvents/RimWellEventTimeline.h | 2 +- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.cpp b/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.cpp index dad65c6f3d..da7add7ae5 100644 --- a/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.cpp +++ b/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.cpp @@ -529,7 +529,7 @@ bool RimWellEventTimeline::applyPerfEvent( const RimWellEventPerf& event, RimWel //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RimWellEventTimeline::applyValveEvent( const RimWellEventValve& event, RimWellPath& wellPath ) +bool RimWellEventTimeline::applyValveEvent( RimWellEventValve& event, RimWellPath& wellPath ) { auto* perfCollection = wellPath.perforationIntervalCollection(); if ( !perfCollection ) @@ -597,34 +597,45 @@ bool RimWellEventTimeline::applyValveEvent( const RimWellEventValve& event, RimW // Map the event valve type to the RiaDefines type and find a matching template RiaDefines::WellPathComponentType valveComponentType = convertToValveType( event.valveType() ); - // Create a new valve template with the event's specific parameters - if ( RimProject* project = RimProject::current() ) + // Reuse the template assigned to the event; otherwise create one from the event's specific + // parameters and assign it back to the event so the UI shows the template in use + RimValveTemplate* tmpl = event.valveTemplate(); + if ( !tmpl ) { - auto collections = project->allValveTemplateCollections(); - if ( !collections.empty() ) + if ( RimProject* project = RimProject::current() ) { - auto* tmpl = new RimValveTemplate; - tmpl->setType( valveComponentType ); - - tmpl->setFlowCoefficient( event.flowCoefficient() ); - double orifice_mm = 2000.0 * std::sqrt( event.area() / cvf::PI_D ); - tmpl->setOrificeDiameter( orifice_mm ); - - if ( valveComponentType == RiaDefines::WellPathComponentType::AICD ) + auto collections = project->allValveTemplateCollections(); + if ( !collections.empty() ) { - tmpl->setAicdParameter( AICD_STRENGTH, event.aicdStrength() ); - tmpl->setAicdParameter( AICD_DENSITY_CALIB_FLUID, event.aicdDensityCalibFluid() ); - tmpl->setAicdParameter( AICD_VISCOSITY_CALIB_FLUID, event.aicdViscosityCalibFluid() ); - tmpl->setAicdParameter( AICD_VOL_FLOW_EXP, event.aicdVolFlowExp() ); - tmpl->setAicdParameter( AICD_VISOSITY_FUNC_EXP, event.aicdViscFuncExp() ); - } + tmpl = new RimValveTemplate; + tmpl->setType( valveComponentType ); - tmpl->setUserLabel( QString( "Event Valve %1" ).arg( event.measuredDepth() ) ); - collections.front()->addItem( tmpl ); - valve->setValveTemplate( tmpl ); + tmpl->setFlowCoefficient( event.flowCoefficient() ); + double orifice_mm = 2000.0 * std::sqrt( event.area() / cvf::PI_D ); + tmpl->setOrificeDiameter( orifice_mm ); + + if ( valveComponentType == RiaDefines::WellPathComponentType::AICD ) + { + tmpl->setAicdParameter( AICD_STRENGTH, event.aicdStrength() ); + tmpl->setAicdParameter( AICD_DENSITY_CALIB_FLUID, event.aicdDensityCalibFluid() ); + tmpl->setAicdParameter( AICD_VISCOSITY_CALIB_FLUID, event.aicdViscosityCalibFluid() ); + tmpl->setAicdParameter( AICD_VOL_FLOW_EXP, event.aicdVolFlowExp() ); + tmpl->setAicdParameter( AICD_VISOSITY_FUNC_EXP, event.aicdViscFuncExp() ); + } + + tmpl->setUserLabel( QString( "Event Valve %1" ).arg( event.measuredDepth() ) ); + collections.front()->addItem( tmpl ); + event.setValveTemplate( tmpl ); + event.updateConnectedEditors(); + } } } + if ( tmpl ) + { + valve->setValveTemplate( tmpl ); + } + targetPerf->updateConnectedEditors(); return true; diff --git a/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.h b/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.h index 1d88fb985f..b6ba5b88b2 100644 --- a/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.h +++ b/ApplicationLibCode/ProjectDataModel/WellEvents/RimWellEventTimeline.h @@ -109,7 +109,7 @@ private: bool applyTubingEvent( const RimWellEventTubing& event, RimWellPath& wellPath ); bool applyPerfEvent( const RimWellEventPerf& event, RimWellPath& wellPath ); - bool applyValveEvent( const RimWellEventValve& event, RimWellPath& wellPath ); + bool applyValveEvent( RimWellEventValve& event, RimWellPath& wellPath ); std::vector filteredAndSortedEventsForUi() const;