From c40c3f8abc14fca2e6c47aa29fb0ca0f002b2064 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 22 Feb 2024 15:50:54 +0100 Subject: [PATCH] Add edit polygon in active view --- .../RimExtrudedCurveIntersection.cpp | 1 + .../ProjectDataModel/Polygons/RimPolygon.cpp | 34 +++++++++++++++++++ .../ProjectDataModel/Polygons/RimPolygon.h | 2 ++ .../Polygons/RimPolygonTools.cpp | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp b/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp index 0d6a575bd32..ea3a166ab8d 100644 --- a/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Intersections/RimExtrudedCurveIntersection.cpp @@ -214,6 +214,7 @@ RimExtrudedCurveIntersection::RimExtrudedCurveIntersection() CAF_PDM_InitField( &m_editPolygonButton, "EditPolygonButton", false, "Edit" ); m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() ); m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + m_editPolygonButton.xmlCapability()->disableIO(); CAF_PDM_InitScriptableFieldNoDefault( &m_userPolylineXyz, "Points", "Points", "", "Use Ctrl-C for copy and Ctrl-V for paste", "" ); diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp index c25f1dd0ab2..02e82afc26d 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp @@ -20,9 +20,12 @@ #include "RigPolyLinesData.h" +#include "Rim3dView.h" #include "RimPolygonAppearance.h" +#include "RimPolygonTools.h" #include "cafCmdFeatureMenuBuilder.h" +#include "cafPdmUiPushButtonEditor.h" #include "cafPdmUiTreeAttributes.h" CAF_PDM_SOURCE_INIT( RimPolygon, "RimPolygon" ); @@ -37,6 +40,12 @@ RimPolygon::RimPolygon() CAF_PDM_InitField( &m_isReadOnly, "IsReadOnly", false, "Read Only" ); CAF_PDM_InitFieldNoDefault( &m_pointsInDomainCoords, "PointsInDomainCoords", "Points" ); + + CAF_PDM_InitField( &m_editPolygonButton, "EditPolygonButton", false, "Edit" ); + m_editPolygonButton.uiCapability()->setUiEditorTypeName( caf::PdmUiPushButtonEditor::uiEditorTypeName() ); + m_editPolygonButton.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN ); + m_editPolygonButton.xmlCapability()->disableIO(); + CAF_PDM_InitFieldNoDefault( &m_appearance, "Appearance", "Appearance" ); m_appearance = new RimPolygonAppearance; m_appearance.uiCapability()->setUiTreeChildrenHidden( true ); @@ -131,6 +140,7 @@ void RimPolygon::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiO { uiOrdering.add( nameField() ); uiOrdering.add( &m_isReadOnly ); + uiOrdering.add( &m_editPolygonButton ); auto groupPoints = uiOrdering.addNewGroup( "Points" ); groupPoints->setCollapsedByDefault(); @@ -151,6 +161,16 @@ void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons { objectChanged.send(); } + + if ( changedField == &m_editPolygonButton ) + { + auto activeView = RiaApplication::instance()->activeReservoirView(); + RimPolygonTools::selectPolygonInView( this, activeView ); + + m_editPolygonButton = false; + + return; + } } //-------------------------------------------------------------------------------------------------- @@ -161,6 +181,20 @@ void RimPolygon::childFieldChangedByUi( const caf::PdmFieldHandle* changedChildF objectChanged.send(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimPolygon::defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) +{ + if ( field == &m_editPolygonButton ) + { + if ( auto attrib = dynamic_cast( attribute ) ) + { + attrib->m_buttonText = "Edit in Active View"; + } + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h index 8f1281fcf92..0562acd6529 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h @@ -61,9 +61,11 @@ class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override; void childFieldChangedByUi( const caf::PdmFieldHandle* changedChildField ) override; + void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override; private: caf::PdmField m_isReadOnly; + caf::PdmField m_editPolygonButton; caf::PdmField> m_pointsInDomainCoords; caf::PdmChildField m_appearance; }; diff --git a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp index d77eedb3283..9d75180a8ce 100644 --- a/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp +++ b/ApplicationLibCode/ProjectDataModel/Polygons/RimPolygonTools.cpp @@ -51,7 +51,7 @@ RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf:: return nullptr; } - if ( auto gridView = sourceObject->firstAncestorOfType() ) + if ( auto gridView = sourceObject->firstAncestorOrThisOfType() ) { auto polyCollection = gridView->polygonInViewCollection();