Skip to content

Commit

Permalink
Rename connector attributes (#77)
Browse files Browse the repository at this point in the history
Rename `pinnumbers` to `pins`.
Rename `pinout` to `pinlabels`.
  • Loading branch information
formatc1702 committed Jul 19, 2020
1 parent 071c776 commit d63308b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
34 changes: 17 additions & 17 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Connector:
subtype: Optional[str] = None
pincount: Optional[int] = None
notes: Optional[str] = None
pinout: List[Any] = field(default_factory=list)
pinnumbers: List[Any] = field(default_factory=list)
pinlabels: List[Any] = field(default_factory=list)
pins: List[Any] = field(default_factory=list)
color: Optional[str] = None
show_name: bool = None
show_pincount: bool = None
Expand All @@ -39,25 +39,25 @@ def __post_init__(self):
self.pincount = 1

if self.pincount is None:
if self.pinout:
self.pincount = len(self.pinout)
elif self.pinnumbers:
self.pincount = len(self.pinnumbers)
if self.pinlabels:
self.pincount = len(self.pinlabels)
elif self.pins:
self.pincount = len(self.pins)
else:
raise Exception('You need to specify at least one, pincount, pinout or pinnumbers')
raise Exception('You need to specify at least one, pincount, pins or pinlabels')

if self.pinout and self.pinnumbers:
if len(self.pinout) != len(self.pinnumbers):
raise Exception('Given pinout and pinnumbers size mismatch')
if self.pinlabels and self.pins:
if len(self.pinlabels) != len(self.pins):
raise Exception('Given pins and pinlabels size mismatch')

# create default lists for pinnumbers (sequential) and pinouts (blank) if not specified
if not self.pinnumbers:
self.pinnumbers = list(range(1, self.pincount + 1))
if not self.pinout:
self.pinout = [''] * self.pincount
# create default lists for pins (sequential) and pinlabels (blank) if not specified
if not self.pins:
self.pins = list(range(1, self.pincount + 1))
if not self.pinlabels:
self.pinlabels = [''] * self.pincount

if len(self.pinnumbers) != len(set(self.pinnumbers)):
raise Exception('Pin numbers are not unique')
if len(self.pins) != len(set(self.pins)):
raise Exception('Pins are not unique')

if self.show_name is None:
if self.autogenerate:
Expand Down
30 changes: 15 additions & 15 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_pin:
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors
if name is not None and name in self.connectors:
connector = self.connectors[name]
if pin in connector.pinnumbers and pin in connector.pinout:
if connector.pinnumbers.index(pin) == connector.pinout.index(pin):
if pin in connector.pins and pin in connector.pinlabels:
if connector.pins.index(pin) == connector.pinlabels.index(pin):
# TODO: Maybe issue a warning? It's not worthy of an exception if it's unambiguous, but maybe risky?
pass
else:
raise Exception(f'{name}:{pin} is defined both in pinout and pinnumbers, for different pins.')
if pin in connector.pinout:
if connector.pinout.count(pin) > 1:
raise Exception(f'{name}:{pin} is defined both in pinlabels and pins, for different pins.')
if pin in connector.pinlabels:
if connector.pinlabels.count(pin) > 1:
raise Exception(f'{name}:{pin} is defined more than once.')
else:
index = connector.pinout.index(pin)
pin = connector.pinnumbers[index] # map pin name to pin number
index = connector.pinlabels.index(pin)
pin = connector.pins[index] # map pin name to pin number
if name == from_name:
from_pin = pin
if name == to_name:
to_pin = pin
if not pin in connector.pinnumbers:
if not pin in connector.pins:
raise Exception(f'{name}:{pin} not found.')

self.cables[via_name].connect(from_name, from_pin, via_pin, to_name, to_pin)
Expand Down Expand Up @@ -104,16 +104,16 @@ def create_graph(self) -> Graph:
html = html.replace('><!-- colorbar --></td>', colorbar)

if connector.style != 'simple':
pinouts = []
for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout):
if connector.hide_disconnected_pins and not connector.visible_pins.get(pinnumber, False):
pinlist = []
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
continue
pinouts.append([f'<td port="p{pinnumber}l">{pinnumber}</td>' if connector.ports_left else None,
f'<td>{pinname}</td>' if pinname else '',
f'<td port="p{pinnumber}r">{pinnumber}</td>' if connector.ports_right else None])
pinlist.append([f'<td port="p{pin}l">{pin}</td>' if connector.ports_left else None,
f'<td>{pinlabel}</td>' if pinlabel else '',
f'<td port="p{pin}r">{pin}</td>' if connector.ports_right else None])

pinhtml = '<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
for i, pin in enumerate(pinouts):
for i, pin in enumerate(pinlist):
pinhtml = f'{pinhtml}<tr>'
for column in pin:
if column is not None:
Expand Down

0 comments on commit d63308b

Please sign in to comment.