Skip to content

Commit 7be35a4

Browse files
committed
Move mates processing above tweak processing (#358)
Bug: Not all generated dot output could be changed by tweak entries. Observed in #325 (comment) Tweak processing must be the very last dot producing code to enable tweaking any dot output. Fix: Move all other dot producing code above Tweak processing.
1 parent 8cc2481 commit 7be35a4

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/wireviz/Harness.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,38 @@ def create_graph(self) -> Graph:
530530
fillcolor=translate_color(bgcolor, "HEX"),
531531
)
532532

533+
# mates
534+
for mate in self.mates:
535+
if mate.shape[-1] == ">":
536+
dir = "both" if mate.shape[0] == "<" else "forward"
537+
else:
538+
dir = "back" if mate.shape[0] == "<" else "none"
539+
540+
if isinstance(mate, MatePin):
541+
color = "#000000"
542+
elif isinstance(mate, MateComponent):
543+
color = "#000000:#000000"
544+
else:
545+
raise Exception(f"{mate} is an unknown mate")
546+
547+
from_connector = self.connectors[mate.from_name]
548+
to_connector = self.connectors[mate.to_name]
549+
if isinstance(mate, MatePin) and from_connector.style != "simple":
550+
from_pin_index = from_connector.pins.index(mate.from_pin)
551+
from_port_str = f":p{from_pin_index+1}r"
552+
else: # MateComponent or style == 'simple'
553+
from_port_str = ""
554+
if isinstance(mate, MatePin) and to_connector.style != "simple":
555+
to_pin_index = to_connector.pins.index(mate.to_pin)
556+
to_port_str = f":p{to_pin_index+1}l"
557+
else: # MateComponent or style == 'simple'
558+
to_port_str = ""
559+
code_from = f"{mate.from_name}{from_port_str}:e"
560+
code_to = f"{mate.to_name}{to_port_str}:w"
561+
562+
dot.attr("edge", color=color, style="dashed", dir=dir)
563+
dot.edge(code_from, code_to)
564+
533565
def typecheck(name: str, value: Any, expect: type) -> None:
534566
if not isinstance(value, expect):
535567
raise Exception(
@@ -595,41 +627,9 @@ def typecheck(name: str, value: Any, expect: type) -> None:
595627
typecheck("tweak.append", self.tweak.append, str)
596628
dot.body.append(self.tweak.append)
597629

598-
# TODO: All code below until "return dot" must be moved above all tweak processing!
599-
for mate in self.mates:
600-
if mate.shape[0] == "<" and mate.shape[-1] == ">":
601-
dir = "both"
602-
elif mate.shape[0] == "<":
603-
dir = "back"
604-
elif mate.shape[-1] == ">":
605-
dir = "forward"
606-
else:
607-
dir = "none"
608-
609-
if isinstance(mate, MatePin):
610-
color = "#000000"
611-
elif isinstance(mate, MateComponent):
612-
color = "#000000:#000000"
613-
else:
614-
raise Exception(f"{mate} is an unknown mate")
615-
616-
from_connector = self.connectors[mate.from_name]
617-
to_connector = self.connectors[mate.to_name]
618-
if isinstance(mate, MatePin) and from_connector.style != "simple":
619-
from_pin_index = from_connector.pins.index(mate.from_pin)
620-
from_port_str = f":p{from_pin_index+1}r"
621-
else: # MateComponent or style == 'simple'
622-
from_port_str = ""
623-
if isinstance(mate, MatePin) and to_connector.style != "simple":
624-
to_pin_index = to_connector.pins.index(mate.to_pin)
625-
to_port_str = f":p{to_pin_index+1}l"
626-
else: # MateComponent or style == 'simple'
627-
to_port_str = ""
628-
code_from = f"{mate.from_name}{from_port_str}:e"
629-
code_to = f"{mate.to_name}{to_port_str}:w"
630-
631-
dot.attr("edge", color=color, style="dashed", dir=dir)
632-
dot.edge(code_from, code_to)
630+
# Tweak processing above must be the last before returning dot.
631+
# Please don't insert any code that might change the dot contents
632+
# after tweak processing.
633633

634634
return dot
635635

0 commit comments

Comments
 (0)