Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to include aditional bom lines. #80

Merged
merged 3 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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