← Commit history

Merge PR #624: 0.2.121: Altium-import and round-board fixes (#268, #269, #270); Fields 0.10.15 note (release-0.2.121 -> main) merge

Colby Knox ·16d764123d · ·parents 1a4edf2, 0cbd65f

Showing changes introduced by the merge (against its first parent).

12 files changed +346−20
Cargo.lock+33−10
@@ -4,7 +4,7 @@ version = 4  [[package]] name = "adom-aiflow"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-analyze",  "aiflow-board",@@ -15,9 +15,11 @@ dependencies = [  "aiflow-pours",  "aiflow-router",  "aiflow-run",+ "base64",  "clap",  "notify",  "regex-lite",+ "ruzstd",  "serde",  "serde_json",  "sha2",@@ -25,7 +27,7 @@ dependencies = [  [[package]] name = "aiflow-analyze"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "serde",@@ -35,7 +37,7 @@ dependencies = [  [[package]] name = "aiflow-board"-version = "0.2.120"+version = "0.2.121" dependencies = [  "roxmltree",  "serde",@@ -44,7 +46,7 @@ dependencies = [  [[package]] name = "aiflow-bridge"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "serde",@@ -53,7 +55,7 @@ dependencies = [  [[package]] name = "aiflow-copper"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -63,7 +65,7 @@ dependencies = [  [[package]] name = "aiflow-grid"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "serde",@@ -72,7 +74,7 @@ dependencies = [  [[package]] name = "aiflow-place"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "serde",@@ -81,7 +83,7 @@ dependencies = [  [[package]] name = "aiflow-pours"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "aiflow-copper",@@ -91,7 +93,7 @@ dependencies = [  [[package]] name = "aiflow-router"-version = "0.2.120"+version = "0.2.121" dependencies = [  "aiflow-board",  "aiflow-grid",@@ -102,7 +104,7 @@ dependencies = [  [[package]] name = "aiflow-run"-version = "0.2.120"+version = "0.2.121" dependencies = [  "serde",  "serde_json",@@ -158,6 +160,12 @@ dependencies = [  "windows-sys 0.61.2", ] +[[package]]+name = "base64"+version = "0.22.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"+ [[package]] name = "bitflags" version = "2.13.2"@@ -424,6 +432,15 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" +[[package]]+name = "ruzstd"+version = "0.8.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a7c1c839d570d835527c9a5e4db7cb2198683a988cb9d7293fc8674e6bd58fc8"+dependencies = [+ "twox-hash",+]+ [[package]] name = "same-file" version = "1.0.6"@@ -504,6 +521,12 @@ dependencies = [  "unicode-ident", ] +[[package]]+name = "twox-hash"+version = "2.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "86a801b3cea342a06d468c8710662aa29e5e05e4f5c0d62f00bbb7f2ad7941c2"+ [[package]] name = "typenum" version = "1.20.1"
Cargo.toml+1−1
@@ -14,7 +14,7 @@ members = [ ]  [workspace.package]-version = "0.2.120"+version = "0.2.121" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
bin/adom-aiflow
⋯ 1 unchanged line ⋯
crates/adom-aiflow/Cargo.toml+3
@@ -25,4 +25,7 @@ aiflow-bridge = { workspace = true }  sha2 = "0.10" regex-lite = "0.1"+# issue #268: KiCad 10 footprint-embedded 3D models are base64 of zstd (`(data |KLUv...|)`)+base64 = "0.22"+ruzstd = "0.8" notify = "8"
crates/adom-aiflow/src/embedded_models.rsadded+146
@@ -0,0 +1,146 @@+//! Issue #268 (King Silver): KiCad 10 keeps a footprint's 3D model inside the footprint (or the board) when it was+//! embedded, as KiCad's Altium importer does: `(embedded_files (file (name "x.step") (type model) (data |KLUv...|)))`,+//! the model path `kicad-embed://x.step`. The data is base64 of zstd. Such a model is resolved when its file is+//! there; the orientation check reads its size from the embedded bytes, written once into the run.+use aiflow_board::{sx::Node, Board};+use base64::Engine;+use std::collections::BTreeMap;+use std::io::Read;+use std::path::{Path, PathBuf};++pub const PREFIX: &str = "kicad-embed://";++/// The embedded files of one `embedded_files` node: name -> base64 text.+fn files_of(n: &Node) -> BTreeMap<String, String> {+    let mut out = BTreeMap::new();+    for ef in n.find_all("embedded_files") {+        for f in ef.find_all("file") {+            let Some(name) = f.find("name").and_then(|x| x.value()) else { continue };+            let data: String = f.find("data").map(|d| (1..).map_while(|k| d.atom(k)).collect::<Vec<_>>().concat()).unwrap_or_default();+            out.insert(name.to_string(), data.replace(['|', ' ', '\t', '\n', '\r'], ""));+        }+    }+    out+}++/// Every embedded file a footprint may name: its own (by reference) and the board's.+pub struct Embedded { by_ref: BTreeMap<String, BTreeMap<String, String>>, board: BTreeMap<String, String> }++impl Embedded {+    pub fn of(board: &Board) -> Embedded {+        let mut by_ref = BTreeMap::new();+        for fp in board.root.find_all("footprint") {+            let Some(r) = aiflow_board::reference_of(fp) else { continue };+            let f = files_of(fp);+            if !f.is_empty() { by_ref.insert(r, f); }+        }+        // the board's own embedded files: an `embedded_files` directly under kicad_pcb+        let mut board_files = BTreeMap::new();+        for ef in board.root.nodes().filter(|n| n.tag == "embedded_files") {+            for f in ef.find_all("file") {+                let Some(name) = f.find("name").and_then(|x| x.value()) else { continue };+                let data: String = f.find("data").map(|d| (1..).map_while(|k| d.atom(k)).collect::<Vec<_>>().concat()).unwrap_or_default();+                board_files.insert(name.to_string(), data.replace(['|', ' ', '\t', '\n', '\r'], ""));+            }+        }+        Embedded { by_ref, board: board_files }+    }++    /// The base64 of `kicad-embed://name` for this reference, its footprint's first, then the board's.+    fn data(&self, reference: &str, path: &str) -> Option<&String> {+        let name = path.strip_prefix(PREFIX)?;+        self.by_ref.get(reference).and_then(|f| f.get(name)).or_else(|| self.board.get(name)).filter(|d| !d.is_empty())+    }++    /// Whether this embedded model is in the board file.+    pub fn present(&self, reference: &str, path: &str) -> bool { self.data(reference, path).is_some() }++    /// The embedded model written as a file into `dir` (once; the same bytes are not decoded again), for its size.+    pub fn extract(&self, reference: &str, path: &str, dir: &Path) -> Result<PathBuf, String> {+        let data = self.data(reference, path).ok_or_else(|| format!("{path} is not embedded in {reference} or the board"))?;+        let name = path.strip_prefix(PREFIX).unwrap_or(path).replace(['/', '\\'], "_");+        let tag: String = data.chars().take(24).filter(|c| c.is_ascii_alphanumeric()).collect();+        let out = dir.join(format!("{}-{name}", &tag[..tag.len().min(12)]));+        if out.is_file() { return Ok(out); }+        let bytes = decode(data)?;+        std::fs::create_dir_all(dir).map_err(|e| e.to_string())?;+        std::fs::write(&out, bytes).map_err(|e| e.to_string())?;+        Ok(out)+    }+}++/// base64, then zstd when the bytes carry zstd's magic number (KiCad compresses every embedded file).+pub fn decode(b64: &str) -> Result<Vec<u8>, String> {+    let raw = base64::engine::general_purpose::STANDARD.decode(b64.as_bytes()).map_err(|e| format!("embedded data is not base64: {e}"))?;+    if raw.starts_with(&[0x28, 0xB5, 0x2F, 0xFD]) {+        let mut d = ruzstd::decoding::StreamingDecoder::new(raw.as_slice()).map_err(|e| format!("embedded data does not decompress: {e}"))?;+        let mut out = Vec::new();+        d.read_to_end(&mut out).map_err(|e| format!("embedded data does not decompress: {e}"))?;+        Ok(out)+    } else { Ok(raw) }+}++/// The bridge's "missing model" lines ("<footprint> (<refs>): <model>, <model>") without the embedded models the board+/// file does carry; and how many models that took off.+pub fn drop_present(missing: Vec<String>, emb: &Embedded) -> (Vec<String>, u64) {+    let mut gone_total = 0u64;+    let mut out = Vec::new();+    for m in missing {+        let Some((head, models)) = m.split_once("): ") else { out.push(m); continue };+        let refs: Vec<&str> = head.rsplit_once(" (").map(|(_, r)| r.split(',').map(str::trim).collect()).unwrap_or_default();+        let list: Vec<&str> = models.split(", ").collect();+        let keep: Vec<&str> = list.iter().copied().filter(|p| !(p.starts_with(PREFIX) && refs.iter().any(|r| emb.present(r, p)))).collect();+        gone_total += (list.len() - keep.len()) as u64;+        if !keep.is_empty() { out.push(format!("{head}): {}", keep.join(", "))); }+    }+    (out, gone_total)+}++#[cfg(test)]+mod tests {+    use super::*;++    /// A footprint carrying its STEP inside, KiCad 10's way (zstd frame, base64, `|...|`), and the board's own.+    fn board(embedded_step: &str) -> Board {+        let b64 = |bytes: &[u8]| base64::engine::general_purpose::STANDARD.encode(bytes);+        // a stored (raw-block) zstd frame of `embedded_step`: magic, frame header (single segment, 1-byte size), raw block+        let mut z = vec![0x28, 0xB5, 0x2F, 0xFD, 0x20, embedded_step.len() as u8];+        let n = embedded_step.len() as u32;+        let hdr = (n << 3) | 1; // last block, raw+        z.extend_from_slice(&[(hdr & 0xff) as u8, ((hdr >> 8) & 0xff) as u8, ((hdr >> 16) & 0xff) as u8]);+        z.extend_from_slice(embedded_step.as_bytes());+        let data = b64(&z);+        let (a, b) = data.split_at(data.len() / 2);+        Board::from_text("t.kicad_pcb", format!(r#"(kicad_pcb (version 20260101) (layers (0 "F.Cu" signal) (25 "Edge.Cuts" user))+  (gr_rect (start 0 0) (end 20 10) (layer "Edge.Cuts"))+  (footprint "Imported:LED" (layer "F.Cu") (at 5 5) (property "Reference" "D1")+    (pad "1" smd rect (at 0 0) (size 1 1) (layers "F.Cu"))+    (model "kicad-embed://led.step")+    (embedded_files (file (name "led.step") (type model) (data |{a}+      {b}|) (checksum "x"))))+  (footprint "Imported:R" (layer "F.Cu") (at 9 5) (property "Reference" "R1")+    (pad "1" smd rect (at 0 0) (size 1 1) (layers "F.Cu"))+    (model "kicad-embed://board-level.step"))+  (embedded_files (file (name "board-level.step") (type model) (data |{}|))))"#, b64(b"ISO-10303-21; raw"))).unwrap()+    }++    #[test]+    fn an_embedded_model_is_present_and_decodes() {+        let step = "ISO-10303-21;\nHEADER;\nENDSEC;\nEND-ISO-10303-21;\n";+        let b = board(step);+        let e = Embedded::of(&b);+        assert!(e.present("D1", "kicad-embed://led.step"));+        assert!(e.present("R1", "kicad-embed://board-level.step"), "the board's own embedded files");+        assert!(!e.present("D1", "kicad-embed://other.step"));+        assert!(!e.present("D1", "${KICAD9_3DMODEL_DIR}/x.step"));+        let dir = std::env::temp_dir().join(format!("aiflow-emb-{}", std::process::id()));+        let f = e.extract("D1", "kicad-embed://led.step", &dir).unwrap();+        assert_eq!(std::fs::read_to_string(&f).unwrap(), step, "zstd frame decoded");+        let raw = e.extract("R1", "kicad-embed://board-level.step", &dir).unwrap();+        assert_eq!(std::fs::read(&raw).unwrap(), b"ISO-10303-21; raw", "uncompressed data is kept as it is");+        let _ = std::fs::remove_dir_all(&dir);+        let (left, n) = drop_present(vec!["Imported:LED (D1): kicad-embed://led.step".into(), "Imported:X (U9): kicad-embed://gone.step, ${KIPRJMOD}/x.step".into(), "Lib:FP (C1): /missing.step".into()], &e);+        assert_eq!(n, 1);+        assert_eq!(left, vec!["Imported:X (U9): kicad-embed://gone.step, ${KIPRJMOD}/x.step".to_string(), "Lib:FP (C1): /missing.step".to_string()]);+    }+}
crates/adom-aiflow/src/fields_versions.rs+37
@@ -15,6 +15,8 @@ //!   where there is none: a round board's rise read about 15 % low, a T shape several %, rounded corners under //!   1 %; its stitching fix plan could put vias off the board. Rectangles are byte-identical. (0.10.13 had the //!   fix but stamped 0.10.12; a note on such a solve is harmless.)+//! - 0.10.15 (adom/adom-fields#38, PR 23 from King Silver): a `hot` SMD part whose pads are all on B.Cu had its watts+//!   put into F.Cu and its tab read there. A two-sided board read about 30 % low, a single-sided one far too hot. use serde_json::Value; use std::path::Path; @@ -55,6 +57,15 @@ pub fn stale_notes(fields: &Value, spec: &Value, board: &Path) -> Vec<String> {             out.push(format!("this Fields solve is adom-fields {}, before 0.10.14, which solved every board as its bounding rectangle; this board's edge is not one ({why}), so FR4 was counted where there is none (a round board's rise read about 15 % low, a T shape several %, rounded corners under 1 %) and a stitching fix plan could put vias off the board. Update adom-fields (adom-wiki pkg install adom/adom-fields) and solve again.", version_text(solver)));         }     }+    // 0.10.15: a hot part on the bottom side (every pad on B.Cu, none through) took its heat on F.Cu+    if solver < (0, 10, 15) {+        if let Some(b) = plan_board(board, &text) {+            let parts = bottom_hot_parts(spec, &b);+            if !parts.is_empty() {+                out.push(format!("this Fields solve is adom-fields {}, before 0.10.15, which put the watts of a hot part on the bottom side into F.Cu and read its tab there ({}): its rise is wrong either way (a two-sided board read about 30 % low, a single-sided one far too hot). Update adom-fields (adom-wiki pkg install adom/adom-fields) and solve again.", version_text(solver), parts.join(", ")));+            }+        }+    }     if solver < (0, 10, 9) && text.contains("(kicad_pcb") {         if let Ok(b) = aiflow_board::Board::from_text(&board.display().to_string(), text) {             let mut parts = Vec::new();@@ -98,6 +109,14 @@ pub fn shaped_edge(b: &aiflow_board::Board) -> Option<String> {     Some(if (0..k).any(|i| !axis(corners[i], corners[(i + 1) % k])) { "a curved or slanted edge".to_string() } else { format!("a {k}-corner outline") }) } +/// Issue (adom-fields 0.10.15): the spec's hot parts that are bottom-side SMD parts: every pad on B.Cu, none through.+fn bottom_hot_parts(spec: &Value, b: &aiflow_board::Board) -> Vec<String> {+    spec["hot"].as_object().into_iter().flatten().map(|(n, _)| n).filter(|n| {+        let pads = b.pads_of(n);+        !pads.is_empty() && pads.iter().all(|p| p.on_b && !p.on_f && !p.thru)+    }).cloned().collect()+}+ /// The board net a spec name means, as Fields 0.10.12 reads it: the exact name, else the one net that differs only by /// a leading "/". None when there is none (or more than one). fn board_net<'a>(b: &'a aiflow_board::Board, name: &str) -> Option<&'a str> {@@ -257,4 +276,22 @@ mod tests {         d     } ++    /// adom-fields 0.10.15: a hot SMD part on the bottom side, solved before it, is told to solve again; one on top is not.+    #[test]+    fn a_bottom_hot_part_solved_before_0_10_15_is_told_to_solve_again() {+        let dir = std::env::temp_dir().join(format!("aiflow-fv-bottom-{}", std::process::id()));+        std::fs::create_dir_all(&dir).unwrap();+        let p = dir.join("b.kicad_pcb");+        std::fs::write(&p, r#"(kicad_pcb (layers (0 "F.Cu" signal) (2 "B.Cu" signal) (25 "Edge.Cuts" user)) (gr_rect (start 0 0) (end 20 20) (layer "Edge.Cuts"))+  (footprint "Q" (layer "B.Cu") (at 5 5) (property "Reference" "U2") (pad "1" smd rect (at 0 0) (size 2 2) (layers "B.Cu") (net "GND")))+  (footprint "Q" (layer "F.Cu") (at 12 5) (property "Reference" "U1") (pad "1" smd rect (at 0 0) (size 2 2) (layers "F.Cu") (net "GND"))))"#).unwrap();+        let spec = json!({"hot": {"U2": {"watts": 1.0}, "U1": {"watts": 1.0}}});+        let old = stale_notes(&json!({"inputIdentity": {"solverVersion": "0.10.14"}}), &spec, &p);+        assert!(old.iter().any(|n| n.contains("before 0.10.15") && n.contains("(U2)")), "{old:?}");+        assert!(!old.iter().any(|n| n.contains("before 0.10.15") && n.contains("U1")), "a top-side part is unchanged");+        assert!(stale_notes(&json!({"inputIdentity": {"solverVersion": "0.10.15"}}), &spec, &p).is_empty());+        let _ = std::fs::remove_dir_all(&dir);+    }+ }
crates/adom-aiflow/src/main.rs+13−1
@@ -31,6 +31,7 @@ mod schematic_identity; mod remote_binding; mod placement_verify; mod altium_placement;+mod embedded_models; mod assembly_contacts; mod provenance; mod spec_freeze;@@ -3735,8 +3736,14 @@ fn model_orientation_fit(board: &Board, project_dir: &Path, cache_path: Option<&         .filter(|fp| fp.find("layer").and_then(|l| l.value()) != Some("B.Cu"))         .filter_map(|fp| Some((aiflow_board::reference_of(fp)?, mechanical::local_box(fp, &["F.Fab"]).or_else(|| mechanical::local_box(fp, &["F.CrtYd"]))?))).collect();     let mut unresolved: BTreeMap<String, Vec<String>> = BTreeMap::new();+    // issue #268: footprint-embedded models are read from the board file, written once into the run+    let emb = embedded_models::Embedded::of(board);+    let emb_dir = cache_path.and_then(|p| p.parent()).map(|d| d.join("embedded-models")).unwrap_or_else(|| std::env::temp_dir().join("aiflow-embedded-models"));     for m in checks::model_refs(board) {-        let Some(file) = checks::resolve_model(&m.path, project_dir) else { unresolved.entry(m.path.clone()).or_default().push(m.reference.clone()); continue };+        let embedded = m.path.starts_with(embedded_models::PREFIX).then(|| emb.extract(&m.reference, &m.path, &emb_dir));+        if let Some(Err(e)) = &embedded { notes.push(format!("{} ({}): {e}", m.reference, m.path)); }+        let file = match embedded { Some(Ok(f)) => Some(f), Some(Err(_)) => None, None => checks::resolve_model(&m.path, project_dir) };+        let Some(file) = file else { unresolved.entry(m.path.clone()).or_default().push(m.reference.clone()); continue };         let meta = std::fs::metadata(&file).ok();         let key = format!("{}|{}|{}", file.display(), meta.as_ref().map(|x| x.len()).unwrap_or(0), meta.and_then(|x| x.modified().ok()).and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok()).map(|d| d.as_secs()).unwrap_or(0));         let got = match cache.get(&key) {@@ -8284,6 +8291,11 @@ fn main() {             // complete modelBindings + viewer classes (KiCad Bridge 1.0.22+); file resolution is not render proof             let mc = aiflow_bridge::model_check_summary(&d);             let mut missing = mc.missing.clone();+            // issue #268: a model embedded in its footprint (kicad-embed://) that the board file carries is resolved+            let emb = embedded_models::Embedded::of(&board_of(&r));+            let (kept, embedded_ok) = embedded_models::drop_present(std::mem::take(&mut missing), &emb);+            missing = kept;+            unresolved = unresolved.saturating_sub(embedded_ok);             // issue #226: a bare solder land (out of the BOM, no model) expects none; every other footprint with no             // model is named, never an empty list             let local = board_of(&r);
crates/adom-aiflow/src/placement_verify.rs+33−2
@@ -104,6 +104,12 @@ pub fn edge_connector_why(board: &Board, p: &Value, spec: &Value) -> Result<(),S     Ok(()) } +/// Issue #269: the saved board's footprints (with a reference, without one), each footprint counted once.+fn saved_counts(board: &Board) -> (usize, usize) {+    let unnamed = board.root.find_all("footprint").filter(|fp| aiflow_board::reference_of(fp).as_deref().map_or(true, str::is_empty)).count();+    (board.footprints.keys().filter(|r| !r.is_empty()).count(), unnamed)+}+ /// Issue #243: the same board file whatever the spelling: backslashes or slashes, and a Windows path's case. pub fn same_board_path(a: &str, b: &str) -> bool {     let norm = |p: &str| { let q = p.trim().replace('\\', "/"); if q.as_bytes().get(1) == Some(&b':') { q.to_ascii_lowercase() } else { q } };@@ -127,9 +133,17 @@ pub fn check_with_spec(board: &Board, before: &Value, validation: &Value, after:             return Err(format!("placement snapshot ({which} the check) does not qualify: {}", failed.join("; ")));         }         let parts=state["footprints"].as_array().ok_or("missing live footprints")?;-        if parts.len()!=board.footprints.len() || state["footprintCount"].as_u64()!=Some(parts.len() as u64) { return Err("live/saved footprint counts differ".into()); }+        // issue #269 (King Silver): footprints with an empty reference (an Altium import's free pads and mounting+        // holes, board-only) collapse into one entry of the saved board's by-reference map: count them apart on both+        // sides; they have no reference to compare a pose by+        let unnamed_live = parts.iter().filter(|p| p["ref"].as_str().is_some_and(str::is_empty)).count();+        let named_live = parts.len() - unnamed_live;+        let (named_saved, unnamed_saved) = saved_counts(board);+        if named_live != named_saved || unnamed_live != unnamed_saved || state["footprintCount"].as_u64()!=Some(parts.len() as u64) {+            return Err(format!("live/saved footprint counts differ: live {named_live} with a reference and {unnamed_live} without, saved {named_saved} and {unnamed_saved}"));+        }         let mut refs=BTreeSet::new();-        for p in parts {+        for p in parts.iter().filter(|p| !p["ref"].as_str().is_some_and(str::is_empty)) {             let reference=p["ref"].as_str().ok_or("missing reference")?;             if !refs.insert(reference) { return Err(format!("duplicate live reference {reference}")); }             let f=board.footprints.get(reference).ok_or_else(||format!("unexpected live reference {reference}"))?;@@ -233,6 +247,23 @@ pub fn locked_hint(reply: &serde_json::Value) -> Option<String> {  #[cfg(test)] mod tests {+    #[test]+    fn footprints_without_a_reference_are_counted_each() {+        // issue #269 (King Silver): two board-only free pads with an empty reference beside a named part+        let b=Board::from_text("fixture", "(kicad_pcb (gr_rect (start 0 0) (end 10 10) (layer \"Edge.Cuts\")) (footprint \"L:R\" (layer \"F.Cu\") (at 5 5 0) (property \"Reference\" \"R1\")) (footprint \"FreePad\" (layer \"F.Cu\") (at 2 2 0) (property \"Reference\" \"\") (attr board_only)) (footprint \"FreePad\" (layer \"F.Cu\") (at 8 8 0) (property \"Reference\" \"\") (attr board_only)))".into()).unwrap();+        assert_eq!(saved_counts(&b), (1, 2));+        let r1 = json!({"ref":"R1","x":5,"y":5,"rotation":0,"side":"F.Cu","footprint":"L:R","insideOutline":true});+        let free = |x: f64| json!({"ref":"","x":x,"y":x,"rotation":0,"side":"F.Cu","footprint":"FreePad","insideOutline":true});+        let s=json!({"success":true,"source":"live-editor","revision":"rev","boardPath":"board","footprintCount":3,"footprints":[r1, free(2.0), free(8.0)]});+        let v=json!({"success":true,"source":"live-editor","revision":"rev","currentRevision":"rev","stale":false,"placed":true,"outsideOutline":[],"parked":[],"courtyardOverlaps":[],"withoutCourtyard":[],"drc":{"available":true,"source":"live-editor-snapshot","placementClean":true,"placementViolationCount":0,"errors":0,"violationReportMayBeTruncated":false}});+        assert!(check_with_spec(&b,&s,&v,&s,"board",&Value::Null).is_ok(), "{:?}", check_with_spec(&b,&s,&v,&s,"board",&Value::Null));+        let mut short = s.clone();+        short["footprints"].as_array_mut().unwrap().pop();+        short["footprintCount"] = json!(2);+        let e = check_with_spec(&b,&short,&v,&short,"board",&Value::Null).unwrap_err();+        assert!(e.contains("1 without") && e.contains("saved 1 and 2"), "{e}");+    }+     #[test]     fn a_locked_footprint_points_at_place_verify() {         let h = super::locked_hint(&serde_json::json!({"errorCode": "footprint_locked", "offendingRefs": ["MP1"], "message": "pass allowLocked:true"})).unwrap();
crates/adom-aiflow/src/pourverify.rs+55−4
@@ -19,7 +19,34 @@ pub fn hash(path: &Path) -> Result<String, String> { fn number(n: &Node, key: &str, default: f64) -> f64 {     n.find(key).and_then(|v| v.number(1)).unwrap_or(default) }+/// Issue #270 (King Silver): a KiCad outline's points, `(xy x y)` and KiCad 10's `(arc (start) (mid) (end))` alike, the+/// arc sampled every 0.1 mm, each point rounded to 0.1 um so the board's zone and a plan written from it compare equal.+pub fn pts_points(pts: &Node) -> Vec<(f64, f64)> {+    let r = |v: f64| (v * 10000.0).round() / 10000.0;+    let at = |n: &Node, tag: &str| n.find(tag).and_then(|p| Some((p.number(1)?, p.number(2)?)));+    let mut out: Vec<(f64, f64)> = Vec::new();+    for c in pts.nodes() {+        let new: Vec<(f64, f64)> = match c.tag.as_str() {+            "xy" => c.number(1).zip(c.number(2)).into_iter().collect(),+            "arc" => match (at(c, "start"), at(c, "mid"), at(c, "end")) {+                (Some(a), Some(m), Some(b)) => aiflow_board::geom::arc_points(a, m, b, 0.1),+                _ => Vec::new(),+            },+            _ => Vec::new(),+        };+        for q in new.into_iter().map(|(x, y)| (r(x), r(y))) {+            if out.last() != Some(&q) { out.push(q); }+        }+    }+    if out.len() > 1 && out.first() == out.last() { out.pop(); }+    out+}+ fn canonical(n: &Node) -> Value {+    // issue #270: a zone outline compares as its points, arcs sampled, whichever way it is written+    if n.tag == "pts" && n.nodes().any(|c| c.tag == "arc") {+        return json!(["pts", [], pts_points(n).iter().map(|(x, y)| json!(["xy", [x, y], []])).collect::<Vec<_>>()]);+    }     let mut children: Vec<Value> = n.nodes().map(canonical).collect();     if n.tag != "pts" {         children.sort_by_key(Value::to_string);@@ -115,7 +142,7 @@ fn field_label(key: &str) -> &str { fn points(n: &Node) -> Vec<(f64, f64)> {     n.find_all("polygon")         .filter_map(|p| p.find("pts"))-        .flat_map(|pts| pts.find_all("xy").filter_map(|xy| Some((xy.number(1)?, xy.number(2)?))).collect::<Vec<_>>())+        .flat_map(|pts| pts_points(pts))         .collect() } @@ -219,7 +246,7 @@ fn keepout_clear(board: &Board, actual: &[&Node], z: &Value, label: &str) -> Vec             let fills: Vec<Vec<(f64, f64)>> = n.find_all("filled_polygon")                 .filter(|p| p.find("layer").and_then(Node::value) == Some(layer))                 .filter_map(|p| p.find("pts"))-                .map(|pts| pts.find_all("xy").filter_map(|xy| Some((xy.number(1)?, xy.number(2)?))).collect())+                .map(|pts| pts_points(pts))                 .collect();             if fills.iter().any(|f| overlap(f, &poly)) {                 out.push(format!("{label}: pour copper of {net} (board zone {i}, {}) on {layer} lies inside the keepout", zone_name(n)));@@ -458,7 +485,7 @@ pub fn check_with(board: &Board, plan: &Value, keepouts_landed: bool) -> Result<                 let filled = n.find_all("filled_polygon").any(|p| {                     p.find("layer").and_then(Node::value) == layer.as_str()                         && p.find("pts")-                            .is_some_and(|pts| pts.find_all("xy").count() >= 3)+                            .is_some_and(|pts| pts_points(pts).len() >= 3)                 });                 if !filled {                     failed.push(format!("{label}: no saved filled polygon on {layer}"));@@ -877,7 +904,7 @@ pub fn plan_from_board(board: &Board) -> Value {             .map(|x| (1..).map_while(|j| x.atom(j)).map(str::to_string).collect()).unwrap_or_default();         layers.dedup();         let loops: Vec<Value> = n.find_all("polygon").filter_map(|p| p.find("pts"))-            .map(|pts| json!(pts.find_all("xy").filter_map(|xy| Some(json!([xy.number(1)?, xy.number(2)?]))).collect::<Vec<_>>()))+            .map(|pts| json!(pts_points(pts).iter().map(|(x, y)| json!([x, y])).collect::<Vec<_>>()))             .collect();         let name = n.find("name").and_then(Node::value).map(str::to_string).unwrap_or_else(|| format!("board zone {i}"));         let mut z = json!({"name": name, "layers": layers});@@ -1561,4 +1588,28 @@ mod tests {         assert_eq!(proof["pass"], true, "{proof}");         assert_eq!(proof["groups"].as_array().unwrap().len(), 3);     }++    #[test]+    fn a_zone_outline_of_arcs_is_read_and_verifies() {+        // issue #270 (King Silver): a round board's zone is four arcs in its outline, no xy points+        let (c, r) = (10.0f64, 8.0f64);+        let at = |deg: f64| { let a = deg.to_radians(); (c + r * a.cos(), c + r * a.sin()) };+        let arc = |a0: f64, a1: f64| { let (s, m, e) = (at(a0), at((a0 + a1) / 2.0), at(a1)); format!("(arc (start {} {}) (mid {} {}) (end {} {}))", s.0, s.1, m.0, m.1, e.0, e.1) };+        let outline = format!("{} {} {} {}", arc(0.0, 90.0), arc(90.0, 180.0), arc(180.0, 270.0), arc(270.0, 360.0));+        let fill: String = (0..36).map(|k| { let p = at(k as f64 * 10.0); format!("(xy {} {})", p.0, p.1) }).collect::<Vec<_>>().join(" ");+        let text = format!(r#"(kicad_pcb (version 20260101) (layers (0 "F.Cu" signal) (31 "B.Cu" signal)) (net 0 "") (net 1 "GND")+ (gr_circle (center 10 10) (end 19.5 10) (layer "Edge.Cuts"))+ (zone (net 1) (net_name "GND") (layer "F.Cu") (uuid "ring-1") (name "ground") (hatch edge 0.5)+  (connect_pads (clearance 0.3)) (min_thickness 0.2) (filled_areas_thickness no)+  (fill yes (thermal_gap 0.4) (thermal_bridge_width 0.35))+  (polygon (pts {outline}))+  (filled_polygon (layer "F.Cu") (pts {fill}))))"#);+        let b = Board::from_text("test", text).unwrap();+        let plan = plan_from_board(&b);+        let poly = plan["zones"][0]["polygon"].as_array().unwrap();+        assert!(poly.len() > 100, "the four arcs are sampled, not dropped: {} points", poly.len());+        let proof = check_with(&b, &plan, true).unwrap();+        assert_eq!(proof["pass"], true, "{proof}");+    }+ }
docs/release-0.2.121.mdadded+23
@@ -0,0 +1,23 @@+# adom-aiflow 0.2.121++Three fixes for boards converted from Altium and round boards (King Silver).++## place verify: footprints with no reference (issue #269)++A board imported from Altium keeps its free pads and mounting holes as board-only footprints with an empty reference. The saved board is read by reference, so those collapsed into one entry and `place verify` failed with "live/saved footprint counts differ" although both sides had 21 footprints. Footprints with an empty reference are now counted apart on both sides and must match in number; the message gives both counts when they don't. They have no reference to compare a pose by, so the per-part checks cover the named footprints, as before.++## verify-pours: zone outlines made of arcs (issue #270)++KiCad 10 keeps arcs in a zone's outline (`(arc (start) (mid) (end))` inside `pts`). The zone readers took only `xy` points, so a round board's zone of four arcs read as no points and `verify-pours --from-board` stopped. Arcs are now read: sampled every 0.1 mm and rounded to 0.1 µm, the same way for the board's zone and a plan written from it, so the two compare equal.++## models: 3D models embedded in the footprint (issue #268)++KiCad 10 can keep a footprint's STEP inside the footprint (`kicad-embed://x.step` with `(embedded_files ...)`), as KiCad's Altium importer does. `models` listed every such model as unresolved, though KiCad renders them.++- A `kicad-embed://` model whose file is in its footprint's (or the board's) `embedded_files` counts as resolved.+- The orientation check reads its size from the embedded bytes (base64 of zstd), written once into the run's `embedded-models/` folder.+- Checked against real KiCad embedded models: each decodes to its STEP.++## Fields: a hot part on the bottom side solved before adom-fields 0.10.15++adom-fields 0.10.15 (adom/adom-fields#38, from King Silver) puts a bottom-side hot part's heat on B.Cu. Before it, a `hot` SMD part whose pads are all on B.Cu had its watts put into F.Cu and its tab read there: a two-sided board read about 30 % low, a single-sided one far too hot. `analyze` now notes a Fields solve older than 0.10.15 with such a part, names it, and suggests updating adom-fields and solving again. Top-side and through-hole parts are unchanged. As with the other Fields notes, it is a suggestion; the screen itself is unchanged.
package.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow",   "type": "app",-  "version": "0.2.120",+  "version": "0.2.121",   "title": "AI Flow",   "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.",   "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",
page.json+1−1
@@ -1,7 +1,7 @@ {   "slug": "adom-aiflow",   "type": "app",-  "version": "0.2.120",+  "version": "0.2.121",   "title": "AI Flow",   "description": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. One Rust binary with a crate per step (placement helpers, a grid router with Kelvin taps, pours with keepouts, KiCad's DRC gate, live landing through the KiCad Bridge, copper measurement, current and thermal analysis) and a finish line that refuses an unfinished board. Every command answers with hints for the AI; every turn, its thinking time and every rework loop go into run.jsonl, so Claude, Codex and any other engine are compared on the same flow. KiCad, Fusion 360 and Altium Designer today (the same steps and gates through each tool's bridge); Adom's own web apps next.",   "summary": "Adom's AI Flow: a tool to help the AI follow all of the steps it takes to build a board. The AI thinks its way from placement through routing, pours, current and thermal analysis to a delivered video; the binary does the fast, deterministic parts of every step, hands back hints, and keeps a ledger of every turn, every return to an earlier step, and the clock from the prompt to done.",