Skip to content

Commit aaee522

Browse files
committed
Add board variant whitelist
1 parent 37626f6 commit aaee522

File tree

2 files changed

+36
-24
lines changed

2 files changed

+36
-24
lines changed

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import pcbnew
1010
import wx
11-
from typing import Dict
1211

1312
import dialog.settings_dialog as dialog
1413
import units
@@ -50,13 +49,43 @@ def logwarn(msg):
5049
logger.warn(msg)
5150

5251

53-
def generate_bom(pcb, config, extra_fields, filter_layer=None):
52+
def skip_component(m, config, extra_data, filter_layer):
53+
# type: (pcbnew.MODULE, Config, dict, int) -> bool
54+
# filter part by layer
55+
if filter_layer is not None and filter_layer != m.GetLayer():
56+
return True
57+
58+
# skip blacklisted components
59+
ref = m.GetReference()
60+
ref_prefix = re.findall('^[A-Z]*', ref)[0]
61+
if ref in config.component_blacklist:
62+
return True
63+
if ref_prefix + '*' in config.component_blacklist:
64+
return True
65+
66+
# skip components with dnp field not empty
67+
if config.dnp_field and ref in extra_data \
68+
and config.dnp_field in extra_data[ref] \
69+
and extra_data[ref][config.dnp_field]:
70+
return True
71+
72+
# skip components with wrong variant field
73+
if config.board_variant_field and config.board_variants:
74+
if ref in extra_data:
75+
ref_variant = extra_data[ref][config.board_variant_field]
76+
if ref_variant not in config.board_variants:
77+
return True
78+
79+
return False
80+
81+
82+
def generate_bom(pcb, config, extra_data, filter_layer=None):
5483
# type: (pcbnew.BOARD, Config, Dict[str, dict], int) -> list
5584
"""
5685
Generate BOM from pcb layout.
5786
:param pcb: pcbnew BOARD object
5887
:param config: Config object
59-
:param extra_fields: Extra fields data
88+
:param extra_data: Extra fields data
6089
:param filter_layer: include only parts for given layer
6190
:return: BOM table (qty, value, footprint, refs)
6291
"""
@@ -84,22 +113,7 @@ def natural_sort(l):
84113
# build grouped part list
85114
part_groups = {}
86115
for m in pcb.GetModules():
87-
# filter part by layer
88-
if filter_layer is not None and filter_layer != m.GetLayer():
89-
continue
90-
91-
# skip blacklisted components
92-
ref = m.GetReference()
93-
ref_prefix = re.findall('^[A-Z]*', ref)[0]
94-
if ref in config.component_blacklist:
95-
continue
96-
if ref_prefix + '*' in config.component_blacklist:
97-
continue
98-
99-
# skip components with dnp field not empty
100-
if config.dnp_field and ref in extra_fields \
101-
and config.dnp_field in extra_fields[ref] \
102-
and extra_fields[ref][config.dnp_field]:
116+
if skip_component(m, config, extra_data, filter_layer):
103117
continue
104118

105119
# group part refs by value and footprint
@@ -581,7 +595,8 @@ def Run(self):
581595
import argparse
582596

583597
parser = argparse.ArgumentParser(
584-
description='KiCad PCB pick and place assistant')
598+
description='KiCad PCB pick and place assistant',
599+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
585600
parser.add_argument('file', type=str, help="KiCad PCB file")
586601
config = Config()
587602
config.add_options(parser)

InteractiveHtmlBom/schematic_data/parser_base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from typing import Tuple
2-
3-
41
class ParserBase:
52
DEFAULT_FIELDS = []
63

@@ -11,7 +8,7 @@ def __init__(self, file_name):
118
self.file_name = file_name
129

1310
def get_extra_field_data(self):
14-
# type: () -> Tuple[list, dict]
11+
# type: () -> tuple
1512
"""
1613
Parses the file and returns a extra field data.
1714
:return: tuple of the format

0 commit comments

Comments
 (0)