Skip to content

Commit 11b7b0b

Browse files
committed
Add warning when some references are not found in netlist/xml file
1 parent a763492 commit 11b7b0b

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def logerror(msg):
4747
def logwarn(msg):
4848
if is_cli:
4949
logger.warn(msg)
50+
else:
51+
wx.LogWarning(msg)
5052

5153

5254
def skip_component(m, config, extra_data, filter_layer):
@@ -116,6 +118,7 @@ def natural_sort(l):
116118
}
117119

118120
# build grouped part list
121+
warning_shown = False
119122
part_groups = {}
120123
for m in pcb.GetModules():
121124
if skip_component(m, config, extra_data, filter_layer):
@@ -145,12 +148,21 @@ def natural_sort(l):
145148
extras = [extra_data[ref].get(f, '')
146149
for f in config.extra_fields]
147150
else:
151+
# Some components are on pcb but not in schematic data.
152+
# Show a warning about possibly outdated netlist/xml file.
153+
# Doing it only once when generating full bom is enough.
154+
if filter_layer is None:
155+
logwarn(
156+
'Component %s is missing from schematic data.' % ref)
157+
warning_shown = True
148158
extras = [''] * len(config.extra_fields)
149159

150160
group_key = (norm_value, tuple(extras), footprint, attr)
151161
valrefs = part_groups.setdefault(group_key, [value, []])
152162
valrefs[1].append(ref)
153163

164+
if warning_shown:
165+
logwarn('Netlist/xml file is likely out of date.')
154166
# build bom table, sort refs
155167
bom_table = []
156168
for (norm_value, extras, footprint, attr), valrefs in part_groups.items():
@@ -613,7 +625,7 @@ def Run(self):
613625
config.netlist_initial_directory = os.path.dirname(
614626
pcbnew.GetBoard().GetFileName())
615627
extra_data_file = find_latest_schematic_data(
616-
config.netlist_initial_directory)
628+
config.netlist_initial_directory)
617629
if extra_data_file is not None:
618630
dlg.set_extra_data_path(extra_data_file)
619631
config.transfer_to_dialog(dlg.panel)

InteractiveHtmlBom/schematic_data/netlistparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def get_extra_field_data(self):
2424
fields = f[1:]
2525
if ref is None:
2626
return None
27+
ref_fields = comp_dict.setdefault(ref, {})
2728
if fields is None:
2829
continue
2930
for f in fields:
3031
if len(f) > 1:
3132
field_set.add(f[1][1])
3233
if len(f) > 2:
33-
ref_fields = comp_dict.setdefault(ref, {})
3434
ref_fields[f[1][1]] = f[2]
3535

3636
return list(field_set), comp_dict

InteractiveHtmlBom/schematic_data/xmlparser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ def get_extra_field_data(self):
1818
field_set = set()
1919
comp_dict = {}
2020
for c in components:
21+
ref_fields = comp_dict.setdefault(c.attributes['ref'].value, {})
2122
for f in c.getElementsByTagName('field'):
2223
name = f.attributes['name'].value
2324
if name not in self.DEFAULT_FIELDS:
2425
field_set.add(name)
25-
ref_fields = comp_dict.setdefault(
26-
c.attributes['ref'].value, {})
2726
ref_fields[name] = self.get_text(f.childNodes)
2827

2928
return list(field_set), comp_dict

0 commit comments

Comments
 (0)