Skip to content

Commit

Permalink
Gui: [skip ci] add commands to save & restore camera positions so tha…
Browse files Browse the repository at this point in the history
…t they can be bound to a space mouse button
  • Loading branch information
wwmayer committed Nov 27, 2020
1 parent e92fff2 commit 15e6610
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/Gui/CommandView.cpp
Expand Up @@ -199,6 +199,74 @@ Action * StdPerspectiveCamera::createAction(void)
return pcAction;
}

//===========================================================================

// 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
//===========================================================================

DEF_3DV_CMD(StdCmdViewSaveCamera)

StdCmdViewSaveCamera::StdCmdViewSaveCamera()
: Command("Std_ViewSaveCamera")
{
sGroup = QT_TR_NOOP("Standard-View");
sMenuText = QT_TR_NOOP("Save current camera");
sToolTipText = QT_TR_NOOP("Save current camera settings");
sStatusTip = QT_TR_NOOP("Save current camera settings");
sWhatsThis = "Std_ViewSaveCamera";
eType = Alter3DView;
}

void StdCmdViewSaveCamera::activated(int iMsg)
{
Q_UNUSED(iMsg);

const char* ppReturn=0;
if (getGuiApplication()->sendMsgToActiveView("GetCamera",&ppReturn))
globalCameraPosition = ppReturn;
}

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

StdCmdViewRestoreCamera::StdCmdViewRestoreCamera()
: Command("Std_ViewRestoreCamera")
{
sGroup = QT_TR_NOOP("Standard-View");
sMenuText = QT_TR_NOOP("Restore saved camera");
sToolTipText = QT_TR_NOOP("Restore saved camera settings");
sStatusTip = QT_TR_NOOP("Restore saved camera settings");
sWhatsThis = "Std_ViewRestoreCamera";
eType = Alter3DView;
}

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());
}

//===========================================================================
// Std_FreezeViews
//===========================================================================
Expand Down Expand Up @@ -3554,6 +3622,8 @@ void CreateViewStdCommands(void)
rcCmdMgr.addCommand(new StdPerspectiveCamera());
rcCmdMgr.addCommand(new StdCmdToggleClipPlane());
rcCmdMgr.addCommand(new StdCmdDrawStyle());
rcCmdMgr.addCommand(new StdCmdViewSaveCamera());
rcCmdMgr.addCommand(new StdCmdViewRestoreCamera());
rcCmdMgr.addCommand(new StdCmdFreezeViews());
rcCmdMgr.addCommand(new StdViewZoomIn());
rcCmdMgr.addCommand(new StdViewZoomOut());
Expand Down

0 comments on commit 15e6610

Please sign in to comment.