From a59e8e99243a895197a30d6cd6dd8d744dd606de Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 11 Nov 2026 10:32:51 +0100 Subject: Keep only the current router: drop the Python router, router-rs -> router 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 --- tools/router/src/io.rs | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 tools/router/src/io.rs (limited to 'tools/router/src/io.rs') 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>, + #[serde(rename = "B")] + pub b: Option>, +} + +#[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, + #[serde(default)] + pub fps: BTreeMap, + #[serde(default)] + pub netclass: HashMap, + #[serde(default)] + pub classes: HashMap, + #[serde(default)] + pub fpcopper: Vec, + /// copper pours (not rule areas): net, layer, outline + #[serde(default)] + pub zones: Vec, + #[serde(default)] + pub keepouts: Vec>, + /// Owning footprint of each keepout ("" for board rule areas); absent in old dumps. + #[serde(default)] + pub keepout_refs: Vec, + #[serde(default)] + pub tracks: Vec, + #[serde(default)] + pub vias: Vec, +} + +impl BoardJson { + pub fn load(path: &str) -> anyhow::Result { + 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, + pub vias: Vec, + pub failed: Vec>, + pub log: Vec, +} + +#[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, + #[serde(default)] + pub vias: Vec, + #[serde(default)] + pub fps: BTreeMap, + #[serde(default)] + pub pads: Vec, +} + +impl CopperJson { + pub fn load(path: &str) -> anyhow::Result { + 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()) + } +} -- cgit v1.3