diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 9d83a3d..4df9c7a 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -24,7 +24,8 @@ class Harness: def __init__(self): self.color_mode = 'SHORT' - self.mini_bom_mode = True + self.show_part_numbers = True # TODO: Make configurable via YAML + self.show_bom_item_numbers = True # TODO: Make configurable via YAML self.connectors = {} self.cables = {} self._bom = [] # Internal Cache for generated bom @@ -114,16 +115,17 @@ class Harness: html = [] rows = [[remove_links(connector.name) if connector.show_name else None], - [f'P/N: {remove_links(connector.pn)}' if connector.pn else None, - html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))], - [html_line_breaks(connector.type), + ['<BOM Number>' if self.show_bom_item_numbers else None, # TODO: Show actual BOM number + html_line_breaks(connector.type), html_line_breaks(connector.subtype), f'{connector.pincount}-pin' if connector.show_pincount else None, connector.color, html_colorbar(connector.color)], + [f'P/N: {remove_links(connector.pn)}' if connector.pn else None, + html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))] if self.show_part_numbers else None, '' if connector.style != 'simple' else None, [html_image(connector.image)], [html_caption(connector.image)]] - rows.extend(get_additional_component_table(self, connector)) + rows.append(get_additional_component_table(self, connector)) rows.append([html_line_breaks(connector.notes)]) html.extend(nested_html_table(rows)) @@ -209,7 +211,7 @@ class Harness: [html_image(cable.image)], [html_caption(cable.image)]] - rows.extend(get_additional_component_table(self, cable)) + rows.append(get_additional_component_table(self, cable)) # TODO: reimplement rows.append([html_line_breaks(cable.notes)]) html.extend(nested_html_table(rows)) diff --git a/src/wireviz/wv_bom.py b/src/wireviz/wv_bom.py index f71abc1..85ff0f8 100644 --- a/src/wireviz/wv_bom.py +++ b/src/wireviz/wv_bom.py @@ -20,18 +20,40 @@ def get_additional_component_table(harness: "Harness", component: Union[Connecto """Return a list of diagram node table row strings with additional components.""" rows = [] if component.additional_components: - rows.append(["Additional components"]) + # rows.append(["Additional components"]) for part in component.additional_components: common_args = { 'qty': part.qty * component.get_qty_multiplier(part.qty_multiplier), 'unit': part.unit, } - if harness.mini_bom_mode: - id = get_bom_index(harness.bom(), part) - rows.append(component_table_entry(f'#{id} ({part.type.rstrip()})', **common_args)) - else: - rows.append(component_table_entry(part.description, **common_args, **optional_fields(part))) - return rows + # if True: + # id = get_bom_index(harness.bom(), part) + # rows.append(component_table_entry(f'#{id} ({part.type.rstrip()})', **common_args)) + # else: + # rows.append(component_table_entry(part.description, **common_args, **optional_fields(part))) + id = get_bom_index(harness.bom(), part) + manufacturer_str = manufacturer_info_field(part.manufacturer, part.mpn) + columns = [] + if harness.show_bom_item_numbers: + columns.append(f'
{id}
') + columns.append(f'{part.qty}' + (f' {part.unit}' if part.unit else ' x')) + columns.append(f'{part.type}') + if harness.show_part_numbers: + columns.append(f'P/N: {part.pn}' if part.pn else '') + columns.append(f'{manufacturer_str}' if manufacturer_str else '') + # TODO: Add note column as proposed in #222 + + rowstr = '' + ''.join([f'{col}' for col in columns]) + '' + rows.append(rowstr) + + print(rows) + pre = '' + post = '
' + if len(rows) > 0: + tbl = pre + ''.join(rows) + post + else: + return None + return tbl def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]: """Return a list of BOM entries with additional components.""" @@ -157,9 +179,9 @@ def component_table_entry( + (manufacturer_str or '')) # format the above output as left aligned text in a single visible cell # indent is set to two to match the indent in the generated html table - return f''' + return f''' -
{html_line_breaks(output)}
''' + ''' def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]: """Return the manufacturer and/or the mpn in one single string or None otherwise."""