@@ -530,6 +530,38 @@ def create_graph(self) -> Graph:
530
530
fillcolor = translate_color (bgcolor , "HEX" ),
531
531
)
532
532
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
+
533
565
def typecheck (name : str , value : Any , expect : type ) -> None :
534
566
if not isinstance (value , expect ):
535
567
raise Exception (
@@ -595,41 +627,9 @@ def typecheck(name: str, value: Any, expect: type) -> None:
595
627
typecheck ("tweak.append" , self .tweak .append , str )
596
628
dot .body .append (self .tweak .append )
597
629
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.
633
633
634
634
return dot
635
635
0 commit comments