Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in mate processing #358

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 35 additions & 45 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,38 @@ def create_graph(self) -> Graph:
fillcolor=translate_color(bgcolor, "HEX"),
)

# mates
for mate in self.mates:
if mate.shape[-1] == ">":
dir = "both" if mate.shape[0] == "<" else "forward"
else:
dir = "back" if mate.shape[0] == "<" else "none"

if isinstance(mate, MatePin):
color = "#000000"
elif isinstance(mate, MateComponent):
color = "#000000:#000000"
else:
raise Exception(f"{mate} is an unknown mate")

from_connector = self.connectors[mate.from_name]
to_connector = self.connectors[mate.to_name]
if isinstance(mate, MatePin) and from_connector.style != "simple":
from_pin_index = from_connector.pins.index(mate.from_pin)
from_port_str = f":p{from_pin_index+1}r"
else: # MateComponent or style == 'simple'
from_port_str = ""
if isinstance(mate, MatePin) and to_connector.style != "simple":
to_pin_index = to_connector.pins.index(mate.to_pin)
to_port_str = f":p{to_pin_index+1}l"
else: # MateComponent or style == 'simple'
to_port_str = ""
code_from = f"{mate.from_name}{from_port_str}:e"
code_to = f"{mate.to_name}{to_port_str}:w"

dot.attr("edge", color=color, style="dashed", dir=dir)
dot.edge(code_from, code_to)

def typecheck(name: str, value: Any, expect: type) -> None:
if not isinstance(value, expect):
raise Exception(
Expand Down Expand Up @@ -595,51 +627,9 @@ def typecheck(name: str, value: Any, expect: type) -> None:
typecheck("tweak.append", self.tweak.append, str)
dot.body.append(self.tweak.append)

for mate in self.mates:
if mate.shape[0] == "<" and mate.shape[-1] == ">":
dir = "both"
elif mate.shape[0] == "<":
dir = "back"
elif mate.shape[-1] == ">":
dir = "forward"
else:
dir = "none"

if isinstance(mate, MatePin):
color = "#000000"
elif isinstance(mate, MateComponent):
color = "#000000:#000000"
else:
raise Exception(f"{mate} is an unknown mate")

from_connector = self.connectors[mate.from_name]
if (
isinstance(mate, MatePin)
and self.connectors[mate.from_name].style != "simple"
):
from_pin_index = from_connector.pins.index(mate.from_pin)
from_port_str = f":p{from_pin_index+1}r"
else: # MateComponent or style == 'simple'
from_port_str = ""
if (
isinstance(mate, MatePin)
and self.connectors[mate.to_name].style != "simple"
):
to_pin_index = to_connector.pins.index(mate.to_pin)
to_port_str = (
f":p{to_pin_index+1}l"
if isinstance(mate, MatePin)
and self.connectors[mate.to_name].style != "simple"
else ""
)
else: # MateComponent or style == 'simple'
to_port_str = ""
code_from = f"{mate.from_name}{from_port_str}:e"
to_connector = self.connectors[mate.to_name]
code_to = f"{mate.to_name}{to_port_str}:w"

dot.attr("edge", color=color, style="dashed", dir=dir)
dot.edge(code_from, code_to)
# Tweak processing above must be the last before returning dot.
# Please don't insert any code that might change the dot contents
# after tweak processing.

return dot

Expand Down
Loading