File: gbr_plotter_apertures.h

package info (click to toggle)
kicad 9.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 771,448 kB
  • sloc: cpp: 969,355; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 228; javascript: 167; perl: 10
file content (211 lines) | stat: -rw-r--r-- 7,213 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2020 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Plotting engine (Gerber)
 *
 * @file gbr_plotter_apertures.h
 */

#pragma once


/* Class to handle a D_CODE when plotting a board using Standard Aperture Templates
 * (complex apertures need aperture macros to be flashed)
 * 5 types:
 * Circle (round)
 * Rectangle
 * Obround (oval)
 * regular polygon
 *
 * We need round apertures to plot lines, so we also defined a aperture type for plotting
 *
 * Other aperture types are aperture macros
 */
#define FIRST_DCODE_VALUE 10    // D_CODE < 10 is a command, D_CODE >= 10 is a tool

class APERTURE
{
public:
    enum APERTURE_TYPE {
        AT_CIRCLE   = 1,        // round aperture, to flash pads
        AT_RECT     = 2,        // rect aperture, to flash pads
        AT_PLOTTING = 3,        // round aperture, to plot lines
        AT_OVAL     = 4,        // oval aperture, to flash pads
        AT_REGULAR_POLY = 5,    // Regular polygon (n vertices, n = 3 .. 12, with rotation)
        AT_REGULAR_POLY3,       // Regular polygon 3 vertices, with rotation
        AT_REGULAR_POLY4,       // Regular polygon 4 vertices, with rotation
        AT_REGULAR_POLY5,       // Regular polygon 5 vertices, with rotation
        AT_REGULAR_POLY6,       // Regular polygon 6 vertices, with rotation
        AT_REGULAR_POLY7,       // Regular polygon 7 vertices, with rotation
        AT_REGULAR_POLY8,       // Regular polygon 8 vertices, with rotation
        AT_REGULAR_POLY9,       // Regular polygon 9 vertices, with rotation
        AT_REGULAR_POLY10,      // Regular polygon 10 vertices, with rotation
        AT_REGULAR_POLY11,      // Regular polygon 11 vertices, with rotation
        AT_REGULAR_POLY12,      // Regular polygon 12 vertices, with rotation
        AM_ROUND_RECT,          // Aperture macro for round rect pads
        AM_ROT_RECT,            // Aperture macro for rotated rect pads
        APER_MACRO_OUTLINE4P,   // Aperture macro for trapezoid pads (outline with 4 corners)
        APER_MACRO_OUTLINE5P,   // Aperture macro for pad polygons with 5 corners (chamfered pads)
        APER_MACRO_OUTLINE6P,   // Aperture macro for pad polygons with 6 corners (chamfered pads)
        APER_MACRO_OUTLINE7P,   // Aperture macro for pad polygons with 7 corners (chamfered pads)
        APER_MACRO_OUTLINE8P,   // Aperture macro for pad polygons with 8 corners (chamfered pads)
        AM_ROTATED_OVAL,        // Aperture macro for rotated oval pads
                                // (not rotated uses a primitive)
        AM_FREE_POLYGON         // Aperture macro to create on the fly a free polygon, with
                                // only one parameter: rotation
    };

    void SetSize( const VECTOR2I& aSize )
    {
        m_Size = aSize;
    }

    const VECTOR2I GetSize()
    {
        return m_Size;
    }

    void SetDiameter( int aDiameter )
    {
        m_Radius = aDiameter/2;
    }

    int GetDiameter()
    {
        // For round primitive, the diameter is the m_Size.x ot m_Size.y
        if( m_Type == AT_CIRCLE || m_Type == AT_PLOTTING )
            return m_Size.x;

        // For rounded shapes (macro apertures), return m_Radius * 2
        // but usually they use the radius (m_Radius)
        return m_Radius*2;
    }

    void SetRegPolyVerticeCount( int aCount )
    {
        if( aCount < 3 )
            aCount = 3;
        else if( aCount > 12 )
            aCount = 12;

        m_Type = (APERTURE_TYPE)(AT_REGULAR_POLY3 - 3 + aCount);
    }

    int GetRegPolyVerticeCount()
    {
        return m_Type - AT_REGULAR_POLY3 + 3;
    }

    void SetRotation( const EDA_ANGLE& aRotation ) { m_Rotation = aRotation; }
    EDA_ANGLE GetRotation() { return m_Rotation; }

    // Type ( Line, rect , circulaire , ovale poly 3 to 12 vertices, aperture macro )
    APERTURE_TYPE m_Type;

    // horiz and Vert size
    VECTOR2I        m_Size;

    // list of corners for polygon shape
    std::vector<VECTOR2I> m_Corners;

    // Radius for polygon and round rect shape
    int           m_Radius;

    // Rotation in degrees
    EDA_ANGLE     m_Rotation;

    // code number ( >= 10 )
    int           m_DCode;

    // the attribute attached to this aperture
    // Only one attribute is allowed by aperture
    // 0 = no specific aperture attribute
    int           m_ApertureAttribute;
};


/** A class to define an aperture macros based on a free polygon, i.e. using a
 * primitive 4 to describe a free polygon with a rotation.
 * the aperture macro has only one parameter: rotation and is defined on the fly
 * for  aGerber file
 */
class APER_MACRO_FREEPOLY
{
public:
    APER_MACRO_FREEPOLY( const std::vector<VECTOR2I>& aPolygon, int aId )
    {
        m_Corners = aPolygon;
        m_Id = aId;
    }

    /**
     * @return true if aPolygon is the same as this, i.e. if the
     * aPolygon is the same as m_Corners
     * @param aOther is the candidate to compare
     */
    bool IsSamePoly( const std::vector<VECTOR2I>& aPolygon ) const;

    /**
     * print the aperture macro definition to aOutput
     * @param aOutput is the FILE to write
     * @param aIu2GbrMacroUnit is the scaling factor from coordinates value to
     * the Gerber file macros units (always mm or inches)
     */
    void Format( FILE * aOutput, double aIu2GbrMacroUnit );

    int CornersCount() const { return (int)m_Corners.size(); }

    std::vector<VECTOR2I> m_Corners;
    int m_Id;
};


class APER_MACRO_FREEPOLY_LIST
{
public:
    APER_MACRO_FREEPOLY_LIST() {}

    void ClearList() { m_AMList.clear(); }

    int AmCount() const { return (int)m_AMList.size(); }

    /**
     * append a new APER_MACRO_FREEPOLY containing the polygon aPolygon to the current list
     */
    void Append( const std::vector<VECTOR2I>& aPolygon );

    /**
     * @return the index in m_AMList of the APER_MACRO_FREEPOLY having the
     * same polygon as aPolygon, or -1
     * @param aCandidate is the polygon candidate to compare
     */
    int FindAm( const std::vector<VECTOR2I>& aPolygon ) const;

    /**
     * print the aperture macro list to aOutput
     * @param aOutput is the FILE to write
     * @param aIu2GbrMacroUnit is the scaling factor from coordinates value to
     * the Gerber file macros units (always mm or inches)
     */
    void Format( FILE * aOutput, double aIu2GbrMacroUnit );

    std::vector<APER_MACRO_FREEPOLY> m_AMList;
};