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

Detect and assign unit within cable length attribute #198

Merged
merged 4 commits into from
Dec 13, 2020
Merged
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
22 changes: 18 additions & 4 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ def __post_init__(self) -> None:
try:
g, u = self.gauge.split(' ')
except Exception:
raise Exception('Gauge must be a number, or number and unit separated by a space')
raise Exception(f'Cable {self.name} gauge={self.gauge} - Gauge must be a number, or number and unit separated by a space')
self.gauge = g

formatc1702 marked this conversation as resolved.
Show resolved Hide resolved
if self.gauge_unit is not None:
print(f'Warning: Cable {self.name} gauge_unit={self.gauge_unit} is ignored because its gauge contains {u}')
if u.upper() == 'AWG':
self.gauge_unit = u.upper()
else:
Expand All @@ -214,11 +216,23 @@ def __post_init__(self) -> None:
else:
pass # gauge not specified

self.connections = []

if self.length_unit is None: #Default wire length units to meters if left undeclared
if isinstance(self.length, str): # length and unit specified
try:
L, u = self.length.split(' ')
L = float(L)
except Exception:
raise Exception(f'Cable {self.name} length={self.length} - Length must be a number, or number and unit separated by a space')
self.length = L
if self.length_unit is not None:
print(f'Warning: Cable {self.name} length_unit={self.length_unit} is ignored because its length contains {u}')
self.length_unit = u
elif not any(isinstance(self.length, t) for t in [int, float]):
raise Exception(f'Cable {self.name} length has a non-numeric value')
elif self.gauge_unit is None:
self.length_unit = 'm'

self.connections = []

if self.wirecount: # number of wires explicitly defined
if self.colors: # use custom color palette (partly or looped if needed)
pass
Expand Down