Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ferrule output code generation, make more flexible #65

Merged
merged 2 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/demo02.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ferrules:
ferrule_crimp:
type: Crimp ferrule
subtype: 0.25 mm²
color: YE

connectors:
X1:
Expand Down
53 changes: 20 additions & 33 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,27 @@ def create_graph(self):

for key, connector in self.connectors.items():
if connector.category == 'ferrule':
subtype = f', {connector.subtype}' if connector.subtype else ''
color = wv_colors.translate_color(connector.color, self.color_mode) if connector.color else ''
infostring = f'{connector.type}{subtype} {color}'

# id = identification
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 '']
identification = list(filter(None, identification))
if(len(identification) > 0):
infostring = f'{infostring}<br/>'
for attrib in identification:
infostring = f'{infostring}{attrib}, '
infostring = infostring[:-2] # remove trainling comma and space

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',
margin='0',
orientation='0' if connector.ports_left else '180',
label='''<

<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0" CELLPADDING="2"><TR>
<TD PORT="p1l"> {infostring_l} </TD>
{colorbar}
<TD PORT="p1r"> {infostring_r} </TD>
</TR></TABLE>


>'''.format(infostring_l=infostring_l, infostring_r=infostring_r, colorbar=colorbar))
rows = [[connector.type, connector.subtype, connector.color, '<!-- colorbar -->' if connector.color else None],
[connector.manufacturer,
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]]
rows = [list(filter(None, row)) for row in rows] # remove missing attributes

html = '<table border="0" cellspacing="0" cellpadding="0">'
for row in rows:
if len(row) > 0:
html = f'{html}<tr><td><table border="0" cellspacing="0" cellpadding="3" cellborder="1"><tr>'
for cell in row:
html = f'{html}<td>{cell}</td>'
html = f'{html}</tr></table></td></tr>'
html = f'{html}</table>'

if connector.color: # add color bar next to color info, if present
colorbar = f'<td bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4"></td>'
html = html.replace('<td><!-- colorbar --></td>', colorbar)

dot.node(key, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white')

else: # not a ferrule
identification = [connector.manufacturer,
Expand Down
2 changes: 1 addition & 1 deletion tutorial/tutorial06.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ connectors:
subtype: female
F_10_1: # manually define a ferrule (with unique designator)
category: ferrule
type: Ferrule, crimp
type: Crimp ferrule
subtype: 1.0 mm²
color: YE

Expand Down