From c0152eeb684d8c5749668883de929afabd6d0cb5 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 13 Sep 2014 10:18:52 +0200 Subject: [PATCH] FreeCAD-VR: command integration --- src/Gui/CMakeLists.txt | 6 +++--- src/Gui/CommandView.cpp | 32 ++++++++++++++++++++++++++++ src/Gui/View3DInventor.cpp | 13 ++++++++++- src/Gui/View3DInventorRiftViewer.cpp | 8 +++++-- src/Gui/View3DInventorViewer.cpp | 13 +++++++++++ src/Gui/View3DInventorViewer.h | 4 ++++ src/Gui/Workbench.cpp | 6 +++++- 7 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 13214c515..4a4f6e235 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -8,9 +8,9 @@ if (FREECAD_USE_3DCONNEXION) add_definitions(-D_USE_3DCONNEXION_SDK) endif(FREECAD_USE_3DCONNEXION) -if (OCULUS_FOUND) - add_definitions(-D_USE_OCULUS_RIFT_SDK ) -endif(OCULUS_FOUND) +if (BUILD_VR) + add_definitions(-DBUILD_VR ) +endif(BUILD_VR) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 8afd1aa77..8bd70449b 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -1408,6 +1408,37 @@ bool StdViewDockUndockFullscreen::isActive(void) return false; } + +//=========================================================================== +// Std_ViewVR +//=========================================================================== +DEF_STD_CMD_A(StdCmdViewVR); + +StdCmdViewVR::StdCmdViewVR() + : Command("Std_ViewVR") +{ + sGroup = QT_TR_NOOP("Standard-View"); + sMenuText = QT_TR_NOOP("FreeCAD-VR"); + sToolTipText = QT_TR_NOOP("Extend the FreeCAD 3D Window to a Oculus Rift"); + sWhatsThis = "Std_ViewVR"; + sStatusTip = QT_TR_NOOP("Extend the FreeCAD 3D Window to a Oculus Rift"); + sPixmap = "view-zoom-all"; + eType = Alter3DView; +} + +void StdCmdViewVR::activated(int iMsg) +{ + //doCommand(Command::Gui,"Gui.activeDocument().activeView().fitAll()"); + doCommand(Command::Gui,"Gui.SendMsgToActiveView(\"ViewVR\")"); +} + +bool StdCmdViewVR::isActive(void) +{ + return getGuiApplication()->sendHasMsgToActiveView("ViewVR"); +} + + + //=========================================================================== // Std_ViewScreenShot //=========================================================================== @@ -2453,6 +2484,7 @@ void CreateViewStdCommands(void) rcCmdMgr.addCommand(new StdCmdViewTop()); rcCmdMgr.addCommand(new StdCmdViewAxo()); rcCmdMgr.addCommand(new StdCmdViewFitAll()); + rcCmdMgr.addCommand(new StdCmdViewVR()); rcCmdMgr.addCommand(new StdCmdViewFitSelection()); rcCmdMgr.addCommand(new StdCmdViewRotateLeft()); rcCmdMgr.addCommand(new StdCmdViewRotateRight()); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 61d417f79..1d44f3b00 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -366,7 +366,7 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M _viewer->turnDeltaDimensionsOn(); else _viewer->turnDeltaDimensionsOff(); - } + } else{ unsigned long col1 = rGrp.GetUnsigned("BackgroundColor",3940932863UL); unsigned long col2 = rGrp.GetUnsigned("BackgroundColor2",859006463UL); // default color (dark blue) @@ -545,6 +545,11 @@ bool View3DInventor::onMsg(const char* pMsg, const char** ppReturn) _viewer->viewAll(); return true; } + else if (strcmp("ViewVR",pMsg) == 0) { + // call the VR portion of the viewer + _viewer->viewVR(); + return true; + } else if(strcmp("ViewSelection",pMsg) == 0) { _viewer->viewSelection(); return true; @@ -728,6 +733,12 @@ bool View3DInventor::onHasMsg(const char* pMsg) const return true; else if(strcmp("ViewFit",pMsg) == 0) return true; + else if(strcmp("ViewVR",pMsg) == 0) +#ifdef BUILD_VR + return true; +#elif + return false; +#endif else if(strcmp("ViewSelection",pMsg) == 0) return true; else if(strcmp("ViewBottom",pMsg) == 0) diff --git a/src/Gui/View3DInventorRiftViewer.cpp b/src/Gui/View3DInventorRiftViewer.cpp index 1adb46afd..6e8725557 100644 --- a/src/Gui/View3DInventorRiftViewer.cpp +++ b/src/Gui/View3DInventorRiftViewer.cpp @@ -33,7 +33,11 @@ #include "PreCompiled.h" -#if _USE_OCULUS_RIFT_SDK +#if BUILD_VR + +#ifndef OCULUS_FOUND +# error "Build VR without the Oculus SDK makes no sense at all" +#endif #define USE_SO_OFFSCREEN_RENDERER //#define USE_FRAMEBUFFER @@ -480,4 +484,4 @@ int oculusTest(void) //return app.exec(); } -#endif //_USE_OCULUS_RIFT_SDK \ No newline at end of file +#endif //BUILD_VR \ No newline at end of file diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index e7563f3c4..af3325c72 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1636,6 +1636,19 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) } } +#if BUILD_VR +extern int oculusTest(void); +#endif + +void View3DInventorViewer::viewVR(void) +{ +#if BUILD_VR + oculusTest(); +#endif +} + + + void View3DInventorViewer::boxZoom(const SbBox2s& box) { navigation->boxZoom(box); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 1fe23218c..733059a38 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -310,6 +310,10 @@ public: */ void viewAll(); void viewAll(float factor); + + /// Breaks out a VR window for a Rift + void viewVR(void); + /** * Reposition the current camera so we can see all selected objects * of the scene. Therefore we search for all SOFCSelection nodes, if diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index fa9c70c2f..df1906121 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -487,7 +487,11 @@ MenuItem* StdWorkbench::setupMenuBar() const *view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" << "Separator" << stdviews << "Std_FreezeViews" << "Std_DrawStyle" << "Separator" << view3d << zoom << "Std_ViewDockUndockFullscreen" << "Std_AxisCross" << "Std_ToggleClipPlane" - << "Std_TextureMapping" << "Separator" << visu + << "Std_TextureMapping" +#ifdef BUILD_VR + << "Std_ViewVR" +#endif + << "Separator" << visu << "Std_ToggleVisibility" << "Std_ToggleNavigation" << "Std_SetAppearance" << "Std_RandomColor" << "Separator" << "Std_MeasureDistance" << "Separator"