Skip to content

Commit

Permalink
Add update of polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Feb 6, 2024
1 parent aa09059 commit 23b905f
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "WellPathCommands/RicPolylineTargetsPickEventHandler.h"

#include "cafCmdFeatureMenuBuilder.h"
#include "cafDisplayCoordTransform.h"
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiTableViewEditor.h"
Expand Down Expand Up @@ -110,6 +111,8 @@ void RimPolygonInView::insertTarget( const RimPolylineTarget* targetToInsertBefo
m_targets.insert( index, targetToInsert );
else
m_targets.push_back( targetToInsert );

updatePolygonFromTargets();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -119,6 +122,8 @@ void RimPolygonInView::deleteTarget( RimPolylineTarget* targetToDelete )
{
m_targets.removeChild( targetToDelete );
delete targetToDelete;

updatePolygonFromTargets();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -166,6 +171,17 @@ caf::PickEventHandler* RimPolygonInView::pickEventHandler() const
return m_pickTargetsEventHandler.get();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInView::onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& updatedObjects )
{
if ( childArray == &m_targets )
{
updatePolygonFromTargets();
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -186,6 +202,41 @@ cvf::ref<RigPolyLinesData> RimPolygonInView::polyLinesData() const
return pld;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonInView::updatePolygonFromTargets()
{
if ( m_polygon )
{
std::vector<cvf::Vec3d> 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 );
}
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -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();
;
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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 );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,24 @@ class RimPolygonInView : public RimCheckableNamedObject, public RimPolylinesData
bool pickingEnabled() const override;
caf::PickEventHandler* pickEventHandler() const override;

void onChildrenUpdated( caf::PdmChildArrayFieldHandle* childArray, std::vector<caf::PdmObjectHandle*>& updatedObjects ) override;

protected:
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
QList<caf::PdmOptionItemInfo> 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<RigPolyLinesData> polyLinesData() const override;

void updatePolygonFromTargets();
void updateTargetsFromPolygon();

private:
caf::PdmPtrField<RimPolygon*> m_polygon;

Expand Down

0 comments on commit 23b905f

Please sign in to comment.