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 9
/
fp_test.py
154 lines (122 loc) · 5.71 KB
/
fp_test.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
# 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 sys
#sys.path.append("C:\\msys64\\mingw32\\lib\\python2.7\\site-packages")
#sys.path.append("C:\\msys64\\mingw32\\share\\kicad\\scripting\\plugins")
import pcbnew
import PadArray as PA
import FootprintWizardBase
class TestWizard(FootprintWizardBase.FootprintWizard):
def GetName(self):
return "TestFootprint"
def GetDescription(self):
return "Quad Flat Package footprint wizardess"
def CheckParameters(self):
self.CheckParam("Pads","n",min_value=100,info="This is a test error")
def GenerateParameterList(self):
print("Generating parameters")
self.AddParam("Pads", "n", pcbnew.uInteger, 44, multiple=4, designator='A')
self.AddParam("Pads", "pitch", pcbnew.uMM, 0.5, designator='Q')
self.AddParam("Pads", "width", pcbnew.uMM, 0.25)
self.AddParam("Pads", "length", pcbnew.uMM, 1.5)
self.AddParam("Pads", "pitch", pcbnew.uMM, 15)
self.AddParam("Pads", "pitch", "mm", 15)
self.AddParam("Pads", "oval", pcbnew.uBool, True)
self.AddParam("Package", "width", pcbnew.uMM, 14)
self.AddParam("Package", "height", pcbnew.uMM, 14)
self.AddParam("Package", "courtyard margin", pcbnew.uMM, 1)
self.AddParam("guff","blob","percent","-23")
self.AddParam("Options", "a",[1,2,3,4,5], 2)
self.AddParam("Options", "B",[1,2,3,4,5], 3)
self.AddParam("Options", "c","a,b,c,d,e","7a")
self.AddParam("Options", "d","a,b,c,d,e","d")
def GetValue(self):
return "QFP_{d}".format(d=self.values['Pads']['n'])
#return "QFP_%d" % self.parameters["Pads"]["n"]
def BuildThisFootprint(self):
pads = self.parameters["Pads"]
pad_pitch = pads["pitch"]
pad_length = pads["length"]
pad_width = pads["width"]
v_pitch = pads["pitch"]
h_pitch = pads["pitch"]
pads_per_row = pads["n"] // 4
row_len = (pads_per_row - 1) * pad_pitch
pad_shape = pcbnew.PAD_SHAPE_OVAL if pads["oval"] else pcbnew.PAD_SHAPE_RECT
h_pad = PA.PadMaker(self.module).SMDPad( pad_length, pad_width,
shape=pad_shape, rot_degree=90.0)
v_pad = PA.PadMaker(self.module).SMDPad( pad_length, pad_width, shape=pad_shape)
#left row
pin1Pos = pcbnew.wxPoint(-h_pitch / 2, 0)
array = PA.PadLineArray(h_pad, pads_per_row, pad_pitch, True, pin1Pos)
array.SetFirstPadInArray(1)
array.AddPadsToModule(self.draw)
#bottom row
pin1Pos = pcbnew.wxPoint(0, v_pitch / 2)
array = PA.PadLineArray(v_pad, pads_per_row, pad_pitch, False, pin1Pos)
array.SetFirstPadInArray(pads_per_row + 1)
array.AddPadsToModule(self.draw)
#right row
pin1Pos = pcbnew.wxPoint(h_pitch / 2, 0)
array = PA.PadLineArray(h_pad, pads_per_row, -pad_pitch, True,
pin1Pos)
array.SetFirstPadInArray(2*pads_per_row + 1)
array.AddPadsToModule(self.draw)
#top row
pin1Pos = pcbnew.wxPoint(0, -v_pitch / 2)
array = PA.PadLineArray(v_pad, pads_per_row, -pad_pitch, False,
pin1Pos)
array.SetFirstPadInArray(3*pads_per_row + 1)
array.AddPadsToModule(self.draw)
lim_x = self.parameters["Package"]["width"] / 2
lim_y = self.parameters["Package"]["height"] / 2
inner = (row_len / 2) + pad_pitch
#top left - diagonal
self.draw.Line(-lim_x, -inner, -inner, -lim_y)
# top right
self.draw.Polyline([(inner, -lim_y), (lim_x, -lim_y), (lim_x, -inner)])
# bottom left
self.draw.Polyline([(-inner, lim_y), (-lim_x, lim_y), (-lim_x, inner)])
# bottom right
self.draw.Polyline([(inner, lim_y), (lim_x, lim_y), (lim_x, inner)])
# Courtyard
cmargin = self.parameters["Package"]["courtyard margin"]
self.draw.SetLayer(pcbnew.F_CrtYd)
sizex = (lim_x + cmargin) * 2 + pad_length
sizey = (lim_y + cmargin) * 2 + pad_length
# round size to nearest 0.1mm, rectangle will thus land on a 0.05mm grid
sizex = pcbnew.PutOnGridMM(sizex, 0.1)
sizey = pcbnew.PutOnGridMM(sizey, 0.1)
# set courtyard line thickness to the one defined in KLC
thick = self.draw.GetLineThickness()
self.draw.SetLineThickness(pcbnew.FromMM(0.05))
self.draw.Box(0, 0, sizex, sizey)
# restore line thickness to previous value
self.draw.SetLineThickness(pcbnew.FromMM(thick))
#reference and value
text_size = self.GetTextSize() # IPC nominal
text_offset = v_pitch / 2 + text_size + pad_length / 2
self.draw.Value(0, text_offset, text_size)
self.draw.Reference(0, -text_offset, text_size)
# set SMD attribute
self.module.SetAttributes(pcbnew.MOD_CMS)
TestWizard().register()
if __name__ == '__main__':
w = TestWizard()
w.BuildFootprint()
print w.Show()
print w.buildmessages