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

add length_unit support for wire and cable lengths #171

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 4 additions & 0 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class Cable:
gauge_unit: Optional[str] = None
show_equiv: bool = False
length: float = 0
length_unit: Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
length_unit: Optional[str] = None
length_unit: str = 'm'

When any None value is always replaced with the same real default string value in __post_init__(), then there is no reason to have an optional type and None as default value - see why in my #156 (comment). The same effect is better obtained with the real default string value here in the declaration.

color: Optional[str] = None
wirecount: Optional[int] = None
shield: bool = False
Expand Down Expand Up @@ -119,6 +120,9 @@ def __post_init__(self):

self.connections = []

if self.length_unit is None: #Default wire length units to meters if left undeclared
self.length_unit = 'm'

Comment on lines +123 to +125
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.length_unit is None: #Default wire length units to meters if left undeclared
self.length_unit = 'm'

The same effect is better obtained with the real default string value in the declaration above.

if self.wirecount: # number of wires explicitly defined
if self.colors: # use custom color palette (partly or looped if needed)
pass
Expand Down
4 changes: 2 additions & 2 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def create_graph(self) -> Graph:
f'{cable.wirecount}x' if cable.show_wirecount else None,
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else None,
'+ S' if cable.shield else None,
f'{cable.length} m' if cable.length > 0 else None,
f'{cable.length} {cable.length_unit}' if cable.length > 0 else None,
cable.color, '<!-- colorbar -->' if cable.color else None],
'<!-- wire table -->',
[html_line_breaks(cable.notes)]]
Expand Down Expand Up @@ -365,7 +365,7 @@ def bom(self):
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}'
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
item = {'item': name, 'qty': round(total_length, 3), 'unit': shared.length_unit, 'designators': designators,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already commented this code change in my #161 (comment). Choice 2 is the easiest to implement by including c.length_unit in the tuple returned from the cable_group lambda just above this loop:

cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.length_unit, c.wirecount, c.shield, c.pn, c.manufacturer, c.mpn)

Then, remember to implement the same changes for bundle wires below as for cables here.

'manufacturer': remove_line_breaks(shared.manufacturer), 'mpn': remove_line_breaks(shared.mpn), 'pn': shared.pn}
bom_cables.append(item)
# bundles (ignores wirecount)
Expand Down