//! 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()) } }