Skip to content
Snippets Groups Projects
Commit 6fdf8861 authored by stefan's avatar stefan
Browse files

Added support for 3DConnexion 3DMouse devices

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1897 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 918f255a
Branches
Tags
No related merge requests found
......@@ -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}
)
......
# 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)
......@@ -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")
......
......@@ -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
......@@ -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
......
//------------------------------------------------------------------------------
// 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")
;
}
//------------------------------------------------------------------------------
// 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
......@@ -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
......
......@@ -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")
......
//------------------------------------------------------------------------------
// 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
//------------------------------------------------------------------------------
// 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment