From 67dc73a752f7fae13c8438da0570f5723eb25866 Mon Sep 17 00:00:00 2001 From: Tyler Ward Date: Tue, 21 Jul 2020 23:00:25 +0100 Subject: [PATCH] Add extra components to connector nodes in graph --- src/wireviz/Harness.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 8940c191..6deb10ac 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -97,8 +97,29 @@ def create_graph(self) -> Graph: html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, connector.color, '' if connector.color else None], - '' if connector.style != 'simple' else None, - [html_line_breaks(connector.notes)]] + '' if connector.style != 'simple' else None] + if connector.additional_components is not None: + rows.append(["Additional components"]) + for extra in connector.additional_components: + if 'qty' in extra: + if isinstance(extra['qty'], int) or isinstance(extra['qty'], float): + qty = extra['qty'] + else: # check for special quantities + if extra['qty'] == 'pincount': + qty = connector.pincount + elif extra['qty'] == 'connectioncount': + qty = sum(1 for value in connector.visible_pins.values() if value is True) + else: + raise ValueError('invalid aty parameter') + else: + qty = 1 + rows.append([extra["type"], qty]) + rows.append([extra["manufacturer"], + f'MPN: {extra["manufacturer_part_number"]}' if "manufacturer_part_number" in extra else None, + f'IPN: {extra["internal_part_number"]}' if "internal_part_number" in extra else None],) + rows.append([f'P/N: {extra["pn"]}' if extra["pn"] else None, + html_line_breaks(manufacturer_info_field(extra.get("manufacturer", None), extra.get("mpn", None)))]) + rows.append([html_line_breaks(connector.notes)]) html.extend(nested_html_table(rows)) if connector.color: # add color bar next to color info, if present