main
Colby Knox 0.2.80 (unreleased): place_decoupling, plan_fanout, estimate_cost and check_clearance from engine 0.10.3 (236/236 stand… 8144f67
//! A placement review before routing: courtyard overlaps, parts off or over the board edge, pads near the edge, parts
//! on a mounting hole. The standard's shared engine answers it (vendor/adom-eda-checks `placement`, standard 0.7.0)
//! from the board model and the bodies companion.
use serde_json::{json, Value};

/// altium_placement_check {filePath?, marginMm?, edgeMm?}
pub fn placement_check(args: &Value) -> Value {
    if let Some(g) = crate::support::need_licensed() { return g; }
    if let Some(p) = crate::support::s(args, "filePath") { if let Some(e) = crate::support::must_open(&p, 60) { return e; } }
    let st = crate::routing::routing_state(&json!({}));
    if st.get("success").and_then(|v| v.as_bool()) != Some(true) { return st; }
    // the parts' 3D bodies (silk_state's 'body' box takes in the designator text and made every neighbour overlap);
    // without them the engine reviews the pads alone and says so (bodiesUsed: false)
    let b = crate::bodies::bodies_on(&json!({}), Some(&st));
    let b = if b.get("success").and_then(|v| v.as_bool()) == Some(true) { b } else { Value::Null };
    crate::checks::engine("placement_check", &json!({"board": st, "bodies": b, "args": args}))
}