-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add support for line breaks in certain fields #64
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4ac4da
Implement line break parsing for some fields
formatc1702 46ed241
Remove any newlines in fields for BOM generation
formatc1702 c2fa1d0
Merge changes to ferrule code generation
formatc1702 501303c
Implement line break parsing for ferrules
formatc1702 0252476
Fix bug in bundle wire BOM generation
formatc1702 e1e6655
Outsource nested HTML table creation to helper function
formatc1702 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ ferrules: | |
ferrule_crimp: | ||
type: Crimp ferrule | ||
subtype: 0.25 mm² | ||
color: YE | ||
|
||
connectors: | ||
X1: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from wireviz.DataClasses import Connector, Cable | ||
from graphviz import Graph | ||
from wireviz import wv_colors | ||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, flatten2d, index_if_list | ||
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, nested, nested_html_table, flatten2d, index_if_list, html_line_breaks, graphviz_line_breaks, remove_line_breaks | ||
from collections import Counter | ||
from typing import List | ||
|
||
|
@@ -60,24 +60,18 @@ def create_graph(self): | |
for key, connector in self.connectors.items(): | ||
if connector.category == 'ferrule': | ||
|
||
rows = [[connector.type, connector.subtype, connector.color, '<!-- colorbar -->' if connector.color else None], | ||
rows = [[html_line_breaks(connector.type), html_line_breaks(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]] | ||
f'IPN: {connector.internal_part_number}' if connector.internal_part_number else None], | ||
[html_line_breaks(connector.notes)]] | ||
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>' | ||
html = nested_html_table(rows) | ||
|
||
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) | ||
colorbar = f' bgcolor="{wv_colors.translate_color(connector.color, "HEX")}" width="4"></td>' # leave out '<td' from string to preserve any existing attributes of the <td> tag | ||
html = html.replace('><!-- colorbar --></td>', colorbar) | ||
|
||
dot.node(key, label=f'<{html}>', shape='none', margin='0', style='filled', fillcolor='white') | ||
|
||
|
@@ -86,8 +80,8 @@ def create_graph(self): | |
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 = [connector.type, | ||
connector.subtype, | ||
attributes = [graphviz_line_breaks(connector.type), | ||
graphviz_line_breaks(connector.subtype), | ||
f'{connector.pincount}-pin' if connector.show_pincount else''] | ||
pinouts = [[], [], []] | ||
for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout): | ||
|
@@ -98,7 +92,7 @@ def create_graph(self): | |
pinouts[0].append(f'<p{pinnumber}l>{pinnumber}') | ||
if connector.ports_right: | ||
pinouts[2].append(f'<p{pinnumber}r>{pinnumber}') | ||
label = [connector.name if connector.show_name else '', identification, attributes, pinouts, connector.notes] | ||
label = [connector.name if connector.show_name else '', identification, attributes, pinouts, graphviz_line_breaks(connector.notes)] | ||
dot.node(key, label=nested(label)) | ||
|
||
if len(connector.loops) > 0: | ||
|
@@ -132,7 +126,7 @@ def create_graph(self): | |
f'IPN: {cable.internal_part_number}' if (cable.internal_part_number and not isinstance(cable.internal_part_number, list)) else ''] | ||
identification = list(filter(None, identification)) | ||
|
||
attributes = [f'{cable.type}' if cable.type else '', | ||
attributes = [html_line_breaks(cable.type) if cable.type else '', | ||
f'{len(cable.colors)}x' if cable.show_wirecount else '', | ||
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '', | ||
'+ S' if cable.shield else '', | ||
|
@@ -153,7 +147,7 @@ def create_graph(self): | |
html = f'{html}</tr></table></td></tr>' # end identification row | ||
html = f'{html}<tr>' # attribute row | ||
for attrib in attributes: | ||
html = f'{html}<td>{attrib}</td>' | ||
html = f'{html}<td balign="left">{attrib}</td>' | ||
html = f'{html}</tr>' # attribute row | ||
html = f'{html}</table></td></tr>' # name+attributes table | ||
|
||
|
@@ -204,7 +198,7 @@ def create_graph(self): | |
|
||
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 cellpadding="3" balign="left">{html_line_breaks(cable.notes)}</td></tr>' # notes table | ||
html = f'{html}<tr><td> </td></tr>' # spacer at the end | ||
|
||
html = f'{html}</table>' # main table | ||
|
@@ -308,8 +302,8 @@ def bom(self): | |
shared = next(iter(items.values())) | ||
designators = list(items.keys()) | ||
designators.sort() | ||
conn_type = f', {shared.type}' if shared.type else '' | ||
conn_subtype = f', {shared.subtype}' if shared.subtype else '' | ||
conn_type = f', {remove_line_breaks(shared.type)}' if shared.type else '' | ||
conn_subtype = f', {remove_line_breaks(shared.subtype)}' if shared.subtype else '' | ||
conn_pincount = f', {shared.pincount} pins' if shared.category != 'ferrule' else '' | ||
conn_color = f', {shared.color}' if shared.color else '' | ||
name = f'Connector{conn_type}{conn_subtype}{conn_pincount}{conn_color}' | ||
|
@@ -328,7 +322,7 @@ def bom(self): | |
designators = list(items.keys()) | ||
designators.sort() | ||
total_length = sum(i.length for i in items.values()) | ||
cable_type = f', {shared.type}' if shared.type else '' | ||
cable_type = f', {remove_line_breaks(shared.type)}' if shared.type else '' | ||
gauge_name = f' x {shared.gauge} {shared.gauge_unit}' if shared.gauge else ' wires' | ||
shield_name = ' shielded' if shared.shield else '' | ||
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}' | ||
|
@@ -342,7 +336,7 @@ def bom(self): | |
if bundle.category == 'bundle': | ||
# add each wire from each bundle to the wirelist | ||
for index, color in enumerate(bundle.colors, 0): | ||
wirelist.append({'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name, | ||
wirelist.append({'type': bundle.type, 'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name, | ||
'manufacturer': index_if_list(bundle.manufacturer, index), | ||
'manufacturer part number': index_if_list(bundle.manufacturer_part_number, index), | ||
'internal part number': index_if_list(bundle.internal_part_number, index)}) | ||
|
@@ -355,8 +349,8 @@ def bom(self): | |
designators = list(dict.fromkeys(designators)) # remove duplicates | ||
designators.sort() | ||
total_length = sum(i['length'] for i in items) | ||
wire_type = f', {shared["type"]}' if 'type' in shared else '' | ||
gauge_name = f', {shared["gauge"]} {shared["gauge_unit"]}' if 'gauge' in shared else '' | ||
wire_type = f', {remove_line_breaks(shared["type"])}' if shared.get('type', None) else '' | ||
gauge_name = f', {shared["gauge"]} {shared["gauge_unit"]}' if shared.get('gauge', None) else '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new syntax catches both missing keys and keys with |
||
gauge_color = f', {shared["color"]}' if 'color' in shared != '' else '' | ||
name = f'Wire{wire_type}{gauge_name}{gauge_color}' | ||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were ignoring the type for bundles. In general, I see no reason to.