kicad_monkey_fab/view/
zones.rs1use crate::geom::{AreaKind, AreaShape, FabArea, FabLayerItems, Placement2D, Ring2D, pt_up};
4use crate::layer_map::LayerMap;
5use kicad_monkey_core::pcb::PcbZone;
6use std::collections::HashMap;
7
8pub fn emit_zone(
10 zone: &PcbZone,
11 net: Option<&str>,
12 layer_map: &LayerMap,
13 buckets: &mut HashMap<String, FabLayerItems>,
14) {
15 if zone.keepout.is_some() {
16 return;
17 }
18 let fallback_layer = zone.layers.first().map(String::as_str).unwrap_or("");
19 for fp_poly in &zone.filled_polygons {
20 let klayer = if fp_poly.layer.is_empty() {
21 fallback_layer
22 } else {
23 fp_poly.layer.as_str()
24 };
25 if klayer == "Edge.Cuts" {
26 continue;
27 }
28 let Some(fab_key) = layer_map.fab_key(klayer) else {
29 continue;
30 };
31 let pts: Vec<_> = fp_poly.points.iter().map(|p| pt_up(p.x, p.y)).collect();
32 let Some(ring) = Ring2D::from_points_oriented(&pts, true) else {
33 continue;
34 };
35 let is_cu = klayer.ends_with(".Cu");
36 buckets
37 .entry(fab_key.to_owned())
38 .or_default()
39 .areas
40 .push(FabArea {
41 kind: if is_cu {
42 AreaKind::PolygonCopper
43 } else {
44 AreaKind::Region
45 },
46 shape: AreaShape::Region {
47 outer: ring,
48 holes: Vec::new(),
49 },
50 placement: Placement2D::identity(),
51 net: if is_cu { net.map(str::to_owned) } else { None },
52 component: None,
53 source: zone.uuid.clone(),
54 });
55 }
56}