Skip to content

Commit

Permalink
Use unique index for connector pin ports
Browse files Browse the repository at this point in the history
Use unique numerical index instead of string (which might cause issues when using pin names that are not unique when ignoring upper/lower case).
  • Loading branch information
formatc1702 committed Mar 23, 2021
1 parent cf91977 commit 29b5e36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class Connector:
pincount: Optional[int] = None
image: Optional[Image] = None
notes: Optional[MultilineHypertext] = None
pinlabels: List[Pin] = field(default_factory=list)
pins: List[Pin] = field(default_factory=list)
pinlabels: List[Pin] = field(default_factory=list)
pincolors: List[Color] = field(default_factory=list)
color: Optional[Color] = None
show_name: Optional[bool] = None
Expand Down
17 changes: 10 additions & 7 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_wire:
raise Exception(f'{via_name}:{via_wire} is used for more than one wire.')
via_wire = cable.wirelabels.index(via_wire) + 1 # list index starts at 0, wire IDs start at 1

self.cables[via_name].connect(from_name, from_pin, via_wire, to_name, to_pin)
from_pin_new = self.connectors[from_name].pins.index(from_pin) if from_pin is not None else None
to_pin_new = self.connectors[to_name].pins.index(to_pin) if to_pin is not None else None

self.cables[via_name].connect(from_name, from_pin_new, via_wire, to_name, to_pin_new)
if from_name in self.connectors:
self.connectors[from_name].activate_pin(from_pin)
if to_name in self.connectors:
Expand Down Expand Up @@ -135,12 +138,12 @@ def create_graph(self) -> Graph:
pinhtml = []
pinhtml.append('<table border="0" cellspacing="0" cellpadding="3" cellborder="1">')

for pin, pinlabel, pincolor in zip_longest(connector.pins, connector.pinlabels, connector.pincolors):
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
for pinid, (pinname, pinlabel, pincolor) in enumerate(zip_longest(connector.pins, connector.pinlabels, connector.pincolors)):
if connector.hide_disconnected_pins and not connector.visible_pins.get(pinname, False):
continue
pinhtml.append(' <tr>')
if connector.ports_left:
pinhtml.append(f' <td port="p{pin}l">{pin}</td>')
pinhtml.append(f' <td port="p{pinid}l">{pinname}</td>')
if pinlabel:
pinhtml.append(f' <td>{pinlabel}</td>')
if connector.pincolors:
Expand All @@ -155,7 +158,7 @@ def create_graph(self) -> Graph:
pinhtml.append( ' <td colspan="2"></td>')

if connector.ports_right:
pinhtml.append(f' <td port="p{pin}r">{pin}</td>')
pinhtml.append(f' <td port="p{pinid}r">{pinname}</td>')
pinhtml.append(' </tr>')

pinhtml.append(' </table>')
Expand Down Expand Up @@ -305,7 +308,7 @@ def create_graph(self) -> Graph:
if from_connector.show_name:
from_info = [str(connection.from_name), str(connection.from_port)]
if from_connector.pinlabels:
pinlabel = from_connector.pinlabels[from_connector.pins.index(connection.from_port)]
pinlabel = from_connector.pinlabels[connection.from_port]
if pinlabel != '':
from_info.append(pinlabel)
from_string = ':'.join(from_info)
Expand All @@ -321,7 +324,7 @@ def create_graph(self) -> Graph:
if to_connector.show_name:
to_info = [str(connection.to_name), str(connection.to_port)]
if to_connector.pinlabels:
pinlabel = to_connector.pinlabels[to_connector.pins.index(connection.to_port)]
pinlabel = to_connector.pinlabels[connection.to_port]
if pinlabel != '':
to_info.append(pinlabel)
to_string = ':'.join(to_info)
Expand Down

0 comments on commit 29b5e36

Please sign in to comment.