aboutsummaryrefslogtreecommitdiff
path: root/tools/router/src/io.rs
diff options
context:
space:
mode:
authorLouis <louis@dnge.de>2026-11-11 10:32:51 +0100
committerLouis <louis@dnge.de>2026-11-11 10:32:51 +0100
commita59e8e99243a895197a30d6cd6dd8d744dd606de (patch)
tree8910cc7476ff1317932257dfc8497a0f9ffc29f7 /tools/router/src/io.rs
parent6f2bbe1f94e4321c329f92ec3420f6d32fd7b26d (diff)
downloadhw-toolchain-a59e8e99243a895197a30d6cd6dd8d744dd606de.tar.gz
Keep only the current router: drop the Python router, router-rs -> routerHEADmain
The sequential Python/C router (pcbroute.py, pipeline.py, astar.c) is gone. The Rust crate takes its place at tools/router/, next to the KiCad I/O scripts it uses (dump_board.py, write_board.py, plot_routes.py). knowledge/tooling/router.md is now the Rust router's reference; the small Python venv for plots and 3D checks moves to tools/.venv (tools/requirements.txt). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/router/src/io.rs')
-rw-r--r--tools/router/src/io.rs145
1 files changed, 145 insertions, 0 deletions
diff --git a/tools/router/src/io.rs b/tools/router/src/io.rs
new file mode 100644
index 0000000..be51147
--- /dev/null
+++ b/tools/router/src/io.rs
@@ -0,0 +1,145 @@
+//! JSON formats shared with the Python tools: board.json from tools/router/dump_board.py
+//! in, routes.json for tools/router/write_board.py and plot_routes.py out.
+
+use serde::{Deserialize, Serialize};
+use std::collections::{BTreeMap, HashMap};
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct PadJson {
+ #[serde(rename = "ref")]
+ pub refdes: String,
+ pub num: String,
+ pub net: String,
+ pub x: f64,
+ pub y: f64,
+ pub drill: f64,
+ #[serde(default)]
+ pub npth: bool,
+ #[serde(rename = "F")]
+ pub f: Option<Vec<[f64; 2]>>,
+ #[serde(rename = "B")]
+ pub b: Option<Vec<[f64; 2]>>,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct FpJson {
+ pub x: f64,
+ pub y: f64,
+ pub rot: f64,
+ #[serde(default)]
+ pub value: String,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct ClassJson {
+ pub track: f64,
+ pub via: f64,
+}
+
+/// Footprint copper that is not a pad, on "F" or "B".
+#[derive(Deserialize, Serialize, Clone)]
+pub struct FpCopperJson {
+ #[serde(rename = "ref")]
+ pub refdes: String,
+ pub layer: String,
+ pub poly: Vec<[f64; 2]>,
+}
+
+/// A copper pour: net, layer ("F.Cu" / "B.Cu") and outline.
+#[derive(Deserialize, Serialize, Clone)]
+pub struct ZoneJson {
+ pub net: String,
+ pub layer: String,
+ pub pts: Vec<[f64; 2]>,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct TrackJson {
+ pub net: String,
+ pub layer: String,
+ pub x1: f64,
+ pub y1: f64,
+ pub x2: f64,
+ pub y2: f64,
+ pub w: f64,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct ViaJson {
+ pub net: String,
+ pub x: f64,
+ pub y: f64,
+ pub d: f64,
+ #[serde(default)]
+ pub drill: f64,
+}
+
+#[derive(Deserialize, Serialize, Clone)]
+pub struct BoardJson {
+ pub bounds: [f64; 4],
+ pub pads: Vec<PadJson>,
+ #[serde(default)]
+ pub fps: BTreeMap<String, FpJson>,
+ #[serde(default)]
+ pub netclass: HashMap<String, String>,
+ #[serde(default)]
+ pub classes: HashMap<String, ClassJson>,
+ #[serde(default)]
+ pub fpcopper: Vec<FpCopperJson>,
+ /// copper pours (not rule areas): net, layer, outline
+ #[serde(default)]
+ pub zones: Vec<ZoneJson>,
+ #[serde(default)]
+ pub keepouts: Vec<Vec<[f64; 2]>>,
+ /// Owning footprint of each keepout ("" for board rule areas); absent in old dumps.
+ #[serde(default)]
+ pub keepout_refs: Vec<String>,
+ #[serde(default)]
+ pub tracks: Vec<TrackJson>,
+ #[serde(default)]
+ pub vias: Vec<ViaJson>,
+}
+
+impl BoardJson {
+ pub fn load(path: &str) -> anyhow::Result<BoardJson> {
+ use anyhow::Context;
+ let s = std::fs::read_to_string(path).with_context(|| path.to_string())?;
+ serde_json::from_str(&s).with_context(|| path.to_string())
+ }
+}
+
+#[derive(Serialize)]
+pub struct RoutesJson {
+ pub segs: Vec<TrackJson>,
+ pub vias: Vec<ViaJson>,
+ pub failed: Vec<Vec<String>>,
+ pub log: Vec<serde_json::Value>,
+}
+
+#[derive(Deserialize)]
+pub struct PadNet {
+ #[serde(rename = "ref")]
+ pub refdes: String,
+ pub net: String,
+}
+
+/// Fixed copper: a board dump (tracks, vias, fps, pads) or just tracks and vias.
+#[derive(Deserialize)]
+pub struct CopperJson {
+ #[serde(default)]
+ pub tracks: Vec<TrackJson>,
+ #[serde(default)]
+ pub vias: Vec<ViaJson>,
+ #[serde(default)]
+ pub fps: BTreeMap<String, FpJson>,
+ #[serde(default)]
+ pub pads: Vec<PadNet>,
+}
+
+impl CopperJson {
+ pub fn load(path: &str) -> anyhow::Result<CopperJson> {
+ use anyhow::Context;
+ let s = std::fs::read_to_string(path).with_context(|| path.to_string())?;
+ serde_json::from_str(&s).with_context(|| path.to_string())
+ }
+}