SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Face and edge dialogs name the body of their picks (#7174)
Robson Pereira207679e2618e
diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rsindex 71b26e0e0b..4690557fdc 100644--- a/crates/engine/src/cmd/features.rs+++ b/crates/engine/src/cmd/features.rs@@ -1709,7 +1709,13 @@ fn press_pull(s: &mut Session, p: &Value) -> Result<Value> {// Another curved face moves along its normal.if super::face::face_is_planar(s, fp) == Some(false) {let r = super::find_command("solid.offset_face").ok_or_else(|| bad(cmd, "solid.offset_face"))?;- return (r.run)(s, &json!({"faces": [face], "distance": distance}));+ let mut q = json!({"faces": [face], "distance": distance});+ // The face's body, when given, goes along: found by point alone, a face inside another+ // part's box (a screw bore in a housing) can be looked for on that part instead.+ if let Some(body) = p.get("body").filter(|b| b.is_string()) {+ q["body"] = body.clone();+ }+ return (r.run)(s, &q);}}// Pushed in: the extrude cuts the other way by as much (a bare number stays one, so it keepsdiff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 33bb76cf76..81063bb859 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -4833,6 +4833,26 @@ fn sels(d: &Dialog, i: usize) -> &[Sel] {selection::items(&d.inputs, i)}+/// The body every picked edge and face lies on, when they all lie on one. A face feature given+/// it finds its faces there alone; without it, it looks through every body for each point and+/// takes the one whose box is nearest, which in an assembly can be an enclosing part with no face+/// there ("no face at …") and meshes every part of a large design (#4555, as Shell names it).+fn single_body(picks: &[Sel]) -> Option<String> {+ let mut bodies = picks.iter().filter_map(|x| match x {+ Sel::Edge { body, .. } | Sel::Face { body, .. } => Some(body),+ _ => None,+ });+ bodies.next().filter(|first| bodies.all(|b| b == *first)).cloned()+}++/// `p` with the picked faces' or edges' body named ([`single_body`]).+fn with_single_body(mut p: Value, picks: &[Sel]) -> Value {+ if let Some(body) = single_body(picks) {+ p["body"] = json!(body);+ }+ p+}+/// Section Analysis with a section on and no plane picked: OK turns the section off.fn section_turns_off(s: &Session, inputs: &[selection::SelInput]) -> bool {s.section.is_some() && selection::items(inputs, 0).is_empty()@@ -5286,7 +5306,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S}let edges: Vec<Value> = uniq.into_iter().map(pt).collect();if *chamfer {- let mut p = json!({"edges": edges, "distance": radius});+ let mut p = with_single_body(json!({"edges": edges, "distance": radius}), sels(d, 0));match *ctype {1 => p["distance2"] = json!(distance2),2 => p["angle"] = json!(angle),@@ -5297,7 +5317,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S}("solid.chamfer", p)} else {- let mut p = json!({"edges": edges, "radius": radius});+ let mut p = with_single_body(json!({"edges": edges, "radius": radius}), sels(d, 0));let style = d.extra.get("type").and_then(Value::as_str);if matches!(style, Some("variable" | "spline")) {// The start radius goes at one end of the first edge (Swap Ends: the other).@@ -5571,7 +5591,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, SKind::ReplaceFace => {need(0, "faces to move")?;need(1, "the target")?;- let mut p = json!({"faces": face_points(0)});+ let mut p = with_single_body(json!({"faces": face_points(0)}), sels(d, 0));match sels(d, 1).first() {Some(Sel::Plane { name }) => p["target"] = json!(name),Some(Sel::Face { point, .. }) => p["target_face"] = pt(*point),@@ -5581,7 +5601,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S}Kind::DeleteFaces => {need(0, "faces")?;- ("face.delete", json!({"faces": face_points(0)}))+ ("face.delete", with_single_body(json!({"faces": face_points(0)}), sels(d, 0)))}Kind::Align { flip, components, axes, angle } => {need(0, if *components { "components" } else { "bodies" })?;@@ -5697,7 +5717,7 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S}Kind::OffsetFaces { .. } => {need(0, "faces")?;- ("solid.offset_face", json!({"faces": face_points(0)}))+ ("solid.offset_face", with_single_body(json!({"faces": face_points(0)}), sels(d, 0)))}Kind::Thread { designation, length, suggested, options, .. } => {need(0, "a cylindrical face")?;diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rsindex c4c1439baa..7c9ce232e6 100644--- a/crates/ui-egui/src/dialogs_dense.rs+++ b/crates/ui-egui/src/dialogs_dense.rs@@ -1301,6 +1301,57 @@ mod tests {h.frames(2);}+ #[test]+ fn fillet_and_chamfer_name_the_body_of_their_edges() {+ // Named, the feature looks for its edges on that body alone instead of meshing every+ // body of the design on each preview and apply.+ let h = fillet_harness();+ let body = h.app.session.world_state().unwrap().bodies.first().unwrap().name.clone();+ let p = parameters(&h);+ assert_eq!(p["body"], json!(body), "{p}");+ // Edges of two bodies name none: each point finds its own.+ let mut h = Harness::new();+ sample(&mut h);+ h.app.run("solid.box", json!({"length":4,"width":4,"height":4,"corner":[20,0,0],"operation":"new"})).unwrap();+ let a = edge_sel(&h.app.session, Vec3::new(5.0, 0.0, 5.0)).unwrap();+ let b = edge_sel(&h.app.session, Vec3::new(22.0, 0.0, 4.0)).unwrap();+ h.app.session.selection = vec![a, b];+ h.step(&json!({"start":"solid.chamfer"})).unwrap();+ h.frames(4);+ let commands = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();+ let (cmd, p) = commands.first().unwrap();+ assert_eq!(*cmd, "solid.chamfer");+ assert!(p.get("body").is_none(), "{p}");+ }++ #[test]+ fn press_pull_on_a_bore_inside_another_part_moves_that_bore() {+ // A pin standing inside a hollow housing that comes first: by its point alone the face+ // was looked for on the housing, whose box holds it, and the command failed with+ // "no face at …". The dialog now names the pin.+ let mut h = Harness::new();+ h.app.run("solid.box", json!({"length":100,"width":100,"height":100,"body_name":"Housing"})).unwrap();+ h.app.run("solid.box", json!({"length":80,"width":80,"height":100,"corner":[10,10,10],"operation":"cut","targets":["Housing"]})).unwrap();+ h.app.run("solid.cylinder", json!({"base":[50,50,20],"radius":5,"height":20,"operation":"new","body_name":"Pin"})).unwrap();+ let face = face_sel(&h.app.session, Vec3::new(55.0, 50.0, 30.0)).unwrap();+ assert!(matches!(&face, Sel::Face { body, .. } if body == "Pin"), "{face:?}");+ h.app.session.selection = vec![face];+ h.step(&json!({"start":"solid.press_pull"})).unwrap();+ h.frames(4);+ let commands = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();+ let (cmd, mut p) = commands.first().cloned().unwrap();+ assert_eq!(cmd, "solid.offset_face");+ assert_eq!(p["body"], json!("Pin"), "{p}");+ p["distance"] = json!(1);+ h.app.run(&cmd, p).unwrap();+ let st = h.app.session.world_state().unwrap();+ let pin = st.body("Pin").unwrap().measure().unwrap();+ let expected = std::f64::consts::PI * 36.0 * 20.0;+ assert!((pin.volume - expected).abs() < expected * 1e-3, "pin volume {} (expected {expected})", pin.volume);+ let housing = st.body("Housing").unwrap().measure().unwrap();+ assert!((housing.volume - (1e6 - 80.0 * 80.0 * 90.0)).abs() < 1.0, "the housing is unchanged: {}", housing.volume);+ }+#[test]fn every_type_choice_produces_its_supported_command_without_changing_defaults() {for (label, key) in FILLET_TYPES {