← Commit history

0.2.79 source (unreleased): engine 0.2.1 (standard 0.5.1): GenCAD shapes keyed by their pads (#17)

Colby Knox ·50cd8014e2 · ·parent d915247
6 files changed +42−10
CHANGELOG.md+3−2
@@ -2,8 +2,9 @@  ## 0.2.79 (unreleased) -- **The board-file writers moved into the standard's engine** (EDA Bridge Standard #16, standard 0.5.0, adom-eda-checks-  0.2.0, vendored as published): `export_gencad`, `export_dxf` and `import_svg` answer through+- **The board-file writers moved into the standard's engine** (EDA Bridge Standard #16, standard 0.5.1, adom-eda-checks+  0.2.1, vendored as published; 0.2.1 keys a GenCAD shape by its pads too, so two footprints of one name with+  different pads become NAME and NAME_2, #17): `export_gencad`, `export_dxf` and `import_svg` answer through   `adom_eda_checks::writers`, the same code any bridge without a native exporter can use. The bridge reads the board,   writes the files and places the regions. `export_dxf` now draws the copper actually poured (the bridge passes   pour_state), and `poursAsDrawn` names layers drawn from a pour's outline instead. On the lane board, the engine's
bridge-rs/Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-eda-checks"-version = "0.2.0"+version = "0.2.1" dependencies = [  "roxmltree",  "serde_json",
bridge-rs/src/checks.rs+1−1
@@ -6,7 +6,7 @@ use serde_json::{json, Value}; use std::time::Duration;  /// The vendored engine, as vendor/README.md records it.-const ENGINE: &str = "adom-eda-checks 0.2.0 (EDA Bridge Standard 0.5.0)";+const ENGINE: &str = "adom-eda-checks 0.2.1 (EDA Bridge Standard 0.5.1)";  /// adom/pcb-design-rules' vendor records, bundled at build time (vendor/README.md). const RECORDS: &[(&str, &str)] = &[
bridge-rs/vendor/README.md+1−1
@@ -2,7 +2,7 @@  | Folder | From | Version | |---|---|---|-| `adom-eda-checks/` | adom/eda-bridge-standard `engine/` (the shared checks engine) | standard 0.5.0, engine 0.2.0 |+| `adom-eda-checks/` | adom/eda-bridge-standard `engine/` (the shared checks engine) | standard 0.5.1, engine 0.2.1 | | `pcb-design-rules/records/` | adom/pcb-design-rules `rules/records/` (each fab's published limits, with sources and dates) | head of 2026-10-27 |  The wiki has no git protocol, so these are copied at a version: refresh both from their pages, then run the tests.
bridge-rs/vendor/adom-eda-checks/Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-eda-checks"-version = "0.2.0"+version = "0.2.1" edition = "2021" description = "The EDA Bridge Standard's checks and board-file writers, computed from the board model JSON: no bridge calls, no tool." license = "MIT"
bridge-rs/vendor/adom-eda-checks/src/writers/gencad.rs+35−4
@@ -48,16 +48,19 @@ pub fn gencad_text(state: &Value, title: &str, unique_pins: bool) -> (String, Va         let k = (shape.to_string(), (w * 1000.0).round() / 1000.0, (h * 1000.0).round() / 1000.0, (drill * 1000.0).round() / 1000.0);         match pad_defs.iter().position(|p| *p == k) { Some(i) => i, None => { pad_defs.push(k); pad_defs.len() - 1 } }     };-    // shapes: each footprint pattern once, from its first part+    // shapes: one per footprint pattern and pad geometry. Two parts share a shape only when their pins match in the+    // footprint's frame: two different footprints of the same name (from two libraries) get NAME and NAME_2 (#17)     struct Pin { name: String, pad: usize, x: f64, y: f64, rot: f64, through: bool }     let mut shapes: Vec<(String, Vec<Pin>, bool)> = Vec::new();     let mut shape_of: Vec<(String, String)> = Vec::new(); // ref -> shape name+    // the same pins within 5 um: the board model keeps positions to 1 um, so a rotated part's pins come back a micron off+    // (BQ25792's R3 against R5: 2.319 against 2.320 mm), and float noise turns 0 into -1e-16+    let same_pins = |a: &[Pin], b: &[Pin]| a.len() == b.len() && a.iter().zip(b).all(|(p, q)| p.name == q.name && p.pad == q.pad+        && (p.x - q.x).abs() < 0.005 && (p.y - q.y).abs() < 0.005 && (p.rot - q.rot).abs() < 0.05);     for c in &comps {         let rf = c["ref"].as_str().unwrap_or("").to_string();         let pattern = c["pattern"].as_str().unwrap_or("").to_string();-        let name = if pattern.is_empty() { format!("SHAPE_{rf}") } else { pattern.clone() };-        shape_of.push((rf.clone(), name.clone()));-        if shapes.iter().any(|s| s.0 == name) { continue; }+        let base = if pattern.is_empty() { format!("SHAPE_{rf}") } else { pattern.clone() };         let (cx, cy, th) = (f(&c["x"]), f(&c["y"]), f(&c["rotation"]).to_radians());         let bottom = c["side"] == "bottom";         let mut pins = Vec::new();@@ -83,6 +86,15 @@ pub fn gencad_text(state: &Value, title: &str, unique_pins: bool) -> (String, Va             let id = pad_name(p["shape"].as_str().unwrap_or("rect"), w, h, f(&p["drill"]));             pins.push(Pin { name: nm, pad: id, x: lx, y: ly, rot, through });         }+        // the same pattern with the same pins: reuse that shape; the same name with other pins: a new name+        if let Some(existing) = shapes.iter().find(|(n, ps, _)| (*n == base || n.starts_with(&format!("{base}_"))) && same_pins(ps, &pins)) {+            shape_of.push((rf, existing.0.clone()));+            continue;+        }+        let mut name = base.clone();+        let mut k = 2;+        while shapes.iter().any(|x| x.0 == name) { name = format!("{base}_{k}"); k += 1; }+        shape_of.push((rf, name.clone()));         let th_part = pins.iter().any(|p| p.through);         shapes.push((name, pins, th_part));     }@@ -251,4 +263,23 @@ mod tests {         assert_eq!(r["writtenFrom"], "board model");         assert!(r["text"].as_str().unwrap().starts_with("$HEADER\nGENCAD 1.4\n"));     }++    #[test]+    fn same_named_footprints_with_other_pads_are_two_shapes() {+        let pad = |r: &str, n: &str, x: f64, w: f64| json!({"ref": r, "name": n, "x": x, "y": 0.0, "sizeX": w, "sizeY": 1.0, "shape": "rect", "drill": 0.0, "rotation": 0.0, "layer": "F.Cu", "net": ""});+        // R1 and R2: the same "R0603" footprint (R2 rotated 180): one shape. R3: another library's "R0603", other pads: its own+        let st = json!({"components": [{"ref": "R1", "pattern": "R0603", "x": 0.0, "y": 0.0, "rotation": 0.0, "side": "top"},+                                       {"ref": "R2", "pattern": "R0603", "x": 10.0, "y": 0.0, "rotation": 180.0, "side": "top"},+                                       {"ref": "R3", "pattern": "R0603", "x": 20.0, "y": 0.0, "rotation": 0.0, "side": "top"}],+            "pads": [pad("R1", "1", -0.8, 0.9), pad("R1", "2", 0.8, 0.9), pad("R2", "1", 10.801, 0.9), pad("R2", "2", 9.2, 0.9),+                     pad("R3", "1", 19.0, 1.2), pad("R3", "2", 21.0, 1.2)]});+        let (t, _) = gencad_text(&st, "x", false);+        assert_eq!(t.matches("SHAPE \"R0603\"\nINSERT").count(), 1, "R1 and R2 share one shape");+        assert!(t.contains("SHAPE \"R0603_2\"\nINSERT"), "R3's footprint is its own shape");+        assert!(!t.contains("R0603_3"), "R2 reuses R1's shape");+        // each part points at its shape+        let comp = |r: &str| t.split(&format!("COMPONENT \"{r}\"\n")).nth(1).unwrap().lines().find(|l| l.starts_with("SHAPE ")).unwrap().to_string();+        assert!(comp("R1").starts_with("SHAPE \"R0603\"") && comp("R2").starts_with("SHAPE \"R0603\"") && comp("R3").starts_with("SHAPE \"R0603_2\""));+    } }+