SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Sketch on a thickened surface's face (#7641) (#7703)
Raymond Thurman6b5c5dc6e870
diff --git a/crates/doc/src/eval_surface.rs b/crates/doc/src/eval_surface.rsindex b6ff6d3fb1..4a14057671 100644--- a/crates/doc/src/eval_surface.rs+++ b/crates/doc/src/eval_surface.rs@@ -63,13 +63,16 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature,let t = val(vals, thickness, Kind::Length)?;let mut tools = Vec::new();for n in bodies {- let b = st.body(n).ok_or_else(|| DocError::Unknown(format!("body `{n}`")))?;- tools.push(kernel::thicken(&b.body, t, *symmetric)?);+ let b = st.body(n).cloned().ok_or_else(|| DocError::Unknown(format!("body `{n}`")))?;+ // Kept face, offset and edge walls. Carry that history so a sketch can attach+ // to the solid's faces and follow the thickness (#7641).+ let thickened = kernel::thicken(&b.body, t, *symmetric)?;+ tools.push(Traced::step(thickened, &[&b.traced()]));}if tools.is_empty() {return Err(DocError::Invalid("pick the surfaces to thicken".into()));}- apply_op(doc, st, f, tools, *operation, &crate::plain(targets))+ apply_traced(doc, st, f, tools, *operation, &crate::plain(targets))}FeatureKind::SurfaceTrim { body, plane, tool, keep, keep_more, curves, with, keep_with, stitch, extend } => {let i = st.bodies.iter().position(|b| &b.name == body).ok_or_else(|| DocError::Unknown(format!("body `{body}`")))?;diff --git a/crates/engine/src/naming_history_tests.rs b/crates/engine/src/naming_history_tests.rsindex bd7ea0f7b6..fd4bc9f61e 100644--- a/crates/engine/src/naming_history_tests.rs+++ b/crates/engine/src/naming_history_tests.rs@@ -787,3 +787,61 @@ fn a_chamfer_running_past_the_side_edges_it_takes_up_is_named_by_its_edge() {let at = solidcraft_doc::naming::face_names_at(&s.model.state(), &[on(40.0), on(150.0)]);assert_eq!(at, vec![blends[0].clone(), blends[0].clone()]);}++/// A line extruded into a surface and thickened into a slab. Every face of the slab is named+/// from that history, and a sketch on the offset face attaches and follows the thickness (#7641).+#[test]+fn a_sketch_on_a_thickened_surface_follows_the_face() {+ let mut s = Session::default();+ run(&mut s, "parameters.add", json!({"name": "thick", "expression": "2 mm"}));+ run(&mut s, "sketch.create", json!({"plane": "XY", "name": "Line"}));+ run(&mut s, "sketch.line", json!({"points": [[0, 0], [40, 0]], "ids": ["l1"]}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "surface.extrude", json!({"sketch": "Line", "curves": ["l1"], "distance": 30, "body_name": "Sheet"}));+ run(&mut s, "surface.thicken", json!({"bodies": ["Sheet"], "thickness": "thick", "body_name": "Slab"}));+ // The offset face is the copy at y = -2. Its frame is X and Z, origin on that plane.+ let made = run(&mut s, "sketch.create", json!({"plane": {"face": [30.0, -2.0, 10.0]}, "name": "OnFace"}));+ assert_eq!(made["attachment"], "exact_face", "{made}");+ let named = names(&s, "Slab");+ assert!(named.iter().all(|(_, exact)| *exact), "a thickened face must keep exact history: {named:?}");+ // Kept face keeps the sheet's name; the offset and the edge walls are the thicken feature's.+ assert!(named.iter().any(|(n, _)| n == "F2:side:l1"), "{named:?}");+ assert!(named.iter().any(|(n, _)| n == "F3:inner:F2:side:l1"), "{named:?}");+ assert_eq!(named.iter().filter(|(n, _)| n.starts_with("F3:blend:")).count(), 4, "{named:?}");+ run(&mut s, "sketch.circle.center", json!({"center": [20, 15], "radius": 3}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "solid.extrude", json!({"sketch": "OnFace", "distance": 4, "operation": "join", "name": "Boss"}));+ // An end wall (the face at x = 0) takes a sketch too.+ let wall = run(&mut s, "sketch.create", json!({"plane": {"face": [0.0, -1.0, 15.0]}, "name": "OnWall"}));+ assert_eq!(wall["attachment"], "exact_face", "{wall}");+ run(&mut s, "sketch.finish", json!({}));++ let slab = |s: &Session| {+ let body = s.model.state().body("Slab").unwrap().body.clone();+ let measured = solidcraft_kernel::measure(&body).unwrap();+ (measured.volume, measured.bbox.min.y)+ };+ let (volume, min_y) = slab(&s);+ let boss = std::f64::consts::PI * 9.0 * 4.0;+ // The join of the cylinder is a hair under the analytic sum (about 0.02 mm³ here).+ assert!((volume - (2400.0 + boss)).abs() < 0.05, "slab 40×30×2 plus the boss {}: got {volume}", 2400.0 + boss);+ assert!((min_y - (-6.0)).abs() < 1e-6, "the boss stands 4 mm off y = -2: {min_y}");+ assert_eq!(error(&s, "OnFace"), None);+ assert_eq!(error(&s, "Boss"), None);+ assert_eq!(warning(&s, "Boss"), None);++ change(&mut s, "thick", "4 mm");+ assert_eq!(error(&s, "OnFace"), None);+ assert_eq!(error(&s, "Boss"), None);+ assert_eq!(warning(&s, "OnFace"), None);+ assert_eq!(warning(&s, "Boss"), None);+ let (volume, min_y) = slab(&s);+ assert!((volume - (4800.0 + boss)).abs() < 0.05, "the slab grew with the thickness and the boss stayed whole {}: got {volume}", 4800.0 + boss);+ assert!((min_y - (-8.0)).abs() < 1e-6, "the boss followed the face to y = -4: {min_y}");++ let mut cold = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());+ cold.refresh();+ let (volume, min_y) = slab(&cold);+ assert!((volume - (4800.0 + boss)).abs() < 0.05 && (min_y - (-8.0)).abs() < 1e-6, "reopened: {volume} {min_y}");+ assert_eq!(error(&cold, "Boss"), None);+}diff --git a/docs/face-attachments.md b/docs/face-attachments.mdindex 7c2c2dcd0a..c76e1fe118 100644--- a/docs/face-attachments.md+++ b/docs/face-attachments.md@@ -25,9 +25,11 @@ and follows it through every later feature. That covers a Cut's walls and floor(`F5:side:l1`, `F5:top`), a chamfer face (`F7:blend:…`), each copy a pattern or mirror makes(`F4:[email protected]`: the seed's face and the copy's instance), a side wall a Join merged from twofeatures (named after the first, answering to the other), the pieces a later feature split-a face into (all pieces of one name on one oriented plane are that face), and the face Split Body+a face into (all pieces of one name on one oriented plane are that face), the face Split Bodycuts with a plane (`F4:section` on each part: a construction plane, a sketch line or a plane given-outright, so a sketch on it follows the plane when a parameter moves it). A lineage face's+outright, so a sketch on it follows the plane when a parameter moves it), and the faces of a+thickened surface: the face that was kept, the offset (`F3:inner:F2:side:l1`) and the walls on+the surface's edges (`F3:blend:…`). A sketch on any of those follows the thickness. A lineage face'splane is its current exact plane, measured in a frame that depends on the plane alone: itsorigin where the definition origin projects onto it, its x axis the first of the definition'sX, Y and Z axes not steep to it (`|cos| < 0.6`), projected. The construction certificates