KiCad PCB EDA Suite
Loading...
Searching...
No Matches
padstack.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) 2024 Jon Evans <[email protected]>
5 * Copyright (C) 2024 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
21#ifndef KICAD_PADSTACK_H
22#define KICAD_PADSTACK_H
23
24#include <memory>
25#include <optional>
26#include <wx/string.h>
27
28#include <api/serializable.h>
29#include <geometry/eda_angle.h>
30#include <layer_ids.h>
31#include <math/vector2d.h>
32#include <properties/property.h>
33#include <zones.h>
34
35class BOARD_ITEM;
36class PCB_SHAPE;
37
38
44enum class PAD_SHAPE : int
45{
46 CIRCLE,
47 RECTANGLE, // do not use just RECT: it collides in a header on MSYS2
48 OVAL,
51
52 // Rectangle with a chamfered corner ( and with rounded other corners).
54 CUSTOM // A shape defined by user, using a set of basic shapes
55 // (thick segments, circles, arcs, polygons).
56};
57
62{
63 CIRCLE,
64 OBLONG,
65};
66
72enum class PAD_ATTRIB
73{
74 PTH,
75 SMD,
76 CONN,
79 NPTH,
81};
82
83
89enum class PAD_PROP
90{
91 NONE,
92 BGA,
95 TESTPOINT,
96 HEATSINK,
99};
100
101
115class PADSTACK : public SERIALIZABLE
116{
117public:
120 enum class TYPE
121 {
122 NORMAL,
123 VIA,
124 MOUNTING
125 };
126
127 enum class MODE
128 {
129 NORMAL,
131 CUSTOM
132 };
133
136 {
137 KEEP_ALL,
140 };
141
143 {
144 OUTLINE,
146 };
147
150 {
154
155 /*
156 * Most of the time the hole is the center of the shape (m_Offset = 0). But some designers
157 * use oblong/rect pads with a hole moved to one of the oblong/rect pad shape ends.
158 * In all cases the hole is at the pad position. This offset is from the hole to the center
159 * of the pad shape (ie: the copper area around the hole).
160 * ShapePos() returns the board shape position according to the offset and the pad rotation.
161 */
163
168
174
175 SHAPE_PROPS();
176 bool operator==( const SHAPE_PROPS& aOther ) const;
177 };
178
192 {
194 std::optional<ZONE_CONNECTION> zone_connection;
195 std::optional<int> thermal_spoke_width;
196 std::optional<EDA_ANGLE> thermal_spoke_angle;
197 std::optional<int> thermal_gap;
198 std::optional<int> clearance;
199
200 /*
201 * Editing definitions of primitives for custom pad shapes. In local coordinates relative
202 * to m_Pos (NOT shapePos) at orient 0.
203 */
204 std::vector<std::shared_ptr<PCB_SHAPE>> custom_shapes;
205
206 bool operator==( const COPPER_LAYER_PROPS& aOther ) const;
207 };
208
212 {
213 std::optional<int> solder_mask_margin;
214 std::optional<int> solder_paste_margin;
215 std::optional<double> solder_paste_margin_ratio;
216 std::optional<bool> has_solder_mask;
217 std::optional<bool> has_solder_paste;
218
219 bool operator==( const OUTER_LAYER_PROPS& aOther ) const;
220 };
221
224 {
229
230 bool operator==( const DRILL_PROPS& aOther ) const;
231 };
232
233public:
234 PADSTACK( BOARD_ITEM* aParent );
235 virtual ~PADSTACK() = default;
236 PADSTACK( const PADSTACK& aOther );
237 PADSTACK& operator=( const PADSTACK &aOther );
238
239 bool operator==( const PADSTACK& aOther ) const;
240 bool operator!=( const PADSTACK& aOther ) const { return !operator==( aOther ); }
241
242 void Serialize( google::protobuf::Any &aContainer ) const override;
243 bool Deserialize( const google::protobuf::Any &aContainer ) override;
244
245 const LSET& LayerSet() const { return m_layerSet; }
246 LSET& LayerSet() { return m_layerSet; }
247 void SetLayerSet( const LSET& aSet ) { m_layerSet = aSet; }
248
249 PCB_LAYER_ID StartLayer() const;
250 PCB_LAYER_ID EndLayer() const;
251
252 MODE Mode() const { return m_mode; }
253 void SetMode( MODE aMode ) { m_mode = aMode; }
254
256 wxString Name() const;
257
260 {
261 m_orientation = aAngle;
263 }
264
265 DRILL_PROPS& Drill() { return m_drill; }
266 const DRILL_PROPS& Drill() const { return m_drill; }
267
269 const DRILL_PROPS& SecondaryDrill() const { return m_secondaryDrill; }
270
273
276
279
282
283 // The following section has convenience getters for the padstack properties on a given layer.
284
285 PAD_SHAPE Shape( PCB_LAYER_ID aLayer = F_Cu ) const;
286 void SetShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
287
288 VECTOR2I& Size( PCB_LAYER_ID aLayer = F_Cu );
289 const VECTOR2I& Size( PCB_LAYER_ID aLayer = F_Cu ) const;
290
292 void SetDrillShape( PAD_DRILL_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
293
294 VECTOR2I& Offset( PCB_LAYER_ID aLayer = F_Cu );
295 const VECTOR2I& Offset( PCB_LAYER_ID aLayer = F_Cu ) const;
296
297 PAD_SHAPE AnchorShape( PCB_LAYER_ID aLayer = F_Cu ) const;
298 void SetAnchorShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
299
301 const VECTOR2I& TrapezoidDeltaSize( PCB_LAYER_ID aLayer = F_Cu ) const;
302
303 double RoundRectRadiusRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
304 void SetRoundRectRadiusRatio( double aRatio, PCB_LAYER_ID aLayer = F_Cu );
305
306 int RoundRectRadius( PCB_LAYER_ID aLayer = F_Cu ) const;
307 void SetRoundRectRadius( double aRadius, PCB_LAYER_ID aLayer = F_Cu );
308
309 double ChamferRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
310 void SetChamferRatio( double aRatio, PCB_LAYER_ID aLayer = F_Cu );
311
312 int& ChamferPositions( PCB_LAYER_ID aLayer = F_Cu );
313 const int& ChamferPositions( PCB_LAYER_ID aLayer = F_Cu ) const;
314 void SetChamferPositions( int aPositions, PCB_LAYER_ID aLayer = F_Cu );
315
316 std::optional<int>& Clearance( PCB_LAYER_ID aLayer = F_Cu );
317 const std::optional<int>& Clearance( PCB_LAYER_ID aLayer = F_Cu ) const;
318
319 std::optional<int>& SolderMaskMargin( PCB_LAYER_ID aLayer = F_Cu );
320 const std::optional<int>& SolderMaskMargin( PCB_LAYER_ID aLayer = F_Cu ) const;
321
322 std::optional<int>& SolderPasteMargin( PCB_LAYER_ID aLayer = F_Cu );
323 const std::optional<int>& SolderPasteMargin( PCB_LAYER_ID aLayer = F_Cu ) const;
324
325 std::optional<double>& SolderPasteMarginRatio( PCB_LAYER_ID aLayer = F_Cu );
326 const std::optional<double>& SolderPasteMarginRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
327
328 std::optional<ZONE_CONNECTION>& ZoneConnection( PCB_LAYER_ID aLayer = F_Cu );
329 const std::optional<ZONE_CONNECTION>& ZoneConnection( PCB_LAYER_ID aLayer = F_Cu ) const;
330
331 std::optional<int>& ThermalSpokeWidth( PCB_LAYER_ID aLayer = F_Cu );
332 const std::optional<int>& ThermalSpokeWidth( PCB_LAYER_ID aLayer = F_Cu ) const;
333
334 std::optional<int>& ThermalGap( PCB_LAYER_ID aLayer = F_Cu );
335 const std::optional<int>& ThermalGap( PCB_LAYER_ID aLayer = F_Cu ) const;
336
338 void SetThermalSpokeAngle( EDA_ANGLE aAngle, PCB_LAYER_ID aLayer = F_Cu );
339
340 std::vector<std::shared_ptr<PCB_SHAPE>>& Primitives( PCB_LAYER_ID aLayer = F_Cu );
341 const std::vector<std::shared_ptr<PCB_SHAPE>>& Primitives( PCB_LAYER_ID aLayer = F_Cu ) const;
342
348 void AddPrimitive( PCB_SHAPE* aShape, PCB_LAYER_ID aLayer = F_Cu );
349
355 void AppendPrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
356 PCB_LAYER_ID aLayer = F_Cu );
357
364 void ReplacePrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
365 PCB_LAYER_ID aLayer = F_Cu );
366
367 void ClearPrimitives( PCB_LAYER_ID aLayer = F_Cu );
368
369private:
372
375
378
380 wxString m_customName;
381
384
387
390
392
399
404 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> m_copperOverrides;
405
408
411
415
418};
419
420#ifndef SWIG
422#endif
423
424
425#endif //KICAD_PADSTACK_H
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:576
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition: padstack.h:116
void SetRoundRectRadius(double aRadius, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:354
const DRILL_PROPS & Drill() const
Definition: padstack.h:266
bool operator==(const PADSTACK &aOther) const
Definition: padstack.cpp:75
CUSTOM_SHAPE_ZONE_MODE CustomShapeInZoneMode() const
Definition: padstack.h:280
void SetCustomShapeInZoneMode(CUSTOM_SHAPE_ZONE_MODE aM)
Definition: padstack.h:281
std::optional< int > & Clearance(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:394
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: padstack.cpp:91
void SetChamferRatio(double aRatio, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:370
std::vector< std::shared_ptr< PCB_SHAPE > > & Primitives(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:496
void SetChamferPositions(int aPositions, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:388
std::optional< double > & SolderPasteMarginRatio(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:430
wxString m_customName
! An override for the IPC-7351 padstack name
Definition: padstack.h:380
OUTER_LAYER_PROPS m_topOverrides
! Any non-null optional values here override the mask/paste settings for the top layers
Definition: padstack.h:407
void SetAnchorShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:317
void SetRoundRectRadiusRatio(double aRatio, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:341
DRILL_PROPS m_drill
! The primary drill parameters, which also define the start and end layers for through-hole vias and ...
Definition: padstack.h:414
void SetThermalSpokeAngle(EDA_ANGLE aAngle, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:490
UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
Definition: padstack.h:391
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition: padstack.h:272
COPPER_LAYER_PROPS & CopperLayerDefaults()
Definition: padstack.h:274
void SetMode(MODE aMode)
Definition: padstack.h:253
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:454
std::optional< int > & SolderPasteMargin(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:418
void SetOrientation(EDA_ANGLE aAngle)
Definition: padstack.h:259
std::optional< int > & SolderMaskMargin(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:406
const LSET & LayerSet() const
Definition: padstack.h:245
PADSTACK & operator=(const PADSTACK &aOther)
Definition: padstack.cpp:58
LSET & LayerSet()
Definition: padstack.h:246
std::unordered_map< PCB_LAYER_ID, COPPER_LAYER_PROPS > m_copperOverrides
! Any entries here override the copper layer settings on the given copper layer.
Definition: padstack.h:404
DRILL_PROPS m_secondaryDrill
! Secondary drill, used to define back-drilling
Definition: padstack.h:417
PAD_SHAPE AnchorShape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:311
COPPER_LAYER_PROPS m_defaultCopperProps
! The properties applied to copper layers if they aren't overridden
Definition: padstack.h:386
int RoundRectRadius(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:347
const COPPER_LAYER_PROPS & CopperLayerDefaults() const
Definition: padstack.h:275
EDA_ANGLE ThermalSpokeAngle(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:478
OUTER_LAYER_PROPS m_defaultOuterProps
! The properties applied to outer technical layers if they aren't overridden
Definition: padstack.h:389
void AppendPrimitives(const std::vector< std::shared_ptr< PCB_SHAPE > > &aPrimitivesList, PCB_LAYER_ID aLayer=F_Cu)
Appends a copy of each shape in the given list to this padstack's custom shape list.
Definition: padstack.cpp:514
CUSTOM_SHAPE_ZONE_MODE m_customShapeInZoneMode
How to build the custom shape in zone, to create the clearance area: CUSTOM_SHAPE_ZONE_MODE::OUTLINE ...
Definition: padstack.h:398
void AddPrimitive(PCB_SHAPE *aShape, PCB_LAYER_ID aLayer=F_Cu)
Adds a custom shape primitive to the padstack.
Definition: padstack.cpp:508
int & ChamferPositions(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:376
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition: padstack.h:271
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:466
DRILL_PROPS & Drill()
Definition: padstack.h:265
BOARD_ITEM * m_parent
! The BOARD_ITEM this PADSTACK belongs to; will be used as the parent for owned shapes
Definition: padstack.h:371
OUTER_LAYER_PROPS & OuterLayerDefaults()
Definition: padstack.h:277
LSET m_layerSet
! The board layers that this padstack is active on
Definition: padstack.h:377
double RoundRectRadiusRatio(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:335
VECTOR2I & TrapezoidDeltaSize(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:323
CUSTOM_SHAPE_ZONE_MODE
Definition: padstack.h:143
PCB_LAYER_ID EndLayer() const
Definition: padstack.cpp:209
const DRILL_PROPS & SecondaryDrill() const
Definition: padstack.h:269
PAD_DRILL_SHAPE DrillShape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:287
VECTOR2I & Offset(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:299
void ClearPrimitives(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:532
OUTER_LAYER_PROPS m_bottomOverrides
! Any non-null optional values here override the mask/paste settings for bottom layers
Definition: padstack.h:410
virtual ~PADSTACK()=default
@ CUSTOM
Shapes can be defined on arbitrary layers.
@ TOP_INNER_BOTTOM
Up to three shapes can be defined (top, inner, bottom)
DRILL_PROPS & SecondaryDrill()
Definition: padstack.h:268
VECTOR2I & Size(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:275
void SetDrillShape(PAD_DRILL_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:293
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
Definition: padstack.h:136
PCB_LAYER_ID StartLayer() const
Definition: padstack.cpp:203
MODE Mode() const
Definition: padstack.h:252
bool operator!=(const PADSTACK &aOther) const
Definition: padstack.h:240
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: padstack.cpp:155
const OUTER_LAYER_PROPS & OuterLayerDefaults() const
Definition: padstack.h:278
wxString Name() const
! Returns the name of this padstack in IPC-7351 format
Definition: padstack.cpp:196
double ChamferRatio(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:364
PAD_SHAPE Shape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:263
void ReplacePrimitives(const std::vector< std::shared_ptr< PCB_SHAPE > > &aPrimitivesList, PCB_LAYER_ID aLayer=F_Cu)
Clears the existing primitive list (freeing the owned shapes) and adds copies of the given shapes to ...
Definition: padstack.cpp:522
EDA_ANGLE GetOrientation() const
Definition: padstack.h:258
void SetLayerSet(const LSET &aSet)
Definition: padstack.h:247
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:442
TYPE
! Padstack type, mostly for IPC-7351 naming and attributes Note that TYPE::MOUNTING is probably not c...
Definition: padstack.h:121
@ NORMAL
Padstack for a footprint pad.
@ MOUNTING
A mounting hole (plated or unplated, not associated with a footprint)
@ VIA
Padstack for a via.
MODE m_mode
! The copper layer variation mode this padstack is in
Definition: padstack.h:374
void SetShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:269
EDA_ANGLE m_orientation
! The rotation of the pad relative to an outer reference frame
Definition: padstack.h:383
Interface for objects that can be serialized to Protobuf messages.
Definition: serializable.h:36
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ F_Cu
Definition: layer_ids.h:64
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition: padstack.h:62
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition: padstack.h:73
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition: padstack.h:45
PAD_PROP
The set of pad properties used in Gerber files (Draw files, and P&P files) to define some properties ...
Definition: padstack.h:90
@ FIDUCIAL_LOCAL
a fiducial (usually a smd) local to the parent footprint
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
@ MECHANICAL
a pad used for mechanical support
@ HEATSINK
a pad used as heat sink, usually in SMD footprints
@ NONE
no special fabrication property
@ TESTPOINT
a test point pad
@ CASTELLATED
a pad with a castellated through hole
@ BGA
Smd pad, used in BGA footprints.
#define DECLARE_ENUM_TO_WXANY(type)
Definition: property.h:729
The features of a padstack that can vary between copper layers All parameters are optional; leaving t...
Definition: padstack.h:192
std::optional< ZONE_CONNECTION > zone_connection
Definition: padstack.h:194
std::optional< int > thermal_spoke_width
Definition: padstack.h:195
std::vector< std::shared_ptr< PCB_SHAPE > > custom_shapes
Definition: padstack.h:204
bool operator==(const COPPER_LAYER_PROPS &aOther) const
Definition: padstack.cpp:236
std::optional< EDA_ANGLE > thermal_spoke_angle
Definition: padstack.h:196
std::optional< int > clearance
Definition: padstack.h:198
std::optional< int > thermal_gap
Definition: padstack.h:197
! The properties of a padstack drill. Drill position is always the pad position (origin).
Definition: padstack.h:224
PCB_LAYER_ID start
Definition: padstack.h:227
PCB_LAYER_ID end
Definition: padstack.h:228
bool operator==(const DRILL_PROPS &aOther) const
Definition: padstack.cpp:256
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
Definition: padstack.h:225
PAD_DRILL_SHAPE shape
Definition: padstack.h:226
! The features of a padstack that can vary on outer layers.
Definition: padstack.h:212
std::optional< double > solder_paste_margin_ratio
Definition: padstack.h:215
std::optional< int > solder_paste_margin
Definition: padstack.h:214
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
Definition: padstack.h:216
std::optional< int > solder_mask_margin
Definition: padstack.h:213
std::optional< bool > has_solder_paste
True if this outer layer has solder paste.
Definition: padstack.h:217
bool operator==(const OUTER_LAYER_PROPS &aOther) const
Definition: padstack.cpp:246
! The set of properties that define a pad's shape on a given layer
Definition: padstack.h:150
VECTOR2I trapezoid_delta_size
Delta for PAD_SHAPE::TRAPEZOID; half the delta squeezes one end and half expands the other.
Definition: padstack.h:173
double round_rect_corner_radius
Definition: padstack.h:164
VECTOR2I offset
Offset of the shape center from the pad center.
Definition: padstack.h:162
bool operator==(const SHAPE_PROPS &aOther) const
Definition: padstack.cpp:226
VECTOR2I size
Size of the shape, or of the anchor pad for custom shape pads.
Definition: padstack.h:153
double chamfered_rect_ratio
Size of chamfer: ratio of smallest of X,Y size.
Definition: padstack.h:166
double round_rect_radius_ratio
Definition: padstack.h:165
PAD_SHAPE shape
Shape of the pad.
Definition: padstack.h:151
PAD_SHAPE anchor_shape
Shape of the anchor when shape == PAD_SHAPE::CUSTOM.
Definition: padstack.h:152