diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 5b50bb4d..28f8b74d 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -17,6 +17,7 @@ def __init__(self): self.color_mode = 'SHORT' self.connectors = {} self.cables = {} + self.additional_bom_items = [] def add_connector(self, name, *args, **kwargs): self.connectors[name] = Connector(name, *args, **kwargs) @@ -24,6 +25,9 @@ def add_connector(self, name, *args, **kwargs): def add_cable(self, name, *args, **kwargs): self.cables[name] = Cable(name, *args, **kwargs) + def add_bom_item(self, item): + self.additional_bom_items.append(item) + def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin): for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors if name is not None and name in self.connectors: @@ -316,6 +320,7 @@ def bom(self): bom = [] bom_connectors = [] bom_cables = [] + bom_extra = [] # connectors connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.manufacturer_part_number, c.internal_part_number) for group in Counter([connector_group(v) for v in self.connectors.values()]): @@ -379,6 +384,16 @@ def bom(self): bom_cables.append(item) bom_cables = sorted(bom_cables, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050) bom.extend(bom_cables) + + for item in self.additional_bom_items: + name = item['description'] if item.get('description', None) else '' + if isinstance(item.get('designators', None), List): + item['designators'].sort() # sort designators if a list is provided + item = {'item': name, 'qty': item.get('qty', None), 'unit': item.get('unit', None), 'designators': item.get('designators', None), + 'manufacturer': item.get('manufacturer', None), 'manufacturer part number': item.get('manufacturer_part_number', None), 'internal part number': item.get('internal_part_number', None)} + bom_extra.append(item) + bom_extra = sorted(bom_extra, key=lambda k: k['item']) + bom.extend(bom_extra) return bom def bom_list(self): diff --git a/src/wireviz/wireviz.py b/src/wireviz/wireviz.py index dfdf8877..518dccaa 100755 --- a/src/wireviz/wireviz.py +++ b/src/wireviz/wireviz.py @@ -169,6 +169,11 @@ def check_designators(what, where): # helper function to_pin = connection_list[i+1][j][1] harness.connect(from_name, from_pin, via_name, via_pin, to_name, to_pin) + if "additional_bom_items" in yaml_data: + for line in yaml_data["additional_bom_items"]: + harness.add_bom_item(line) + + if file_out is not None: harness.output(filename=file_out, fmt=('png', 'svg'), view=False)