From 1914aec92f957a8d0d28437d0d01c8615065a1f3 Mon Sep 17 00:00:00 2001 From: Torsten Sadowski Date: Tue, 20 Nov 2018 22:28:50 +0100 Subject: [PATCH] Spacemice support refactored to use a common base class --- ...entCommon.h => GuiAbstractNativeEvent.cpp} | 27 ++++++---- src/Gui/3Dconnexion/GuiAbstractNativeEvent.h | 53 +++++++++++++++++++ src/Gui/3Dconnexion/GuiNativeEventLinux.cpp | 5 +- src/Gui/3Dconnexion/GuiNativeEventLinux.h | 17 ++++-- .../3Dconnexion/GuiNativeEventLinuxX11.cpp | 6 +-- src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h | 14 +++-- src/Gui/3Dconnexion/GuiNativeEventMac.cpp | 14 ++--- src/Gui/3Dconnexion/GuiNativeEventMac.h | 16 ++++-- src/Gui/3Dconnexion/GuiNativeEventWin32.cpp | 3 +- src/Gui/3Dconnexion/GuiNativeEventWin32.h | 15 ++++-- src/Gui/CMakeLists.txt | 3 ++ 11 files changed, 125 insertions(+), 48 deletions(-) rename src/Gui/3Dconnexion/{GuiNativeEventCommon.h => GuiAbstractNativeEvent.cpp} (77%) create mode 100644 src/Gui/3Dconnexion/GuiAbstractNativeEvent.h diff --git a/src/Gui/3Dconnexion/GuiNativeEventCommon.h b/src/Gui/3Dconnexion/GuiAbstractNativeEvent.cpp similarity index 77% rename from src/Gui/3Dconnexion/GuiNativeEventCommon.h rename to src/Gui/3Dconnexion/GuiAbstractNativeEvent.cpp index dbce8d4e02..f14e8a1f9c 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventCommon.h +++ b/src/Gui/3Dconnexion/GuiAbstractNativeEvent.cpp @@ -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::vectormotionDataArray; +#include "GuiAbstractNativeEvent.h" +#include "GuiApplicationNativeEventAware.h" + +std::vector 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" diff --git a/src/Gui/3Dconnexion/GuiAbstractNativeEvent.h b/src/Gui/3Dconnexion/GuiAbstractNativeEvent.h new file mode 100644 index 0000000000..4040e931fe --- /dev/null +++ b/src/Gui/3Dconnexion/GuiAbstractNativeEvent.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (c) 2018 Torsten Sadowski * + * * + * 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 +#include + +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::vectormotionDataArray; + }; +} + + +#endif //GUIABSTRACTNATIVEEVENT_H diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp b/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp index 3f877d8fec..8cd1269307 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventLinux.cpp @@ -31,12 +31,9 @@ #include -std::vector Gui::GuiNativeEvent::motionDataArray(6,0); - Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app) -: QObject(app) +: GuiAbstractNativeEvent(app) { - mainApp = app; } Gui::GuiNativeEvent::~GuiNativeEvent() diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinux.h b/src/Gui/3Dconnexion/GuiNativeEventLinux.h index 0156312700..c14d43734c 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinux.h +++ b/src/Gui/3Dconnexion/GuiNativeEventLinux.h @@ -23,8 +23,7 @@ #ifndef GUINATIVEEVENT_H #define GUINATIVEEVENT_H -#include -#include +#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(); }; } diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp index c5b50102ca..f97a822c7b 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.cpp @@ -21,6 +21,7 @@ ***************************************************************************/ #include "SpaceballEvent.h" + #include #include "GuiNativeEventLinuxX11.h" @@ -50,12 +51,9 @@ #undef Complex #endif // #if QT_VERSION >= 0x050000 -std::vector Gui::GuiNativeEvent::motionDataArray(6,0); - Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app) -: QObject(app) +: GuiAbstractNativeEvent(app) { - mainApp = app; } Gui::GuiNativeEvent::~GuiNativeEvent() diff --git a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h index 3e5cd773c3..1c3ca4f3c2 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h +++ b/src/Gui/3Dconnexion/GuiNativeEventLinuxX11.h @@ -23,8 +23,8 @@ #ifndef GUINATIVEEVENT_H #define GUINATIVEEVENT_H +#include "GuiAbstractNativeEvent.h" #include -#include #if QT_VERSION >= 0x050000 #include @@ -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); diff --git a/src/Gui/3Dconnexion/GuiNativeEventMac.cpp b/src/Gui/3Dconnexion/GuiNativeEventMac.cpp index 2a3e6e1c76..73980b2f6e 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventMac.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventMac.cpp @@ -36,8 +36,6 @@ With special thanks to marcxs for making the first steps #include #include -std::vector 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(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() diff --git a/src/Gui/3Dconnexion/GuiNativeEventMac.h b/src/Gui/3Dconnexion/GuiNativeEventMac.h index 9e69e596a4..bbe712b435 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventMac.h +++ b/src/Gui/3Dconnexion/GuiNativeEventMac.h @@ -23,11 +23,9 @@ #ifndef GUINATIVEEVENT_H #define GUINATIVEEVENT_H -#include -#include +#include "GuiAbstractNativeEvent.h" class QMainWindow; -class GUIApplicationNativeEventAware; #include #include @@ -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; diff --git a/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp b/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp index 7046b79b0f..a73e6af35a 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp +++ b/src/Gui/3Dconnexion/GuiNativeEventWin32.cpp @@ -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 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() diff --git a/src/Gui/3Dconnexion/GuiNativeEventWin32.h b/src/Gui/3Dconnexion/GuiNativeEventWin32.h index 77bfb1b48a..e64b35026a 100644 --- a/src/Gui/3Dconnexion/GuiNativeEventWin32.h +++ b/src/Gui/3Dconnexion/GuiNativeEventWin32.h @@ -23,11 +23,10 @@ #ifndef GUINATIVEEVENT_H #define GUINATIVEEVENT_H -#include +#include "GuiAbstractNativeEvent.h" #include "3Dconnexion/MouseParameters.h" -#include #include //#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(); diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 58b1337b4e..d33ade947a 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -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