1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
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())
}
}
|