Skip to content

Commit

Permalink
Gui: [skip ci] improve commands Std_ViewSaveCamera & Std_ViewRestoreC…
Browse files Browse the repository at this point in the history
…amera to save/restore camera per view

Implement resetToHomePosition() for Blender style
  • Loading branch information
wwmayer committed Nov 27, 2020
1 parent 15e6610 commit 5f7df94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/Gui/BlenderNavigationStyle.cpp
Expand Up @@ -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:
Expand Down
28 changes: 9 additions & 19 deletions src/Gui/CommandView.cpp
Expand Up @@ -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
//===========================================================================
Expand All @@ -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::View3DInventor*>(Gui::getMainWindow()->activeWindow());
if (view) {
view->getViewer()->saveHomePosition();
}
}

//===========================================================================
// Std_ViewRestoreCamera
//===========================================================================
DEF_STD_CMD_A(StdCmdViewRestoreCamera)
DEF_3DV_CMD(StdCmdViewRestoreCamera)

StdCmdViewRestoreCamera::StdCmdViewRestoreCamera()
: Command("Std_ViewRestoreCamera")
Expand All @@ -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::View3DInventor*>(Gui::getMainWindow()->activeWindow());
if (view) {
view->getViewer()->resetToHomePosition();
}
}

//===========================================================================
Expand Down

0 comments on commit 5f7df94

Please sign in to comment.