Merge branch 'dev' of github.com:slightlynybbled/WireViz into dev
This commit is contained in:
commit
8c33b9f954
18
CONTRIBUTING.md
Normal file
18
CONTRIBUTING.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Contribution Guidelines
|
||||||
|
|
||||||
|
When contributing to this repository, please first discuss the change you
|
||||||
|
wish to make via issue, email, or any other method with the owners of this
|
||||||
|
repository before making a change.
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
|
||||||
|
1. Fork this repository to your repository
|
||||||
|
1. Clone the repository to your local machine
|
||||||
|
1. Checkout the `dev` branch
|
||||||
|
1. Make any changes to the code on the `dev` branch
|
||||||
|
1. Push your changes to your fork
|
||||||
|
1. Create new pull request
|
||||||
|
|
||||||
|
## Documentation Strings
|
||||||
|
|
||||||
|
Documentation strings are to follow the Google Style ([examples](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html)).
|
||||||
@ -4,7 +4,7 @@
|
|||||||
from wireviz.DataClasses import Connector, Cable
|
from wireviz.DataClasses import Connector, Cable
|
||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
from wireviz import wv_colors
|
from wireviz import wv_colors
|
||||||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, \
|
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
|
||||||
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
|
nested_html_table, flatten2d, index_if_list, html_line_breaks, \
|
||||||
graphviz_line_breaks, remove_line_breaks
|
graphviz_line_breaks, remove_line_breaks
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
@ -86,13 +86,11 @@ class Harness:
|
|||||||
for key, connector in self.connectors.items():
|
for key, connector in self.connectors.items():
|
||||||
if connector.category == 'ferrule':
|
if connector.category == 'ferrule':
|
||||||
|
|
||||||
rows = [[html_line_breaks(connector.type), html_line_breaks(connector.subtype), connector.color, '<!-- colorbar -->' if connector.color else None],
|
rows = [[connector.manufacturer,
|
||||||
[connector.manufacturer,
|
|
||||||
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
|
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
|
||||||
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None],
|
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None],
|
||||||
|
[html_line_breaks(connector.type), html_line_breaks(connector.subtype), connector.color, '<!-- colorbar -->' if connector.color else None],
|
||||||
[html_line_breaks(connector.notes)]]
|
[html_line_breaks(connector.notes)]]
|
||||||
rows = [list(filter(None, row)) for row in rows] # remove missing attributes
|
|
||||||
|
|
||||||
html = nested_html_table(rows)
|
html = nested_html_table(rows)
|
||||||
|
|
||||||
if connector.color: # add color bar next to color info, if present
|
if connector.color: # add color bar next to color info, if present
|
||||||
@ -102,24 +100,37 @@ class Harness:
|
|||||||
dot.node(key, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white')
|
dot.node(key, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white')
|
||||||
|
|
||||||
else: # not a ferrule
|
else: # not a ferrule
|
||||||
identification = [connector.manufacturer,
|
|
||||||
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else '',
|
|
||||||
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else '']
|
|
||||||
|
|
||||||
attributes = [graphviz_line_breaks(connector.type),
|
rows = [[connector.name if connector.show_name else None],
|
||||||
graphviz_line_breaks(connector.subtype),
|
[connector.manufacturer,
|
||||||
f'{connector.pincount}-pin' if connector.show_pincount else'']
|
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
|
||||||
pinouts = [[], [], []]
|
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None],
|
||||||
|
[html_line_breaks(connector.type),
|
||||||
|
html_line_breaks(connector.subtype),
|
||||||
|
f'{connector.pincount}-pin' if connector.show_pincount else None],
|
||||||
|
'<!-- connector table -->',
|
||||||
|
[html_line_breaks(connector.notes)]]
|
||||||
|
html = nested_html_table(rows)
|
||||||
|
|
||||||
|
pinouts = []
|
||||||
for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout):
|
for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout):
|
||||||
if connector.hide_disconnected_pins and not connector.visible_pins.get(pinnumber, False):
|
if connector.hide_disconnected_pins and not connector.visible_pins.get(pinnumber, False):
|
||||||
continue
|
continue
|
||||||
pinouts[1].append(pinname)
|
pinouts.append([f'<td port="p{pinnumber}l">{pinnumber}</td>' if connector.ports_left else None,
|
||||||
if connector.ports_left:
|
f'<td>{pinname}</td>' if pinname else '',
|
||||||
pinouts[0].append(f'<p{pinnumber}l>{pinnumber}')
|
f'<td port="p{pinnumber}r">{pinnumber}</td>' if connector.ports_right else None])
|
||||||
if connector.ports_right:
|
|
||||||
pinouts[2].append(f'<p{pinnumber}r>{pinnumber}')
|
pinhtml = '<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
|
||||||
label = [connector.name if connector.show_name else '', identification, attributes, pinouts, graphviz_line_breaks(connector.notes)]
|
for i, pin in enumerate(pinouts):
|
||||||
dot.node(key, label=nested(label))
|
pinhtml = f'{pinhtml}<tr>'
|
||||||
|
for column in pin:
|
||||||
|
if column is not None:
|
||||||
|
pinhtml = f'{pinhtml}{column}'
|
||||||
|
pinhtml = f'{pinhtml}</tr>'
|
||||||
|
pinhtml = f'{pinhtml}</table>'
|
||||||
|
html = html.replace('<!-- connector table -->', pinhtml)
|
||||||
|
|
||||||
|
dot.node(key, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white')
|
||||||
|
|
||||||
if len(connector.loops) > 0:
|
if len(connector.loops) > 0:
|
||||||
dot.attr('edge', color='#000000:#ffffff:#000000')
|
dot.attr('edge', color='#000000:#ffffff:#000000')
|
||||||
|
|||||||
@ -30,31 +30,21 @@ def awg_equiv(mm2):
|
|||||||
def mm2_equiv(awg):
|
def mm2_equiv(awg):
|
||||||
return mm2_equiv_table.get(str(awg), 'Unknown')
|
return mm2_equiv_table.get(str(awg), 'Unknown')
|
||||||
|
|
||||||
def nested(inp):
|
|
||||||
l = []
|
|
||||||
for x in inp:
|
|
||||||
if isinstance(x, list):
|
|
||||||
if len(x) > 0:
|
|
||||||
n = nested(x)
|
|
||||||
if n != '':
|
|
||||||
l.append('{' + n + '}')
|
|
||||||
else:
|
|
||||||
if x is not None:
|
|
||||||
if x != '':
|
|
||||||
l.append(str(x))
|
|
||||||
return '|'.join(l)
|
|
||||||
|
|
||||||
def nested_html_table(rows):
|
def nested_html_table(rows):
|
||||||
# input: list of lists
|
# input: list, each item may be scalar or list
|
||||||
# output: a parent table with one child table per parent list item
|
# output: a parent table with one child table per parent item that is list, and one cell per parent item that is scalar
|
||||||
# purpose: create the appearance of one table, where cell widths are independent between rows
|
# purpose: create the appearance of one table, where cell widths are independent between rows
|
||||||
html = '<table border="0" cellspacing="0" cellpadding="0">'
|
html = '<table border="0" cellspacing="0" cellpadding="0">'
|
||||||
for row in rows:
|
for row in rows:
|
||||||
if len(row) > 0:
|
if isinstance(row, List):
|
||||||
html = f'{html}<tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>'
|
if len(row) > 0 and any(row):
|
||||||
for cell in row:
|
html = f'{html}<tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>'
|
||||||
html = f'{html}<td balign="left">{cell}</td>'
|
for cell in row:
|
||||||
html = f'{html}</tr></table></td></tr>'
|
if cell is not None:
|
||||||
|
html = f'{html}<td balign="left">{cell}</td>'
|
||||||
|
html = f'{html}</tr></table></td></tr>'
|
||||||
|
elif row is not None:
|
||||||
|
html = f'{html}<tr><td>{row}</td></tr>'
|
||||||
html = f'{html}</table>'
|
html = f'{html}</table>'
|
||||||
return html
|
return html
|
||||||
|
|
||||||
@ -117,7 +107,7 @@ def html_line_breaks(inp):
|
|||||||
return inp.replace('\n', '<br />') if isinstance(inp, str) else inp
|
return inp.replace('\n', '<br />') if isinstance(inp, str) else inp
|
||||||
|
|
||||||
def graphviz_line_breaks(inp):
|
def graphviz_line_breaks(inp):
|
||||||
return inp.replace('\n', '\\l') if isinstance(inp, str) else inp # \l generates left-aligned new lines. http://www.graphviz.org/doc/info/attrs.html#k:escString
|
return inp.replace('\n', '\\n') if isinstance(inp, str) else inp # \n generates centered new lines. http://www.graphviz.org/doc/info/attrs.html#k:escString
|
||||||
|
|
||||||
def remove_line_breaks(inp):
|
def remove_line_breaks(inp):
|
||||||
return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp
|
return inp.replace('\n', ' ').rstrip() if isinstance(inp, str) else inp
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user