Skip to content

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

Browser: Turn Up Axis on a placement row asks that placement whether it can move (#8786) (#8788)

Christian Hammacher93d0298d254a
diff --git a/crates/ui-egui/src/context_menu.rs b/crates/ui-egui/src/context_menu.rs
index 3dca67bb7d..7c6fc5e81d 100644
--- a/crates/ui-egui/src/context_menu.rs
+++ b/crates/ui-egui/src/context_menu.rs
@@ -833,6 +833,8 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
entries.insert(0, Item::heading("Shared child: edits affect all copies of its parent"));
}
let bodies = app.session.occurrence_bodies(path, true).unwrap_or_default();
+ // The component's menu asks its first placement; this row may be another one.
+ let movable = !placement.grounded && app.session.held_by_rigid_group(placement.occurrence).is_none();
for item in &mut entries {
match item.id.as_str() {
"ui.activate" => {
@@ -846,11 +848,13 @@ fn occurrence_items(app: &SolveApp, path: &[u64]) -> Vec<Item> {
}
"ui.moveOccurrence" => {
item.params = Some(json!({"occurrence": placement.occurrence, "path": path}));
- item.enabled = !placement.grounded && app.session.held_by_rigid_group(placement.occurrence).is_none();
+ item.enabled = movable;
}
"ui.properties" => item.params = Some(json!({"occurrence": placement.occurrence, "path": path})),
"ui.turnUpAxis" => {
+ item.enabled = movable;
for child in &mut item.children {
+ child.enabled = movable;
if let Some(params) = child.params.as_mut() {
params["occurrence"] = json!(placement.occurrence);
}
diff --git a/crates/ui-egui/src/occurrence_ui_tests.rs b/crates/ui-egui/src/occurrence_ui_tests.rs
index 8ffbb2687a..54f98b5b2d 100644
--- a/crates/ui-egui/src/occurrence_ui_tests.rs
+++ b/crates/ui-egui/src/occurrence_ui_tests.rs
@@ -128,6 +128,24 @@ fn occurrence_second_row_selects_exact_path_and_menu_actions() {
assert_eq!(h.app.session.active_occurrence_path, Some(vec![second]));
}
+#[test]
+fn turn_up_axis_follows_the_placement_right_clicked() {
+ // Whichever placement comes first, a grounded one can't turn and a free one can.
+ let (mut h, _, first, second) = fixture();
+ let turns = |h: &Harness, occurrence: u64| {
+ let items = context_menu::items(&h.app, &Target::Occurrence { path: vec![occurrence] });
+ let turn = items.into_iter().find(|i| i.id == "ui.turnUpAxis").unwrap();
+ let children: Vec<_> = turn.children.iter().map(|c| (c.enabled, c.params.as_ref().unwrap()["occurrence"].as_u64())).collect();
+ (turn.enabled, children)
+ };
+ for (grounded, free) in [(first, second), (second, first)] {
+ h.app.run("occurrence.ground", json!({"occurrence": grounded, "grounded": true})).unwrap();
+ h.app.run("occurrence.ground", json!({"occurrence": free, "grounded": false})).unwrap();
+ assert_eq!(turns(&h, free), (true, vec![(true, Some(free)); 2]), "free placement {free}");
+ assert_eq!(turns(&h, grounded), (false, vec![(false, Some(grounded)); 2]), "grounded placement {grounded}");
+ }
+}
+
#[test]
fn occurrence_eye_and_fold_are_independent_and_survive_rename() {
let (mut h, component, first, second) = fixture();