Spacemice support refactored to use a common base class

This commit is contained in:
Torsten Sadowski
2018-11-20 22:28:50 +01:00
committed by wmayer
parent 91b2a3cff3
commit c6882e8de7
11 changed files with 125 additions and 48 deletions

View File

@@ -20,15 +20,20 @@
* *
***************************************************************************/
Q_OBJECT
public:
GuiNativeEvent(GUIApplicationNativeEventAware *app);
~GuiNativeEvent();
void initSpaceball(QMainWindow *window);
private:
GuiNativeEvent();
GuiNativeEvent(const GuiNativeEvent&);
GuiNativeEvent& operator=(const GuiNativeEvent&);
GUIApplicationNativeEventAware *mainApp;
static std::vector<int>motionDataArray;
#include "GuiAbstractNativeEvent.h"
#include "GuiApplicationNativeEventAware.h"
std::vector<int> Gui::GuiAbstractNativeEvent::motionDataArray(6,0);
Gui::GUIApplicationNativeEventAware* Gui::GuiAbstractNativeEvent::mainApp;
Gui::GuiAbstractNativeEvent::GuiAbstractNativeEvent(GUIApplicationNativeEventAware *app)
: QObject(app)
{
mainApp = app;
}
Gui::GuiAbstractNativeEvent::~GuiAbstractNativeEvent()
{}
#include "3Dconnexion/moc_GuiAbstractNativeEvent.cpp"

View File

@@ -0,0 +1,53 @@
/***************************************************************************
* Copyright (c) 2018 Torsten Sadowski <tsadowski[at]gmx.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 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 Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUIABSTRACTNATIVEEVENT_H
#define GUIABSTRACTNATIVEEVENT_H
#include <QObject>
#include <vector>
class QMainWindow;
namespace Gui
{
class GUIApplicationNativeEventAware;
class GuiAbstractNativeEvent : public QObject
{
Q_OBJECT
public:
GuiAbstractNativeEvent(GUIApplicationNativeEventAware *app);
virtual ~GuiAbstractNativeEvent()=0;
virtual void initSpaceball(QMainWindow *window)=0;
private:
GuiAbstractNativeEvent();
GuiAbstractNativeEvent(const GuiAbstractNativeEvent&);
GuiAbstractNativeEvent& operator=(const GuiAbstractNativeEvent&);
protected:
static GUIApplicationNativeEventAware *mainApp;
static std::vector<int>motionDataArray;
};
}
#endif //GUIABSTRACTNATIVEEVENT_H

View File

@@ -31,12 +31,9 @@
#include <spnav.h>
std::vector<int> Gui::GuiNativeEvent::motionDataArray(6,0);
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
: QObject(app)
: GuiAbstractNativeEvent(app)
{
mainApp = app;
}
Gui::GuiNativeEvent::~GuiNativeEvent()

View File

@@ -23,8 +23,7 @@
#ifndef GUINATIVEEVENT_H
#define GUINATIVEEVENT_H
#include <vector>
#include <QObject>
#include "GuiAbstractNativeEvent.h"
class QMainWindow;
@@ -32,10 +31,18 @@ namespace Gui
{
class GUIApplicationNativeEventAware;
class GuiNativeEvent : public QObject
class GuiNativeEvent : public GuiAbstractNativeEvent
{
#include "GuiNativeEventCommon.h"
private slots:
Q_OBJECT
public:
GuiNativeEvent(GUIApplicationNativeEventAware *app);
~GuiNativeEvent() override final;
void initSpaceball(QMainWindow *window) override final;
private:
GuiNativeEvent();
GuiNativeEvent(const GuiNativeEvent&);
GuiNativeEvent& operator=(const GuiNativeEvent&);
private Q_SLOTS:
void pollSpacenav();
};
}

View File

@@ -21,6 +21,7 @@
***************************************************************************/
#include "SpaceballEvent.h"
#include <QMainWindow>
#include "GuiNativeEventLinuxX11.h"
@@ -50,12 +51,9 @@
#undef Complex
#endif // #if QT_VERSION >= 0x050000
std::vector<int> Gui::GuiNativeEvent::motionDataArray(6,0);
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
: QObject(app)
: GuiAbstractNativeEvent(app)
{
mainApp = app;
}
Gui::GuiNativeEvent::~GuiNativeEvent()

View File

@@ -23,8 +23,8 @@
#ifndef GUINATIVEEVENT_H
#define GUINATIVEEVENT_H
#include "GuiAbstractNativeEvent.h"
#include <vector>
#include <QObject>
#if QT_VERSION >= 0x050000
#include <QAbstractNativeEventFilter>
@@ -39,9 +39,17 @@ namespace Gui
{
class GUIApplicationNativeEventAware;
class GuiNativeEvent : public QObject
class GuiNativeEvent : public GuiAbstractNativeEvent
{
#include "GuiNativeEventCommon.h"
Q_OBJECT
public:
GuiNativeEvent(GUIApplicationNativeEventAware *app);
~GuiNativeEvent() override final;
void initSpaceball(QMainWindow *window) override final;
private:
GuiNativeEvent();
GuiNativeEvent(const GuiNativeEvent&);
GuiNativeEvent& operator=(const GuiNativeEvent&);
public:
#if QT_VERSION >= 0x050000
static bool xcbEventFilter(void *message, long* result);

View File

@@ -36,8 +36,6 @@ With special thanks to marcxs for making the first steps
#include <FCConfig.h>
#include <Base/Console.h>
std::vector<int> Gui::GuiNativeEvent::motionDataArray(6,0);
UInt16 Gui::GuiNativeEvent::tdxClientID = 0;
uint32_t Gui::GuiNativeEvent::lastButtons = 0;
@@ -69,9 +67,6 @@ uint32_t Gui::GuiNativeEvent::lastButtons = 0;
//printf("msg->client: %d, tdxClientID: %d\n", msg->client, tdxClientID);
if (msg->client == tdxClientID)
{
auto inst(dynamic_cast<Gui::GUIApplicationNativeEventAware *>(QApplication::instance()));
if (!inst)
return;
switch (msg->command)
{
case kConnexionCmdHandleAxis:
@@ -82,7 +77,7 @@ uint32_t Gui::GuiNativeEvent::lastButtons = 0;
motionDataArray[3] = -msg->axis[3];
motionDataArray[4] = msg->axis[4];
motionDataArray[5] = msg->axis[5];
inst->postMotionEvent(motionDataArray);
mainApp->postMotionEvent(motionDataArray);
break;
}
@@ -96,13 +91,13 @@ uint32_t Gui::GuiNativeEvent::lastButtons = 0;
for (uint8_t bt = 0; bt < 32; bt++)
{
if (pressedButtons & 1)
inst->postButtonEvent(bt, 1);
mainApp->postButtonEvent(bt, 1);
pressedButtons = pressedButtons>>1;
}
for (uint8_t bt = 0; bt < 32; bt++)
{
if (releasedButtons & 1)
inst->postButtonEvent(bt, 0);
mainApp->postButtonEvent(bt, 0);
releasedButtons = releasedButtons>>1;
}
lastButtons = msg->buttons;
@@ -124,9 +119,8 @@ uint32_t Gui::GuiNativeEvent::lastButtons = 0;
}
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
: QObject(app)
: GuiAbstractNativeEvent(app)
{
mainApp = app;
}
Gui::GuiNativeEvent::~GuiNativeEvent()

View File

@@ -23,11 +23,9 @@
#ifndef GUINATIVEEVENT_H
#define GUINATIVEEVENT_H
#include <vector>
#include <QObject>
#include "GuiAbstractNativeEvent.h"
class QMainWindow;
class GUIApplicationNativeEventAware;
#include <IOKit/IOKitLib.h>
#include <ConnexionClientAPI.h>
@@ -46,9 +44,17 @@ namespace Gui
{
class GUIApplicationNativeEventAware;
class GuiNativeEvent : public QObject
class GuiNativeEvent : public GuiAbstractNativeEvent
{
#include "GuiNativeEventCommon.h"
Q_OBJECT
public:
GuiNativeEvent(GUIApplicationNativeEventAware *app);
~GuiNativeEvent() override final;
void initSpaceball(QMainWindow *window) override final;
private:
GuiNativeEvent();
GuiNativeEvent(const GuiNativeEvent&);
GuiNativeEvent& operator=(const GuiNativeEvent&);
private:
static UInt16 tdxClientID; /* ID assigned by the driver */
static uint32_t lastButtons;

View File

@@ -49,7 +49,6 @@ http://www.3dconnexion.com/forum/viewtopic.php?f=19&t=4968&sid=72c018bdcf0e6edc9
#include "GuiRawInputEventFilter.h"
#endif // #if QT_VERSION >= 0x050000
std::vector<int> Gui::GuiNativeEvent::motionDataArray(6,0);
Gui::GuiNativeEvent* Gui::GuiNativeEvent::gMouseInput = 0;
@@ -180,8 +179,8 @@ static const struct tag_VirtualKeys _3dmouseVirtualKeys[]=
};
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
: GuiAbstractNativeEvent(app)
{
mainApp = app;
}
Gui::GuiNativeEvent::~GuiNativeEvent()

View File

@@ -23,11 +23,10 @@
#ifndef GUINATIVEEVENT_H
#define GUINATIVEEVENT_H
#include <QObject>
#include "GuiAbstractNativeEvent.h"
#include "3Dconnexion/MouseParameters.h"
#include <vector>
#include <map>
//#define _WIN32_WINNT 0x0501 //target at least windows XP
@@ -43,9 +42,17 @@ namespace Gui
{
class GUIApplicationNativeEventAware;
class GuiNativeEvent : public QObject
class GuiNativeEvent : public GuiAbstractNativeEvent
{
#include "GuiNativeEventCommon.h"
Q_OBJECT
public:
GuiNativeEvent(GUIApplicationNativeEventAware *app);
~GuiNativeEvent() override final;
void initSpaceball(QMainWindow *window) override final;
private:
GuiNativeEvent();
GuiNativeEvent(const GuiNativeEvent&);
GuiNativeEvent& operator=(const GuiNativeEvent&);
public:
static bool Is3dmouseAttached();

View File

@@ -293,6 +293,7 @@ set(Gui_MOC_HDRS
GraphvizView.h
GuiApplication.h
GuiApplicationNativeEventAware.h
3Dconnexion/GuiAbstractNativeEvent.h
InputVector.h
MainWindow.h
ManualAlignment.h
@@ -1140,6 +1141,7 @@ SET(FreeCADGui_CPP_SRCS
ExpressionCompleter.cpp
GuiApplication.cpp
GuiApplicationNativeEventAware.cpp
3Dconnexion/GuiAbstractNativeEvent.cpp
GuiConsole.cpp
Macro.cpp
MergeDocuments.cpp
@@ -1168,6 +1170,7 @@ SET(FreeCADGui_SRCS
GraphicsViewZoom.h
GuiApplication.h
GuiApplicationNativeEventAware.h
3Dconnexion/GuiAbstractNativeEvent.h
GuiConsole.h
InventorAll.h
Macro.h