KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_aperture_macro.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
23
24#include <boost/test/unit_test.hpp>
25
26#include <aperture_macro.h>
27#include <am_primitive.h>
28#include <am_param.h>
29#include <dcode.h>
30#include <gerber_draw_item.h>
31#include <gerber_file_image.h>
33
34
35BOOST_AUTO_TEST_SUITE( GerbviewApertureMacro )
36
37
38namespace
39{
40
46int circlePrimitiveSegmentCount( double aDiameterMm )
47{
48 APERTURE_MACRO macro;
49 AM_PRIMITIVE prim( true, AMP_CIRCLE );
50
51 auto pushValue =
52 []( AM_PRIMITIVE& aPrim, double aValue )
53 {
54 AM_PARAM param;
55 param.PushOperator( PUSHVALUE, aValue );
56 aPrim.m_Params.push_back( param );
57 };
58
59 // exposure ON, diameter, center x, center y
60 pushValue( prim, 1.0 );
61 pushValue( prim, aDiameterMm );
62 pushValue( prim, 0.0 );
63 pushValue( prim, 0.0 );
64
65 SHAPE_POLY_SET buffer;
66 prim.ConvertBasicShapeToPolygon( &macro, buffer );
67
68 BOOST_REQUIRE_GT( buffer.OutlineCount(), 0 );
69
70 // The conversion closes the outline by repeating the first point.
71 return buffer.Outline( 0 ).PointCount() - 1;
72}
73
74} // namespace
75
76
77// Guards against regressing to a fixed segment count independent of the circle size.
78BOOST_AUTO_TEST_CASE( CirclePrimitiveTessellationScalesWithSize )
79{
80 int smallCount = circlePrimitiveSegmentCount( 0.2 );
81 int largeCount = circlePrimitiveSegmentCount( 20.0 );
82
83 // A larger circle needs more segments to hold the same maximum deviation.
84 BOOST_CHECK_GT( largeCount, smallCount );
85
86 // Both counts follow the TransformCircleToPolygon convention of a multiple of 8 segments
87 // with an 8-segment floor.
88 BOOST_CHECK_GE( smallCount, 8 );
89 BOOST_CHECK_EQUAL( smallCount % 8, 0 );
90 BOOST_CHECK_EQUAL( largeCount % 8, 0 );
91}
92
93
105BOOST_AUTO_TEST_CASE( EmptyMacroProducesNoOutlines )
106{
108
109 D_CODE* dcode = image.GetDCODEOrCreate( 10, true );
110 BOOST_REQUIRE( dcode != nullptr );
111 dcode->m_ApertType = APT_MACRO;
112
113 // A macro with no primitives simulates a macro with invalid template parameters:
114 // it produces no shapes, so GetApertureMacroShape returns an empty SHAPE_POLY_SET.
115 APERTURE_MACRO emptyMacro;
116 emptyMacro.m_AmName = wxT( "EMPTY_TEST_MACRO" );
117 dcode->SetMacro( &emptyMacro );
118
119 GERBER_DRAW_ITEM item( &image );
121 item.m_DCode = 10;
122
123 SHAPE_POLY_SET* shape = emptyMacro.GetApertureMacroShape( &item, VECTOR2I( 0, 0 ) );
124
125 BOOST_REQUIRE( shape != nullptr );
126 BOOST_CHECK_EQUAL( shape->OutlineCount(), 0 );
127
128 // ConvertShapeToPolygon must also leave m_Polygon with 0 outlines for an empty macro.
129 dcode->ConvertShapeToPolygon( &item );
131}
132
133
@ PUSHVALUE
Definition am_param.h:146
@ AMP_CIRCLE
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition am_param.h:281
void PushOperator(parm_item_type aType, double aValue)
Add an operator/operand to the current stack.
Definition am_param.cpp:139
An aperture macro primitive as given in gerber layer format doc.
AM_PARAMS m_Params
A sequence of parameters used by the primitive.
Support the "aperture macro" defined within standard RS274X.
wxString m_AmName
The name of the aperture macro as defined like AMVB_RECTANGLE* (name is VB_RECTANGLE)
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
Calculate the primitive shape for flashed items.
A gerber DCODE (also called Aperture) definition.
Definition dcode.h:76
void SetMacro(APERTURE_MACRO *aMacro)
Definition dcode.h:127
APERTURE_T m_ApertType
Aperture type ( Line, rectangle, circle, oval poly, macro )
Definition dcode.h:198
SHAPE_POLY_SET m_Polygon
Definition dcode.h:213
void ConvertShapeToPolygon(const GERBER_DRAW_ITEM *aParent)
Convert a shape to an equivalent polygon.
Definition dcode.cpp:288
GBR_BASIC_SHAPE_TYPE m_ShapeType
Hold the image data and parameters for one gerber file and layer parameters.
int PointCount() const
Return the number of points (vertices) in this line chain.
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
int OutlineCount() const
Return the number of outlines in the set.
@ APT_MACRO
Definition dcode.h:50
@ GBR_SPOT_MACRO
BOOST_AUTO_TEST_CASE(CirclePrimitiveTessellationScalesWithSize)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683