@@ -44,7 +44,7 @@ def normalize(point):
44
44
return [point [0 ] * 1e-6 , point [1 ] * 1e-6 ]
45
45
46
46
def parse_shape (self , d ):
47
- # type: (pcbnew.DRAWSEGMENT ) -> dict | None
47
+ # type: (pcbnew.PCB_SHAPE ) -> dict or None
48
48
shape = {
49
49
pcbnew .S_SEGMENT : "segment" ,
50
50
pcbnew .S_CIRCLE : "circle" ,
@@ -249,7 +249,7 @@ def get_all_drawings(self):
249
249
return drawings
250
250
251
251
def parse_pad (self , pad ):
252
- # type: (pcbnew.D_PAD ) -> dict or None
252
+ # type: (pcbnew.PAD ) -> dict or None
253
253
layers_set = list (pad .GetLayerSet ().Seq ())
254
254
layers = []
255
255
if pcbnew .F_Cu in layers_set :
@@ -318,7 +318,7 @@ def parse_pad(self, pad):
318
318
return pad_dict
319
319
320
320
def parse_footprints (self ):
321
- # type: (list ) -> list
321
+ # type: () -> list
322
322
footprints = []
323
323
for f in self .footprints :
324
324
ref = f .GetReference ()
@@ -362,11 +362,13 @@ def parse_footprints(self):
362
362
if pads :
363
363
# Try to guess first pin name.
364
364
pads = sorted (pads , key = lambda el : el [0 ])
365
- pin1_pads = [p for p in pads if p [0 ] in ['1' , 'A' , 'A1' , 'P1' , 'PAD1' ]]
365
+ pin1_pads = [p for p in pads if p [0 ] in
366
+ ['1' , 'A' , 'A1' , 'P1' , 'PAD1' ]]
366
367
if pin1_pads :
367
368
pin1_pad_name = pin1_pads [0 ][0 ]
368
369
else :
369
- # No pads have common first pin name, pick lexicographically smallest.
370
+ # No pads have common first pin name,
371
+ # pick lexicographically smallest.
370
372
pin1_pad_name = pads [0 ][0 ]
371
373
for pad_name , pad_dict in pads :
372
374
if pad_name == pin1_pad_name :
@@ -398,9 +400,9 @@ def parse_tracks(self, tracks):
398
400
"width" : track .GetWidth () * 1e-6 ,
399
401
"net" : track .GetNetname (),
400
402
}
401
- for l in [pcbnew .F_Cu , pcbnew .B_Cu ]:
402
- if track .IsOnLayer (l ):
403
- result [l ].append (track_dict )
403
+ for layer in [pcbnew .F_Cu , pcbnew .B_Cu ]:
404
+ if track .IsOnLayer (layer ):
405
+ result [layer ].append (track_dict )
404
406
else :
405
407
if track .GetLayer () in [pcbnew .F_Cu , pcbnew .B_Cu ]:
406
408
track_dict = {
@@ -419,15 +421,16 @@ def parse_tracks(self, tracks):
419
421
420
422
def parse_zones (self , zones ):
421
423
result = {pcbnew .F_Cu : [], pcbnew .B_Cu : []}
422
- for zone in zones : # type: pcbnew.ZONE_CONTAINER
424
+ for zone in zones : # type: pcbnew.ZONE
423
425
if (not zone .IsFilled () or
424
426
hasattr (zone , 'GetIsKeepout' ) and zone .GetIsKeepout () or
425
427
hasattr (zone , 'GetIsRuleArea' ) and zone .GetIsRuleArea ()):
426
428
continue
427
- layers = [l for l in list (zone .GetLayerSet ().Seq ())
428
- if l in [pcbnew .F_Cu , pcbnew .B_Cu ]]
429
+ layers = [layer for layer in list (zone .GetLayerSet ().Seq ())
430
+ if layer in [pcbnew .F_Cu , pcbnew .B_Cu ]]
429
431
for layer in layers :
430
432
try :
433
+ # kicad 5.1 and earlier
431
434
poly_set = zone .GetFilledPolysList ()
432
435
except TypeError :
433
436
poly_set = zone .GetFilledPolysList (layer )
@@ -483,12 +486,21 @@ def footprint_to_component(footprint):
483
486
484
487
def parse (self ):
485
488
title_block = self .board .GetTitleBlock ()
489
+ title = title_block .GetTitle ()
490
+ revision = title_block .GetRevision ()
491
+ company = title_block .GetCompany ()
492
+ if (hasattr (self .board , "GetProject" ) and
493
+ hasattr (pcbnew , "ExpandTextVars" )):
494
+ project = self .board .GetProject ()
495
+ title = pcbnew .ExpandTextVars (title , project )
496
+ revision = pcbnew .ExpandTextVars (revision , project )
497
+ company = pcbnew .ExpandTextVars (company , project )
498
+
486
499
file_date = title_block .GetDate ()
487
500
if not file_date :
488
501
file_mtime = os .path .getmtime (self .file_name )
489
502
file_date = datetime .fromtimestamp (file_mtime ).strftime (
490
503
'%Y-%m-%d %H:%M:%S' )
491
- title = title_block .GetTitle ()
492
504
pcb_file_name = os .path .basename (self .file_name )
493
505
if not title :
494
506
# remove .kicad_pcb extension
@@ -520,8 +532,8 @@ def parse(self):
520
532
"footprints" : self .parse_footprints (),
521
533
"metadata" : {
522
534
"title" : title ,
523
- "revision" : title_block . GetRevision () ,
524
- "company" : title_block . GetCompany () ,
535
+ "revision" : revision ,
536
+ "company" : company ,
525
537
"date" : file_date ,
526
538
},
527
539
"bom" : {},
@@ -560,8 +572,7 @@ def defaults(self):
560
572
def Run (self ):
561
573
from ..version import version
562
574
from ..errors import ParsingException
563
- self .version = version
564
- config = Config (self .version )
575
+ config = Config (version )
565
576
board = pcbnew .GetBoard ()
566
577
pcb_file_name = board .GetFileName ()
567
578
0 commit comments