Skip to content

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

Browser: surface bodies get the surface icon in the Bodies folder (#4165) (#4168)

Frankb5bab3f66390
diff --git a/assets/icons/ui/design/requested_icons.txt b/assets/icons/ui/design/requested_icons.txt
index 60cbb03ef4..bd041b1f09 100644
--- a/assets/icons/ui/design/requested_icons.txt
+++ b/assets/icons/ui/design/requested_icons.txt
@@ -247,6 +247,7 @@ status_error false
status_recovery false
style false
suppress false
+surface false
surface_blend false
surface_boundary false
surface_extend false
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index ed7781df12..0a217381ab 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -68,6 +68,9 @@ pub struct ModelBody {
/// [`kernel::measure`] of `body` (with the body it was measured on), worked out once and
/// shared by clones: inspecting a design again measures only the bodies that changed.
measured: Arc<OnceLock<(Body, kernel::Result<kernel::BodyMeasure>)>>,
+ /// [`Body::is_surface`] of `body` (with the body it was measured on), worked out once and
+ /// shared by clones.
+ surface: Arc<OnceLock<(Body, bool)>>,
}
impl ModelBody {
@@ -93,6 +96,16 @@ impl ModelBody {
source_key: 0,
outline: Arc::new(OnceLock::new()),
measured: Arc::new(OnceLock::new()),
+ surface: Arc::new(OnceLock::new()),
+ }
+ }
+
+ /// A surface body: some shell does not close ([`Body::is_surface`]), worked out once.
+ pub fn is_surface(&self) -> bool {
+ match self.surface.get_or_init(|| (self.body.clone(), self.body.is_surface())) {
+ (measured, s) if measured.same(&self.body) => *s,
+ // The body was replaced in this cell's holder since: look again.
+ _ => self.body.is_surface(),
}
}
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index 8613d6ac52..66b5de014e 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -1767,7 +1767,8 @@ fn entries(app: &SolveApp, comp: u64, folder: &str) -> Vec<Entry> {
key: b.name.clone(),
row_key: format!("b:{}", b.name),
label: b.name.clone(),
- icon: "body",
+ // An open shell is a surface body, not a solid.
+ icon: if b.is_surface() { "surface" } else { "body" },
visible: !app.session.visibility.hidden_bodies.contains(&b.name),
selected: sel.iter().any(|x| matches!(x, Sel::Body { name } if *name == b.name)),
color: None,
diff --git a/crates/ui-egui/src/browser_model_tests.rs b/crates/ui-egui/src/browser_model_tests.rs
index 75594e8b88..504ef7603b 100644
--- a/crates/ui-egui/src/browser_model_tests.rs
+++ b/crates/ui-egui/src/browser_model_tests.rs
@@ -141,3 +141,25 @@ fn hovering_a_collapsed_nested_placement_walks_its_subtree_once() {
h.call("ui.move", json!({"x":at.x,"y":at.y + 1.0}));
assert_eq!(h.app.viewport.hover_bodies.len(), 7);
}
+
+/// An open curve turned round is a surface body and the Bodies folder shows it as one; a closed
+/// profile turned all the way round, and a box, are solids.
+#[test]
+fn bodies_folder_tells_surfaces_from_solids() {
+ let mut h = crate::scenario::Harness::new();
+ let mut run = |id: &str, p: serde_json::Value| {
+ h.app.run(id, p).unwrap();
+ };
+ run("sketch.create", json!({"plane":"XY", "name":"S"}));
+ run("sketch.line", json!({"points":[[3, 0], [3, 4]], "ids":["side"]}));
+ run("sketch.rectangle.two_point", json!({"p0":[5, 0], "p1":[7, 3]}));
+ run("sketch.finish", json!({}));
+ run("surface.revolve", json!({"sketch":"S", "curves":["side"], "axis":"y", "body_name":"Tube"}));
+ run("surface.revolve", json!({"sketch":"S", "profiles":[0], "axis":"y", "body_name":"Ring"}));
+ run("solid.box", json!({"length":2, "width":2, "height":2, "corner":[20, 0, 0]}));
+ super::prepare_model(&mut h.app);
+ let icons: Vec<(String, &str)> = super::entries(&h.app, 0, "bodies").into_iter().map(|e| (e.key, e.icon)).collect();
+ assert_eq!(icons.len(), 3, "{icons:?}");
+ assert_eq!(icons[..2], [("Tube".to_string(), "surface"), ("Ring".to_string(), "body")]);
+ assert_eq!(icons[2].1, "body", "the box is a solid");
+}