KiCad PCB EDA Suite
class_aperture_macro.h
Go to the documentation of this file.
1 
5 #ifndef _APERTURE_MACRO_H_
6 #define _APERTURE_MACRO_H_
7 
8 /*
9  * This program source code file is part of KiCad, a free EDA CAD application.
10  *
11  * Copyright (C) 1992-2010 Jean-Pierre Charras <jp.charras at wanadoo.fr>
12  * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
13  * Copyright (C) 1992-2010 KiCad Developers, see AUTHORS.txt for contributors.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, you may find one here:
27  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28  * or you may search the http://www.gnu.org website for the version 2 license,
29  * or you may write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31  */
32 
33 #include <vector>
34 #include <set>
35 
36 #include <base_struct.h>
37 #include <class_am_param.h>
38 #include <class_eda_rect.h>
39 
40 class SHAPE_POLY_SET;
41 
42 /*
43  * An aperture macro defines a complex shape and is a list of aperture primitives.
44  * Each aperture primitive defines a simple shape (circle, rect, regular polygon...)
45  * Inside a given aperture primitive, a fixed list of parameters defines info
46  * about the shape: size, thickness, number of vertex ...
47  *
48  * Each parameter can be an immediate value or a defered value.
49  * When value is defered, it is defined when the aperture macro is instancied by
50  * an ADD macro command
51  * Note also a defered parameter can be defined in aperture macro,
52  * but outside aperture primitives. Example
53  * %AMRECTHERM*
54  * $4=$3/2* parameter $4 is half value of parameter $3
55  * 21,1,$1-$3,$2-$3,0-$1/2-$4,0-$2/2-$4,0*
56  * For the aperture primitive, parameters $1 to $3 will be defined in ADD command,
57  * and $4 is defined inside the macro
58  *
59  * Each basic shape can be a positive shape or a negative shape.
60  * a negative shape is "local" to the whole shape.
61  * It must be seen like a hole in the shape, and not like a standard negative object.
62  */
63 
72  AMP_UNKNOWN = -1, // A value for uninitialized AM_PRIMITIVE.
73  AMP_COMMENT = 0, // A primitive description is not really a primitive, this is a comment
74  AMP_CIRCLE = 1, // Circle. (diameter and position)
75  AMP_LINE2 = 2, // Line with rectangle ends. (Width, start and end pos + rotation)
76  AMP_LINE20 = 20, // Same as AMP_LINE2
77  AMP_LINE_CENTER = 21, // Rectangle. (height, width and center pos + rotation)
78  AMP_LINE_LOWER_LEFT = 22, // Rectangle. (height, width and left bottom corner pos + rotation)
79  AMP_EOF = 3, // End Of File marquer: not really a shape
80  AMP_OUTLINE = 4, // Free polyline (n corners + rotation)
81  AMP_POLYGON = 5, // Closed regular polygon(diameter, number of vertices (3 to 10), rotation)
82  AMP_MOIRE = 6, // A cross hair with n concentric circles + rotation
83  AMP_THERMAL = 7 // Thermal shape (pos, outer and inner diameter, cross hair thickness + rotation)
84 };
85 
86 
93 {
94 public:
97  // the primitive
98  bool m_GerbMetric; // units for this primitive:
99  // false = Inches, true = metric
100 public: AM_PRIMITIVE( bool aGerbMetric, AM_PRIMITIVE_ID aId = AMP_UNKNOWN )
101  {
102  primitive_id = aId;
103  m_GerbMetric = aGerbMetric;
104  }
105 
106 
108 
117  bool IsAMPrimitiveExposureOn( const GERBER_DRAW_ITEM* aParent ) const;
118 
119  /* Draw functions: */
120 
131  int GetShapeDim( const GERBER_DRAW_ITEM* aParent );
132 
140  void DrawBasicShape( const GERBER_DRAW_ITEM* aParent,
141  SHAPE_POLY_SET& aShapeBuffer,
142  wxPoint aShapePos );
143 private:
144 
152  void ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
153  std::vector<wxPoint>& aBuffer );
154 };
155 
156 
157 typedef std::vector<AM_PRIMITIVE> AM_PRIMITIVES;
158 
164 {
165  wxString name;
167 
168  /* A defered parameter can be defined in aperture macro,
169  * but outside aperture primitives. Example
170  * %AMRECTHERM*
171  * $4=$3/2* parameter $4 is half value of parameter $3
172  * m_localparamStack handle a list of local defered parameters
173  */
175 
178 
190  double GetLocalParam( const D_CODE* aDcode, unsigned aParamId ) const;
191 
192 
200  SHAPE_POLY_SET* GetApertureMacroShape( const GERBER_DRAW_ITEM* aParent, wxPoint aShapePos );
201 
213  void DrawApertureMacroShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC,
214  COLOR4D aColor, wxPoint aShapePos, bool aFilledShape );
215 
228  int GetShapeDim( GERBER_DRAW_ITEM* aParent );
229 
232  {
233  return m_boundingBox;
234  }
235 };
236 
237 
244 {
245  // a "less than" test on two APERTURE_MACROs (.name wxStrings)
246  bool operator()( const APERTURE_MACRO& am1, const APERTURE_MACRO& am2 ) const
247  {
248  return am1.name.Cmp( am2.name ) < 0; // case specific wxString compare
249  }
250 };
251 
252 
258 typedef std::set<APERTURE_MACRO, APERTURE_MACRO_less_than> APERTURE_MACRO_SET;
259 typedef std::pair<APERTURE_MACRO_SET::iterator, bool> APERTURE_MACRO_SET_PAIR;
260 
261 
262 #endif // ifndef _APERTURE_MACRO_H_
wxString name
The name of the aperture macro.
void DrawBasicShape(const GERBER_DRAW_ITEM *aParent, SHAPE_POLY_SET &aShapeBuffer, wxPoint aShapePos)
Function drawBasicShape Draw (in fact generate the actual polygonal shape of) the primitive shape of ...
void DrawApertureMacroShape(GERBER_DRAW_ITEM *aParent, EDA_RECT *aClipBox, wxDC *aDC, COLOR4D aColor, wxPoint aShapePos, bool aFilledShape)
Function DrawApertureMacroShape Draw the primitive shape for flashed items.
EDA_RECT m_boundingBox
The bounding box of the item, calculated by GetApertureMacroShape.
std::pair< APERTURE_MACRO_SET::iterator, bool > APERTURE_MACRO_SET_PAIR
AM_PRIMITIVE_ID
Enum AM_PRIMITIVE_ID is the set of all "aperture macro primitives" (primitive numbers).
std::vector< AM_PARAM > AM_PARAMS
int GetShapeDim(const GERBER_DRAW_ITEM *aParent)
GetShapeDim Calculate a value that can be used to evaluate the size of text when displaying the D-Cod...
Struct APERTURE_MACRO_less_than is used by std:set instantiation which uses APERTURE_...
void ConvertShapeToPolygon(const GERBER_DRAW_ITEM *aParent, std::vector< wxPoint > &aBuffer)
Function ConvertShapeToPolygon convert a shape to an equivalent polygon.
SHAPE_POLY_SET * GetApertureMacroShape(const GERBER_DRAW_ITEM *aParent, wxPoint aShapePos)
Function GetApertureMacroShape Calculate the primitive shape for flashed items.
Class SHAPE_POLY_SET.
bool operator()(const APERTURE_MACRO &am1, const APERTURE_MACRO &am2) const
std::vector< AM_PRIMITIVE > AM_PRIMITIVES
SHAPE_POLY_SET m_shape
The shape of the item, calculated by GetApertureMacroShape.
double GetLocalParam(const D_CODE *aDcode, unsigned aParamId) const
function GetLocalParam Usually, parameters are defined inside the aperture primitive using immediate ...
AM_PRIMITIVE(bool aGerbMetric, AM_PRIMITIVE_ID aId=AMP_UNKNOWN)
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:82
EDA_RECT GetBoundingBox() const
Returns the bounding box of the shape.
Class EDA_RECT handles the component boundary box.
Struct AM_PRIMITIVE holds an aperture macro primitive as given in Table 3 of http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf.
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
Basic classes for most KiCad items.
int GetShapeDim(GERBER_DRAW_ITEM *aParent)
Function GetShapeDim Calculate a value that can be used to evaluate the size of text when displaying ...
std::set< APERTURE_MACRO, APERTURE_MACRO_less_than > APERTURE_MACRO_SET
Type APERTURE_MACRO_SET is a sorted collection of APERTURE_MACROS whose key is the name field in the ...
AM_PARAMS params
A sequence of parameters used by.
bool IsAMPrimitiveExposureOn(const GERBER_DRAW_ITEM *aParent) const
Function IsAMPrimitiveExposureOn.
AM_PRIMITIVE_ID primitive_id
The primitive type.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39