← Commit history
0.2.118: PR #165 (isolation barriers, jumper pads), hole clearance, per-shape bodies (closes #255 #256 #262 #264)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
12 files changed
+145−20
Cargo.lock+10−10Cargo.toml+1−1bin/adom-aiflowcrates/adom-aiflow/src/main.rs+3crates/adom-aiflow/src/mechanical.rs+26−6crates/aiflow-router/src/lib.rs+18crates/aiflow-router/src/project_rules.rs+30crates/aiflow-router/src/rules.rs+6−1crates/aiflow-router/tests/obstacles.rs+32docs/release-0.2.118.md+17package.json+1−1page.json+1−1Cargo.lock+10−10@@ -4,7 +4,7 @@ version = 4 [[package]] name = "adom-aiflow"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-analyze", "aiflow-board",@@ -25,7 +25,7 @@ dependencies = [ [[package]] name = "aiflow-analyze"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "serde",@@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "aiflow-board"-version = "0.2.117"+version = "0.2.118" dependencies = [ "roxmltree", "serde",@@ -44,7 +44,7 @@ dependencies = [ [[package]] name = "aiflow-bridge"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "serde",@@ -53,7 +53,7 @@ dependencies = [ [[package]] name = "aiflow-copper"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "aiflow-grid",@@ -63,7 +63,7 @@ dependencies = [ [[package]] name = "aiflow-grid"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "serde",@@ -72,7 +72,7 @@ dependencies = [ [[package]] name = "aiflow-place"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "serde",@@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "aiflow-pours"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "aiflow-copper",@@ -91,7 +91,7 @@ dependencies = [ [[package]] name = "aiflow-router"-version = "0.2.117"+version = "0.2.118" dependencies = [ "aiflow-board", "aiflow-grid",@@ -102,7 +102,7 @@ dependencies = [ [[package]] name = "aiflow-run"-version = "0.2.117"+version = "0.2.118" dependencies = [ "serde", "serde_json",
Cargo.toml+1−1@@ -14,7 +14,7 @@ members = [ ] [workspace.package]-version = "0.2.117"+version = "0.2.118" edition = "2021" license = "MIT" repository = "https://wiki.adom.inc/adom/adom-aiflow"
bin/adom-aiflow⋯ 1 unchanged line ⋯
crates/adom-aiflow/src/main.rs+3@@ -5734,6 +5734,9 @@ fn main() { let pc = aiflow_router::project_rules::read(&b, pro.as_deref(), dru.as_deref(), rules.clearance); for (n, v) in &pc.nets { let e = rules.net_clearance.entry(n.clone()).or_insert(*v); if *v > *e { *e = *v; } } rules.clear_regions = pc.regions.clone();+ // issue #255: the board-wide hole clearance of the .kicad_dru, when wider than the spec's+ if let Some(hc) = pc.hole_clearance.filter(|hc| *hc > rules.hole_clearance) { rules.hole_clearance = hc; }+ if rules.hole_clearance > rules.clearance { eprintln!("project rules: tracks and vias keep {} mm from drilled holes (hole clearance)", rules.hole_clearance); } if !pc.nets.is_empty() || !pc.regions.is_empty() { eprintln!("project rules: {} net(s) with a wider clearance from net classes or rules{}{}", pc.nets.len(), if pc.regions.is_empty() { String::new() } else { format!("; clearance region(s) {}", pc.regions.iter().map(|g| format!("{} {} mm", g.name, g.clearance)).collect::<Vec<_>>().join(", ")) },
crates/adom-aiflow/src/mechanical.rs+26−6@@ -399,13 +399,12 @@ pub fn check(b: &Board, board_path: &str, model_box: &dyn Fn(&str) -> Option<(f6 if pads == 0 || is_net_tie(fp) || (flag(fp, "exclude_from_bom") && flag(fp, "exclude_from_pos_files")) { continue; } let mut got = false; for (layer, front) in [("F.Fab", true), ("B.Fab", false)] {- let (closed, open) = layer_geometry(fp, layer);- let pts: Vec<Pt> = closed.into_iter().chain(open).flatten().collect();- if pts.len() < 3 { continue; }- let h = hull(&pts);- if h.len() < 3 { continue; }+ // issue #256 (Ryan Bertsch): a body drawn as separate closed shapes (a module on four corner sockets) is+ // one body per shape, as body_parts reads it (issue #236), never one hull over the parts between them+ let parts = body_parts(fp, layer);+ if parts.is_empty() { continue; } got = true;- bodies.push(Shape { reference: reference.clone(), front, polys: place(vec![h], x, y, rot) });+ bodies.push(Shape { reference: reference.clone(), front, polys: place(parts, x, y, rot) }); } if !got { if let Some((x0, y0, x1, y1)) = model_box(&reference) {@@ -547,6 +546,27 @@ pub(crate) mod tests { Board::from_text("t.kicad_pcb", t).unwrap() } + #[test]+ fn a_module_on_four_corner_sockets_is_four_bodies() {+ // issue #256 (Ryan Bertsch): a daughterboard on four 2x5 sockets draws four rectangles on F.Fab; a cap placed+ // between the sockets is under the module, not in a body; a cap on a socket still collides+ let module = |x: f64, y: f64| {+ let mut s = format!(" (footprint \"T:Module\" (layer \"F.Cu\") (at {x} {y})\n (property \"Reference\" \"U1\" (at 0 0 0) (layer \"F.Fab\"))\n (attr through_hole)\n");+ for (k, (cx, cy)) in [(-12.0f64, -8.0f64), (12.0, -8.0), (12.0, 8.0), (-12.0, 8.0)].into_iter().enumerate() {+ s.push_str(&format!(" (fp_rect (start {} {}) (end {} {}) (layer \"F.Fab\") (width 0.1))\n", cx - 2.0, cy - 1.0, cx + 2.0, cy + 1.0));+ s.push_str(&format!(" (pad \"{}\" thru_hole circle (at {cx} {cy}) (size 1.6 1.6) (drill 1.0) (layers \"*.Cu\"))\n", k + 1));+ }+ s.push_str(" )\n");+ s+ };+ let between = board(&[module(110.0, 80.0), part("C1", 110.0, 80.0, 1.6, 0.8, None, "")]);+ let r = check(&between, "/nonexistent/t.kicad_pcb", &|_| None);+ assert!(r.body_overlaps.is_empty(), "a cap between the sockets: {:?}", r.body_overlaps);+ let on_socket = board(&[module(110.0, 80.0), part("C2", 98.0, 72.0, 1.6, 0.8, None, "")]);+ let r = check(&on_socket, "/nonexistent/t.kicad_pcb", &|_| None);+ assert_eq!(r.body_overlaps.len(), 1, "a cap on a socket: {:?}", r.body_overlaps);+ }+ #[test] fn the_issue_example_two_5mm_bodies_4mm_apart_overlap_by_1mm() { // C6 at (105, 75.5) and C7 at (105, 79.5), each a 5 mm body: no courtyards, bodies overlap 1 mm
crates/aiflow-router/src/lib.rs+18@@ -437,6 +437,10 @@ impl Router { for c in g.disk_cells((h.x, h.y), h.size.0.min(h.size.1) / 2.0, None) { m.bits[c] = true; }+ // issue #255 (Deepak Madan): tracks and vias keep the board's hole clearance from a drilled hole's edge,+ // not only the ordinary copper clearance they keep from these cells: grow the hole by the difference+ let extra = self.rules.hole_clearance - self.rules.clearance;+ if extra > 1e-9 { m = g.dilate(&m, extra / g.res); } let fpi = self.fp_index.get(&h.reference).map(|&k| k as i16).unwrap_or(-1); for c in m.bits.iter().enumerate().filter(|(_, b)| **b).map(|(i, _)| i) { for l in [F_CU, B_CU] {@@ -448,6 +452,20 @@ impl Router { self.thru_cells.bits[c] = true; } }+ // issue #255: an NPTH kept as a no-net through pad (a mounting hole listing copper layers, pad size = drill)+ // keeps the hole clearance too: the ring between its edge and the hole clearance is stamped as no-net copper+ let extra = self.rules.hole_clearance - self.rules.clearance;+ if extra > 1e-9 {+ let pads = self.board.pads.clone();+ for p in pads.iter().filter(|p| p.thru && p.net.is_empty() && p.drill.is_some_and(|d| d + 1e-6 >= p.size.0.min(p.size.1))) {+ let fpi = self.fp_index.get(&p.reference).map(|&k| k as i16).unwrap_or(-1);+ for c in g.disk_cells((p.x, p.y), p.size.0.min(p.size.1) / 2.0 + extra, None) {+ for l in [F_CU, B_CU] {+ if self.pad_raw[l][c] == -1 { self.pad_raw[l][c] = -2; self.pad_owner[l][c] = fpi; }+ }+ }+ }+ } } /// Resolve the planeUnder regions and mark their cells. A region the board cannot resolve is
crates/aiflow-router/src/project_rules.rs+30@@ -25,6 +25,20 @@ pub struct ProjectClearances { pub regions: Vec<ClearRegion>, /// rules with a clearance the router could not place, as written pub not_applied: Vec<String>,+ /// Issue #255: the largest board-wide (unconditioned) `hole_clearance` minimum, mm+ pub hole_clearance: Option<f64>,+}++/// Issue #255: the largest `hole_clearance` minimum of a .kicad_dru rule with no condition (board-wide).+pub fn dru_hole_clearance(dru: &str) -> Option<f64> {+ let re_rule = regex_lite::Regex::new(r#"\(rule\s"#).unwrap();+ let re_hc = regex_lite::Regex::new(r#"\(constraint\s+hole_clearance\s+\(min\s+([0-9.]+\s*(?:mm|mil)?)\)"#).unwrap();+ let starts: Vec<usize> = re_rule.find_iter(dru).map(|m| m.start()).collect();+ starts.iter().enumerate().filter_map(|(k, &s)| {+ let block = &dru[s..starts.get(k + 1).copied().unwrap_or(dru.len())];+ if block.contains("(condition") { return None; }+ re_hc.captures(block).and_then(|c| mm(&c[1]))+ }).fold(None, |a: Option<f64>, v| Some(a.map_or(v, |a| a.max(v)))) } /// A KiCad net class pattern (`*` and `?` wildcards) against a net name; a leading "/" is ignored on both sides.@@ -93,6 +107,7 @@ fn area(board: &Board, name: &str) -> Option<Vec<Pt>> { /// are any), `base` the clearance the router already uses everywhere. pub fn read(board: &Board, pro: Option<&str>, dru: Option<&str>, base: f64) -> ProjectClearances { let mut out = ProjectClearances::default();+ out.hole_clearance = dru.and_then(dru_hole_clearance); let nets: Vec<String> = board.nets.keys().cloned().collect(); let pro: Value = pro.and_then(|t| serde_json::from_str(t).ok()).unwrap_or(Value::Null); let class_clr: BTreeMap<String, f64> = pro["net_settings"]["classes"].as_array().into_iter().flatten()@@ -174,4 +189,19 @@ mod tests { fn patterns_match_like_kicad() { assert!(glob("/HV_*", "/HV_BUS") && glob("HV_*", "/HV_BUS") && glob("V?", "V5") && !glob("HV_*", "/LV_BUS")); }++ #[test]+ fn a_board_wide_hole_clearance_rule_is_read() {+ // issue #255 (Deepak Madan): the 3rd party fab's 2L rules hold copper 0.25 mm from a hole's edge+ let dru = r#"(version 1)+(rule "Hole to copper" (constraint hole_clearance (min 0.25mm)))+(rule "HV holes" (condition "A.NetClass == 'HV'") (constraint hole_clearance (min 0.6mm)))+(rule "Track" (constraint track_width (min 0.127mm)))"#;+ assert_eq!(dru_hole_clearance(dru), Some(0.25), "the conditioned rule is not board-wide");+ assert_eq!(dru_hole_clearance("(version 1)\n(rule \"x\" (constraint hole_clearance (min 10mil)))"), Some(0.254));+ assert_eq!(dru_hole_clearance("(version 1)"), None);+ let b = Board::from_text("t.kicad_pcb", BOARD.to_string()).unwrap();+ assert_eq!(read(&b, None, Some(dru), 0.1).hole_clearance, Some(0.25));+ }+ }
crates/aiflow-router/src/rules.rs+6−1@@ -57,6 +57,10 @@ pub struct Rules { /// opt in on a VIPPO-capable fab. #[serde(default)] pub allow_via_in_pad: bool,+ /// Issue #255 (Deepak Madan): copper to a drilled hole's edge (mm): spec `holeClearance`, or a board-wide+ /// `hole_clearance` rule in the project's .kicad_dru (main.rs reads it). 0: the ordinary clearance only.+ #[serde(default)]+ pub hole_clearance: f64, /// Issue #262: isolation domains (spec `isolationDomains`: [{nets, clearance}]). A net in one domain keeps the /// domain's clearance from every net outside it (a net outside every domain keeps the other domain's), and only /// the ordinary clearance from nets of its own domain: an isolation barrier between net groups, the way a KiCad@@ -101,7 +105,7 @@ impl Default for Rules { track: 0.25, clearance: 0.2, net_clearance: Default::default(), via: 0.8, drill: 0.4, via_small: 0.6, drill_small: 0.3, edge: 0.5, stub: 0.25, narrow: 0.5, escape: 0.45, corridor: 0.5, ic_zone: 2.0, channel: 2.5, planes: BTreeMap::new(), wide: BTreeMap::new(), mid: BTreeMap::new(), hole_to_hole: 0.25, via_search_mm: 6.0, kelvin: BTreeMap::new(), signal_priority: Vec::new(), plane_under: Vec::new(), decoupling: Vec::new(), impedance: BTreeMap::new(), clear_regions: Vec::new(),- route_layers: Vec::new(), vias: true, allow_via_in_pad: false, isolation: Vec::new(), isolation_exempt: Vec::new(),+ route_layers: Vec::new(), vias: true, allow_via_in_pad: false, hole_clearance: 0.0, isolation: Vec::new(), isolation_exempt: Vec::new(), } } }@@ -134,6 +138,7 @@ impl Rules { } if let Some(v) = num("edgeClearance") { r.edge = v; } if let Some(v) = num("holeToHoleClearance").or_else(||num("holeToHole")) { r.hole_to_hole = v; }+ if let Some(v) = num("holeClearance") { r.hole_clearance = v; } if spec.get("allowViaInPad").and_then(|v| v.as_bool()) == Some(true) || spec.get("fab").and_then(|f| f.get("viaInPad")).and_then(|v| v.as_str()).is_some_and(|s| s.eq_ignore_ascii_case("filled-capped")) {
crates/aiflow-router/tests/obstacles.rs+32@@ -113,3 +113,35 @@ fn plane_pad_on_a_part_off_the_board_does_not_panic() { } assert!(failed >= 2); }++/// Issue #255 (Deepak Madan): tracks keep the board's hole clearance (0.25 mm at the 3rd party fab, here 0.6 mm to+/// be plain) from a drilled hole's edge, not only the ordinary clearance: a mask-only NPTH (a Tag-Connect alignment+/// hole) and an NPTH pad that lists copper layers (a mounting hole).+#[test]+fn tracks_keep_the_hole_clearance_from_an_npth() {+ for (layers, d) in [("\"*.Mask\"", 1.0), ("\"*.Cu\" \"*.Mask\"", 1.0)] {+ let text = format!(r#"(kicad_pcb+ (layers (0 "F.Cu" signal) (31 "B.Cu" signal))+ (net 1 "SIG")+ (gr_rect (start 0 0) (end 20 12) (layer "Edge.Cuts"))+ (footprint "test" (layer "F.Cu") (at 3 6) (property "Reference" "J1")+ (pad "1" smd rect (at 0 0) (size 1 1) (layers "F.Cu") (net 1 "SIG")))+ (footprint "test" (layer "F.Cu") (at 17 6) (property "Reference" "J2")+ (pad "1" smd rect (at 0 0) (size 1 1) (layers "F.Cu") (net 1 "SIG")))+ (footprint "TC2030" (layer "F.Cu") (at 10 6) (property "Reference" "J3")+ (pad "" np_thru_hole circle (at 0 0) (size {d} {d}) (drill {d}) (layers {layers}))))"#);+ // a track 0.4 mm from the hole's edge: clear at the ordinary 0.2 mm clearance, too close at 0.6 mm+ let probe = 10.0 + d / 2.0 + 0.4;+ let blocked = |hc: f64| {+ let board = Board::from_text("npth.kicad_pcb", text.clone()).unwrap();+ let rules = Rules { clearance: 0.2, hole_clearance: hc, ..Rules::default() };+ let mut r = Router::new(board, rules, false);+ let win = (0, 0, r.grid.w as i64 - 1, r.grid.h as i64 - 1);+ let (orth, _, _, _) = r.obstacle_maps(0, 0.1, win, false);+ let (i, j) = r.grid.to_cell(probe, 6.0);+ orth[0].get(i as usize, j as usize)+ };+ assert!(!blocked(0.0), "{layers}: the ordinary clearance lets a track pass 0.4 mm from the hole");+ assert!(blocked(0.6), "{layers}: a 0.6 mm hole clearance keeps it out");+ }+}
docs/release-0.2.118.mdadded+17@@ -0,0 +1,17 @@+# adom-aiflow 0.2.118++## Router: isolation barriers, jumper pad groups, via-in-pad (PR #165, Kenneth Foli Jørgensen; issues #262, #264, #217)++Merged from Kenneth's PR, made for a 4-layer board with an isolated 802.3af PD and a mains section.++- **Isolation barriers (#262).** A project rule `A.NetClass == 'X' && B.NetClass != 'X'` (or `!B.hasNetclass('X')`) was read as a clearance from every net, the class's own nets included, so a dense isolated circuit could not route. Such a rule is now listed as not applied by the router (KiCad's DRC in the gate still judges it). The barrier itself is given to the router as spec `isolationDomains: [{"nets": [...], "clearance": mm}]`: a net in one domain keeps the domain's clearance from every net outside it, and only the ordinary clearance from its own domain's nets. `isolationExempt` names nets that bridge the barrier on purpose (the mid-node of two Y capacitors). The straightening pass keeps the barrier too.+- **Jumper pad groups (#264).** Pads joined inside a footprint (`(jumper_pad_groups ("13" "14"))`, a jack's shield tabs joined by its shell) are one terminal: the router no longer routes a track between them, and the board-copper connectivity counts them as joined.+- **Via-in-pad (#217).** The plane-stitch fallback no longer puts a via in an SMD pad unless spec `allowViaInPad` is set, as `connect` already did; the failure says so.++## Router: hole clearance from drilled holes (issue #255, Deepak Madan)++`route` kept tracks only the ordinary copper clearance from a drilled hole, while the gate checks the board's hole clearance, so a route passing a Tag-Connect alignment hole failed the gate with `hole_clearance`. Tracks and vias now keep the hole clearance from every NPTH: a mask-only one and one kept as a no-net pad (a mounting hole). It is read from a board-wide `hole_clearance` rule in the project's .kicad_dru, or spec `holeClearance`, whichever is larger; `route` says when it applies one.++## gate: a body drawn as separate shapes (issue #256, Ryan Bertsch)++The body overlap check took one hull around all of a footprint's F.Fab graphics. A module riding on four corner sockets, drawn as four rectangles, "overlapped" every low part placed between the sockets, though KiCad's DRC and the courtyard check passed. Bodies are now read per closed shape when the shapes stand apart, as the fitted-body reader already did (issue #236). A part on a socket still collides.
package.json+1−1@@ -1,7 +1,7 @@ { "slug": "adom-aiflow", "type": "app",- "version": "0.2.117",+ "version": "0.2.118", "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.117",+ "version": "0.2.118", "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.",