22from __future__
import division
29 Useful construction functions for common types of pads, providing
30 sensible defaults for common pads.
35 @param module: the module the pads will be part of
39 def THPad(self, Vsize, Hsize, drill, shape=pcbnew.PAD_SHAPE_OVAL,
42 A basic through-hole pad of the given size and shape
43 @param Vsize: the vertical size of the pad
44 @param Hsize: the horizontal size of the pad
45 @param drill: the drill diameter
46 @param shape: the shape of the pad
47 @param rot_degree: the pad rotation, in degrees
52 pad.SetAttribute(pcbnew.PAD_ATTRIB_PTH)
53 pad.SetLayerSet(pad.PTHMask())
61 A round though-hole pad. A shortcut for THPad()
62 @param size: pad diameter
63 @param drill: drill diameter
65 pad = self.
THPad(size, size, drill, shape=pcbnew.PAD_SHAPE_CIRCLE)
70 A round non-plated though hole (NPTH)
72 @param drill: the drill diameter (equals the NPTH diameter)
76 pad.SetShape(pcbnew.PAD_SHAPE_CIRCLE)
77 pad.SetAttribute(pcbnew.PAD_ATTRIB_NPTH)
78 pad.SetLayerSet(pad.UnplatedHoleMask())
82 def SMDPad(self, Vsize, Hsize, shape=pcbnew.PAD_SHAPE_RECT, rot_degree=0):
84 Create a surface-mount pad of the given size and shape
85 @param Vsize: the vertical size of the pad
86 @param Hsize: the horizontal size of the pad
87 @param shape: the shape of the pad
88 @param rot_degree: the pad rotation, in degrees
93 pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
94 pad.SetLayerSet(pad.SMDMask())
99 def AperturePad(self, Vsize, Hsize, shape=pcbnew.PAD_SHAPE_RECT, rot_degree=0):
101 Create a aperture pad of the given size and shape, i.e. a smd pad shape
102 on the solder paste and not on a copper
104 @param Vsize: the vertical size of the aperture
105 @param Hsize: the horizontal size of the aperture
106 @param shape: the shape of the pad
107 @param rot_degree: the pad rotation, in degrees
112 pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
113 pad.SetLayerSet(pad.ApertureMask())
120 A round surface-mount pad. A shortcut for SMDPad()
121 @param size: pad diameter
123 pad = self.
SMDPad(size, size, shape=pcbnew.PAD_SHAPE_CIRCLE)
129 A class to assist in creating repetitive grids of pads
131 Generally, PadArrays have an internal prototypical pad, and copy this
132 for each pad in the array. They can also have a special pad for the
133 first pad, and a custom function to name the pad.
135 Generally, PadArray is used as a base class for more specific array
141 @param pad: the prototypical pad
153 Set a name for all the pins. If given, this overrides the
156 @param pinNames: the name to use for all pins
162 If the array has a different first pad, this is the pad that
164 @param firstPad: the prototypical first pad
170 Set the numbering for the first pad in the array
171 @param fpNum: the number for the first pad
177 Add a pad to the array, under the same footprint as the main
179 @param pad: pad to add
181 self.
pad.GetParent().Add(pad)
185 Get a pad in the array with the given position
186 @param is_first_pad: use the special first pad if there is one
187 @param pos: the pad position
189 if (self.
firstPad and is_first_pad):
195 pad = pad.Duplicate()
202 Get the pad name from the naming function, or the pre-set
203 pinNames parameter (set with SetPinNames)
213 Implement this as needed for each array type
215 raise NotImplementedError;
223 def __init__(self, pad, nx, ny, px, py, centre=pcbnew.VECTOR2I(0, 0)):
225 @param pad: the prototypical pad of the array
226 @param nx: number of pads in x-direction
227 @param ny: number of pads in y-direction
228 @param px: pitch in x-direction
229 @param py: pitch in y-direction
230 @param centre: array centre point
236 super(PadGridArray, self).
__init__(pad)
245 alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
247 Utility function to generate an alphabetical name:
249 eg. 1 - A, 2 - B, 26 - AA, etc
251 @param aIndex: index of 'A': 0 for 0 - A
252 @param n: the pad index
253 @param alphabet: set of allowable chars if not A-Z,
254 e.g. ABCDEFGHJKLMNPRTUVWY for BGA
257 div, mod = divmod(n - aIndex, len(alphabet))
258 alpha = alphabet[mod]
267 Implementation of the naming function: right to left, top-to-bottom
269 @param x: the pad x index
270 @param y: the pad y index
277 Create the pads and add them to the module in the correct positions
279 @param dc: the drawing context
282 pin1posX = self.
centre.x - self.
px * (self.
nx - 1) / 2
283 pin1posY = self.
centre.y - self.
py * (self.
ny - 1) / 2
285 for x
in range(0, self.
nx):
286 posX = pin1posX + (x * self.
px)
288 for y
in range(self.
ny):
289 posY = pin1posY + (self.
py * y)
290 pos = dc.TransformPoint(posX, posY)
291 pad = self.
GetPad(x == 0
and y == 0, pos)
298 A pad grid array with a fixed name, used for things like thermal
304 Simply return the firstPadNum
313 A staggered pin array
316 def __init__(self, pad, pad_count, line_count, line_pitch,
317 pad_pitch, centre=pcbnew.VECTOR2I(0, 0)):
319 @param pad: the prototypical pad
320 @param pad_count: total pad count
321 @param line_count: number of staggered lines
322 @param line_pitch: distance between lines
323 @param pad_pitch: distance between pads in a line
324 @param centre: array centre point
326 super(PadZGridArray, self).
__init__(pad)
336 Naming just increased with pad index in array
342 Create the pads and add them to the module in the correct positions
344 @param dc: the drawing context
352 posX = pin1posX + (padnum * self.
pad_pitch)
355 pos = dc.TransformPoint(posX, posY)
356 pad = self.
GetPad(padnum == 0, pos)
357 pad.SetName(self.
GetName(padnum))
368 Shortcut cases for a single-row grid array. Can be used for
369 constructing sections of larger footprints.
373 centre=pcbnew.VECTOR2I(0, 0)):
375 @param pad: the prototypical pad
376 @param n: number of pads in array
377 @param pitch: distance between pad centres
378 @param isVertical: horizontal or vertical array (can also use the
379 drawing contexts transforms for more control)
380 @param centre: array centre
384 super(PadLineArray, self).
__init__(pad, 1, n, 0, pitch, centre)
386 super(PadLineArray, self).
__init__(pad, n, 1, pitch, 0, centre)
394 def __init__(self, pad, n, r, angle_offset=0, centre=pcbnew.VECTOR2I(0, 0),
395 clockwise=
True, padRotationEnable=
False, padRotationOffset=0):
397 @param pad: the prototypical pad
398 @param n: number of pads in array
399 @param r: the circle radius
400 @param angle_offset: angle of the first pad
401 @param centre: array centre point
402 @param clockwise: array increases in a clockwise direction
403 @param padRotationEnable: also rotate pads when placing
404 @param padRotationOffset: rotation of first pad
407 super(PadCircleArray, self).
__init__(pad)
419 Naming around the circle, CW or CCW according to the clockwise flag
425 Create the pads and add them to the module in the correct positions
427 @param dc: the drawing context
430 for pin
in range(0, self.
n):
436 pos_x = math.sin(angle * math.pi / 180) * self.
r
437 pos_y = -math.cos(angle * math.pi / 180) * self.
r
438 pos = dc.TransformPoint(pos_x, pos_y)
439 pad = self.
GetPad(pin == 0, pos)
450 Layout pads according to a custom array of [x,y] data
455 @param pad: the prototypical pad
456 @param array: the position data array
458 super(PadCustomArray, self).
__init__(pad)
464 Simple increment along the given array
465 @param n: the pad index in the array
471 Create the pads and add them to the module in the correct positions
473 @param dc: the drawing context
476 for i
in range(len(self.
array)):
477 pos = dc.TransformPoint(self.
array[i][0], self.
array[i][1])
478 pad = self.
GetPad(i == 0, pos)
A pad grid array with a fixed name, used for things like thermal pads and via grids.
NamingFunction(self, nx, ny)
Simply return the firstPadNum.
A class to assist in creating repetitive grids of pads.
NamingFunction(self, *args, **kwargs)
Implement this as needed for each array type.
SetPinNames(self, pinNames)
Set a name for all the pins.
GetPad(self, is_first_pad, pos)
Get a pad in the array with the given position.
GetName(self, *args, **kwargs)
Get the pad name from the naming function, or the pre-set pinNames parameter (set with SetPinNames)
SetFirstPadType(self, firstPad)
If the array has a different first pad, this is the pad that is used.
SetFirstPadInArray(self, fpNum)
Set the numbering for the first pad in the array.
AddPad(self, pad)
Add a pad to the array, under the same footprint as the main prototype pad.
AddPadsToModule(self, dc)
Create the pads and add them to the module in the correct positions.
__init__(self, pad, n, r, angle_offset=0, centre=pcbnew.VECTOR2I(0, 0), clockwise=True, padRotationEnable=False, padRotationOffset=0)
NamingFunction(self, n)
Naming around the circle, CW or CCW according to the clockwise flag.
Layout pads according to a custom array of [x,y] data.
NamingFunction(self, n)
Simple increment along the given array.
__init__(self, pad, array)
AddPadsToModule(self, dc)
Create the pads and add them to the module in the correct positions.
__init__(self, pad, nx, ny, px, py, centre=pcbnew.VECTOR2I(0, 0))
NamingFunction(self, x, y)
Implementation of the naming function: right to left, top-to-bottom.
AlphaNameFromNumber(self, n, aIndex=1, alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Utility function to generate an alphabetical name:
AddPadsToModule(self, dc)
Create the pads and add them to the module in the correct positions.
Shortcut cases for a single-row grid array.
__init__(self, pad, n, pitch, isVertical, centre=pcbnew.VECTOR2I(0, 0))
Useful construction functions for common types of pads, providing sensible defaults for common pads.
AperturePad(self, Vsize, Hsize, shape=pcbnew.PAD_SHAPE_RECT, rot_degree=0)
SMTRoundPad(self, size)
A round surface-mount pad.
THRoundPad(self, size, drill)
A round though-hole pad.
THPad(self, Vsize, Hsize, drill, shape=pcbnew.PAD_SHAPE_OVAL, rot_degree=0)
A basic through-hole pad of the given size and shape.
NPTHRoundPad(self, drill)
A round non-plated though hole (NPTH)
SMDPad(self, Vsize, Hsize, shape=pcbnew.PAD_SHAPE_RECT, rot_degree=0)
__init__(self, pad, pad_count, line_count, line_pitch, pad_pitch, centre=pcbnew.VECTOR2I(0, 0))
AddPadsToModule(self, dc)
Create the pads and add them to the module in the correct positions.
NamingFunction(self, pad_pos)
Naming just increased with pad index in array.