KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 (C) 1992-2017 Jean-Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
25
26
27#include <gerbview.h>
28#include <aperture_macro.h>
29#include <gerber_draw_item.h>
30
32{
33 // store the initial values coming from aDcode into m_localParamValues
34 // for n parameters, they are local params $1 to $n
35 m_localParamValues.clear();
36
37 // Note: id_param = 1... n, not 0
38 for( unsigned id_param = 1; id_param <= aDcode->GetParamCount(); id_param++ )
39 m_localParamValues[id_param] = aDcode->GetParam( id_param );
40
42}
43
44
46{
47 // Evaluate m_localParamValues from current m_paramLevelEval to
48 // aPrimitive.m_LocalParamLevel
49 // if m_paramLevelEval >= m_LocalParamLevel, do nothing: the
50 // m_localParamValues are already up to date
51
52 if( m_paramLevelEval >= aPrimitive.m_LocalParamLevel )
53 return;
54
56 {
58 int prm_index = am_param.GetIndex();
59
60 double value = am_param.GetValueFromMacro( this );
61
62 // if am_param value is not yet stored in m_localParamValues, add it.
63 // if it is already in m_localParamValues, update its value;
64 m_localParamValues[ prm_index ] = value;
65 }
66}
67
68
70{
71 // return the local param value stored in m_localParamValues
72 // if not existing, returns 0
73
74 if( m_localParamValues.find( aIndex ) != m_localParamValues.end() )
75 return m_localParamValues[ aIndex ];
76
77 return 0.0;
78}
79
80
82{
83 m_primitivesList.push_back( aPrimitive );
84 m_primitivesList.back().m_LocalParamLevel = m_localParamStack.size();
85}
86
91
92
97
98
100 const VECTOR2I& aShapePos )
101{
102 SHAPE_POLY_SET holeBuffer;
103
104 m_shape.RemoveAllContours();
105 D_CODE* dcode = aParent->GetDcodeDescr();
106 InitLocalParams( dcode );
107
108 for( AM_PRIMITIVE& prim_macro : m_primitivesList )
109 {
110 if( prim_macro.m_Primitive_id == AMP_COMMENT )
111 continue;
112
113 if( prim_macro.IsAMPrimitiveExposureOn( this ) )
114 {
115 prim_macro.ConvertBasicShapeToPolygon( this, m_shape );
116 }
117 else
118 {
119 prim_macro.ConvertBasicShapeToPolygon( this, holeBuffer );
120
121 if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
122 {
123 m_shape.BooleanSubtract( holeBuffer );
124 holeBuffer.RemoveAllContours();
125 }
126 }
127 }
128
129 // Merge and cleanup basic shape polygons
130 m_shape.Simplify();
131
132 // A hole can be is defined inside a polygon, or the polygons themselve can create
133 // a hole when merged, so we must fracture the polygon to be able to drawn it
134 // (i.e link holes by overlapping edges)
135 m_shape.Fracture();
136
137 // Move m_shape to the actual draw position:
138 for( int icnt = 0; icnt < m_shape.OutlineCount(); icnt++ )
139 {
140
141 SHAPE_LINE_CHAIN& outline = m_shape.Outline( icnt );
142
143 for( int jj = 0; jj < outline.PointCount(); jj++ )
144 {
145 VECTOR2I point = outline.CPoint( jj );
146 point += aShapePos;
147 point = aParent->GetABPosition( point );
148 outline.SetPoint( jj, point );
149 }
150 }
151
152 return &m_shape;
153}
@ AMP_COMMENT
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition am_param.h:281
unsigned GetIndex() const
Definition am_param.h:305
double GetValueFromMacro(APERTURE_MACRO *aApertureMacro) const
Definition am_param.cpp:69
An aperture macro primitive as given in gerber layer format doc.
int m_LocalParamLevel
void InitLocalParams(const D_CODE *aDcode)
Init m_localParamValues to a initial values coming from aDcode and clear m_paramLevelEval must be cal...
double GetLocalParamValue(int aIndex)
std::map< int, double > m_localParamValues
m_localParamValues is the current value of local parameters after evaluation the key is the local par...
int m_paramLevelEval
the current level of local param values evaluation when a primitive is evaluated, if its m_LocalParam...
std::vector< AM_PRIMITIVE > m_primitivesList
A list of AM_PRIMITIVEs to define the shape of the aperture macro.
void AddLocalParamDefToStack()
A deferred parameter can be defined in aperture macro, but outside aperture primitives.
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, const VECTOR2I &aShapePos)
Calculate the primitive shape for flashed items.
AM_PARAM & GetLastLocalParamDefFromStack()
AM_PARAMS m_localParamStack
m_localparamStack handle a list of local deferred parameters
SHAPE_POLY_SET m_shape
The shape of the item, calculated by GetApertureMacroShape.
void AddPrimitiveToList(AM_PRIMITIVE &aPrimitive)
Add a new ptimitive ( AMP_CIRCLE, AMP_LINE2 ...) to the list of primitives to define the full shape o...
void EvalLocalParams(const AM_PRIMITIVE &aPrimitive)
Evaluate m_localParamValues from current m_paramLevelEval to aPrimitive m_LocalParamLevel if m_paramL...
A gerber DCODE (also called Aperture) definition.
Definition dcode.h:76
double GetParam(unsigned aIdx) const
Return a parameter stored in parameter list.
Definition dcode.h:117
unsigned GetParamCount() const
Return the number of parameters stored in parameter list.
Definition dcode.h:106
D_CODE * GetDcodeDescr() const
Return the GetDcodeDescr of this object, or NULL.
VECTOR2I GetABPosition(const VECTOR2I &aXYPosition) const
Return the image position of aPosition for this object.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
void SetPoint(int aIndex, const VECTOR2I &aPos)
Move a point to a specific location.
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
void RemoveAllContours()
Remove all outlines & holes (clears) the polygon set.
int OutlineCount() const
Return the number of outlines in the set.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683