SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Emboss: an emboss or deboss that changes nothing says so (#10940) (#10944)
thocsmith70603de6540f
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex 2403b45830..aa14a5c549 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -7266,7 +7266,7 @@ fn eval_feature(| FeatureKind::Rib { .. }| FeatureKind::ReplaceFace { .. }| FeatureKind::Align { .. }- | FeatureKind::Remove { .. } => more::eval(doc, vals, f, st),+ | FeatureKind::Remove { .. } => more::eval(doc, vals, f, st, warning),FeatureKind::Sketch { plane, sketch } => {let anchor = crate::face_anchor::plane_face_anchor(plane);let fst = match anchor {diff --git a/crates/doc/src/eval_more.rs b/crates/doc/src/eval_more.rsindex 9e47d518ae..06593f6ba1 100644--- a/crates/doc/src/eval_more.rs+++ b/crates/doc/src/eval_more.rs@@ -8,7 +8,7 @@ use crate::sheet;use solidcore_record::{Loop2, Seg2};use solidcraft_geom::{Aabb3, Ring};-pub(super) fn eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &mut ModelState) -> Result<()> {+pub(super) fn eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature, st: &mut ModelState, warning: &mut Option<String>) -> Result<()> {match &f.kind {FeatureKind::Emboss { sketch, profiles, depth, deboss, targets, face } => {let ss = st.sketch(sketch.0).ok_or_else(|| DocError::Unknown(format!("sketch {sketch}")))?;@@ -59,7 +59,20 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Feature,if st.bodies.is_empty() {return Err(DocError::Invalid("there is no body to emboss".into()));}- apply_op(doc, st, f, tools, if *deboss { Operation::Cut } else { Operation::Join }, &crate::plain(targets))+ // #10940: an emboss or deboss whose tool lies clear of the body (a sketch on the far+ // side of the material, a depth that stops short) used to report success and change+ // nothing. Say so: the body is compared before and after, as the command's reply does.+ let before: Vec<Body> = st.bodies.iter().map(|b| b.body.clone()).collect();+ apply_op(doc, st, f, tools, if *deboss { Operation::Cut } else { Operation::Join }, &crate::plain(targets))?;+ let unchanged = st.bodies.len() == before.len() && st.bodies.iter().zip(&before).all(|(b, old)| old.same(&b.body));+ if unchanged {+ let what = if *deboss { "deboss" } else { "emboss" };+ append_warning(+ warning,+ format!("the {what} changed nothing; check where its profile lies, which side of the face the sketch is on, and the depth"),+ );+ }+ Ok(())}FeatureKind::Rib { .. } => {let tools = rib_tools(vals, st, f, None)?;diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rsindex 83ea9ad977..5272c15c8e 100644--- a/crates/engine/src/cmd/features_more_tests.rs+++ b/crates/engine/src/cmd/features_more_tests.rs@@ -2668,3 +2668,39 @@ fn align_axes_are_world_axes_on_a_placed_component() {assert!(near(after.min.y, before.min.y + 20.0) && near(after.max.y, before.max.y + 20.0), "y: {after:?}");assert!(near(after.min.z, before.min.z) && near(after.max.z, before.max.z), "z: {after:?}");}++/// #10940: an Emboss or Deboss whose tool misses the body was recorded as a success that changed+/// nothing, with no warning. It now says that it changed nothing; one that works says nothing.+#[test]+fn an_emboss_that_changes_nothing_says_so() {+ let mut s = Session::default();+ run(&mut s, "sheet.manage_rules", json!({"name": "T1", "thickness": "0.8 mm", "k_factor": "0.5", "bend_radius": "0.8 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": [60, 40]}));+ run(&mut s, "sketch.finish", json!({}));+ run(&mut s, "sheet.flange", json!({"sketch": "Base"}));+ let before = volume(&mut s);+ // A sketch 5 mm below the sheet: a deboss goes down, away from the sheet, and misses it.+ run(&mut s, "sketch.create", json!({"plane": {"origin": [0, 0, -5], "x_dir": [1, 0, 0], "y_dir": [0, 1, 0]}, "name": "Logo"}));+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [10, 10], "p1": [20, 20]}));+ run(&mut s, "sketch.finish", json!({}));+ let reply = run(&mut s, "solid.emboss", json!({"sketch": "Logo", "depth": 0.6, "mode": "deboss"}));+ let warning = reply["warning"].as_str().unwrap_or_default();+ assert!(warning.contains("deboss changed nothing"), "{reply}");+ assert!(reply["changed_bodies"].as_array().is_some_and(Vec::is_empty), "{reply}");+ assert!(rel(volume(&mut s), before) < 1e-9);+}++#[test]+fn an_emboss_that_works_has_no_warning() {+ let mut s = Session::default();+ run(&mut s, "solid.box", json!({"length": 40, "width": 30, "height": 10}));+ run(&mut s, "sketch.create", json!({"plane": {"face": [20, 15, 10]}, "name": "Logo"}));+ run(&mut s, "sketch.rectangle.two_point", json!({"p0": [5, 5], "p1": [15, 15]}));+ run(&mut s, "sketch.finish", json!({}));+ for mode in ["emboss", "deboss"] {+ let reply = run(&mut s, "solid.emboss", json!({"sketch": "Logo", "depth": 2, "mode": mode}));+ assert!(reply["warning"].is_null(), "{mode}: {reply}");+ run(&mut s, "edit.undo", json!({}));+ }+}