Skip to content

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

Construction planes, axes and points hide with their component's placement (#9790) (#9791)

Erlis Vidal6d89de1f5ace
diff --git a/crates/engine/src/construct_tests.rs b/crates/engine/src/construct_tests.rs
index 3fe9f2c49e..5fcfabdc18 100644
--- a/crates/engine/src/construct_tests.rs
+++ b/crates/engine/src/construct_tests.rs
@@ -585,3 +585,25 @@ fn offset_plane_through_a_point_follows_the_point() {
// A distance and a point at once is refused.
assert!(s.execute("construct.plane.offset", &json!({"base": "XY", "offset": 5, "through": {"vertex": [0, 0, 0]}})).is_err());
}
+
+/// Hiding the placement a component is shown at hides its construction geometry too, as it
+/// hides its bodies and sketches.
+#[test]
+fn hiding_an_occurrence_hides_its_construction_geometry() {
+ let mut s = Session::default();
+ run(&mut s, "component.create", json!({"name": "Part"}));
+ run(&mut s, "construct.plane.offset", json!({"base": "XY", "offset": "5 mm", "name": "Shelf"}));
+ run(&mut s, "construct.axis.two_planes", json!({"a": "XZ", "b": "YZ", "name": "Spine"}));
+ run(&mut s, "construct.point.three_planes", json!({"a": "XY", "b": "XZ", "c": "YZ", "name": "Pin"}));
+ let component = s.doc.features.iter().find(|f| f.name == "Shelf").map(|f| f.component).unwrap();
+ assert_ne!(component, 0);
+ let path = s.doc.first_path(component);
+ run(&mut s, "component.activate", json!({"component": 0}));
+ for name in ["Shelf", "Spine", "Pin"] {
+ assert!(s.construction_visible(name), "{name}");
+ }
+ run(&mut s, "browser.visibility", json!({"paths": [path], "visible": false}));
+ for name in ["Shelf", "Spine", "Pin"] {
+ assert!(!s.construction_visible(name), "{name} shows in a hidden placement");
+ }
+}
diff --git a/crates/engine/src/occurrences.rs b/crates/engine/src/occurrences.rs
index 8d6ac6cc79..1e00d50e30 100644
--- a/crates/engine/src/occurrences.rs
+++ b/crates/engine/src/occurrences.rs
@@ -590,29 +590,43 @@ impl Session {
})
}
+ /// The placement a sketch or construction feature is drawn at: the active one while its
+ /// component is being edited, else the component's first (empty for the design's own).
+ fn feature_path(&self, component: u64) -> Vec<u64> {
+ match &self.active_occurrence_path {
+ _ if component == 0 => Vec::new(),
+ Some(p) if self.active_component == component => p.clone(),
+ _ => self.doc.first_path(component),
+ }
+ }
+
+ /// Is the placement a sketch or construction feature is drawn at shown?
+ pub fn feature_placement_visible(&self, id: u64) -> bool {
+ if self.visibility.hidden_occurrences.is_empty() {
+ return true;
+ }
+ let component = self.doc.feature(id).map_or(0, |f| f.component);
+ component == 0 || self.occurrence_visible(&self.feature_path(component))
+ }
+
/// 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)?
+ /// is drawn at?
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())
+ self.item_folder_hidden(&Self::folder_scope(&self.feature_path(component)), 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?
+ /// its folder or a group it is in, nor by a hidden placement of its component?
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"),
+ Some(f) => self.feature_placement_visible(f.id) && !self.feature_folder_hidden(f.id, "construction"),
None => true,
}
}
diff --git a/crates/engine/src/view.rs b/crates/engine/src/view.rs
index 611151ba6d..85d4e1274e 100644
--- a/crates/engine/src/view.rs
+++ b/crates/engine/src/view.rs
@@ -828,7 +828,7 @@ pub fn sketch_shown(s: &Session, id: u64) -> bool {
if s.active_sketch == Some(id) || s.feature_edit_sketch == Some(id) {
return true;
}
- if !sketch_component_visible(s, id) || s.feature_folder_hidden(id, "sketches") {
+ if !s.feature_placement_visible(id) || s.feature_folder_hidden(id, "sketches") {
return false;
}
if s.doc
@@ -845,23 +845,6 @@ pub fn sketch_shown(s: &Session, id: u64) -> bool {
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 being
-/// edited, else the component's first)?
-fn sketch_component_visible(s: &Session, id: u64) -> bool {
- if s.visibility.hidden_occurrences.is_empty() {
- return true;
- }
- let component = s.doc.feature(id).map_or(0, |f| f.component);
- if component == 0 {
- return true;
- }
- let path = match &s.active_occurrence_path {
- Some(p) if s.active_component == component => p.clone(),
- _ => s.doc.first_path(component),
- };
- s.occurrence_visible(&path)
-}
-
/// Is a sketch used by a later feature? A sheet metal base or contour flange uses its sketch as
/// an Extrude does: shown, its lines lie on the sheet's edges and take the clicks meant for
/// them (#6804). So does a Hole at sketch points: shown, its points are drawn in the holes