Skip to content

Commit

Permalink
Add ability to include aditional BOM lines (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Ward authored Jul 13, 2020
1 parent 3eed968 commit 8b69e9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ 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)

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:
Expand Down Expand Up @@ -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()]):
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions src/wireviz/wireviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8b69e9a

Please sign in to comment.