Merge multi-color wires into refactored code
This commit is contained in:
parent
f0d10bfef8
commit
525be74c98
1
setup.py
1
setup.py
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
50
src/batch.py
50
src/batch.py
@ -1,50 +0,0 @@
|
||||
import wireviz
|
||||
import os
|
||||
|
||||
demos = 2 # 2
|
||||
examples = 7 # 7
|
||||
tutorials = 7 # 7
|
||||
|
||||
if demos:
|
||||
for i in range(1,demos+1):
|
||||
fn = '../examples/demo{:02d}.yml'.format(i)
|
||||
print(fn)
|
||||
wireviz.parse(fn, gen_bom=True)
|
||||
|
||||
if examples:
|
||||
with open(os.path.abspath('../examples/readme.md'), 'w') as file:
|
||||
file.write('# Example gallery\n')
|
||||
for i in range(1,examples+1):
|
||||
fn = '../examples/ex{:02d}.yml'.format(i)
|
||||
print(fn)
|
||||
wireviz.parse(fn, gen_bom=True)
|
||||
|
||||
file.write('## Example {:02d}\n'.format(i))
|
||||
file.write('\n\n'.format(i))
|
||||
file.write('[Source](ex{:02d}.yml) - [Bill of Materials](ex{:02d}.bom.tsv)\n\n\n'.format(i,i))
|
||||
|
||||
if tutorials:
|
||||
with open(os.path.abspath('../tutorial/readme.md'), 'w') as file:
|
||||
file.write('# WireViz Tutorial\n')
|
||||
for i in range(1,tutorials+1):
|
||||
fn = '../tutorial/tutorial{:02d}.yml'.format(i)
|
||||
print(fn)
|
||||
wireviz.parse(fn, gen_bom=True)
|
||||
|
||||
with open(os.path.abspath('../tutorial/tutorial{:02d}.md'.format(i)), 'r') as info:
|
||||
for line in info:
|
||||
file.write(line.replace('## ', '## {} - '.format(i)))
|
||||
file.write('\n[Source](tutorial{:02d}.yml):\n\n'.format(i))
|
||||
|
||||
with open(os.path.abspath('../tutorial/tutorial{:02d}.yml'.format(i)), 'r') as src:
|
||||
file.write('```yaml\n')
|
||||
for line in src:
|
||||
file.write(line)
|
||||
file.write('```\n')
|
||||
file.write('\n')
|
||||
|
||||
file.write('\nOutput:\n\n'.format(i))
|
||||
|
||||
file.write('\n\n'.format(i))
|
||||
|
||||
file.write('[Bill of Materials](tutorial{:02d}.bom.tsv)\n\n\n'.format(i))
|
||||
0
src/wireviz.py → src/wireviz.old
Executable file → Normal file
0
src/wireviz.py → src/wireviz.old
Executable file → Normal file
@ -39,7 +39,7 @@ class Harness:
|
||||
font = 'arial'
|
||||
dot.attr('graph', rankdir='LR',
|
||||
ranksep='2',
|
||||
bgcolor='white',
|
||||
bgcolor=wv_colors.default_bknd_color,
|
||||
nodesep='0.33',
|
||||
fontname=font)
|
||||
dot.attr('node', shape='record',
|
||||
@ -65,7 +65,6 @@ class Harness:
|
||||
infostring_l = infostring if connector.ports_right else ''
|
||||
infostring_r = infostring if connector.ports_left else ''
|
||||
|
||||
# INFO: Leaving this one as a string.format form because f-strings do not work well with triple quotes
|
||||
colorbar = f'<TD BGCOLOR="{wv_colors.translate_color(connector.color, "HEX")}" BORDER="1" SIDES="LR" WIDTH="4"></TD>' if connector.color else ''
|
||||
dot.node(key, shape='none',
|
||||
style='filled',
|
||||
@ -141,7 +140,7 @@ class Harness:
|
||||
html = f'{html}</tr>' # attribute row
|
||||
html = f'{html}</table></td></tr>' # name+attributes table
|
||||
|
||||
html = f'{html}<tr><td> </td></tr>' # spacer between attributes and wires
|
||||
html = f'{html}<tr><td></td></tr>' # spacer between attributes and wires
|
||||
|
||||
html = f'{html}<tr><td><table border="0" cellspacing="0" cellborder="0">' # conductor table
|
||||
|
||||
@ -154,27 +153,29 @@ class Harness:
|
||||
for bla in p:
|
||||
html = f'{html}<td>{bla}</td>'
|
||||
html = f'{html}</tr>'
|
||||
bgcolor = wv_colors.translate_color(connection, 'hex')
|
||||
bgcolor = bgcolor if bgcolor != '' else '#ffffff'
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" height="6" bgcolor="{bgcolor}" border="2" sides="tb" port="w{i}"></td></tr>'
|
||||
|
||||
bgcolors = ('#000000:' + wv_colors.translate_color(connection, 'hex') + ':#000000').split(':')
|
||||
html = f'{html}<tr><td colspan="{len(p)}" border="0" cellspacing="0" cellpadding="0" port="w{i}" height="{(2 * len(bgcolors))}"><table cellspacing="0" cellborder="0" border = "0">'
|
||||
for j, bgcolor in enumerate(
|
||||
bgcolors[::-1]): # Reverse to match the curved wires when more than 2 colors
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" height="2" bgcolor="{bgcolor if bgcolor != "" else wv_colors.default_color}" border="0"></td></tr>'
|
||||
html = html + '</table></td></tr>'
|
||||
if cable.shield:
|
||||
p = ['<!-- s_in -->', 'Shield', '<!-- s_out -->']
|
||||
html = f'{html}<tr><td> </td></tr>' # spacer
|
||||
html = f'{html}<tr><td></td></tr>' # spacer
|
||||
html = f'{html}<tr>'
|
||||
for bla in p:
|
||||
html = html + f'<td>{bla}</td>'
|
||||
html = f'{html}</tr>'
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" height="6" border="2" sides="b" port="ws"></td></tr>'
|
||||
html = f'{html}<tr><td colspan="{len(p)}" cellpadding="0" bgcolor="{wv_colors.shield_color}" height="6" border="2" sides="b" port="ws"></td></tr>'
|
||||
|
||||
html = f'{html}<tr><td> </td></tr>' # spacer at the end
|
||||
html = f'{html}<tr><td></td></tr>' # spacer at the end
|
||||
|
||||
html = f'{html}</table>' # conductor table
|
||||
|
||||
html = f'{html}</td></tr>' # main table
|
||||
if cable.notes:
|
||||
html = f'{html}<tr><td cellpadding="3">{cable.notes}</td></tr>' # notes table
|
||||
html = f'{html}<tr><td> </td></tr>' # spacer at the end
|
||||
html = f'{html}<tr><td></td></tr>' # spacer at the end
|
||||
|
||||
html = f'{html}</table>' # main table
|
||||
|
||||
@ -182,12 +183,10 @@ class Harness:
|
||||
for connection in cable.connections:
|
||||
if isinstance(connection.via_port, int): # check if it's an actual wire and not a shield
|
||||
search_color = cable.colors[connection.via_port - 1]
|
||||
if search_color in wv_colors.color_hex:
|
||||
dot.attr('edge', color=f'#000000:{wv_colors.color_hex[search_color]}:#000000')
|
||||
else: # color name not found
|
||||
dot.attr('edge', color='#000000:#ffffff:#000000')
|
||||
dot.attr('edge', color='#000000:{wire_color}:#000000'.format(
|
||||
wire_color=wv_colors.get_color_hex(search_color)))
|
||||
else: # it's a shield connection
|
||||
dot.attr('edge', color='#000000')
|
||||
dot.attr('edge', color=wv_colors.shield_color)
|
||||
|
||||
if connection.from_port is not None: # connect to left
|
||||
from_ferrule = self.connectors[connection.from_name].category == 'ferrule'
|
||||
|
||||
@ -9,7 +9,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
from wireviz import wireviz
|
||||
|
||||
demos = 2 # 2
|
||||
examples = 9 # 9
|
||||
examples = 10 # 10
|
||||
tutorials = 7 # 7
|
||||
|
||||
if demos:
|
||||
|
||||
@ -1,13 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import sys
|
||||
|
||||
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'],
|
||||
'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'],
|
||||
}
|
||||
|
||||
color_hex = {
|
||||
default_color = '#ffffff'
|
||||
|
||||
# default_bkgnd_color = '#ffffff' # white
|
||||
default_bknd_color = '#fffbf8' # off-white beige-ish
|
||||
|
||||
# Convention: Color names should be 2 letters long, to allow for multicolored wires
|
||||
|
||||
shield_color = '#aaaaaa:#84878c' # SN
|
||||
|
||||
_color_hex = {
|
||||
'BK': '#000000',
|
||||
'WH': '#ffffff',
|
||||
'GY': '#999999',
|
||||
@ -19,10 +43,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
|
||||
'SN': '#aaaaaa:#84878c',
|
||||
# Yellow-green PE wire
|
||||
'PE': '#54aa85:#f7f854:#54aa85',
|
||||
}
|
||||
|
||||
color_full = {
|
||||
_color_full = {
|
||||
'BK': 'black',
|
||||
'WH': 'white',
|
||||
'GY': 'grey',
|
||||
@ -35,9 +66,13 @@ color_full = {
|
||||
'BU': 'blue',
|
||||
'VT': 'violet',
|
||||
'BN': 'brown',
|
||||
'SL': 'slate',
|
||||
'CU': 'bare copper',
|
||||
'SN': 'tinned copper',
|
||||
}
|
||||
|
||||
color_ger = {
|
||||
# TODO Help wanted: can someone check the german translation?
|
||||
_color_ger = {
|
||||
'BK': 'sw',
|
||||
'WH': 'ws',
|
||||
'GY': 'gr',
|
||||
@ -50,29 +85,52 @@ color_ger = {
|
||||
'BU': 'bl',
|
||||
'VT': 'vi',
|
||||
'BN': 'br',
|
||||
# To the best of my ability, likely incorrect:
|
||||
|
||||
# Slate --> Schieferfarbe --> SI ??
|
||||
'SL': 'si',
|
||||
# Copper
|
||||
'CU': 'ku',
|
||||
# Tinned
|
||||
'SN': 'si'
|
||||
}
|
||||
|
||||
|
||||
def translate_color(inp, color_mode):
|
||||
if inp == '':
|
||||
output = ''
|
||||
else:
|
||||
|
||||
def get_color_hex(input):
|
||||
if len(input) == 4: # give wires with EXACTLY 2 colors that striped/banded look
|
||||
input = input + input[:2]
|
||||
try:
|
||||
output = ":".join([_color_hex[input[i:i + 2]] for i in range(0, len(input), 2)])
|
||||
except KeyError:
|
||||
print("Unknown Color Specified", file=sys.stderr)
|
||||
output = default_color
|
||||
#raise Exception('Unknown Color Name')
|
||||
if input == '':
|
||||
output = default_color
|
||||
return output
|
||||
|
||||
|
||||
def translate_color(input, color_mode):
|
||||
if input == '':
|
||||
return ''
|
||||
upper = color_mode.isupper()
|
||||
if not (color_mode.isupper() or color_mode.islower()):
|
||||
raise Exception('Unknown color mode capitalization')
|
||||
|
||||
color_mode = color_mode.lower()
|
||||
if color_mode == 'full':
|
||||
output = color_full[inp].lower()
|
||||
elif color_mode == 'FULL':
|
||||
output = color_full[inp].upper()
|
||||
output = "/".join([_color_full[input[i:i+2]] for i in range(0,len(input),2)])
|
||||
elif color_mode == 'hex':
|
||||
output = color_hex[inp].lower()
|
||||
elif color_mode == 'HEX':
|
||||
output = color_hex[inp].upper()
|
||||
output = get_color_hex(input)
|
||||
elif color_mode == 'ger':
|
||||
output = color_ger[inp].lower()
|
||||
elif color_mode == 'GER':
|
||||
output = color_ger[inp].upper()
|
||||
output = "".join([_color_ger[input[i:i+2]] for i in range(o,len(input),2)])
|
||||
elif color_mode == 'short':
|
||||
output = inp.lower()
|
||||
elif color_mode == 'SHORT':
|
||||
output = inp.upper()
|
||||
output = input
|
||||
else:
|
||||
raise Exception('Unknown color mode')
|
||||
return output
|
||||
if upper:
|
||||
return output.upper()
|
||||
else:
|
||||
return output.lower()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user