From 5765f416ca32478aaa07a2300e57aa5d677aa6c2 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Mon, 28 Apr 2025 17:45:21 +0200 Subject: [PATCH] Gui: MayaGesture navigation fixes (#20948) * Gui: Gesture and MayaGesture style disable H key in editing mode * Gui: MayaGesture style go back to IDLE after dragging/panning/zooming * Gui: MayaGesture more Maya like zoom behavior --- src/Gui/Navigation/GestureNavigationStyle.cpp | 3 +- .../Navigation/MayaGestureNavigationStyle.cpp | 28 +++++++++++++++---- src/Gui/Navigation/NavigationStyle.h | 4 ++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Gui/Navigation/GestureNavigationStyle.cpp b/src/Gui/Navigation/GestureNavigationStyle.cpp index 8dd6c24e8c..a7ee06b82c 100644 --- a/src/Gui/Navigation/GestureNavigationStyle.cpp +++ b/src/Gui/Navigation/GestureNavigationStyle.cpp @@ -315,7 +315,8 @@ public: bool press = (kbev->getState() == SoKeyboardEvent::DOWN); switch (kbev->getKey()) { case SoKeyboardEvent::H: - if (!press) { + // Disable H key in editing mode because of conflict with sketcher + if (!ns.viewer->isEditing() && !press) { ns.setupPanningPlane(ns.viewer->getCamera()); ns.lookAtPoint(kbev->getPosition()); } diff --git a/src/Gui/Navigation/MayaGestureNavigationStyle.cpp b/src/Gui/Navigation/MayaGestureNavigationStyle.cpp index 9d7e31ebf5..ccf6770fce 100644 --- a/src/Gui/Navigation/MayaGestureNavigationStyle.cpp +++ b/src/Gui/Navigation/MayaGestureNavigationStyle.cpp @@ -113,6 +113,19 @@ bool MayaGestureNavigationStyle::testMoveThreshold(const SbVec2s currentPos) con return SbVec2f(movedBy).length() >= this->mouseMoveThreshold; } +void MayaGestureNavigationStyle::zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos) +{ + const float dx = thispos[0] - prevpos[0]; + const float dy = thispos[1] - prevpos[1]; + + // Compute zoom based on diagonal difference. + float value = (dx - dy) * 10.0f; + + if (this->invertZoom) + value = -value; + zoom(viewer->getSoRenderManager()->getCamera(), value); +} + SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev) { // Events when in "ready-to-seek" mode are ignored, except those @@ -279,11 +292,14 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev) const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; switch (event->getKey()) { case SoKeyboardEvent::H: - processed = true; - if (!press) { - setupPanningPlane(viewer->getCamera()); - lookAtPoint(event->getPosition()); - } + // Disable H key in editing mode because of conflict with sketcher + if (!viewer->isEditing()) { + processed = true; + if (!press) { + setupPanningPlane(viewer->getCamera()); + lookAtPoint(event->getPosition()); + } + } break; default: break; @@ -514,7 +530,7 @@ SbBool MayaGestureNavigationStyle::processSoEvent(const SoEvent * const ev) processed = true; } else { //all buttons are released //end of dragging/panning/whatever - setViewingMode(NavigationStyle::SELECTION); + setViewingMode(NavigationStyle::IDLE); processed = true; } //end of else (some buttons down) break; diff --git a/src/Gui/Navigation/NavigationStyle.h b/src/Gui/Navigation/NavigationStyle.h index 802f497e32..2b918039a1 100644 --- a/src/Gui/Navigation/NavigationStyle.h +++ b/src/Gui/Navigation/NavigationStyle.h @@ -214,7 +214,7 @@ protected: void setupPanningPlane(const SoCamera* camera); int getDelta() const; void zoom(SoCamera * camera, float diffvalue); - void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos); + virtual void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos); void doZoom(SoCamera * camera, int wheeldelta, const SbVec2f& pos); void doZoom(SoCamera * camera, float logzoomfactor, const SbVec2f& pos); void doRotate(SoCamera * camera, float angle, const SbVec2f& pos); @@ -412,6 +412,8 @@ public: const char* mouseButtons(ViewerMode) override; protected: + void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos) override; + SbBool processSoEvent(const SoEvent * const ev) override; SbVec2s mousedownPos;//the position where some mouse button was pressed (local pixel coordinates).