SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Press Pull: route curved faces to Offset Face (#2873) (#3463)
jason3w8c853fff3eb6
diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rsindex c2c2702eae..2755e2419c 100644--- a/crates/engine/src/cmd/features.rs+++ b/crates/engine/src/cmd/features.rs@@ -88,7 +88,7 @@ pub static COMMANDS: &[CommandSpec] = &[CommandSpec::new("solid.offset_face", "Offset Face", offset_face).at("SOLID", "MODIFY").icon("offset_face")- .params("faces: [[x,y,z] points on planar faces, or face names from model.faces]; distance: expr (positive: outward); body?"),+ .params("faces: [[x,y,z] points on faces (planar or curved), or face names from model.faces]; distance: expr (positive: outward); body?"),CommandSpec::new("solid.thread", "Thread", thread).at("SOLID", "CREATE").icon("thread")diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 8bb0481d66..8372ea1907 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -116,7 +116,9 @@ pub fn anchor(app: &SolveApp, d: &Dialog) -> Option<(Vec3, Option<Vec3>)> {let dir = by_sketch.first().and_then(|(sk, ids)| solidcraft_engine::doc::sketch_hole_direction(&st, *sk, ids, flip));(at, normal.or(dir.map(|d| -d)))}- Kind::Section { .. } | Kind::OffsetPlane { .. } | Kind::OffsetFaces { .. } => (at, normal),+ // A curved face offsets along its outward normal where it was picked.+ Kind::OffsetFaces { .. } => (at, normal.or_else(|| solidcraft_engine::doc::hole_direction_at(&st, at).map(|d| -d))),+ Kind::Section { .. } | Kind::OffsetPlane { .. } => (at, normal),// Fillet radii and chamfer distances grow the way `blend_grow_dir` gives (into the body// on an outside edge, into the open corner on an inside one); shell thickness grows into// the body.diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex c8768b7818..347005c5d4 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -117,7 +117,7 @@ crate::dialog_descriptor::dialog_descriptors! {FeatureKind::Scale { factor, .. }) {factor: String = "2".into() => factor.to_string(),} => json!({"factor": factor});- OffsetFaces("solid.offset_face", "OFFSET FACE", [("Faces", PLANAR_FACES, true)],+ OffsetFaces("solid.offset_face", "OFFSET FACE", [("Faces", FACES, true)],FeatureKind::OffsetFace { distance, .. }) {distance: String = "2 mm".into() => distance.to_string(),} => json!({"distance": distance});@@ -454,6 +454,9 @@ pub struct Dialog {pub(crate) chain_applied: bool,/// Shell feedback is derived from the picks, never saved as additional face references.shell_chain: std::cell::RefCell<Option<ShellChain>>,+ /// An extrude Press Pull opened with nothing selected: its first pick may be a curved face or+ /// an edge, which reopens Press Pull on it (an offset or a fillet).+ pub press_pull: bool,}#[derive(Clone, Debug)]@@ -632,6 +635,7 @@ impl Dialog {picked_edges: Vec::new(),chain_applied,shell_chain: Default::default(),+ press_pull: false,}}@@ -3764,7 +3768,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S("solid.scale", json!({"bodies": sels(d, 0).body_names()}))}Kind::OffsetFaces { .. } => {- need(0, "planar faces")?;+ need(0, "faces")?;("solid.offset_face", json!({"faces": face_points(0)}))}Kind::Thread { designation, length, suggested, .. } => {diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 4c14fafdbf..1fb2775ee3 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1054,10 +1054,29 @@ impl SolveApp {self.cancel_sketch();return;}- // Press Pull: edges get a fillet, faces and profiles an extrude.+ // Press Pull: edges get a fillet, curved faces an offset, planar faces and profiles an extrude.if id == "solid.press_pull" {- let edges = self.session.selection.iter().any(|s| matches!(s, solidcraft_engine::Sel::Edge { .. }));- return self.start(if edges { "solid.fillet" } else { "solid.extrude" });+ let sel = &self.session.selection;+ let edges = sel.iter().any(|s| matches!(s, solidcraft_engine::Sel::Edge { .. }));+ let curved = sel.iter().any(+ |s| matches!(s, solidcraft_engine::Sel::Face { body, index, .. } if dialogs::planar_face(&self.session, body, *index).is_none()),+ );+ if edges {+ return self.start("solid.fillet");+ }+ if curved {+ return self.start("solid.offset_face");+ }+ let empty = sel.is_empty();+ self.start("solid.extrude");+ if empty+ && let Some(d) = &mut self.dialog+ && let Some(input) = d.inputs.first_mut()+ {+ input.accept |= selection::FACES | selection::EDGES;+ d.press_pull = true;+ }+ return;}if let Some(spec) = solidcraft_engine::find_command(id)&& (tools::Tool::for_command(id).is_some() || dialogs::Dialog::for_command(self, id).is_some())diff --git a/crates/ui-egui/src/preselect_tests.rs b/crates/ui-egui/src/preselect_tests.rsindex 7153f72a10..fdc5f90914 100644--- a/crates/ui-egui/src/preselect_tests.rs+++ b/crates/ui-egui/src/preselect_tests.rs@@ -739,6 +739,56 @@ fn face_then_extrude_press_pulls_it() {assert!(cmds[0].1.get("face").is_some());}+/// Press Pull on a hole's wall offsets it, rather than refusing it as Extrude does (#2873).+#[test]+fn curved_face_then_press_pull_offsets_it() {+ let mut app = app_with(json!([+ {"command": "solid.box", "params": {"length": 40, "width": 30, "height": 20}},+ {"command": "solid.cylinder", "params": {"radius": 5, "height": 20, "base": [20, 15, 0], "operation": "cut"}}+ ]));+ let st = app.session.model.state();+ let wall = st.body("Body1").unwrap().body.faces(0.01).unwrap().into_iter().find(|f| f.plane_normal.is_none()).unwrap().index;+ drop(st);+ let d = start(&mut app, vec![Sel::Face { body: "Body1".into(), index: wall, point: Vec3::new(25.0, 15.0, 10.0) }], "solid.press_pull");+ assert!(matches!(d.kind, Kind::OffsetFaces { .. }));+ let cmds = apply_commands(&app, &d).unwrap();+ assert_eq!(cmds[0].0, "solid.offset_face");+}++/// Press Pull with nothing selected: a click on a hole's wall reopens it as Offset Face, a click+/// on the top keeps the extrude (#2873).+#[test]+fn press_pull_then_curved_face_offsets_it() {+ let script = json!([+ {"command": "solid.box", "params": {"length": 40, "width": 30, "height": 20}},+ {"command": "solid.cylinder", "params": {"radius": 5, "height": 20, "base": [20, 15, 0], "operation": "cut"}}+ ]);+ let mut app = app_with(script.clone());+ let st = app.session.model.state();+ let wall = st.body("Body1").unwrap().body.faces(0.01).unwrap().into_iter().find(|f| f.plane_normal.is_none()).unwrap().index;+ drop(st);+ app.start("solid.press_pull");+ assert!(matches!(app.dialog.as_ref().unwrap().kind, Kind::Extrude { .. }));+ let p = Vec3::new(25.0, 15.0, 10.0);+ let hit = crate::viewport::Hit::Face { body: "Body1".into(), index: wall, point: p };+ crate::viewport::dialog_pick(&mut app, &hit, Sel::Face { body: "Body1".into(), index: wall, point: p });+ let d = app.dialog.clone().unwrap();+ assert!(matches!(d.kind, Kind::OffsetFaces { .. }));+ // Both halves of the hole's wall.+ assert_eq!(d.inputs[0].items.len(), 2);++ let mut app = app_with(script);+ app.start("solid.press_pull");+ let top = face(&app, Vec3::new(20.0, 15.0, 20.0));+ let hit = crate::viewport::Hit::Face {+ body: "Body1".into(),+ index: if let Sel::Face { index, .. } = &top { *index } else { 0 },+ point: Vec3::new(5.0, 5.0, 20.0),+ };+ crate::viewport::dialog_pick(&mut app, &hit, top);+ assert!(matches!(app.dialog.as_ref().unwrap().kind, Kind::Extrude { .. }));+}+#[test]fn faces_then_shell_and_face_then_hole() {let mut app = boxed();diff --git a/crates/ui-egui/src/smart_extrude_ui_tests.rs b/crates/ui-egui/src/smart_extrude_ui_tests.rsindex 4c1b4ca7df..f4beae9f2f 100644--- a/crates/ui-egui/src/smart_extrude_ui_tests.rs+++ b/crates/ui-egui/src/smart_extrude_ui_tests.rs@@ -123,3 +123,31 @@ fn an_explicit_reverse_keeps_the_operation() {drag_to(&mut h, 2.0);assert_eq!(state(&h), (1, JOIN, false));}++/// Press Pull on a hole's wall shows an arrow along the wall's normal: dragged 2 mm towards the+/// axis, the 5 mm hole closes to 3 mm (#2873).+#[test]+fn press_pull_drags_a_hole_wall() {+ let mut h = Harness::new();+ h.app.run("solid.box", json!({"length":40,"width":30,"height":20})).unwrap();+ h.app.run("solid.cylinder", json!({"radius":5,"height":20,"base":[20,15,0],"operation":"cut"})).unwrap();+ let st = h.app.session.model.state();+ let wall = st.body("Body1").unwrap().body.faces(0.01).unwrap().into_iter().find(|f| f.plane_normal.is_none()).unwrap().index;+ drop(st);+ h.step(&json!({"call":"ui.view","params":{"view":"home"}})).unwrap();+ h.step(&json!({"call":"ui.view","params":{"view":"fit"}})).unwrap();+ h.settle();+ let p = solidcraft_engine::geom::Vec3::new(25.0, 15.0, 10.0);+ h.app.session.selection = vec![solidcraft_engine::Sel::Face { body: "Body1".into(), index: wall, point: p }];+ h.step(&json!({"start":"solid.press_pull"})).unwrap();+ h.frames(2);+ h.step(&json!({"drag":[{"handle":"arrow"},{"world":[23,15,10]}]})).unwrap();+ h.frames(2);+ let Some(Dialog { kind: Kind::OffsetFaces { distance }, .. }) = &h.app.dialog else { panic!("offset dialog: {:?}", h.app.dialog) };+ let d = h.app.session.doc.eval(distance, solidcraft_engine::doc::expr::Kind::Length).unwrap();+ assert!((d - 2.0).abs() < 0.05, "{distance}");+ h.step(&json!({"key":"Enter"})).unwrap();+ assert!(h.app.dialog.is_none());+ let v = volume(&h);+ assert!((v - (24000.0 - std::f64::consts::PI * 9.0 * 20.0)).abs() / v < 5e-4, "{v}");+}diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 88364ace9a..e7ccdaf4e6 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -2089,6 +2089,21 @@ pub(crate) fn dialog_pick(app: &mut SolveApp, hit: &Hit, sel: Sel) {if app.applying.is_some() {return;}+ // Press Pull's first pick of a curved face or an edge reopens it as an offset or a fillet.+ if let Some(d) = &app.dialog+ && d.press_pull+ && d.inputs.first().is_some_and(|i| i.items.is_empty())+ && match &sel {+ Sel::Edge { .. } => true,+ Sel::Face { body, index, .. } => crate::dialogs::planar_face(&app.session, body, *index).is_none(),+ _ => false,+ }+ {+ crate::dialogs::cancel(app);+ app.session.selection = vec![sel];+ app.start("solid.press_pull");+ return;+ }let Some(mut d) = app.dialog.take() else { return };// With holes moving by clicking (Preferences), a Single hole picked again on its face moves there.if app.preferences.hole_moves && crate::hole_place::pick_moves(&mut d, &app.session, &sel) {