← Commit history

2.47.13: assemble-altium shares a footprint only when the 3D model matches too; GH 3e1f1ed

Colby Knox ·664caba690 · ·parent 4368490
8 files changed +62−20
CHANGELOG.md+3
@@ -1,5 +1,8 @@ # Changelog +## 2.47.13 (2026-12-03)+- `assemble-altium` no longer gives parts on a common package the first part's 3D model. Parts share one footprint only when the land pattern and the 3D model bytes both match. A part with the same land pattern but its own model (or no model) gets its own footprint named `<footprint>_<MPN>`, listed in `renamed` with the reason, for example "same footprint as LM317, with this part's own 3D model". Before, five TO-220 regulators and four SOIC-8 parts came out with 2 footprints and 2 bodies; now 9 and 9. `deduped` lists only true folds. A footprint name used by different geometry is also renamed `<name>_<MPN>` (it was `<name>@2`).+ ## 2.47.12 (2026-11-13) - `assemble-altium --out` keeps every dot in the base name. `--out "Rev 1.2"` writes `Rev 1.2.SchLib` and `Rev 1.2.PcbLib`; it used to cut at the last dot and write `Rev 1.SchLib`, and a name like `parts_2.47.11` lost two segments. Only a `.SchLib`, `.PcbLib` or `.IntLib` already on the base is replaced. 
Cargo.lock+1−1
@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"  [[package]] name = "adom-lbr"-version = "2.47.12"+version = "2.47.13" dependencies = [  "altium-codec",  "anyhow",
Cargo.toml+1−1
@@ -1,6 +1,6 @@ [package] name = "adom-lbr"-version = "2.47.12"+version = "2.47.13" 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.12+2.47.13
bin/adom-lbr
⋯ 1 unchanged line ⋯
package.json+1−1
@@ -1,6 +1,6 @@ {   "slug": "adom-lbr",-  "version": "2.47.12",+  "version": "2.47.13",   "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.12",+  "version": "2.47.13",   "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+53−14
@@ -299,8 +299,9 @@ enum Commands {     },     /// Assemble MANY adom-lbr JSONs into ONE native Altium library pair:     /// <out>.SchLib holding every symbol (components named by MPN) and-    /// <out>.PcbLib holding every footprint, content-deduped so N parts-    /// sharing a land pattern share one footprint. Prints a JSON report+    /// <out>.PcbLib holding every footprint. Parts share one footprint only when+    /// the land pattern AND the 3D model bytes match; a part with its own model+    /// gets <footprint>_<MPN>, listed in renamed[] with the reason. Prints a JSON report     /// (schlib, pcblib, components, footprints, deduped[], renamed[],     /// skipped[]) for machine callers; skips are always NAMED, never silent,     /// and a partial library still ships. Exit 2 only when nothing assembled.@@ -313,9 +314,9 @@ enum Commands {         /// Paths to adom-lbr JSONs (one per part)         #[arg(required = true)]         parts: Vec<PathBuf>,-        /// Keep one footprint PER PART even when two parts share a land pattern-        /// (each part then carries its own 3D body and its symbol links its own-        /// footprint name). Default: identical patterns collapse to one footprint.+        /// Keep the source footprint name in the sharing key, so parts fold only when+        /// name, land pattern and 3D model all match. Default: name is ignored, and+        /// parts with the same land pattern and the same model share one footprint.         #[arg(long)]         no_dedupe: bool,     },@@ -3505,6 +3506,12 @@ fn eagle_keepout_lost(part: &str, kms: &[&str]) -> Option<LostFeature> {     }) } +/// `want`, else `want_2`, `want_3`, ...: the first not already taken.+fn unique_suffixed(taken: &std::collections::BTreeSet<String>, want: &str) -> String {+    if !taken.contains(want) { return want.to_string(); }+    (2..).map(|i| format!("{want}_{i}")).find(|c| !taken.contains(c)).unwrap()+}+ /// `<base>.<ext>` for an assemble-altium `--out` base. Only an Altium library /// extension already on the base is replaced; any other dot is part of the name, /// so "Rev 1.2" and "parts_2.47.11" keep every character (with_extension cut both@@ -4174,6 +4181,13 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or             let mut lost_features: Vec<Value> = Vec::new();             let mut refused: Vec<Value> = Vec::new();             let mut fp_by_content: BTreeMap<String, String> = BTreeMap::new();+            // Geometry alone -> (first footprint with it, its part): a later part on the+            // same land pattern but a different 3D model gets its own footprint, and the+            // rename says whose geometry it repeats.+            let mut fp_by_geometry: BTreeMap<String, (String, String)> = BTreeMap::new();+            // Model file name -> its bytes' sha256, so a name reused by different bytes+            // is qualified rather than overwriting the first part's body.+            let mut model_names: BTreeMap<String, String> = BTreeMap::new();             let mut fp_shared: BTreeMap<String, Vec<String>> = BTreeMap::new();             let mut fp_names: BTreeSet<String> = BTreeSet::new();             let mut comp_names: BTreeSet<String> = BTreeSet::new();@@ -4217,7 +4231,7 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or                 // Footprint content-dedup: same geometry = one footprint.                 let mut content_probe = p.footprint.clone();                 content_probe.name = if no_dedupe { p.footprint.name.clone() } else { String::new() };-                let key = serde_json::to_string(&content_probe).unwrap_or_default();+                let geometry_key = serde_json::to_string(&content_probe).unwrap_or_default();                 // The part's STEP body (wiki adom-lbr#22): model_3d as a path                 // (relative to the JSON), else <mpn>.step beside it. A missing                 // model is a NAMED report entry, never silent.@@ -4253,23 +4267,37 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or                     }),                     Err(e) => { model_missing.push(json!({"part": p.mpn, "reason": format!("read {}: {e}", sp.display())})); None }                 });+                // Parts fold onto one footprint only when the land pattern AND the 3D model+                // are the same: wiki parts carry STEP bodies etched with their own MPN, and+                // folding on geometry alone gave every part on a TO-220 or SOIC-8 the first+                // part's body. "none" keeps a model-less part off a footprint with a body.+                let model_hash = part_model.as_ref()+                    .map(|m| { use sha2::{Digest, Sha256}; format!("{:x}", Sha256::digest(&m.step)) })+                    .unwrap_or_else(|| "none".into());+                let key = format!("{geometry_key}\u{0}{model_hash}");                 if part_model.is_none() && model_missing.iter().all(|m| m["part"] != json!(p.mpn.clone())) {                     model_missing.push(json!({"part": p.mpn,                         "reason": "no 3D model: model_3d is empty and no <mpn>.step sits beside the JSON"}));                 }                 let fp_name = if let Some(existing) = fp_by_content.get(&key) {                     fp_shared.entry(existing.clone()).or_default().push(p.mpn.clone());-                    // A later part can supply the model its shared footprint lacks.-                    if let (Some(i), Some(m)) = (fp_index.get(existing), part_model) {-                        if models[*i].is_none() { models[*i] = Some(m); }-                    }                     existing.clone()                 } else {                     let want_fp = if p.footprint.name.is_empty() { format!("{}-fp", p.mpn) } else { p.footprint.name.clone() };-                    let n = unique(&fp_names, &want_fp);-                    if n != want_fp {-                        renamed.push(json!({"kind": "footprint", "from": want_fp, "to": n, "part": p.mpn}));-                    }+                    let n = if fp_names.contains(&want_fp) {+                        let base = format!("{want_fp}_{}", part_file_stem(&p.mpn));+                        let n = unique_suffixed(&fp_names, &base);+                        let reason = match fp_by_geometry.get(&geometry_key) {+                            Some((_, first)) if part_model.is_some() => format!("same footprint as {first}, with this part's own 3D model"),+                            Some((_, first)) => format!("same footprint as {first}, which has a 3D model this part does not"),+                            None => "a different footprint already has this name".to_string(),+                        };+                        renamed.push(json!({"kind": "footprint", "from": want_fp, "to": n, "part": p.mpn, "reason": reason}));+                        n+                    } else {+                        want_fp+                    };+                    fp_by_geometry.entry(geometry_key.clone()).or_insert((n.clone(), p.mpn.clone()));                     fp_names.insert(n.clone());                     fp_by_content.insert(key, n.clone());                     fp_shared.insert(n.clone(), vec![p.mpn.clone()]);@@ -4277,6 +4305,17 @@ The geometry is fine but a BOM cannot order this part - pass --part-metadata or                     f.name = n.clone();                     fp_index.insert(n.clone(), fps.len());                     fps.push(f);+                    let part_model = part_model.map(|mut m| {+                        if model_names.get(&m.name).is_some_and(|h| *h != model_hash) {+                            let stem = m.name.trim_end_matches(".step").to_string();+                            let to = (2..).map(|i| format!("{stem}_{i}.step")).find(|c| !model_names.contains_key(c)).unwrap();+                            renamed.push(json!({"kind": "model", "from": m.name, "to": to, "part": p.mpn,+                                "reason": "another part's different 3D model already has this name"}));+                            m.name = to;+                        }+                        model_names.insert(m.name.clone(), model_hash.clone());+                        m+                    });                     models.push(part_model);                     n                 };