From 9fdcba8229654c3d4ea9564da0c558f145424b96 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 13 Oct 2016 10:26:49 +0200 Subject: [PATCH] Gerbview: Fix 2 (minor) issues in aperture macro "moire". Add a .gbr test file for this aperture macro. --- common/convert_basic_shapes_to_polygon.cpp | 13 ++++++-- gerbview/class_am_param.h | 2 +- gerbview/class_aperture_macro.cpp | 16 ++++++++-- .../aperture_macro_moire.gbr | 32 +++++++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 gerbview/gerber_test_files/aperture_macro_moire.gbr diff --git a/common/convert_basic_shapes_to_polygon.cpp b/common/convert_basic_shapes_to_polygon.cpp index 92fb9e1669..6ac6beaffb 100644 --- a/common/convert_basic_shapes_to_polygon.cpp +++ b/common/convert_basic_shapes_to_polygon.cpp @@ -283,16 +283,23 @@ void TransformRingToPolygon( SHAPE_POLY_SET& aCornerBuffer, wxPoint aCentre, int aRadius, int aCircleToSegmentsCount, int aWidth ) { - int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree - - // Compute the corners posituions and creates poly + // Compute the corners positions and creates the poly wxPoint curr_point; int inner_radius = aRadius - ( aWidth / 2 ); int outer_radius = inner_radius + aWidth; + if( inner_radius <= 0 ) + { //In this case, the ring is just a circle (no hole inside) + TransformCircleToPolygon( aCornerBuffer, aCentre, aRadius + ( aWidth / 2 ), + aCircleToSegmentsCount ); + return; + } + aCornerBuffer.NewOutline(); // Draw the inner circle of the ring + int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree + for( int ii = 0; ii < 3600; ii += delta ) { curr_point.x = inner_radius; diff --git a/gerbview/class_am_param.h b/gerbview/class_am_param.h index c60e311a07..7ce2c8416e 100644 --- a/gerbview/class_am_param.h +++ b/gerbview/class_am_param.h @@ -63,7 +63,7 @@ * %AMMOIRE10* * 6,0,0,0.350000,0.005,0.050,3,0.005,0.400000,0.0*% * Example of instanciation: - * %ADD19THERM19*% + * %ADD19MOIRE10*% * * A simple definition, one parameter: * %AMCIRCLE* diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index 03e1f2cf18..8a04c2f604 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -280,15 +280,25 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, // Draw circles: wxPoint center = aParent->GetABPosition( curPos ); // adjust outerDiam by this on each nested circle - int diamAdjust = (gap + penThickness); //*2; //Should we use * 2 ? + int diamAdjust = (gap + penThickness) * 2; for( int i = 0; i < numCircles; ++i, outerDiam -= diamAdjust ) { if( outerDiam <= 0 ) break; - TransformRingToPolygon( aShapeBuffer, center, - (outerDiam - penThickness) / 2, seg_per_circle, penThickness ); + // Note: outerDiam is the outer diameter of the ring. + // the ring graphic diameter is (outerDiam - penThickness) + if( outerDiam <= penThickness ) + { // No room to draw a ring (no room for the hole): + // draw a circle instead (with no hole), with the right diameter + TransformCircleToPolygon( aShapeBuffer, center, + outerDiam / 2, seg_per_circle ); + } + else + TransformRingToPolygon( aShapeBuffer, center, + (outerDiam - penThickness) / 2, + seg_per_circle, penThickness ); } // Draw the cross: diff --git a/gerbview/gerber_test_files/aperture_macro_moire.gbr b/gerbview/gerber_test_files/aperture_macro_moire.gbr new file mode 100644 index 0000000000..c5b7aa1774 --- /dev/null +++ b/gerbview/gerber_test_files/aperture_macro_moire.gbr @@ -0,0 +1,32 @@ +G04 Verification of moire aperture macro * +%MOMM*% +%FSLAX23Y23*% +%OFA0.0000B0.0000*% +G90* +G04 parameters are +G04 1 X coordinate of center point, a decimal* +G04 2 Y coordinate of center point, a decimal* +G04 3 Outer diameter of outer concentric ring, a decimal >= 0* +G04 4 Ring thickness, a decimal >= 0* +G04 5 Gap between rings, a decimal >= 0* +G04 6 Maximum number of rings, an integer >= 0* +G04 7 Cross hair thickness, a decimal >= 0* +G04 8 Cross hair length, a decimal >= 0* +G04 9 Rotation angle of the moiré primitive* +%AMMOIRE* +6,0,0, 11.0,1.3,1.2,6, 0.2,14, 20* +% +G04 Outline* +%ADD10C,0.1*% +X0Y0D02* +G54D10* +X0Y0D01* +X40000D01* +Y40000D01* +X0D01* +Y0D01* +G04 Draw Moire * +%ADD10MOIRE*% +G54D10* +X20000Y20000D03* +M02*