SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Browser: hidden items grey out, and folders keep their own visibility (#2308)
N3MI-DG3eeb20d2bdba
diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rsindex 2b2f675330..b60de5ff46 100644--- a/crates/doc/src/document.rs+++ b/crates/doc/src/document.rs@@ -2420,6 +2420,12 @@ pub struct Visibility {/// Assembly joints by id: their glyphs are not drawn (they still constrain and move).#[serde(skip_serializing_if = "Vec::is_empty")]pub hidden_joints: Vec<u64>,+ /// Browser folders and groups hidden themselves, by tree key: `<scope>/<folder>` or+ /// `<scope>/g<group id>`, where the scope is `c0` (the design) or `o:<placement path>`+ /// (`o:4/9/bodies`). Their items keep their own state: they are drawn again, as they were,+ /// once the folder is shown.+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub hidden_folders: Vec<String>,}impl Visibility {@@ -2431,6 +2437,7 @@ impl Visibility {&& self.hidden_sketches.is_empty()&& self.shown_sketches.is_empty()&& self.hidden_joints.is_empty()+ && self.hidden_folders.is_empty()}}diff --git a/crates/doc/src/format/pending/browser-folder-visibility.rs b/crates/doc/src/format/pending/browser-folder-visibility.rsnew file mode 100644index 0000000000..279a8178f7--- /dev/null+++ b/crates/doc/src/format/pending/browser-folder-visibility.rs@@ -0,0 +1,5 @@+//! A browser folder or group can be hidden on its own (`visibility.hidden_folders`, tree keys+//! such as `c0/bodies`, `o:4/sketches` or `c0/g7`): its items keep their own hidden state and+//! are drawn again as they were once it is shown. Older designs need no transformation: they+//! hide no folder, and a folder's eye then follows its own state. The last release asks for an+//! update instead of opening a design with this format number.diff --git a/crates/engine/src/cmd/browser.rs b/crates/engine/src/cmd/browser.rsindex 45a666d854..1de6dd786b 100644--- a/crates/engine/src/cmd/browser.rs+++ b/crates/engine/src/cmd/browser.rs@@ -40,7 +40,9 @@ pub static COMMANDS: &[CommandSpec] = &[CommandSpec::new("browser.visibility", "Show/Hide", visibility).icon("eye").noundo().params("visible: bool; items?: [sketch id or name | body name | construction name | joint name | O|X|Y|Z|XY|XZ|YZ]; \or joints?: [joint id or name] (their glyphs; they still constrain and move parts); \- or folder?: bodies|sketches|construction|origin|joints (all of it); or paths?: [[occurrence ids]] (exact placements and descendants), isolate?: bool (requires paths and visible:true). Saved with the design; not an undo step",+ or folder?: bodies|sketches|construction|origin|joints (all of it; showing also shows its browser folders and groups); \+ or tree_folders?: [browser folder or group key: c0/bodies, o:4/sketches, c0/g7, c0/joints, c0/canvases] (the folder or group itself: its items keep their own state); \+ or paths?: [[occurrence ids]] (exact placements and descendants), isolate?: bool (requires paths and visible:true). Saved with the design; not an undo step",),];@@ -197,9 +199,46 @@ fn shown_item(s: &Session, key: &str) -> Option<Shown> {ORIGIN.iter().find(|o| o.eq_ignore_ascii_case(key)).map(|o| Shown::Origin(o.to_string()))}+/// A browser folder or group key (`Visibility::hidden_folders`): `c0` or `o:<ids>`, then+/// `/bodies`, `/sketches`, `/construction`, `/joints`, `/canvases` or `/g<group id>`.+fn tree_folder_key(k: &str) -> bool {+ let Some((scope, last)) = k.rsplit_once('/') else { return false };+ let scope_ok =+ scope == "c0" || scope.strip_prefix("o:").is_some_and(|ids| ids.split('/').count() <= 64 && ids.split('/').all(|i| i.parse::<u64>().is_ok()));+ let last_ok =+ FOLDERS.contains(&last) || ["joints", "canvases"].contains(&last) || last.strip_prefix('g').is_some_and(|g| g.parse::<u64>().is_ok());+ k.len() <= 2048 && scope_ok && last_ok+}+fn visibility(s: &mut Session, p: &Value) -> Result<Value> {let cmd = "browser.visibility";let visible = bool_(p, "visible").ok_or_else(|| bad(cmd, "`visible` must be true or false"))?;+ if let Some(value) = p.get("tree_folders") {+ if ["items", "folder", "joints", "paths"].iter().any(|k| p.get(*k).is_some()) {+ return Err(bad(cmd, "give `tree_folders`, `items`, `folder`, `joints` or `paths`, not several"));+ }+ let keys = value+ .as_array()+ .filter(|a| !a.is_empty() && a.len() <= 10_000)+ .ok_or_else(|| bad(cmd, "`tree_folders` must list 1..10000 browser folder or group keys"))?;+ // Every key is checked before anything changes.+ let keys: Vec<String> = keys+ .iter()+ .map(|k| {+ k.as_str().filter(|k| tree_folder_key(k)).map(str::to_string).ok_or_else(|| {+ bad(cmd, "a browser folder or group key is `<c0 | o:ids>/<folder | g<group id>>`, such as `c0/bodies` or `o:4/g7`")+ })+ })+ .collect::<Result<_>>()?;+ for k in &keys {+ s.visibility.hidden_folders.retain(|h| h != k);+ if !visible {+ s.visibility.hidden_folders.push(k.clone());+ }+ }+ s.revision += 1;+ return Ok(json!({"visible":visible,"changed":keys.len(),"visibility":s.visibility}));+ }if let Some(value) = p.get("paths") {if p.get("items").is_some() || p.get("folder").is_some() {return Err(bad(cmd, "give paths, items or folder, not several"));@@ -291,6 +330,12 @@ fn visibility(s: &mut Session, p: &Value) -> Result<Value> {}(None, None) => return Err(bad(cmd, "`items` or `folder` is required")),};+ // Showing all of a kind also shows the browser folders and groups that hold it.+ if visible && let Some(f) = str_(p, "folder") {+ let groups: Vec<String> = s.doc.browser_groups.iter().filter(|g| g.folder == f).map(|g| format!("/g{}", g.id)).collect();+ let own = format!("/{f}");+ s.visibility.hidden_folders.retain(|k| !k.ends_with(&own) && !groups.iter().any(|g| k.ends_with(g.as_str())));+ }let v = &mut s.visibility;if visible && str_(p, "folder") == Some("bodies") {v.hidden_occurrences.clear();@@ -979,6 +1024,13 @@ mod tests {assert!(std::sync::Arc::ptr_eq(&s.doc, &doc0) && s.undo.len() == undo0, "view state, not a design change");run(&mut s, "browser.visibility", json!({"folder": "sketches", "visible": true}));assert_eq!(lines(&s), n0);+ // The browser's Sketches folder hidden: sketches shown one by one aren't drawn either,+ // only the sketch being edited.+ assert!(s.visibility.shown_sketches.contains(&floor));+ assert!([floor, drain].iter().all(|id| !crate::view::sketch_drawn(&s, *id, false)));+ s.active_sketch = Some(floor);+ assert!(crate::view::sketch_drawn(&s, floor, false) && !crate::view::sketch_drawn(&s, drain, false));+ s.active_sketch = None;// Bodies (following a rename) and construction planes.run(&mut s, "browser.visibility", json!({"items": [body.clone(), "Floor", "xy"], "visible": false}));assert!(crate::view::scene(&s, &cam).meshes.is_empty());@@ -1066,4 +1118,67 @@ mod tests {run(&mut s, "edit.undo", json!({}));assert_eq!(s.doc.browser_groups.len(), 1, "ungroup undoes");}++ #[test]+ fn hidden_folders_and_groups_keep_their_items_state() {+ let mut s = Session::default();+ run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10}));+ run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [20, 0, 0]}));+ run(&mut s, "solid.box", json!({"length": 10, "width": 10, "height": 10, "corner": [40, 0, 0]}));+ let [a, b, c] = [names(&s)[0].clone(), names(&s)[1].clone(), names(&s)[2].clone()];+ let shown = |s: &Session| [&a, &b, &c].map(|n| s.body_visible(n));+ run(&mut s, "browser.visibility", json!({"items": [a.clone()], "visible": false}));++ // Hiding the folder hides every body; their own state is kept.+ run(&mut s, "browser.visibility", json!({"tree_folders": ["c0/bodies"], "visible": false}));+ assert_eq!(shown(&s), [false; 3]);+ assert_eq!(s.visibility.hidden_bodies, vec![a.clone()]);+ // Showing a body in a hidden folder doesn't show the folder, nor draw the body.+ run(&mut s, "browser.visibility", json!({"items": [b.clone()], "visible": true}));+ assert!(s.folder_hidden("c0/bodies") && !s.body_visible(&b));+ // Showing the folder brings back what was shown before.+ run(&mut s, "browser.visibility", json!({"tree_folders": ["c0/bodies"], "visible": true}));+ assert_eq!(shown(&s), [false, true, true]);+ // Hiding every body leaves the folder shown.+ run(&mut s, "browser.visibility", json!({"items": [a.clone(), b.clone(), c.clone()], "visible": false}));+ assert!(!s.folder_hidden("c0/bodies"), "hiding every item doesn't hide the folder");+ run(&mut s, "browser.visibility", json!({"items": [b.clone(), c.clone()], "visible": true}));++ // A group the same way.+ let g = run(&mut s, "browser.group", json!({"folder": "bodies", "items": [a.clone(), b.clone()]}))["group"].as_u64().unwrap();+ let key = format!("c0/g{g}");+ run(&mut s, "browser.visibility", json!({"tree_folders": [key], "visible": false}));+ assert_eq!(shown(&s), [false, false, true]);+ run(&mut s, "browser.visibility", json!({"tree_folders": [key], "visible": true}));+ assert_eq!(shown(&s), [false, true, true]);+ run(&mut s, "browser.visibility", json!({"items": [a.clone(), b.clone()], "visible": false}));+ assert!(!s.folder_hidden(&key), "hiding every item doesn't hide the group");++ // Saved with the design.+ run(&mut s, "browser.visibility", json!({"tree_folders": [key, "o:4/sketches"], "visible": false}));+ let v: solidcraft_doc::Visibility = serde_json::from_value(serde_json::to_value(&s.visibility).unwrap()).unwrap();+ assert_eq!(v.hidden_folders, vec![key.clone(), "o:4/sketches".to_string()]);+ // Showing every body also shows the folders and groups that hold bodies.+ run(&mut s, "browser.visibility", json!({"folder": "bodies", "visible": true}));+ assert_eq!(shown(&s), [true; 3]);+ assert_eq!(s.visibility.hidden_folders, vec!["o:4/sketches".to_string()]);++ // Hostile keys are refused, and nothing changes.+ for p in [+ json!({"tree_folders": [], "visible": false}),+ json!({"tree_folders": "c0/bodies", "visible": false}),+ json!({"tree_folders": ["bodies"], "visible": false}),+ json!({"tree_folders": ["c1/bodies"], "visible": false}),+ json!({"tree_folders": ["o:/bodies"], "visible": false}),+ json!({"tree_folders": ["o:x/bodies"], "visible": false}),+ json!({"tree_folders": ["c0/gx"], "visible": false}),+ json!({"tree_folders": ["c0/nope"], "visible": false}),+ json!({"tree_folders": [7], "visible": false}),+ json!({"tree_folders": ["c0/bodies"], "items": [c.clone()], "visible": false}),+ json!({"tree_folders": [format!("o:{}1/bodies", "1/".repeat(70))], "visible": false}),+ ] {+ assert!(s.execute("browser.visibility", &p).is_err(), "{p}");+ }+ assert_eq!(s.visibility.hidden_folders, vec!["o:4/sketches".to_string()]);+ }}diff --git a/crates/engine/src/occurrences.rs b/crates/engine/src/occurrences.rsindex 0fd615cfe6..342f131c87 100644--- a/crates/engine/src/occurrences.rs+++ b/crates/engine/src/occurrences.rs@@ -28,6 +28,7 @@ fn invalid(message: &str) -> EngineError {pub(crate) struct VisibilityCache {revision: u64,paths: Vec<Vec<u64>>,+ folders: Vec<String>,bodies: std::collections::BTreeSet<String>,}@@ -186,31 +187,106 @@ impl Session {/// Whether a joint's glyph is drawn (`browser.visibility`). Hiding a joint only hides its/// drawing: it still constrains and drives the parts.+ /// Is the joint shown itself (its own eye; the Joints folder may still hide it)?pub fn joint_visible(&self, id: u64) -> bool {!self.visibility.hidden_joints.contains(&id)}+ /// Is the joint's glyph drawn: shown itself, in a shown Joints folder?+ pub fn joint_drawn(&self, id: u64) -> bool {+ self.joint_visible(id) && !self.folder_hidden("c0/joints")+ }++ /// The scope of a placement's browser folders and groups: `c0` for the design (an empty+ /// path), `o:<ids joined by />` for a placement.+ pub fn folder_scope(path: &[u64]) -> String {+ if path.is_empty() { "c0".to_string() } else { format!("o:{}", path.iter().map(u64::to_string).collect::<Vec<_>>().join("/")) }+ }++ /// Is a browser folder or group hidden itself (by tree key, see `Visibility::hidden_folders`)?+ pub fn folder_hidden(&self, key: &str) -> bool {+ self.visibility.hidden_folders.iter().any(|k| k == key)+ }++ /// Is an item (its browser key: body name, feature id) hidden by its folder, or by a group+ /// of that folder it is in, at a placement scope ([`Self::folder_scope`])?+ pub fn item_folder_hidden(&self, scope: &str, component: u64, folder: &str, item: &str) -> bool {+ if self.visibility.hidden_folders.is_empty() {+ return false;+ }+ self.folder_hidden(&format!("{scope}/{folder}"))+ || self.doc.browser_groups.iter().any(|g| {+ g.component == component+ && g.folder == folder+ && g.items.iter().any(|i| i == item)+ && self.folder_hidden(&format!("{scope}/g{}", g.id))+ })+ }++ /// Is a sketch or construction feature hidden by its folder or group, at the placement it+ /// is drawn at (the active one while its component is being edited, else the first)?+ pub fn feature_folder_hidden(&self, id: u64, folder: &str) -> bool {+ if self.visibility.hidden_folders.is_empty() {+ return false;+ }+ let component = self.doc.feature(id).map_or(0, |f| f.component);+ let path = match &self.active_occurrence_path {+ _ if component == 0 => Vec::new(),+ Some(p) if self.active_component == component => p.clone(),+ _ => self.doc.first_path(component),+ };+ self.item_folder_hidden(&Self::folder_scope(&path), component, folder, &id.to_string())+ }++ /// Is construction geometry or an origin item (by name) shown: not hidden itself, nor by+ /// its folder or a group it is in?+ pub fn construction_visible(&self, name: &str) -> bool {+ if self.visibility.hidden_origin.iter().any(|h| h == name) {+ return false;+ }+ match self.doc.features.iter().find(|f| f.name == name) {+ Some(f) => !self.feature_folder_hidden(f.id, "construction"),+ None => true,+ }+ }+pub fn body_visible(&self, name: &str) -> bool {if self.visibility.hidden_bodies.iter().any(|n| n == name) || self.body_removed_later(name) {return false;}- if self.visibility.hidden_occurrences.is_empty() {+ let v = &self.visibility;+ if v.hidden_occurrences.is_empty() && v.hidden_folders.is_empty() {return true;}if let Ok(mut cache) = self.occurrence_visibility_cache.lock() {- if cache.as_ref().is_none_or(|c| c.revision != self.revision || c.paths != self.visibility.hidden_occurrences) {- let bodies = self- .doc- .body_frames(&self.model.state())- .into_iter()- .filter(|(_, _, path, _)| !self.occurrence_visible(path))- .map(|(name, _, _, _)| name)- .collect();- *cache = Some(VisibilityCache { revision: self.revision, paths: self.visibility.hidden_occurrences.clone(), bodies });+ if cache.as_ref().is_none_or(|c| c.revision != self.revision || c.paths != v.hidden_occurrences || c.folders != v.hidden_folders) {+ *cache = Some(VisibilityCache {+ revision: self.revision,+ paths: v.hidden_occurrences.clone(),+ folders: v.hidden_folders.clone(),+ bodies: self.bodies_hidden_by_parents(),+ });}return cache.as_ref().is_none_or(|c| !c.bodies.contains(name));}- self.doc.body_frames(&self.model.state()).iter().find(|(n, _, _, _)| n == name).is_none_or(|(_, _, path, _)| self.occurrence_visible(path))+ !self.bodies_hidden_by_parents().contains(name)+ }++ /// World names of the bodies a hidden placement, folder or group above them hides (their+ /// own state aside).+ fn bodies_hidden_by_parents(&self) -> std::collections::BTreeSet<String> {+ let st = self.model.state();+ let mut out = std::collections::BTreeSet::new();+ for (component, path, _) in self.doc.placements() {+ let placement_hidden = !path.is_empty() && !self.occurrence_visible(&path);+ let scope = Self::folder_scope(&path);+ for b in st.bodies.iter().filter(|b| self.doc.model_body_component(b) == component) {+ if placement_hidden || self.item_folder_hidden(&scope, component, "bodies", &b.name) {+ out.insert(self.doc.world_body_name(&st, &b.name, component, &path));+ }+ }+ }+ out}/// Is this body deleted by a feature the history marker has rolled off, while a sketch isdiff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rsindex 3684244e3c..3208fefe4e 100644--- a/crates/engine/src/view.rs+++ b/crates/engine/src/view.rs@@ -533,18 +533,18 @@ pub fn sketch_shown(s: &Session, id: u64) -> bool {sketch_drawn(s, id, true)}-/// Is a sketch drawn, with the browser's Sketches folder shown (`folder`) or hidden? The sketch-/// being edited always is; otherwise not when hidden, nor in a hidden component, and one used by-/// a feature only when shown on its own.+/// Is a sketch drawn, with sketches shown (`folder`) or hidden? The sketch being edited always+/// is; otherwise not when hidden, nor in a hidden component, Sketches folder or group (even one+/// shown on its own), and one used by a feature only when shown on its own.pub fn sketch_drawn(s: &Session, id: u64, folder: bool) -> bool {let v = &s.visibility;if s.active_sketch == Some(id) {return true;}- if v.hidden_sketches.contains(&id) || !sketch_component_visible(s, id) {+ if !folder || v.hidden_sketches.contains(&id) || !sketch_component_visible(s, id) || s.feature_folder_hidden(id, "sketches") {return false;}- v.shown_sketches.contains(&id) || (folder && !sketch_consumed(s, id))+ v.shown_sketches.contains(&id) || !sketch_consumed(s, id)}/// Is the placement a sketch is drawn at shown (the active one while its component is beingdiff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rsindex dd4c35b198..96d248348c 100644--- a/crates/ui-egui/src/browser.rs+++ b/crates/ui-egui/src/browser.rs@@ -77,6 +77,10 @@ pub struct TreeState {/// A Section Analysis hidden with its eye in the Analysis folder: its plane (origin,/// normal), so the eye can bring it back (#822).pub hidden_section: Option<(solidcraft_engine::geom::Vec3, solidcraft_engine::geom::Vec3)>,+ /// The Analysis folder hidden with its own eye, and the Section Analysis hidden with its+ /// own: the section shows only while neither is, and each eye keeps its state.+ pub analysis_hidden: bool,+ pub section_hidden: bool,/// What waits for the Capture Position question: a command id, or [`SAVE`].pub capture_prompt: Option<String>,/// The last row clicked (for Shift ranges).@@ -113,12 +117,13 @@ impl OccMove {// Queries used by the menus// ----------------------------------------------------------------------------------------------/// Is a sketch drawn in the viewport?+/// Is a sketch shown itself (its eye)? A hidden Sketches folder or component still keeps it out+/// of the viewport (`solidcraft_engine::view::sketch_drawn`).pub fn sketch_visible(app: &SolveApp, id: u64) -> bool {if app.session.visibility.hidden_sketches.contains(&id) {return false;}- app.session.visibility.shown_sketches.contains(&id) || (app.ui.show_sketches && !solidcraft_engine::view::sketch_consumed(&app.session, id))+ app.session.visibility.shown_sketches.contains(&id) || !solidcraft_engine::view::sketch_consumed(&app.session, id)}pub fn set_sketch_visible(app: &mut SolveApp, id: u64, on: bool) {@@ -154,24 +159,23 @@ pub fn group_name(app: &SolveApp, id: u64) -> Option<String> {}/// The menu of a group row.-pub fn group_items(app: &SolveApp, id: u64) -> Vec<Item> {+pub fn group_items(app: &SolveApp, id: u64, scope: &str) -> Vec<Item> {let Some(g) = find_group(app, id) else { return Vec::new() };let mut v = vec![Item::action("ui.rename", "Rename", "").with(json!({ "group": id })),Item::action("ui.ungroup", "Ungroup", "folder").with(json!({ "group": id })),+ Item::sep(),+ // The group itself: its items keep their own state.+ Item::action("ui.folderVisible", "Show/Hide", "eye").key("V").with(json!({ "key": format!("{scope}/g{id}") })),];if g.folder == "bodies" {- let bodies = group_bodies(app, id);- let hidden = !bodies.is_empty() && bodies.iter().all(|b| app.session.visibility.hidden_bodies.contains(b));- v.push(Item::sep());- v.push(Item::action(if hidden { "ui.show" } else { "ui.hide" }, "Show/Hide", "eye").key("V").with(json!({ "bodies": bodies })));- v.push(Item::action("ui.isolate", "Isolate", "").with(json!({ "bodies": bodies })));+ v.push(Item::action("ui.isolate", "Isolate", "").with(json!({ "bodies": group_bodies(app, id) })));}v}/// The menu of a folder row (Bodies, Sketches, Construction).-pub fn folder_items(app: &SolveApp, component: u64, folder: &str) -> Vec<Item> {+pub fn folder_items(app: &SolveApp, component: u64, folder: &str, scope: &str) -> Vec<Item> {let sel: Vec<String> = selected_keys(app, component, folder);let all = entries(app, component, folder);let mut v = Vec::new();@@ -187,7 +191,7 @@ pub fn folder_items(app: &SolveApp, component: u64, folder: &str) -> Vec<Item> {v.push(Item::action("ui.groupSelected", "Group Selected", "folder").with(json!({ "component": component, "folder": folder, "items": sel })));}v.push(Item::sep());- v.push(Item::action("ui.folderVisible", "Show/Hide", "eye").key("V").with(json!({ "component": component, "folder": folder })));+ v.push(Item::action("ui.folderVisible", "Show/Hide", "eye").key("V").with(json!({ "key": format!("{scope}/{folder}") })));v.push(Item::action("ui.showAll", "Show All", "eye"));v}@@ -205,16 +209,10 @@ pub fn origin_items(app: &SolveApp) -> Vec<Item> {]}-/// Show or hide everything in a component folder.-pub fn toggle_folder(app: &mut SolveApp, component: u64, folder: &str) {- if folder == "sketches" {- app.ui.show_sketches = !app.ui.show_sketches;- return;- }- let all = entries(app, component, folder);- let any = all.iter().any(|e| e.visible);- let refs: Vec<&Entry> = all.iter().collect();- set_visible(app, folder, &refs, !any);+/// Show or hide a browser folder or group itself, by tree key (`c0/bodies`, `o:4/g7`): its+/// items keep their own state, and hiding or showing them never changes it.+pub fn toggle_folder(app: &mut SolveApp, key: &str) {+ let _ = app.run("browser.visibility", json!({ "tree_folders": [key], "visible": app.session.folder_hidden(key) }));}/// Selected browser items of the folder of a body or sketch, when more than one (for Group@@ -266,6 +264,8 @@ pub fn group_action(app: &mut SolveApp, action: &str, p: &Value) {const ROW_H: f32 = 22.0;const INDENT: f32 = 14.0;+/// Opacity of a dimmed row's icon (a hidden body, sketch, origin item, …).+const DIM_ICON_OPACITY: f32 = 0.4;/// One row's look.#[derive(Default)]@@ -329,7 +329,6 @@ pub(crate) fn draw_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {}let mut x = r.left() + 2.0 + row.depth as f32 * INDENT;let cy = r.center().y;- let ink = if row.dim { t.text_dim } else { t.icon };// The row is one widget: where a click lands decides what it does (the fold arrow with// padding, the eye, the radio, or the row itself), so a click on the arrow never also// selects the row or starts a drag.@@ -363,7 +362,8 @@ pub(crate) fn draw_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {// Eye.if let Some(vis) = row.eye {let er = Rect::from_center_size(pos2(x + 8.0, cy), vec2(15.0, 15.0));- icons::paint(ui.painter(), er, "eye", if vis { ink } else { t.border }, t.icon_fill, t.accent);+ // A closed eye, or the eye of a faded row, draws faint like the row's icon.+ icons::paint_icon(ui.painter(), er, "eye", if vis && !row.dim { 1.0 } else { DIM_ICON_OPACITY });if !vis {ui.painter().line_segment([er.left_bottom() + vec2(2.0, -2.0), er.right_top() + vec2(-2.0, 2.0)], Stroke::new(1.4, t.text_dim));}@@ -383,7 +383,9 @@ pub(crate) fn draw_row(ui: &mut egui::Ui, id: egui::Id, row: &Row) -> RowResp {}if !row.icon.is_empty() {let ir = Rect::from_min_size(pos2(x, cy - 8.0), vec2(16.0, 16.0));- icons::paint(ui.painter(), ir, row.icon, ink, if row.dim { t.panel_header } else { t.icon_fill }, t.accent);+ // Icons are full-colour images (a tint colour only sets their opacity): a hidden or+ // faded row draws its icon faint, like its label.+ icons::paint_icon(ui.painter(), ir, row.icon, if row.dim { DIM_ICON_OPACITY } else { 1.0 });x += 21.0;}let col = row.color.unwrap_or(if row.dim { t.text_dim } else { t.text });@@ -878,7 +880,15 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {let r = draw_row(ui,ui.id().with(key),- &Row { depth, fold: Some(open), eye: Some(app.ui.show_origin), icon: "origin", label: "Origin", ..Default::default() },+ &Row {+ depth,+ fold: Some(open),+ eye: Some(app.ui.show_origin),+ icon: "origin",+ label: "Origin",+ dim: !app.ui.show_origin,+ ..Default::default()+ },);if r.fold || r.clicked {toggle(app, key, false);@@ -912,7 +922,8 @@ fn origin_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {let r = draw_row(ui,ui.id().with(("o", k)),- &Row { depth: depth + 1, eye: Some(visible), icon, label, selected, dim: !app.ui.show_origin, ..Default::default() },+ // Faded when hidden itself or with the whole Origin.+ &Row { depth: depth + 1, eye: Some(visible), icon, label, selected, dim: !visible || !app.ui.show_origin, ..Default::default() },);if r.eye {if visible {@@ -1013,25 +1024,31 @@ pub fn view_items(app: &SolveApp, name: &str) -> Vec<Item> {/// to hide and show it, a double-click to edit it and a menu to delete it (#822).fn analysis_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut Actions) {if app.session.section.is_some() {- // A section made (or remade) while an older one was hidden replaces it.+ // A section made (or remade) while an older one was hidden replaces it, shown.app.tree.hidden_section = None;+ app.tree.analysis_hidden = false;+ app.tree.section_hidden = false;}- let visible = app.session.section.is_some();- if !visible && app.tree.hidden_section.is_none() {+ if app.session.section.is_none() && app.tree.hidden_section.is_none() {+ app.tree.analysis_hidden = false;+ app.tree.section_hidden = false;return;}+ // Each eye is its own: the folder's never follows the section's, nor the other way round.+ let (folder_shown, section_shown) = (!app.tree.analysis_hidden, !app.tree.section_hidden);let key = "analysis";let open = is_open(app, key, true);let r = draw_row(ui,ui.id().with(key),- &Row { depth, fold: Some(open), eye: Some(visible), icon: "folder", label: "Analysis", ..Default::default() },+ &Row { depth, fold: Some(open), eye: Some(folder_shown), icon: "folder", label: "Analysis", dim: !folder_shown, ..Default::default() },);if r.fold || r.clicked {toggle(app, key, true);}if r.eye {- set_section_visible(app, !visible);+ app.tree.analysis_hidden = folder_shown;+ sync_section(app);}if !open {return;@@ -1039,10 +1056,17 @@ fn analysis_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mutlet r = draw_row(ui,ui.id().with("section_analysis"),- &Row { depth: depth + 1, eye: Some(visible), icon: "section", label: "Section Analysis", dim: !visible, ..Default::default() },+ &Row {+ depth: depth + 1,+ eye: Some(section_shown),+ icon: "section",+ label: "Section Analysis",+ dim: !section_shown || !folder_shown,+ ..Default::default()+ },);if r.eye {- set_section_visible(app, !visible);+ set_section_shown(app, !section_shown);}if r.double {app.start("inspect.section");@@ -1052,6 +1076,19 @@ fn analysis_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut}}+/// Show or hide the Section Analysis itself (its eye): a hidden Analysis folder still keeps it+/// off.+pub fn set_section_shown(app: &mut SolveApp, shown: bool) {+ app.tree.section_hidden = !shown;+ sync_section(app);+}++/// The section is on while both the Analysis folder and the section itself are shown.+fn sync_section(app: &mut SolveApp) {+ let on = !app.tree.analysis_hidden && !app.tree.section_hidden;+ set_section_visible(app, on);+}+/// Hide the Section Analysis (keeping its plane to show it again) or show the hidden one.pub fn set_section_visible(app: &mut SolveApp, visible: bool) {if visible {@@ -1070,7 +1107,7 @@ pub fn set_section_visible(app: &mut SolveApp, visible: bool) {/// The menu of the Section Analysis row.pub fn section_items(app: &SolveApp) -> Vec<Item> {- let visible = app.session.section.is_some();+ let visible = !app.tree.section_hidden;vec![Item::action("ui.editSection", "Edit Section Analysis", "section"),Item::sep(),@@ -1080,6 +1117,9 @@ pub fn section_items(app: &SolveApp) -> Vec<Item> {]}+/// The Canvases folder's tree key (`Visibility::hidden_folders`).+pub const CANVASES: &str = "c0/canvases";+/// The Canvases folder (reference images) with an eye per canvas.fn canvas_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut Actions) {let canvases: Vec<(u64, String, bool)> = app.session.doc.canvases.iter().map(|c| (c.id, c.name.clone(), c.visible)).collect();@@ -1088,16 +1128,18 @@ fn canvas_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut A}let key = "canvases";let open = is_open(app, key, true);- let any = canvases.iter().any(|c| c.2);- let r =- draw_row(ui, ui.id().with(key), &Row { depth, fold: Some(open), eye: Some(any), icon: "folder", label: "Canvases", ..Default::default() });+ // The folder's eye is its own: each canvas keeps its eye while the folder hides them all.+ let shown = !app.session.folder_hidden(CANVASES);+ let r = draw_row(+ ui,+ ui.id().with(key),+ &Row { depth, fold: Some(open), eye: Some(shown), icon: "folder", label: "Canvases", dim: !shown, ..Default::default() },+ );if r.fold || r.clicked {toggle(app, key, true);}if r.eye {- for (id, _, _) in &canvases {- let _ = app.run("canvas.edit", json!({ "canvas": id, "visible": !any }));- }+ toggle_folder(app, CANVASES);}if !open {return;@@ -1107,7 +1149,16 @@ fn canvas_rows(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize, acts: &mut Alet r = draw_row(ui,ui.id().with(("canvas", id)),- &Row { depth: depth + 1, eye: Some(visible), icon: "canvas", label: &name, name: true, selected, dim: !visible, ..Default::default() },+ &Row {+ depth: depth + 1,+ eye: Some(visible),+ icon: "canvas",+ label: &name,+ name: true,+ selected,+ dim: !visible || !shown,+ ..Default::default()+ },);if r.eye {let _ = app.run("canvas.edit", json!({ "canvas": id, "visible": !visible }));@@ -1319,7 +1370,7 @@ fn entries(app: &SolveApp, comp: u64, folder: &str) -> Vec<Entry> {row_key: format!("b:{}", b.name),label: b.name.clone(),icon: "body",- visible: app.session.body_visible(&b.name),+ 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,locked: app.ui.locked_bodies.contains(&b.name),@@ -1467,7 +1518,7 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Optione.sel = Some(Sel::Body { name: body.world.clone() });e.target = Some(Target::Body { name: body.world.clone() });e.bodies = vec![body.world.clone()];- e.visible = app.session.body_visible(&body.world);+ e.visible = !app.session.visibility.hidden_bodies.contains(&body.world);e.selected = app.session.selection.contains(&Sel::Body { name: body.world.clone() });e.row_key = format!("b:{}", body.world);} else {@@ -1491,28 +1542,27 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Option}}let open = is_open(app, &key, true);- let any_visible = if folder == "sketches" { app.ui.show_sketches } else { all.iter().any(|e| e.visible) };+ // The folder's eye is its own: hiding it hides its items without changing theirs, and its+ // items never change it. It and everything in it fade while it or a placement above is+ // hidden, whatever their own eyes say.+ let shown = !app.session.folder_hidden(&key);+ let folder_faded = !shown || path.is_some_and(|p| !app.session.occurrence_visible(p));let r = draw_row(ui,ui.id().with(&key),- &Row { depth, fold: Some(open), eye: Some(any_visible), icon: "folder", label: folder_label(folder), ..Default::default() },+ &Row { depth, fold: Some(open), eye: Some(shown), icon: "folder", label: folder_label(folder), dim: folder_faded, ..Default::default() },);if r.fold || r.clicked {toggle(app, &key, true);}if r.eye {- if folder == "sketches" {- app.ui.show_sketches = !app.ui.show_sketches;- } else {- let refs: Vec<&Entry> = all.iter().collect();- set_visible(app, folder, &refs, !any_visible);- }+ toggle_folder(app, &key);}if r.hovered {acts.hover_bodies = all.iter().flat_map(|e| e.bodies.clone()).collect();}if let Some(p) = r.secondary {- acts.menu = Some((p, Target::Folder { component: comp, folder: fstatic.to_string() }));+ acts.menu = Some((p, Target::Folder { component: comp, folder: fstatic.to_string(), scope: prefix.clone() }));}// Dropping on the folder row takes items out of their groups, to the end.if let Some(resp) = &r.resp@@ -1528,7 +1578,8 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Optionfor (g, items) in &groups {let gkey = format!("{prefix}/g{}", g.id);let gopen = is_open(app, &gkey, true);- let gvis = items.is_empty() || items.iter().any(|e| e.visible);+ let gshown = !app.session.folder_hidden(&gkey);+ let group_faded = folder_faded || !gshown;let label = format!("{} ({})", g.name, items.len());let r = draw_row(ui,@@ -1536,11 +1587,11 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Option&Row {depth: depth + 1,fold: Some(gopen),- eye: Some(gvis),+ eye: Some(gshown),icon: "folder",label: &label,name: true,- dim: !gvis,+ dim: group_faded,..Default::default()},);@@ -1548,14 +1599,13 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Optiontoggle(app, &gkey, true);}if r.eye {- let refs: Vec<&Entry> = items.iter().collect();- set_visible(app, folder, &refs, !gvis);+ toggle_folder(app, &gkey);}if r.hovered {acts.hover_bodies = items.iter().flat_map(|e| e.bodies.clone()).collect();}if let Some(p) = r.secondary {- acts.menu = Some((p, Target::Group { id: g.id }));+ acts.menu = Some((p, Target::Group { id: g.id, scope: prefix.clone() }));}if let Some(resp) = &r.resp&& let Some(d) = drop_target(ui, resp, |d: &Drag| d.comp == comp && d.folder == fstatic, DropMark::Box)@@ -1564,12 +1614,12 @@ fn folder_rows_at(app: &mut SolveApp, ui: &mut egui::Ui, comp: u64, path: Option}if gopen {for e in items {- entry_row(app, ui, comp, path, fstatic, e, depth + 2, Some(g.id), &loose_keys, acts);+ entry_row(app, ui, comp, path, fstatic, e, depth + 2, Some(g.id), &loose_keys, group_faded, acts);}}}for e in &loose {- entry_row(app, ui, comp, path, fstatic, e, depth + 1, None, &loose_keys, acts);+ entry_row(app, ui, comp, path, fstatic, e, depth + 1, None, &loose_keys, folder_faded, acts);}let _ = t;}@@ -1586,6 +1636,8 @@ fn entry_row(depth: usize,group: Option<u64>,loose: &[String],+ // A placement or folder above is hidden: the row fades, its eye stays its own.+ parent_hidden: bool,acts: &mut Actions,) {app.tree.order.push(e.row_key.clone());@@ -1605,7 +1657,7 @@ fn entry_row(label: &e.label,name: true,selected: e.selected,- dim: !e.visible,+ dim: !e.visible || parent_hidden,color: e.color,badges,..Default::default()@@ -1654,7 +1706,7 @@ fn entry_row(acts.menu = Some((p, t));}if let Some(sketch) = pattern_sketch.filter(|_| patterns_open) {- crate::sketch_pattern_tree::rows(app, ui, sketch, depth + 1, "browser", path.map(|path| (comp, path)));+ crate::sketch_pattern_tree::rows(app, ui, sketch, depth + 1, "browser", path.map(|path| (comp, path)), !e.visible || parent_hidden);}let Some(resp) = &r.resp else { return };// Drag: the selected items of this folder when this one is selected, else just this one.@@ -1901,7 +1953,12 @@ pub fn dims_overlay(app: &SolveApp, ctx: &egui::Context) {let proj = crate::viewport::projection(app, rect);let painter = ctx.layer_painter(egui::LayerId::background()).with_clip_rect(rect);let st = app.session.world_state();- for id in app.ui.shown_dims.iter().filter(|id| app.session.active_sketch != Some(**id) && sketch_visible(app, **id)) {+ for id in app+ .ui+ .shown_dims+ .iter()+ .filter(|id| app.session.active_sketch != Some(**id) && solidcraft_engine::view::sketch_drawn(&app.session, **id, app.ui.show_sketches))+ {let Some(ss) = st.sketch(*id) else { continue };let sk = &ss.sketch;let to = |p: Vec2| proj.to_screen(ss.plane.to_world(p));diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rsindex db0ad1ad44..d916376997 100644--- a/crates/ui-egui/src/context_menu.rs+++ b/crates/ui-egui/src/context_menu.rs@@ -47,9 +47,10 @@ pub enum Target {Occurrence {path: Vec<u64>,},- /// A browser group of items.+ /// A browser group of items, under the design (`scope` `c0`) or a placement (`o:<path>`).Group {id: u64,+ scope: String,},/// The Origin folder.Origin,@@ -78,10 +79,12 @@ pub enum Target {},/// The Section Analysis in the browser's Analysis folder.Section,- /// A component's Bodies, Sketches or Construction folder.+ /// A component's Bodies, Sketches or Construction folder, under the design (`scope` `c0`)+ /// or a placement (`o:<path>`).Folder {component: u64,folder: String,+ scope: String,},}@@ -265,7 +268,7 @@ pub fn target_bodies(app: &SolveApp, target: &Target) -> Vec<String> {Target::Body { name } => vec![name.clone()],Target::Component { id } => component_bodies(app, *id),Target::Occurrence { path } => app.session.occurrence_bodies(path, true).unwrap_or_default(),- Target::Group { id } => crate::browser::group_bodies(app, *id),+ Target::Group { id, .. } => crate::browser::group_bodies(app, *id),Target::Sketch { .. }| Target::Plane { .. }| Target::OriginPlane { .. }@@ -330,8 +333,8 @@ pub fn items(app: &SolveApp, target: &Target) -> Vec<Item> {Target::OriginPlane { name } => origin_plane_items(app, name),Target::Component { id } => component_items(app, *id),Target::Occurrence { path } => occurrence_items(app, path),- Target::Group { id } => crate::browser::group_items(app, *id),- Target::Folder { component, folder } => crate::browser::folder_items(app, *component, folder),+ Target::Group { id, scope } => crate::browser::group_items(app, *id, scope),+ Target::Folder { component, folder, scope } => crate::browser::folder_items(app, *component, folder, scope),Target::Canvas { id } => crate::browser::canvas_items(app, *id),Target::Origin => crate::browser::origin_items(app),Target::NamedViews => vec![act("ui.newView", "New Named View", "perspective")],@@ -470,7 +473,9 @@ fn viewport_items(app: &SolveApp) -> Vec<Item> {v.push(act("ui.fit", "Fit", "fit"));v.push(act("ui.home", "Home View", "home"));v.push(Item::sep());- let anything_hidden = !app.session.visibility.hidden_bodies.is_empty() || !app.session.visibility.hidden_sketches.is_empty();+ let anything_hidden = !app.session.visibility.hidden_bodies.is_empty()+ || !app.session.visibility.hidden_sketches.is_empty()+ || !app.session.visibility.hidden_folders.is_empty();v.push(act("ui.showAll", "Show All", "eye").on(anything_hidden));v.push(act("ui.showAll", "Unisolate", "").on(!app.session.visibility.hidden_bodies.is_empty()));v.push(Item::sep());@@ -902,6 +907,9 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {"ui.showAll" => {let _ = app.run("browser.visibility", json!({"folder":"bodies", "visible":true}));app.session.visibility.hidden_sketches.clear();+ // Hidden folders and groups too, so everything really shows.+ app.session.visibility.hidden_folders.clear();+ app.ui.show_sketches = true;}"ui.isolate" => {app.session.visibility.hidden_bodies =@@ -987,7 +995,7 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {drop(app.run("inspect.section", json!({"clear": true})));}"ui.editSection" => app.start("inspect.section"),- "ui.sectionVisible" => crate::browser::set_section_visible(app, p.get("visible").and_then(Value::as_bool).unwrap_or(true)),+ "ui.sectionVisible" => crate::browser::set_section_shown(app, p.get("visible").and_then(Value::as_bool).unwrap_or(true)),"ui.fit" => app.animate_view("fit"),"ui.home" => app.animate_view("home"),// One command for the whole selection: all fixed unless all already are.@@ -1088,8 +1096,8 @@ pub fn run_item(app: &mut SolveApp, item: &Item, at: Pos2) {}}"ui.folderVisible" => {- if let Some(f) = p.get("folder").and_then(Value::as_str) {- crate::browser::toggle_folder(app, id_of(&p, "component").unwrap_or(0), f);+ if let Some(key) = p.get("key").and_then(Value::as_str) {+ crate::browser::toggle_folder(app, key);}}"ui.originAll" => {diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 0ed0b48f49..7157f20a30 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -330,12 +330,13 @@ fn dispatch(app: &mut SolveApp, ctx: &egui::Context, method: &str, p: &Value) ->}"ui.set" => {// What is hidden lives in the session (`browser.visibility`); `ui.set` still sets it.- const VIS: [(&str, &str); 5] = [+ const VIS: [(&str, &str); 6] = [("hiddenBodies", "hidden_bodies"),("hiddenOrigin", "hidden_origin"),("hiddenSketches", "hidden_sketches"),("shownSketches", "shown_sketches"),("hiddenJoints", "hidden_joints"),+ ("hiddenFolders", "hidden_folders"),];let mut cur = serde_json::to_value(&app.ui).unwrap_or(json!({}));let mut vis = serde_json::to_value(&app.session.visibility).unwrap_or(json!({}));diff --git a/crates/ui-egui/src/dialogs_assembly.rs b/crates/ui-egui/src/dialogs_assembly.rsindex 75136aec07..493918224b 100644--- a/crates/ui-egui/src/dialogs_assembly.rs+++ b/crates/ui-egui/src/dialogs_assembly.rs@@ -1297,18 +1297,18 @@ pub fn browser_joints(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {return;}// Drawn like every other browser node (its fold, eye and rows publish `fold:Joints`,- // `eye:Joints`, `row:<name>`). The folder's eye hides every joint's glyph, or shows them- // all when none is shown.+ // `eye:Joints`, `row:<name>`). The folder's eye is its own: hiding it hides every joint's+ // glyph without changing each joint's eye.let key = "c0/joints";let open = is_open(app, key, true);- let any_visible = joints.iter().any(|j| app.session.joint_visible(j.0));+ let folder_shown = !app.session.folder_hidden(key);let r = draw_row(ui,ui.id().with(key),- &Row { depth, fold: Some(open), eye: Some(any_visible), icon: "folder", label: "Joints", ..Default::default() },+ &Row { depth, fold: Some(open), eye: Some(folder_shown), icon: "folder", label: "Joints", dim: !folder_shown, ..Default::default() },);if r.eye {- let _ = app.run("browser.visibility", json!({ "folder": "joints", "visible": !any_visible }));+ crate::browser::toggle_folder(app, key);} else if r.fold || r.clicked {toggle(app, key, true);}@@ -1329,7 +1329,7 @@ pub fn browser_joints(app: &mut SolveApp, ui: &mut egui::Ui, depth: usize) {label: &name,name: true,selected,- dim: suppressed || !visible,+ dim: suppressed || !visible || !folder_shown,..Default::default()},);@@ -1472,7 +1472,7 @@ pub fn drawn_joints(app: &SolveApp) -> Vec<(u64, bool)> {.iter().filter_map(|j| {let picked = app.tree.picked_joints.contains(&j.id);- (picked || app.session.joint_visible(j.id)).then_some((j.id, picked))+ (picked || app.session.joint_drawn(j.id)).then_some((j.id, picked))}).collect()}diff --git a/crates/ui-egui/src/i18n_menu_tests.rs b/crates/ui-egui/src/i18n_menu_tests.rsindex 0b486dcf82..8640392616 100644--- a/crates/ui-egui/src/i18n_menu_tests.rs+++ b/crates/ui-egui/src/i18n_menu_tests.rs@@ -54,13 +54,13 @@ fn take(app: &SolveApp, out: &mut BTreeSet<String>) {for id in &components {take_items(out, &context_menu::items(app, &Target::Component { id: *id }));for folder in ["bodies", "sketches", "construction"] {- take_items(out, &context_menu::items(app, &Target::Folder { component: *id, folder: folder.to_string() }));- take_items(out, &browser::folder_items(app, *id, folder));+ take_items(out, &context_menu::items(app, &Target::Folder { component: *id, folder: folder.to_string(), scope: "c0".into() }));+ take_items(out, &browser::folder_items(app, *id, folder, "c0"));}}for id in &groups {- take_items(out, &context_menu::items(app, &Target::Group { id: *id }));- take_items(out, &browser::group_items(app, *id));+ take_items(out, &context_menu::items(app, &Target::Group { id: *id, scope: "c0".into() }));+ take_items(out, &browser::group_items(app, *id, "c0"));}for spec in solidcraft_engine::command_specs().iter() {let target = Target::ToolbarCommand { id: spec.id.to_string() };diff --git a/crates/ui-egui/src/joint_browser_tests.rs b/crates/ui-egui/src/joint_browser_tests.rsindex b4ca0a63f2..603c8daef9 100644--- a/crates/ui-egui/src/joint_browser_tests.rs+++ b/crates/ui-egui/src/joint_browser_tests.rs@@ -46,7 +46,7 @@ fn drawn(h: &Harness) -> Vec<(u64, bool)> {}#[test]-fn eyes_hide_and_show_joints_and_the_folder_toggles_all() {+fn eyes_hide_and_show_joints_and_the_folder_keeps_their_state() {let mut h = harness();let (hinge, glue) = (id(&h, "Hinge"), id(&h, "Glue"));assert_eq!(drawn(&h), [(hinge, false), (glue, false)], "every joint draws by default");@@ -56,11 +56,20 @@ fn eyes_hide_and_show_joints_and_the_folder_toggles_all() {assert_eq!(drawn(&h), [(glue, false)], "a hidden joint isn't drawn");assert!(crate::scenario::handle_at("row:Hinge").is_some(), "a hidden joint stays listed");- // The folder's eye: some shown → all hidden; none shown → all shown.+ // The folder's eye is its own: hiding it hides every glyph without changing a joint's+ // eye, and showing it brings back what was shown before (Hinge stays hidden).click(&mut h, "eye:Joints");assert!(drawn(&h).is_empty());+ assert!(!h.app.session.joint_visible(hinge) && h.app.session.joint_visible(glue));+ click(&mut h, "eye:Hinge");+ assert!(drawn(&h).is_empty(), "a joint shown in a hidden folder stays undrawn");+ assert!(h.app.session.folder_hidden("c0/joints"), "a joint's eye doesn't change the folder's");+ click(&mut h, "eye:Hinge");click(&mut h, "eye:Joints");- assert_eq!(drawn(&h), [(hinge, false), (glue, false)]);+ assert_eq!(drawn(&h), [(glue, false)]);+ // Hiding every joint leaves the folder shown.+ click(&mut h, "eye:Glue");+ assert!(!h.app.session.folder_hidden("c0/joints"));}#[test]diff --git a/crates/ui-egui/src/menu_tests.rs b/crates/ui-egui/src/menu_tests.rsindex 405c315700..7a0a3cf208 100644--- a/crates/ui-egui/src/menu_tests.rs+++ b/crates/ui-egui/src/menu_tests.rs@@ -286,18 +286,23 @@ fn folder_and_group_menus_make_rename_and_drop_groups() {let names: Vec<String> = app.session.model.state().bodies.iter().map(|b| b.name.clone()).collect();let items: Vec<_> = names.iter().map(|n| json!({"type": "body", "name": n})).collect();app.run("select.set", json!({ "items": items })).unwrap();- let folder = Target::Folder { component: 0, folder: "bodies".into() };+ let folder = Target::Folder { component: 0, folder: "bodies".into(), scope: "c0".into() };act(&mut app, &folder, "Group Selected");let g = app.session.doc.browser_groups[0].clone();assert_eq!(g.items.len(), 2);// A body's menu offers grouping too while several are selected.assert!(context_menu::items(&app, &Target::Body { name: names[0].clone() }).iter().any(|i| i.label == "Group Selected"));- let t = Target::Group { id: g.id };+ let t = Target::Group { id: g.id, scope: "c0".into() };act(&mut app, &t, "Rename");assert!(context_menu::finish_rename(&mut app, Some("Parts"), true));assert_eq!(app.session.doc.browser_groups[0].name, "Parts");+ // Show/Hide hides the group itself: its bodies keep their own state but aren't drawn.act(&mut app, &t, "Show/Hide");- assert_eq!(app.session.visibility.hidden_bodies.len(), 2);+ assert!(app.session.visibility.hidden_bodies.is_empty());+ assert!(app.session.folder_hidden(&format!("c0/g{}", g.id)));+ assert!(g.items.iter().all(|b| !app.session.body_visible(b)));+ act(&mut app, &t, "Show/Hide");+ assert!(g.items.iter().all(|b| app.session.body_visible(b)));act(&mut app, &t, "Ungroup");assert!(app.session.doc.browser_groups.is_empty());act(&mut app, &folder, "New Group");@@ -484,7 +489,7 @@ fn menus_follow_fusion_order() {"Find in Timeline",],);- let folder = context_menu::items(&app, &Target::Folder { component: 0, folder: "bodies".into() });+ let folder = context_menu::items(&app, &Target::Folder { component: 0, folder: "bodies".into(), scope: "c0".into() });order(&folder, &["Create Components from Bodies", "New Group", "Show/Hide", "Show All"]);let origin = context_menu::items(&app, &Target::Origin);order(&origin, &["Show/Hide", "Show All", "Hide Planes", "Hide Axes"]);diff --git a/crates/ui-egui/src/ref_images.rs b/crates/ui-egui/src/ref_images.rsindex 4916a8c7b1..f4f3c33e22 100644--- a/crates/ui-egui/src/ref_images.rs+++ b/crates/ui-egui/src/ref_images.rs@@ -69,7 +69,7 @@ fn forget_removed(app: &SolveApp) {pub fn gpu_images(app: &SolveApp) -> Vec<GpuImage> {forget_removed(app);let doc = &app.session.doc;- if doc.canvases.is_empty() {+ if doc.canvases.is_empty() || app.session.folder_hidden(crate::browser::CANVASES) {return Vec::new();}let (vals, _) = doc.param_values();@@ -109,7 +109,7 @@ pub fn show(app: &SolveApp, ui: &egui::Ui, painter: &egui::Painter, proj: &Proj)}forget_removed(app);let doc = &app.session.doc;- if doc.canvases.is_empty() {+ if doc.canvases.is_empty() || app.session.folder_hidden(crate::browser::CANVASES) {return;}let (vals, _) = doc.param_values();diff --git a/crates/ui-egui/src/section_browser_tests.rs b/crates/ui-egui/src/section_browser_tests.rsindex ca84efacdf..4ba4adfd09 100644--- a/crates/ui-egui/src/section_browser_tests.rs+++ b/crates/ui-egui/src/section_browser_tests.rs@@ -52,9 +52,17 @@ fn the_eye_hides_and_shows_the_section_and_delete_removes_it() {let back = h.app.session.section.expect("the eye turns it back on");assert!((back.0 - section.0).len() < 1e-9 && (back.1 - section.1).len() < 1e-9, "the same plane: {back:?} vs {section:?}");- // The folder's eye does the same.+ // The folder's eye is its own: hiding it turns the section off without changing the+ // section's eye, and hiding the section doesn't change the folder's.click(&mut h, "eye:Analysis");assert_eq!(h.app.session.section, None);+ assert!(h.app.tree.analysis_hidden && !h.app.tree.section_hidden);+ menu(&mut h, "Show/Hide");+ assert!(h.app.session.section.is_none() && h.app.tree.section_hidden, "the menu hides the section itself");+ assert!(h.app.tree.analysis_hidden, "the section's eye doesn't change the folder's");+ click(&mut h, "eye:Analysis");+ assert_eq!(h.app.session.section, None, "the section was hidden on its own meanwhile");+ assert!(!h.app.tree.analysis_hidden);menu(&mut h, "Show/Hide");assert!(h.app.session.section.is_some(), "Show/Hide in the menu brings it back");diff --git a/crates/ui-egui/src/sketch_pattern_tree.rs b/crates/ui-egui/src/sketch_pattern_tree.rsindex 09c2cbea58..180397f053 100644--- a/crates/ui-egui/src/sketch_pattern_tree.rs+++ b/crates/ui-egui/src/sketch_pattern_tree.rs@@ -14,7 +14,8 @@ pub(crate) fn has_patterns(app: &SolveApp, sketch: u64) -> bool {/// Shared by the parts browser and the vertical feature history. The stored document is the/// source, so rolled-back sketches retain their children without showing preview-only copies.-pub(crate) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, sketch: u64, depth: usize, scope: &str, occurrence: Option<(u64, &[u64])>) {+/// `dim`: the sketch is hidden (or a placement above it), so its patterns fade with it.+pub(crate) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, sketch: u64, depth: usize, scope: &str, occurrence: Option<(u64, &[u64])>, dim: bool) {let patterns: Vec<_> = app.session.doc.sketch(sketch).map(|sk| sk.patterns.clone()).unwrap_or_default();for pattern in patterns {let (name, icon) = match pattern.kind {@@ -41,7 +42,7 @@ pub(crate) fn rows(app: &mut SolveApp, ui: &mut egui::Ui, sketch: u64, depth: uslet response = draw_row(ui,ui.id().with(("sketch_pattern", sketch, &pattern.id)),- &Row { depth, icon, label: &label, name: true, selected, ..Default::default() },+ &Row { depth, icon, label: &label, name: true, selected, dim, ..Default::default() },);if let Some(rect) = response.rect {crate::scenario::publish_handle(&format!("{scope}:sketch-pattern:{sketch}:{}", pattern.id), rect.center());diff --git a/crates/ui-egui/src/timeline_left.rs b/crates/ui-egui/src/timeline_left.rsindex fb70bbf79f..d9792ad233 100644--- a/crates/ui-egui/src/timeline_left.rs+++ b/crates/ui-egui/src/timeline_left.rs@@ -814,7 +814,7 @@ fn vertical_features(app: &mut SolveApp, ui: &mut egui::Ui) {});if has_patterns && patterns_open {let depth = group_id.map_or(1, |group| group_depth(&groups, group) + 2);- crate::sketch_pattern_tree::rows(app, ui, *id, depth, "timeline", None);+ crate::sketch_pattern_tree::rows(app, ui, *id, depth, "timeline", None, false);}previous_visible_group = group_id;}diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex 350681f774..ca076296f4 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -305,6 +305,7 @@ fn scene_key(app: &SolveApp) -> u64 {app.session.visibility.hidden_occurrences.hash(&mut h);app.session.visibility.hidden_sketches.hash(&mut h);app.session.visibility.shown_sketches.hash(&mut h);+ app.session.visibility.hidden_folders.hash(&mut h);app.ui.hidden_profiles.hash(&mut h);app.session.active_component.hash(&mut h);app.session.active_occurrence_path.hash(&mut h);@@ -942,10 +943,8 @@ pub fn origin_axes(app: &SolveApp) -> Vec<(&'static str, Vec3)> {/// past it either side), at least the origin axes' length around the axis's origin: (name,/// from, to).pub fn construction_axis_segments(app: &SolveApp) -> Vec<(String, Vec3, Vec3)> {- let axes: Vec<_> = solidcraft_engine::view::construction_axes(&app.session)- .into_iter()- .filter(|(_, n, _, _)| !app.session.visibility.hidden_origin.contains(n))- .collect();+ let axes: Vec<_> =+ solidcraft_engine::view::construction_axes(&app.session).into_iter().filter(|(_, n, _, _)| app.session.construction_visible(n)).collect();if axes.is_empty() {return Vec::new();}@@ -975,7 +974,7 @@ pub fn construction_axis_segments(app: &SolveApp) -> Vec<(String, Vec3, Vec3)> {pub fn construction_points(app: &SolveApp) -> Vec<(String, Vec3)> {solidcraft_engine::view::construction_points(&app.session).into_iter()- .filter(|(_, n, _)| !app.session.visibility.hidden_origin.contains(n))+ .filter(|(_, n, _)| app.session.construction_visible(n)).map(|(_, n, p)| (n, p)).collect()}@@ -985,7 +984,7 @@ pub fn construction_quads(app: &SolveApp) -> Vec<(String, Vec3, [Vec3; 4])> {let h = origin_size(app.cam.half_height()) * 1.2;solidcraft_engine::view::construction_planes(&app.session).into_iter()- .filter(|(_, n, _)| !app.session.visibility.hidden_origin.contains(n))+ .filter(|(_, n, _)| app.session.construction_visible(n)).map(|(_, name, pl)| {let (o, x, y) = (pl.origin, pl.x * h, pl.y * h);(name, pl.normal(), [o - x - y, o + x - y, o + x + y, o - x + y])@@ -1902,6 +1901,7 @@ fn highlight_geometry_key(app: &SolveApp) -> u64 {app.session.visibility.hidden_origin.hash(&mut h);app.session.visibility.hidden_bodies.hash(&mut h);app.session.visibility.hidden_occurrences.hash(&mut h);+ app.session.visibility.hidden_folders.hash(&mut h);h.finish()}diff --git a/docs/control-protocol.md b/docs/control-protocol.mdindex 855f752b01..1849342733 100644--- a/docs/control-protocol.md+++ b/docs/control-protocol.md@@ -122,7 +122,7 @@ labels; `prefs:measure_axis_distances` identifies the checkbox.| Method | Params | Notes ||---|---|---|| `ui.inspect` | — | UI state, pending file picker (`file_picker_busy`; compatibility alias `file_dialog_open`, no path), what is hidden (`visibility`: bodies, origin and construction items, sketches, joints (`hidden_joints`, joint ids); set it with the `browser.visibility` command), viewport rect, camera, active tool/dialog, the status line (`status`: text and whether it is an error), hover, renderer, timings, live preview (`active`, `busy`, `error`, `ms`, bodies it stands in for) |-| `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, …), and `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme |+| `ui.set` | any `UiState` field (`tab`, `perspective`, `showGrid`, `dark`, …), and `hiddenBodies`, `hiddenOrigin`, `hiddenSketches`, `shownSketches`, `hiddenJoints`, `hiddenFolders` (whole lists; `browser.visibility` changes single items) | `dark: false` switches to the light theme || `ui.view` | `view`: `front`, `back`, `top`, `bottom`, `left`, `right`, `iso`, `home`, `fit`; `animate` (bool, default false: snap) | || `ui.camera` | `target?`: `[x, y, z]` (mm), `yaw?`, `pitch?`, `roll?` (radians), `distance?` (mm), `fov?`, `up?`; `fit?`: `true`, `false` or `[occurrence id or name…]` (`root`: the bodies outside every component) | the viewport's orbit camera: it looks at `target` from `distance` away; `yaw` 0 looks along +Y (from the front), `pitch` is the elevation (±π/2: straight down or up), `roll` turns the image. Fields given are set first (the others keep their values), then `fit` frames the listed occurrences (or everything), keeping the direction. The reply, passed back, sets the same view again, so a framing can be stored and replayed. `fov` and `up` follow the perspective setting (`ui.set`) and the up axis preference (`ui.prefs`) and can't change here; a refused field changes nothing || `ui.start` | `command`, `params?` | like a toolbar click: starts the sketch tool or dialog for the command. `params` sets what the dialog opens on, and nothing runs until OK: `joint.drive` takes `joint` (id or name; without it, the joint picked in the browser, else the first joint that moves) and `values` (numbers in degrees or millimetres, or expressions); `motion.study` takes `study` (id or name), which opens that study to edit and chart. A command that takes no params is refused before it starts; a param the dialog doesn't take is refused and the dialog closes |