From 1151783a3426dfa74b3a6e62df3e626687e3dca6 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Tue, 13 Jul 2021 10:23:55 +0200 Subject: [PATCH] Gerbview: fix an issue (Debug only) with RoundRect aperture macro. When a RoundRect aperture macro was used with a radius = 0, a wxWidget assert was generated, due to incorrect polygonal shape to draw. --- common/plotters/gbr_plotter_aperture_macros.h | 6 ++--- gerbview/am_primitive.cpp | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/plotters/gbr_plotter_aperture_macros.h b/common/plotters/gbr_plotter_aperture_macros.h index 9dd463d4ca..29c291de30 100644 --- a/common/plotters/gbr_plotter_aperture_macros.h +++ b/common/plotters/gbr_plotter_aperture_macros.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -108,10 +108,10 @@ "%AMOutline5P*\n\ 0 Free polygon, 5 corners , with rotation*\n\ 0 The origin of the aperture is its center*\n\ -0 number of corners: always 8*\n\ +0 number of corners: always 5*\n\ 0 $1 to $10 corner X, Y*\n\ 0 $11 Rotation angle, in degrees counterclockwise*\n\ -0 create outline with 8 corners*\n\ +0 create outline with 5 corners*\n\ 4,1,5,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$1,$2,$11*%\n" // A aperture macro to define a polygon by 6 corners diff --git a/gerbview/am_primitive.cpp b/gerbview/am_primitive.cpp index ae0c02e41d..50e39afca4 100644 --- a/gerbview/am_primitive.cpp +++ b/gerbview/am_primitive.cpp @@ -7,7 +7,7 @@ * * Copyright (C) 1992-2017 Jean-Pierre Charras * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -96,10 +96,12 @@ void AM_PRIMITIVE::DrawBasicShape( const GERBER_DRAW_ITEM* aParent, SHAPE_POLY_SET& aShapeBuffer, wxPoint aShapePos ) { - #define TO_POLY_SHAPE { aShapeBuffer.NewOutline(); \ - for( unsigned jj = 0; jj < polybuffer.size(); jj++ )\ - aShapeBuffer.Append( polybuffer[jj].x, polybuffer[jj].y );\ - aShapeBuffer.Append( polybuffer[0].x, polybuffer[0].y );} + #define TO_POLY_SHAPE { if( polybuffer.size() > 1 )\ + { aShapeBuffer.NewOutline(); \ + for( unsigned jj = 0; jj < polybuffer.size(); jj++ )\ + aShapeBuffer.Append( polybuffer[jj].x, polybuffer[jj].y );\ + aShapeBuffer.Append( polybuffer[0].x, polybuffer[0].y );}\ + } // Draw the primitive shape for flashed items. static std::vector polybuffer; // create a static buffer to avoid a lot of memory reallocation @@ -462,8 +464,13 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent, * is a optional parameter: rotation from origin. * type is not stored in parameters list, so the first parameter is exposure */ - wxPoint center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); int radius = scaletoIU( params[1].GetValue( tool ), m_GerbMetric ) / 2; + // A circle primitive can have a 0 size (for instance when used in roundrect macro), + // so skip it + if( radius <= 0 ) + break; + + wxPoint center = mapPt( params[2].GetValue( tool ), params[3].GetValue( tool ), m_GerbMetric ); wxPoint corner; const int delta = 3600 / seg_per_circle; // rot angle in 0.1 degree @@ -806,6 +813,9 @@ SHAPE_POLY_SET* APERTURE_MACRO::GetApertureMacroShape( const GERBER_DRAW_ITEM* a } } + // Merge and cleanup basic shape polygons + m_shape.Simplify( SHAPE_POLY_SET::PM_FAST ); + // If a hole is defined inside a polygon, we must fracture the polygon // to be able to drawn it (i.e link holes by overlapping edges) if( hasHole )