Skip to content

Commit

Permalink
Add edit polygon in active view
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 23, 2024
1 parent 8b7a6b9 commit 6f57f51
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void RimPolygonFilter::fieldChangedByUi( const caf::PdmFieldHandle* changedField
{
if ( changedField == &m_editPolygonButton )
{
RimPolygonTools::selectPolygonInView( m_cellFilterPolygon(), this );
RimPolygonTools::selectAndActivatePolygonInView( m_cellFilterPolygon(), this );

m_editPolygonButton = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", "" );

Expand Down Expand Up @@ -523,7 +524,7 @@ void RimExtrudedCurveIntersection::fieldChangedByUi( const caf::PdmFieldHandle*

if ( changedField == &m_editPolygonButton )
{
RimPolygonTools::selectPolygonInView( m_projectPolygon(), this );
RimPolygonTools::selectAndActivatePolygonInView( m_projectPolygon(), this );

m_editPolygonButton = false;

Expand Down
35 changes: 35 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@

#include "RigPolyLinesData.h"

#include "RiaApplication.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" );
Expand All @@ -37,6 +41,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 );
Expand Down Expand Up @@ -131,6 +141,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();
Expand All @@ -151,6 +162,16 @@ void RimPolygon::fieldChangedByUi( const caf::PdmFieldHandle* changedField, cons
{
objectChanged.send();
}

if ( changedField == &m_editPolygonButton )
{
auto activeView = RiaApplication::instance()->activeReservoirView();
RimPolygonTools::selectAndActivatePolygonInView( this, activeView );

m_editPolygonButton = false;

return;
}
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -161,6 +182,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<caf::PdmUiPushButtonEditorAttribute*>( attribute ) )
{
attrib->m_buttonText = "Edit in Active View";
}
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Polygons/RimPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> m_isReadOnly;
caf::PdmField<bool> m_editPolygonButton;
caf::PdmField<std::vector<cvf::Vec3d>> m_pointsInDomainCoords;
caf::PdmChildField<RimPolygonAppearance*> m_appearance;
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
void RimPolygonTools::selectAndActivatePolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
Expand All @@ -51,7 +51,7 @@ RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf::
return nullptr;
}

if ( auto gridView = sourceObject->firstAncestorOfType<RimGridView>() )
if ( auto gridView = sourceObject->firstAncestorOrThisOfType<RimGridView>() )
{
auto polyCollection = gridView->polygonInViewCollection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PdmObject;
class RimPolygonTools
{
public:
static void selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
static void selectAndActivatePolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );

private:
static RimPolygonInView* findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject );
Expand Down

0 comments on commit 6f57f51

Please sign in to comment.