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 <lset.h>
32#include <math/vector2d.h>
33#include <properties/property.h>
34#include <zones.h>
35
36class BOARD_ITEM;
37class PCB_SHAPE;
38
39
45enum class PAD_SHAPE : int
46{
47 CIRCLE,
48 RECTANGLE, // do not use just RECT: it collides in a header on MSYS2
49 OVAL,
52
53 // Rectangle with a chamfered corner ( and with rounded other corners).
55 CUSTOM // A shape defined by user, using a set of basic shapes
56 // (thick segments, circles, arcs, polygons).
57};
58
63{
64 CIRCLE,
65 OBLONG,
66};
67
73enum class PAD_ATTRIB
74{
75 PTH,
76 SMD,
77 CONN,
80 NPTH,
82};
83
84
90enum class PAD_PROP
91{
92 NONE,
93 BGA,
96 TESTPOINT,
97 HEATSINK,
100};
101
102
116class PADSTACK : public SERIALIZABLE
117{
118public:
121 enum class TYPE
122 {
123 NORMAL,
124 VIA,
125 MOUNTING
126 };
127
128 enum class MODE
129 {
130 NORMAL,
132 CUSTOM
133 };
134
137 {
138 KEEP_ALL,
141 };
142
144 {
145 OUTLINE,
147 };
148
151 {
155
156 /*
157 * Most of the time the hole is the center of the shape (m_Offset = 0). But some designers
158 * use oblong/rect pads with a hole moved to one of the oblong/rect pad shape ends.
159 * In all cases the hole is at the pad position. This offset is from the hole to the center
160 * of the pad shape (ie: the copper area around the hole).
161 * ShapePos() returns the board shape position according to the offset and the pad rotation.
162 */
164
169
175
176 SHAPE_PROPS();
177 bool operator==( const SHAPE_PROPS& aOther ) const;
178 };
179
193 {
195 std::optional<ZONE_CONNECTION> zone_connection;
196 std::optional<int> thermal_spoke_width;
197 std::optional<EDA_ANGLE> thermal_spoke_angle;
198 std::optional<int> thermal_gap;
199 std::optional<int> clearance;
200
201 /*
202 * Editing definitions of primitives for custom pad shapes. In local coordinates relative
203 * to m_Pos (NOT shapePos) at orient 0.
204 */
205 std::vector<std::shared_ptr<PCB_SHAPE>> custom_shapes;
206
207 bool operator==( const COPPER_LAYER_PROPS& aOther ) const;
208 };
209
213 {
214 std::optional<int> solder_mask_margin;
215 std::optional<int> solder_paste_margin;
216 std::optional<double> solder_paste_margin_ratio;
217 std::optional<bool> has_solder_mask;
218 std::optional<bool> has_solder_paste;
219
220 bool operator==( const MASK_LAYER_PROPS& aOther ) const;
221 };
222
225 {
230
231 bool operator==( const DRILL_PROPS& aOther ) const;
232 };
233
234public:
235 PADSTACK( BOARD_ITEM* aParent );
236 virtual ~PADSTACK() = default;
237 PADSTACK( const PADSTACK& aOther );
238 PADSTACK& operator=( const PADSTACK &aOther );
239
240 bool operator==( const PADSTACK& aOther ) const;
241 bool operator!=( const PADSTACK& aOther ) const { return !operator==( aOther ); }
242
243 void Serialize( google::protobuf::Any &aContainer ) const override;
244 bool Deserialize( const google::protobuf::Any &aContainer ) override;
245
246 const LSET& LayerSet() const { return m_layerSet; }
247 LSET& LayerSet() { return m_layerSet; }
248 void SetLayerSet( const LSET& aSet ) { m_layerSet = aSet; }
249
250 PCB_LAYER_ID StartLayer() const;
251 PCB_LAYER_ID EndLayer() const;
252
253 MODE Mode() const { return m_mode; }
254 void SetMode( MODE aMode ) { m_mode = aMode; }
255
257 wxString Name() const;
258
261 {
262 m_orientation = aAngle;
264 }
265
266 DRILL_PROPS& Drill() { return m_drill; }
267 const DRILL_PROPS& Drill() const { return m_drill; }
268
270 const DRILL_PROPS& SecondaryDrill() const { return m_secondaryDrill; }
271
274
277
280
283
290 std::optional<bool> IsTented( PCB_LAYER_ID aSide ) const;
291
294
295 // The following section has convenience getters for the padstack properties on a given layer.
296
297 PAD_SHAPE Shape( PCB_LAYER_ID aLayer = F_Cu ) const;
298 void SetShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
299
300 VECTOR2I& Size( PCB_LAYER_ID aLayer = F_Cu );
301 const VECTOR2I& Size( PCB_LAYER_ID aLayer = F_Cu ) const;
302
304 void SetDrillShape( PAD_DRILL_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
305
306 VECTOR2I& Offset( PCB_LAYER_ID aLayer = F_Cu );
307 const VECTOR2I& Offset( PCB_LAYER_ID aLayer = F_Cu ) const;
308
309 PAD_SHAPE AnchorShape( PCB_LAYER_ID aLayer = F_Cu ) const;
310 void SetAnchorShape( PAD_SHAPE aShape, PCB_LAYER_ID aLayer = F_Cu );
311
313 const VECTOR2I& TrapezoidDeltaSize( PCB_LAYER_ID aLayer = F_Cu ) const;
314
315 double RoundRectRadiusRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
316 void SetRoundRectRadiusRatio( double aRatio, PCB_LAYER_ID aLayer = F_Cu );
317
318 int RoundRectRadius( PCB_LAYER_ID aLayer = F_Cu ) const;
319 void SetRoundRectRadius( double aRadius, PCB_LAYER_ID aLayer = F_Cu );
320
321 double ChamferRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
322 void SetChamferRatio( double aRatio, PCB_LAYER_ID aLayer = F_Cu );
323
324 int& ChamferPositions( PCB_LAYER_ID aLayer = F_Cu );
325 const int& ChamferPositions( PCB_LAYER_ID aLayer = F_Cu ) const;
326 void SetChamferPositions( int aPositions, PCB_LAYER_ID aLayer = F_Cu );
327
328 std::optional<int>& Clearance( PCB_LAYER_ID aLayer = F_Cu );
329 const std::optional<int>& Clearance( PCB_LAYER_ID aLayer = F_Cu ) const;
330
331 std::optional<int>& SolderMaskMargin( PCB_LAYER_ID aLayer = F_Cu );
332 const std::optional<int>& SolderMaskMargin( PCB_LAYER_ID aLayer = F_Cu ) const;
333
334 std::optional<int>& SolderPasteMargin( PCB_LAYER_ID aLayer = F_Cu );
335 const std::optional<int>& SolderPasteMargin( PCB_LAYER_ID aLayer = F_Cu ) const;
336
337 std::optional<double>& SolderPasteMarginRatio( PCB_LAYER_ID aLayer = F_Cu );
338 const std::optional<double>& SolderPasteMarginRatio( PCB_LAYER_ID aLayer = F_Cu ) const;
339
340 std::optional<ZONE_CONNECTION>& ZoneConnection( PCB_LAYER_ID aLayer = F_Cu );
341 const std::optional<ZONE_CONNECTION>& ZoneConnection( PCB_LAYER_ID aLayer = F_Cu ) const;
342
343 std::optional<int>& ThermalSpokeWidth( PCB_LAYER_ID aLayer = F_Cu );
344 const std::optional<int>& ThermalSpokeWidth( PCB_LAYER_ID aLayer = F_Cu ) const;
345
346 std::optional<int>& ThermalGap( PCB_LAYER_ID aLayer = F_Cu );
347 const std::optional<int>& ThermalGap( PCB_LAYER_ID aLayer = F_Cu ) const;
348
350 void SetThermalSpokeAngle( EDA_ANGLE aAngle, PCB_LAYER_ID aLayer = F_Cu );
351
352 std::vector<std::shared_ptr<PCB_SHAPE>>& Primitives( PCB_LAYER_ID aLayer = F_Cu );
353 const std::vector<std::shared_ptr<PCB_SHAPE>>& Primitives( PCB_LAYER_ID aLayer = F_Cu ) const;
354
360 void AddPrimitive( PCB_SHAPE* aShape, PCB_LAYER_ID aLayer = F_Cu );
361
367 void AppendPrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
368 PCB_LAYER_ID aLayer = F_Cu );
369
376 void ReplacePrimitives( const std::vector<std::shared_ptr<PCB_SHAPE>>& aPrimitivesList,
377 PCB_LAYER_ID aLayer = F_Cu );
378
379 void ClearPrimitives( PCB_LAYER_ID aLayer = F_Cu );
380
381private:
384
387
390
392 wxString m_customName;
393
396
399
402
405
407
414
419 std::unordered_map<PCB_LAYER_ID, COPPER_LAYER_PROPS> m_copperOverrides;
420
424
427};
428
429#ifndef SWIG
431#endif
432
433
434#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:79
EDA_ANGLE Normalize()
Definition: eda_angle.h:221
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:35
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition: padstack.h:117
void SetRoundRectRadius(double aRadius, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:352
const DRILL_PROPS & Drill() const
Definition: padstack.h:267
bool operator==(const PADSTACK &aOther) const
Definition: padstack.cpp:74
CUSTOM_SHAPE_ZONE_MODE CustomShapeInZoneMode() const
Definition: padstack.h:292
void SetCustomShapeInZoneMode(CUSTOM_SHAPE_ZONE_MODE aM)
Definition: padstack.h:293
std::optional< int > & Clearance(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:392
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: padstack.cpp:89
void SetChamferRatio(double aRatio, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:368
MASK_LAYER_PROPS & FrontOuterLayers()
Definition: padstack.h:278
std::vector< std::shared_ptr< PCB_SHAPE > > & Primitives(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:498
void SetChamferPositions(int aPositions, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:386
std::optional< double > & SolderPasteMarginRatio(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:431
wxString m_customName
! An override for the IPC-7351 padstack name
Definition: padstack.h:392
void SetAnchorShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:315
void SetRoundRectRadiusRatio(double aRatio, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:339
DRILL_PROPS m_drill
! The primary drill parameters, which also define the start and end layers for through-hole vias and ...
Definition: padstack.h:423
void SetThermalSpokeAngle(EDA_ANGLE aAngle, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:492
UNCONNECTED_LAYER_MODE m_unconnectedLayerMode
Definition: padstack.h:406
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition: padstack.h:273
COPPER_LAYER_PROPS & CopperLayerDefaults()
Definition: padstack.h:275
std::optional< bool > IsTented(PCB_LAYER_ID aSide) const
Checks if this padstack is tented (covered in soldermask) on the given side.
Definition: padstack.cpp:540
void SetMode(MODE aMode)
Definition: padstack.h:254
std::optional< int > & ThermalSpokeWidth(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:456
std::optional< int > & SolderPasteMargin(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:418
void SetOrientation(EDA_ANGLE aAngle)
Definition: padstack.h:260
const MASK_LAYER_PROPS & BackOuterLayers() const
Definition: padstack.h:282
std::optional< int > & SolderMaskMargin(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:404
const LSET & LayerSet() const
Definition: padstack.h:246
PADSTACK & operator=(const PADSTACK &aOther)
Definition: padstack.cpp:58
LSET & LayerSet()
Definition: padstack.h:247
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:419
DRILL_PROPS m_secondaryDrill
! Secondary drill, used to define back-drilling
Definition: padstack.h:426
PAD_SHAPE AnchorShape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:309
MASK_LAYER_PROPS m_backMaskProps
! The overrides applied to back outer technical layers
Definition: padstack.h:404
COPPER_LAYER_PROPS m_defaultCopperProps
! The properties applied to copper layers if they aren't overridden
Definition: padstack.h:398
int RoundRectRadius(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:345
const COPPER_LAYER_PROPS & CopperLayerDefaults() const
Definition: padstack.h:276
EDA_ANGLE ThermalSpokeAngle(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:480
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:516
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:413
void AddPrimitive(PCB_SHAPE *aShape, PCB_LAYER_ID aLayer=F_Cu)
Adds a custom shape primitive to the padstack.
Definition: padstack.cpp:510
int & ChamferPositions(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:374
const MASK_LAYER_PROPS & FrontOuterLayers() const
Definition: padstack.h:279
UNCONNECTED_LAYER_MODE UnconnectedLayerMode() const
Definition: padstack.h:272
std::optional< int > & ThermalGap(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:468
DRILL_PROPS & Drill()
Definition: padstack.h:266
BOARD_ITEM * m_parent
! The BOARD_ITEM this PADSTACK belongs to; will be used as the parent for owned shapes
Definition: padstack.h:383
LSET m_layerSet
! The board layers that this padstack is active on
Definition: padstack.h:389
double RoundRectRadiusRatio(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:333
VECTOR2I & TrapezoidDeltaSize(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:321
CUSTOM_SHAPE_ZONE_MODE
Definition: padstack.h:144
PCB_LAYER_ID EndLayer() const
Definition: padstack.cpp:207
const DRILL_PROPS & SecondaryDrill() const
Definition: padstack.h:270
PAD_DRILL_SHAPE DrillShape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:285
MASK_LAYER_PROPS m_frontMaskProps
! The overrides applied to front outer technical layers
Definition: padstack.h:401
VECTOR2I & Offset(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:297
void ClearPrimitives(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:534
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:269
VECTOR2I & Size(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:273
void SetDrillShape(PAD_DRILL_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:291
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
Definition: padstack.h:137
PCB_LAYER_ID StartLayer() const
Definition: padstack.cpp:201
MODE Mode() const
Definition: padstack.h:253
bool operator!=(const PADSTACK &aOther) const
Definition: padstack.h:241
MASK_LAYER_PROPS & BackOuterLayers()
Definition: padstack.h:281
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: padstack.cpp:153
wxString Name() const
! Returns the name of this padstack in IPC-7351 format
Definition: padstack.cpp:194
double ChamferRatio(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:362
PAD_SHAPE Shape(PCB_LAYER_ID aLayer=F_Cu) const
Definition: padstack.cpp:261
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:524
EDA_ANGLE GetOrientation() const
Definition: padstack.h:259
void SetLayerSet(const LSET &aSet)
Definition: padstack.h:248
std::optional< ZONE_CONNECTION > & ZoneConnection(PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:444
TYPE
! Padstack type, mostly for IPC-7351 naming and attributes Note that TYPE::MOUNTING is probably not c...
Definition: padstack.h:122
@ 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:386
void SetShape(PAD_SHAPE aShape, PCB_LAYER_ID aLayer=F_Cu)
Definition: padstack.cpp:267
EDA_ANGLE m_orientation
! The rotation of the pad relative to an outer reference frame
Definition: padstack.h:395
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:63
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition: padstack.h:74
@ 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:46
PAD_PROP
The set of pad properties used in Gerber files (Draw files, and P&P files) to define some properties ...
Definition: padstack.h:91
@ 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:193
std::optional< ZONE_CONNECTION > zone_connection
Definition: padstack.h:195
std::optional< int > thermal_spoke_width
Definition: padstack.h:196
std::vector< std::shared_ptr< PCB_SHAPE > > custom_shapes
Definition: padstack.h:205
bool operator==(const COPPER_LAYER_PROPS &aOther) const
Definition: padstack.cpp:234
std::optional< EDA_ANGLE > thermal_spoke_angle
Definition: padstack.h:197
std::optional< int > clearance
Definition: padstack.h:199
std::optional< int > thermal_gap
Definition: padstack.h:198
! The properties of a padstack drill. Drill position is always the pad position (origin).
Definition: padstack.h:225
PCB_LAYER_ID start
Definition: padstack.h:228
PCB_LAYER_ID end
Definition: padstack.h:229
bool operator==(const DRILL_PROPS &aOther) const
Definition: padstack.cpp:254
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
Definition: padstack.h:226
PAD_DRILL_SHAPE shape
Definition: padstack.h:227
! The features of a padstack that can vary on outer layers.
Definition: padstack.h:213
bool operator==(const MASK_LAYER_PROPS &aOther) const
Definition: padstack.cpp:244
std::optional< int > solder_mask_margin
Definition: padstack.h:214
std::optional< int > solder_paste_margin
Definition: padstack.h:215
std::optional< double > solder_paste_margin_ratio
Definition: padstack.h:216
std::optional< bool > has_solder_mask
True if this outer layer has mask (is not tented)
Definition: padstack.h:217
std::optional< bool > has_solder_paste
True if this outer layer has solder paste.
Definition: padstack.h:218
! The set of properties that define a pad's shape on a given layer
Definition: padstack.h:151
VECTOR2I trapezoid_delta_size
Delta for PAD_SHAPE::TRAPEZOID; half the delta squeezes one end and half expands the other.
Definition: padstack.h:174
double round_rect_corner_radius
Definition: padstack.h:165
VECTOR2I offset
Offset of the shape center from the pad center.
Definition: padstack.h:163
bool operator==(const SHAPE_PROPS &aOther) const
Definition: padstack.cpp:224
VECTOR2I size
Size of the shape, or of the anchor pad for custom shape pads.
Definition: padstack.h:154
double chamfered_rect_ratio
Size of chamfer: ratio of smallest of X,Y size.
Definition: padstack.h:167
double round_rect_radius_ratio
Definition: padstack.h:166
PAD_SHAPE shape
Shape of the pad.
Definition: padstack.h:152
PAD_SHAPE anchor_shape
Shape of the anchor when shape == PAD_SHAPE::CUSTOM.
Definition: padstack.h:153