Simplify overlapping points after editing
Fixes https://gitlab.com/kicad/code/kicad/-/issues/21571
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "tool/point_editor_behavior.h"
|
||||
|
||||
#include <advanced_config.h>
|
||||
#include <commit.h>
|
||||
#include <geometry/shape_poly_set.h>
|
||||
|
||||
|
||||
@@ -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() );
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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<PCB_GENERATOR*>( 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 )
|
||||
|
||||
Reference in New Issue
Block a user