/
sop.py
120 lines (101 loc) · 3.37 KB
/
sop.py
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
# module sop
#
# Copyright (C) 2012 Russ Dill <Russ.Dill@asu.edu>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
import pscad
import itertools
from decimal import Decimal as D
import patterns
defaults = {
'round_off' : "0.05",
'placement' : "0.25",
'grid' : "0.5",
'clearance' : "0.15",
'mask' : "2.5 mil",
'silk' : "0.2",
'paste_fraction': "0.35",
'paste_max': "1.0",
'pad_paste_fraction': "1.0",
'quad' : False
}
def part(m):
m = pscad.wrapper(defaults.items() + m.items())
try:
pin_count = m.n
pin_names = itertools.count(1)
except:
pin_count = len(m.pins.split(','))
pin_names = (i for i in m.pins.split(','))
if 'pads_x' in m:
pads_x = m.pads_x
elif m.quad:
pads_x = pin_count / 4
else:
pads_x = 0
pads_y = pin_count / 2 - pads_x
try:
body_y = m.body_y
except:
body_y = m.width - m.pad_l - m.silk * 3
if 'height' in m:
height = m.height
else:
height = m.width
pad = pscad.rounded_square((m.pad_w, m.pad_l), m.round_off, center=True)
row_y = pscad.down(m.width / 2) + pscad.row(
pscad.paste_fraction(pad, (1,m.pad_paste_fraction)),
m.pitch, pads_y, center=True)
if m.quad:
row_x = pscad.down(height / 2) + pscad.row(
pscad.paste_fraction(pad, (1,m.pad_paste_fraction)),
m.pitch, pads_x, center=True)
pads = pscad.pad(pin_names, m.clearance, m.mask) + (
row_y, pscad.rotate(90) + row_x,
pscad.rotate(180) + row_y, pscad.rotate(270) + row_x
)
else:
pads = pscad.pad(pin_names, m.clearance, m.mask) + (
row_y, pscad.rotate(180) + row_y
)
try:
if m.quad:
raise Exception()
if body_y > m.width - m.pad_l - m.silk * 2:
edge = m.body_x / 2 - m.pitch * D(pin_count) / 4
body = patterns.brackets([m.body_x, body_y], edge, center=True)
else:
body = pscad.square([m.body_x, body_y], center=True)
all = pads, pscad.silk(m.silk) + body
except:
all = pads
try:
corners = m.corners
except:
corners = m.pad_w * 2
silk = pscad.silk(m.silk) + (
patterns.placement_courtyard(all, m.placement, m.grid, corners),
pscad.down(m.width / 2) +
pscad.left(m.silk + m.pitch * pads_y / 2) +
pscad.line([0, m.pad_l * D("0.7")], center=True)
)
return all, silk
def with_thermal_pad(m):
m = pscad.wrapper(defaults.items() + m.items())
try:
thermal_name = m.pins.split(',')[-1]
except:
thermal_name = m.n + 1
thermal_size = (m.thermal_x, m.thermal_y)
return part(m), pscad.pad(thermal_name, m.clearance, m.mask) + (
patterns.thermal_pad(pscad.square(thermal_size, center=True),
thermal_size, m.paste_fraction, m.paste_max)
)