This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
FPC_wizard.py
158 lines (125 loc) · 5.47 KB
/
FPC_wizard.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
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
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
from __future__ import division
import pcbnew
import FootprintWizardBase
class FPC_FootprintWizard(FootprintWizardBase.FootprintWizard):
def GetName(self):
return "FPC (SMT connector)"
def GetDescription(self):
return "FPC (SMT connector) Footprint Wizard"
def GetValue(self):
pins = self.parameters["Pads"]["n"]
return "FPC_%d" % pins
def GenerateParameterList(self):
self.AddParam( "Pads", "n", self.uInteger, 40 )
self.AddParam( "Pads", "pitch", self.uMM, 0.5 )
self.AddParam( "Pads", "width", self.uMM, 0.25 )
self.AddParam( "Pads", "height", self.uMM, 1.6)
self.AddParam( "Shield", "shield_to_pad", self.uMM, 1.6 )
self.AddParam( "Shield", "from_top", self.uMM, 1.3 )
self.AddParam( "Shield", "width", self.uMM, 1.5 )
self.AddParam( "Shield", "height", self.uMM, 2 )
# build a rectangular pad
def smdRectPad(self,module,size,pos,name):
pad = pcbnew.D_PAD(module)
pad.SetSize(size)
pad.SetShape(pcbnew.PAD_SHAPE_RECT)
pad.SetAttribute(pcbnew.PAD_ATTRIB_SMD)
pad.SetLayerSet( pad.SMDMask() )
pad.SetPos0(pos)
pad.SetPosition(pos)
pad.SetName(name)
return pad
def CheckParameters(self):
#TODO implement custom parameter checking
pass
def BuildThisFootprint(self):
p = self.parameters
pad_count = int(p["Pads"]["n"])
pad_width = p["Pads"]["width"]
pad_height = p["Pads"]["height"]
pad_pitch = p["Pads"]["pitch"]
shl_width = p["Shield"]["width"]
shl_height = p["Shield"]["height"]
shl_to_pad = p["Shield"]["shield_to_pad"]
shl_from_top = p["Shield"]["from_top"]
offsetX = pad_pitch * ( pad_count-1 ) / 2
size_pad = pcbnew.wxSize( pad_width, pad_height )
size_shld = pcbnew.wxSize(shl_width, shl_height)
size_text = self.GetTextSize() # IPC nominal
# Gives a position and size to ref and value texts:
textposy = pad_height/2 + pcbnew.FromMM(1) + self.GetTextThickness()
angle_degree = 0.0
self.draw.Reference( 0, textposy, size_text, angle_degree )
textposy = textposy + size_text + self.GetTextThickness()
self.draw.Value( 0, textposy, size_text )
# create a pad array and add it to the module
for n in range ( 0, pad_count ):
xpos = pad_pitch*n - offsetX
pad = self.smdRectPad(self.module,size_pad, pcbnew.wxPoint(xpos,0),str(n+1))
self.module.Add(pad)
# Mechanical shield pads: left pad and right pad
xpos = -shl_to_pad-offsetX
pad_s0_pos = pcbnew.wxPoint(xpos,shl_from_top)
pad_s0 = self.smdRectPad(self.module, size_shld, pad_s0_pos, "0")
xpos = (pad_count-1) * pad_pitch+shl_to_pad - offsetX
pad_s1_pos = pcbnew.wxPoint(xpos,shl_from_top)
pad_s1 = self.smdRectPad(self.module, size_shld, pad_s1_pos, "0")
self.module.Add(pad_s0)
self.module.Add(pad_s1)
# add footprint outline
linewidth = self.draw.GetLineThickness()
margin = linewidth
# upper line
posy = -pad_height/2 - linewidth/2 - margin
xstart = - pad_pitch*0.5-offsetX
xend = pad_pitch * pad_count + xstart;
self.draw.Line( xstart, posy, xend, posy )
# lower line
posy = pad_height/2 + linewidth/2 + margin
self.draw.Line(xstart, posy, xend, posy)
# around left mechanical pad (the outline around right pad is mirrored/y axix)
yend = pad_s0_pos.y + shl_height/2 + margin
self.draw.Line(xstart, posy, xstart, yend)
self.draw.Line(-xstart, posy, -xstart, yend)
posy = yend
xend = pad_s0_pos.x - (shl_width/2 + linewidth + margin*2)
self.draw.Line(xstart, posy, xend, posy)
# right pad side
self.draw.Line(-xstart, posy, -xend, yend)
# set SMD attribute
self.module.SetAttributes(pcbnew.MOD_CMS)
# vertical segment at left of the pad
xstart = xend
yend = posy - (shl_height + linewidth + margin*2)
self.draw.Line(xstart, posy, xend, yend)
# right pad side
self.draw.Line(-xstart, posy, -xend, yend)
# horizontal segment above the pad
xstart = xend
xend = - pad_pitch*0.5-offsetX
posy = yend
self.draw.Line(xstart, posy, xend, yend)
# right pad side
self.draw.Line(-xstart, posy,-xend, yend)
# vertical segment above the pad
xstart = xend
yend = -pad_height/2 - linewidth/2 - margin
self.draw.Line(xstart, posy, xend, yend)
# right pad side
self.draw.Line(-xstart, posy, -xend, yend)
FPC_FootprintWizard().register()