← Commit history
Merge PR #537: verify-pours: KiCad's teardrop zones are not unplanned pours (fix/verify-pours-teardrops -> main) merge
Showing changes introduced by the merge (against its first parent).
1 file changed
+45−4
crates/adom-aiflow/src/pourverify.rs+45−4@@ -157,6 +157,13 @@ fn diff_line(d: &[Value]) -> String { .join("; ") } +/// A teardrop zone (`(attr (teardrop (type padvia)))`, priority 30000): KiCad makes these itself on a+/// refill, for every pad and via whose teardrops are enabled. They are not pours, the plan never names+/// them and no flow owns them (`land pours` skips the live ones by their row type for the same reason).+pub fn is_teardrop(n: &Node) -> bool {+ n.find("attr").is_some_and(|a| a.find("teardrop").is_some())+}+ fn zone_name(n: &Node) -> &str { n.find("name").and_then(Node::value).unwrap_or("unnamed") }@@ -344,13 +351,13 @@ pub fn check_with(board: &Board, plan: &Value, keepouts_landed: bool) -> Result< let expected = expected_zone(board, z, &loops)?; let wanted = signature(board, &expected); let matches: Vec<usize> = (0..actual.len())- .filter(|i| !used.contains(i) && signatures[*i] == wanted+ .filter(|i| !used.contains(i) && !is_teardrop(actual[*i]) && signatures[*i] == wanted && z.get("boardZoneUuid").is_none_or(|id| zone_id(actual[*i]).as_deref() == id.as_str())) .collect(); if matches.len() != 1 { // name the closest unused board zone and every field where it differs let closest = (0..actual.len())- .filter(|i| !used.contains(i))+ .filter(|i| !used.contains(i) && !is_teardrop(actual[*i])) .map(|i| (i, differences(&wanted, &signatures[i], &expected, actual[i]))) .min_by_key(|(i, d)| (d.len(), *i)); let mut line = format!(@@ -439,14 +446,18 @@ pub fn check_with(board: &Board, plan: &Value, keepouts_landed: bool) -> Result< // No hidden extra copper: every saved copper zone needs an explicit plan entry. A keepout rule area the // plan does not own (issue #189: drawn by the human to keep copper off a spot) is theirs: it adds no copper, // so it is recorded, not failed.+ // KiCad's own teardrop zones (made by a refill from the pads' teardrop settings) are listed apart:+ // they are not pours and no plan describes them. let mut board_keepouts = Vec::new();+ let mut teardrops = Vec::new(); for (i, n) in actual.iter().enumerate().filter(|(i, _)| !used.contains(i)) {- if n.find("keepout").is_some() { board_keepouts.push(json!({"boardZoneIndex": i, "name": zone_name(n)})); }+ if is_teardrop(n) { teardrops.push(json!({"boardZoneIndex": i, "net": signatures[i]["net"], "layer": n.find("layer").and_then(Node::value)})); }+ else if n.find("keepout").is_some() { board_keepouts.push(json!({"boardZoneIndex": i, "name": zone_name(n)})); } else { failed.push(format!("unplanned board zone {i}: {}", zone_name(n))); } } Ok( json!({"mode":"verified-existing","pass":failed.is_empty(),"failed":failed,"groups":groups,"differences":report,- "keepoutsCheckedClear":cleared, "boardKeepoutsNotInPlan":board_keepouts,+ "keepoutsCheckedClear":cleared, "boardKeepoutsNotInPlan":board_keepouts, "boardTeardrops":teardrops, "ownershipGranted":false,"scope":if keepouts_landed { "saved filled polygons and planned zone geometry/settings; native DRC, measured copper and electrical/thermal checks remain separate" } else { "saved filled polygons and planned zone geometry/settings; keepouts (not landed by this tool) checked clear of saved pour fill; native DRC, measured copper and electrical/thermal checks remain separate" }}), ) }@@ -832,6 +843,8 @@ type Reply = Result<(String, Vec<String>), (String, Vec<String>)>; pub fn plan_from_board(board: &Board) -> Value { let mut zones = Vec::new(); for (i, n) in board.root.find_all("zone").enumerate() {+ // a teardrop is KiCad's, remade on every refill: never a pour to adopt+ if is_teardrop(n) { continue; } let sig = signature(board, n); let mut layers: Vec<String> = n.find("layer").or_else(|| n.find("layers")) .map(|x| (1..).map_while(|j| x.atom(j)).map(str::to_string).collect()).unwrap_or_default();@@ -1033,6 +1046,34 @@ mod tests { assert_eq!(r["pass"], false); assert!(r["failed"].to_string().contains("unplanned board zone"), "{r}"); }+ /// KiCad's own teardrop zone, as a refill writes it for a pad whose teardrops are enabled.+ const TEARDROP: &str = r#"(zone (net "GND") (layer "F.Cu") (uuid "teardrop-1") (name "$teardrop_padvia$") (hatch full 0.1) (priority 30000) (attr (teardrop (type padvia))) (connect_pads yes (clearance 0)) (min_thickness 0.0254) (filled_areas_thickness no) (fill yes (thermal_gap 0.5) (thermal_bridge_width 0.5) (island_removal_mode 1)) (polygon (pts (xy 6 6) (xy 6.5 6) (xy 6.5 6.2))) (filled_polygon (layer "F.Cu") (pts (xy 6 6) (xy 6.5 6) (xy 6.5 6.2))))"#;++ #[test]+ fn kicad_teardrops_are_listed_apart_not_failed_as_unplanned_pours() {+ // a KiCad refill adds a teardrop zone on each pad whose footprint enables teardrops+ let (b, p) = fixture();+ let mut t = b.text[..b.text.len() - 1].to_string(); t.push_str(TEARDROP); t.push(')');+ let board = Board::from_text("test", t).unwrap();+ assert!(is_teardrop(board.root.find_all("zone").nth(1).unwrap()));+ assert!(!is_teardrop(board.root.find("zone").unwrap()));+ let r = check(&board, &p).unwrap();+ assert_eq!(r["pass"], true, "{r}");+ assert_eq!(r["boardTeardrops"].as_array().map(Vec::len), Some(1), "{r}");+ assert_eq!(r["boardTeardrops"][0]["boardZoneIndex"], 1, "{r}");+ assert_eq!(r["boardTeardrops"][0]["layer"], "F.Cu", "{r}");+ assert!(!r["failed"].to_string().contains("unplanned"), "{r}");+ // a teardrop never stands in for a planned pour that is missing+ let only = Board::from_text("test", format!("{} {TEARDROP})", r#"(kicad_pcb (version 20260101) (layers (0 "F.Cu" signal) (31 "B.Cu" signal)) (gr_rect (start 0 0) (end 10 10) (layer "Edge.Cuts"))"#)).unwrap();+ let r = check(&only, &p).unwrap();+ assert_eq!(r["pass"], false, "{r}");+ assert!(r["failed"].to_string().contains("found 0") && r["failed"].to_string().contains("no unmatched board zone is left"), "{r}");+ // --from-board records the pours, never KiCad's teardrops+ let plan = plan_from_board(&board);+ assert_eq!(plan["zones"].as_array().map(Vec::len), Some(1), "{plan}");+ assert!(!plan.to_string().contains("teardrop"), "{plan}");+ assert_eq!(check(&board, &plan).unwrap()["pass"], true);+ } #[test] fn native_hole_loops_are_verified_without_flattening() { let (b, mut p) = fixture();