Add support for Multicolored (banded) wires

Also add in the 25 pair code, and the full DIN code
This commit is contained in:
Andrew Katz 2020-06-24 21:01:49 -04:00
parent 10e747c81e
commit 21bc9b1773
2 changed files with 97 additions and 49 deletions

View File

@ -33,9 +33,10 @@ class Harness:
dot.body.append('// Graph generated by WireViz') dot.body.append('// Graph generated by WireViz')
dot.body.append('// https://github.com/formatc1702/WireViz') dot.body.append('// https://github.com/formatc1702/WireViz')
font = 'arial' font = 'arial'
bgcolor = wv_colors.default_bknd_color
dot.attr('graph', rankdir='LR', dot.attr('graph', rankdir='LR',
ranksep='2', ranksep='2',
bgcolor='white', bgcolor=bgcolor,
nodesep='0.33', nodesep='0.33',
fontname=font) fontname=font)
dot.attr('node', shape='record', dot.attr('node', shape='record',
@ -141,7 +142,7 @@ class Harness:
for bla in p: for bla in p:
html = html + '<td>{}</td>'.format(bla) html = html + '<td>{}</td>'.format(bla)
html = html + '</tr>' html = html + '</tr>'
bgcolor = wv_colors.translate_color(x, 'hex') bgcolor = ":".join(wv_colors.translate_color(x, 'hex').split(':')[:2])
html = html + '<tr><td colspan="{colspan}" cellpadding="0" height="6" bgcolor="{bgcolor}" border="2" sides="tb" port="{port}"></td></tr>'.format(colspan=len(p), bgcolor=bgcolor if bgcolor != '' else '#ffffff', port='w{}'.format(i)) html = html + '<tr><td colspan="{colspan}" cellpadding="0" height="6" bgcolor="{bgcolor}" border="2" sides="tb" port="{port}"></td></tr>'.format(colspan=len(p), bgcolor=bgcolor if bgcolor != '' else '#ffffff', port='w{}'.format(i))
if c.shield: if c.shield:
@ -168,10 +169,10 @@ class Harness:
for x in c.connections: for x in c.connections:
if isinstance(x.via_port, int): # check if it's an actual wire and not a shield if isinstance(x.via_port, int): # check if it's an actual wire and not a shield
search_color = c.colors[x.via_port-1] search_color = c.colors[x.via_port-1]
if search_color in wv_colors.color_hex: # if search_color in wv_colors.color_hex:
dot.attr('edge',color='#000000:{wire_color}:#000000'.format(wire_color=wv_colors.color_hex[search_color])) dot.attr('edge',color='#000000:{wire_color}:#000000'.format(wire_color=wv_colors.get_color_hex(search_color)))
else: # color name not found # else: # color name not found
dot.attr('edge',color='#000000:#ffffff:#000000') # dot.attr('edge',color='#000000:#ffffff:#000000')
else: # it's a shield connection else: # it's a shield connection
dot.attr('edge',color='#000000') dot.attr('edge',color='#000000')
@ -230,6 +231,7 @@ class Harness:
file.write('</body></html>') file.write('</body></html>')
# TODO: add support for types of cables / Part Numbers
def bom(self): def bom(self):
bom = [] bom = []
bom_connectors = [] bom_connectors = []

View File

@ -1,54 +1,100 @@
COLOR_CODES = { COLOR_CODES = {
'DIN': ['WH','BN','GN','YE','GY','PK','BU','RD','BK','VT'], # ,'GYPK','RDBU','WHGN','BNGN','WHYE','YEBN','WHGY','GYBN','WHPK','PKBN'], 'DIN': ['WH', 'BN', 'GN', 'YE', 'GY', 'PK', 'BU', 'RD', 'BK', 'VT', 'GYPK', 'RDBU', 'WHGN', 'BNGN', 'WHYE', 'YEBN',
'IEC': ['BN','RD','OG','YE','GN','BU','VT','GY','WH','BK'], 'WHGY', 'GYBN', 'WHPK', 'PKBN', 'WHBU', 'BNBU', 'WHRD', 'BNRD', 'WHBK', 'BNBK', 'GYGN', 'YEGY', 'PKGN',
'BW': ['BK','WH'] 'YEPK', 'GNBU', 'YEBU', 'GNRD', 'YERD', 'GNBK', 'YEBK', 'GYBU', 'PKBU', 'GYRD', 'PKRD', 'GYBK', 'PKBK',
} 'BUBK', 'RDBK', 'WHBNBK', 'YEGNBK', 'GYPKBK', 'RDBUBK', 'WHGNBK', 'BNGNBK', 'WHYEBK', 'YEBNBK', 'WHGYBK',
'GYBNBK', 'WHPKBK', 'PKBNBK', 'WHBUBK', 'BNBUBK', 'WHRDBK', 'BNRDBK'],
'IEC': ['BN', 'RD', 'OG', 'YE', 'GN', 'BU', 'VT', 'GY', 'WH', 'BK'],
'BW': ['BK', 'WH'],
'TEL': ['BUWH', 'WHBU', 'OGWH', 'WHOG', 'GNWH', 'WHGN', 'BNWH', 'WHBN', 'SLWH', 'WHSL', 'BURD', 'RDBU', 'OGRD',
'RDOG', 'GNRD', 'RDGN', 'BNRD', 'RDBN', 'SLRD', 'RDSL', 'BUBK', 'BKBU', 'OGBK', 'BKOG', 'GNBK', 'BKGN',
'BNBK', 'BKBN', 'SLBK', 'BKSL', 'BUYW', 'YWBU', 'OGYW', 'YWOG', 'GNYW', 'YWGN', 'BNYW', 'YWBN', 'SLYW',
'YWSL', 'BUVT', 'VTBU', 'OGVT', 'VTOG', 'GNVT', 'VTGN', 'BNVT', 'VTBN', 'SLVT', 'VTSL'],
'TELALT': ['WHBU', 'BU', 'WHOG', 'OG', 'WHGN', 'GN', 'WHBN', 'BN', 'WHSL', 'SL', 'RDBU', 'BURD', 'RDOG', 'OGRD',
'RDGN', 'GNRD', 'RDBN', 'BNRD', 'RDSL', 'SLRD', 'BKBU', 'BUBK', 'BKOG', 'OGBK', 'BKGN', 'GNBK', 'BKBN',
'BNBK', 'BKSL', 'SLBK', 'YWBU', 'BUYW', 'YWOG', 'OGYW', 'YWGN', 'GNYW', 'YWBN', 'BNYW', 'YWSL', 'SLYW',
'VTBU', 'BUVT', 'VTOG', 'OGVT', 'VTGN', 'GNVT', 'VTBN', 'BNVT', 'VTSL', 'SLVT'],
'T568A': ['WHGN', 'GN', 'WHOG', 'BU', 'WHBU', 'OG', 'WHBN', 'BN'],
'T568B': ['WHOG', 'OG', 'WHGN', 'BU', 'WHBU', 'GN', 'WHBN', 'BN'],
}
_default_color = '#ffffff'
# default_bkgnd_color = '#ffffff' # white
default_bknd_color = '#fffbf8' # off-white beige-ish
color_hex = { color_hex = {
'BK': '#000000', 'BK': '#000000',
'WH': '#ffffff', 'WH': '#ffffff',
'GY': '#999999', 'GY': '#999999',
'PK': '#ff66cc', 'PK': '#ff66cc',
'RD': '#ff0000', 'RD': '#ff0000',
'OG': '#ff8000', 'OG': '#ff8000',
'YE': '#ffff00', 'YE': '#ffff00',
'GN': '#00ff00', 'GN': '#00ff00',
'TQ': '#00ffff', 'TQ': '#00ffff',
'BU': '#0066ff', 'BU': '#0066ff',
'VT': '#8000ff', 'VT': '#8000ff',
'BN': '#666600', 'BN': '#a52a2a',
} 'SL': '#708090',
# Faux-copper look, for bare CU wire
'CU': '#d6775e:#895956',
# Silvery look for tinned bare wire
'TI': '#aaaaaa:#84878c',
# Yellow-green PE wire
'PE': '#54aa85:#f7f854:#54aa85',
}
# TODO: Add a helper method for this, that can deal with banded wires
color_full = { color_full = {
'BK': 'black', 'BK': 'black',
'WH': 'white', 'WH': 'white',
'GY': 'grey', 'GY': 'grey',
'PK': 'pink', 'PK': 'pink',
'RD': 'red', 'RD': 'red',
'OG': 'orange', 'OG': 'orange',
'YE': 'yellow', 'YE': 'yellow',
'GN': 'green', 'GN': 'green',
'TQ': 'turquoise', 'TQ': 'turquoise',
'BU': 'blue', 'BU': 'blue',
'VT': 'violet', 'VT': 'violet',
'BN': 'brown', 'BN': 'brown',
'SL': 'slate',
'CU': 'bare copper',
'TI': 'tinned copper',
} }
# TODO Help wanted! Need help translating colors/banded colors to german shortcodes
color_ger = { color_ger = {
'BK': 'sw', 'BK': 'sw',
'WH': 'ws', 'WH': 'ws',
'GY': 'gr', 'GY': 'gr',
'PK': 'rs', 'PK': 'rs',
'RD': 'rt', 'RD': 'rt',
'OG': 'or', 'OG': 'or',
'YE': 'ge', 'YE': 'ge',
'GN': 'gn', 'GN': 'gn',
'TQ': 'tk', 'TQ': 'tk',
'BU': 'bl', 'BU': 'bl',
'VT': 'vi', 'VT': 'vi',
'BN': 'br', 'BN': 'br',
} }
def get_color_hex(input):
if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look
input = input + input[:2]
output = ''
for i in range(0, len(input), 2): # Split into 2 letter chunks
if input[i:i + 2] in color_hex:
output += color_hex[input[i:i + 2]]
if i + 2 != len(input):
output += ':'
if output == '':
output = _default_color
return output
def translate_color(input, color_mode): def translate_color(input, color_mode):
if input == '': if input == '':
output = '' output = ''
@ -58,9 +104,9 @@ def translate_color(input, color_mode):
elif color_mode == 'FULL': elif color_mode == 'FULL':
output = color_full[input].upper() output = color_full[input].upper()
elif color_mode == 'hex': elif color_mode == 'hex':
output = color_hex[input].lower() output = get_color_hex(input).lower()
elif color_mode == 'HEX': elif color_mode == 'HEX':
output = color_hex[input].upper() output = get_color_hex(input).upper()
elif color_mode == 'ger': elif color_mode == 'ger':
output = color_ger[input].lower() output = color_ger[input].lower()
elif color_mode == 'GER': elif color_mode == 'GER':