diff --git a/common/tool/point_editor_behavior.cpp b/common/tool/point_editor_behavior.cpp index 2c4ed7d846..7f7d6ed8f2 100644 --- a/common/tool/point_editor_behavior.cpp +++ b/common/tool/point_editor_behavior.cpp @@ -24,6 +24,7 @@ #include "tool/point_editor_behavior.h" #include +#include #include @@ -101,6 +102,11 @@ void POLYGON_POINT_EDIT_BEHAVIOR::UpdateOutlineFromPoints( SHAPE_POLY_SET& aOu } +void POLYGON_POINT_EDIT_BEHAVIOR::FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) +{ + m_polygon.RemoveNullSegments(); +} + void EDA_SEGMENT_POINT_EDIT_BEHAVIOR::MakePoints( EDIT_POINTS& aPoints ) { aPoints.AddPoint( m_segment.GetStart() ); diff --git a/include/tool/point_editor_behavior.h b/include/tool/point_editor_behavior.h index 11e0e9880d..6a72c6736b 100644 --- a/include/tool/point_editor_behavior.h +++ b/include/tool/point_editor_behavior.h @@ -69,6 +69,17 @@ public: */ virtual void UpdatePoints( EDIT_POINTS& aPoints ) = 0; + /** + * Finalize the edit operation. (optional) + * + * This is called once, after the user has finished editing + * (e.g. released the mouse button). + * + * @param aPoints The final positions of the edit points. + * @param aCommit The commit object to use to modify the item. + */ + virtual void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) {}; + /** * Update the item with the new positions of the edit points. * @@ -168,6 +179,8 @@ public: UpdateOutlineFromPoints( m_polygon, aEditedPoint, aPoints ); } + void FinalizeItem( EDIT_POINTS& aPoints, COMMIT& aCommit ) override; + private: SHAPE_POLY_SET& m_polygon; }; diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 8529d7d778..01a9434789 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -2326,6 +2326,9 @@ int PCB_POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) getViewControls()->SetAutoPan( false ); setAltConstraint( false ); + if( m_editorBehavior ) + m_editorBehavior->FinalizeItem( *m_editPoints, commit ); + if( item->Type() == PCB_GENERATOR_T ) { PCB_GENERATOR* generator = static_cast( item ); @@ -2565,7 +2568,30 @@ void PCB_POINT_EDITOR::updatePoints() if( !m_editorBehavior ) return; + int editedIndex = -1; + + if( m_editedPoint ) + { + for( unsigned ii = 0; ii < m_editPoints->PointsSize(); ++ii ) + { + if( &m_editPoints->Point( ii ) == m_editedPoint ) + { + editedIndex = ii; + break; + } + } + } + m_editorBehavior->UpdatePoints( *m_editPoints ); + + if( editedIndex >= 0 ) + { + if( editedIndex < (int) m_editPoints->PointsSize() ) + m_editedPoint = &m_editPoints->Point( editedIndex ); + else + m_editedPoint = nullptr; + } + getView()->Update( m_editPoints.get() ); if( m_angleItem )