From 5f7df94ea1f567f832dc7ad03233794029c5a04b Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 27 Nov 2020 12:27:25 +0100 Subject: [PATCH] Gui: [skip ci] improve commands Std_ViewSaveCamera & Std_ViewRestoreCamera to save/restore camera per view Implement resetToHomePosition() for Blender style --- src/Gui/BlenderNavigationStyle.cpp | 4 ++++ src/Gui/CommandView.cpp | 28 +++++++++------------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/Gui/BlenderNavigationStyle.cpp b/src/Gui/BlenderNavigationStyle.cpp index f556b4b1373d..b5b0cfbc4215 100644 --- a/src/Gui/BlenderNavigationStyle.cpp +++ b/src/Gui/BlenderNavigationStyle.cpp @@ -145,6 +145,10 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) processed = true; viewer->saveHomePosition(); break; + case SoKeyboardEvent::R: + processed = true; + viewer->resetToHomePosition(); + break; case SoKeyboardEvent::S: case SoKeyboardEvent::HOME: case SoKeyboardEvent::LEFT_ARROW: diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 36d544cfde5c..5ed54ca0e28c 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -204,10 +204,6 @@ Action * StdPerspectiveCamera::createAction(void) // The two commands below are provided for convenience so that they can be bound // to a button of a space mouse -namespace { - std::string globalCameraPosition; -} - //=========================================================================== // Std_ViewSaveCamera //=========================================================================== @@ -229,15 +225,16 @@ void StdCmdViewSaveCamera::activated(int iMsg) { Q_UNUSED(iMsg); - const char* ppReturn=0; - if (getGuiApplication()->sendMsgToActiveView("GetCamera",&ppReturn)) - globalCameraPosition = ppReturn; + Gui::View3DInventor* view = qobject_cast(Gui::getMainWindow()->activeWindow()); + if (view) { + view->getViewer()->saveHomePosition(); + } } //=========================================================================== // Std_ViewRestoreCamera //=========================================================================== -DEF_STD_CMD_A(StdCmdViewRestoreCamera) +DEF_3DV_CMD(StdCmdViewRestoreCamera) StdCmdViewRestoreCamera::StdCmdViewRestoreCamera() : Command("Std_ViewRestoreCamera") @@ -254,17 +251,10 @@ void StdCmdViewRestoreCamera::activated(int iMsg) { Q_UNUSED(iMsg); - std::string camera = globalCameraPosition; - std::string setCamera = std::string("SetCamera ") + camera; - getGuiApplication()->sendMsgToActiveView(setCamera.c_str()); -} - -bool StdCmdViewRestoreCamera::isActive() -{ - if (globalCameraPosition.empty()) - return false; - Gui::MDIView* view = Gui::getMainWindow()->activeWindow(); - return view && view->isDerivedFrom(Gui::View3DInventor::getClassTypeId()); + Gui::View3DInventor* view = qobject_cast(Gui::getMainWindow()->activeWindow()); + if (view) { + view->getViewer()->resetToHomePosition(); + } } //===========================================================================