KiCad PCB EDA Suite
gbr_plotter_apertures.h
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) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
27 #pragma once
28 
29 
30 /* Class to handle a D_CODE when plotting a board using Standard Aperture Templates
31  * (complex apertures need aperture macros to be flashed)
32  * 5 types:
33  * Circle (round)
34  * Rectangle
35  * Obround (oval)
36  * regular polygon
37  *
38  * We need round apertures to plot lines, so we also defined a aperture type for plotting
39  *
40  * Other aperture types are aperture macros
41  */
42 #define FIRST_DCODE_VALUE 10 // D_CODE < 10 is a command, D_CODE >= 10 is a tool
43 
44 class APERTURE
45 {
46 public:
48  AT_CIRCLE = 1, // round aperture, to flash pads
49  AT_RECT = 2, // rect aperture, to flash pads
50  AT_PLOTTING = 3, // round aperture, to plot lines
51  AT_OVAL = 4, // oval aperture, to flash pads
52  AT_REGULAR_POLY = 5, // Regular polygon (n vertices, n = 3 .. 12, with rotation)
53  AT_REGULAR_POLY3, // Regular polygon 3 vertices, with rotation
54  AT_REGULAR_POLY4, // Regular polygon 4 vertices, with rotation
55  AT_REGULAR_POLY5, // Regular polygon 5 vertices, with rotation
56  AT_REGULAR_POLY6, // Regular polygon 6 vertices, with rotation
57  AT_REGULAR_POLY7, // Regular polygon 7 vertices, with rotation
58  AT_REGULAR_POLY8, // Regular polygon 8 vertices, with rotation
59  AT_REGULAR_POLY9, // Regular polygon 9 vertices, with rotation
60  AT_REGULAR_POLY10, // Regular polygon 10 vertices, with rotation
61  AT_REGULAR_POLY11, // Regular polygon 11 vertices, with rotation
62  AT_REGULAR_POLY12, // Regular polygon 12 vertices, with rotation
63  AM_ROUND_RECT, // Aperture macro for round rect pads
64  AM_ROT_RECT, // Aperture macro for rotated rect pads
65  APER_MACRO_OUTLINE4P, // Aperture macro for trapezoid pads (outline with 4 corners)
66  APER_MACRO_OUTLINE5P, // Aperture macro for pad polygons with 5 corners (chamfered pads)
67  APER_MACRO_OUTLINE6P, // Aperture macro for pad polygons with 6 corners (chamfered pads)
68  APER_MACRO_OUTLINE7P, // Aperture macro for pad polygons with 7 corners (chamfered pads)
69  APER_MACRO_OUTLINE8P, // Aperture macro for pad polygons with 8 corners (chamfered pads)
70  AM_ROTATED_OVAL, // Aperture macro for rotated oval pads
71  // (not rotated uses a primitive)
72  AM_FREE_POLYGON // Aperture macro to create on the fly a free polygon, with
73  // only one parameter: rotation
74  };
75 
76  void SetSize( const wxSize& aSize )
77  {
78  m_Size = aSize;
79  }
80 
81  const wxSize GetSize()
82  {
83  return m_Size;
84  }
85 
86  void SetDiameter( int aDiameter )
87  {
88  m_Radius = aDiameter/2;
89  }
90 
92  {
93  // For round primitive, the diameter is the m_Size.x ot m_Size.y
94  if( m_Type == AT_CIRCLE || m_Type == AT_PLOTTING )
95  return m_Size.x;
96 
97  // For rounded shapes (macro apertures), return m_Radius * 2
98  // but usually they use the radius (m_Radius)
99  return m_Radius*2;
100  }
101 
102  void SetRegPolyVerticeCount( int aCount )
103  {
104  if( aCount < 3 )
105  aCount = 3;
106  else if( aCount > 12 )
107  aCount = 12;
108 
109  m_Type = (APERTURE_TYPE)(AT_REGULAR_POLY3 - 3 + aCount);
110  }
111 
113  {
114  return m_Type - AT_REGULAR_POLY3 + 3;
115  }
116 
117  void SetRotation( double aRotDegree )
118  {
119  // The rotation is stored in degree
120  m_Rotation = aRotDegree;
121  }
122 
123  double GetRotation()
124  {
125  // The rotation is stored in degree
126  return m_Rotation;
127  }
128 
129  // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices, aperture macro )
131 
132  // horiz and Vert size
133  wxSize m_Size;
134 
135  // list of corners for polygon shape
136  std::vector<wxPoint> m_Corners;
137 
138  // Radius for polygon and round rect shape
139  int m_Radius;
140 
141  // Rotation in degrees
142  double m_Rotation;
143 
144  // code number ( >= 10 )
145  int m_DCode;
146 
147  // the attribute attached to this aperture
148  // Only one attribute is allowed by aperture
149  // 0 = no specific aperture attribute
151 };
152 
153 
160 {
161 public:
162  APER_MACRO_FREEPOLY( const std::vector<wxPoint>& aPolygon, int aId )
163  {
164  m_Corners = aPolygon;
165  m_Id = aId;
166  }
167 
173  bool IsSamePoly( const std::vector<wxPoint>& aPolygon ) const;
174 
181  void Format( FILE * aOutput, double aIu2GbrMacroUnit );
182 
183  int CornersCount() const { return (int)m_Corners.size(); }
184 
185  std::vector<wxPoint> m_Corners;
186  int m_Id;
187 };
188 
189 
191 {
192 public:
194 
195  void ClearList() { m_AMList.clear(); }
196 
197  int AmCount() const { return (int)m_AMList.size(); }
198 
202  void Append( const std::vector<wxPoint>& aPolygon );
203 
209  int FindAm( const std::vector<wxPoint>& aPolygon ) const;
210 
217  void Format( FILE * aOutput, double aIu2GbrMacroUnit );
218 
219  std::vector<APER_MACRO_FREEPOLY> m_AMList;
220 };
void SetRegPolyVerticeCount(int aCount)
void SetRotation(double aRotDegree)
APERTURE_TYPE m_Type
void SetDiameter(int aDiameter)
APER_MACRO_FREEPOLY(const std::vector< wxPoint > &aPolygon, int aId)
void SetSize(const wxSize &aSize)
void Append(const std::vector< wxPoint > &aPolygon)
append a new APER_MACRO_FREEPOLY containing the polygon aPolygon to the current list
A class to define an aperture macros based on a free polygon, i.e.
std::vector< wxPoint > m_Corners
int GetRegPolyVerticeCount()
std::vector< APER_MACRO_FREEPOLY > m_AMList
const wxSize GetSize()
std::vector< wxPoint > m_Corners
int FindAm(const std::vector< wxPoint > &aPolygon) const
double GetRotation()
void Format(FILE *aOutput, double aIu2GbrMacroUnit)
print the aperture macro definition to aOutput
void Format(FILE *aOutput, double aIu2GbrMacroUnit)
print the aperture macro list to aOutput
bool IsSamePoly(const std::vector< wxPoint > &aPolygon) const