From 23b905f39738eb7fe96b11d93857e777c5150ff9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 6 Feb 2024 17:14:47 +0100 Subject: [PATCH] Add update of polygon --- .../Polygons/RimPolygonInView.cpp | 66 ++++++++++++++++++- .../Polygons/RimPolygonInView.h | 6 ++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp index a770df3b64..32ad4bc664 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.cpp @@ -29,6 +29,7 @@ #include "WellPathCommands/RicPolylineTargetsPickEventHandler.h" +#include "cafCmdFeatureMenuBuilder.h" #include "cafDisplayCoordTransform.h" #include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiTableViewEditor.h" @@ -110,6 +111,8 @@ void RimPolygonInView::insertTarget( const RimPolylineTarget* targetToInsertBefo m_targets.insert( index, targetToInsert ); else m_targets.push_back( targetToInsert ); + + updatePolygonFromTargets(); } //-------------------------------------------------------------------------------------------------- @@ -119,6 +122,8 @@ void RimPolygonInView::deleteTarget( RimPolylineTarget* targetToDelete ) { m_targets.removeChild( targetToDelete ); delete targetToDelete; + + updatePolygonFromTargets(); } //-------------------------------------------------------------------------------------------------- @@ -166,6 +171,17 @@ caf::PickEventHandler* RimPolygonInView::pickEventHandler() const return m_pickTargetsEventHandler.get(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector& updatedObjects ) +{ + if ( childArray == &m_targets ) + { + updatePolygonFromTargets(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -186,6 +202,41 @@ cvf::ref RimPolygonInView::polyLinesData() const return pld; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::updatePolygonFromTargets() +{ + if ( m_polygon ) + { + std::vector points; + for ( const RimPolylineTarget* target : m_targets ) + { + points.push_back( target->targetPointXYZ() ); + } + m_polygon->setPointsInDomainCoords( points ); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::updateTargetsFromPolygon() +{ + if ( m_polygon ) + { + m_targets.deleteChildren(); + + for ( const auto& p : m_polygon->pointsInDomainCoords() ) + { + auto target = new RimPolylineTarget(); + target->setAsPointXYZ( p ); + + m_targets.push_back( target ); + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -203,7 +254,6 @@ void RimPolygonInView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin void RimPolygonInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) { updateVisualization(); - ; } //-------------------------------------------------------------------------------------------------- @@ -272,6 +322,20 @@ void RimPolygonInView::defineEditorAttribute( const caf::PdmFieldHandle* field, } } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygonInView::defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) +{ + caf::CmdFeatureMenuBuilder menuBuilder; + + menuBuilder << "RicNewPolylineTargetFeature"; + menuBuilder << "Separator"; + menuBuilder << "RicDeletePolylineTargetFeature"; + + menuBuilder.appendToMenu( menu ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h index 2a68581eac..c59af9cce5 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonInView.h @@ -62,6 +62,8 @@ class RimPolygonInView : public RimCheckableNamedObject, public RimPolylinesData bool pickingEnabled() const override; caf::PickEventHandler* pickEventHandler() const override; + void onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector& updatedObjects ) override; + protected: void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; @@ -69,11 +71,15 @@ class RimPolygonInView : public RimCheckableNamedObject, public RimPolylinesData QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; + void defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) override; private: void updateNameField(); cvf::ref polyLinesData() const override; + void updatePolygonFromTargets(); + void updateTargetsFromPolygon(); + private: caf::PdmPtrField m_polygon;