Add wire colors

This commit is contained in:
Daniel Rojas 2020-05-22 12:43:18 +02:00
parent 48e744a0ce
commit e084da0d4a
2 changed files with 22 additions and 4 deletions

View File

@ -8,9 +8,10 @@ X1[label="X1 | {{DCD|RX|TX|DTR|GND|DSR|RTS|CTS|RI} | {<p1>1|<p2>2|<p3>3|<p4>4|<p
X2[label="X2 | {{<p1>1|<p2>2|<p3>3|<p4>4|<p5>5|<p6>6} | {|||||}}}"]
W1[label="W1 | {{<w1i>1|<w2i>2|<w3i>3|<w4i>4} | {WH|BN|GN|Shield} | {<w1o>1|<w2o>2|<w3o>3|<w4o>4}}}"]
{edge[style=bold]{X1:p2 -> W1:w1i; W1:w1o -> X2:p1}
{X1:p3 -> W1:w2i; W1:w2o -> X2:p3}
{X1:p5 -> W1:w3i; W1:w3o -> X2:p2}
{edge[style=bold]
{edge[color="#000000:#ffffff:#000000"] X1:p2 -> W1:w1i; W1:w1o -> X2:p1}
{edge[color="#000000:#808000:#000000"] X1:p3 -> W1:w2i; W1:w2o -> X2:p3}
{edge[color="#000000:#00ff00:#000000"] X1:p5 -> W1:w3i; W1:w3o -> X2:p2}
}

View File

@ -2,6 +2,20 @@
COLOR_CODE_DIN = ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT']
COLOR_CODE_IEC = ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK']
color_dict = {'BK': '#000000',
'WH': '#ffffff',
'GY': '#808080',
'PK': '#ff80c0',
'RD': '#ff0000',
'OG': '#ff8000',
'YE': '#ffff00',
'GN': '#00ff00',
'TQ': '#00ffff',
'BU': '#0000ff',
'VT': '#8000ff',
'BN': '#808000',
}
class Node:
def __init__(self, name, num_pins=None, pinout=None, ports_left=False, ports_right=False):
@ -126,9 +140,12 @@ class Cable:
s = s + '}}"]'
s = s + '\n\n{edge[style=bold]'
s = s + '\n\n{edge[style=bold]\n'
for x in self.connections:
s = s + '{'
search_color = self.colors[x[2]-1]
if search_color in color_dict:
s = s + 'edge[color="#000000:{wire_color}:#000000"] '.format(wire_color=color_dict[search_color])
t = '{from_name}:p{from_port} -> {via_name}:w{via_wire}i; {via_name}:w{via_wire}o -> {to_name}:p{to_port}'.format(from_name=x[0],from_port=x[1],via_name=self.name, via_wire=x[2],to_name=x[3],to_port=x[4])
s = s + t
s = s + '}\n'