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('// https://github.com/formatc1702/WireViz')
font = 'arial'
bgcolor = wv_colors.default_bknd_color
dot.attr('graph', rankdir='LR',
ranksep='2',
bgcolor='white',
bgcolor=bgcolor,
nodesep='0.33',
fontname=font)
dot.attr('node', shape='record',
@ -141,7 +142,7 @@ class Harness:
for bla in p:
html = html + '<td>{}</td>'.format(bla)
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))
if c.shield:
@ -168,10 +169,10 @@ class Harness:
for x in c.connections:
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]
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]))
else: # color name not found
dot.attr('edge',color='#000000:#ffffff:#000000')
# if search_color in wv_colors.color_hex:
dot.attr('edge',color='#000000:{wire_color}:#000000'.format(wire_color=wv_colors.get_color_hex(search_color)))
# else: # color name not found
# dot.attr('edge',color='#000000:#ffffff:#000000')
else: # it's a shield connection
dot.attr('edge',color='#000000')
@ -230,6 +231,7 @@ class Harness:
file.write('</body></html>')
# TODO: add support for types of cables / Part Numbers
def bom(self):
bom = []
bom_connectors = []

View File

@ -1,9 +1,28 @@
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',
'WHGY', 'GYBN', 'WHPK', 'PKBN', 'WHBU', 'BNBU', 'WHRD', 'BNRD', 'WHBK', 'BNBK', 'GYGN', 'YEGY', 'PKGN',
'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']
'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 = {
'BK': '#000000',
'WH': '#ffffff',
@ -16,9 +35,17 @@ color_hex = {
'TQ': '#00ffff',
'BU': '#0066ff',
'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 = {
'BK': 'black',
'WH': 'white',
@ -32,8 +59,12 @@ color_full = {
'BU': 'blue',
'VT': 'violet',
'BN': 'brown',
'SL': 'slate',
'CU': 'bare copper',
'TI': 'tinned copper',
}
# TODO Help wanted! Need help translating colors/banded colors to german shortcodes
color_ger = {
'BK': 'sw',
'WH': 'ws',
@ -49,6 +80,21 @@ color_ger = {
'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):
if input == '':
output = ''
@ -58,9 +104,9 @@ def translate_color(input, color_mode):
elif color_mode == 'FULL':
output = color_full[input].upper()
elif color_mode == 'hex':
output = color_hex[input].lower()
output = get_color_hex(input).lower()
elif color_mode == 'HEX':
output = color_hex[input].upper()
output = get_color_hex(input).upper()
elif color_mode == 'ger':
output = color_ger[input].lower()
elif color_mode == 'GER':