From 5a7129ffdfb6dcd3c22c0f0491d5440c891b9bb2 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 7 Apr 2020 15:07:52 +0200 Subject: [PATCH] #5779 Create Well Path : Add auto generated target at sea level --- .../RimWellPathGeometryDef.cpp | 101 +++++++++--------- .../ProjectDataModel/RimWellPathGeometryDef.h | 14 ++- .../ProjectDataModel/RimWellPathTarget.cpp | 8 ++ .../ProjectDataModel/RimWellPathTarget.h | 1 + 4 files changed, 66 insertions(+), 58 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp index 5187f25a87..886024ab1e 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp @@ -45,18 +45,6 @@ #include "cafPdmUiTreeOrdering.h" #include "cvfGeometryTools.h" -namespace caf -{ -template <> -void caf::AppEnum::setUp() -{ - addItem( RimWellPathGeometryDef::START_AT_FIRST_TARGET, "START_AT_FIRST_TARGET", "Start at First Target" ); - addItem( RimWellPathGeometryDef::START_AT_SURFACE, "START_AT_SURFACE", "Start at Surface" ); - - setDefault( RimWellPathGeometryDef::START_AT_SURFACE ); -} -} // namespace caf - CAF_PDM_SOURCE_INIT( RimWellPathGeometryDef, "WellPathGeometryDef" ); //-------------------------------------------------------------------------------------------------- @@ -79,10 +67,19 @@ RimWellPathGeometryDef::RimWellPathGeometryDef() m_wellTargets.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::TOP ); m_wellTargets.uiCapability()->setCustomContextMenuEnabled( true ); + CAF_PDM_InitField( &m_useAutoGeneratedTargetAtSeaLevel, + "UseAutoGeneratedTargetAtSeaLevel", + true, + "Generate Target at Sea Level", + "", + "", + "" ); + CAF_PDM_InitField( &m_pickPointsEnabled, "m_pickPointsEnabled", false, "", "", "", "" ); caf::PdmUiPushButtonEditor::configureEditorForField( &m_pickPointsEnabled ); - CAF_PDM_InitFieldNoDefault( &m_wellStartType, "WellStartType", "Start Type", "", "", "" ); + m_autoTargetAtSeaLevel.reset( new RimWellPathTarget ); + m_autoTargetAtSeaLevel->setEnabled( false ); } //-------------------------------------------------------------------------------------------------- @@ -151,6 +148,8 @@ cvf::ref RimWellPathGeometryDef::createWellPathGeometry() { cvf::ref wellPathGeometry = new RigWellPath; + updateTargetAtSeaLevel(); + RiaLineArcWellPathCalculator wellPathCalculator = lineArcWellPathCalculator(); if ( wellPathCalculator.lineArcEndpoints().size() < 2 ) return wellPathGeometry; @@ -167,32 +166,6 @@ cvf::ref RimWellPathGeometryDef::createWellPathGeometry() wellPathGeometry->setDatumElevation( m_airGap ); } - if ( m_wellStartType == START_AT_SURFACE && !wellPathGeometry->m_wellPathPoints.empty() ) - { - cvf::Vec3d mslPoint = wellPathGeometry->m_wellPathPoints.front(); - mslPoint.z() = 0.0; - double depthDiff = mslPoint.z() - wellPathGeometry->m_wellPathPoints.front().z(); - if ( std::abs( depthDiff ) > 1.0e-8 ) - { - CAF_ASSERT( wellPathGeometry->m_wellPathPoints.size() == wellPathGeometry->m_measuredDepths.size() ); - - std::vector newPoints; - newPoints.reserve( wellPathGeometry->m_wellPathPoints.size() + 1 ); - std::vector newMds; - newMds.reserve( wellPathGeometry->m_measuredDepths.size() + 1 ); - - newPoints.push_back( mslPoint ); - newMds.push_back( 0.0 ); - for ( size_t i = 0; i < wellPathGeometry->m_wellPathPoints.size(); ++i ) - { - newPoints.push_back( wellPathGeometry->m_wellPathPoints[i] ); - newMds.push_back( wellPathGeometry->m_measuredDepths[i] + depthDiff ); - } - wellPathGeometry->m_wellPathPoints.swap( newPoints ); - wellPathGeometry->m_measuredDepths.swap( newMds ); - } - } - return wellPathGeometry; } //-------------------------------------------------------------------------------------------------- @@ -336,14 +309,6 @@ QList { QList options; - if ( fieldNeedingOptions == &m_wellStartType ) - { - options.push_back( caf::PdmOptionItemInfo( "Start at Surface", RimWellPathGeometryDef::START_AT_SURFACE ) ); - - options.push_back( - caf::PdmOptionItemInfo( "Start at First Target", RimWellPathGeometryDef::START_AT_FIRST_TARGET ) ); - } - return options; } @@ -371,13 +336,14 @@ void RimWellPathGeometryDef::fieldChangedByUi( const caf::PdmFieldHandle* change //-------------------------------------------------------------------------------------------------- void RimWellPathGeometryDef::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - uiOrdering.add( &m_wellStartType ); uiOrdering.add( &m_referencePointUtmXyd ); uiOrdering.add( &m_airGap ); - if ( m_wellStartType == START_AT_FIRST_TARGET ) + if ( !m_useAutoGeneratedTargetAtSeaLevel() ) { uiOrdering.add( &m_mdAtFirstTarget ); } + + uiOrdering.add( &m_useAutoGeneratedTargetAtSeaLevel ); uiOrdering.add( &m_wellTargets ); uiOrdering.add( &m_pickPointsEnabled ); uiOrdering.skipRemainingFields( true ); @@ -397,6 +363,12 @@ void RimWellPathGeometryDef::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTre std::vector RimWellPathGeometryDef::activeWellTargets() const { std::vector active; + + if ( m_useAutoGeneratedTargetAtSeaLevel() && !m_wellTargets.empty() ) + { + active.push_back( m_autoTargetAtSeaLevel.get() ); + } + for ( const auto& wt : m_wellTargets ) { if ( wt->isEnabled() ) @@ -455,6 +427,35 @@ RiaLineArcWellPathCalculator RimWellPathGeometryDef::lineArcWellPathCalculator() return wellPathCalculator; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathGeometryDef::updateTargetAtSeaLevel() +{ + if ( m_useAutoGeneratedTargetAtSeaLevel && !m_wellTargets.empty() ) + { + cvf::Vec3d newPos = cvf::Vec3d::ZERO; + + auto firstTarget = m_wellTargets[0]; + + cvf::Vec3d targetTangent = firstTarget->tangent(); + double radius = firstTarget->radius1(); + + cvf::Vec3d tangentInHorizontalPlane = targetTangent; + tangentInHorizontalPlane[2] = 0.0; + tangentInHorizontalPlane.normalize(); + + RiaOffshoreSphericalCoords sphTangent( targetTangent ); + double inc = sphTangent.inc(); + double horizontalLengthFromTarget = radius - radius * cvf::Math::cos( inc ); + + newPos = firstTarget->targetPointXYZ() - horizontalLengthFromTarget * tangentInHorizontalPlane; + newPos.z() = -referencePointXyz().z(); + + m_autoTargetAtSeaLevel->setAsPointXYZAndTangentTarget( {newPos[0], newPos[1], newPos[2]}, 0, 0 ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -552,6 +553,6 @@ void RimWellPathGeometryDef::initAfterRead() { if ( RiaApplication::instance()->project()->isProjectFileVersionEqualOrOlderThan( "2019.12.1" ) ) { - m_wellStartType = START_AT_FIRST_TARGET; + m_autoTargetAtSeaLevel = false; } } diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h index aad0462f9f..e964944c25 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.h @@ -19,12 +19,14 @@ #include "RiaLineArcWellPathCalculator.h" #include "RiaWellPlanCalculator.h" + #include "cafAppEnum.h" #include "cafPdmChildArrayField.h" #include "cafPdmField.h" #include "cafPdmFieldCvfVec3d.h" #include "cafPdmObject.h" #include "cafPdmPtrField.h" + #include "cvfObject.h" class RimWellPath; @@ -41,12 +43,6 @@ public: RimWellPathGeometryDef(); ~RimWellPathGeometryDef() override; - enum WellStartType - { - START_AT_FIRST_TARGET, - START_AT_SURFACE, - }; - cvf::Vec3d referencePointXyz() const; void setReferencePointXyz( const cvf::Vec3d& refPointXyz ); @@ -92,6 +88,8 @@ private: RiaLineArcWellPathCalculator lineArcWellPathCalculator() const; + void updateTargetAtSeaLevel(); + private: caf::PdmField m_referencePointUtmXyd; @@ -99,10 +97,10 @@ private: caf::PdmField m_mdAtFirstTarget; caf::PdmChildArrayField m_wellTargets; + caf::PdmField m_useAutoGeneratedTargetAtSeaLevel; caf::PdmField m_pickPointsEnabled; - caf::PdmField> m_wellStartType; - std::shared_ptr m_pickTargetsEventHandler; + std::unique_ptr m_autoTargetAtSeaLevel; }; diff --git a/ApplicationCode/ProjectDataModel/RimWellPathTarget.cpp b/ApplicationCode/ProjectDataModel/RimWellPathTarget.cpp index 934f9e092a..d6890026a0 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathTarget.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathTarget.cpp @@ -70,6 +70,14 @@ RimWellPathTarget::~RimWellPathTarget() { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellPathTarget::setEnabled( bool enable ) +{ + m_isEnabled = enable; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/RimWellPathTarget.h b/ApplicationCode/ProjectDataModel/RimWellPathTarget.h index 50d8d8a5f0..e1c0398fa5 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathTarget.h +++ b/ApplicationCode/ProjectDataModel/RimWellPathTarget.h @@ -33,6 +33,7 @@ public: RimWellPathTarget(); ~RimWellPathTarget() override; + void setEnabled( bool enable ); bool isEnabled() const; void setAsPointTargetXYD( const cvf::Vec3d& point );