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;