New addit. compo. BOM table proof of concept

This commit is contained in:
Daniel Rojas 2021-03-23 10:49:56 +01:00
parent 523d0c659e
commit 8c26c8fbbd
2 changed files with 39 additions and 15 deletions

View File

@ -24,7 +24,8 @@ class Harness:
def __init__(self): def __init__(self):
self.color_mode = 'SHORT' 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.connectors = {}
self.cables = {} self.cables = {}
self._bom = [] # Internal Cache for generated bom self._bom = [] # Internal Cache for generated bom
@ -114,16 +115,17 @@ class Harness:
html = [] html = []
rows = [[remove_links(connector.name) if connector.show_name else None], rows = [[remove_links(connector.name) if connector.show_name else None],
[f'P/N: {remove_links(connector.pn)}' if connector.pn else None, ['<BOM Number>' if self.show_bom_item_numbers else None, # TODO: Show actual BOM number
html_line_breaks(manufacturer_info_field(connector.manufacturer, connector.mpn))], html_line_breaks(connector.type),
[html_line_breaks(connector.type),
html_line_breaks(connector.subtype), html_line_breaks(connector.subtype),
f'{connector.pincount}-pin' if connector.show_pincount else None, f'{connector.pincount}-pin' if connector.show_pincount else None,
connector.color, html_colorbar(connector.color)], 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,
'<!-- connector table -->' if connector.style != 'simple' else None, '<!-- connector table -->' if connector.style != 'simple' else None,
[html_image(connector.image)], [html_image(connector.image)],
[html_caption(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)]) rows.append([html_line_breaks(connector.notes)])
html.extend(nested_html_table(rows)) html.extend(nested_html_table(rows))
@ -209,7 +211,7 @@ class Harness:
[html_image(cable.image)], [html_image(cable.image)],
[html_caption(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)]) rows.append([html_line_breaks(cable.notes)])
html.extend(nested_html_table(rows)) html.extend(nested_html_table(rows))

View File

@ -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.""" """Return a list of diagram node table row strings with additional components."""
rows = [] rows = []
if component.additional_components: if component.additional_components:
rows.append(["Additional components"]) # rows.append(["Additional components"])
for part in component.additional_components: for part in component.additional_components:
common_args = { common_args = {
'qty': part.qty * component.get_qty_multiplier(part.qty_multiplier), 'qty': part.qty * component.get_qty_multiplier(part.qty_multiplier),
'unit': part.unit, 'unit': part.unit,
} }
if harness.mini_bom_mode: # 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) id = get_bom_index(harness.bom(), part)
rows.append(component_table_entry(f'#{id} ({part.type.rstrip()})', **common_args)) manufacturer_str = manufacturer_info_field(part.manufacturer, part.mpn)
columns = []
if harness.show_bom_item_numbers:
columns.append(f'<table border="0"><tr><td border="1" style="rounded">{id}</td></tr></table>')
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 = '<tr>' + ''.join([f'<td align="left" balign="left">{col}</td>' for col in columns]) + '</tr>'
rows.append(rowstr)
print(rows)
pre = '<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
post = '</table>'
if len(rows) > 0:
tbl = pre + ''.join(rows) + post
else: else:
rows.append(component_table_entry(part.description, **common_args, **optional_fields(part))) return None
return rows return tbl
def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]: def get_additional_component_bom(component: Union[Connector, Cable]) -> List[BOMEntry]:
"""Return a list of BOM entries with additional components.""" """Return a list of BOM entries with additional components."""
@ -157,9 +179,9 @@ def component_table_entry(
+ (manufacturer_str or '')) + (manufacturer_str or ''))
# format the above output as left aligned text in a single visible cell # 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 # indent is set to two to match the indent in the generated html table
return f'''<table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr> return f'''<tr>
<td align="left" balign="left">{html_line_breaks(output)}</td> <td align="left" balign="left">{html_line_breaks(output)}</td>
</tr></table>''' </tr>'''
def manufacturer_info_field(manufacturer: Optional[str], mpn: Optional[str]) -> Optional[str]: 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.""" """Return the manufacturer and/or the mpn in one single string or None otherwise."""