Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Construction: a plane on a sheet's flat face follows the face (#6217)

NOWN-DEVbe08517de2f6
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index d7a3b37010..783c22fa27 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -6883,6 +6883,11 @@ fn eval_feature(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st:
}
pl
}
+ // On a flat face of a sheet: that panel's plane as it is now, as a sketch on the
+ // face finds it (the stored plane is only where the face was picked).
+ None if crate::sheet::plane_sheet_face(plane).is_some() => {
+ doc.resolve_plane_in(vals, &sheet_face_plane_in_frame(doc, st, f.component, plane)?, 0, Some(st))?
+ }
// A plane of numbers alone reads no body: placing them all is the design's size.
None if plane_is_fixed(plane) => doc.resolve_plane_in(vals, plane, 0, Some(st))?,
// Picks on bodies of other (moved) components are where those bodies are shown.
diff --git a/crates/engine/src/cmd/offset_plane_face_tests.rs b/crates/engine/src/cmd/offset_plane_face_tests.rs
index c0e52fc46f..2047ba1c46 100644
--- a/crates/engine/src/cmd/offset_plane_face_tests.rs
+++ b/crates/engine/src/cmd/offset_plane_face_tests.rs
@@ -100,6 +100,42 @@ fn offset_plane_redefined_on_itself_is_refused() {
assert!((plane(&s, "Side").origin.y + 7.0).abs() < 1e-9, "{:?}", plane(&s, "Side"));
}
+/// A flat face of a sheet is kept by its sheet face name, as a sketch on it is: the plane follows
+/// the flange when the sheet changes (it stayed where the face was picked).
+#[test]
+fn offset_plane_from_a_sheet_flange_face_follows_the_flange() {
+ let mut s = Session::default();
+ run(&mut s, "sheet.manage_rules", json!({"name": "R1", "thickness": "1 mm", "bend_radius": "1 mm", "active": true}));
+ run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Base"}));
+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [320, 200]}));
+ let d = run(&mut s, "sketch.dimension", json!({"entities": ["l1"], "value": 320}));
+ let width = d["param"].as_str().or_else(|| d["name"].as_str()).unwrap_or("d1").to_string();
+ run(&mut s, "sketch.finish", json!({}));
+ run(&mut s, "sheet.flange", json!({"sketch": "Base"}));
+ run(&mut s, "sheet.flange", json!({"edges": [[320, 100, 1]], "height": 30}));
+ let flange = s.doc.features.last().map_or(0, |f| f.id);
+ // The flange's inner face, picked as model.faces lists it (body and index), 5 mm out along its normal.
+ let name = format!("sheet:Body1:F{flange}.0:top");
+ let faces = run(&mut s, "model.faces", json!({"body": "Body1"}));
+ let face = faces["faces"].as_array().unwrap().iter().find(|f| f["sheet_face"].as_str() == Some(name.as_str())).unwrap().clone();
+ run(
+ &mut s,
+ "construct.plane.offset",
+ json!({"base": {"face": face["point"], "body": "Body1", "index": face["index"]}, "offset": 5, "name": "Out"}),
+ );
+ let out = plane(&s, "Out");
+ assert!((out.normal().x.abs() - 1.0).abs() < 1e-9, "{out:?}");
+ let x0 = out.origin.x;
+ // 80 mm wider: the flange moves 80 mm along x, and the plane with it.
+ run(&mut s, "parameters.change", json!({"name": width, "expression": "400"}));
+ let moved = plane(&s, "Out");
+ assert!((moved.origin.x - x0 - 80.0).abs() < 1e-9, "{x0} -> {moved:?}");
+ assert!(s.model.results.iter().all(|r| r.error.is_none()), "{:?}", s.model.results);
+ // Reopened, the attachment still resolves where the face is.
+ let reopened = Session::new(Document::from_json(&s.doc.to_json()).unwrap());
+ assert!((plane(&reopened, "Out").origin.x - x0 - 80.0).abs() < 1e-9);
+}
+
#[test]
fn plane_at_angle_from_a_planar_face_follows_the_face() {
let mut s = Session::default();