From ba37d6fca35b67fc04a21aa111aba97c80c3a1b0 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 6 Apr 2017 19:04:47 +0200 Subject: [PATCH] Temporary fix of broken command add corner to zone in GAL mode. Fixes: lp:1680339 https://bugs.launchpad.net/kicad/+bug/1680339 --- common/geometry/shape_poly_set.cpp | 3 ++- pcbnew/tools/point_editor.cpp | 22 ++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index aa4a0214a0..7313725655 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -202,7 +202,8 @@ void SHAPE_POLY_SET::InsertVertex( int aGlobalIndex, VECTOR2I aNewVertex ) if( aGlobalIndex < 0 ) aGlobalIndex = 0; - if( aGlobalIndex >= TotalVertices() ){ + if( aGlobalIndex >= TotalVertices() ) + { Append( aNewVertex ); } else diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index e7661191f3..b6544cce5b 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -781,15 +781,21 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) commit.Modify( zone ); // Handle the last segment, so other segments can be easily handled in a loop - unsigned int nearestIdx = outline->TotalVertices() - 1, nextNearestIdx = 0; - SEG side( outline->Vertex( nearestIdx ), outline->Vertex( nextNearestIdx ) ); - unsigned int nearestDist = side.Distance( cursorPos ); + unsigned int nearestIdx = 0; + unsigned int nextNearestIdx = 0; + unsigned int nearestDist = INT_MAX; - for( int i = 0; i < outline->TotalVertices() - 1; ++i ) + for( int i = 0; i < outline->TotalVertices(); ++i ) { - side = SEG( outline->Vertex( i ), outline->Vertex( i + 1 ) ); + int jj = i+1; + + if( jj >= outline->TotalVertices() ) + jj = 0; + + SEG side( outline->Vertex( i ), outline->Vertex( jj ) ); unsigned int distance = side.Distance( cursorPos ); + if( distance < nearestDist ) { nearestDist = distance; @@ -798,6 +804,7 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) } } + // Find the point on the closest segment VECTOR2I sideOrigin = outline->Vertex( nearestIdx ); VECTOR2I sideEnd = outline->Vertex( nextNearestIdx ); @@ -809,7 +816,9 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) if( nearestPoint == sideOrigin || nearestPoint == sideEnd ) nearestPoint = ( sideOrigin + sideEnd ) / 2; - outline->InsertVertex( nearestIdx, nearestPoint ); + // Add corner between nearestIdx and nextNearestIdx: + outline->InsertVertex( nextNearestIdx, nearestPoint ); + zone->Hatch(); commit.Push( _( "Add a zone corner" ) ); } @@ -853,6 +862,7 @@ int POINT_EDITOR::addCorner( const TOOL_EVENT& aEvent ) commit.Push( _( "Split segment" ) ); } } + updatePoints(); return 0; }