← Commit history
pour: a spec pour must name its copper layers
spec.pours copper entries are refused with `layer` (singular), without `layers`, with a malformed list
or with a layer the board does not have.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 file changed
+38
crates/aiflow-pours/src/lib.rs+38@@ -238,6 +238,27 @@ pub fn check_settings(z: &Value) -> Result<(), String> { Ok(()) } +/// A copper pour in spec.pours names its copper layers as `layers`, each a copper layer of this board.+/// Nothing else gives it a layer: a pour without them became a zone on no layer (written with+/// `layer`, the singular, it was accepted silently and found only when `land pours` compared it).+fn pour_layers(board: &Board, net: &str, e: &Value) -> Result<(), String> {+ let have = if board.copper_layers.is_empty() { String::new() } else { format!(" (this board has {})", board.copper_layers.join(", ")) };+ if let Some(l) = e.get("layer") {+ return Err(format!("pour {net}: `layer` is not a pour key; name its copper layers as a list: \"layers\": [{}]{have}", match l { Value::String(s) => format!("\"{s}\""), other => other.to_string() }));+ }+ let Some(list) = e.get("layers") else { return Err(format!("pour {net} needs `layers`, its copper layers as a list (for example [\"F.Cu\", \"B.Cu\"]){have}")) };+ let names: Vec<&str> = list.as_array().map(|a| a.iter().filter_map(Value::as_str).collect()).unwrap_or_default();+ if names.is_empty() || list.as_array().is_some_and(|a| a.len() != names.len()) {+ return Err(format!("pour {net}: `layers` is a list of copper layer names (for example [\"F.Cu\", \"B.Cu\"]), not {list}{have}"));+ }+ if !board.copper_layers.is_empty() {+ if let Some(bad) = names.iter().find(|l| !board.copper_layers.iter().any(|c| c == *l)) {+ return Err(format!("pour {net}: {bad} is not a copper layer of this board{have}"));+ }+ }+ Ok(())+}+ /// (zones in the kicad_add_zone shape, via plan entries, keepout count) from the spec and the routing plan. pub fn build(board: &Board, spec: &Value, plan: Option<&Value>) -> Result<(Vec<Value>, Vec<Value>, usize), String> { build_with(board, spec, plan, &[]) } @@ -270,6 +291,7 @@ pub fn build_with(board: &Board, spec: &Value, plan: Option<&Value>, planned: &[ let near = aiflow_board::netname::close(&named, board.nets.keys()); return Err(if near.is_empty() { format!("pour {named}: the board has no pads on that net") } else { format!("pour {named}: the board has no pads on that net; the board has {} (name that in the spec)", near.join(", ")) }); };+ pour_layers(board, &net, &e)?; let mut z = serde_json::Map::new(); for (k, v) in e.as_object().unwrap() { if !matches!(k.as_str(), "around" | "margin" | "exclude" | "polygon" | "outline" | "inset") {@@ -794,6 +816,22 @@ mod net_name_tests { let e = build(&board(), &json!({"pours": [{"net": "VOUT", "outline": true}]}), None).unwrap_err(); assert_eq!(e, "pour VOUT: the board has no pads on that net"); }+ #[test]+ fn a_pour_names_its_copper_layers() {+ // `layer` (singular) used to pass silently and plan a zone on no layer, with default thermals+ let e = build(&board(), &json!({"pours": [{"net": "GND", "outline": true, "layer": "F.Cu"}]}), None).unwrap_err();+ assert!(e.contains("`layer` is not a pour key") && e.contains("\"layers\": [\"F.Cu\"]") && e.contains("this board has F.Cu, B.Cu"), "{e}");+ let e = build(&board(), &json!({"pours": [{"net": "GND", "outline": true}]}), None).unwrap_err();+ assert!(e.starts_with("pour /GND needs `layers`"), "{e}");+ for bad in [json!([]), json!("F.Cu"), json!(["F.Cu", 1])] {+ let e = build(&board(), &json!({"pours": [{"net": "GND", "outline": true, "layers": bad}]}), None).unwrap_err();+ assert!(e.contains("`layers` is a list of copper layer names"), "{e}");+ }+ let e = build(&board(), &json!({"pours": [{"net": "GND", "outline": true, "layers": ["F.Cu", "In1.Cu"]}]}), None).unwrap_err();+ assert!(e.contains("In1.Cu is not a copper layer of this board"), "{e}");+ let (zones, _, _) = build(&board(), &json!({"pours": [{"net": "GND", "outline": true, "layers": ["F.Cu", "B.Cu"]}]}), None).unwrap();+ assert_eq!(zones[0]["layers"], json!(["F.Cu", "B.Cu"]));+ } } #[cfg(test)] mod issue90_tests {