Show pin labels of adjacent connectors in cable node (#70)

This commit is contained in:
Daniel Rojas 2020-11-11 20:59:27 +01:00
parent 3bf448c692
commit eebf932c8d

View File

@ -282,26 +282,44 @@ class Harness:
html = [row.replace('<!-- wire table -->', '\n'.join(wirehtml)) for row in html] html = [row.replace('<!-- wire table -->', '\n'.join(wirehtml)) for row in html]
# connections # connections
for connection_color in cable.connections: for connection in cable.connections:
if isinstance(connection_color.via_port, int): # check if it's an actual wire and not a shield if isinstance(connection.via_port, int): # check if it's an actual wire and not a shield
dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection_color.via_port - 1], pad=pad) + ['#000000'])) dot.attr('edge', color=':'.join(['#000000'] + wv_colors.get_color_hex(cable.colors[connection.via_port - 1], pad=pad) + ['#000000']))
else: # it's a shield connection else: # it's a shield connection
# shield is shown with specified color and black borders, or as a thin black wire otherwise # shield is shown with specified color and black borders, or as a thin black wire otherwise
dot.attr('edge', color=':'.join(['#000000', shield_color_hex, '#000000']) if isinstance(cable.shield, str) else '#000000') dot.attr('edge', color=':'.join(['#000000', shield_color_hex, '#000000']) if isinstance(cable.shield, str) else '#000000')
if connection_color.from_port is not None: # connect to left if connection.from_port is not None: # connect to left
from_port = f':p{connection_color.from_port}r' if self.connectors[connection_color.from_name].style != 'simple' else '' from_connector = self.connectors[connection.from_name]
code_left_1 = f'{connection_color.from_name}{from_port}:e' from_port = f':p{connection.from_port}r' if from_connector.style != 'simple' else ''
code_left_2 = f'{cable.name}:w{connection_color.via_port}:w' code_left_1 = f'{connection.from_name}{from_port}:e'
code_left_2 = f'{cable.name}:w{connection.via_port}:w'
dot.edge(code_left_1, code_left_2) dot.edge(code_left_1, code_left_2)
from_string = f'{connection_color.from_name}:{connection_color.from_port}' if self.connectors[connection_color.from_name].show_name else '' if from_connector.show_name:
html = [row.replace(f'<!-- {connection_color.via_port}_in -->', from_string) for row in html] from_info = [str(connection.from_name), str(connection.from_port)]
if connection_color.to_port is not None: # connect to right if from_connector.pinlabels:
code_right_1 = f'{cable.name}:w{connection_color.via_port}:e' pinlabel = from_connector.pinlabels[from_connector.pins.index(connection.from_port)]
to_port = f':p{connection_color.to_port}l' if self.connectors[connection_color.to_name].style != 'simple' else '' if pinlabel != '':
code_right_2 = f'{connection_color.to_name}{to_port}:w' from_info.append(pinlabel)
from_string = ':'.join(from_info)
else:
from_string = ''
html = [row.replace(f'<!-- {connection.via_port}_in -->', from_string) for row in html]
if connection.to_port is not None: # connect to right
to_connector = self.connectors[connection.to_name]
code_right_1 = f'{cable.name}:w{connection.via_port}:e'
to_port = f':p{connection.to_port}l' if self.connectors[connection.to_name].style != 'simple' else ''
code_right_2 = f'{connection.to_name}{to_port}:w'
dot.edge(code_right_1, code_right_2) dot.edge(code_right_1, code_right_2)
to_string = f'{connection_color.to_name}:{connection_color.to_port}' if self.connectors[connection_color.to_name].show_name else '' if to_connector.show_name:
html = [row.replace(f'<!-- {connection_color.via_port}_out -->', to_string) for row in html] to_info = [str(connection.to_name), str(connection.to_port)]
if to_connector.pinlabels:
pinlabel = to_connector.pinlabels[to_connector.pins.index(connection.to_port)]
if pinlabel != '':
to_info.append(pinlabel)
to_string = ':'.join(to_info)
else:
to_string = ''
html = [row.replace(f'<!-- {connection.via_port}_out -->', to_string) for row in html]
html = '\n'.join(html) html = '\n'.join(html)
dot.node(cable.name, label=f'<\n{html}\n>', shape='box', dot.node(cable.name, label=f'<\n{html}\n>', shape='box',