Skip to content

Commit 9e11051

Browse files
committed
Simplify connector loop code
1 parent cf6d367 commit 9e11051

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/wireviz/DataClasses.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class Connector:
2525
show_pincount: bool = True
2626
hide_disconnected_pins: bool = False
2727
autogenerate: bool = False
28+
loops: List[Any] = field(default_factory=list)
2829

2930
def __post_init__(self):
3031
self.ports_left = False
3132
self.ports_right = False
32-
self.loops = []
3333
self.visible_pins = {}
3434

3535
if self.pincount is None:
@@ -55,11 +55,12 @@ def __post_init__(self):
5555
if len(self.pinnumbers) != len(set(self.pinnumbers)):
5656
raise Exception('Pin numbers are not unique')
5757

58-
def loop(self, from_pin, to_pin):
59-
self.loops.append((from_pin, to_pin))
60-
if self.hide_disconnected_pins:
61-
self.visible_pins[from_pin] = True
62-
self.visible_pins[to_pin] = True
58+
for loop in self.loops:
59+
# TODO: check that pins to connect actually exist
60+
# TODO: allow using pin labels in addition to pin numbers, just like when defining regular connections
61+
# TODO: include properties of wire used to create the loop
62+
if len(loop) != 2:
63+
raise Exception('Loops must be between exactly two pins!')
6364

6465
def activate_pin(self, pin):
6566
self.visible_pins[pin] = True

src/wireviz/Harness.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ def add_connector(self, name, *args, **kwargs):
2222
def add_cable(self, name, *args, **kwargs):
2323
self.cables[name] = Cable(name, *args, **kwargs)
2424

25-
def loop(self, connector_name, from_pin, to_pin):
26-
self.connectors[connector_name].loop(from_pin, to_pin)
27-
2825
def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin):
2926

3027
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors
@@ -46,7 +43,6 @@ def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin):
4643
from_pin = pin
4744
if name == to_name:
4845
to_pin = pin
49-
# TODO: what happens with loops?
5046
if not pin in connector.pinnumbers:
5147
raise Exception(f'{name}:{pin} not found.')
5248

0 commit comments

Comments
 (0)