From 1127bcb142b61fc94535c8c2a39e07286964c0f0 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 23 Mar 2021 22:49:42 +0100 Subject: [PATCH 1/6] Use unique index for connector pin ports Use unique numerical index instead of string (which might cause issues when using pin names that are not unique when ignoring upper/lower case). --- src/wireviz/DataClasses.py | 2 +- src/wireviz/Harness.py | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index f3bb3430..31cbce00 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -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 diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 5a8c1728..14a48ad8 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -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_id = self.connectors[from_name].pins.index(from_pin) if from_pin is not None else None + to_pin_id = 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_id, via_wire, to_name, to_pin_id) if from_name in self.connectors: self.connectors[from_name].activate_pin(from_pin) if to_name in self.connectors: @@ -135,12 +138,12 @@ def create_graph(self) -> Graph: pinhtml = [] pinhtml.append('') - 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(' ') if connector.ports_left: - pinhtml.append(f' ') + pinhtml.append(f' ') if pinlabel: pinhtml.append(f' ') if connector.pincolors: @@ -155,7 +158,7 @@ def create_graph(self) -> Graph: pinhtml.append( ' ') if connector.ports_right: - pinhtml.append(f' ') + pinhtml.append(f' ') pinhtml.append(' ') pinhtml.append('
{pin}{pinname}{pinlabel}{pin}{pinname}
') @@ -303,9 +306,9 @@ def create_graph(self) -> Graph: code_left_2 = f'{cable.name}:w{connection.via_port}:w' dot.edge(code_left_1, code_left_2) if from_connector.show_name: - from_info = [str(connection.from_name), str(connection.from_port)] + from_info = [str(connection.from_name), str(self.connectors[connection.from_name].pins[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) @@ -319,9 +322,9 @@ def create_graph(self) -> Graph: code_right_2 = f'{connection.to_name}{to_port}:w' dot.edge(code_right_1, code_right_2) if to_connector.show_name: - to_info = [str(connection.to_name), str(connection.to_port)] + to_info = [str(connection.to_name), str(self.connectors[connection.to_name].pins[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) From 7e2339e74cd686b011875aa9b860e61e959753d9 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 22 Aug 2021 19:01:20 +0200 Subject: [PATCH 2/6] Make internal pin IDs start from 1 instead of 0 so that in the standard case, internal pin IDs match the actual connector's pin numbers, which usually start from 1. Co-authored-by: kvid --- src/wireviz/Harness.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 14a48ad8..69bc9a9c 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -143,7 +143,7 @@ def create_graph(self) -> Graph: continue pinhtml.append(' ') if connector.ports_left: - pinhtml.append(f' {pinname}') + pinhtml.append(f' {pinname}') if pinlabel: pinhtml.append(f' {pinlabel}') if connector.pincolors: @@ -158,7 +158,7 @@ def create_graph(self) -> Graph: pinhtml.append( ' ') if connector.ports_right: - pinhtml.append(f' {pinname}') + pinhtml.append(f' {pinname}') pinhtml.append(' ') pinhtml.append(' ') @@ -301,7 +301,7 @@ def create_graph(self) -> Graph: dot.attr('edge', color=':'.join(['#000000', shield_color_hex, '#000000']) if isinstance(cable.shield, str) else '#000000') if connection.from_port is not None: # connect to left from_connector = self.connectors[connection.from_name] - from_port = f':p{connection.from_port}r' if from_connector.style != 'simple' else '' + from_port = f':p{connection.from_port+1}r' if from_connector.style != 'simple' else '' code_left_1 = f'{connection.from_name}{from_port}:e' code_left_2 = f'{cable.name}:w{connection.via_port}:w' dot.edge(code_left_1, code_left_2) @@ -318,7 +318,7 @@ def create_graph(self) -> Graph: if connection.to_port is not None: # connect to right to_connector = self.connectors[connection.to_name] code_right_1 = f'{cable.name}:w{connection.via_port}:e' - to_port = f':p{connection.to_port}l' if self.connectors[connection.to_name].style != 'simple' else '' + to_port = f':p{connection.to_port+1}l' if self.connectors[connection.to_name].style != 'simple' else '' code_right_2 = f'{connection.to_name}{to_port}:w' dot.edge(code_right_1, code_right_2) if to_connector.show_name: From 4fef57b38d292ebb27f7917f2b3871aa73295e1f Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 22 Aug 2021 19:02:45 +0200 Subject: [PATCH 3/6] Rename `pinid` to `pinindex` as suggested by @kvid. Co-authored-by: kvid --- src/wireviz/Harness.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 69bc9a9c..29f5556b 100644 --- a/src/wireviz/Harness.py +++ b/src/wireviz/Harness.py @@ -138,12 +138,12 @@ def create_graph(self) -> Graph: pinhtml = [] pinhtml.append('') - for pinid, (pinname, pinlabel, pincolor) in enumerate(zip_longest(connector.pins, connector.pinlabels, connector.pincolors)): + for pinindex, (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(' ') if connector.ports_left: - pinhtml.append(f' ') + pinhtml.append(f' ') if pinlabel: pinhtml.append(f' ') if connector.pincolors: @@ -158,7 +158,7 @@ def create_graph(self) -> Graph: pinhtml.append( ' ') if connector.ports_right: - pinhtml.append(f' ') + pinhtml.append(f' ') pinhtml.append(' ') pinhtml.append('
{pinname}{pinname}{pinlabel}{pinname}{pinname}
') From b06ae96df3a4d6374bee3c3c74413d1d063e2218 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 22 Aug 2021 19:08:11 +0200 Subject: [PATCH 4/6] Update type hints as suggested by @kvid. Co-authored-by: kvid --- src/wireviz/DataClasses.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index 31cbce00..87dc93ba 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -25,8 +25,9 @@ # Type combinations Colors = PlainText # One or more two-letter color names (Color) concatenated into one string Pin = Union[int, PlainText] # Pin identifier +PinIndex = int # Zero-based pin index Wire = Union[int, PlainText] # Wire number or Literal['s'] for shield -NoneOrMorePins = Union[Pin, Tuple[Pin, ...], None] # None, one, or a tuple of pins +NoneOrMorePinIndices = Union[PinIndex, Tuple[PinIndex, ...], None] # None, one, or a tuple of zero-based pin indices OneOrMoreWires = Union[Wire, Tuple[Wire, ...]] # One or a tuple of wires @@ -277,8 +278,8 @@ def __post_init__(self) -> None: self.additional_components[i] = AdditionalComponent(**item) # The *_pin arguments accept a tuple, but it seems not in use with the current code. - def connect(self, from_name: Optional[Designator], from_pin: NoneOrMorePins, via_wire: OneOrMoreWires, - to_name: Optional[Designator], to_pin: NoneOrMorePins) -> None: + def connect(self, from_name: Optional[Designator], from_pin: NoneOrMorePinIndices, via_wire: OneOrMoreWires, + to_name: Optional[Designator], to_pin: NoneOrMorePinIndices) -> None: from_pin = int2tuple(from_pin) via_wire = int2tuple(via_wire) to_pin = int2tuple(to_pin) @@ -305,7 +306,7 @@ def get_qty_multiplier(self, qty_multiplier: Optional[CableMultiplier]) -> float @dataclass class Connection: from_name: Optional[Designator] - from_port: Optional[Pin] + from_port: Optional[PinIndex] via_port: Wire to_name: Optional[Designator] - to_port: Optional[Pin] + to_port: Optional[PinIndex] From afd4147a7665da2af7f31600b3835d4cc4635d8f Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Sun, 22 Aug 2021 19:46:35 +0200 Subject: [PATCH 5/6] Update changelog --- docs/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2231db45..3d303876 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,7 @@ ## Misc. fixes +- Remove case-sensitivity issues with pin names and labels. ([#160](https://github.com/formatc1702/WireViz/issues/160), [#229](https://github.com/formatc1702/WireViz/pull/229)) - Improve type hinting ([#156](https://github.com/formatc1702/WireViz/issues/156), [#163](https://github.com/formatc1702/WireViz/pull/163)) - Move BOM management and HTML functions to separate modules ([#151](https://github.com/formatc1702/WireViz/issues/151), [#192](https://github.com/formatc1702/WireViz/pull/192)) - Bug fixes ([#218](https://github.com/formatc1702/WireViz/pull/218), [#221](https://github.com/formatc1702/WireViz/pull/221)) From ef289f59bfacef04adafa006baa35899f465c6d9 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Mon, 23 Aug 2021 19:23:40 +0200 Subject: [PATCH 6/6] Revert "Update changelog" The change will instead be logged in the `doc/changelog` branch --- docs/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3d303876..2231db45 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,7 +13,6 @@ ## Misc. fixes -- Remove case-sensitivity issues with pin names and labels. ([#160](https://github.com/formatc1702/WireViz/issues/160), [#229](https://github.com/formatc1702/WireViz/pull/229)) - Improve type hinting ([#156](https://github.com/formatc1702/WireViz/issues/156), [#163](https://github.com/formatc1702/WireViz/pull/163)) - Move BOM management and HTML functions to separate modules ([#151](https://github.com/formatc1702/WireViz/issues/151), [#192](https://github.com/formatc1702/WireViz/pull/192)) - Bug fixes ([#218](https://github.com/formatc1702/WireViz/pull/218), [#221](https://github.com/formatc1702/WireViz/pull/221))