Skip to content

Commit 699ea3b

Browse files
committed
Add an option to generate hole series or slot in drill file
1 parent 79923a0 commit 699ea3b

File tree

6 files changed

+98
-16
lines changed

6 files changed

+98
-16
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ step 4: the BOM and Postion CSV file will be generated under the same folder of
4949
## Attention:
5050

5151
The GenMFDoc() command will change the Aux original point
52+
53+
## Preivew
54+
55+
56+
![holes_with_ref](holes_with_ref.png)
57+
58+
59+
![slot_without_ref](slot_without_ref.png)

desc.png

14.8 KB
Loading

gerber_drill.py

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
129129
#drlwriter.GenDrillReportFile( rptfn );
130130

131131
if split_G85:
132-
SplitG85InDrill(pctl.GetPlotDirName(), False, split_G85)
132+
logger("Split the slot into holes")
133+
SplitSlotInDrill(pctl.GetPlotDirName(), False, split_G85)
133134

134135
files = [f for f in os.listdir(pctl.GetPlotDirName()) if f.endswith('.gbr')]
135136
for f in files:
@@ -140,7 +141,10 @@ def GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "plot/", plotReferen
140141
plotFiles.append( pctl.GetPlotDirName() + f )
141142

142143
brdName = board.GetFileName()
143-
brdName = brdName[brdName.rfind(os.path.sep)+1: brdName.rfind('.')]
144+
s = os.path.split(brdName)
145+
brdName = s[1]
146+
brdName = brdName[0:brdName.rfind('.')]
147+
logger("Board Name:", brdName)
144148
zipName = pctl.GetPlotDirName() + brdName + "_gerber.zip"
145149
logger("Zip them into " + zipName)
146150

@@ -161,7 +165,30 @@ def FromGerberPosition(position_str):
161165

162166
def same(p1,p2,diff = 0.0001):
163167
return (abs(p1[0]-p2[0])<diff) and (abs(p1[1]-p2[1])<diff)
164-
168+
169+
def SplitSlot(p1, p2, step = 0.2):
170+
r = []
171+
dx = p2[0] - p1[0]
172+
dy = p2[1] - p1[1]
173+
dist = sqrt(dx*dx+dy*dy)
174+
td = 0
175+
pt = [p1[0],p1[1]]
176+
count = 0
177+
while not same(pt,p2):
178+
r.append('X%sY%s\n' %(str(float('%.3f'%pt[0])),str(float('%.3f'%pt[1]))))
179+
pt[0] = pt[0] + step*dx/dist
180+
pt[1] = pt[1] + step*dy/dist
181+
if dist - td < (step*1.5):
182+
pt[0] = p2[0]
183+
pt[1] = p2[1]
184+
else:
185+
td = td + step
186+
count = count + 1
187+
if count > 50:
188+
break
189+
r.append('X%sY%s\n' %(str(float('%.3f'%pt[0])),str(float('%.3f'%pt[1]))))
190+
return r
191+
165192
def SplitG85(G85Data,step = 0.2):
166193
t = G85Data.split('G85')
167194
r = []
@@ -187,9 +214,9 @@ def SplitG85(G85Data,step = 0.2):
187214
if count > 50:
188215
break
189216
r.append('X%sY%s\n' %(str(float('%.3f'%pt[0])),str(float('%.3f'%pt[1]))))
190-
return r, True
217+
return r
191218
else:
192-
return [G85Data], False
219+
return None
193220

194221
def HoleSize(line):
195222
r = re.compile('(T[0-9]+)C([-0-9.]+)')
@@ -206,9 +233,21 @@ def round(value, round = 0.1):
206233
t = math.ceil(t)
207234
return t * round
208235

209-
def SplitG85InDrill(drillPath, newfilename = True,step = 0.2):
210-
''' Split the G85 command to hole seqence in drill file
211-
'''
236+
def isG05(line):
237+
return line.find('G05') == 0
238+
239+
def isG00(line):
240+
return line.find('G00') == 0
241+
def isG01(line):
242+
return line.find('G01') == 0
243+
def isM15(line):
244+
return line.find('M15') == 0
245+
def isM16(line):
246+
return line.find('M16') == 0
247+
248+
249+
250+
def SplitSlotInDrill(drillPath, newfilename = True,step = 0.2):
212251
files = [f for f in os.listdir(drillPath) if f.endswith('.drl')]
213252
for fn in files:
214253
infn = drillPath + fn
@@ -219,6 +258,9 @@ def SplitG85InDrill(drillPath, newfilename = True,step = 0.2):
219258
skip_G05 = False
220259
holes = {}
221260
curHolesSize = None
261+
slot_mode = False
262+
hole_begin = None
263+
hole_end = None
222264
for line in ins:
223265
hn,hs = HoleSize(line)
224266
if hn and hs:
@@ -228,17 +270,39 @@ def SplitG85InDrill(drillPath, newfilename = True,step = 0.2):
228270
step = 0.2
229271
if curHolesSize:
230272
step = round(curHolesSize/3)
231-
r, nextSkip = SplitG85(line, step)
232-
if skip_G05 and (r[0].find('G05') == 0):
233-
skip_G05 = False
273+
r = SplitG85(line, step)
274+
if not r:
275+
if isG00(line):
276+
slot_mode = True
277+
hole_begin = FromGerberPosition(line)
278+
if not slot_mode:
279+
if r:
280+
skip_G05 = True
281+
for l in r:
282+
outline.append(l)
283+
else:
284+
if skip_G05 and isG05(line):
285+
skip_G05 = False
286+
else:
287+
outline.append(line)
234288
else:
235-
skip_G05 = nextSkip
236-
for l in r:
237-
outline.append(l)
289+
if isG01(line):
290+
hole_end = FromGerberPosition(line)
291+
if isG05(line):
292+
slot_mode = False
293+
if hole_begin and hole_end:
294+
r = SplitSlot(hole_begin, hole_end, step)
295+
for l in r:
296+
outline.append(l)
297+
else:
298+
logger("Slot hole format error")
299+
hole_begin = None
300+
hole_end = None
238301
ins.close()
239302
if newfilename:
240303
outfn = infn.replace(".drl", "_no_slot.drl")
241304
fo = open(outfn, "w+")
242305
fo.writelines(outline)
243306
fo.close()
307+
244308

holes_with_ref.png

50.3 KB
Loading

mf_tool.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,16 +668,18 @@ def __init__(self):
668668
self.chkPos = wx.CheckBox(self, label = "Positon File ", pos = (15, 30))
669669
self.chkGerber = wx.CheckBox(self, label = "Gerber Files", pos = (15, 50))
670670
self.chkPlotRef = wx.CheckBox(self, label = "Plot Reference", pos = (130, 50))
671+
self.chkSplitSlot = wx.CheckBox(self, label = "Split Slot", pos = (280, 50))
671672
self.chkBOM.SetValue(True)
672673
self.chkPos.SetValue(True)
673674
self.chkGerber.SetValue(True)
674675
self.chkPlotRef.SetValue(True)
676+
self.chkSplitSlot.SetValue(True)
675677

676678
self.static_text = wx.StaticText(self, -1, 'Log:', style=wx.ALIGN_CENTER, pos = (15, 70))
677679
self.area_text = wx.TextCtrl(self, -1, '', size=(770, 300), pos = (15, 90),
678680
style=(wx.TE_MULTILINE | wx.TE_AUTO_SCROLL | wx.TE_DONTWRAP| wx.TE_READONLY))
679681

680-
self.btnGen = wx.Button(self, label = "Generate Manufacture Docs", pos=(300, 30))
682+
self.btnGen = wx.Button(self, label = "Generate Manufacture Docs", pos=(400, 30))
681683
self.Bind(wx.EVT_BUTTON, self.Onclick, self.btnGen)
682684

683685
self.btnClearLog = wx.Button(self, label = "Clear Log", pos=(700, 30))
@@ -703,7 +705,15 @@ def Onclick(self, e):
703705
GenMFDoc(needGenBOM = self.chkBOM.GetValue(), needGenPos = self.chkPos.GetValue(), logger = lambda *args: self.log(*args) )
704706
if self.chkGerber.GetValue():
705707
self.area_text.AppendText("Start generate gerber files\n")
706-
gerberPath = gd.GenGerberDrill(board = None, split_G85 = 0.2, plotDir = "gerber/", plotReference = self.chkPlotRef.GetValue(), logger = lambda *args: self.log(*args))
708+
split_slot = None
709+
if self.chkSplitSlot.GetValue():
710+
split_slot = 0.2
711+
gerberPath = gd.GenGerberDrill(
712+
board = None,
713+
split_G85 = split_slot,
714+
plotDir = "gerber/",
715+
plotReference = self.chkPlotRef.GetValue(),
716+
logger = lambda *args: self.log(*args))
707717
self.area_text.AppendText( 'Gerber file dir is "%s"' % gerberPath)
708718
except Exception as e:
709719
self.area_text.AppendText("Error:\n")

slot_without_ref.png

54.1 KB
Loading

0 commit comments

Comments
 (0)