by adom
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.
← Commit history
2.47.7: footprint keepouts ride the hub; EAGLE restrict layers; Altium names the loss (#35); GH 0f11ecc
15 files changed
+297−29
CHANGELOG.md+5Cargo.lock+1−1Cargo.toml+1−1VERSION+1−1bin/adom-lbrcrates/altium-codec/src/altium_decode.rs+2−2crates/altium-codec/src/kicad.rs+35crates/altium-codec/src/kicad_export.rs+9crates/altium-codec/src/lib.rs+11−7crates/altium-codec/src/model.rs+15package.json+1−1page.json+1−1src/main.rs+153−15tests/fixtures/keepout/repro4.kicad_mod+12tests/fixtures/keepout/repro4.kicad_sym+50CHANGELOG.md+5@@ -1,5 +1,10 @@ # Changelog +## 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`.+- The Altium lanes do not write keepout regions yet. They report `WARN: [lost-keepout]` and a `LOST:` line, and `--strict` refuses, the same policy as the pad-margin losses.+ ## 2.47.6 (2026-10-21) - `generate` writes a KiCad `no_connect` pin as EAGLE `direction="nc"`. It used to fall through to `io`, so Fusion's ERC treated an unconnected pin (a connector's mounting tab, say) as a bidirectional signal. All twelve KiCad pin types are mapped (`free` becomes `pas`), an unrecognized type is named in a `WARN: [pin-type-unmapped]` line, and importing an EAGLE `nc` pin writes KiCad's `no_connect`. (#33) - A boxed symbol keeps its pin names when it carries artwork inside the box, such as adom-symbol's chip outline. Names are hidden only on small drawings like LEDs and crystals, whose pins do not end on a body rectangle. (#34)
Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-lbr"-version = "2.47.6"+version = "2.47.7" dependencies = [ "altium-codec", "anyhow",
Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.47.6"+version = "2.47.7" 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.6+2.47.7
bin/adom-lbr⋯ 1 unchanged line ⋯
crates/altium-codec/src/altium_decode.rs+2−2@@ -108,7 +108,7 @@ pub fn decode_altium_with( (fp, ch) } None => (- Footprint { name: mpn.to_string(), pads: vec![], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None },+ Footprint { name: mpn.to_string(), pads: vec![], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() }, FootprintChoice { name: String::new(), rule: "none", listed }, ), };@@ -704,7 +704,7 @@ fn decode_pcblib_footprint(bytes: &[u8], want: Option<&str>) -> Result<Footprint } } - Ok(Footprint { name: fp_name, pads, graphics, polys: vec![], mask_margin_mm: None, paste_margin_mm: None })+ Ok(Footprint { name: fp_name, pads, graphics, polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() }) } /// Altium layer byte → neutral role. Counterpart of `pcblib::layer_enc`.
crates/altium-codec/src/kicad.rs+35@@ -426,6 +426,7 @@ pub(crate) fn import_footprint(text: &str) -> Result<Footprint> { pads, graphics: import_footprint_graphics(&root), polys: import_footprint_polys(&root),+ keepouts: import_footprint_keepouts(&root), mask_margin_mm: root.child("solder_mask_margin").and_then(|m| m.nums().first().copied()), paste_margin_mm: root.child("solder_paste_margin").and_then(|m| m.nums().first().copied()), })@@ -521,6 +522,40 @@ fn import_footprint_graphics(root: &Sx) -> Vec<FpGraphic> { /// Import a KiCad footprint's FILLED polygons (`fp_poly`) into [`FpPoly`]s /// (mm, Y-down): the pin-1 marker shape (wiki #16). The whole `(pts …)` vertex /// list rides across; stroke width when the source states one.+/// Footprint zones that carry a `keepout` block. A zone with no keepout is a+/// copper pour, which a library footprint does not ship, so only keepouts ride.+fn import_footprint_keepouts(root: &Sx) -> Vec<crate::model::Keepout> {+ let mut out = Vec::new();+ for z in root.children("zone") {+ let Some(k) = z.child("keepout") else { continue };+ let mut layers: Vec<String> = Vec::new();+ for key in ["layers", "layer"] {+ if let Some(l) = z.child(key) {+ for item in l.items().iter().skip(1) {+ if let Sx::Atom(a) = item { layers.push(a.trim_matches('"').to_string()); }+ }+ }+ }+ let not_allowed: Vec<String> = k.items().iter().skip(1)+ .filter(|c| c.atom_at(1) == Some("not_allowed"))+ .filter_map(|c| c.head().map(str::to_string))+ .collect();+ let mut points: Vec<[f64; 2]> = Vec::new();+ if let Some(pts) = z.child("polygon").and_then(|p| p.child("pts")) {+ let mut xys = Vec::new();+ pts.collect("xy", &mut xys);+ for xy in xys {+ let n = xy.nums();+ if n.len() >= 2 { points.push([n[0], n[1]]); }+ }+ }+ if points.len() >= 3 && !layers.is_empty() && !not_allowed.is_empty() {+ out.push(crate::model::Keepout { layers, points, not_allowed });+ }+ }+ out+}+ fn import_footprint_polys(root: &Sx) -> Vec<crate::model::FpPoly> { let mut out = Vec::new(); let mut polys = Vec::new();
crates/altium-codec/src/kicad_export.rs+9@@ -345,6 +345,15 @@ pub fn export_kicad_footprint_for(fp: &Footprint, ver: KicadVersion) -> String { } s.push_str(")\n"); }+ // Keepout areas ride back out as KiCad keepout zones.+ for k in &fp.keepouts {+ let layers: String = k.layers.iter().map(|l| format!(" \"{l}\"")).collect();+ let rule = |what: &str| if k.not_allowed.iter().any(|n| n == what) { "not_allowed" } else { "allowed" };+ let pts: String = k.points.iter().map(|p| format!(" (xy {} {})", n(p[0]), n(p[1]))).collect();+ s.push_str(&format!(+ "\t(zone (net 0) (net_name \"\") (layers{layers}) (hatch edge 0.5)\n\t\t(connect_pads (clearance 0))\n\t\t(min_thickness 0.25)\n\t\t(keepout (tracks {}) (vias {}) (pads {}) (copperpour {}) (footprints {}))\n\t\t(fill (thermal_gap 0.5) (thermal_bridge_width 0.5))\n\t\t(polygon (pts{pts})))\n",+ rule("tracks"), rule("vias"), rule("pads"), rule("copperpour"), rule("footprints")));+ } s.push_str(")\n"); s }
crates/altium-codec/src/lib.rs+11−7@@ -20,7 +20,7 @@ pub use altium_decode::{decode_altium, decode_altium_with, decode_intlib_part, e pub use intlib::{decode_intlib, encode_intlib}; pub use kicad::{import_kicad, import_kicad_with_pin_map}; pub use kicad_export::{export_kicad_footprint, export_kicad_symbol};-pub use model::{AdomLbrPart, BodyRect, ConnectEntry, Footprint, FpGraphic, FpLayer, Graphic, Label, Pad, Parameter, Pin, Symbol};+pub use model::{AdomLbrPart, BodyRect, ConnectEntry, Footprint, FpGraphic, FpLayer, Graphic, Keepout, Label, Pad, Parameter, Pin, Symbol}; pub use pcblib::{decode_pcblib, encode_pcblib, encode_pcblib_many, encode_pcblib_many_with_models, EmbeddedModel}; pub use schlib::{add_symbols_to_schlib, decode_schlib_first, encode_schlib}; @@ -58,7 +58,9 @@ mod tests { shape: "rect".into(), plated: None, mask_margin_mm: mask, paste_margin_mm: paste, paste_margin_ratio: None }; let fp = Footprint { name: "EXP".into(), graphics: vec![], polys: vec![], mask_margin_mm: Some(0.1), paste_margin_mm: None,- pads: vec![pad("1", 0.0, Some(-0.05), Some(-0.05)), pad("2", 2.0, None, None)] };+ pads: vec![pad("1", 0.0, Some(-0.05), Some(-0.05)), pad("2", 2.0, None, None)],+ keepouts: Vec::new(),+ }; let bytes = encode_pcblib(&fp).expect("encode"); let back = decode_altium(None, Some(&bytes), "EXP").expect("decode").footprint; let p1 = &back.pads[0];@@ -228,8 +230,8 @@ mod tests { use std::io::Read; let pad = Pad { number: "1".into(), x_mm: 0.0, y_mm: 0.0, w_mm: 1.0, h_mm: 1.0, drill_mm: 0.0, rotation: 0.0, shape: "rect".into(), plated: None, mask_margin_mm: None, paste_margin_mm: None, paste_margin_ratio: None };- let fp1 = Footprint { name: "WITHMODEL".into(), pads: vec![pad.clone()], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None };- let fp2 = Footprint { name: "BARE".into(), pads: vec![pad], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None };+ let fp1 = Footprint { name: "WITHMODEL".into(), pads: vec![pad.clone()], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() };+ let fp2 = Footprint { name: "BARE".into(), pads: vec![pad], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() }; let step = b"ISO-10303-21;\r\nHEADER;\r\nENDSEC;\r\nEND-ISO-10303-21;\r\n".to_vec(); let m = EmbeddedModel { name: "WITHMODEL.step".into(), step: step.clone(), rot_x: 0.0, rot_y: 0.0, rot_z: 0.0, dz_mil: 0.0, overall_height_mil: 0.0 };@@ -275,7 +277,7 @@ mod tests { let long = "JST_PH_B2B-PH-K_1x02_P2.00mm_Vertical"; let pad = Pad { number: "1".into(), x_mm: 0.0, y_mm: 0.0, w_mm: 1.0, h_mm: 1.0, drill_mm: 0.0, rotation: 0.0, shape: "rect".into(), plated: None, mask_margin_mm: None, paste_margin_mm: None, paste_margin_ratio: None };- let mk = |name: &str| Footprint { name: name.into(), pads: vec![pad.clone()], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None };+ let mk = |name: &str| Footprint { name: name.into(), pads: vec![pad.clone()], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() }; let bytes = encode_pcblib_many(&[mk(long), mk(&format!("{long}2"))]).expect("encode"); let mut comp = cfb::CompoundFile::open(std::io::Cursor::new(bytes)).unwrap(); let tops: Vec<String> = comp.read_root_storage().filter(|e| e.is_storage())@@ -394,8 +396,8 @@ mod tests { b.pins.push(Pin { number: "3".into(), name: "C".into(), x: -100, y: -300, length: Some(100), rotation: 0, electrical_type: None }); let sch = encode_schlib(&[a, b]).expect("encode schlib"); let pad = |n: &str, x: f64| Pad { number: n.into(), x_mm: x, y_mm: 0.0, w_mm: 1.0, h_mm: 1.0, drill_mm: 0.0, rotation: 0.0, shape: "rect".into(), plated: None, mask_margin_mm: None, paste_margin_mm: None, paste_margin_ratio: None };- let fpa = Footprint { name: "FPA".into(), pads: vec![pad("1", 0.0)], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None };- let fpb = Footprint { name: "FPB".into(), pads: vec![pad("1", 0.0), pad("2", 2.0)], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None };+ let fpa = Footprint { name: "FPA".into(), pads: vec![pad("1", 0.0)], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() };+ let fpb = Footprint { name: "FPB".into(), pads: vec![pad("1", 0.0), pad("2", 2.0)], graphics: vec![], polys: vec![], mask_margin_mm: None, paste_margin_mm: None, keepouts: Vec::new() }; let pcb = encode_pcblib_many(&[fpa, fpb]).expect("encode pcblib"); let pb = decode_altium(Some(&sch), Some(&pcb), "PARTB").expect("decode PARTB");@@ -435,6 +437,7 @@ mod tests { line(FpLayer::Courtyard, 3.0), line(FpLayer::Copper, 4.0), ],+ keepouts: Vec::new(), }; let bytes = encode_pcblib(&fp).expect("encode"); let part = decode_altium(None, Some(&bytes), "LAYERFP").expect("decode");@@ -522,6 +525,7 @@ mod tests { polys: vec![], mask_margin_mm: None, paste_margin_mm: None,+ keepouts: Vec::new(), }; let bytes = encode_pcblib(&fp).expect("encode"); let decoded = decode_pcblib(&bytes).expect("decode our own output");
crates/altium-codec/src/model.rs+15@@ -315,6 +315,21 @@ pub struct Footprint { /// Footprint-level solder-paste margin default in mm. #[serde(default, skip_serializing_if = "Option::is_none")] pub paste_margin_mm: Option<f64>,+ /// Keepout areas (KiCad `zone` with a `keepout` block): copper-free strips+ /// such as an isolated part's creepage gap. Optional field, so binaries+ /// that predate it skip it.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub keepouts: Vec<Keepout>,+}++/// A keepout area on a footprint, vertices in mm, Y-down neutral.+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]+pub struct Keepout {+ /// KiCad copper layer names as written: "F.Cu", "B.Cu", "In1.Cu", "*.Cu", "F&B.Cu".+ pub layers: Vec<String>,+ pub points: Vec<[f64; 2]>,+ /// What may not enter: any of tracks, vias, pads, copperpour, footprints.+ pub not_allowed: Vec<String>, } /// A filled polygon on a footprint layer, vertices in mm, Y-down neutral.
package.json+1−1@@ -1,6 +1,6 @@ { "slug": "adom-lbr",- "version": "2.47.6",+ "version": "2.47.7", "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+1−1@@ -1,6 +1,6 @@ { "slug": "adom-lbr",- "version": "2.47.6",+ "version": "2.47.7", "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": {},
src/main.rs+153−15@@ -1495,6 +1495,7 @@ fn emit_variant_package(xml: &mut String, km: &str, name: &str, description: &st } } xml.push_str(&package_graphics(km));+ xml.push_str(&keepout_eagle_xml(km)); xml.push_str("</package>\n"); groups }@@ -2458,6 +2459,7 @@ pub(crate) fn generate_lbr_gates(sym: &ParsedSymbol, fp_content: Option<&str>, s } else { xml.push_str(&silk); }+ xml.push_str(&keepout_eagle_xml(km)); let mut top = sy2; let mut bot = sy1; for p in &mod_pads {@@ -3210,7 +3212,11 @@ impl LostFeature { /// policy: the human WARN on stderr (the shape people already read), and the /// structured LOST: json line on stdout for the wiki export workers. fn report_lost(l: &LostFeature) {- eprintln!("WARN: [{}] pads {} carry {}; {}.", l.code, l.pad_list(), l.feature, l.effect);+ if l.pads.is_empty() {+ eprintln!("WARN: [{}] {} carries {}; {}.", l.code, l.part, l.feature, l.effect);+ } else {+ eprintln!("WARN: [{}] pads {} carry {}; {}.", l.code, l.pad_list(), l.feature, l.effect);+ } println!("LOST: {}", l.json()); } @@ -3218,7 +3224,7 @@ fn report_lost(l: &LostFeature) { /// is actually lost. Pure on `strict` (not the global) so tests cannot race. fn strict_refusal(strict: bool, lane: &str, lost: &[LostFeature]) -> Option<String> { if !strict || lost.is_empty() { return None; }- let what: Vec<String> = lost.iter().map(|l| format!("{} on pads {}", l.feature, l.pad_list())).collect();+ let what: Vec<String> = lost.iter().map(|l| if l.pads.is_empty() { l.feature.clone() } else { format!("{} on pads {}", l.feature, l.pad_list()) }).collect(); Some(format!("nothing written for the {lane} lane: refused under --strict: {}", what.join("; "))) } @@ -3264,6 +3270,88 @@ fn altium_lost_feature(part: &str, fp: &altium_codec::Footprint) -> Option<LostF }) } +/// One line per keepout: its layers and what it keeps out.+fn keepout_summary(k: &altium_codec::Keepout) -> String {+ format!("keepout on {} (no {})", k.layers.join("+"), k.not_allowed.join("/"))+}++/// The Altium lane has no keepout Region record yet (it ships only byte-calibrated+/// records), so every keepout area is a named loss there.+fn altium_keepout_lost(part: &str, fp: &altium_codec::Footprint) -> Option<LostFeature> {+ if fp.keepouts.is_empty() { return None; }+ Some(LostFeature {+ code: "lost-keepout",+ part: part.to_string(),+ feature: fp.keepouts.iter().map(keepout_summary).collect::<Vec<_>>().join("; "),+ pads: vec![],+ effect: "the Altium lane does not write keepout regions yet, so the PcbLib ships without them; draw the keepout in Altium before routing near this part".into(),+ })+}++fn altium_losses(part: &str, fp: &altium_codec::Footprint) -> Vec<LostFeature> {+ altium_lost_feature(part, fp).into_iter().chain(altium_keepout_lost(part, fp)).collect()+}++/// KiCad keepout zones in a .kicad_mod, read for the EAGLE lane.+fn mod_keepouts(km: &str) -> Vec<altium_codec::Keepout> {+ let na = regex_lite::Regex::new(r"\((tracks|vias|pads|copperpour|footprints)\s+not_allowed\)").unwrap();+ let lay = regex_lite::Regex::new(r#"\(layers?((?:\s+"?[^\s()"]+"?)+)\)"#).unwrap();+ let xy = regex_lite::Regex::new(r"\(xy\s+([-\d.eE+]+)\s+([-\d.eE+]+)\)").unwrap();+ sexpr_blocks(km, "zone").into_iter().filter(|z| z.contains("(keepout")).filter_map(|z| {+ let layers: Vec<String> = lay.captures(z).map(|c| c[1].split_whitespace().map(|t| t.trim_matches('"').to_string()).collect()).unwrap_or_default();+ let not_allowed: Vec<String> = na.captures_iter(z).map(|c| c[1].to_string()).collect();+ let poly = z.find("(polygon").map(|i| &z[i..]).unwrap_or("");+ let points: Vec<[f64; 2]> = xy.captures_iter(poly).filter_map(|c| Some([c[1].parse().ok()?, c[2].parse().ok()?])).collect();+ (points.len() >= 3 && !layers.is_empty() && !not_allowed.is_empty()).then_some(altium_codec::Keepout { layers, points, not_allowed })+ }).collect()+}++/// EAGLE has restrict layers for the outer copper (41 tRestrict, 42 bRestrict), vias+/// (43 vRestrict) and parts (39 tKeepout, 40 bKeepout), and none for inner copper.+/// Returns (layer numbers, true when an inner-layer restriction is dropped).+fn keepout_eagle_layers(k: &altium_codec::Keepout) -> (Vec<u32>, bool) {+ let has = |w: &str| k.not_allowed.iter().any(|n| n == w);+ let any_l = |f: &dyn Fn(&str) -> bool| k.layers.iter().any(|l| f(l));+ let top = any_l(&|l| l == "F.Cu" || l == "*.Cu" || l == "F&B.Cu");+ let bot = any_l(&|l| l == "B.Cu" || l == "*.Cu" || l == "F&B.Cu");+ let inner = any_l(&|l| l == "*.Cu" || (l.starts_with("In") && l.ends_with(".Cu")));+ let copper = has("tracks") || has("pads") || has("copperpour");+ let mut out = Vec::new();+ if copper && top { out.push(41); }+ if copper && bot { out.push(42); }+ if has("vias") { out.push(43); }+ if has("footprints") && (top || !bot) { out.push(39); }+ if has("footprints") && bot { out.push(40); }+ (out, copper && inner)+}++fn keepout_eagle_xml(km: &str) -> String {+ let mut xml = String::new();+ for k in mod_keepouts(km) {+ for layer in keepout_eagle_layers(&k).0 {+ xml.push_str(&format!(" <polygon width=\"0.127\" layer=\"{layer}\">\n"));+ for p in &k.points {+ xml.push_str(&format!(" <vertex x=\"{:.4}\" y=\"{:.4}\"/>\n", p[0], -p[1]));+ }+ xml.push_str(" </polygon>\n");+ }+ }+ xml+}++fn eagle_keepout_lost(part: &str, kms: &[&str]) -> Option<LostFeature> {+ let lost: Vec<String> = kms.iter().flat_map(|km| mod_keepouts(km)).filter(|k| keepout_eagle_layers(k).1)+ .map(|k| keepout_summary(&k)).collect();+ if lost.is_empty() { return None; }+ Some(LostFeature {+ code: "lost-keepout",+ part: part.to_string(),+ feature: format!("inner-layer copper restriction ({})", lost.join("; ")),+ pads: vec![],+ effect: "EAGLE restrict layers cover top and bottom copper and vias only, so the keepout is written there and inner layers are not restricted; check inner-layer routing in Fusion".into(),+ })+}+ /// Pin/pad agreement for an imported part. A symbol whose pins do not all land /// on pads, or a footprint with far more pads than the symbol has pins, is the /// shape of a wrong pairing (a 32-pin symbol on a 100-pad footprint, wiki #28).@@ -3586,7 +3674,9 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or // Losses are decided here, once, before anything is linted or // written: the parser only collected the margin pads.- let lost: Vec<LostFeature> = eagle_lost_feature(&parsed.name, eagle_margin_drain()).into_iter().collect();+ let kms: Vec<&str> = fp_content.as_deref().into_iter().chain(pkg_variants.iter().map(|v| v.km.as_str())).collect();+ let lost: Vec<LostFeature> = eagle_lost_feature(&parsed.name, eagle_margin_drain()).into_iter()+ .chain(eagle_keepout_lost(&parsed.name, &kms)).collect(); for l in &lost { report_lost(l); } if let Some(why) = strict_refusal(cli.strict, "EAGLE/Fusion", &lost) { eprintln!("ERROR: [LOST_FEATURES] {why}");@@ -3880,7 +3970,7 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or Commands::ExportAltium { part, out_dir } => { let p = load_part(&part);- let lost: Vec<LostFeature> = altium_lost_feature(&p.mpn, &p.footprint).into_iter().collect();+ let lost: Vec<LostFeature> = altium_losses(&p.mpn, &p.footprint); for l in &lost { report_lost(l); } if let Some(why) = strict_refusal(cli.strict, "Altium", &lost) { eprintln!("ERROR: [LOST_FEATURES] {why}");@@ -3937,17 +4027,16 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or }; let mut sym = p.symbol.clone(); seed_parameters(&mut sym, &p);- if let Some(l) = altium_lost_feature(&p.mpn, &p.footprint) {- report_lost(&l);- if let Some(why) = strict_refusal(cli.strict, "Altium", std::slice::from_ref(&l)) {- // Under --strict the part is refused, the rest still- // assemble; the loss stays a NAMED entry, never silent.- skipped.push(json!({"part": path.display().to_string(), "reason": why}));- refused.push(l.json());- continue;- }- lost_features.push(l.json());+ let losses = altium_losses(&p.mpn, &p.footprint);+ for l in &losses { report_lost(l); }+ if let Some(why) = strict_refusal(cli.strict, "Altium", &losses) {+ // Under --strict the part is refused, the rest still+ // assemble; the loss stays a NAMED entry, never silent.+ skipped.push(json!({"part": path.display().to_string(), "reason": why}));+ for l in &losses { refused.push(l.json()); }+ continue; }+ for l in &losses { lost_features.push(l.json()); } // The component a user picks in Altium is the ORDERABLE part, // so it takes the MPN (the deviceset=MPN doctrine); the source // symbol name is often a shared class name like Conn_01x02.@@ -4067,7 +4156,7 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or Commands::ExportIntlib { part, out } => { let p = load_part(&part);- let lost: Vec<LostFeature> = altium_lost_feature(&p.mpn, &p.footprint).into_iter().collect();+ let lost: Vec<LostFeature> = altium_losses(&p.mpn, &p.footprint); for l in &lost { report_lost(l); } if let Some(why) = strict_refusal(cli.strict, "Altium", &lost) { eprintln!("ERROR: [LOST_FEATURES] {why}");@@ -5291,3 +5380,52 @@ mod pin_semantics_tests { } } }++#[cfg(test)]+mod keepout_tests {+ use super::*;+ const FP: &str = include_str!("../tests/fixtures/keepout/repro4.kicad_mod");+ const SYM: &str = include_str!("../tests/fixtures/keepout/repro4.kicad_sym");++ #[test]+ fn keepouts_ride_the_hub_and_round_trip_through_kicad() {+ let part = altium_codec::import_kicad(SYM, FP, "REPRO4").unwrap();+ let k = &part.footprint.keepouts;+ assert_eq!(k.len(), 1);+ assert_eq!(k[0].layers, vec!["F.Cu", "B.Cu"]);+ assert_eq!(k[0].not_allowed, vec!["tracks", "vias", "pads", "copperpour"]);+ assert_eq!(k[0].points.len(), 4);+ let again = altium_codec::kicad_export::export_kicad_footprint(&part.footprint);+ let back = altium_codec::import_kicad(SYM, &again, "REPRO4").unwrap();+ assert_eq!(back.footprint.keepouts, part.footprint.keepouts);+ }++ #[test]+ fn the_altium_lane_names_the_keepout_as_lost_and_strict_refuses() {+ let part = altium_codec::import_kicad(SYM, FP, "REPRO4").unwrap();+ let lost = altium_losses(&part.mpn, &part.footprint);+ assert!(lost.iter().any(|l| l.code == "lost-keepout" && l.feature.contains("F.Cu+B.Cu")), "{:?}", lost.iter().map(|l| l.json()).collect::<Vec<_>>());+ assert!(strict_refusal(true, "Altium", &lost).is_some());+ let mut bare = part.footprint.clone();+ bare.keepouts.clear();+ assert!(altium_losses("P", &bare).is_empty(), "no keepout, no loss");+ }++ #[test]+ fn generate_writes_restrict_polygons_and_names_inner_layer_loss() {+ let sym = parse_kicad_sym(SYM, None).unwrap();+ let xml = generate_lbr(&sym, Some(FP), None, 0.38, &Default::default(), &[]).unwrap();+ for layer in ["41", "42", "43"] {+ assert!(xml.contains(&format!(r#"<polygon width="0.127" layer="{layer}">"#)), "layer {layer} missing");+ }+ assert!(!xml.contains(r#"layer="39""#), "footprints were allowed, so no tKeepout");+ assert!(lint_lbr(&xml).errors.is_empty(), "{:?}", lint_lbr(&xml).errors);+ assert!(eagle_keepout_lost("R", &[FP]).is_none(), "F.Cu + B.Cu is fully representable");+ let all = FP.replace(r#"(layers "F.Cu" "B.Cu")"#, r#"(layers "*.Cu")"#);+ assert!(eagle_keepout_lost("R", &[&all]).is_some(), "inner layers cannot be restricted in EAGLE");+ let only_vias = altium_codec::Keepout { layers: vec!["F.Cu".into()], points: vec![], not_allowed: vec!["vias".into()] };+ assert_eq!(keepout_eagle_layers(&only_vias).0, vec![43]);+ let parts = altium_codec::Keepout { layers: vec!["B.Cu".into()], points: vec![], not_allowed: vec!["footprints".into()] };+ assert_eq!(keepout_eagle_layers(&parts).0, vec![40]);+ }+}
tests/fixtures/keepout/repro4.kicad_modadded+12@@ -0,0 +1,12 @@+(footprint "REPRO4" (version 20240108) (generator "repro") (layer "F.Cu")+ (pad "1" smd rect (at -3 -0.635) (size 1 0.5) (layers "F.Cu" "F.Paste" "F.Mask"))+ (pad "2" smd rect (at -3 0.635) (size 1 0.5) (layers "F.Cu" "F.Paste" "F.Mask"))+ (pad "3" smd rect (at 3 0.635) (size 1 0.5) (layers "F.Cu" "F.Paste" "F.Mask"))+ (pad "4" smd rect (at 3 -0.635) (size 1 0.5) (layers "F.Cu" "F.Paste" "F.Mask"))+ (zone (net 0) (net_name "") (layers "F.Cu" "B.Cu") (hatch edge 0.5)+ (connect_pads (clearance 0))+ (min_thickness 0.25)+ (keepout (tracks not_allowed) (vias not_allowed) (pads not_allowed) (copperpour not_allowed) (footprints allowed))+ (fill (thermal_gap 0.5) (thermal_bridge_width 0.5))+ (polygon (pts (xy -1.5 -2) (xy 1.5 -2) (xy 1.5 2) (xy -1.5 2))))+)
tests/fixtures/keepout/repro4.kicad_symadded+50@@ -0,0 +1,50 @@+(kicad_symbol_lib+ (version 20231120)+ (generator "adom")+ (symbol "REPRO4"+ (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" "REPRO4"+ (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" "2-column symbol."+ (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" "REPRO4"+ (at 0 -24.86 0)+ (effects (font (size 1.27 1.27)) (hide yes))+ )+ (symbol "REPRO4_0_1"+ (rectangle (start -12.70 2.54) (end 12.70 -7.08)+ (stroke (width 0.254) (type default))+ (fill (type background))+ )+ )+ (symbol "REPRO4_1_1"+ (pin input line (at -15.24 -2.00 0) (length 2.54) (name "A") (number "1"))+ (pin input line (at -15.24 -4.54 0) (length 2.54) (name "B") (number "2"))+ (pin output line (at 15.24 -2.00 180) (length 2.54) (name "Y") (number "3"))+ (pin output line (at 15.24 -4.54 180) (length 2.54) (name "Z") (number "4"))+ )+ )+)