diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a729ed80753201a3a425e2b968332132e42196c..d5a8b2cb819986e23a2fe33619a566898e74d45c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,8 @@ option(ENABLE_IMG "whether the image processing module should be compiled" ON) option(USE_DOUBLE_PRECISION "whether to compile in double precision" OFF) +option(ENABLE_SPNAV "whether 3DConnexion devices should be supported" + OFF) option(STATIC_PROPERTY_WORKAROUND "workaround for static property bug with some boost/boost_python combinations" OFF) option(DEPLOYMENT "switch on deployment settings" OFF) @@ -192,11 +194,16 @@ if (ENABLE_GUI) ost_find_python_module(PyQt4) endif() +if (ENABLE_SPNAV) + find_package(SpNav REQUIRED) +endif() + # basic environment include_directories(${Boost_INCLUDE_DIRS} ${FFTW_INCLUDE_PATH} ${EIGEN2_INCLUDE_DIR} ${TIFF_INCLUDE_DIR} + ${SPNAV_INCLUDE_DIR} ) diff --git a/cmake_support/FindSpNav.cmake b/cmake_support/FindSpNav.cmake new file mode 100644 index 0000000000000000000000000000000000000000..cf117b82f48745a354427e00c7aa5c89e29d0628 --- /dev/null +++ b/cmake_support/FindSpNav.cmake @@ -0,0 +1,28 @@ +# Try to find SpaceNav lib +# adapted from FINDEIGEN.cmake of OpenStructure by Stefan Scheuber <stefan.scheuber@unibas.ch> +# license see FINDEIGEN.cmake +# +# Once done this will define +# +# SPNAV_FOUND - system has spacenav lib +# SPNAV_LIBRARIES - List of libraries when using SpNav. +# SPNAV_INCLUDE_DIR - the spacenav include directory + +if (SPNAV_INCLUDE_DIR) + # in cache already + set(SPNAV_FOUND TRUE) + +else (SPNAV_INCLUDE_DIR) + find_path (SPNAV_INCLUDE_DIR NAMES spnav.h) + find_library (SPNAV_LIBRARIES NAMES spnav) +endif(SPNAV_INCLUDE_DIR) + +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (SPNAV DEFAULT_MSG SPNAV_LIBRARIES SPNAV_INCLUDE_DIR) + +mark_as_advanced (SPNAV_LIBRARIES SPNAV_INCLUDE_DIR) + + + + + diff --git a/modules/config/CMakeLists.txt b/modules/config/CMakeLists.txt index 7293ce38cab08487c8de31c10edd58af9d0427cf..9c5c890916dd6cefd673103ab40cd147dbefa72b 100644 --- a/modules/config/CMakeLists.txt +++ b/modules/config/CMakeLists.txt @@ -38,6 +38,11 @@ if (_STATICPROPS) else() set(static_props 0) endif() +if (ENABLE_SPNAV) + set(spnav_enabled 1) +else() + set(spnav_enabled 0) +endif() set(config_hh_generator "CMake") set(CONFIG_HH_FILE "${CMAKE_CURRENT_SOURCE_DIR}/config.hh") diff --git a/modules/config/config.hh.in b/modules/config/config.hh.in index 292d504bdf3afbabf3583ae3c77bbaa484fc8b1f..4d6fc6ff1fd4d58d400161820eece3d9078ac572 100644 --- a/modules/config/config.hh.in +++ b/modules/config/config.hh.in @@ -29,4 +29,5 @@ #define OST_IMG_ENABLED @img_enabled@ #define OST_DOUBLE_PRECISION @double_prec@ #define OST_STATIC_PROPERTY_WORKAROUND @static_props@ +#define OST_SPNAV_ENABLED @spnav_enabled@ #endif diff --git a/modules/gui/pymod/CMakeLists.txt b/modules/gui/pymod/CMakeLists.txt index e60d52db820c53ab44a5ac3ecd366f4f999bf1fd..d3cad752d59ff0696b638b6943e7f4ace59e3b22 100644 --- a/modules/gui/pymod/CMakeLists.txt +++ b/modules/gui/pymod/CMakeLists.txt @@ -65,6 +65,12 @@ if (ENABLE_IMG) ) endif() +if (ENABLE_SPNAV) + list( APPEND OST_GUI_PYMOD_SOURCES + export_input.cc + ) +endif() + set(OST_GUI_PYMOD_MODULES __init__.py init_menubar.py diff --git a/modules/gui/pymod/export_input.cc b/modules/gui/pymod/export_input.cc new file mode 100644 index 0000000000000000000000000000000000000000..b5bc4c51be70ed5b9d2f4c07a862d11895758ee7 --- /dev/null +++ b/modules/gui/pymod/export_input.cc @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#include <boost/python.hpp> +#include <iostream> +#include "spnav_input_proxy.hh" + +using namespace boost::python; +using namespace ost; +using namespace ost::gui; + +namespace { + +object spnav_get_instance() +{ + static object sip_module=import("sip"); + static object pyqt4_module=import("PyQt4.QtCore"); + SpnavInput* spnav = SpnavInput::Instance(); + unsigned long addr = reinterpret_cast<unsigned long>(spnav); + object obj(addr); + object qthread = pyqt4_module.attr("QThread"); + object thread = sip_module.attr("wrapinstance")(addr, qthread); + + return thread; +} + +} + +void export_Input() +{ + class_<SpnavInputProxy, bases<SipHandlerBase> >("SpnavInput",no_init) + .def("GetQThread", &spnav_get_instance).staticmethod("GetQThread") + .def("Instance", &SpnavInputProxy::Instance, + return_value_policy<reference_existing_object>()).staticmethod("Instance") + ; +} + diff --git a/modules/gui/pymod/spnav_input_proxy.hh b/modules/gui/pymod/spnav_input_proxy.hh new file mode 100644 index 0000000000000000000000000000000000000000..3421f8d598d4ee8890d9dc5bcdc39c14feeecfb5 --- /dev/null +++ b/modules/gui/pymod/spnav_input_proxy.hh @@ -0,0 +1,40 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ +#ifndef OST_GUI_SPNAV_INPUT_PROXY_HH +#define OST_GUI_SPNAV_INPUT_PROXY_HH + +#include <ost/gui/input/spnav_input.hh> + +#include "sip_handler.hh" + +namespace ost { namespace gui { + +class SpnavInputProxy : public SipHandler<SpnavInput> { +public: + SpnavInputProxy(SpnavInput* input=NULL): + SipHandler<SpnavInput>(input) + { } + static SpnavInputProxy* Instance(){ + return new SpnavInputProxy(SpnavInput::Instance()); + } +}; + +}} + +#endif diff --git a/modules/gui/pymod/wrap_gui.cc b/modules/gui/pymod/wrap_gui.cc index 15a615e95da8f7ca09cd46ad1ba1b7f4af5c36d3..19bc5a37a46854985df382e86862f2782eedb931 100644 --- a/modules/gui/pymod/wrap_gui.cc +++ b/modules/gui/pymod/wrap_gui.cc @@ -43,6 +43,9 @@ void export_RemoteSiteLoader(); void export_FileLoader(); void export_Widget(); +#if OST_SPNAV_ENABLED +void export_Input(); +#endif #ifdef OST_IMG_ENABLED void export_data_viewer(); @@ -116,6 +119,10 @@ BOOST_PYTHON_MODULE(_gui) export_FileLoader(); export_Widget(); + #if OST_SPNAV_ENABLED + export_Input(); + #endif + #if OST_IMG_ENABLED export_data_viewer(); #endif diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index f9698b9d3cf061a0cea86e870170c4f8216bbbdc..e9e413416a48bbe8b28ec426b803f20ad1baf77a 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -70,6 +70,14 @@ scene_win.hh scene_win_model.hh ) + +if (ENABLE_SPNAV) +set(OST_GUI_INPUT_HEADERS +spnav_input.hh + IN_DIR input +) +endif() + set(OST_GUI_PLOT_VIEWER_HEADERS plot_axis_base.hh plot_axis_horizontal.hh @@ -385,6 +393,15 @@ if (ENABLE_IMG) ) endif() +if (ENABLE_SPNAV) + list(APPEND OST_GUI_SOURCES + input/spnav_input.cc + ) + list(APPEND HEADERS_TO_BE_MOCCED + input/spnav_input.hh + ) +endif() + set(QT_USE_QTOPENGL 1) set(QT_USE_QTNETWORK 1) include(${QT_USE_FILE}) @@ -396,10 +413,11 @@ module(NAME gui SOURCES ${OST_GUI_MOCS} ${OST_GUI_SOURCES} ${OST_GUI_PYTHON_SHELL_HEADERS} IN_DIR python_shell ${OST_GUI_PANEL_BAR_HEADERS} IN_DIR panel_bar ${OST_GUI_SCENE_WIN_HEADERS} IN_DIR scene_win + ${OST_GUI_INPUT_HEADERS} ${OST_GUI_DATA_VIEWER_HEADERS} ${OST_GUI_HEADERS} DEPENDS_ON gfx io mol_alg - LINK ${QT_LIBRARIES} ${PYTHON_LIBRARIES} ${BOOST_PYTHON_LIBRARIES}) + LINK ${QT_LIBRARIES} ${PYTHON_LIBRARIES} ${BOOST_PYTHON_LIBRARIES} ${SPNAV_LIBRARIES}) include_directories(${PYTHON_INCLUDE_PATH}) qt4_add_resources(OST_QT_RESOURCE dngr.qrc) qt4_wrap_cpp(OST_GOSTY_MOC "gosty.hh") diff --git a/modules/gui/src/input/spnav_input.cc b/modules/gui/src/input/spnav_input.cc new file mode 100644 index 0000000000000000000000000000000000000000..61b548191499f3c9444abe19e44abb5f777d766c --- /dev/null +++ b/modules/gui/src/input/spnav_input.cc @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ + +/* + Author: Stefan Scheuber +*/ + +#include "spnav_input.hh" + +#include <iostream> + +#include <ost/io/io_exception.hh> + +#include <stdio.h> +#include <stdlib.h> +#include <signal.h> +#include <spnav.h> + +namespace ost { namespace gui { + +SpnavInput* SpnavInput::spnav_=NULL; + +SpnavInput::SpnavInput(QObject* parent): QThread(parent) +{ + qRegisterMetaType<geom::Mat4>("geom::Mat4"); + if(spnav_open()==-1) { + throw(io::IOException("failed to connect to the space navigator daemon\n")); + } +} + +void SpnavInput::run(){ + + spnav_event sev; + + while(spnav_wait_event(&sev)) { + if(sev.type == SPNAV_EVENT_MOTION) { + emit this->deviceTransformed(sev.motion.x,sev.motion.y,sev.motion.z, sev.motion.rx, sev.motion.ry, sev.motion.rz); + } else { /* SPNAV_EVENT_BUTTON */ + printf("got button %s event b(%d)\n", sev.button.press ? "press" : "release", sev.button.bnum); + if(sev.button.press) + emit this->deviceButtonPressed(sev.button.bnum); + } + } +} + +SpnavInput::~SpnavInput(){ + spnav_close(); +} + +SpnavInput* SpnavInput::Instance() { + if (!SpnavInput::spnav_) { + SpnavInput::spnav_=new SpnavInput; + } + return SpnavInput::spnav_; +} + +}} //ns diff --git a/modules/gui/src/input/spnav_input.hh b/modules/gui/src/input/spnav_input.hh new file mode 100644 index 0000000000000000000000000000000000000000..776fd5de425179ab59bb39c9fa144ae12bee4b81 --- /dev/null +++ b/modules/gui/src/input/spnav_input.hh @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2010 by the OpenStructure authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ + +/* + Author: Stefan Scheuber +*/ +#ifndef OST_GUI_SPNAV_INPUT_HH +#define OST_GUI_SPNAV_INPUT_HH + +#include <QThread> +#include <QMetaType> + +#include <ost/geom/geom.hh> +#include <ost/gui/module_config.hh> + +Q_DECLARE_METATYPE(geom::Mat4); + +namespace ost { namespace gui { + +class DLLEXPORT_OST_GUI SpnavInput : public QThread { + Q_OBJECT +public: + ~SpnavInput(); + virtual void run(); + + static SpnavInput* Instance(); + +signals: + void deviceTransformed(int,int,int,int,int,int); + void deviceButtonPressed(int); + +private: + SpnavInput(QObject* parent=NULL); + static SpnavInput* spnav_; +}; + +}} //ns + +#endif