From 6701e1ce98c2f0044ba8177c7be6a14c1b3f50ad Mon Sep 17 00:00:00 2001
From: Thomas Kramer <code@tkramer.ch>
Date: Mon, 29 Apr 2024 18:03:50 +0200
Subject: [PATCH] make route visualization optional, use different color for
 each net

---
 src/lclayout/graphrouter/inspect.py | 16 ++++++++++++++--
 src/lclayout/standalone.py          |  5 ++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/lclayout/graphrouter/inspect.py b/src/lclayout/graphrouter/inspect.py
index 61b7fbe..56f6945 100644
--- a/src/lclayout/graphrouter/inspect.py
+++ b/src/lclayout/graphrouter/inspect.py
@@ -6,6 +6,7 @@ Wrap a graph router and add visual inspection capabilities.
 """
 
 import os
+import math
 import networkx as nx
 
 from typing import *
@@ -68,10 +69,21 @@ class InspectRouter(GraphRouter):
                 layer, (x, y) = n
                 pos[n] = (x, y)
                 
+        def hue2rgb(hue: float) -> str:
+            assert 0. <= hue <= 1.
+
+            a = 2 * math.pi / 3
+            [r,g,b] = [int(255* math.cos(hue*math.pi + i*a) ** 2) for i in range(3)]
+
+            return f"#{r:02x}{g:02x}{b:02x}"
+                
+        net_names = sorted(routes.keys())
+        num_routes = len(routes)
+        colors = (hue2rgb(i/(num_routes+1)) for i in range(num_routes))
         
-        for (name, tree) in routes.items():
+        for name, color in zip(net_names, colors):
+            tree = routes[name]
             edges = tree.edges
-            color = "black"
             edges = [e for e in edges if not self._is_virtual_node_fn(e[0]) and not self._is_virtual_node_fn(e[1])]
             nx.draw_networkx_edges(self._graph, pos, edgelist=edges, width=4, edge_color=color)
 
diff --git a/src/lclayout/standalone.py b/src/lclayout/standalone.py
index a45ccf9..edd50c8 100644
--- a/src/lclayout/standalone.py
+++ b/src/lclayout/standalone.py
@@ -878,6 +878,8 @@ def main():
 
     parser.add_argument('--debug-routing-graph', action='store_true',
                         help='write full routing graph to the layout instead of wires')
+    parser.add_argument('--debug-visual', action='store_true',
+                        help='write visual debug information to the debug output directory')
     parser.add_argument('--debug-smt-solver', action='store_true',
                         help='enable debug mode: display routing nodes in layout, \
                         show unsatisfiable core if SMT DRC cleaning fails.')
@@ -952,7 +954,8 @@ def main():
                            orientation_change_penalty=tech.orientation_change_penalty
                            )
 
-    router = InspectRouter(router)
+    if args.debug_visual:
+        router = InspectRouter(router, output_dir = args.debug_output_dir)
 
     layouter = LcLayout(tech=tech,
                         layout=layout,
-- 
GitLab