by adom
Let an AI (Claude, ChatGPT, Codex or any agent) run Altium Designer for you: create symbols and footprints, place parts (also from Altium 365), wire and annotate schematics, Update PCB, set the stack-up and rules, route, pour copper, add mounting holes and stitching vias, run ERC and DRC, and make Gerbers, BOMs and STEP. Free in Hydrogen; bring your own AI and Altium licence.
← Commit history
lint_library on the standard's engine (adom-eda-checks 0.21.1, vendored as published); open finds a document under any path spelling and still opens it (run_drc crash fixed); show_footprint name alias
16 files changed
+446−21
CHANGELOG.md+13README.md+5−4bridge-rs/Cargo.lock+1−1bridge-rs/src/liblint.rs+152bridge-rs/src/main.rs+1bridge-rs/src/project.rs+4−1bridge-rs/src/surfaces.rs+2−1bridge-rs/src/verbs.rs+7−1bridge-rs/vendor/adom-eda-checks/Cargo.toml+1−1bridge-rs/vendor/adom-eda-checks/README.md+1bridge-rs/vendor/adom-eda-checks/src/lib.rs+4−2bridge-rs/vendor/adom-eda-checks/src/liblint.rs+239bridge-rs/vendor/adom-eda-checks/src/main.rs+1−1dev-skills/altium-bridge-test/run_verb_tests.py+4src/agent/AdomAgent.pas.tmpl+9−8src/bridge.json+2−1CHANGELOG.md+13@@ -13,6 +13,19 @@ Develop with pad 1 of TST_SOIC8 widened to 2 x 0.9 mm: the plan found U1 (top, 0 degrees) and U2 (bottom, 90 degrees) differing on pad 1 only; apply replaced both with their nets kept, both still at their places, and a second plan found them up to date while U3, not named, still differs.+- **`altium_lint_library`: check a library before it ships** (EDA Bridge Standard #28, checks tier). KiCad's verb of+ the same name lints a file KiCad has to parse; an Altium library always parses, so this one reads every footprint or+ symbol (or the `names` given) and the standard's shared engine checks what is in them (adom-eda-checks 0.21.1,+ standard 0.24.2, `lint_library`, vendored as published). Footprints: `no_pads`, `zero_size_pad`, `unnumbered_pad`,+ `duplicate_pad_number` (one number on lands that do not touch: a split exposed pad is one land), `no_courtyard`+ (Mechanical 15), `no_silkscreen`, `no_3d_body`, `origin_off_part` (outside the pads and courtyard grown by 1 mm),+ `no_description`. Symbols: `no_pins`, `unnumbered_pin`, `duplicate_pin_number`, `no_part_number`, `no_footprint`, and+ against the linked footprint (in `footprintLibraries`, default the PcbLibs beside the SchLib) `footprint_not_found`,+ `pin_without_pad`, `pad_without_pin`. Each rule has one severity, listed in the reply's `rules`; `ok` is false on any+ error or any item not read. Run on the battery's libraries it found BAT_FP_X, the battery's `xcopy_footprint` copy,+ sitting 1270 mm off its origin: a real bug in that verb (#29). `read_footprint` gains `graphicsLayerIds`, its+ graphics counted by Altium layer id.+- `show_footprint`'s `name` alias works: the default footprint was filled in first, so `name` never counted. - **One Altium document per file, whatever the spelling of its path.** Altium opens `C:/x/a.PcbLib` as a second document beside `C:\x\a.PcbLib`, so an edit on one copy was never seen by a read of the other (Battery.PcbLib was open three times). Every drive-letter path now reaches the agent with backslashes, and opening, closing and the
README.md+5−4@@ -15,7 +15,7 @@ normal session. Ask in plain words and it: - makes the outputs: Gerbers, NC drill, pick and place, BOMs grouped by MPN (JLCPCB, Mouser, DigiKey files), schematic PDF and STEP, checking that the outline and every copper layer reached the Gerbers -258 commands, tested on Altium Designer 26.11 and Altium Designer Develop. It runs in **Hydrogen**, Adom's free+259 commands, tested on Altium Designer 26.11 and Altium Designer Develop. It runs in **Hydrogen**, Adom's free desktop app, through Adom Bridge. You bring your own AI subscription and your own Altium licence. ::youtube{id="dFecpcIzdSE" title="An AI designs a 12 V to 5 V buck converter in Altium Designer"}@@ -29,7 +29,7 @@ and the verb prefix `altium_`. ## What it can do -Tested on Altium Designer 26.11.1 and Altium Designer Develop. 258 verbs; each row names the ones+Tested on Altium Designer 26.11.1 and Altium Designer Develop. 259 verbs; each row names the ones behind it (prefix `altium_`). | Area | What the AI can do | Verbs |@@ -70,7 +70,7 @@ This bridge is the reference for the [EDA Bridge Standard](https://wiki.adom.inc Altium Designer is the user's own **host app**. The bridge finds an installed Altium (`%ProgramFiles%\Altium\AD*\X2.EXE`, Designer or Develop), starts it in the background, runs a small-**DelphiScript agent** inside it, and gives the AI 258 `altium_*` verbs.+**DelphiScript agent** inside it, and gives the AI 259 `altium_*` verbs. - **Page and docs:** https://wiki.adom.inc/adom/altium-bridge - **Bridge SDK:** https://wiki.adom.inc/adom/adom-bridge-sdk@@ -170,7 +170,7 @@ way to read it). A stopped engine is restarted with `altium_agent_recover`. <!-- verbs:start (tools/readme_verbs.py writes this list) --> -All 258 verbs, by area (prefix `altium_`). `altium_describe` returns the live catalog with every input, output, hint and example.+All 259 verbs, by area (prefix `altium_`). `altium_describe` returns the live catalog with every input, output, hint and example. ### Running Altium: launch, close, health, dialogs @@ -252,6 +252,7 @@ All 258 verbs, by area (prefix `altium_`). `altium_describe` returns the live ca - `altium_simulate`: Run a circuit simulation of a schematic sheet in Altium's mixed-signal simulator (Advanced Sim) and return the signals as data: an operating point, a DC sweep, an AC sweep or a transient, as the standard's simulate gives them. - `altium_export_spice`: The schematic's SPICE netlist from Altium's mixed-signal simulator (the .nsx its Mixed Sim output writes): elements, analyses, models. - `altium_update_footprints_from_library`: Compare each placed footprint with its library's current one and, with apply:true, replace the ones that differ, keeping where the part sits (position, rotation, side), its designator and comment, its pad nets by pad number and its schematic link.+- `altium_lint_library`: Check a .PcbLib or .SchLib before it ships: footprints without pads, courtyard, silkscreen or 3D body, with duplicate or missing pad numbers, an origin off the part or no description; symbols without pins or a footprint, with duplicate pin numbers or no part number, and pins that no pad of the linked footprint answers. - `altium_export_library_part`: Export one library part into its own small library files: a symbol library with only its symbol, a footprint library with only its footprint, and its 3D model file. - `altium_create_part_project`: Generate a small real project (schematic and board) around one library part, so the part can be shown and tested in every view: schematic, 2D board and 3D board. - `altium_library_views`: Pictures of library parts for review, each as an image file: the schematic symbol, the footprint (pads and layers), the 3D body seated on the footprint, and the device view that maps symbol pins to pads.
bridge-rs/Cargo.lock+1−1@@ -10,7 +10,7 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "adom-eda-checks"-version = "0.20.0"+version = "0.21.1" dependencies = [ "roxmltree", "serde_json",
bridge-rs/src/liblint.rsadded+152@@ -0,0 +1,152 @@+//! lint_library: is a library fit to ship? The rules are the standard's (EDA Bridge Standard #28), run by the shared+//! engine (adom-eda-checks `lint_library`); this module reads the library from Altium and hands it over. KiCad's lint+//! adds its tool's verdict on the file; an Altium library always parses, so Altium sends content only.+use serde_json::{json, Value};+use std::collections::BTreeMap;+use std::path::{Path, PathBuf};++fn f(v: &Value) -> f64 { v.as_f64().unwrap_or(0.0) }++/// One footprint as read_footprint answers it, in the engine's terms. A key is sent only when it was read: an empty+/// one is a finding (no courtyard on Mechanical 15, nothing on the overlays, no 3D body). Pure.+pub fn engine_footprint(name: &str, fp: &Value) -> Value {+ let pads: Vec<Value> = fp["pads"].as_array().cloned().unwrap_or_default().iter().map(|p| {+ let (mut w, mut h) = (f(&p["sizeMm"][0]), f(&p["sizeMm"][1]));+ // the copper's box in the footprint's frame: a quarter turn swaps the sides, any other turn takes the larger+ let rot = f(&p["rotation"]).rem_euclid(180.0);+ if (rot - 90.0).abs() < 0.01 { std::mem::swap(&mut w, &mut h); } else if rot > 0.01 && (rot - 180.0).abs() > 0.01 { let m = w.max(h); w = m; h = m; }+ json!({"number": p["number"], "x": p["at"][0], "y": p["at"][1], "w": w, "h": h, "hole": p["drillMm"], "plated": p["type"] != "npth"})+ }).collect();+ let ids = &fp["graphicsLayerIds"];+ let on = |id: &str| ids.get(id).and_then(|v| v.as_i64()).unwrap_or(0) > 0;+ json!({"name": name, "pads": pads,+ "courtyard": if on("71") { fp["courtyardMm"].clone() } else { Value::Null },+ "silk": if on("33") || on("34") { json!([[0, 0]]) } else { json!([]) },+ "bodies": fp["models"].as_array().cloned().unwrap_or_default(),+ "description": fp["description"].as_str().unwrap_or("")})+}++/// The footprint a symbol links: its current PCBLIB model, else its first.+fn linked_footprint(sym: &Value) -> Option<String> {+ let models: Vec<&Value> = sym["models"].as_array().map(|a| a.iter().filter(|m| m["type"].as_str().map(|t| t.eq_ignore_ascii_case("PCBLIB")).unwrap_or(false)).collect()).unwrap_or_default();+ models.iter().find(|m| m["isCurrent"] == json!(true)).or(models.first()).and_then(|m| m["name"].as_str()).map(str::to_string)+}++/// One symbol as read_symbol answers it, in the engine's terms. Pure.+pub fn engine_symbol(name: &str, sym: &Value) -> Value {+ let pins: Vec<Value> = sym["pins"].as_array().cloned().unwrap_or_default().iter().map(|p| json!({"number": p["des"], "name": p["name"]})).collect();+ let param = |n: &str| sym["params"].as_array().and_then(|a| a.iter().find(|p| p["name"].as_str().map(|x| x.eq_ignore_ascii_case(n)).unwrap_or(false)))+ .and_then(|p| p["value"].as_str()).map(str::trim).filter(|v| !v.is_empty()).map(str::to_string);+ json!({"name": name, "pins": pins, "footprint": linked_footprint(sym).unwrap_or_default(),+ "partNumber": param("MPN").or_else(|| param("Manufacturer Part Number")).unwrap_or_default()})+}++fn data(r: &Value) -> Value { if r["data"].is_object() { r["data"].clone() } else { r.clone() } }+fn ok(r: &Value) -> bool { r.get("success").and_then(|v| v.as_bool()) == Some(true) && data(r)["ok"] != json!(false) }+fn names_of(lib: &str) -> Result<Vec<String>, Value> {+ let r = crate::surfaces::list_library(&json!({"libraryPath": lib}));+ if !ok(&r) { return Err(r); }+ Ok(data(&r)["names"].as_array().map(|a| a.iter().filter_map(|x| x.as_str().map(str::to_string)).collect()).unwrap_or_default())+}++/// altium_lint_library {libraryPath | filePath, names?, footprintLibraries? | footprintLibrary?}+pub fn lint_library(args: &Value) -> Value {+ if let Some(g) = crate::support::need_licensed() { return g; }+ let Some(lib) = crate::support::s(args, "libraryPath").or_else(|| crate::support::s(args, "filePath")) else {+ return json!({"success": false, "errorCode": "bad_args", "error": "libraryPath (a .PcbLib or .SchLib) is required"});+ };+ let low = lib.to_lowercase();+ let kind = if low.ends_with(".pcblib") { "pcb" } else if low.ends_with(".schlib") { "sch" } else {+ return json!({"success": false, "errorCode": "bad_args", "error": "libraryPath must be a .PcbLib or .SchLib"});+ };+ let all = match names_of(&lib) { Ok(n) => n, Err(e) => return e };+ let want: Vec<String> = args.get("names").and_then(|v| v.as_array()).map(|a| a.iter().filter_map(|x| x.as_str().map(|s| s.to_lowercase())).collect()).unwrap_or_default();+ let names: Vec<String> = all.into_iter().filter(|n| want.is_empty() || want.contains(&n.to_lowercase())).collect();+ let mut unread = Vec::new();+ if kind == "pcb" {+ let mut fps = Vec::new();+ for n in &names {+ let fp = crate::project::read_footprint(&json!({"libraryPath": lib, "name": n}));+ if ok(&fp) { fps.push(engine_footprint(n, &fp)); } else { unread.push(json!({"name": n, "error": fp.get("error")})); }+ }+ let mut r = adom_eda_checks::liblint::lint_library(&json!({"library": {"footprints": fps, "unread": unread}}));+ r["library"] = json!(lib); r["kind"] = json!(kind);+ return r;+ }+ // a SchLib: its symbols, checked against the footprints they link, from the libraries named or the PcbLibs beside it+ let mut fp_libs: Vec<String> = args.get("footprintLibraries").and_then(|v| v.as_array()).map(|a| a.iter().filter_map(|x| x.as_str().map(str::to_string)).collect()).unwrap_or_default();+ if let Some(l) = crate::support::s(args, "footprintLibrary") { fp_libs.push(l); }+ if fp_libs.is_empty() { fp_libs = sibling_pcblibs(Path::new(&lib.replace('\\', "/"))).iter().map(|p| p.to_string_lossy().to_string()).collect(); }+ let mut syms = Vec::new();+ for n in &names {+ let r = crate::library::read_symbol(&json!({"libraryPath": lib, "symbolName": n}));+ if ok(&r) { syms.push(engine_symbol(n, &data(&r))); } else { unread.push(json!({"name": n, "error": r.get("error").or(data(&r).get("error"))})); }+ }+ let lib_names: Vec<(String, Vec<String>)> = fp_libs.iter().map(|l| (l.clone(), names_of(l).unwrap_or_default())).collect();+ // each linked footprint read once, from the first library that has it; one not found is left out, so the+ // engine names it footprint_not_found+ let mut fps: BTreeMap<String, Value> = BTreeMap::new();+ for s in &syms {+ let Some(fpn) = s["footprint"].as_str().filter(|n| !n.is_empty()).map(str::to_string) else { continue };+ if fps.contains_key(&fpn) { continue; }+ let hit = lib_names.iter().find_map(|(l, ns)| ns.iter().find(|n| n.eq_ignore_ascii_case(&fpn)).map(|n| (l, n.clone())));+ if let Some((l, n)) = hit {+ let fp = crate::project::read_footprint(&json!({"libraryPath": l, "name": n}));+ if ok(&fp) { fps.insert(fpn.clone(), engine_footprint(&fpn, &fp)); }+ }+ }+ let findings: Vec<Value> = syms.iter().flat_map(|s| adom_eda_checks::liblint::lint_symbol(s, Some(&fps))).collect();+ // the engine's reply, with the symbol findings as ours: the footprints were read to check pins, not to lint them+ let mut r = adom_eda_checks::liblint::lint_library(&json!({"library": {"findings": findings, "unread": unread}}));+ r["checked"] = json!(syms.len());+ r["library"] = json!(lib); r["kind"] = json!(kind); r["footprintLibraries"] = json!(fp_libs);+ r+}++fn sibling_pcblibs(schlib: &Path) -> Vec<PathBuf> {+ let dir = schlib.parent().unwrap_or(Path::new("."));+ let mut out: Vec<PathBuf> = std::fs::read_dir(dir).into_iter().flatten().flatten().map(|e| e.path())+ .filter(|p| p.extension().map(|x| x.eq_ignore_ascii_case("PcbLib")).unwrap_or(false)).collect();+ out.sort();+ out+}++#[cfg(test)]+mod tests {+ use super::*;+ use adom_eda_checks::liblint::{lint_footprint, lint_symbol};++ fn pad(n: &str, x: f64, y: f64) -> Value { json!({"number": n, "type": "smd", "at": [x, y], "sizeMm": [1.0, 0.6], "drillMm": 0.0, "rotation": 0.0}) }+ fn rules(v: &[Value]) -> Vec<String> { v.iter().map(|f| f["rule"].as_str().unwrap().to_string()).collect() }++ #[test]+ fn a_good_footprint_is_clean() {+ let fp = json!({"pads": [pad("1", -1.0, 0.0), pad("2", 1.0, 0.0)], "graphicsLayerIds": {"33": 4, "71": 4}, "courtyardMm": [-1.6, -0.5, 1.6, 0.5], "models": [{}], "description": "0603"});+ assert_eq!(rules(&lint_footprint(&engine_footprint("R0603", &fp))), Vec::<String>::new());+ }++ #[test]+ fn what_altium_did_not_draw_is_a_finding() {+ // BAT_FP_X as the battery's xcopy left it (#29): 1270 mm off, nothing on the overlays or Mechanical 15, no body+ let fp = json!({"pads": [pad("1", -1271.016, -1270.0), pad("2", -1268.984, -1270.0)], "graphicsLayerIds": {}, "courtyardMm": [0, 0, 0, 0], "models": [], "description": "battery"});+ let r = rules(&lint_footprint(&engine_footprint("BAT_FP_X", &fp)));+ assert_eq!(r, ["no_courtyard", "origin_off_part", "no_silkscreen", "no_3d_body"]);+ }++ #[test]+ fn a_turned_pad_is_measured_turned() {+ let mut p = pad("1", 0.0, 0.0); p["rotation"] = json!(90.0);+ assert_eq!(engine_footprint("X", &json!({"pads": [p]}))["pads"][0]["w"], json!(0.6));+ }++ #[test]+ fn symbol_pins_against_footprint_pads() {+ let sym = json!({"pins": [{"des": "1"}, {"des": "2"}, {"des": "3"}], "params": [{"name": "Manufacturer Part Number", "value": "X1"}],+ "models": [{"type": "PCBLIB", "name": "SOT23", "isCurrent": true}]});+ let mut fps = BTreeMap::new();+ fps.insert("SOT23".to_string(), engine_footprint("SOT23", &json!({"pads": [pad("1", 0.0, 0.0), pad("2", 2.0, 0.0), pad("4", 4.0, 0.0)]})));+ assert_eq!(rules(&lint_symbol(&engine_symbol("Q1", &sym), Some(&fps))), ["pin_without_pad", "pad_without_pin"]);+ assert_eq!(rules(&lint_symbol(&engine_symbol("Q1", &sym), Some(&BTreeMap::new()))), ["footprint_not_found"]);+ assert_eq!(rules(&lint_symbol(&engine_symbol("B", &json!({"pins": []})), Some(&fps))), ["no_pins", "no_footprint", "no_part_number"]);+ }+}
bridge-rs/src/main.rs+1@@ -32,6 +32,7 @@ mod hier; mod coppermap; mod current; mod fpupdate;+mod liblint; mod impedance; mod inspect; mod lengths;
bridge-rs/src/project.rs+4−1@@ -363,6 +363,9 @@ pub fn read_footprint(args: &Value) -> Value { json!({"number": p[0], "type": if hole > 0.0 { if p[9].as_bool() == Some(false) { "npth" } else { "pth" } } else { "smd" }, "shape": shape(p[7].as_i64().unwrap_or(0)), "at": [mm(&p[1]), mm(&p[2])], "sizeMm": [mm(&p[3]), mm(&p[4])], "drillMm": hole, "layers": [layer], "rotation": p[8].as_f64().unwrap_or(0.0) / 1000.0}) }).collect();+ // the same counts by Altium's layer id, which names nothing on a board's layer map (33 Top Overlay, 71 Mechanical 15)+ let mut by_id = serde_json::Map::new();+ for o in d["other"].as_array().cloned().unwrap_or_default() { let k = o[1].as_i64().unwrap_or(0).to_string(); let n = by_id.get(&k).and_then(|v| v.as_i64()).unwrap_or(0); by_id.insert(k, json!(n + 1)); } let mut graphics = serde_json::Map::new(); for o in d["other"].as_array().cloned().unwrap_or_default() { let l = crate::routing::layer_name(o[1].as_i64().unwrap_or(0)); *graphics.entry(l).or_insert(json!(0)) = json!(graphics.get(&crate::routing::layer_name(o[1].as_i64().unwrap_or(0))).and_then(|v| v.as_i64()).unwrap_or(0) + 1); } let mut layers: Vec<String> = pads.iter().filter_map(|p| p["layers"][0].as_str().map(str::to_string)).chain(graphics.keys().cloned()).collect();@@ -379,7 +382,7 @@ pub fn read_footprint(args: &Value) -> Value { let b = court.map(|c| json!(c)).unwrap_or(d["box"].clone()); let models: Vec<Value> = d["bodies"].as_array().cloned().unwrap_or_default().iter().map(|x| json!({"path": x["model"], "heightMm": mm(&x["overallHeight"]), "standoffMm": mm(&x["standoff"])})).collect(); json!({"success": true, "name": d["name"], "library": lib, "description": d["description"], "pads": pads, "layers": layers, "courtyardMm": if court.is_some() { b.clone() } else { json!([mm(&b[0]), mm(&b[1]), mm(&b[2]), mm(&b[3])]) },- "graphics": graphics, "attributes": {"mount": if pads.iter().any(|p| p["type"] == "pth") { "through_hole" } else { "smd" }},+ "graphics": graphics, "graphicsLayerIds": by_id, "attributes": {"mount": if pads.iter().any(|p| p["type"] == "pth") { "through_hole" } else { "smd" }}, "properties": {"description": d["description"], "heightMm": mm(&d["height"])}, "models": models, "_hint": "Positions from the footprint's origin, mm. courtyardMm is the footprint's bounding box (Altium courtyards are a mechanical layer's graphics). altium_footprint_primitives reads a placed part."}) }
bridge-rs/src/surfaces.rs+2−1@@ -169,8 +169,9 @@ pub fn show_symbol(args: &Value) -> Value { fn with_demo_footprint(args: &Value) -> Value { let mut a = args.clone(); let custom = args.get("libraryPath").is_some() || args.get("filePath").is_some();+ // name is footprintName's alias: filling the default first made it never count (BAT_FP shown for BAT_FP_X, 2026-10-30) if a.get("footprintName").is_none() {- a["footprintName"] = json!(if custom { "" } else { support::DEMO_FOOTPRINT });+ a["footprintName"] = a.get("name").cloned().unwrap_or(json!(if custom { "" } else { support::DEMO_FOOTPRINT })); } a }
bridge-rs/src/verbs.rs+7−1@@ -22,7 +22,7 @@ pub const KNOWN: &[&str] = &[ "list_nets", "net_connections", "layers", "copper_layers", "read_rules", "set_layer_visibility", "footprint_primitives", "schematic_data", "layer_stack", "net_classes", "diff_pairs", "board_outline", "set_track_width", "find_space", "selection", "check_orientation", "replicate_layout", "outjob_info", "find_symbol", "part_parameters", // the live-board lane AI Flow drives- "routing_state", "route_net", "plan_route", "move_parts", "place_decoupling", "plan_fanout", "estimate_cost", "simulate", "export_spice", "update_footprints_from_library", "export_library_part", "create_part_project", "library_views", "render_board_3d", "render_board_layers", "document_info", "close_all_documents", "project_info", "project_create", "project_rename", "project_snapshot", "cross_probe", "read_footprint", "export_odb", "export_ipc2581", "export_ipc356", "export_dxf", "export_gencad", "import_svg", "edit_footprint", "generate_body", "remove_parts", "edit_parts", "align_parts", "set_layer_count", "copy_routing", "check_clearance", "remove_graphics", "place_vias", "board_features", "sch_sheet_symbol", "netlist", "silkscreen_prep", "net_lengths", "teardrops", "component_classes", "read_sheet_file", "fab_check", "panelize", "impedance", "current_capacity", "height_check", "bodies", "copper_balance", "return_path", "silk_designators", "via_fence", "assembly_check", "jlcpcb_order", "schematic_review", "pin_pad_check", "route_pair", "thermal_vias", "board_report", "placement_check", "auto_classes", "length_tune", "remove_items", "ripup_nets", "apply_pours", "pour_state", "remove_pours", "repour", "routing_drc", "build_board", "set_outline", "set_design_rules", "zoom_to", "add_rule", "build_schematic", "export_manufacturing", "select_net", "silk_state", "apply_silkscreen",+ "routing_state", "route_net", "plan_route", "move_parts", "place_decoupling", "plan_fanout", "estimate_cost", "simulate", "export_spice", "update_footprints_from_library", "lint_library", "export_library_part", "create_part_project", "library_views", "render_board_3d", "render_board_layers", "document_info", "close_all_documents", "project_info", "project_create", "project_rename", "project_snapshot", "cross_probe", "read_footprint", "export_odb", "export_ipc2581", "export_ipc356", "export_dxf", "export_gencad", "import_svg", "edit_footprint", "generate_body", "remove_parts", "edit_parts", "align_parts", "set_layer_count", "copy_routing", "check_clearance", "remove_graphics", "place_vias", "board_features", "sch_sheet_symbol", "netlist", "silkscreen_prep", "net_lengths", "teardrops", "component_classes", "read_sheet_file", "fab_check", "panelize", "impedance", "current_capacity", "height_check", "bodies", "copper_balance", "return_path", "silk_designators", "via_fence", "assembly_check", "jlcpcb_order", "schematic_review", "pin_pad_check", "route_pair", "thermal_vias", "board_report", "placement_check", "auto_classes", "length_tune", "remove_items", "ripup_nets", "apply_pours", "pour_state", "remove_pours", "repour", "routing_drc", "build_board", "set_outline", "set_design_rules", "zoom_to", "add_rule", "build_schematic", "export_manufacturing", "select_net", "silk_state", "apply_silkscreen", // surfaces "show_project", "show_schematic", "show_2d_board", "show_3d_board", "show_library", "show_symbol", "show_footprint", "show_3d_chip", "list_library", "demo",@@ -447,6 +447,11 @@ fn describe() -> Value { json!({"footprints": "[{ref, footprint, library, status: up_to_date | differs | library_not_found, diff?: {padsAdded, padsRemoved, padsChanged: [{pad, changes}], bodies3d?}, why?}]", "differs": "int", "plan": "bool", "mutated": "bool", "replaced": "[{ref, replaced, netsKept, netsBefore}] (apply)", "problems": "[read-back problems] (apply)", "revision": "string"}), 600, "Plan first: each differing part's diff names the pads added, removed or changed (moved, resized, reshaped, redrilled, surface or through-hole) and a 3D body count that differs. apply:true replaces every differing part and reads them back: each must sit where it did and match its library. Save with altium_save.", &["edit_footprint", "footprint_from_land_pattern", "swap_footprint", "routing_drc", "save"], &["A pad new in the library has no net, and a removed pad's net goes with it: read padsAdded and padsRemoved before apply.", "Tracks are not moved to follow pads that moved: run altium_routing_drc after."], json!({"filePath": "C:/proj/Board.PcbDoc", "refs": ["U1"]})),+ verb_doc("lint_library", "Check a .PcbLib or .SchLib before it ships: footprints without pads, courtyard, silkscreen or 3D body, with duplicate or missing pad numbers, an origin off the part or no description; symbols without pins or a footprint, with duplicate pin numbers or no part number, and pins that no pad of the linked footprint answers. KiCad's verb of the same name (KiCad's checks that the file parses; an Altium library always does, so this one checks what is in it).",+ json!({"libraryPath": "the .PcbLib or .SchLib (required; filePath accepted too)", "names": "[name] (default every footprint or symbol)", "footprintLibraries": "[.PcbLib] for a SchLib: where the linked footprints are (default the .PcbLibs in the SchLib's folder); footprintLibrary for one"}),+ json!({"ok": "bool: no errors and every item read", "checked": "int", "errors": "int", "warnings": "int", "infos": "int", "findings": "[{name, kind: footprint|symbol, rule, severity: error|warning|info, detail}]", "unread": "[{name, error}]", "footprintLibraries": "[path] (SchLib)"}), 600,+ "Rules: no_pads, zero_size_pad, unnumbered_pad, duplicate_pad_number, no_courtyard (Mechanical 15), no_silkscreen, no_3d_body, origin_off_part, no_description; no_pins, unnumbered_pin, duplicate_pin_number, no_part_number, no_footprint, footprint_not_found, pin_without_pad, pad_without_pin. Read-only.",+ &["read_footprint", "read_symbol", "edit_footprint", "pin_pad_check", "list_library"], &["Each item is one read (about half a second): a library of hundreds takes minutes; names picks a few.", "duplicate_pad_number is right for one pin on several pads (a thermal pad): it is a warning, not an error."], json!({"libraryPath": "C:/lib/Parts.SchLib"})), verb_doc("move_parts", "Move, rotate and flip placed components (side top or bottom; flip:true turns a part over); each part is read back to 0.001 mm, the exact rotation and its side. One undo step.", json!({"parts": "[{ref, x, y, rotation, side?: top|bottom, flip?: bool}] - mm and degrees, Altium's frame; or {ref, dx, dy} to move by an offset; rotation and side kept when left out", "expectedRevision": "string (optional) - the revision you last read; refused with stale_board if the board changed", "boardId": "string (optional) - refused with board_mismatch unless this is the current board", "expectPath": "string (optional)"}), json!({"revision": "string", "results": "[ok|err:...]", "mismatches": "[{ref, asked, got}] when a part did not land where asked (errorCode readback_mismatch)"}), 300,@@ -2184,6 +2189,7 @@ pub fn dispatch(command: &str, args: &Value, _forwarded: &[(String, String)]) -> "xcopy_footprint" => library::xcopy_footprint(args), "swap_footprint" => library::swap_footprint(args), "update_footprints_from_library" => crate::fpupdate::update_footprints_from_library(args),+ "lint_library" => crate::liblint::lint_library(args), "symbol_mode" => library::symbol_mode(args), "cleanup_libs" => library::cleanup_libs(args), "install_library" => library::install_library(args),
bridge-rs/vendor/adom-eda-checks/Cargo.toml+1−1@@ -1,6 +1,6 @@ [package] name = "adom-eda-checks"-version = "0.20.0"+version = "0.21.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/README.md+1@@ -29,6 +29,7 @@ boards the engine gives the same answers the Altium bridge 0.2.76 gives. | `pin_pad_check` | board, sheetParts | each symbol's pins against its footprint's pads: pins with no pad (a net that can never reach copper), pads with no pin (mounting and exposed pads excepted), parts only on the sheets or only on the board. From the Altium bridge's schreview.rs | | `place_decoupling` | board, bodies? | positions for an IC's decoupling caps (`ic`, `caps?`, `gapMm` 0.3): each just outside the IC's box on the side of the power pin it serves, turned so its power pad faces the pin and level with it, sliding along when the spot is taken (by a part on the same side, or a through-hole pad from the other). Without `caps` it takes caps across ground and a supply of the IC, leaving out (`leftOut`) a signal net with one cap (a crystal's load) and a cap nearer another IC's pin on that supply. Each cap's pads keep clear of the stubs and vias plan_fanout would give the IC's other pins (`leaveFanout`, default true), so the fanout still fits after. A cap it cannot place stays where it is and keeps its spot. `icPowerNets` lists the IC's supplies. `moveArgs` is move_parts' arguments; `validation` is placement_check on the moved board. From the KiCad bridge's place_tools | | `length_tune` | board, rules? | a serpentine on the net's longest straight track with room beside it, its bumps sized to add exactly what `targetMm` (or `matchTo`, another net's length) asks, every bump `clearance` (the board's strictest rule) from other nets' pads, routed tracks and vias and inside the board; answered as the track to `remove` and the `routeNet` that replaces it. From the Altium bridge's lengthtune.rs |+| `lint_library` | library | is a symbol or footprint library fit to ship (standard #28): the shared rules with a fixed severity each (`no_pads`, `zero_size_pad`, `duplicate_pad_number`, `no_courtyard`, `origin_off_part`, `pin_without_pad`, `pad_without_pin`, `no_part_number`, ...; `rules` in the reply lists them), checked from the footprints and symbols the bridge sends; a key left out is not checked, a key sent empty is a finding; the bridge's own findings (`tool_refuses_file`) pass through | | `net_lengths` | board | the routed length of each net (tracks and arcs, by layer, with its vias), the skew of each differential pair (`pairs`, else found by net name: `_P`/`_N`, `+`/`-`) and the spread of each matched-length group against its tolerance (`groups`). From the Altium bridge's lengths.rs | | `placement_check` | board, bodies? | courtyard overlaps (pads and bodies, grown by `marginMm`), parts off or over the edge, pads within `edgeMm` of the edge, parts on mounting holes; `stacked` lists plan-view overlaps where one part sits wholly above the other (a part under a raised molecule: pads apart, no bodies meeting in 3D); `bodiesUsed: false` when no bodies were given | | `plan_fanout` | board, stack?, rules? | the fanout of a BGA or QFN/QFP (`ref`): pitch and package from its pads; a BGA's outer ring escapes on the surface and each inner ball takes a dogbone via, or a via in the pad when the dogbone does not fit (`style` auto); a perimeter pad takes an outward stub, with a via at its end for ground or `viaPerimeter`, and an exposed pad a via grid. `calls` are route_net arguments, one per net; `conflicts` lists each via and stub closer than the clearance to another net's pad, track, arc or via anywhere on the board. A pin its net's copper already reaches is skipped (`includeRouted` plans it anyway), the exposed-pad grid keeps clear of holes already there, and `crossesPours` names other nets' pours the plan runs into (repour before DRC). From the KiCad bridge's place_tools |
bridge-rs/vendor/adom-eda-checks/src/lib.rs+4−2@@ -4,7 +4,7 @@ //! answers the verb under its own prefix (`kicad_return_path`). Replies keep the standard envelope (`success`, //! `errorCode`, `error`, `_hint`) and name verbs without a prefix. //!-//! Every check takes one input bundle, `{board, stack?, pours?, rules?, silk?, fab?, bodies?, prices?, sheetParts?, netlist?, args?}` (see `input`).+//! Every check takes one input bundle, `{board, stack?, pours?, rules?, silk?, fab?, bodies?, prices?, sheetParts?, netlist?, library?, args?}` (see `input`). use serde_json::Value; pub mod assembly;@@ -21,6 +21,7 @@ pub mod input; pub mod landpattern; pub mod lengths; pub mod lengthtune;+pub mod liblint; pub mod pairroute; pub mod panel; pub mod report;@@ -39,7 +40,7 @@ pub mod writers; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); /// The checks this build answers, by standard verb name.-pub const CHECKS: &[&str] = &["assembly_check", "auto_classes", "board_report", "check_clearance", "check_orientation", "copper_balance", "current_capacity", "estimate_cost", "fab_check", "find_space", "footprint_from_land_pattern", "height_check", "impedance", "length_tune", "net_lengths", "panelize", "pin_pad_check", "place_decoupling", "placement_check", "plan_fanout", "plan_route", "return_path", "review_board", "route_pair", "schematic_review", "silk_designators", "teardrops", "thermal_vias", "via_fence"];+pub const CHECKS: &[&str] = &["assembly_check", "auto_classes", "board_report", "check_clearance", "check_orientation", "copper_balance", "current_capacity", "estimate_cost", "fab_check", "find_space", "footprint_from_land_pattern", "height_check", "impedance", "length_tune", "lint_library", "net_lengths", "panelize", "pin_pad_check", "place_decoupling", "placement_check", "plan_fanout", "plan_route", "return_path", "review_board", "route_pair", "schematic_review", "silk_designators", "teardrops", "thermal_vias", "via_fence"]; /// Run one check or writer by its standard name. The reply carries `engine`. pub fn run(check: &str, input: &Value) -> Value {@@ -65,6 +66,7 @@ fn answer(check: &str, input: &Value) -> Value { "height_check" => bodies::height_check(input), "impedance" => impedance::impedance(input), "length_tune" => lengthtune::length_tune(input),+ "lint_library" => liblint::lint_library(input), "net_lengths" => lengths::net_lengths(input), "panelize" => panel::panelize(input), "pin_pad_check" => schreview::pin_pad_check(input),
bridge-rs/vendor/adom-eda-checks/src/liblint.rsadded+239@@ -0,0 +1,239 @@+//! Library lint (EDA Bridge Standard #28): is a symbol or footprint library fit to ship? The content rules every bridge+//! can share, from the footprints and symbols it already reads; a bridge adds its tool's own (KiCad's+//! `tool_refuses_file`) to the same findings. Severity belongs to the rule, not the bridge. A rule is only evaluated+//! when the bridge sent what it needs: a key left out means "not read" and emits nothing, a key sent empty is a finding.+use serde_json::{json, Value};+use std::collections::{BTreeMap, BTreeSet};++/// The shared vocabulary: (kind, rule, severity).+pub const RULES: &[(&str, &str, &str)] = &[+ ("footprint", "no_pads", "error"),+ ("footprint", "zero_size_pad", "error"),+ ("footprint", "unnumbered_pad", "warning"),+ ("footprint", "duplicate_pad_number", "warning"),+ ("footprint", "no_courtyard", "warning"),+ ("footprint", "origin_off_part", "warning"),+ ("footprint", "no_silkscreen", "info"),+ ("footprint", "no_3d_body", "info"),+ ("footprint", "no_description", "info"),+ ("symbol", "no_pins", "error"),+ ("symbol", "footprint_not_found", "error"),+ ("symbol", "pin_without_pad", "error"),+ ("symbol", "unnumbered_pin", "warning"),+ ("symbol", "duplicate_pin_number", "warning"),+ ("symbol", "no_footprint", "warning"),+ ("symbol", "pad_without_pin", "warning"),+ ("symbol", "no_part_number", "info"),+ ("library", "tool_refuses_file", "error"),+];++/// How far past the pads and courtyard the origin may sit before it counts as off the part (mm).+pub const ORIGIN_MARGIN_MM: f64 = 1.0;++fn severity(rule: &str) -> &'static str { RULES.iter().find(|r| r.1 == rule).map(|r| r.2).unwrap_or("warning") }+fn f(v: &Value) -> f64 { v.as_f64().unwrap_or(0.0) }+fn text(v: &Value) -> String { match v { Value::String(s) => s.trim().to_string(), Value::Number(n) => n.to_string(), _ => String::new() } }+/// Sent but empty: null, "", [] or {}.+fn empty(v: &Value) -> bool { match v { Value::Null => true, Value::String(s) => s.trim().is_empty(), Value::Array(a) => a.is_empty(), Value::Object(o) => o.is_empty(), _ => false } }+/// A pad no pin connects to: a mechanical hole, or unplated.+fn mechanical(p: &Value) -> bool { p["mechanical"] == true || p["plated"] == false }+/// "Lib:Name" and "Name" name the same footprint.+fn base(name: &str) -> &str { name.rsplit(':').next().unwrap_or(name) }+/// "pin 3 has" or "pins 2, 3 have".+fn list(word: &str, items: &[&String]) -> String {+ let names = items.iter().map(|s| s.as_str()).collect::<Vec<_>>().join(", ");+ if items.len() == 1 { format!("{word} {names} has") } else { format!("{word}s {names} have") }+}++/// A courtyard's extent: [x0, y0, x1, y1], {x0, y0, x1, y1}, or a list of [x, y] points.+fn extent(c: &Value) -> Option<(f64, f64, f64, f64)> {+ if let Some(a) = c.as_array() {+ if a.len() == 4 && a.iter().all(|v| v.is_number()) { return Some((f(&a[0]).min(f(&a[2])), f(&a[1]).min(f(&a[3])), f(&a[0]).max(f(&a[2])), f(&a[1]).max(f(&a[3])))); }+ let pts: Vec<(f64, f64)> = a.iter().filter_map(|p| p.as_array().filter(|q| q.len() >= 2).map(|q| (f(&q[0]), f(&q[1])))).collect();+ if pts.is_empty() { return None; }+ return Some(pts.iter().fold((f64::MAX, f64::MAX, f64::MIN, f64::MIN), |b, p| (b.0.min(p.0), b.1.min(p.1), b.2.max(p.0), b.3.max(p.1))));+ }+ if c["x0"].is_number() { return Some((f(&c["x0"]).min(f(&c["x1"])), f(&c["y0"]).min(f(&c["y1"])), f(&c["x0"]).max(f(&c["x1"])), f(&c["y0"]).max(f(&c["y1"])))); }+ None+}++/// A pad's copper box (the hole's, if larger), in the footprint's frame.+fn pad_box(p: &Value) -> (f64, f64, f64, f64) {+ let (x, y) = (f(&p["x"]), f(&p["y"]));+ let (w, h) = (f(&p["w"]).max(f(&p["hole"])) / 2.0, f(&p["h"]).max(f(&p["hole"])) / 2.0);+ (x - w, y - h, x + w, y + h)+}++/// How many separate lands the boxes make: boxes that touch or overlap (within 0.01 mm) join.+fn lands(boxes: &[(f64, f64, f64, f64)]) -> usize {+ let mut group: Vec<usize> = (0..boxes.len()).collect();+ fn root(g: &mut Vec<usize>, i: usize) -> usize { let mut i = i; while g[i] != i { g[i] = g[g[i]]; i = g[i]; } i }+ let touch = |a: &(f64, f64, f64, f64), b: &(f64, f64, f64, f64)| a.0 <= b.2 + 0.01 && b.0 <= a.2 + 0.01 && a.1 <= b.3 + 0.01 && b.1 <= a.3 + 0.01;+ for i in 0..boxes.len() { for j in i + 1..boxes.len() { if touch(&boxes[i], &boxes[j]) { let (a, b) = (root(&mut group, i), root(&mut group, j)); group[a] = b; } } }+ (0..boxes.len()).filter(|&i| root(&mut group, i) == i).count()+}++fn finding(name: &str, kind: &str, rule: &str, detail: String) -> Value {+ json!({"name": name, "kind": kind, "rule": rule, "severity": severity(rule), "detail": detail})+}++/// The findings for one footprint (pads in its own frame, mm, origin at 0,0).+pub fn lint_footprint(fp: &Value) -> Vec<Value> {+ let name = text(&fp["name"]);+ let mut out = Vec::new();+ let pads = fp["pads"].as_array().cloned().unwrap_or_default();+ if pads.is_empty() { out.push(finding(&name, "footprint", "no_pads", "the footprint has no pads".into())); }+ let mut seen: BTreeMap<String, Vec<(f64, f64, f64, f64)>> = BTreeMap::new();+ for p in &pads {+ let (w, h, hole) = (f(&p["w"]), f(&p["h"]), f(&p["hole"]));+ if (w <= 0.0 || h <= 0.0) && hole <= 0.0 { out.push(finding(&name, "footprint", "zero_size_pad", format!("pad {} is {w} x {h} mm", text(&p["number"])))); }+ let n = text(&p["number"]);+ if n.is_empty() { if !mechanical(p) { out.push(finding(&name, "footprint", "unnumbered_pad", format!("a pad at ({}, {}) has no number", f(&p["x"]), f(&p["y"])))); } }+ else if !mechanical(p) { seen.entry(n).or_default().push(pad_box(p)); }+ }+ // pads sharing a number that touch or overlap are one land (a split exposed pad, thermal vias in it): a duplicate+ // is a number on lands apart from each other+ for (n, boxes) in &seen {+ let lands = lands(boxes);+ if lands > 1 { out.push(finding(&name, "footprint", "duplicate_pad_number", format!("pad number {n} is on {lands} separate lands ({} pads)", boxes.len()))); }+ }+ let court = fp.get("courtyard");+ if court.map(empty).unwrap_or(false) { out.push(finding(&name, "footprint", "no_courtyard", "no courtyard".into())); }+ // the origin should sit on the part: inside the pads and courtyard, grown by the margin+ let mut b: Option<(f64, f64, f64, f64)> = None;+ let mut grow = |e: (f64, f64, f64, f64)| b = Some(b.map_or(e, |o| (o.0.min(e.0), o.1.min(e.1), o.2.max(e.2), o.3.max(e.3))));+ for p in &pads { let (x, y, w, h) = (f(&p["x"]), f(&p["y"]), f(&p["w"]).max(f(&p["hole"])) / 2.0, f(&p["h"]).max(f(&p["hole"])) / 2.0); grow((x - w, y - h, x + w, y + h)); }+ if let Some(e) = court.and_then(extent) { grow(e); }+ if let Some((x0, y0, x1, y1)) = b {+ let m = ORIGIN_MARGIN_MM;+ if 0.0 < x0 - m || 0.0 > x1 + m || 0.0 < y0 - m || 0.0 > y1 + m {+ let (dx, dy) = ((x0 - m).max(0.0) + (0.0f64).max(-(x1 + m)), (y0 - m).max(0.0) + (0.0f64).max(-(y1 + m)));+ out.push(finding(&name, "footprint", "origin_off_part", format!("the origin is {:.3} mm outside the pads and courtyard (part spans x {x0:.3}..{x1:.3}, y {y0:.3}..{y1:.3})", (dx * dx + dy * dy).sqrt())));+ }+ }+ if fp.get("silk").map(empty).unwrap_or(false) { out.push(finding(&name, "footprint", "no_silkscreen", "no silkscreen".into())); }+ if fp.get("bodies").map(empty).unwrap_or(false) { out.push(finding(&name, "footprint", "no_3d_body", "no 3D body".into())); }+ if fp.get("description").map(empty).unwrap_or(false) { out.push(finding(&name, "footprint", "no_description", "no description".into())); }+ out+}++/// The findings for one symbol, against the footprints the bridge sent (None: footprints not read, so the+/// footprint rules that need them are not evaluated).+pub fn lint_symbol(sym: &Value, footprints: Option<&BTreeMap<String, Value>>) -> Vec<Value> {+ let name = text(&sym["name"]);+ let mut out = Vec::new();+ let pins = sym["pins"].as_array().cloned().unwrap_or_default();+ if pins.is_empty() { out.push(finding(&name, "symbol", "no_pins", "the symbol has no pins".into())); }+ let mut numbers: BTreeMap<String, usize> = BTreeMap::new();+ for p in &pins {+ let n = text(&p["number"]);+ if n.is_empty() { out.push(finding(&name, "symbol", "unnumbered_pin", format!("pin {} has no number", text(&p["name"])))); }+ else { *numbers.entry(n).or_default() += 1; }+ }+ for (n, k) in &numbers { if *k > 1 { out.push(finding(&name, "symbol", "duplicate_pin_number", format!("{k} pins are numbered {n}"))); } }+ let fps: Vec<String> = match sym.get("footprint") {+ Some(Value::Array(a)) => a.iter().map(text).filter(|s| !s.is_empty()).collect(),+ Some(v) => Some(text(v)).filter(|s| !s.is_empty()).into_iter().collect(),+ None => Vec::new(),+ };+ if sym.get("footprint").map(empty).unwrap_or(false) { out.push(finding(&name, "symbol", "no_footprint", "no footprint is linked".into())); }+ if let Some(lib) = footprints {+ for fpn in &fps {+ let Some(fp) = lib.get(fpn).or_else(|| lib.get(base(fpn))) else {+ out.push(finding(&name, "symbol", "footprint_not_found", format!("footprint {fpn} is not in the footprint libraries checked")));+ continue;+ };+ let pads: BTreeSet<String> = fp["pads"].as_array().map(|a| a.iter().filter(|p| !mechanical(p)).map(|p| text(&p["number"])).filter(|n| !n.is_empty()).collect()).unwrap_or_default();+ let missing: Vec<&String> = numbers.keys().filter(|n| !pads.contains(*n)).collect();+ if !missing.is_empty() { out.push(finding(&name, "symbol", "pin_without_pad", format!("{} no pad on {fpn}", list("pin", &missing)))); }+ let spare: Vec<&String> = pads.iter().filter(|n| !numbers.contains_key(*n)).collect();+ if !spare.is_empty() { out.push(finding(&name, "symbol", "pad_without_pin", format!("{} no pin on {fpn}", list("pad", &spare)))); }+ }+ }+ if sym.get("partNumber").map(empty).unwrap_or(false) { out.push(finding(&name, "symbol", "no_part_number", "no manufacturer part number".into())); }+ out+}++/// lint_library: input {library: {footprints?: [{name, pads: [{number, x, y, w, h, hole?, mechanical?, plated?}],+/// courtyard?, silk?, bodies?, description?}], symbols?: [{name, pins: [{number, name?}], footprint?, partNumber?}],+/// unread?: [{name, error}], findings?: [the bridge's own]}, args: {names?}}. Symbols are checked against the footprints+/// sent (the library's own, or those of footprintLibraries the bridge resolved).+pub fn lint_library(input: &Value) -> Value {+ let lib = &input["library"];+ if !lib.is_object() { return crate::input::refuse("bad_args", "library is required: {footprints?, symbols?, unread?, findings?}"); }+ let names: Option<BTreeSet<String>> = input["args"]["names"].as_array().map(|a| a.iter().map(text).collect());+ let wanted = |v: &Value| names.as_ref().map(|n| n.contains(&text(&v["name"]))).unwrap_or(true);+ let fps = lib["footprints"].as_array().cloned().unwrap_or_default();+ let syms = lib["symbols"].as_array().cloned().unwrap_or_default();+ let by_name: Option<BTreeMap<String, Value>> = lib.get("footprints").filter(|v| v.is_array()).map(|_| fps.iter().map(|fp| (text(&fp["name"]), fp.clone())).flat_map(|(n, fp)| [(base(&n).to_string(), fp.clone()), (n, fp)]).collect());+ let mut findings: Vec<Value> = lib["findings"].as_array().cloned().unwrap_or_default();+ let mut checked = 0;+ for fp in fps.iter().filter(|v| wanted(v)) { checked += 1; findings.extend(lint_footprint(fp)); }+ for s in syms.iter().filter(|v| wanted(v)) { checked += 1; findings.extend(lint_symbol(s, by_name.as_ref())); }+ let count = |sev: &str| findings.iter().filter(|x| x["severity"] == sev).count();+ let (errors, warnings, infos) = (count("error"), count("warning"), count("info"));+ let unread = lib["unread"].as_array().cloned().unwrap_or_default();+ json!({"success": true, "ok": errors == 0 && unread.is_empty(), "checked": checked, "errors": errors, "warnings": warnings, "infos": infos,+ "findings": findings, "unread": unread,+ "rules": RULES.iter().map(|r| json!({"kind": r.0, "rule": r.1, "severity": r.2})).collect::<Vec<_>>(),+ "_hint": "Errors stop a part working; warnings are usually mistakes; infos are gaps. A rule is only checked when the bridge read what it needs, so a missing finding is not a pass for a rule the bridge could not read."})+}++#[cfg(test)]+mod tests {+ use super::*;++ fn pad(n: &str, x: f64, y: f64) -> Value { json!({"number": n, "x": x, "y": y, "w": 0.6, "h": 1.5}) }++ #[test]+ fn a_clean_footprint_and_its_symbol_pass() {+ let r = lint_library(&json!({"library": {+ "footprints": [{"name": "SOT23", "pads": [pad("1", -0.95, -1.1), pad("2", 0.95, -1.1), pad("3", 0.0, 1.1)], "courtyard": [-1.7, -2.0, 1.7, 2.0], "silk": [[0, 0]], "bodies": [{"h": 1.1}], "description": "SOT-23"}],+ "symbols": [{"name": "BJT", "pins": [{"number": "1"}, {"number": "2"}, {"number": "3"}], "footprint": "Lib:SOT23", "partNumber": "MMBT3904"}]}}));+ assert_eq!(r["ok"], true, "{r}");+ assert_eq!(r["checked"], 2);+ assert_eq!(r["findings"], json!([]));+ }++ #[test]+ fn the_shared_rules_fire_with_their_own_severity() {+ // the xcopy bug of altium-bridge#29: a copy 1270 mm off its origin+ let far = json!({"name": "BAT_FP_X", "pads": [pad("1", 1270.0, 0.0), pad("1", 1272.0, 0.0), json!({"number": "", "x": 1271.0, "y": 0.0, "w": 0.0, "h": 0.0})], "courtyard": null, "silk": [], "description": ""});+ let r = lint_library(&json!({"library": {"footprints": [far],+ "symbols": [{"name": "BAT", "pins": [{"number": "1"}, {"number": "2"}], "footprint": "BAT_FP_X", "partNumber": ""}, {"name": "LOST", "pins": [{"number": "1"}], "footprint": "NOPE"}, {"name": "BARE", "pins": [], "footprint": ""}],+ "findings": [{"name": "X", "kind": "library", "rule": "tool_refuses_file", "severity": "error", "detail": "kicad-cli: bad token"}]}}));+ let rules: Vec<&str> = r["findings"].as_array().unwrap().iter().map(|x| x["rule"].as_str().unwrap()).collect();+ for want in ["tool_refuses_file", "zero_size_pad", "unnumbered_pad", "duplicate_pad_number", "no_courtyard", "origin_off_part", "no_silkscreen", "no_description", "pin_without_pad", "no_part_number", "footprint_not_found", "no_pins", "no_footprint"] {+ assert!(rules.contains(&want), "{want} missing from {rules:?}");+ }+ // bodies was not sent, so no_3d_body is not evaluated+ assert!(!rules.contains(&"no_3d_body"));+ assert_eq!(r["ok"], false);+ assert!(r["findings"].as_array().unwrap().iter().all(|x| x["severity"] == severity(x["rule"].as_str().unwrap())));+ let off = r["findings"].as_array().unwrap().iter().find(|x| x["rule"] == "origin_off_part").unwrap();+ assert!(off["detail"].as_str().unwrap().starts_with("the origin is 1268.700 mm"), "{off}");+ }++ #[test]+ fn a_split_exposed_pad_is_one_land() {+ // KiCad's Package_SO: an exposed pad 17 as four tiles and two thermal vias, plus two pins both numbered 1+ let ep: Vec<Value> = [(-0.6, -0.6), (0.6, -0.6), (-0.6, 0.6), (0.6, 0.6)].iter().map(|&(x, y)| json!({"number": "17", "x": x, "y": y, "w": 1.2, "h": 1.2})).chain([json!({"number": "17", "x": 0.0, "y": 0.0, "w": 0.6, "h": 0.6, "hole": 0.3}), json!({"number": "17", "x": 0.3, "y": 0.0, "w": 0.0, "h": 0.0, "mechanical": true})]).collect();+ let mut pads = ep.clone();+ pads.extend([pad("1", -2.7, 1.9), pad("1", 2.7, 1.9)]);+ let r = lint_library(&json!({"library": {"footprints": [{"name": "HTSSOP", "pads": pads}]}}));+ let d: Vec<&str> = r["findings"].as_array().unwrap().iter().filter(|x| x["rule"] == "duplicate_pad_number").map(|x| x["detail"].as_str().unwrap()).collect();+ assert_eq!(d, vec!["pad number 1 is on 2 separate lands (2 pads)"], "{r}");+ }++ #[test]+ fn a_spare_pad_warns_and_a_mechanical_one_does_not() {+ let fp = json!({"name": "USB", "pads": [pad("1", 0.0, 0.0), pad("2", 0.65, 0.0), pad("S1", 3.0, 0.0), json!({"number": "", "x": -2.0, "y": 1.0, "w": 0.0, "h": 0.0, "hole": 0.65, "plated": false})]});+ let r = lint_library(&json!({"library": {"footprints": [fp], "symbols": [{"name": "USB", "pins": [{"number": "1"}, {"number": "2"}], "footprint": "USB"}]}}));+ let f: Vec<(&str, &str)> = r["findings"].as_array().unwrap().iter().map(|x| (x["rule"].as_str().unwrap(), x["detail"].as_str().unwrap())).collect();+ assert_eq!(f, vec![("pad_without_pin", "pad S1 has no pin on USB")], "{r}");+ assert_eq!(r["ok"], true, "a warning does not fail the library");+ // a name filter, and unread items fail ok+ let r = lint_library(&json!({"library": {"footprints": [{"name": "A", "pads": []}, {"name": "B", "pads": [pad("1", 0.0, 0.0)]}], "unread": [{"name": "C", "error": "locked"}]}, "args": {"names": ["B"]}}));+ assert_eq!((r["checked"].clone(), r["errors"].clone(), r["ok"].clone()), (json!(1), json!(0), json!(false)));+ }+}
bridge-rs/vendor/adom-eda-checks/src/main.rs+1−1@@ -23,7 +23,7 @@ fn bundle(rest: &[String]) -> Result<Value, String> { while let Some(flag) = it.next() { let val = it.next().ok_or_else(|| format!("{flag} needs a value"))?; match flag.as_str() {- "--board" | "--stack" | "--pours" | "--rules" | "--silk" | "--fab" | "--bodies" | "--prices" | "--sheet-parts" | "--netlist" | "--drc" => {+ "--board" | "--stack" | "--pours" | "--rules" | "--silk" | "--fab" | "--bodies" | "--prices" | "--sheet-parts" | "--netlist" | "--drc" | "--library" => { let key = match flag.as_str() { "--sheet-parts" => "sheetParts", f => &f[2..] }; b[key] = read(val)?; }
dev-skills/altium-bridge-test/run_verb_tests.py+4@@ -164,6 +164,10 @@ def matrix(w): M["edit_footprint"] = dict(phase=2.5, **ok(libraryPath=PL, name="BAT_FP", addPads=[{"number": "99", "at": [5, 5], "sizeMm": [0.5, 0.5]}], metadata={"description": "edited by the battery"}), check=lambda d: d.get("failed") == 0 and len(d.get("changes") or []) == 2)+ # 0.2.84: the SchLib's symbols against the PcbLib beside it: every TST_ symbol's pins have pads, so no errors+ M["lint_library"] = dict(phase=2.5, timeout=300, **ok(libraryPath=SL),+ check=lambda d: d.get("errors") == 0 and (d.get("checked") or 0) >= 4 and d.get("footprintLibraries")+ and not [f for f in d.get("findings") or [] if f.get("rule") in ("pin_without_pad", "footprint_not_found")]) M["build_footprint"] = dict(phase=2, **ref("no spec given: must refuse by name", libraryPath=PL)) M["cleanup_libs"] = dict(phase=2, **anyo("library housekeeping", libraryPath=SL)) M["save"] = dict(phase=2, **ok(filePath=SL))
src/agent/AdomAgent.pas.tmpl+9−8@@ -498,15 +498,16 @@ Begin End; If Kind <> 'Project' Then Begin- { open under another spelling of the path, it is this file: opening it again makes a second copy }+ { open under another spelling of the path, it is this file: open it by ITS spelling, and Altium answers that+ document rather than a second copy. OpenDocument still runs: showing the found document without it left no+ current board, and DRC on it crashed in ADVPCB.DLL (two batteries, 2026-10-30) } Doc := DocAt(Path);- If Doc = Nil Then- Begin- Try- Doc := Client.OpenDocument(Kind, Path);- Except- Doc := Nil;- End;+ If Doc <> Nil Then Path := Doc.FileName;+ Doc := Nil;+ Try+ Doc := Client.OpenDocument(Kind, Path);+ Except+ Doc := Nil; End; If Doc <> Nil Then Begin
src/bridge.json+2−1@@ -197,6 +197,7 @@ "altium_simulate", "altium_export_spice", "altium_update_footprints_from_library",+ "altium_lint_library", "altium_route_pair", "altium_routing_drc", "altium_routing_state",@@ -290,7 +291,7 @@ "launch": 240, "panelize": 240, "impedance": 120,- "current_capacity": 120, "plan_route": 300, "place_decoupling": 300, "plan_fanout": 300, "estimate_cost": 120, "simulate": 900, "export_spice": 900, "update_footprints_from_library": 600,+ "current_capacity": 120, "plan_route": 300, "place_decoupling": 300, "plan_fanout": 300, "estimate_cost": 120, "simulate": 900, "export_spice": 900, "update_footprints_from_library": 600, "lint_library": 600, "height_check": 150, "copper_balance": 240, "return_path": 240,