Skip to content

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

Shell: pick a body from the Browser for a closed hollow (#794) (#11441)

ReDead40b1b70decb7
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 1ffe9e0253..8e42ca344b 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -2399,9 +2399,9 @@ impl CanvasPanel {
}
/// Does the open dialog's active input take bodies (Combine's target and tools, #4452;
-/// Move/Copy's bodies, #4771)? Then a body clicked in the Browser goes there, as a click
-/// on it in the view does, rather than replacing the selection: overlapping bodies are
-/// often only told apart in the Browser.
+/// Move/Copy's bodies, #4771; Shell's Faces/Body for a closed hollow, #794)? Then a body
+/// clicked in the Browser goes there, as a click on it in the view does, rather than
+/// replacing the selection: overlapping bodies are often only told apart in the Browser.
fn dialog_takes_body(app: &SolveApp) -> bool {
app.dialog.as_ref().and_then(|d| d.active_input()).is_some_and(|i| i.accept & crate::selection::BODIES != 0)
}
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs
index 9cc8a731c4..1e13a50fe3 100644
--- a/crates/ui-egui/src/dialogs.rs
+++ b/crates/ui-egui/src/dialogs.rs
@@ -112,7 +112,8 @@ const HOLE_LABELS: [&str; 3] = ["Simple", "Counterbore", "Countersink"];
crate::dialog_descriptor::dialog_descriptors! {
#[derive(Clone, Debug)]
pub enum Kind {
- Shell("solid.shell", "SHELL", [("Faces/Body", FACES, true)],
+ // Faces to remove, or a body for a closed hollow with none (#794).
+ Shell("solid.shell", "SHELL", [("Faces/Body", FACES | BODIES, true)],
FeatureKind::Shell { thickness, .. }) {
thickness: String = "2 mm".into() => shown_expr(thickness, ValueKind::Length),
} => json!({"thickness": thickness});
@@ -1471,6 +1472,11 @@ impl Dialog {
return None;
}
let picks = sels(self, 0);
+ // A body alone is a closed hollow: no faces to chain, so the chip and highlights use the
+ // body pick itself (#794). Returning an empty face list would show "0 selected".
+ if picks.iter().all(|p| !matches!(p, Sel::Face { .. })) {
+ return None;
+ }
if let Ok(cache) = self.shell_chain.try_borrow()
&& let Some(chain) = cache.as_ref()
&& chain.revision == s.revision
@@ -2594,6 +2600,9 @@ fn hint(inp: &SelInput) -> &'static str {
"click sketch points"
} else if inp.label == "Components" {
"click components"
+ } else if inp.label == "Faces/Body" {
+ // Shell (#794): faces open the hollow; a body alone seals a closed void inside.
+ "click faces to remove, or a body in the Browser for a closed hollow"
} else if a & BODIES != 0 {
"click bodies"
} else {
@@ -5001,15 +5010,36 @@ fn dialog_commands(app: &SolveApp, d: &Dialog) -> Result<Vec<(String, Value)>, S
}
}
Kind::Shell { .. } => {
- need(0, "faces to remove")?;
- let mut p = json!({"faces": face_points(0)});
- // The picked faces' body: a point alone may name a flush face of another body (#4555).
- let mut bodies = sels(d, 0).iter().filter_map(|s| if let Sel::Face { body, .. } = s { Some(body) } else { None });
- if let Some(first) = bodies.next()
- && bodies.all(|b| b == first)
- {
- p["body"] = json!(first);
- }
+ let picks = sels(d, 0);
+ let face_sels: Vec<_> = picks.iter().filter(|s| matches!(s, Sel::Face { .. })).collect();
+ let body_names: Vec<_> = picks.iter().filter_map(|s| if let Sel::Body { name } = s { Some(name.as_str()) } else { None }).collect();
+ // A body alone (no faces): a closed hollow (#794, #4009). Faces still open the shell.
+ let p = if face_sels.is_empty() {
+ need(0, "faces to remove, or a body for a closed hollow")?;
+ match body_names.as_slice() {
+ [name] => json!({"faces": [], "body": name}),
+ [] => return Err("select faces to remove, or a body for a closed hollow".into()),
+ _ => return Err("select one body for a closed hollow".into()),
+ }
+ } else {
+ let mut p = json!({"faces": face_points(0)});
+ // The picked faces' body: a point alone may name a flush face of another body (#4555).
+ // A Browser body pick with faces scopes them when they all sit on that body.
+ if let [name] = body_names.as_slice() {
+ if face_sels.iter().any(|s| matches!(s, Sel::Face { body, .. } if body != name)) {
+ return Err("the faces are on a different body than the one picked".into());
+ }
+ p["body"] = json!(name);
+ } else {
+ let mut bodies = face_sels.iter().filter_map(|s| if let Sel::Face { body, .. } = s { Some(body.as_str()) } else { None });
+ if let Some(first) = bodies.next()
+ && bodies.all(|b| b == first)
+ {
+ p["body"] = json!(first);
+ }
+ }
+ p
+ };
("solid.shell", p)
}
Kind::Draft { .. } => {
@@ -6414,7 +6444,7 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
d.chain_applied = false;
d
}
- FeatureKind::Shell { faces, direction, tangent_chain, .. } => {
+ FeatureKind::Shell { faces, direction, tangent_chain, body, .. } => {
let mut d = start("solid.shell")?;
d.kind = Kind::simple_restore(&f.kind)?;
d.extra.insert("tangent_chain".into(), json!(tangent_chain));
@@ -6422,13 +6452,20 @@ pub fn for_feature(app: &SolveApp, id: u64, marker: Option<usize>) -> Option<Dia
d.extra.insert("direction".into(), json!(direction));
}
if let Some(inp) = d.inputs.first_mut() {
- inp.items = faces
- .iter()
- .enumerate()
- .filter_map(|(i, p)| {
- f.face_names.get(i).and_then(|name| named_refill(s, f.kind.face_body(), name, p.0, false)).or_else(|| face_sel(s, p.0))
- })
- .collect();
+ // A closed hollow stores no faces and the body it hollows (#794).
+ if faces.is_empty() {
+ if let Some(name) = body {
+ inp.items = vec![Sel::Body { name: name.to_string() }];
+ }
+ } else {
+ inp.items = faces
+ .iter()
+ .enumerate()
+ .filter_map(|(i, p)| {
+ f.face_names.get(i).and_then(|name| named_refill(s, f.kind.face_body(), name, p.0, false)).or_else(|| face_sel(s, p.0))
+ })
+ .collect();
+ }
}
d
}
@@ -7778,7 +7815,7 @@ mod extrude_mixed_pick_tests {
#[cfg(test)]
mod shell_body_tests {
- //! The Shell dialog says whose face it removes (#4555).
+ //! The Shell dialog says whose face it removes (#4555), and takes a body from the Browser (#794).
use super::*;
use crate::scenario::Harness;
@@ -7804,6 +7841,69 @@ mod shell_body_tests {
assert_eq!(cmd, "solid.shell");
assert_eq!(p["body"], json!(upper), "{p}");
}
+
+ /// #794: a body clicked in the Browser fills Faces/Body, and OK builds a closed hollow
+ /// (`faces: []` with that body) instead of leaving the field on Select.
+ #[test]
+ fn a_body_clicked_in_the_browser_fills_shell_for_a_closed_hollow() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":20,"width":20,"height":20,"corner":[0,0,0]})).unwrap();
+ let name = crate::open_meshing::session_world(&h.app.session).bodies[0].name.to_string();
+ h.step(&json!({"start":"solid.shell"})).unwrap();
+ h.frames(2);
+ let before = h.app.dialog.as_ref().expect("Shell is open");
+ assert!(before.inputs[0].items.is_empty(), "Faces/Body starts empty");
+ assert!(before.inputs[0].accept & BODIES != 0, "Shell accepts bodies");
+ h.step(&json!({"click":{"browser": name}})).unwrap();
+ h.frames(2);
+ let d = h.app.dialog.as_ref().expect("Shell stays open");
+ assert_eq!(d.inputs[0].items, vec![Sel::Body { name: name.clone() }], "the Browser body fills Faces/Body");
+ assert_eq!(d.shell_faces(&h.app.session), None, "a body alone does not expand to an empty face chain");
+ assert_eq!(d.highlighted(&h.app.session), vec![Sel::Body { name: name.clone() }], "the body stays highlighted");
+ let commands = dialog_commands(&h.app, d).unwrap();
+ let (cmd, p) = commands.first().unwrap();
+ assert_eq!(cmd, "solid.shell");
+ assert_eq!(p["faces"], json!([]), "no faces: a closed hollow");
+ assert_eq!(p["body"], json!(name), "{p}");
+ }
+
+ /// A face of one body with another body clicked in the Browser is refused, not sent with the
+ /// wrong body.
+ #[test]
+ fn faces_on_another_body_than_the_browser_pick_are_refused() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":20,"width":20,"height":10,"corner":[0,0,0]})).unwrap();
+ h.app.run("solid.box", json!({"length":20,"width":20,"height":10,"corner":[50,0,0],"operation":"new"})).unwrap();
+ let st = crate::open_meshing::session_world(&h.app.session);
+ let other = st.bodies[1].name.to_string();
+ h.step(&json!({"call":"ui.view","params":{"view":"top"}})).unwrap();
+ h.settle();
+ h.step(&json!({"start":"solid.shell"})).unwrap();
+ h.step(&json!({"click":{"world":[10,10,10]}})).unwrap();
+ h.frames(2);
+ let d = h.app.dialog.as_mut().expect("the shell dialog");
+ assert!(matches!(d.inputs[0].items.as_slice(), [Sel::Face { .. }]), "the top face of the first box is picked");
+ assert!(dialog_commands(&h.app, h.app.dialog.as_ref().unwrap()).is_ok());
+ h.app.dialog.as_mut().unwrap().inputs[0].items.push(Sel::Body { name: other });
+ let d = h.app.dialog.as_ref().unwrap();
+ assert_eq!(dialog_commands(&h.app, d).err().as_deref(), Some("the faces are on a different body than the one picked"));
+ }
+
+ /// A body selected before Shell starts is taken the same way as a Browser click (#794).
+ #[test]
+ fn a_preselected_body_fills_shell_for_a_closed_hollow() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":40,"width":30,"height":12.5})).unwrap();
+ let name = crate::open_meshing::session_world(&h.app.session).bodies[0].name.to_string();
+ h.app.run("select.set", json!({"items":[{"type":"body","name": name}]})).unwrap();
+ h.app.start("solid.shell");
+ h.frames(2);
+ let d = h.app.dialog.as_ref().expect("Shell opens");
+ assert_eq!(d.inputs[0].items, vec![Sel::Body { name: name.clone() }]);
+ let (_, p) = dialog_commands(&h.app, d).unwrap().into_iter().next().unwrap();
+ assert_eq!(p["faces"], json!([]));
+ assert_eq!(p["body"], json!(name));
+ }
}
#[cfg(test)]