2
2
import sys
3
3
4
4
from .common import EcadParser , Component , BoundingBox
5
+ from .svgpath import parse_path
5
6
6
7
7
8
PY3 = sys .version_info [0 ] == 3
@@ -202,7 +203,7 @@ def parse_pad(self, shape):
202
203
else :
203
204
points = []
204
205
angle = int (shape [10 ])
205
- hole_length = self .normalize (shape [12 ])
206
+ hole_length = self .normalize (shape [12 ]) if shape [ 12 ] else 0
206
207
207
208
pad_layers = {
208
209
self .TOP_COPPER_LAYER : ['F' ],
@@ -273,8 +274,7 @@ def add_custom():
273
274
'custom' : add_custom ,
274
275
}.get (pad ['shape' ])()
275
276
276
- @staticmethod
277
- def add_drawing_bounding_box (drawing , bbox ):
277
+ def add_drawing_bounding_box (self , drawing , bbox ):
278
278
# type: (dict, BoundingBox) -> None
279
279
280
280
def add_segment ():
@@ -286,9 +286,13 @@ def add_circle():
286
286
bbox .add_circle (drawing ['start' ][0 ], drawing ['start' ][1 ],
287
287
drawing ['radius' ] + drawing ['width' ] / 2 )
288
288
289
+ def add_svgpath ():
290
+ width = drawing .get ('width' , 0 )
291
+ bbox .add_svgpath (drawing ['svgpath' ], width , self .logger )
292
+
289
293
def add_polygon ():
290
294
if 'polygons' not in drawing :
291
- # TODO: svgpath polygons
295
+ add_svgpath ()
292
296
return
293
297
polygon = drawing ['polygons' ][0 ]
294
298
for point in polygon :
@@ -297,9 +301,9 @@ def add_polygon():
297
301
{
298
302
'segment' : add_segment ,
299
303
'circle' : add_circle ,
300
- 'arc' : lambda : None , # TODO
304
+ 'arc' : add_svgpath ,
301
305
'polygon' : add_polygon ,
302
- 'text' : lambda : None , # TODO
306
+ 'text' : lambda : None , # text is not really needed for bounding box
303
307
}.get (drawing ['type' ])()
304
308
305
309
def parse_lib (self , shape ):
@@ -353,7 +357,7 @@ def parse_lib(self, shape):
353
357
for pad in pads :
354
358
self .add_pad_bounding_box (pad , bbox )
355
359
for drawing in copper_drawings :
356
- self .add_drawing_bounding_box (drawing , bbox )
360
+ self .add_drawing_bounding_box (drawing [ 'drawing' ] , bbox )
357
361
for _ , drawing in extra_drawings :
358
362
self .add_drawing_bounding_box (drawing , bbox )
359
363
bbox .pad (0.5 ) # pad by 5 mil
@@ -430,14 +434,21 @@ def parse(self):
430
434
431
435
drawings , modules , components = self .parse_shapes (pcb ['shape' ])
432
436
433
- bbox = {
434
- "minx" : self .normalize (pcb ['BBox' ]['x' ]),
435
- "miny" : self .normalize (pcb ['BBox' ]['y' ]),
436
- "maxx" : self .normalize (pcb ['BBox' ]['x' ]) + self .normalize (
437
- pcb ['BBox' ]['width' ]),
438
- "maxy" : self .normalize (pcb ['BBox' ]['y' ]) + self .normalize (
439
- pcb ['BBox' ]['height' ])
440
- }
437
+ board_outline_bbox = BoundingBox ()
438
+ for drawing in drawings .get (self .BOARD_OUTLINE_LAYER , []):
439
+ self .add_drawing_bounding_box (drawing , board_outline_bbox )
440
+ if board_outline_bbox .initialized ():
441
+ bbox = board_outline_bbox .to_dict ()
442
+ else :
443
+ # if nothing is drawn on outline layer then rely on EasyEDA bbox
444
+ x = self .normalize (pcb ['BBox' ]['x' ])
445
+ y = self .normalize (pcb ['BBox' ]['y' ])
446
+ bbox = {
447
+ "minx" : x ,
448
+ "miny" : y ,
449
+ "maxx" : x + self .normalize (pcb ['BBox' ]['width' ]),
450
+ "maxy" : y + self .normalize (pcb ['BBox' ]['height' ])
451
+ }
441
452
442
453
pcbdata = {
443
454
"edges_bbox" : bbox ,
0 commit comments