Skip to content

Commit

Permalink
Simplify connector loop code
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Jul 11, 2020
1 parent cf6d367 commit 9e11051
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class Connector:
show_pincount: bool = True
hide_disconnected_pins: bool = False
autogenerate: bool = False
loops: List[Any] = field(default_factory=list)

def __post_init__(self):
self.ports_left = False
self.ports_right = False
self.loops = []
self.visible_pins = {}

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

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

def activate_pin(self, pin):
self.visible_pins[pin] = True
Expand Down
4 changes: 0 additions & 4 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ def add_connector(self, name, *args, **kwargs):
def add_cable(self, name, *args, **kwargs):
self.cables[name] = Cable(name, *args, **kwargs)

def loop(self, connector_name, from_pin, to_pin):
self.connectors[connector_name].loop(from_pin, to_pin)

def connect(self, from_name, from_pin, via_name, via_pin, to_name, to_pin):

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

Expand Down

0 comments on commit 9e11051

Please sign in to comment.