Use polygon as data source for intersection

- Use polygon as data source for intersection
- Add padlock icon
- Show padlock icon on read only polygons
- Add Fwk function appendMenuItems() to make it possible to define context menu content in a PdmObject
- Context menu "Create Polygon Intersection"
- Updates to make visualization consistent with object and object collection enabled state
This commit is contained in:
Magne Sjaastad
2024-02-25 09:21:48 +01:00
committed by GitHub
parent 09151ec6af
commit 28d281e1d6
45 changed files with 632 additions and 125 deletions

View File

@@ -19,7 +19,15 @@
#include "RimPolygon.h"
#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" );
@@ -33,6 +41,10 @@ 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" );
caf::PdmUiPushButtonEditor::configureEditorLabelHidden( &m_editPolygonButton );
CAF_PDM_InitFieldNoDefault( &m_appearance, "Appearance", "Appearance" );
m_appearance = new RimPolygonAppearance;
m_appearance.uiCapability()->setUiTreeChildrenHidden( true );
@@ -61,6 +73,15 @@ void RimPolygon::uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrde
m_appearance->uiOrdering( uiConfigName, uiOrdering );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygon::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
menuBuilder << "RicNewPolygonIntersectionFeature";
menuBuilder << "RicNewPolygonFilterFeature";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -95,6 +116,22 @@ bool RimPolygon::isClosed() const
return m_appearance->isClosed();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygon::setReadOnly( bool isReadOnly )
{
m_isReadOnly = isReadOnly;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygon::isReadOnly() const
{
return m_isReadOnly();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -102,11 +139,14 @@ 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();
groupPoints->add( &m_pointsInDomainCoords );
m_pointsInDomainCoords.uiCapability()->setUiReadOnly( m_isReadOnly() );
auto group = uiOrdering.addNewGroup( "Appearance" );
m_appearance->uiOrdering( uiConfigName, *group );
}
@@ -120,6 +160,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;
}
}
//--------------------------------------------------------------------------------------------------
@@ -129,3 +179,28 @@ 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";
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygon::defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute )
{
if ( m_isReadOnly )
{
caf::PdmUiTreeViewItemAttribute::createTagIfTreeViewItemAttribute( attribute, ":/padlock.svg" );
}
}

View File

@@ -28,6 +28,11 @@
class RimPolygonAppearance;
namespace caf
{
class CmdFeatureMenuBuilder;
}
class RimPolygon : public RimNamedObject, public RimPolylinesDataInterface
{
CAF_PDM_HEADER_INIT;
@@ -43,17 +48,24 @@ public:
void setIsClosed( bool isClosed );
bool isClosed() const;
void setReadOnly( bool isReadOnly );
bool isReadOnly() const;
cvf::ref<RigPolyLinesData> polyLinesData() const override;
void uiOrderingForLocalPolygon( QString uiConfigName, caf::PdmUiOrdering& uiOrdering );
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
void defineObjectEditorAttribute( QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
protected:
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;
};

View File

@@ -139,6 +139,7 @@ std::vector<RimPolygon*> RimPolygonCollection::allPolygons() const
void RimPolygonCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& referringObjects )
{
updateViewTreeItems();
scheduleRedrawViews();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -22,12 +22,14 @@
#include "Rim3dView.h"
#include "RimPolygon.h"
#include "RimPolygonInViewCollection.h"
#include "RimPolylineTarget.h"
#include "RimTools.h"
#include "WellPathCommands/PointTangentManipulator/RicPolyline3dEditor.h"
#include "WellPathCommands/RicPolylineTargetsPickEventHandler.h"
#include "Riu3DMainWindowTools.h"
#include "RiuGuiTheme.h"
#include "RivPolylinePartMgr.h"
@@ -36,6 +38,7 @@
#include "cafDisplayCoordTransform.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTableViewEditor.h"
#include "cafPdmUiTreeAttributes.h"
#include "cvfModelBasicList.h"
@@ -57,6 +60,9 @@ RimPolygonInView::RimPolygonInView()
CAF_PDM_InitField( &m_enablePicking, "EnablePicking", false, "" );
caf::PdmUiPushButtonEditor::configureEditorLabelHidden( &m_enablePicking );
CAF_PDM_InitField( &m_selectPolygon, "SelectPolygon", false, "" );
caf::PdmUiPushButtonEditor::configureEditorLabelHidden( &m_selectPolygon );
CAF_PDM_InitField( &m_handleScalingFactor, "HandleScalingFactor", 1.0, "Handle Scaling Factor" );
CAF_PDM_InitFieldNoDefault( &m_targets, "Targets", "Targets" );
@@ -175,6 +181,13 @@ bool RimPolygonInView::pickingEnabled() const
//--------------------------------------------------------------------------------------------------
caf::PickEventHandler* RimPolygonInView::pickEventHandler() const
{
auto filterColl = firstAncestorOfType<RimPolygonInViewCollection>();
if ( filterColl && !filterColl->isChecked() ) return nullptr;
if ( !isChecked() ) return nullptr;
if ( m_polygon() && polygon()->isReadOnly() ) return nullptr;
return m_pickTargetsEventHandler.get();
}
@@ -244,10 +257,24 @@ void RimPolygonInView::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderin
{
updateNameField();
uiOrdering.add( &m_handleScalingFactor );
bool enableEdit = true;
if ( m_polygon() && m_polygon->isReadOnly() ) enableEdit = false;
if ( m_polygon() ) uiOrdering.add( m_polygon );
uiOrdering.add( &m_enablePicking );
uiOrdering.add( m_polygon );
if ( enableEdit )
{
uiOrdering.add( &m_enablePicking );
uiOrdering.add( &m_targets );
uiOrdering.add( &m_handleScalingFactor );
}
if ( m_polygon() )
{
uiOrdering.add( &m_selectPolygon );
}
uiOrdering.skipRemainingFields();
}
//--------------------------------------------------------------------------------------------------
@@ -260,6 +287,11 @@ void RimPolygonInView::fieldChangedByUi( const caf::PdmFieldHandle* changedField
updateConnectedEditors();
}
if ( changedField == &m_selectPolygon && m_polygon() )
{
Riu3DMainWindowTools::selectAsCurrentItem( m_polygon() );
}
updateVisualization();
}
@@ -289,6 +321,11 @@ void RimPolygonInView::defineObjectEditorAttribute( QString uiConfigName, caf::P
attrib->pickEventHandler = m_pickTargetsEventHandler;
attrib->enablePicking = m_enablePicking;
}
if ( m_polygon() && m_polygon->isReadOnly() )
{
caf::PdmUiTreeViewItemAttribute::createTagIfTreeViewItemAttribute( attribute, ":/padlock.svg" );
}
}
//--------------------------------------------------------------------------------------------------
@@ -301,6 +338,14 @@ void RimPolygonInView::uiOrderingForLocalPolygon( QString uiConfigName, caf::Pdm
uiOrdering.add( &m_handleScalingFactor );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInView::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
if ( m_polygon() ) m_polygon->appendMenuItems( menuBuilder );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -330,6 +375,15 @@ void RimPolygonInView::defineEditorAttribute( const caf::PdmFieldHandle* field,
}
}
if ( field == &m_selectPolygon )
{
auto* pbAttribute = dynamic_cast<caf::PdmUiPushButtonEditorAttribute*>( attribute );
if ( pbAttribute )
{
pbAttribute->m_buttonText = "Go to Polygon";
}
}
if ( field == &m_targets )
{
if ( auto tvAttribute = dynamic_cast<caf::PdmUiTableViewEditorAttribute*>( attribute ) )
@@ -351,6 +405,8 @@ void RimPolygonInView::defineEditorAttribute( const caf::PdmFieldHandle* field,
//--------------------------------------------------------------------------------------------------
void RimPolygonInView::defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget )
{
if ( m_polygon() && m_polygon->isReadOnly() ) return;
caf::CmdFeatureMenuBuilder menuBuilder;
menuBuilder << "RicNewPolylineTargetFeature";

View File

@@ -78,6 +78,7 @@ protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void defineEditorAttribute( const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute ) override;
void defineCustomContextMenu( const caf::PdmFieldHandle* fieldNeedingMenu, QMenu* menu, QWidget* fieldEditorWidget ) override;
void appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const override;
private:
void updateNameField();
@@ -88,6 +89,7 @@ private:
private:
caf::PdmPtrField<RimPolygon*> m_polygon;
caf::PdmField<bool> m_selectPolygon;
caf::PdmField<bool> m_enablePicking;
caf::PdmField<double> m_handleScalingFactor;
caf::PdmChildArrayField<RimPolylineTarget*> m_targets;

View File

@@ -18,6 +18,7 @@
#include "RimPolygonInViewCollection.h"
#include "Rim3dView.h"
#include "RimPolygon.h"
#include "RimPolygonCollection.h"
#include "RimPolygonInView.h"
@@ -83,3 +84,24 @@ std::vector<RimPolygonInView*> RimPolygonInViewCollection::polygonsInView() cons
{
return m_polygons.childrenByType();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInViewCollection::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
RimCheckableObject::fieldChangedByUi( changedField, oldValue, newValue );
if ( changedField == &m_isChecked )
{
for ( auto poly : polygonsInView() )
{
poly->updateConnectedEditors();
}
if ( auto view = firstAncestorOfType<Rim3dView>() )
{
view->scheduleCreateDisplayModelAndRedraw();
}
}
}

View File

@@ -18,8 +18,8 @@
#pragma once
#include "RimCheckableObject.h"
#include "cafPdmChildArrayField.h"
#include "cafPdmObject.h"
class RimPolygonInView;
@@ -27,7 +27,7 @@ class RimPolygonInView;
///
///
//==================================================================================================
class RimPolygonInViewCollection : public caf::PdmObject
class RimPolygonInViewCollection : public RimCheckableObject
{
CAF_PDM_HEADER_INIT;
@@ -38,6 +38,9 @@ public:
std::vector<RimPolygonInView*> polygonsInView() const;
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
private:
caf::PdmChildArrayField<RimPolygonInView*> m_polygons;
};

View File

@@ -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 )
@@ -46,7 +46,12 @@ void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject*
//--------------------------------------------------------------------------------------------------
RimPolygonInView* RimPolygonTools::findPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
if ( auto gridView = sourceObject->firstAncestorOfType<RimGridView>() )
if ( !polygon || !sourceObject )
{
return nullptr;
}
if ( auto gridView = sourceObject->firstAncestorOrThisOfType<RimGridView>() )
{
auto polyCollection = gridView->polygonInViewCollection();

View File

@@ -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 );