From 1c6574e69d853a96366d37a60eb9d273c425cf98 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Fri, 31 Aug 2012 15:58:23 +0200 Subject: [PATCH] Fix 0 length segment in outline zone creation, that breaks zone chamfer option. --- common/drawtxt.cpp | 2 +- pcbnew/zones_by_polygon.cpp | 6 +++++- polygon/PolyLine.cpp | 39 +++++++++++++++++++++++++++++++++++++ polygon/PolyLine.h | 17 +++++++++++++++- 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/common/drawtxt.cpp b/common/drawtxt.cpp index 9d2c1c892c..16e6bfbd94 100644 --- a/common/drawtxt.cpp +++ b/common/drawtxt.cpp @@ -392,7 +392,7 @@ void DrawGraphicText( EDA_DRAW_PANEL* aPanel, aCallback( current_char_pos.x, current_char_pos.y, end.x, end.y ); } else - GRLine( aPanel->GetClipBox(), aDC, + GRLine( clipBox, aDC, current_char_pos.x, current_char_pos.y, end.x, end.y, aWidth, aColor ); return; diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index cb74e05bb4..3a242dbb65 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -671,7 +671,8 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) { ii = zone->GetNumCorners() - 1; - // edge in progress : the current corner coordinate was set by Show_New_Edge_While_Move_Mouse + // edge in progress : the current corner coordinate was set + // by Show_New_Edge_While_Move_Mouse if( zone->GetCornerPosition( ii - 1 ) != zone->GetCornerPosition( ii ) ) { if( !Drc_On || !zone->IsOnCopperLayer() || ( m_drc->Drc( zone, ii - 1 ) == OK_DRC ) ) @@ -705,6 +706,9 @@ bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) return true; } + // Remove the last corner if is is at the same location as the prevoius corner + zone->m_Poly->RemoveNullSegments(); + // Validate the current edge: int icorner = zone->GetNumCorners() - 1; if( zone->IsOnCopperLayer() ) diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index 665e6f74d8..1fab2222d3 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -32,6 +32,42 @@ CPolyLine::~CPolyLine() UnHatch(); } +/* Removes corners which create a null segment edge + * (i.e. when 2 successive corners are at the same location) + * returns the count of removed corners. + */ + int CPolyLine::RemoveNullSegments() +{ + int removed = 0; + + unsigned startcountour = 0; + for( unsigned icnt = 1; icnt < m_CornersList.size(); icnt ++ ) + { + unsigned last = icnt-1; + if( m_CornersList[icnt].end_contour ) + { + last = startcountour; + startcountour = icnt+1; + } + + if( ( m_CornersList[last].x == m_CornersList[icnt].x ) && + ( m_CornersList[last].y == m_CornersList[icnt].y ) ) + { + DeleteCorner( icnt ); + icnt--; + removed ++; + } + + if( m_CornersList[icnt].end_contour ) + { + startcountour = icnt+1; + icnt++; + } + } + + return removed; +} + /** * Function NormalizeAreaOutlines @@ -65,6 +101,7 @@ int CPolyLine::NormalizeAreaOutlines( std::vector* aNewPolygonList ) if( corner.end_contour ) break; } + ClipperLib::SimplifyPolygon( raw_polygon, normalized_polygons ); // enter main outline @@ -148,6 +185,8 @@ int CPolyLine::NormalizeAreaOutlines( std::vector* aNewPolygonList ) polyline->CloseLastContour(); hole++; } + + polyline->RemoveNullSegments(); } return outlines.size(); diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index ed0ecffade..e234cbf0a8 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -103,7 +103,14 @@ public: void AppendCorner( int x, int y ); void InsertCorner( int ic, int x, int y ); - void DeleteCorner( int ic ); + + /** + * Function DeleteCorner + * remove the given corner. if it is the last point of a contour + * keep the controur closed by modifying the previous corner + * @param ic = the index of the corner to delete + */ + void DeleteCorner ( int ic ); void MoveCorner( int ic, int x, int y ); void CloseLastContour(); void RemoveContour( int icont ); @@ -137,6 +144,14 @@ public: */ CPolyLine* Fillet( unsigned int aRadius, unsigned int aSegments ); + /** + * Function RemoveNullSegments + * Removes corners which create a null segment edge + * (i.e. when 2 successive corners are at the same location) + * @return the count of removed corners. + */ + int RemoveNullSegments(); + void RemoveAllContours( void ); // Remove or create hatch