diff options
| author | Louis <louis@dnge.de> | 2026-11-11 10:08:41 +0100 |
|---|---|---|
| committer | Louis <louis@dnge.de> | 2026-11-11 10:08:41 +0100 |
| commit | 2e433fcd0d1afadd8ab786dd30d7d4546bdee43d (patch) | |
| tree | f2a5603703d56b08c1eaa672eaf529ec4b2cc3fa /tools/router/plot_routes.py | |
| download | hw-toolchain-2e433fcd0d1afadd8ab786dd30d7d4546bdee43d.tar.gz | |
hw-toolchain: placer, routers and KiCad helpers for agent-driven hardware work
Rust placer (simulated annealing) and negotiated-congestion router for
2-layer KiCad boards, pnr.sh to place, route, DRC-check and install
candidates, Python KiCad helpers, repo conventions (AGENTS.md) and the
tool documentation under knowledge/. Konnect (KiCad MCP, AGPL) as a
submodule.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/router/plot_routes.py')
| -rw-r--r-- | tools/router/plot_routes.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/router/plot_routes.py b/tools/router/plot_routes.py new file mode 100644 index 0000000..f7b3976 --- /dev/null +++ b/tools/router/plot_routes.py @@ -0,0 +1,63 @@ +"""Plot router output over the board's pads, one colour per net, failed pins marked. + + tools/router/.venv/bin/python tools/router/plot_routes.py board.json routes.json out.png [x0 y0 x1 y1] + +Pads are grey (F.Cu darker, B.Cu-only lighter); F.Cu tracks solid, B.Cu tracks dashed; +vias are circles; every net is labelled at its longest segment; pins listed in +routes.json "failed" get a red cross. Use a window (mm) to zoom into a dense part. +""" +import json +import sys +import zlib + +import matplotlib +matplotlib.use("Agg") +import matplotlib.pyplot as plt # noqa: E402 +from matplotlib.patches import Circle, Polygon # noqa: E402 + +board, routes, out = sys.argv[1:4] +win = [float(v) for v in sys.argv[4:8]] if len(sys.argv) >= 8 else None +d = json.load(open(board)) +r = json.load(open(routes)) +x0, y0, x1, y1 = win or d["bounds"] +scale = 12 if win else 4 +fig = plt.figure(figsize=((x1 - x0) / 25.4 * scale, (y1 - y0) / 25.4 * scale), dpi=100) +ax = fig.add_axes([0, 0, 1, 1]) +ax.set_xlim(x0, x1) +ax.set_ylim(y1, y0) +ax.set_aspect("equal") +ax.axis("off") +cmap = plt.get_cmap("tab20") + + +def col(net): + return cmap(zlib.crc32(net.encode()) % 20) + + +for p in d["pads"]: + poly = p["F"] or p["B"] + if poly: + ax.add_patch(Polygon(poly, closed=True, fc="#9e9e9e" if p["F"] else "#d0d0d0", ec="none", zorder=1)) + if win and x0 <= p["x"] <= x1 and y0 <= p["y"] <= y1: + ax.text(p["x"], p["y"], "%s.%s" % (p["ref"], p["num"]), fontsize=4, ha="center", va="center", zorder=5) +longest = {} +for s in r["segs"]: + lw = s["w"] * 72 / 25.4 * scale * 1.0 + ax.plot([s["x1"], s["x2"]], [s["y1"], s["y2"]], color=col(s["net"]), lw=lw, solid_capstyle="round", + ls="-" if s["layer"] == "F.Cu" else (0, (2, 1)), alpha=0.85 if s["layer"] == "F.Cu" else 0.6, zorder=3) + L = abs(s["x2"] - s["x1"]) + abs(s["y2"] - s["y1"]) + if L > longest.get(s["net"], (0,))[0]: + longest[s["net"]] = (L, (s["x1"] + s["x2"]) / 2, (s["y1"] + s["y2"]) / 2) +for v in r["vias"]: + ax.add_patch(Circle((v["x"], v["y"]), v["d"] / 2, fc="white", ec=col(v["net"]), lw=1.5, zorder=4)) +for net, (L, x, y) in longest.items(): + if x0 <= x <= x1 and y0 <= y <= y1: + ax.text(x, y, net.split("/")[-1], fontsize=6 if win else 4, color="black", zorder=6, + bbox=dict(fc=col(net), ec="none", alpha=0.7, pad=0.5)) +pads = {(p["ref"], p["num"]): p for p in d["pads"]} +for f in r.get("failed", []): + p = pads.get((f[1], f[2])) if len(f) >= 3 else None + if p: + ax.plot([p["x"]], [p["y"]], marker="x", color="red", ms=14, mew=3, zorder=7) +fig.savefig(out) +print("wrote", out) |
