diff --git a/assets/locales/pending/creo-navigation.json b/assets/locales/pending/creo-navigation.json new file mode 100644 index 000000000..878796cf9 --- /dev/null +++ b/assets/locales/pending/creo-navigation.json @@ -0,0 +1,34 @@ +{ + "ar": { + "nav.creo.help": "السحب بالزر الأوسط يدوّر العرض، وShift مع الزر الأوسط يحرّكه، وCtrl مع السحب العمودي بالزر الأوسط يكبّر أو يصغّر (السحب لأسفل للتكبير)؛ وتدوير عجلة الفأرة يكبّر أو يصغّر", + "nav.creo.label": "Creo" + }, + "de": { + "nav.creo.help": "Ziehen mit der mittleren Maustaste dreht, Umschalt+Mitte verschiebt, Strg+Mitte zoomt beim vertikalen Ziehen (nach unten zum Vergrößern); das Mausrad zoomt", + "nav.creo.label": "Creo" + }, + "en": { + "nav.creo.help": "Middle drag orbits, Shift+middle pans, Ctrl+middle drag vertically zooms (down to zoom in); scroll the wheel to zoom", + "nav.creo.label": "Creo" + }, + "he": { + "nav.creo.help": "גרירה בלחצן האמצעי מסובבת את התצוגה, Shift והלחצן האמצעי מזיזים אותה, Ctrl וגרירה אנכית בלחצן האמצעי משנים את הזום (גרירה מטה להגדלה); גלילת הגלגלת משנה גם היא את הזום", + "nav.creo.label": "Creo" + }, + "ja": { + "nav.creo.help": "マウスの中ボタンドラッグで回転、Shift+中ボタンで平行移動、Ctrl+中ボタンの上下ドラッグでズーム(下方向で拡大)。ホイールの回転でもズーム", + "nav.creo.label": "Creo" + }, + "ko": { + "nav.creo.help": "가운데 버튼을 끌면 회전, Shift+가운데 버튼은 이동, Ctrl+가운데 버튼을 위아래로 끌면 확대/축소합니다(아래로 끌면 확대). 휠을 굴려도 확대/축소합니다", + "nav.creo.label": "Creo" + }, + "vi": { + "nav.creo.help": "Kéo nút giữa để xoay, Shift+nút giữa để di chuyển, Ctrl+kéo nút giữa theo chiều dọc để thu phóng (kéo xuống để phóng to); lăn con lăn để thu phóng", + "nav.creo.label": "Creo" + }, + "zh": { + "nav.creo.help": "中键拖动旋转,Shift+中键平移,Ctrl+中键上下拖动缩放(向下放大);滚动滚轮也可缩放", + "nav.creo.label": "Creo" + } +} diff --git a/crates/ui-egui/src/mouse_gesture.rs b/crates/ui-egui/src/mouse_gesture.rs index a11ece4b0..478d9c2a7 100644 --- a/crates/ui-egui/src/mouse_gesture.rs +++ b/crates/ui-egui/src/mouse_gesture.rs @@ -1153,7 +1153,7 @@ mod tests { let mut app = app(); assert!(!active(&app), "off by default"); app.preferences.mouse_gestures.enabled = true; - for nav in ["fusion", "inventor", "alias", "blender", "tinkercad", "openscad", "touchpad"] { + for nav in ["fusion", "creo", "inventor", "alias", "blender", "tinkercad", "openscad", "touchpad"] { app.preferences.nav = nav.into(); assert!(!active(&app), "{nav}: gestures only work with the SolidWorks mouse mode"); } diff --git a/crates/ui-egui/src/navigation.rs b/crates/ui-egui/src/navigation.rs index 31d013891..dc1506551 100644 --- a/crates/ui-egui/src/navigation.rs +++ b/crates/ui-egui/src/navigation.rs @@ -815,7 +815,8 @@ pub(crate) fn handle(app: &mut SolveApp, ui: &mut egui::Ui, rect: Rect, resp: &e Some(NavMode::Zoom) => { let press = ui.input(|i| i.pointer.press_origin()); let anchor = model_zoom_anchor(app, rect, press.or(hover), caps.orbit); - app.cam.zoom_at((f64::from(delta.y) * 0.01).exp(), anchor); + let sign = if crate::prefs::nav_preset(&app.preferences.nav).reverse_drag_zoom { -1.0 } else { 1.0 }; + app.cam.zoom_at((f64::from(delta.y) * 0.01 * sign).exp(), anchor); } _ => {} } diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs index bd990f6d9..b8efe27b9 100644 --- a/crates/ui-egui/src/prefs.rs +++ b/crates/ui-egui/src/prefs.rs @@ -89,6 +89,8 @@ pub struct NavPreset { pub help: &'static str, /// Choosing the preset turns the wheel the other way. pub reverse_zoom: bool, + /// Dragging down zooms in instead of out (independent of the wheel preference). + pub reverse_drag_zoom: bool, /// Choosing the preset sets what a middle double-click does (`None` leaves it as it is). pub middle_double_click: Option<&'static str>, /// Choosing the preset sets "Right drag orbits" (`None` leaves it as it is). @@ -113,6 +115,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Fusion", help: "Middle drag pans, Shift+middle orbits, right drag orbits", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[bind(Middle, NavKeys::SHIFT, Orbit), bind(Middle, NavKeys::NONE, Pan), bind(Right, NavKeys::NONE, Orbit)], @@ -122,6 +125,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "SolidWorks", help: "Middle drag orbits, Ctrl+middle pans, Shift+middle zooms, right drag orbits", reverse_zoom: true, + reverse_drag_zoom: false, // Picked here, the right button is left to the context menu and mouse gestures (#6492). middle_double_click: Some("fit"), right_drag_orbits: Some(false), @@ -132,6 +136,18 @@ pub const NAV_PRESETS: &[NavPreset] = &[ bind(Right, NavKeys::NONE, Orbit), ], }, + // Public Creo Parametric dynamic-viewing bindings; no product code or assets are used. + // https://support.ptc.com/help/creo/creo_pma/r12/usascii/fundamentals/fundamentals/About_Dynamic_Viewing.html + NavPreset { + id: "creo", + label: "Creo", + help: "Middle drag orbits, Shift+middle pans, Ctrl+middle drag vertically zooms (down to zoom in); scroll the wheel to zoom", + reverse_zoom: false, + reverse_drag_zoom: true, + middle_double_click: None, + right_drag_orbits: None, + bindings: &[bind(Middle, NavKeys::CTRL, Zoom), bind(Middle, NavKeys::SHIFT, Pan), bind(Middle, NavKeys::NONE, Orbit)], + }, NavPreset { id: "nx", label: "NX", @@ -140,6 +156,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ // middle drag with Ctrl (zoom) and Shift (pan). help: "Middle drag orbits, Shift+middle pans (NX's middle + right), Ctrl+middle zooms (NX's middle + left); right drag leaves the camera", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: Some("fit"), right_drag_orbits: Some(false), bindings: &[bind(Middle, NavKeys::SHIFT, Pan), bind(Middle, NavKeys::CTRL, Zoom), bind(Middle, NavKeys::NONE, Orbit)], @@ -149,6 +166,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Inventor", help: "Middle drag pans, Shift+middle orbits, Ctrl+middle zooms, right drag orbits", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[ @@ -163,6 +181,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Alias", help: "Shift+Alt+left drag orbits, Shift+Alt+middle pans, Shift+Alt+right zooms; middle drag also pans and right drag orbits", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[ @@ -179,6 +198,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Maya", help: "Alt+left drag orbits, Alt+middle pans, Alt+right zooms; middle drag also pans", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[ @@ -193,6 +213,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Blender", help: "Middle drag orbits, Shift+middle pans, Ctrl+middle zooms; right drag leaves the camera alone", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[bind(Middle, NavKeys::SHIFT, Pan), bind(Middle, NavKeys::CTRL, Zoom), bind(Middle, NavKeys::NONE, Orbit)], @@ -202,6 +223,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Tinkercad", help: "Right drag orbits, middle or Shift+right drag pans", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[bind(Right, NavKeys::SHIFT, Pan), bind(Right, NavKeys::NONE, Orbit), bind(Middle, NavKeys::NONE, Pan)], @@ -211,6 +233,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "OpenSCAD", help: "Left drag on empty space orbits, Shift+left drag box-selects, sketch geometry drags edit; right or middle drag pans, Shift+right or Shift+middle drag zooms", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[ @@ -226,6 +249,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "HFSS", help: "Alt+left drag pans, Shift+Alt+left zooms, Ctrl+left drag on empty space orbits", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, // Ctrl+left orbit is the drag from empty space every preset has: as a binding it would @@ -237,6 +261,7 @@ pub const NAV_PRESETS: &[NavPreset] = &[ label: "Touchpad", help: "Hold Shift and move the pointer to pan; hold Alt/Option and move it to orbit. No mouse button is needed. Vertical scroll zooms.", reverse_zoom: false, + reverse_drag_zoom: false, middle_double_click: None, right_drag_orbits: None, bindings: &[bind(Middle, NavKeys::NONE, Pan), bind(Right, NavKeys::NONE, Orbit)], @@ -257,7 +282,15 @@ impl NavPreset { } pub(crate) fn translated_label(&self) -> &str { - if self.id == TOUCHPAD_NAV { crate::i18n::tr("nav.touchpad.label") } else { crate::i18n::tr_label(self.label) } + match self.id { + "creo" => crate::i18n::tr("nav.creo.label"), + TOUCHPAD_NAV => crate::i18n::tr("nav.touchpad.label"), + _ => crate::i18n::tr_label(self.label), + } + } + + pub(crate) fn translated_help(&self) -> &str { + if self.id == "creo" { crate::i18n::tr("nav.creo.help") } else { crate::i18n::tr_label(self.help) } } } @@ -8536,6 +8569,79 @@ mod tests { assert_eq!(nav_mode(&app, NavButton::Right, none), Some(NavMode::Orbit), "turned back on, the right drag orbits again"); } + #[test] + fn creo_preset_maps_navigation_and_persists() { + let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); + assert_eq!(app.preferences.nav, "fusion"); + choose_nav_preset(&mut app.preferences, nav_preset("creo")); + assert_eq!(app.preferences.nav, "creo"); + assert!(!app.preferences.zoom_reverse); + for (mods, mode) in [ + (Modifiers::NONE, NavMode::Orbit), + (Modifiers::SHIFT, NavMode::Pan), + (Modifiers::CTRL, NavMode::Zoom), + (Modifiers::COMMAND, NavMode::Zoom), + ] { + assert_eq!(nav_mode(&app, NavButton::Middle, mods), Some(mode)); + } + for button in [NavButton::Left, NavButton::Right] { + assert_eq!(nav_mode(&app, button, Modifiers::NONE), None); + } + assert!(nav_preset("creo").reverse_drag_zoom); + for preset in NAV_PRESETS.iter().filter(|p| p.id != "creo") { + assert!(!preset.reverse_drag_zoom, "{} keeps its drag zoom direction", preset.id); + } + let mut other = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); + other.load_prefs(&app.prefs()); + assert_eq!(other.preferences.nav, "creo"); + assert_eq!(nav_mode(&other, NavButton::Middle, Modifiers::NONE), Some(NavMode::Orbit)); + } + + #[test] + fn creo_navigation_settings_show_localised_bindings() { + let _language = crate::i18n::scope("de"); + let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); + control(&mut app, &json!({"open":"Navigation", "nav":"creo", "language":"de"})).unwrap(); + let ctx = crate::fonts::test_context(); + let screen = egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(1400.0, 1000.0)); + let mut textures = std::collections::HashMap::new(); + let mut draw = || { + let raw = egui::RawInput { screen_rect: Some(screen), ..Default::default() }; + let mut output = ctx.run_ui(raw, |ui| show(&mut app, ui.ctx())); + crate::ui_kit::test_textures_update(&mut textures, &output.textures_delta); + output.textures_delta.clear(); + output + }; + for _ in 0..3 { + draw(); + } + let output = draw(); + for label in ["Creo", crate::i18n::tr("prefs.gesture_orbit"), crate::i18n::tr("prefs.gesture_pan"), crate::i18n::tr("prefs.gesture_zoom")] { + assert!(crate::test_support::text_shapes(&output).any(|text| text.galley.text().contains(label)), "missing binding label: {label}"); + } + assert_ne!(nav_preset("creo").translated_help(), nav_preset("creo").help); + if let Ok(dir) = std::env::var("SOLIDCRAFT_CREO_EVIDENCE") { + std::fs::create_dir_all(&dir).unwrap(); + crate::ui_kit::test_raster(&ctx, output.shapes, output.pixels_per_point, screen, &textures) + .save(std::path::Path::new(&dir).join("creo-navigation-de.png")) + .unwrap(); + } + } + + #[test] + fn creo_preset_obeys_preference_transactions() { + let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); + control(&mut app, &json!({"open":"Navigation", "nav":"creo"})).unwrap(); + assert_eq!(app.preferences.nav, "creo"); + control(&mut app, &json!({"button":"cancel"})).unwrap(); + assert_eq!(app.preferences.nav, "fusion"); + control(&mut app, &json!({"open":"Navigation", "nav":"creo", "button":"apply"})).unwrap(); + control(&mut app, &json!({"button":"defaults"})).unwrap(); + assert_eq!(app.preferences.nav, "fusion"); + control(&mut app, &json!({"button":"cancel"})).unwrap(); + assert_eq!(app.preferences.nav, "creo"); + } + #[test] fn openscad_preset_maps_navigation_and_persists() { let mut app = SolveApp::new(solidcraft_engine::Session::default(), Default::default()); diff --git a/crates/ui-egui/src/prefs/navigation.rs b/crates/ui-egui/src/prefs/navigation.rs index 67f97e28c..2abc578b4 100644 --- a/crates/ui-egui/src/prefs/navigation.rs +++ b/crates/ui-egui/src/prefs/navigation.rs @@ -61,7 +61,7 @@ pub(super) fn show(app: &mut SolveApp, ui: &mut egui::Ui, t: &Tokens) { } }); crate::scenario::publish_target("dialog:Pan, zoom, orbit", picker.rect); - picker.on_hover_text(crate::i18n::tr_label(nav_preset(&app.preferences.nav).help)); + picker.on_hover_text(nav_preset(&app.preferences.nav).translated_help()); }); }); }); diff --git a/crates/ui-egui/tests/scenarios/creo_navigation_bindings.json b/crates/ui-egui/tests/scenarios/creo_navigation_bindings.json new file mode 100644 index 000000000..5e4487261 --- /dev/null +++ b/crates/ui-egui/tests/scenarios/creo_navigation_bindings.json @@ -0,0 +1,29 @@ +[ + {"note": "Creo navigation: choose the preset in Preferences, then orbit, pan and zoom using the middle button. Other presets keep their drag zoom direction."}, + {"call": "engine.execute", "params": {"command": "solid.box", "params": {"length": 20, "width": 10, "height": 5}}}, + {"call": "ui.prefs", "params": {"open": "Navigation"}}, + {"click": {"handle": "dialog:Pan, zoom, orbit"}}, + {"widget": "Creo"}, + {"expect": {"prefs": {"nav": "creo"}}}, + {"call": "ui.prefs", "params": {"button": "ok"}}, + {"call": "ui.prefs", "params": {"orbit_around": "view_centre", "zoom_to_cursor": false, "free_orbit": false}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 848, "y1": 500, "steps": 8, "button": "middle"}}, + {"expect": {"camera": {"yaw_deg": 22, "pitch_deg": 0, "panned": false, "zoomed": "no"}, "selection": 0}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 860, "y1": 540, "steps": 8, "shift": true, "button": "middle"}}, + {"expect": {"camera": {"yaw_deg": 0, "pitch_deg": 0, "panned": true, "zoomed": "no"}}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 800, "y1": 560, "steps": 8, "ctrl": true, "button": "middle"}}, + {"expect": {"camera": {"yaw_deg": 0, "pitch_deg": 0, "panned": false, "zoomed": "in"}}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 800, "y1": 440, "steps": 8, "ctrl": true, "button": "middle"}}, + {"expect": {"camera": {"yaw_deg": 0, "pitch_deg": 0, "panned": false, "zoomed": "out"}}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 860, "y1": 540, "steps": 8, "button": "right"}}, + {"expect": {"camera": {"yaw_deg": 0, "pitch_deg": 0, "panned": false, "zoomed": "no"}, "selection": 0}}, + {"call": "ui.prefs", "params": {"nav": "blender"}}, + {"camera": {"yaw": 0, "pitch": 0}}, + {"call": "ui.drag", "params": {"x0": 800, "y0": 500, "x1": 800, "y1": 560, "steps": 8, "ctrl": true, "button": "middle"}}, + {"expect": {"camera": {"yaw_deg": 0, "pitch_deg": 0, "panned": false, "zoomed": "out"}}} +] diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 316d863d4..43440ed5a 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -466,7 +466,7 @@ One setting per line, sorted by name. A change that adds a setting adds its own - `max_step_file_mb` (default 512): the largest STEP or import file opened, in MB, from the default up to 16384 (16 GB) (Preferences › General › Largest file to open, #4086; a `--max-file-size` launch flag overrides both for that run; the web app keeps the defaults and refuses other values; [large files](book/src/guide/files.md#large-files)) - `middle_double_click` (`home` (default), `fit`, `off`) - `msaa` -- `nav` (`fusion`, `solidworks`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`) +- `nav` (`fusion`, `solidworks`, `creo`, `inventor`, `alias`, `blender`, `tinkercad`, `openscad`, `touchpad`) - `nav_bridge_enabled` (default false) and `nav_bridge_port` (default 8765: a device's own app on this computer moves the view, [the navigation bridge](3d-mouse.md#device-apps-the-navigation-bridge)) - `navigator_fit` (default false: a view chosen on the view cube or the axis gizmo also looks at the middle of the model from the one distance that fits its bounding sphere in the free part of the view, at `home_fit_size`; Home and an opened design use the same zoom and centre while it is on, so views chosen after them only turn; #10091) - `offer_stand_up`