* 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 <noreply@anthropic.com> * Add the surface icon to the requested-icons manifest Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user