diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index f3bb3430..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 @@ -95,8 +96,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 @@ -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] diff --git a/src/wireviz/Harness.py b/src/wireviz/Harness.py index 5a8c1728..29f5556b 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('
{pin} | ') + pinhtml.append(f'{pinname} | ') if pinlabel: pinhtml.append(f'{pinlabel} | ') if connector.pincolors: @@ -155,7 +158,7 @@ def create_graph(self) -> Graph: pinhtml.append( '') if connector.ports_right: - pinhtml.append(f' | {pin} | ') + pinhtml.append(f'{pinname} | ') pinhtml.append('