From 2639c77360ee1527ca401741de7137790e40b5f9 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Thu, 30 Jul 2020 08:03:57 +0200 Subject: [PATCH] Refactor cable GraphViz HTML generation to match the one for connectors. --- src/wireviz/Harness.py | 90 +++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 58 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 9cc6b96..7715cd6 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -139,11 +139,12 @@ class Harness: dot.edge(f'{connector.name}:p{loop[0]}{loop_side}:{loop_dir}', f'{connector.name}:p{loop[1]}{loop_side}:{loop_dir}') + # determine if there are double- or triple-colored wires in the harness; # if so, pad single-color wires to make all wires of equal thickness pad = any(len(colorstr) > 2 for cable in self.cables.values() for colorstr in cable.colors) - for _, cable in self.cables.items(): + for key, cable in self.cables.items(): awg_fmt = '' if cable.show_equiv: @@ -155,57 +156,36 @@ class Harness: elif cable.gauge_unit.upper() == 'AWG': awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' - identification = [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else '', - manufacturer_info_field(cable.manufacturer if not isinstance(cable.manufacturer, list) else None, - cable.mpn if not isinstance(cable.mpn, list) else None)] - identification = list(filter(None, identification)) + rows = [[cable.name if cable.show_name else None], + [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else None, + manufacturer_info_field(cable.manufacturer, cable.mpn) if not isinstance(cable.manufacturer, list) else None], + [html_line_breaks(cable.type), + f'{len(cable.colors)}x' if cable.show_wirecount else None, + f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None, + '+ S' if cable.shield else None, + f'{cable.length} m' if cable.length > 0 else None], + '', + [html_line_breaks(cable.notes)]] + html = nested_html_table(rows) - attributes = [html_line_breaks(cable.type) if cable.type else '', - f'{len(cable.colors)}x' if cable.show_wirecount else '', - f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', - '+ S' if cable.shield else '', - f'{cable.length} m' if cable.length > 0 else ''] - attributes = list(filter(None, attributes)) - - html = '' # main table - - if cable.show_name or len(attributes) > 0: - html = f'{html}' # name+attributes table - - html = f'{html}' # spacer between attributes and wires - - html = f'{html}
' # name+attributes table - if cable.show_name: - html = f'{html}' - if(len(identification) > 0): # print an identification row if values specified - html = f'{html}' # end identification row - if(len(attributes) > 0): - html = f'{html}' # attribute row - for attrib in attributes: - html = f'{html}' - html = f'{html}' # attribute row - html = f'{html}
{cable.name}
' - for attrib in identification[0:-1]: - html = f'{html}' # all columns except last have a border on the right (sides="R") - if len(identification) > 0: - html = f'{html}' # last column has no border on the right because the enclosing table borders it - html = f'{html}
{attrib}{identification[-1]}
{attrib}
 
' # conductor table + wirehtml = '
' # conductor table + wirehtml = f'{wirehtml}' for i, connection_color in enumerate(cable.colors, 1): p = [] p.append(f'') p.append(wv_colors.translate_color(connection_color, self.color_mode)) p.append(f'') - html = f'{html}' + wirehtml = f'{wirehtml}' for bla in p: - html = f'{html}' - html = f'{html}' + wirehtml = f'{wirehtml}' + wirehtml = f'{wirehtml}' bgcolors = ['#000000'] + get_color_hex(connection_color, pad=pad) + ['#000000'] - html = f'{html}' if(cable.category == 'bundle'): # for bundles individual wires can have part information # create a list of wire parameters wireidentification = [] @@ -217,18 +197,18 @@ class Harness: wireidentification.append(manufacturer_info) # print parameters into a table row under the wire if(len(wireidentification) > 0): - html = f'{html}' if cable.shield: p = ['', 'Shield', ''] - html = f'{html}' # spacer - html = f'{html}' + wirehtml = f'{wirehtml}' # spacer + wirehtml = f'{wirehtml}' for bla in p: - html = html + f'' - html = f'{html}' + wirehtml = wirehtml + f'' + wirehtml = f'{wirehtml}' if isinstance(cable.shield, str): # shield is shown with specified color and black borders shield_color_hex = wv_colors.get_color_hex(cable.shield)[0] @@ -236,18 +216,12 @@ class Harness: else: # shield is shown as a thin black wire attributes = f'height="2" bgcolor="#000000" border="0"' - html = f'{html}' + wirehtml = f'{wirehtml}' - html = f'{html}' # spacer at the end + wirehtml = f'{wirehtml}' + wirehtml = f'{wirehtml}
 
{bla}
{bla}
' + wirehtml = f'{wirehtml}' + wirehtml = f'{wirehtml}' + wirehtml = wirehtml + '
' for j, bgcolor in enumerate(bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors - html = f'{html}' - html = html + '
' + wirehtml = f'{wirehtml}' + wirehtml = f'{wirehtml}' + wirehtml = f'{wirehtml}
' for attrib in wireidentification: - html = f'{html}' - html = f'{html}
{attrib}
{attrib}
 
 
{bla}
{bla}
 
 
' - html = f'{html}
' # conductor table - - html = f'{html}' # main table - if cable.notes: - html = f'{html}{html_line_breaks(cable.notes)}' # notes table - html = f'{html} ' # spacer at the end - - html = f'{html}' # main table + html = html.replace('', wirehtml) # connections for connection_color in cable.connections: