Test additional component table (WIP)

This commit is contained in:
Daniel Rojas 2021-10-15 14:04:44 +02:00
parent 26b505120a
commit 1799490bf2
4 changed files with 38 additions and 12 deletions

View File

@ -7,6 +7,7 @@ from pathlib import Path
from wireviz.wv_helper import int2tuple, aspect_ratio from wireviz.wv_helper import int2tuple, aspect_ratio
from wireviz.wv_colors import Color, Colors, ColorMode, ColorScheme, COLOR_CODES from wireviz.wv_colors import Color, Colors, ColorMode, ColorScheme, COLOR_CODES
from wireviz.wv_bom_new import Bom_hash, Bom_hash_list from wireviz.wv_bom_new import Bom_hash, Bom_hash_list
from wireviz.wv_gv_html import nested_html_table, bom_bubble
# Each type alias have their legal values described in comments - validation might be implemented in the future # Each type alias have their legal values described in comments - validation might be implemented in the future
PlainText = str # Text not containing HTML tags nor newlines PlainText = str # Text not containing HTML tags nor newlines
@ -180,6 +181,15 @@ class TopLevelGraphicalComponent(GraphicalComponent):
show_name: bool = True show_name: bool = True
def gen_add_bom_table(self):
if self.additional_components:
rows = []
for comp in self.additional_components:
rows.append([bom_bubble(comp.bom_id), comp.qty, comp.description, comp.pn])
return rows
else:
return None
@dataclass @dataclass
class Connector(TopLevelGraphicalComponent): class Connector(TopLevelGraphicalComponent):
@ -241,7 +251,6 @@ class Connector(TopLevelGraphicalComponent):
def activate_pin(self, pin: Pin) -> None: def activate_pin(self, pin: Pin) -> None:
self.visible_pins[pin] = True self.visible_pins[pin] = True
@property
def qty_factor(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int: def qty_factor(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int:
if not qty_multiplier: if not qty_multiplier:
return 1 return 1
@ -376,7 +385,6 @@ class Cable(TopLevelGraphicalComponent):
for i, _ in enumerate(from_pin): for i, _ in enumerate(from_pin):
self.connections.append(Connection(from_name, from_pin[i], via_wire[i], to_name, to_pin[i])) self.connections.append(Connection(from_name, from_pin[i], via_wire[i], to_name, to_pin[i]))
@property
def qty_factor(self, qty_multiplier: Optional[CableMultiplier]) -> float: def qty_factor(self, qty_multiplier: Optional[CableMultiplier]) -> float:
if not qty_multiplier: if not qty_multiplier:
return 1 return 1

View File

@ -13,14 +13,14 @@ from wireviz.DataClasses import AdditionalComponent, Metadata, Options, Tweak, C
from wireviz.wv_colors import get_color_hex, translate_color from wireviz.wv_colors import get_color_hex, translate_color
from wireviz.wv_gv_html import nested_html_table, \ from wireviz.wv_gv_html import nested_html_table, \
html_bgcolor_attr, html_bgcolor, html_colorbar, \ html_bgcolor_attr, html_bgcolor, html_colorbar, \
html_image, html_caption, remove_links, html_line_breaks, bom_bubble html_image, html_caption, remove_links, html_line_breaks, bom_bubble, html_table
# from wireviz.wv_bom import pn_info_string, component_table_entry, \ # from wireviz.wv_bom import pn_info_string, component_table_entry, \
# get_additional_component_table, bom_list, generate_bom, \ # get_additional_component_table, bom_list, generate_bom, \
# HEADER_PN, HEADER_MPN, HEADER_SPN # HEADER_PN, HEADER_MPN, HEADER_SPN
from wireviz.wv_bom_new import pn_info_string, HEADER_PN, HEADER_MPN, HEADER_SPN from wireviz.wv_bom_new import pn_info_string, HEADER_PN, HEADER_MPN, HEADER_SPN
from wireviz.wv_html import generate_html_output from wireviz.wv_html import generate_html_output
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \
open_file_read, open_file_write open_file_read, open_file_write, remove_empty_columns
@dataclass @dataclass
@ -192,9 +192,10 @@ class Harness:
html_colorbar(connector.color)], html_colorbar(connector.color)],
'<!-- 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)],
html_table(remove_empty_columns(connector.gen_add_bom_table()), 2)]
# rows.extend(get_additional_component_table(self, connector)) # rows.extend(get_additional_component_table(self, connector))
rows.append(['Reimplement additional component table!']) # rows.append()
rows.append([html_line_breaks(connector.notes)]) rows.append([html_line_breaks(connector.notes)])
html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor))) html.extend(nested_html_table(rows, html_bgcolor_attr(connector.bgcolor)))
@ -522,8 +523,8 @@ class Harness:
bomlist = [[]] bomlist = [[]]
# HTML output # HTML output
generate_html_output(filename, bomlist, self.metadata, self.options) generate_html_output(filename, bomlist, self.metadata, self.options)
#
def bom(self): # def bom(self):
if not self._bom: # if not self._bom:
self._bom = generate_bom(self) # self._bom = generate_bom(self)
return self._bom # return self._bom

View File

@ -32,6 +32,18 @@ def nested_html_table(rows: List[Union[str, List[Optional[str]], None]], table_a
html.append('</table>') html.append('</table>')
return html return html
def html_table(rows: List[List[str]], indent_level: int = 0) -> str:
html = []
html.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')
for row in rows:
html.append(' <tr>')
for item in row:
html.append(f' <td>{item}</td>')
html.append(' </tr>')
html.append('</table>')
html = [' '*indent_level + row for row in html]
return '\n'.join(html)
def html_bgcolor_attr(color: Color) -> str: def html_bgcolor_attr(color: Color) -> str:
"""Return attributes for bgcolor or '' if no color.""" """Return attributes for bgcolor or '' if no color."""
return f' bgcolor="{translate_color(color, "HEX")}"' if color else '' return f' bgcolor="{translate_color(color, "HEX")}"' if color else ''
@ -75,6 +87,5 @@ def html_size_attr(image):
def html_line_breaks(inp): def html_line_breaks(inp):
return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp return remove_links(inp).replace('\n', '<br />') if isinstance(inp, str) else inp
def bom_bubble(inp): def bom_bubble(inp):
return(f'<table border="0"><tr><td border="1" style="rounded">{inp}</td></tr></table>') return(f'<table border="0"><tr><td border="1" style="rounded">{inp}</td></tr></table>')

View File

@ -116,3 +116,9 @@ def aspect_ratio(image_src):
except Exception as error: except Exception as error:
print(f'aspect_ratio(): {type(error).__name__}: {error}') print(f'aspect_ratio(): {type(error).__name__}: {error}')
return 1 # Assume 1:1 when unable to read actual image size return 1 # Assume 1:1 when unable to read actual image size
def remove_empty_columns(inp: List[List]) -> List[List]:
transp = list(map(list, zip(*inp))) # transpose list
transp = [item for item in transp if any(item)] # remove empty rows (easier)
out = list(map(list, zip(*transp))) # transpose back
return out