From b5bab3f6639089d47bd0035831fc0c08e6cb2b81 Mon Sep 17 00:00:00 2001 From: Frank <58932224+plexi32@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:51:02 +0000 Subject: [PATCH] Browser: surface bodies get the surface icon in the Bodies folder (#4165) (#4168) * Browser: surface bodies get the surface icon in the Bodies folder (#4165) Every row in the Bodies folder had the solid body icon, so a surface (an open shell, such as a Surface Revolve of an open curve) looked like a solid. A body whose shell does not close now shows the existing surface icon; solids keep the body icon. Body::is_surface walks every shell's edges, so ModelBody caches it once per body (shared by clones, like outline_bounds) instead of the browser checking it every frame. Co-Authored-By: Claude Opus 5.5 * Add the surface icon to the requested-icons manifest Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 Co-authored-by: bherbruck --- assets/icons/ui/design/requested_icons.txt | 1 + crates/doc/src/eval.rs | 13 +++++++++++++ crates/ui-egui/src/browser.rs | 3 ++- crates/ui-egui/src/browser_model_tests.rs | 22 ++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/assets/icons/ui/design/requested_icons.txt b/assets/icons/ui/design/requested_icons.txt index 60cbb03ef..bd041b1f0 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 ed7781df1..0a217381a 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)>>, + /// [`Body::is_surface`] of `body` (with the body it was measured on), worked out once and + /// shared by clones. + surface: Arc>, } 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 8613d6ac5..66b5de014 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 { 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 75594e8b8..504ef7603 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"); +}