SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Draw the view orthographic while a sketch is open (#1758)
Pablo López40bdc1132e85
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex dc6ecbc1d2..2a40f6e076 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -976,6 +976,12 @@ impl SolveApp {self.dialog.as_ref().is_some_and(|d| matches!(d.kind, dialogs::Kind::Sketch))}+ /// Is the view drawn in perspective? The perspective preference, except while a sketch is+ /// open: a sketch is drawn and measured on its plane, so the view is parallel (no foreshortening).+ pub fn perspective_view(&self) -> bool {+ self.ui.perspective && self.session.active_sketch.is_none()+ }+pub fn set_status(&mut self, s: impl Into<String>, error: bool) {self.status = Some((s.into(), now_ms(), error));}@@ -1077,7 +1083,7 @@ impl SolveApp {fn fitted_bounds(&self, mut cam: Camera, bounds: &solidcraft_engine::geom::Aabb3) -> Camera {if let Some(layout) = &self.viewport.layout {- return viewport_layout::fit_bounds(cam, bounds, layout, self.ui.perspective).unwrap_or(cam);+ return viewport_layout::fit_bounds(cam, bounds, layout, self.perspective_view()).unwrap_or(cam);}let previous = cam;cam.fit(bounds);diff --git a/crates/ui-egui/src/viewport.rs b/crates/ui-egui/src/viewport.rsindex cd0b69dbef..7256d223f5 100644--- a/crates/ui-egui/src/viewport.rs+++ b/crates/ui-egui/src/viewport.rs@@ -267,7 +267,7 @@ pub fn scene_radius(app: &SolveApp) -> f64 {pub fn projection(app: &SolveApp, rect: Rect) -> Proj {let mut cam = app.cam;- cam.fov = if app.ui.perspective { 0.6 } else { 0.0 };+ cam.fov = if app.perspective_view() { 0.6 } else { 0.0 };let aspect = rect.width() as f64 / rect.height().max(1.0) as f64;Proj { cam, vp: cam.view_proj(aspect, scene_radius(app)), rect }}@@ -1102,7 +1102,7 @@ pub(crate) fn pick_cached(app: &mut SolveApp, proj: &Proj, pos: Pos2) -> Vec<Hitapp.dialog.as_ref().and_then(|d| d.active_input()).map(|i| i.accept).hash(&mut h);app.session.visibility.hidden_bodies.hash(&mut h);app.session.visibility.hidden_occurrences.hash(&mut h);- app.ui.perspective.hash(&mut h);+ app.perspective_view().hash(&mut h);(proj.rect.width().to_bits(), proj.rect.height().to_bits()).hash(&mut h);crate::sketch_display::projection_key(proj, app.viewport.pixels_per_point()).hash(&mut h);let key = h.finish();@@ -5950,6 +5950,22 @@ mod grid_plane_tests {}}+ /// A sketch is drawn in a parallel view even when the preference asks for perspective; the+ /// preference comes back when the sketch is finished.+ #[test]+ fn an_open_sketch_is_drawn_orthographic() {+ let rect = Rect::from_min_size(Pos2::ZERO, egui::vec2(800.0, 600.0));+ let mut app = SolveApp::new(solidcraft_engine::Session::default(), crate::Services::default());+ app.ui.perspective = true;+ assert!(projection(&app, rect).cam.fov > 0.0);+ app.run("sketch.create", json!({"plane": "XZ"})).unwrap();+ assert!(!app.perspective_view());+ assert_eq!(projection(&app, rect).cam.fov, 0.0);+ app.finish_sketch();+ assert!(app.ui.perspective, "the preference is left alone");+ assert!(projection(&app, rect).cam.fov > 0.0);+ }+/// Create Sketch shows the Origin even when the browser hides it, and draws its planes/// through the model so a plane inside a body can be seen and picked; closing it restores/// the hidden, depth-tested Origin.