From bf71a4e012cc10b6430e77ee5fcf7044f450d018 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 18 Aug 2020 10:26:10 +0200 Subject: [PATCH] Gerbview: fix draw issue when drawing a line using a rectangular aperture. Lines using a rectangular aperture are not common, but this is legal in Gerber files. Fixes #5205 https://gitlab.com/kicad/code/kicad/issues/5205 --- gerbview/gerber_draw_item.cpp | 7 ++++--- gerbview/gerbview_painter.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index fe61ac33c0..7a6c4a9463 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -666,17 +666,18 @@ void GERBER_DRAW_ITEM::DrawGbrPoly( EDA_RECT* aClipBox, const wxPoint& aOffset, bool aFilledShape ) { - std::vector points; SHAPE_LINE_CHAIN& poly = m_Polygon.Outline( 0 ); int pointCount = poly.PointCount() - 1; + std::vector points; points.reserve( pointCount ); for( int ii = 0; ii < pointCount; ii++ ) { wxPoint p( poly.Point( ii ).x, poly.Point( ii ).y ); - points[ii] = p + aOffset; - points[ii] = GetABPosition( points[ii] ); + p = p + aOffset; + p = GetABPosition( p ); + points.push_back( p ); } GRClosedPoly( aClipBox, aDC, pointCount, &points[0], aFilledShape, aColor, aColor ); diff --git a/gerbview/gerbview_painter.cpp b/gerbview/gerbview_painter.cpp index 7920d30b25..6f87b74f4e 100644 --- a/gerbview/gerbview_painter.cpp +++ b/gerbview/gerbview_painter.cpp @@ -360,11 +360,16 @@ void GERBVIEW_PAINTER::draw( /*const*/ GERBER_DRAW_ITEM* aItem, int aLayer ) // TODO(JE) Refactor this to allow const aItem D_CODE* code = aItem->GetDcodeDescr(); + if( code && code->m_Shape == APT_RECT ) { if( aItem->m_Polygon.OutlineCount() == 0 ) aItem->ConvertSegmentToPolygon(); - drawPolygon( aItem, aItem->m_Polygon, isFilled ); + + // Warning: drawPolygon modify the polygon to draw, so use a copy + // of aItem->m_Polygon + SHAPE_POLY_SET poly = aItem->m_Polygon; + drawPolygon( aItem, poly, isFilled ); } else {