← Commit history

2.47.8: generate keeps np_thru_hole pads as <hole> elements (#36; GitHub 81c55d6)

Ray ·2667c59582 · ·parent a535df5
9 files changed +189−8
CHANGELOG.md+3
@@ -1,5 +1,8 @@ # Changelog +## 2.47.8 (2026-10-28)+- `generate` keeps a footprint's `np_thru_hole` pads as EAGLE `<hole>` elements, in the main package and every package variant. They used to be dropped, so guide posts, board pegs and holddown holes were missing in Fusion (hr911130a, an ET60S connector, 0741640110), and a named one such as an `MP` pad came out as a plated `<pad>` with copper the footprint does not have. Positions use the pads' y-flip, and a drill offset turns with the pad. An oval slot is drilled at its short width, since a `<hole>` is round, with the slot outline on layer 46 Milling and a `WARN` naming it. (#36, Caleb)+ ## 2.47.7 (2026-10-21) - Footprint keepout areas (a KiCad `zone` with a `keepout` block, such as the creepage strip of an isolated part) are no longer dropped. `import-kicad` carries them in the hub JSON as `footprint.keepouts` (layers, polygon, and what is not allowed), and `export-kicad` writes them back. (#35) - `generate` writes a keepout to EAGLE's restrict layers: tRestrict/bRestrict for copper, vRestrict for vias, tKeepout/bKeepout for parts. EAGLE has no inner-layer restrict layer, so a `*.Cu` or inner-layer copper keepout is reported as `lost-keepout`.
Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-lbr"-version = "2.47.7"+version = "2.47.8" dependencies = [  "altium-codec",  "anyhow",
Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.47.7"+version = "2.47.8" edition = "2021" description = "adom-lbr generator / EDA translator: the canonical adom-lbr JSON is the hub, with native converters to Altium (.SchLib/.PcbLib/.IntLib), EAGLE/Fusion (.lbr), and KiCad. Altium output is written natively — no Altium needed at conversion time." 
VERSION+1−1
@@ -1 +1 @@-2.47.7+2.47.8
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.7",+  "version": "2.47.8",   "type": "app",   "description": "adom-lbr \u2014 the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad \u21c4 Altium \u21c4 EAGLE/Fusion) through one canonical adom-lbr JSON \u2014 symbol + footprint + 3D + pin\u2194pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},
page.json+2−2
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.7",+  "version": "2.47.8",   "type": "app",   "description": "adom-lbr — the EDA library translator. Bring a component in from any supported EDA tool and convert it to any other (KiCad ⇄ Altium ⇄ EAGLE/Fusion) through one canonical adom-lbr JSON — symbol + footprint + 3D + pin↔pad map. Altium is written natively (no Altium needed). Includes the adom-lbr Manager: browse wiki components and view symbol/footprint/3D + the per-EDA layer stackup.",   "dependencies": {},@@ -89,4 +89,4 @@       "label": "Browse parts"     }   ]-}\ No newline at end of file+}
src/main.rs+119−2
@@ -1251,7 +1251,8 @@ fn sexpr_blocks<'a>(km: &'a str, tag: &str) -> Vec<&'a str> {  /// Parse every real (named) pad out of a `.kicad_mod`, preserving the true /// per-side positions, sizes, and rotations. Mechanical pads (empty name) and-/// pads missing position/size are skipped.+/// pads missing position/size are skipped, and so is every `np_thru_hole`: it has+/// no copper, so it is a drilled hole, not a pad (see `parse_mod_holes`). fn parse_mod_pads(km: &str) -> Vec<ModPad> {     // Groups: 1/2 = pad name (quoted/bare), 3 = type (smd/thru_hole), 4 = SHAPE     // (circle/oval/rect/roundrect/…) — the shape word we were previously dropping.@@ -1273,7 +1274,7 @@ fn parse_mod_pads(km: &str) -> Vec<ModPad> {     for block in sexpr_blocks(km, "pad") {         let Some(nc) = name_re.captures(block) else { continue };         let name = nc.get(1).or_else(|| nc.get(2)).map(|m| m.as_str().to_string()).unwrap_or_default();-        if name.is_empty() {+        if name.is_empty() || nc.get(3).map(|m| m.as_str()) == Some("np_thru_hole") {             continue;         }         if margin_re.is_match(block) {@@ -1311,6 +1312,84 @@ fn parse_mod_pads(km: &str) -> Vec<ModPad> {     pads } +/// One KiCad `np_thru_hole` pad: a guide peg, holddown or mounting hole. In EAGLE+/// coordinates (millimetres, Y-up), already offset and rotated, so the writer only+/// formats it.+struct ModHole {+    x: f64,+    y: f64,+    /// Drill along and across the slot; equal for a round hole.+    long: f64,+    short: f64,+    /// Direction of the slot's long axis in EAGLE degrees (counter-clockwise).+    axis: f64,+}++/// Every `np_thru_hole` pad in a `.kicad_mod`, named or not. These were dropped (unnamed)+/// or written as plated `<pad>` copper (named), so the guide pegs and holddowns of+/// connectors like adom/hr911130a never reached the .lbr. The position follows the pad+/// rule exactly (EAGLE y = -KiCad y); a drill `(offset ..)` is in the pad's own frame,+/// so it turns with the pad angle before it is added.+fn parse_mod_holes(km: &str) -> Vec<ModHole> {+    let head_re = regex_lite::Regex::new(r#"^\(pad\s+(?:"[^"]*"|\S+)\s+np_thru_hole\b"#).unwrap();+    let at_re = regex_lite::Regex::new(r#"\(at\s+(-?[\d.]+)\s+(-?[\d.]+)(?:\s+(-?[\d.]+))?\s*\)"#).unwrap();+    // (drill D) or (drill oval W [H]); a missing H means a round oval, W x W.+    let drill_re = regex_lite::Regex::new(r#"\(drill\s+(oval\s+)?(-?[\d.]+)(?:\s+(-?[\d.]+))?"#).unwrap();+    let off_re = regex_lite::Regex::new(r#"\(offset\s+(-?[\d.]+)\s+(-?[\d.]+)\s*\)"#).unwrap();+    let mut holes = Vec::new();+    for block in sexpr_blocks(km, "pad") {+        if !head_re.is_match(block) { continue; }+        let Some(at) = at_re.captures(block) else { continue };+        let Some(d) = drill_re.captures(block) else { continue };+        let x: f64 = at[1].parse().unwrap_or(0.0);+        let y: f64 = at[2].parse().unwrap_or(0.0);+        let angle: f64 = at.get(3).and_then(|m| m.as_str().parse().ok()).unwrap_or(0.0);+        let w: f64 = d[2].parse().unwrap_or(0.0);+        let h: f64 = if d.get(1).is_some() { d.get(3).and_then(|m| m.as_str().parse().ok()).unwrap_or(w) } else { w };+        if w <= 0.0 || h <= 0.0 { continue; }+        let (ox, oy) = off_re.captures(block)+            .map(|c| (c[1].parse().unwrap_or(0.0), c[2].parse().unwrap_or(0.0))).unwrap_or((0.0, 0.0));+        // KiCad's pad angle turns counter-clockwise on screen in a Y-down frame, so local+        // +x lands on (cos a, -sin a) there and on (cos a, sin a) once Y is flipped.+        let (sa, ca) = angle.to_radians().sin_cos();+        let bx = x + ox * ca + oy * sa;+        let by = y - ox * sa + oy * ca;+        let axis = if h > w { angle + 90.0 } else { angle };+        holes.push(ModHole { x: bx, y: -by, long: w.max(h), short: w.min(h), axis });+    }+    holes+}++/// EAGLE for the footprint's non-plated holes: one `<hole>` each. EAGLE's hole is round+/// only, so an oval (slotted) drill becomes a hole of its SHORT width at the slot centre,+/// which never cuts outside the slot, plus the slot outline on layer 46 Milling, which is+/// where EAGLE and Fusion CAM take non-round cutouts from. The fab gets the true slot and+/// the board never gains a hole the footprint did not have.+fn holes_eagle_xml(km: &str) -> String {+    let mut xml = String::new();+    for h in parse_mod_holes(km) {+        xml.push_str(&format!("  <hole x=\"{:.4}\" y=\"{:.4}\" drill=\"{:.4}\"/>\n", h.x, h.y, h.short));+        if h.long - h.short > 1e-6 {+            eprintln!("WARN: oval non-plated hole {:.2} x {:.2} mm at ({:.3}, {:.3}): EAGLE holes are round, so it is drilled {:.2} mm and the slot is drawn on layer 46 Milling",+                h.short, h.long, h.x, h.y, h.short);+            let (s, c) = h.axis.to_radians().sin_cos();+            let (half, r) = ((h.long - h.short) / 2.0, h.short / 2.0);+            // The two end-cap centres, and the outline offset either side of the axis.+            let (c1, c2) = ((h.x - c * half, h.y - s * half), (h.x + c * half, h.y + s * half));+            let (nx, ny) = (-s * r, c * r);+            for ((x1, y1), (x2, y2), curve) in [+                ((c1.0 + nx, c1.1 + ny), (c2.0 + nx, c2.1 + ny), ""),+                ((c2.0 + nx, c2.1 + ny), (c2.0 - nx, c2.1 - ny), " curve=\"-180\""),+                ((c2.0 - nx, c2.1 - ny), (c1.0 - nx, c1.1 - ny), ""),+                ((c1.0 - nx, c1.1 - ny), (c1.0 + nx, c1.1 + ny), " curve=\"-180\""),+            ] {+                xml.push_str(&format!("  <wire x1=\"{:.4}\" y1=\"{:.4}\" x2=\"{:.4}\" y2=\"{:.4}\" width=\"0\" layer=\"46\"{}/>\n", x1, y1, x2, y2, curve));+            }+        }+    }+    xml+}+ /// Map a KiCad pad rotation (degrees) to an EAGLE `rot=` attribute, matching /// Fusion 360's own library export convention: the KiCad angle maps directly /// (KiCad 90 → `R90`), so a non-square pad on a QFP/SOIC top/bottom side is@@ -1494,6 +1573,7 @@ fn emit_variant_package(xml: &mut String, km: &str, name: &str, description: &st                 esc_xml(&out_names[i]), p.x, -p.y, drill, diameter, tht_shape, smd_rotation(p.angle + extra_rot)));         }     }+    xml.push_str(&holes_eagle_xml(km));     xml.push_str(&package_graphics(km));     xml.push_str(&keepout_eagle_xml(km));     xml.push_str("</package>\n");@@ -2448,6 +2528,7 @@ pub(crate) fn generate_lbr_gates(sym: &ParsedSymbol, fp_content: Option<&str>, s                     esc_xml(&out_names[i]), p.x, -p.y, drill, diameter, tht_shape, smd_rotation(p.angle + extra_rot)));             }         }+        xml.push_str(&holes_eagle_xml(km));         // Real silk/fab graphics (circles/lines/arcs); bbox rectangle only as fallback.         let (minx, miny, maxx, maxy) = package_outline(km, &mod_pads);         let (sx1, sy1, sx2, sy2) = (minx, -maxy, maxx, -miny);@@ -5429,3 +5510,39 @@ mod keepout_tests {         assert_eq!(keepout_eagle_layers(&parts).0, vec![40]);     } }++#[cfg(test)]+mod npth_tests {+    use super::*;+    const FP: &str = include_str!("../tests/fixtures/npth/peg2.kicad_mod");+    const SYM: &str = include_str!("../tests/fixtures/npth/peg2.kicad_sym");++    #[test]+    fn non_plated_holes_become_eagle_holes_and_plated_pads_stay_pads() {+        let sym = parse_kicad_sym(SYM, None).unwrap();+        let xml = generate_lbr(&sym, Some(FP), None, 0.38, &Default::default(), &[]).unwrap();+        // Both plated pads stay copper, and no NPTH (named "MP" or unnamed) becomes one.+        assert!(xml.contains(r#"<pad name="1" x="-1.2700" y="-0.0000" drill="0.8000""#), "{xml}");+        assert!(xml.contains(r#"<pad name="2" x="1.2700" y="-0.0000" drill="0.8000""#), "{xml}");+        assert!(!xml.contains(r#"<pad name="MP""#), "a named NPTH has no copper: {xml}");+        // Each NPTH is a hole at the pad's own position, Y flipped like every pad.+        assert!(xml.contains(r#"<hole x="-2.5000" y="-1.5000" drill="1.6000"/>"#), "{xml}");+        assert!(xml.contains(r#"<hole x="2.5000" y="-1.5000" drill="1.1000"/>"#), "{xml}");+        // An oval drill is drilled at its short width and its slot drawn on Milling. This+        // one is 0.8 x 1.6 turned 90 degrees, so the slot runs along EAGLE X.+        assert!(xml.contains(r#"<hole x="0.0000" y="1.5000" drill="0.8000"/>"#), "{xml}");+        assert!(xml.contains(r#"<wire x1="-0.4000" y1="1.9000" x2="0.4000" y2="1.9000" width="0" layer="46"/>"#), "{xml}");+        assert_eq!(xml.matches(r#"layer="46""#).count(), 4, "four slot segments, round holes draw none");+        assert_eq!(xml.matches("<hole ").count(), 3);+        assert!(lint_lbr(&xml).errors.is_empty(), "{:?}", lint_lbr(&xml).errors);+    }++    #[test]+    fn a_drill_offset_turns_with_the_pad() {+        let km = r#"(footprint "T"+            (pad "" np_thru_hole circle (at 1 2 90) (size 1 1) (drill 1 (offset 0.5 0)) (layers "*.Cu")))"#;+        let h = &parse_mod_holes(km)[0];+        // local +x at 90 degrees points up the screen, which is KiCad -y and EAGLE +y.+        assert!((h.x - 1.0).abs() < 1e-9 && (h.y - -1.5).abs() < 1e-9, "({}, {})", h.x, h.y);+    }+}
tests/fixtures/npth/peg2.kicad_modadded+13
@@ -0,0 +1,13 @@+(footprint "PEG2" (version 20240108) (generator "repro") (layer "F.Cu")+  (fp_line (start -3 -2) (end 3 -2) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))+  (fp_line (start -3 2) (end 3 2) (stroke (width 0.12) (type solid)) (layer "F.SilkS"))+  (pad "1" thru_hole rect (at -1.27 0) (size 1.5 1.5) (drill 0.8) (layers "*.Cu" "*.Mask"))+  (pad "2" thru_hole circle (at 1.27 0) (size 1.5 1.5) (drill 0.8) (layers "*.Cu" "*.Mask"))+  (pad "" np_thru_hole circle+    (at -2.5 1.5)+    (size 1.6 1.6)+    (drill 1.6)+    (layers "*.Cu" "*.Mask"))+  (pad "MP" np_thru_hole circle (at 2.5 1.5) (size 1.1 1.1) (drill 1.1) (layers "*.Cu" "*.Mask"))+  (pad "" np_thru_hole oval (at 0 -1.5 90) (size 0.8 1.6) (drill oval 0.8 1.6) (layers "*.Cu" "*.Mask"))+)
tests/fixtures/npth/peg2.kicad_symadded+48
@@ -0,0 +1,48 @@+(kicad_symbol_lib+  (version 20231120)+  (generator "adom")+  (symbol "PEG2"+    (pin_names (offset 1.016))+    (exclude_from_sim no)+    (in_bom yes)+    (on_board yes)+    (property "Reference" "U"+      (at 0.00 5.08 0)+      (effects (font (size 1.27 1.27)))+    )+    (property "Value" "PEG2"+      (at 0.00 -9.62 0)+      (effects (font (size 1.27 1.27)))+    )+    (property "Footprint" ""+      (at 0 -14.70 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Datasheet" ""+      (at 0 -17.24 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Description" "Two-pin connector with guide pegs."+      (at 0 -19.78 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "Manufacturer" "Test"+      (at 0 -22.32 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (property "MPN" "PEG2"+      (at 0 -24.86 0)+      (effects (font (size 1.27 1.27)) (hide yes))+    )+    (symbol "PEG2_0_1"+      (rectangle (start -12.70 2.54) (end 12.70 -7.08)+        (stroke (width 0.254) (type default))+        (fill (type background))+      )+    )+    (symbol "PEG2_1_1"+      (pin input line (at -15.24 -2.00 0) (length 2.54) (name "A") (number "1"))+      (pin output line (at 15.24 -2.00 180) (length 2.54) (name "B") (number "2"))+    )+  )+)