diff --git a/assets/locales/en.json b/assets/locales/en.json index ab5761882..8f016107b 100644 --- a/assets/locales/en.json +++ b/assets/locales/en.json @@ -1004,13 +1004,20 @@ "cmd.timeline_suppress": "Suppress Feature", "cmd.view_ambient_occlusion": "Ambient Occlusion", "cmd.view_apply": "Restore Named View", + "cmd.view_back": "Back View", + "cmd.view_bottom": "Bottom View", "cmd.view_delete": "Delete Named View", + "cmd.view_front": "Front View", "cmd.view_graphics_preset": "Graphics Preset", + "cmd.view_isometric": "Isometric View", + "cmd.view_left": "Left View", "cmd.view_list": "List Named Views", "cmd.view_navigate": "Navigate View", "cmd.view_normal_to": "Normal to Selection", "cmd.view_rename": "Rename Named View", + "cmd.view_right": "Right View", "cmd.view_save": "New Named View", + "cmd.view_top": "Top View", "color.copy": "Click to copy color values", "color.edit": "Click to edit color", "color.gamma": "Showing color values in 0-255 gamma space", diff --git a/assets/locales/ja.json b/assets/locales/ja.json index a0a54ec2e..77df0d503 100644 --- a/assets/locales/ja.json +++ b/assets/locales/ja.json @@ -1004,13 +1004,20 @@ "cmd.timeline_suppress": "フィーチャーを抑制", "cmd.view_ambient_occlusion": "アンビエントオクルージョン", "cmd.view_apply": "名前付きビューを復元", + "cmd.view_back": "背面ビュー", + "cmd.view_bottom": "下面ビュー", "cmd.view_delete": "名前付きビューを削除", + "cmd.view_front": "正面ビュー", "cmd.view_graphics_preset": "グラフィックスプリセット", + "cmd.view_isometric": "等角ビュー", + "cmd.view_left": "左側面ビュー", "cmd.view_list": "名前付きビューを一覧表示", "cmd.view_navigate": "ビューナビゲーション", "cmd.view_normal_to": "選択アイテムに垂直", "cmd.view_rename": "名前付きビューの名前を変更", + "cmd.view_right": "右側面ビュー", "cmd.view_save": "新規名前付きビュー", + "cmd.view_top": "上面ビュー", "color.copy": "クリックして色の値をコピー", "color.edit": "クリックして色を編集", "color.gamma": "0〜255のガンマ空間で色の値を表示", diff --git a/assets/locales/pt-BR.json b/assets/locales/pt-BR.json index 57e5dfed3..be2ffc5c2 100644 --- a/assets/locales/pt-BR.json +++ b/assets/locales/pt-BR.json @@ -765,12 +765,19 @@ "cmd.timeline_suppress": "Suprimir recurso", "cmd.view_ambient_occlusion": "Oclusão de ambiente", "cmd.view_apply": "Restaurar vista nomeada", + "cmd.view_back": "Vista traseira", + "cmd.view_bottom": "Vista inferior", "cmd.view_delete": "Excluir vista nomeada", + "cmd.view_front": "Vista frontal", "cmd.view_graphics_preset": "Predefinição gráfica", + "cmd.view_isometric": "Vista isométrica", + "cmd.view_left": "Vista esquerda", "cmd.view_list": "Listar vistas nomeadas", "cmd.view_navigate": "Navegar na vista", "cmd.view_rename": "Renomear vista nomeada", + "cmd.view_right": "Vista direita", "cmd.view_save": "Nova vista nomeada", + "cmd.view_top": "Vista superior", "color.copy": "Clique para copiar os valores da cor", "color.edit": "Clique para editar a cor", "color.gamma": "Mostrando valores de cor no espaço gama 0-255", diff --git a/assets/locales/zh.json b/assets/locales/zh.json index ec2262293..444b7d754 100644 --- a/assets/locales/zh.json +++ b/assets/locales/zh.json @@ -1004,13 +1004,20 @@ "cmd.timeline_suppress": "抑制特征", "cmd.view_ambient_occlusion": "环境光遮蔽", "cmd.view_apply": "还原命名视图", + "cmd.view_back": "后视图", + "cmd.view_bottom": "仰视图", "cmd.view_delete": "删除命名视图", + "cmd.view_front": "前视图", "cmd.view_graphics_preset": "图形预设", + "cmd.view_isometric": "等轴测视图", + "cmd.view_left": "左视图", "cmd.view_list": "列出命名视图", "cmd.view_navigate": "导航视图", "cmd.view_normal_to": "垂直于所选面", "cmd.view_rename": "重命名命名视图", + "cmd.view_right": "右视图", "cmd.view_save": "新建命名视图", + "cmd.view_top": "俯视图", "color.copy": "单击复制颜色值", "color.edit": "单击编辑颜色", "color.gamma": "以 0–255 伽马空间显示颜色值", diff --git a/crates/engine/src/cmd/mod.rs b/crates/engine/src/cmd/mod.rs index af7a1d9d6..f872540a5 100644 --- a/crates/engine/src/cmd/mod.rs +++ b/crates/engine/src/cmd/mod.rs @@ -41,6 +41,7 @@ pub(crate) use features::{EdgeRefForm, edge_ref_form, sketch_key}; pub use features::{auto_operation, extrude_reach}; pub use sketch_modify::trim_piece; pub use view_dxf::sketch::exportable as view_dxf_exportable; +pub use view_navigation::standard_view; mod component_link; mod config; mod file; diff --git a/crates/engine/src/cmd/view_navigation.rs b/crates/engine/src/cmd/view_navigation.rs index 09b5a1cda..9b14dc431 100644 --- a/crates/engine/src/cmd/view_navigation.rs +++ b/crates/engine/src/cmd/view_navigation.rs @@ -24,7 +24,66 @@ CommandSpec::new("view.normal_to", "Normal to Selection", normal_to) .icon("camera") .noundo() .enabled(|s| normal_target(s).map(|_| ()).ok_or_else(|| "select a planar face or plane".into())) - .params("camera?: Camera (default: current session camera or home view) → camera; Look At the first selected planar face or plane, centered on the picked point; repeat while aligned to flip the side; preserves scale and projection")]; + .params("camera?: Camera (default: current session camera or home view) → camera; Look At the first selected planar face or plane, centered on the picked point; repeat while aligned to flip the side; preserves scale and projection"), +CommandSpec::new("view.front", "Front View", front).icon("camera").noundo().key("Ctrl+1").params(STANDARD_PARAMS), +CommandSpec::new("view.back", "Back View", back).icon("camera").noundo().key("Ctrl+2").params(STANDARD_PARAMS), +CommandSpec::new("view.left", "Left View", left).icon("camera").noundo().key("Ctrl+3").params(STANDARD_PARAMS), +CommandSpec::new("view.right", "Right View", right).icon("camera").noundo().key("Ctrl+4").params(STANDARD_PARAMS), +CommandSpec::new("view.top", "Top View", top).icon("camera").noundo().key("Ctrl+5").params(STANDARD_PARAMS), +CommandSpec::new("view.bottom", "Bottom View", bottom).icon("camera").noundo().key("Ctrl+6").params(STANDARD_PARAMS), +CommandSpec::new("view.isometric", "Isometric View", isometric).icon("camera").noundo().key("Ctrl+7").params(STANDARD_PARAMS)]; + +const STANDARD_PARAMS: &str = "camera?: Camera (default: current session camera or home view) → camera; turns to that standard view as the view cube does, keeping target, distance and projection"; + +/// The standard view a `view.front` … `view.isometric` command turns to. +pub fn standard_view(id: &str) -> Option { + Some(match id { + "view.front" => StandardView::Front, + "view.back" => StandardView::Back, + "view.left" => StandardView::Left, + "view.right" => StandardView::Right, + "view.top" => StandardView::Top, + "view.bottom" => StandardView::Bottom, + "view.isometric" => StandardView::Iso, + _ => return None, + }) +} + +fn front(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.front") +} +fn back(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.back") +} +fn left(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.left") +} +fn right(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.right") +} +fn top(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.top") +} +fn bottom(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.bottom") +} +fn isometric(s: &mut Session, p: &Value) -> Result { + turn_to(s, p, "view.isometric") +} + +fn turn_to(s: &mut Session, p: &Value, cmd: &str) -> Result { + let view = standard_view(cmd).ok_or_else(|| bad(cmd, "not a standard view"))?; + let mut cam: Camera = match p.get("camera") { + Some(value) => serde_json::from_value(value.clone()).map_err(|_| bad(cmd, "invalid camera"))?, + None => s.camera.unwrap_or_else(|| crate::view::home_camera(s)), + }; + if !cam.is_valid() || !cam.fov.is_finite() || !(0.0..std::f64::consts::PI).contains(&cam.fov) { + return Err(bad(cmd, "invalid camera")); + } + cam.set_view(view); + s.camera = Some(cam); + Ok(json!({"camera": cam})) +} fn normal_target(s: &Session) -> Option<(solidcraft_geom::Vec3, solidcraft_geom::Vec3)> { let state = s.world_state(); @@ -276,6 +335,32 @@ mod tests { assert_eq!(s.undo.len(), undo); } + #[test] + fn standard_view_commands_turn_the_camera_and_keep_the_rest() { + let cam = Camera { yaw: 0.3, pitch: 0.4, fov: 0.6, distance: 123.0, ..Default::default() }; + let mut s = Session { camera: Some(cam), ..Default::default() }; + for (id, key, view) in [ + ("view.front", "Ctrl+1", StandardView::Front), + ("view.back", "Ctrl+2", StandardView::Back), + ("view.left", "Ctrl+3", StandardView::Left), + ("view.right", "Ctrl+4", StandardView::Right), + ("view.top", "Ctrl+5", StandardView::Top), + ("view.bottom", "Ctrl+6", StandardView::Bottom), + ("view.isometric", "Ctrl+7", StandardView::Iso), + ] { + assert_eq!(crate::find_command(id).and_then(|c| c.shortcut), Some(key), "{id}"); + let result = s.execute(id, &json!({"camera": cam})).unwrap(); + let to: Camera = serde_json::from_value(result["camera"].clone()).unwrap(); + let mut want = cam; + want.set_view(view); + assert!(to.back().dist(want.back()) < 1e-9, "{id}"); + assert_eq!((to.target, to.distance, to.fov), (cam.target, cam.distance, cam.fov), "{id}"); + assert_eq!(s.camera, Some(to)); + } + assert!(s.undo.is_empty()); + assert!(s.execute("view.top", &json!({"camera": Camera { distance: -1.0, ..Default::default() }})).is_err()); + } + #[test] fn normal_to_selection_rejects_curved_missing_and_invalid_inputs() { let mut s = Session::default(); diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e56dd499a..86399cd9e 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -34,7 +34,7 @@ use serde_json::Value; use solidcraft_doc::{Document, Model, ModelState}; use solidcraft_geom::Vec3; -pub use cmd::{CommandInfo, CommandSpec, auto_operation, command_specs, extrude_reach, find_command}; +pub use cmd::{CommandInfo, CommandSpec, auto_operation, command_specs, extrude_reach, find_command, standard_view}; pub use solidcraft_doc as doc; pub use solidcraft_doc::Visibility; pub use solidcraft_geom as geom; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 55c11daac..cd91d804d 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -941,6 +941,16 @@ impl SolveApp { if self.file_load.busy() || self.file_picker.is_some() { return; } + // Front … Isometric (Ctrl+1…7 by default) turn the view as the view cube's faces do. The + // flat pattern is a 2D page: it has no other side to turn to. + if solidcraft_engine::standard_view(id).is_some() { + if !dialogs_sheet::flat_active(self) { + // `view.isometric` → "isometric", which `StandardView::parse` reads as Iso. + self.animate_view(id.trim_start_matches("view.")); + self.home.open = false; + } + return; + } if id == "view.normal_to" { if self.run(id, json!({"camera": self.cam})).is_ok() { self.follow_view_request(true); diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rs index 8dfd9f63f..0ab865eb0 100644 --- a/crates/ui-egui/src/navigation.rs +++ b/crates/ui-egui/src/navigation.rs @@ -1531,6 +1531,42 @@ mod view_key_tests { assert!((turn(before, h.app.cam.yaw).abs() - 30f64.to_radians()).abs() < 1e-6); } + /// Ctrl+1…7 run Front … Isometric View by default, turning the view as the view cube's faces + /// do; the keys are ordinary shortcuts, so one can be moved to another command and back. + #[test] + fn ctrl_digits_turn_to_the_standard_views_and_can_be_rebound() { + use solidcraft_engine::render::StandardView; + let mut h = Harness::new(); + h.app.preferences.look_at_anim = false; + h.app.run("solid.box", json!({"length": 10, "width": 10, "height": 10})).unwrap(); + h.frames(2); + let looks_from = |h: &mut Harness, digit: &str, view: StandardView| { + // Start from somewhere else, so the key has to move the view. + h.step(&json!({"key": "ArrowLeft"})).unwrap(); + h.frames(2); + h.step(&json!({"key": digit, "cmd": true})).unwrap(); + h.frames(2); + let mut want = h.app.cam; + want.set_view(view); + (h.app.cam.back() - want.back()).len() < 1e-6 + }; + for (digit, view) in [ + ("1", StandardView::Front), + ("2", StandardView::Back), + ("3", StandardView::Left), + ("4", StandardView::Right), + ("5", StandardView::Top), + ("6", StandardView::Bottom), + ("7", StandardView::Iso), + ] { + assert!(looks_from(&mut h, digit, view), "Ctrl+{digit} turns to {view:?}: {:?}", h.app.cam.back()); + } + // Top moves to Ctrl+T; Ctrl+5 then does nothing, Ctrl+T turns to the top. + crate::keymap::bind(&mut h.app, "view.top", "Ctrl+T", false).unwrap(); + assert!(!looks_from(&mut h, "5", StandardView::Top), "Ctrl+5 no longer turns to the top"); + assert!(looks_from(&mut h, "T", StandardView::Top), "Ctrl+T does"); + } + /// #1886: Ctrl+8 looks straight at the sketch; pressed again while the view faces it, it /// looks from the other side, and a third press turns it back. Opening a sketch never flips. #[test] diff --git a/docs/book/src/guide/shortcuts.md b/docs/book/src/guide/shortcuts.md index beaaaf5ab..a4a6e737b 100644 --- a/docs/book/src/guide/shortcuts.md +++ b/docs/book/src/guide/shortcuts.md @@ -41,6 +41,10 @@ if that happens; recording is cancelled if the app loses focus. | Ctrl+Z | Undo | Ctrl+Y | Redo | | Ctrl+N | New Design | Ctrl+O | Open | | Ctrl+S | Save | Delete | Delete the selection | +| Ctrl+1 | Front View | Ctrl+2 | Back View | +| Ctrl+3 | Left View | Ctrl+4 | Right View | +| Ctrl+5 | Top View | Ctrl+6 | Bottom View | +| Ctrl+7 | Isometric View | | | Keys handled by the window itself: