KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
45{
46public:
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 VECTOR2I& aSize )
77 {
78 m_Size = aSize;
79 }
80
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( const EDA_ANGLE& aRotation ) { m_Rotation = aRotation; }
119
120 // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices, aperture macro )
122
123 // horiz and Vert size
125
126 // list of corners for polygon shape
127 std::vector<VECTOR2I> m_Corners;
128
129 // Radius for polygon and round rect shape
131
132 // Rotation in degrees
134
135 // code number ( >= 10 )
137
138 // the attribute attached to this aperture
139 // Only one attribute is allowed by aperture
140 // 0 = no specific aperture attribute
142};
143
144
151{
152public:
153 APER_MACRO_FREEPOLY( const std::vector<VECTOR2I>& aPolygon, int aId )
154 {
155 m_Corners = aPolygon;
156 m_Id = aId;
157 }
158
164 bool IsSamePoly( const std::vector<VECTOR2I>& aPolygon ) const;
165
172 void Format( FILE * aOutput, double aIu2GbrMacroUnit );
173
174 int CornersCount() const { return (int)m_Corners.size(); }
175
176 std::vector<VECTOR2I> m_Corners;
177 int m_Id;
178};
179
180
182{
183public:
185
186 void ClearList() { m_AMList.clear(); }
187
188 int AmCount() const { return (int)m_AMList.size(); }
189
193 void Append( const std::vector<VECTOR2I>& aPolygon );
194
200 int FindAm( const std::vector<VECTOR2I>& aPolygon ) const;
201
208 void Format( FILE * aOutput, double aIu2GbrMacroUnit );
209
210 std::vector<APER_MACRO_FREEPOLY> m_AMList;
211};
int GetRegPolyVerticeCount()
const VECTOR2I GetSize()
EDA_ANGLE GetRotation()
EDA_ANGLE m_Rotation
std::vector< VECTOR2I > m_Corners
void SetRotation(const EDA_ANGLE &aRotation)
APERTURE_TYPE m_Type
void SetSize(const VECTOR2I &aSize)
void SetDiameter(int aDiameter)
void SetRegPolyVerticeCount(int aCount)
std::vector< APER_MACRO_FREEPOLY > m_AMList
void Append(const std::vector< VECTOR2I > &aPolygon)
append a new APER_MACRO_FREEPOLY containing the polygon aPolygon to the current list
int FindAm(const std::vector< VECTOR2I > &aPolygon) const
void Format(FILE *aOutput, double aIu2GbrMacroUnit)
print the aperture macro list to aOutput
A class to define an aperture macros based on a free polygon, i.e.
void Format(FILE *aOutput, double aIu2GbrMacroUnit)
print the aperture macro definition to aOutput
bool IsSamePoly(const std::vector< VECTOR2I > &aPolygon) const
APER_MACRO_FREEPOLY(const std::vector< VECTOR2I > &aPolygon, int aId)
std::vector< VECTOR2I > m_Corners