Spacemouse platform dependent code is moved to different classes. Compiles and works for Linux
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
Implementation by Torsten Sadowski 2018
|
||||
*/
|
||||
|
||||
#include "GuiApplicationNativeEventAware.h"
|
||||
#include "SpaceballEvent.h"
|
||||
#include <QWidget>
|
||||
|
||||
#if defined(SPNAV_FOUND)
|
||||
#include <spnav.h>
|
||||
#endif
|
||||
|
||||
void Gui::GUIApplicationNativeEventAware::pollSpacenav()
|
||||
{
|
||||
spnav_event ev;
|
||||
while(spnav_poll_event(&ev))
|
||||
{
|
||||
QWidget *currentWidget = this->focusWidget();
|
||||
if (!currentWidget)
|
||||
return;
|
||||
if (!setOSIndependentMotionData()) return;
|
||||
importSettings();
|
||||
switch (ev.type)
|
||||
{
|
||||
case SPNAV_EVENT_MOTION:
|
||||
{
|
||||
Spaceball::MotionEvent *motionEvent = new Spaceball::MotionEvent();
|
||||
motionEvent->setTranslations(ev.motion.x, ev.motion.y, ev.motion.z);
|
||||
motionEvent->setRotations(ev.motion.rx, ev.motion.ry, ev.motion.rz);
|
||||
this->postEvent(currentWidget, motionEvent);
|
||||
break;
|
||||
}
|
||||
case SPNAV_EVENT_BUTTON:
|
||||
{
|
||||
Spaceball::ButtonEvent *buttonEvent = new Spaceball::ButtonEvent();
|
||||
buttonEvent->setButtonNumber(ev.button.bnum);
|
||||
if (ev.button.press)
|
||||
{
|
||||
buttonEvent->setButtonStatus(Spaceball::BUTTON_PRESSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonEvent->setButtonStatus(Spaceball::BUTTON_RELEASED);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
81
src/Gui/3Dconnexion/GuiNativeEventLinux.cpp
Normal file
81
src/Gui/3Dconnexion/GuiNativeEventLinux.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
Implementation by Torsten Sadowski 2018
|
||||
*/
|
||||
|
||||
#include "GuiNativeEventLinux.h"
|
||||
|
||||
#include "GuiApplicationNativeEventAware.h"
|
||||
#include "SpaceballEvent.h"
|
||||
#include <FCConfig.h>
|
||||
#include <Base/Console.h>
|
||||
#include <QMainWindow>
|
||||
#include <QTimer>
|
||||
|
||||
#include <spnav.h>
|
||||
|
||||
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
|
||||
: QObject(app)
|
||||
{
|
||||
mainApp = app;
|
||||
}
|
||||
|
||||
Gui::GuiNativeEvent::~GuiNativeEvent()
|
||||
{
|
||||
if (spnav_close())
|
||||
Base::Console().Log("Couldn't disconnect from spacenav daemon\n");
|
||||
else
|
||||
Base::Console().Log("Disconnected from spacenav daemon\n");
|
||||
}
|
||||
|
||||
void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window)
|
||||
{
|
||||
Q_UNUSED(window)
|
||||
if (spnav_open() == -1) {
|
||||
Base::Console().Log("Couldn't connect to spacenav daemon\n");
|
||||
} else {
|
||||
Base::Console().Log("Connected to spacenav daemon\n");
|
||||
QTimer* SpacenavPollTimer = new QTimer(this);
|
||||
connect(SpacenavPollTimer, &QTimer::timeout, this, &GuiNativeEvent::pollSpacenav);
|
||||
SpacenavPollTimer->start(20);
|
||||
mainApp->setSpaceballPresent(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::GuiNativeEvent::pollSpacenav()
|
||||
{
|
||||
spnav_event ev;
|
||||
while(spnav_poll_event(&ev))
|
||||
{
|
||||
QWidget *currentWidget = mainApp->focusWidget();
|
||||
if (!currentWidget)
|
||||
return;
|
||||
//if (!setOSIndependentMotionData()) return;
|
||||
//importSettings();
|
||||
switch (ev.type)
|
||||
{
|
||||
case SPNAV_EVENT_MOTION:
|
||||
{
|
||||
Spaceball::MotionEvent *motionEvent = new Spaceball::MotionEvent();
|
||||
motionEvent->setTranslations(ev.motion.x, ev.motion.y, ev.motion.z);
|
||||
motionEvent->setRotations(ev.motion.rx, ev.motion.ry, ev.motion.rz);
|
||||
mainApp->postEvent(currentWidget, motionEvent);
|
||||
break;
|
||||
}
|
||||
case SPNAV_EVENT_BUTTON:
|
||||
{
|
||||
Spaceball::ButtonEvent *buttonEvent = new Spaceball::ButtonEvent();
|
||||
buttonEvent->setButtonNumber(ev.button.bnum);
|
||||
if (ev.button.press)
|
||||
{
|
||||
buttonEvent->setButtonStatus(Spaceball::BUTTON_PRESSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttonEvent->setButtonStatus(Spaceball::BUTTON_RELEASED);
|
||||
}
|
||||
mainApp->postEvent(currentWidget, buttonEvent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/Gui/3Dconnexion/GuiNativeEventLinux.h
Normal file
28
src/Gui/3Dconnexion/GuiNativeEventLinux.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef GUINATIVEEVENT_H
|
||||
#define GUINATIVEEVENT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QMainWindow;
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
class GuiNativeEvent : public QObject
|
||||
{
|
||||
public:
|
||||
GuiNativeEvent(GUIApplicationNativeEventAware *app);
|
||||
~GuiNativeEvent();
|
||||
void initSpaceball(QMainWindow *window);
|
||||
private:
|
||||
GuiNativeEvent();
|
||||
GuiNativeEvent(GuiNativeEvent*);
|
||||
void pollSpacenav();
|
||||
GUIApplicationNativeEventAware *mainApp;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //GUINATIVEEVENT_H
|
||||
|
||||
@@ -104,6 +104,61 @@ uint32_t Gui::GUIApplicationNativeEventAware::lastButtons = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
|
||||
: QObject(app)
|
||||
{
|
||||
spaceballPresent = false;
|
||||
mainApp = app;
|
||||
}
|
||||
|
||||
Gui::GuiNativeEvent::~GuiNativeEvent()
|
||||
{
|
||||
// if 3Dconnexion library was loaded at runtime
|
||||
if (InstallConnexionHandlers) {
|
||||
// Close our connection with the 3dx driver
|
||||
if (tdxClientID)
|
||||
UnregisterConnexionClient(tdxClientID);
|
||||
CleanupConnexionHandlers();
|
||||
Base::Console().Log("Disconnected from 3Dconnexion driver\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window)
|
||||
{
|
||||
Q_UNUSED(window)
|
||||
OSStatus err;
|
||||
/* make sure the framework is installed */
|
||||
if (InstallConnexionHandlers == NULL)
|
||||
{
|
||||
Base::Console().Log("3Dconnexion framework not found!\n");
|
||||
return;
|
||||
}
|
||||
/* install 3dx message handler in order to receive driver events */
|
||||
err = InstallConnexionHandlers(tdx_drv_handler, 0L, 0L);
|
||||
assert(err == 0);
|
||||
if (err)
|
||||
{
|
||||
Base::Console().Log("Error installing 3Dconnexion handler\n");
|
||||
return;
|
||||
}
|
||||
/* register our app with the driver */
|
||||
// Pascal string Application name required to register driver for application
|
||||
UInt8 tdxAppName[] = {7,'F','r','e','e','C','A','D'};
|
||||
// 32bit appID to register driver for application
|
||||
UInt32 tdxAppID = 'FCAd';
|
||||
tdxClientID = RegisterConnexionClient( tdxAppID, tdxAppName,
|
||||
kConnexionClientModeTakeOver,
|
||||
kConnexionMaskAll );
|
||||
if (tdxClientID == 0)
|
||||
{
|
||||
Base::Console().Log("Couldn't connect to 3Dconnexion driver\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Base::Console().Log("3Dconnexion driver initialized. Client ID: %d\n", tdxClientID);
|
||||
spaceballPresent = true;
|
||||
}
|
||||
|
||||
/*!
|
||||
Called with the processed motion data when a 3D mouse event is received
|
||||
50
src/Gui/3Dconnexion/GuiNativeEventMac.h
Normal file
50
src/Gui/3Dconnexion/GuiNativeEventMac.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef GUINATIVEEVENT_H
|
||||
#define GUINATIVEEVENT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QMainWindow;
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <ConnexionClientAPI.h>
|
||||
// Note that InstallConnexionHandlers will be replaced with
|
||||
// SetConnexionHandlers "in the future".
|
||||
extern OSErr InstallConnexionHandlers(ConnexionMessageHandlerProc messageHandler,
|
||||
ConnexionAddedHandlerProc addedHandler,
|
||||
ConnexionRemovedHandlerProc removedHandler)
|
||||
__attribute__((weak_import));
|
||||
extern UInt16 RegisterConnexionClient(UInt32 signature, UInt8 *name, UInt16 mode,
|
||||
UInt32 mask) __attribute__((weak_import));
|
||||
extern void UnregisterConnexionClient(UInt16 clientID) __attribute__((weak_import));
|
||||
extern void CleanupConnexionHandlers(void) __attribute__((weak_import));
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
class GuiNativeEvent : public QObject
|
||||
{
|
||||
public:
|
||||
GuiNativeEvent(GUIApplicationNativeEventAware *app);
|
||||
~GuiNativeEvent();
|
||||
void initSpaceball(QMainWindow *window);
|
||||
private:
|
||||
GuiNativeEvent();
|
||||
GuiNativeEvent(GuiNativeEvent*);
|
||||
bool spaceballPresent;
|
||||
GUIApplicationNativeEventAware *mainApp;
|
||||
|
||||
static UInt16 tdxClientID; /* ID assigned by the driver */
|
||||
static uint32_t lastButtons;
|
||||
|
||||
static void tdx_drv_handler( io_connect_t connection,
|
||||
natural_t messageType,
|
||||
void *messageArgument );
|
||||
void Move3d();
|
||||
void Button3d(bool buttonDown, int buttonNumber);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //GUINATIVEEVENT_H
|
||||
|
||||
@@ -16,6 +16,8 @@ http://www.3dconnexion.com/forum/viewtopic.php?f=19&t=4968&sid=72c018bdcf0e6edc9
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#include "GuiNativeEventLinux.h"
|
||||
|
||||
#include <QGlobalStatic>
|
||||
#include <QMainWindow>
|
||||
#include <QWidget>
|
||||
@@ -24,8 +26,10 @@ http://www.3dconnexion.com/forum/viewtopic.php?f=19&t=4968&sid=72c018bdcf0e6edc9
|
||||
#include "GuiApplicationNativeEventAware.h"
|
||||
#include "SpaceballEvent.h"
|
||||
|
||||
Gui::GuiNativeEvent* Gui::GuiNativeEvent::gMouseInput = 0;
|
||||
|
||||
|
||||
// Windows dependencies, enumerators and global variables
|
||||
#ifdef _USE_3DCONNEXION_SDK
|
||||
|
||||
#include <QApplication>
|
||||
#include <windows.h>
|
||||
@@ -151,6 +155,42 @@ static const struct tag_VirtualKeys _3dmouseVirtualKeys[]=
|
||||
, const_cast<e3dmouse_virtual_key *>(SpaceMouseWirelessReceiverKeys)
|
||||
};
|
||||
|
||||
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
|
||||
{
|
||||
spaceballPresent = false;
|
||||
mainApp = app;
|
||||
}
|
||||
|
||||
Gui::GuiNativeEvent::~GuiNativeEvent()
|
||||
{
|
||||
if (gMouseInput == this) {
|
||||
gMouseInput = 0;
|
||||
Base::Console().Log("3Dconnexion device detached.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window)
|
||||
{
|
||||
spaceballPresent = Is3dmouseAttached();
|
||||
|
||||
if (spaceballPresent) {
|
||||
fLast3dmouseInputTime = 0;
|
||||
|
||||
if (InitializeRawInput((HWND)mainWindow->winId())){
|
||||
gMouseInput = this;
|
||||
#if QT_VERSION >= 0x050000
|
||||
qApp->installNativeEventFilter(new Gui::RawInputEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter));
|
||||
#else
|
||||
qApp->setEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter);
|
||||
#endif
|
||||
Base::Console().Log("3Dconnexion device initialized.\n");
|
||||
} else {
|
||||
Base::Console().Log("3Dconnexion device is attached, but not initialized.\n");
|
||||
}
|
||||
} else {
|
||||
Base::Console().Log("3Dconnexion device not attached.\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Methods for windows events
|
||||
|
||||
@@ -934,4 +974,3 @@ Error:
|
||||
return processed;
|
||||
}
|
||||
|
||||
#endif // _USE_3DCONNEXION_SDK
|
||||
99
src/Gui/3Dconnexion/GuiNativeEventWin32.h
Normal file
99
src/Gui/3Dconnexion/GuiNativeEventWin32.h
Normal file
@@ -0,0 +1,99 @@
|
||||
#ifndef GUINATIVEEVENT_H
|
||||
#define GUINATIVEEVENT_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "3Dconnexion/MouseParameters.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
//#define _WIN32_WINNT 0x0501 //target at least windows XP
|
||||
#include <Windows.h>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
|
||||
|
||||
class QMainWindow;
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
class GUIApplicationNativeEventAware;
|
||||
|
||||
class GuiNativeEvent : public QObject
|
||||
{
|
||||
public:
|
||||
GuiNativeEvent(GUIApplicationNativeEventAware *app);
|
||||
~GuiNativeEvent();
|
||||
void initSpaceball(QMainWindow *window);
|
||||
private:
|
||||
GuiNativeEvent();
|
||||
GuiNativeEvent(GuiNativeEvent*);
|
||||
GUIApplicationNativeEventAware *mainApp;
|
||||
|
||||
class RawInputEventFilter : public QAbstractNativeEventFilter
|
||||
{
|
||||
public:
|
||||
typedef bool (*EventFilter)(void *message, long *result);
|
||||
RawInputEventFilter(EventFilter filter) : eventFilter(filter) {
|
||||
}
|
||||
virtual ~RawInputEventFilter() {
|
||||
}
|
||||
|
||||
virtual bool nativeEventFilter(const QByteArray & /*eventType*/, void *message, long *result) {
|
||||
return eventFilter(message, result);
|
||||
}
|
||||
|
||||
private:
|
||||
EventFilter eventFilter;
|
||||
};
|
||||
|
||||
public:
|
||||
static bool Is3dmouseAttached();
|
||||
|
||||
I3dMouseParam& MouseParams();
|
||||
const I3dMouseParam& MouseParams() const;
|
||||
|
||||
virtual void Move3d(HANDLE device, std::vector<float>& motionData);
|
||||
virtual void On3dmouseKeyDown(HANDLE device, int virtualKeyCode);
|
||||
virtual void On3dmouseKeyUp(HANDLE device, int virtualKeyCode);
|
||||
|
||||
private:
|
||||
bool InitializeRawInput(HWND hwndTarget);
|
||||
static bool RawInputEventFilter(void* msg, long* result);
|
||||
void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput);
|
||||
UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader);
|
||||
bool TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput);
|
||||
bool ParseRawInput(UINT nInputCode, PRAWINPUT pRawInput);
|
||||
void On3dmouseInput();
|
||||
|
||||
class TInputData
|
||||
{
|
||||
public:
|
||||
TInputData() : fAxes(6) {}
|
||||
|
||||
bool IsZero() {
|
||||
return (0.==fAxes[0] && 0.==fAxes[1] && 0.==fAxes[2] &&
|
||||
0.==fAxes[3] && 0.==fAxes[4] && 0.==fAxes[5]);
|
||||
}
|
||||
|
||||
int fTimeToLive; // For telling if the device was unplugged while sending data
|
||||
bool fIsDirty;
|
||||
std::vector<float> fAxes;
|
||||
};
|
||||
|
||||
HWND fWindow;
|
||||
|
||||
// Data cache to handle multiple rawinput devices
|
||||
std::map< HANDLE, TInputData> fDevice2Data;
|
||||
std::map< HANDLE, unsigned long> fDevice2Keystate;
|
||||
// 3dmouse parameters
|
||||
MouseParameters f3dMouseParams; // Rotate, Pan Zoom etc.
|
||||
// use to calculate distance traveled since last event
|
||||
DWORD fLast3dmouseInputTime;
|
||||
static Gui::GUIApplicationNativeEventAware* gMouseInput;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //GUINATIVEEVENT_H
|
||||
|
||||
@@ -184,21 +184,21 @@ SET(FreeCADGui_SDK_SRCS
|
||||
3Dconnexion/I3dMouseParams.h
|
||||
3Dconnexion/MouseParameters.cpp
|
||||
3Dconnexion/MouseParameters.h
|
||||
3Dconnexion/GuiApplicationNativeEventAwareWin32.cpp
|
||||
3Dconnexion/GuiNativeEventWin32.cpp
|
||||
)
|
||||
SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS})
|
||||
endif(FREECAD_USE_3DCONNEXION AND MSVC)
|
||||
|
||||
if(FREECAD_USE_3DCONNEXION AND APPLE)
|
||||
SET(FreeCADGui_SDK_SRCS
|
||||
3Dconnexion/GuiApplicationNativeEventAwareMac.cpp
|
||||
3Dconnexion/GuiNativeEventMac.cpp
|
||||
)
|
||||
SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS})
|
||||
endif(FREECAD_USE_3DCONNEXION AND APPLE)
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
SET(FreeCADGui_SDK_SRCS
|
||||
3Dconnexion/GuiApplicationNativeEventAwareLinux.cpp
|
||||
3Dconnexion/GuiNativeEventLinux.cpp
|
||||
)
|
||||
SOURCE_GROUP("3D connexion SDK" FILES ${FreeCADGui_SDK_SRCS})
|
||||
endif(UNIX AND NOT APPLE)
|
||||
|
||||
@@ -30,11 +30,9 @@
|
||||
#include "GuiApplicationNativeEventAware.h"
|
||||
#include "SpaceballEvent.h"
|
||||
#include "Application.h"
|
||||
#if defined(Q_OS_LINUX) && defined(SPNAV_FOUND)
|
||||
#include <spnav.h>
|
||||
#if defined(Q_OS_LINUX)
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
#include <QTimer>
|
||||
#undef Bool
|
||||
#undef CursorShape
|
||||
#undef Expose
|
||||
@@ -51,127 +49,28 @@
|
||||
#undef Complex
|
||||
#endif // #if QT_VERSION >= 0x050000
|
||||
|
||||
#endif // if defined(Q_OS_LINUX) && defined(SPNAV_FOUND)
|
||||
#endif // if defined(Q_OS_LINUX)
|
||||
|
||||
#ifdef _USE_3DCONNEXION_SDK
|
||||
//windows
|
||||
#ifdef Q_OS_WIN
|
||||
Gui::GUIApplicationNativeEventAware* Gui::GUIApplicationNativeEventAware::gMouseInput = 0;
|
||||
#endif
|
||||
#endif //_USE_3DCONNEXION_SDK
|
||||
|
||||
Gui::GUIApplicationNativeEventAware::GUIApplicationNativeEventAware(int &argc, char *argv[]) :
|
||||
QApplication (argc, argv), spaceballPresent(false)
|
||||
QApplication (argc, argv)
|
||||
{
|
||||
mainWindow = 0;
|
||||
nativeEvent = new Gui::GuiNativeEvent(this);
|
||||
}
|
||||
|
||||
Gui::GUIApplicationNativeEventAware::~GUIApplicationNativeEventAware()
|
||||
{
|
||||
#if defined(Q_OS_LINUX) && defined(SPNAV_FOUND)
|
||||
if (spnav_close())
|
||||
Base::Console().Log("Couldn't disconnect from spacenav daemon\n");
|
||||
else
|
||||
Base::Console().Log("Disconnected from spacenav daemon\n");
|
||||
|
||||
#elif defined(Q_OS_WIN) && defined(_USE_3DCONNEXION_SDK)
|
||||
if (gMouseInput == this) {
|
||||
gMouseInput = 0;
|
||||
Base::Console().Log("3Dconnexion device detached.\n");
|
||||
}
|
||||
|
||||
#elif defined(Q_OS_MACX) && defined(_USE_3DCONNEXION_SDK)
|
||||
// if 3Dconnexion library was loaded at runtime
|
||||
if (InstallConnexionHandlers) {
|
||||
// Close our connection with the 3dx driver
|
||||
if (tdxClientID)
|
||||
UnregisterConnexionClient(tdxClientID);
|
||||
CleanupConnexionHandlers();
|
||||
Base::Console().Log("Disconnected from 3Dconnexion driver\n");
|
||||
}
|
||||
#endif // Platform switch
|
||||
}
|
||||
|
||||
void Gui::GUIApplicationNativeEventAware::initSpaceball(QMainWindow *window)
|
||||
{
|
||||
mainWindow = window;
|
||||
|
||||
#if defined(Q_OS_LINUX) && defined(SPNAV_FOUND)
|
||||
if (spnav_open() == -1) {
|
||||
Base::Console().Log("Couldn't connect to spacenav daemon\n");
|
||||
} else {
|
||||
Base::Console().Log("Connected to spacenav daemon\n");
|
||||
spaceballPresent = true;
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
QTimer* SpacenavPollTimer = new QTimer(this);
|
||||
connect(SpacenavPollTimer, &QTimer::timeout, this, &GUIApplicationNativeEventAware::pollSpacenav);
|
||||
SpacenavPollTimer->start(20);
|
||||
#endif // #if QT_VERSION >= 0x050000
|
||||
}
|
||||
|
||||
#elif defined(Q_OS_WIN) && defined(_USE_3DCONNEXION_SDK)
|
||||
spaceballPresent = Is3dmouseAttached();
|
||||
|
||||
if (spaceballPresent) {
|
||||
fLast3dmouseInputTime = 0;
|
||||
|
||||
if (InitializeRawInput((HWND)mainWindow->winId())){
|
||||
gMouseInput = this;
|
||||
#if QT_VERSION >= 0x050000
|
||||
qApp->installNativeEventFilter(new Gui::RawInputEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter));
|
||||
#else
|
||||
qApp->setEventFilter(Gui::GUIApplicationNativeEventAware::RawInputEventFilter);
|
||||
#endif
|
||||
Base::Console().Log("3Dconnexion device initialized.\n");
|
||||
} else {
|
||||
Base::Console().Log("3Dconnexion device is attached, but not initialized.\n");
|
||||
}
|
||||
} else {
|
||||
Base::Console().Log("3Dconnexion device not attached.\n");
|
||||
}
|
||||
|
||||
#elif defined(Q_OS_MACX) && defined(_USE_3DCONNEXION_SDK)
|
||||
OSStatus err;
|
||||
/* make sure the framework is installed */
|
||||
if (InstallConnexionHandlers == NULL)
|
||||
{
|
||||
Base::Console().Log("3Dconnexion framework not found!\n");
|
||||
return;
|
||||
}
|
||||
/* install 3dx message handler in order to receive driver events */
|
||||
err = InstallConnexionHandlers(tdx_drv_handler, 0L, 0L);
|
||||
assert(err == 0);
|
||||
if (err)
|
||||
{
|
||||
Base::Console().Log("Error installing 3Dconnexion handler\n");
|
||||
return;
|
||||
}
|
||||
/* register our app with the driver */
|
||||
// Pascal string Application name required to register driver for application
|
||||
UInt8 tdxAppName[] = {7,'F','r','e','e','C','A','D'};
|
||||
// 32bit appID to register driver for application
|
||||
UInt32 tdxAppID = 'FCAd';
|
||||
tdxClientID = RegisterConnexionClient( tdxAppID, tdxAppName,
|
||||
kConnexionClientModeTakeOver,
|
||||
kConnexionMaskAll );
|
||||
if (tdxClientID == 0)
|
||||
{
|
||||
Base::Console().Log("Couldn't connect to 3Dconnexion driver\n");
|
||||
return;
|
||||
}
|
||||
|
||||
Base::Console().Log("3Dconnexion driver initialized. Client ID: %d\n", tdxClientID);
|
||||
spaceballPresent = true;
|
||||
#endif // Platform switch
|
||||
|
||||
nativeEvent->initSpaceball(window);
|
||||
Spaceball::MotionEvent::MotionEventType = QEvent::registerEventType();
|
||||
Spaceball::ButtonEvent::ButtonEventType = QEvent::registerEventType();
|
||||
}
|
||||
|
||||
bool Gui::GUIApplicationNativeEventAware::processSpaceballEvent(QObject *object, QEvent *event)
|
||||
{
|
||||
std::cout << "Gui::GUIApplicationNativeEventAware::processSpaceballEvent" << std::endl;
|
||||
if (!activeWindow()) {
|
||||
qDebug("No active window\n");
|
||||
return true;
|
||||
|
||||
@@ -29,30 +29,12 @@
|
||||
|
||||
class QMainWindow;
|
||||
|
||||
#if defined(Q_OS_WIN) && defined(_USE_3DCONNEXION_SDK)
|
||||
#include "3Dconnexion/MouseParameters.h"
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
//#define _WIN32_WINNT 0x0501 //target at least windows XP
|
||||
#include <Windows.h>
|
||||
#include <QAbstractNativeEventFilter>
|
||||
|
||||
#elif defined(Q_OS_MACX) && defined(_USE_3DCONNEXION_SDK)
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <ConnexionClientAPI.h>
|
||||
// Note that InstallConnexionHandlers will be replaced with
|
||||
// SetConnexionHandlers "in the future".
|
||||
extern OSErr InstallConnexionHandlers(ConnexionMessageHandlerProc messageHandler,
|
||||
ConnexionAddedHandlerProc addedHandler,
|
||||
ConnexionRemovedHandlerProc removedHandler)
|
||||
__attribute__((weak_import));
|
||||
extern UInt16 RegisterConnexionClient(UInt32 signature, UInt8 *name, UInt16 mode,
|
||||
UInt32 mask) __attribute__((weak_import));
|
||||
extern void UnregisterConnexionClient(UInt16 clientID) __attribute__((weak_import));
|
||||
extern void CleanupConnexionHandlers(void) __attribute__((weak_import));
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include "3Dconnexion/GuiNativeEventLinux.h"
|
||||
#elif defined(Q_OS_WIN)
|
||||
#include "3Dconnexion/GuiNativeEventWin32.h"
|
||||
#elif defined(Q_OS_MACX)
|
||||
#include "3Dconnexion/GuiNativeEventMac.h"
|
||||
#endif // Platform switch
|
||||
|
||||
namespace Gui
|
||||
@@ -65,98 +47,15 @@ namespace Gui
|
||||
~GUIApplicationNativeEventAware();
|
||||
void initSpaceball(QMainWindow *window);
|
||||
bool isSpaceballPresent() const {return spaceballPresent;}
|
||||
void setSpaceballPresent(bool present) {spaceballPresent = present;}
|
||||
bool processSpaceballEvent(QObject *object, QEvent *event);
|
||||
private:
|
||||
bool spaceballPresent;
|
||||
QMainWindow *mainWindow;
|
||||
int motionDataArray[6];
|
||||
bool setOSIndependentMotionData();
|
||||
void importSettings();
|
||||
float convertPrefToSensitivity(int value);
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
public:
|
||||
void pollSpacenav();
|
||||
#endif // Q_OS_LINUX
|
||||
|
||||
#ifdef _USE_3DCONNEXION_SDK
|
||||
// For Windows
|
||||
#ifdef Q_OS_WIN
|
||||
class RawInputEventFilter : public QAbstractNativeEventFilter
|
||||
{
|
||||
public:
|
||||
typedef bool (*EventFilter)(void *message, long *result);
|
||||
RawInputEventFilter(EventFilter filter) : eventFilter(filter) {
|
||||
}
|
||||
virtual ~RawInputEventFilter() {
|
||||
}
|
||||
|
||||
virtual bool nativeEventFilter(const QByteArray & /*eventType*/, void *message, long *result) {
|
||||
return eventFilter(message, result);
|
||||
}
|
||||
|
||||
private:
|
||||
EventFilter eventFilter;
|
||||
};
|
||||
|
||||
public:
|
||||
static bool Is3dmouseAttached();
|
||||
|
||||
I3dMouseParam& MouseParams();
|
||||
const I3dMouseParam& MouseParams() const;
|
||||
|
||||
virtual void Move3d(HANDLE device, std::vector<float>& motionData);
|
||||
virtual void On3dmouseKeyDown(HANDLE device, int virtualKeyCode);
|
||||
virtual void On3dmouseKeyUp(HANDLE device, int virtualKeyCode);
|
||||
|
||||
private:
|
||||
bool InitializeRawInput(HWND hwndTarget);
|
||||
static bool RawInputEventFilter(void* msg, long* result);
|
||||
void OnRawInput(UINT nInputCode, HRAWINPUT hRawInput);
|
||||
UINT GetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader);
|
||||
bool TranslateRawInputData(UINT nInputCode, PRAWINPUT pRawInput);
|
||||
bool ParseRawInput(UINT nInputCode, PRAWINPUT pRawInput);
|
||||
void On3dmouseInput();
|
||||
|
||||
class TInputData
|
||||
{
|
||||
public:
|
||||
TInputData() : fAxes(6) {}
|
||||
|
||||
bool IsZero() {
|
||||
return (0.==fAxes[0] && 0.==fAxes[1] && 0.==fAxes[2] &&
|
||||
0.==fAxes[3] && 0.==fAxes[4] && 0.==fAxes[5]);
|
||||
}
|
||||
|
||||
int fTimeToLive; // For telling if the device was unplugged while sending data
|
||||
bool fIsDirty;
|
||||
std::vector<float> fAxes;
|
||||
};
|
||||
|
||||
HWND fWindow;
|
||||
|
||||
// Data cache to handle multiple rawinput devices
|
||||
std::map< HANDLE, TInputData> fDevice2Data;
|
||||
std::map< HANDLE, unsigned long> fDevice2Keystate;
|
||||
// 3dmouse parameters
|
||||
MouseParameters f3dMouseParams; // Rotate, Pan Zoom etc.
|
||||
// use to calculate distance traveled since last event
|
||||
DWORD fLast3dmouseInputTime;
|
||||
static Gui::GUIApplicationNativeEventAware* gMouseInput;
|
||||
#endif // Q_OS_WIN
|
||||
#ifdef Q_OS_MACX
|
||||
private:
|
||||
static UInt16 tdxClientID; /* ID assigned by the driver */
|
||||
static uint32_t lastButtons;
|
||||
public:
|
||||
static void tdx_drv_handler( io_connect_t connection,
|
||||
natural_t messageType,
|
||||
void *messageArgument );
|
||||
void Move3d();
|
||||
void Button3d(bool buttonDown, int buttonNumber);
|
||||
|
||||
#endif// Q_OS_MACX
|
||||
#endif // _USE_3DCONNEXION_SDK
|
||||
GuiNativeEvent *nativeEvent;
|
||||
}; // end class GUIApplicationNativeEventAware
|
||||
} // end namespace Gui
|
||||
|
||||
|
||||
Reference in New Issue
Block a user