SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Perspective view as a command, so a 3D mouse button can switch it (#6143)
Jesper We8a28d1316114
diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rsindex 9b14dc4319..867007c92c 100644--- a/crates/engine/src/cmd/view_navigation.rs+++ b/crates/engine/src/cmd/view_navigation.rs@@ -15,6 +15,8 @@ CommandSpec::new("view.graphics_preset", "Graphics Preset", graphics_preset).icon("settings").noundo().doc_only().params("preset: performance|quality → preset, enabled, display_quality, supersampling, supersampling_adaptive; Quality: AO, Fine, adaptive 2x SSAA; Performance: no AO, Normal, no SSAA"),CommandSpec::new("view.ambient_occlusion", "Ambient Occlusion", ambient_occlusion).icon("settings").noundo().doc_only().params("enabled: bool → enabled; apply soft contact shading in the GPU viewport"),+CommandSpec::new("view.perspective", "Perspective view", perspective)+ .icon("perspective").noundo().doc_only().params("enabled: bool → enabled; draw the view in perspective, or orthographic when false; a sketch being edited is always shown orthographic"),CommandSpec::new("view.navigate", "Navigate View", navigate).icon("orbit").noundo()@@ -617,6 +619,11 @@ fn ambient_occlusion(_s: &mut Session, p: &Value) -> Result<Value> {Ok(json!({"enabled": enabled}))}+fn perspective(_s: &mut Session, p: &Value) -> Result<Value> {+ let enabled = p.get("enabled").and_then(Value::as_bool).ok_or_else(|| bad("view.perspective", "enabled must be a boolean"))?;+ Ok(json!({"enabled": enabled}))+}+#[cfg(test)]mod ambient_occlusion_tests {use super::*;@@ -633,6 +640,20 @@ mod ambient_occlusion_tests {assert_eq!(s.doc.to_json(), before);assert!(s.undo.is_empty());}++ #[test]+ fn perspective_is_a_display_setting_without_editing_design_or_history() {+ let mut s = Session::default();+ let before = s.doc.to_json();+ for enabled in [true, false] {+ assert_eq!(s.execute("view.perspective", &json!({"enabled": enabled})).unwrap(), json!({"enabled": enabled}));+ }+ for p in [json!({}), json!({"enabled": 1}), json!({"enabled": "true"}), json!({"enabled": null})] {+ assert!(s.execute("view.perspective", &p).is_err());+ }+ assert_eq!(s.doc.to_json(), before);+ assert!(s.undo.is_empty());+ }}/// One preset for contact shading, tessellation and supersampling. MSAA stays independent.diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 677bb31322..c84395d2e7 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -151,6 +151,7 @@ fn execute(app: &mut SolveApp, id: &str, params: Value) -> Result<Value, String>"view.layout"| "view.navigate"| "view.ambient_occlusion"+ | "view.perspective"| "view.graphics_preset"| "view.history_layout"| "browser.expand_all"diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 2fbb3be16f..996bc0b99d 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -919,6 +919,11 @@ impl SolveApp {self.preferences.timeline_collapsed = collapsed;}}+ if id == "view.perspective"+ && let Some(perspective) = v.get("enabled").and_then(Value::as_bool)+ {+ self.ui.perspective = perspective;+ }if matches!(id, "view.ambient_occlusion" | "view.graphics_preset") {self.preferences.ambient_occlusion = v.get("enabled").and_then(Value::as_bool).unwrap_or(false);if id == "view.graphics_preset" {@@ -1102,6 +1107,10 @@ impl SolveApp {let _ = self.run(id, json!({"enabled": !self.preferences.ambient_occlusion}));return;}+ if id == "view.perspective" {+ let _ = self.run(id, json!({"enabled": !self.ui.perspective}));+ return;+ }// Another command ends Edit Text (its dialog is not a feature edit to keep).sketch_text_move::cancel_drag(self);if sketch_text::editing(self) || self.dialog.as_ref().is_some_and(|d| matches!(d.kind, dialogs::Kind::TextMove(_))) {diff --git a/crates/ui-egui/src/space_mouse.rs b/crates/ui-egui/src/space_mouse.rsindex b5d2f13935..d1f0fe8197 100644--- a/crates/ui-egui/src/space_mouse.rs+++ b/crates/ui-egui/src/space_mouse.rs@@ -751,6 +751,25 @@ mod tests {assert_eq!((escapes(&raw), ctx.input(|i| i.modifiers.alt)), (0, true));}+ #[test]+ fn a_button_set_to_perspective_view_switches_it_once_per_press() {+ let device = "hid 046d:c62b";+ let mut app = app();+ app.space_mouse.device = Some(device.into());+ app.preferences.space_mouse_buttons.insert(device.into(), [(2, ButtonJob::Command("view.perspective".into()))].into());+ let ctx = window(true);+ let before = app.ui.perspective;+ press(&mut app, &ctx, 0b10, vec![]);+ assert_eq!(app.ui.perspective, !before);+ // Held, it doesn't switch again; the next press switches back.+ press(&mut app, &ctx, 0b10, vec![]);+ assert_eq!(app.ui.perspective, !before);+ press(&mut app, &ctx, 0, vec![]);+ press(&mut app, &ctx, 0b10, vec![]);+ assert_eq!(app.ui.perspective, before);+ assert!(app.session.undo.is_empty(), "a view setting, not an edit");+ }+/// The keyboard and a button hold the same modifier: it stays down until both let go, whichever/// lets go first, for each of Shift, Ctrl and Alt.#[test]