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 (C) 1992-2023 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, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
31#include <gerbview.h>
32#include <aperture_macro.h>
33#include <gerber_draw_item.h>
34
36{
37 // store the initial values coming from aDcode into m_localParamValues
38 // for n parameters, they are local params $1 to $n
39 m_localParamValues.clear();
40
41 // Note: id_param = 1... n, not 0
42 for( unsigned id_param = 1; id_param <= aDcode->GetParamCount(); id_param++ )
43 m_localParamValues[id_param] = aDcode->GetParam( id_param );
44
46}
47
48
50{
51 // Evaluate m_localParamValues from current m_paramLevelEval to
52 // aPrimitive.m_LocalParamLevel
53 // if m_paramLevelEval >= m_LocalParamLevel, do nothing: the
54 // m_localParamValues are already up to date
55
56 if( m_paramLevelEval >= aPrimitive.m_LocalParamLevel )
57 return;
58
60 {
62 int prm_index = am_param.GetIndex();
63
64 double value = am_param.GetValueFromMacro( this );
65
66 // if am_param value is not yet stored in m_localParamValues, add it.
67 // if it is already in m_localParamValues, update its value;
68 m_localParamValues[ prm_index ] = value;
69 }
70}
71
72
74{
75 // return the local param value stored in m_localParamValues
76 // if not existing, returns 0
77
78 if( m_localParamValues.find( aIndex ) != m_localParamValues.end() )
79 return m_localParamValues[ aIndex ];
80
81 return 0.0;
82}
83
84
86{
87 m_primitivesList.push_back( aPrimitive );
88 m_primitivesList.back().m_LocalParamLevel = m_localParamStack.size();
89}
90
92{
93 m_localParamStack.push_back( AM_PARAM() );
94}
95
96
98{
99 return m_localParamStack.back();
100}
101
102
104 const VECTOR2I& aShapePos )
105{
106 SHAPE_POLY_SET holeBuffer;
107
109 D_CODE* dcode = aParent->GetDcodeDescr();
110 InitLocalParams( dcode );
111
112 for( AM_PRIMITIVE& prim_macro : m_primitivesList )
113 {
114 if( prim_macro.m_Primitive_id == AMP_COMMENT )
115 continue;
116
117 if( prim_macro.IsAMPrimitiveExposureOn( this ) )
118 {
119 prim_macro.ConvertBasicShapeToPolygon( this, m_shape );
120 }
121 else
122 {
123 prim_macro.ConvertBasicShapeToPolygon( this, holeBuffer );
124
125 if( holeBuffer.OutlineCount() ) // we have a new hole in shape: remove the hole
126 {
128 holeBuffer.RemoveAllContours();
129 }
130 }
131 }
132
133 // Merge and cleanup basic shape polygons
135
136 // A hole can be is defined inside a polygon, or the polygons themselve can create
137 // a hole when merged, so we must fracture the polygon to be able to drawn it
138 // (i.e link holes by overlapping edges)
140
141 // Move m_shape to the actual draw position:
142 for( int icnt = 0; icnt < m_shape.OutlineCount(); icnt++ )
143 {
144
145 SHAPE_LINE_CHAIN& outline = m_shape.Outline( icnt );
146
147 for( int jj = 0; jj < outline.PointCount(); jj++ )
148 {
149 VECTOR2I point = outline.CPoint( jj );
150 point += aShapePos;
151 point = aParent->GetABPosition( point );
152 outline.SetPoint( jj, point );
153 }
154 }
155
156 return &m_shape;
157}
@ AMP_COMMENT
Definition: am_primitive.h:71
Hold a parameter value for an "aperture macro" as defined within standard RS274X.
Definition: am_param.h:285
unsigned GetIndex() const
Definition: am_param.h:309
double GetValueFromMacro(APERTURE_MACRO *aApertureMacro) const
Definition: am_param.cpp:73
An aperture macro primitive as given in gerber layer format doc.
Definition: am_primitive.h:92
int m_LocalParamLevel
Definition: am_primitive.h:98
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:80
double GetParam(unsigned aIdx) const
Return a parameter stored in parameter list.
Definition: dcode.h:110
unsigned GetParamCount() const
Return the number of parameters stored in parameter list.
Definition: dcode.h:99
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.
void BooleanSubtract(const SHAPE_POLY_SET &b, POLYGON_MODE aFastMode)
Perform boolean polyset difference For aFastMode meaning, see function booleanOp.
void Fracture(POLYGON_MODE aFastMode)
Convert a set of polygons with holes to a single outline with "slits"/"fractures" connecting the oute...
void Simplify(POLYGON_MODE aFastMode)
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFastMo...
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.