Skip to content

Commit a0887b3

Browse files
committed
Fix footprint fields handling for kicad 8
Fixes #447
1 parent 432e702 commit a0887b3

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

InteractiveHtmlBom/ecad/common.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def remap(ref_fields):
4343
by_ref = {r: remap(d) for (r, d) in data.fields_by_ref.items()}
4444
if data.fields_by_index:
4545
by_index = {i: remap(d) for (i, d) in data.fields_by_index.items()}
46-
print([a.get("blah", "") for a in by_index.values()])
4746
else:
4847
by_index = None
4948

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ def __init__(self, file_name, config, logger, board=None):
1919
if self.board is None:
2020
self.board = pcbnew.LoadBoard(self.file_name) # type: pcbnew.BOARD
2121
if hasattr(self.board, 'GetModules'):
22-
self.footprints = list(self.board.GetModules())
22+
self.footprints = list(self.board.GetModules()) # type: list[pcbnew.MODULE]
2323
else:
24-
self.footprints = list(self.board.GetFootprints())
24+
self.footprints = list(self.board.GetFootprints()) # type: list[pcbnew.FOOTPRINT]
2525
self.font_parser = FontParser()
2626

2727
def get_extra_field_data(self, file_name):
@@ -109,7 +109,7 @@ def get_arc_angles(self, d):
109109
return round(a1, 2), round(a2, 2)
110110

111111
def parse_shape(self, d):
112-
# type: (pcbnew.PCB_SHAPE) -> dict or None
112+
# type: (pcbnew.PCB_SHAPE) -> dict | None
113113
shape = {
114114
pcbnew.S_SEGMENT: "segment",
115115
pcbnew.S_CIRCLE: "circle",
@@ -413,10 +413,17 @@ def get_all_drawings(self):
413413
drawings.append(("val", f.Value()))
414414
for d in f.GraphicalItems():
415415
drawings.append((d.GetClass(), d))
416+
if hasattr(f, "GetFields"):
417+
fields = f.GetFields() # type: list[pcbnew.PCB_FIELD]
418+
for field in fields:
419+
if field.IsReference() or field.IsValue():
420+
continue
421+
drawings.append((field.GetClass(), field))
422+
416423
return drawings
417424

418425
def parse_pad(self, pad):
419-
# type: (pcbnew.PAD) -> dict or None
426+
# type: (pcbnew.PAD) -> dict | None
420427
layers_set = list(pad.GetLayerSet().Seq())
421428
layers = []
422429
if pcbnew.F_Cu in layers_set:
@@ -497,7 +504,7 @@ def parse_pad(self, pad):
497504
def parse_footprints(self):
498505
# type: () -> list
499506
footprints = []
500-
for f in self.footprints: # type: pcbnew.FOOTPRINT
507+
for f in self.footprints:
501508
ref = f.GetReference()
502509

503510
# bounding box
@@ -619,8 +626,9 @@ def parse_tracks(self, tracks):
619626
}
620627

621628
def parse_zones(self, zones):
629+
# type: (list[pcbnew.ZONE]) -> dict
622630
result = {pcbnew.F_Cu: [], pcbnew.B_Cu: []}
623-
for zone in zones: # type: pcbnew.ZONE
631+
for zone in zones:
624632
if (not zone.IsFilled() or
625633
hasattr(zone, 'GetIsKeepout') and zone.GetIsKeepout() or
626634
hasattr(zone, 'GetIsRuleArea') and zone.GetIsRuleArea()):

0 commit comments

Comments
 (0)