@@ -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
162166def 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+
165192def 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
194221def 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
0 commit comments