FreeCAD
88 строк · 3.4 Кб
1/***************************************************************************
2* Copyright (c) 2018 Torsten Sadowski <tsadowski[at]gmx.net> *
3* *
4* This file is part of the FreeCAD CAx development system. *
5* *
6* This library is free software; you can redistribute it and/or *
7* modify it under the terms of the GNU Library General Public *
8* License as published by the Free Software Foundation; either *
9* version 2 of the License, or (at your option) any later version. *
10* *
11* This library is distributed in the hope that it will be useful, *
12* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14* GNU Library General Public License for more details. *
15* *
16* You should have received a copy of the GNU Library General Public *
17* License along with this library; see the file COPYING.LIB. If not, *
18* write to the Free Software Foundation, Inc., 59 Temple Place, *
19* Suite 330, Boston, MA 02111-1307, USA *
20* *
21***************************************************************************/
22
23#include <FCConfig.h>
24
25#include "GuiNativeEventLinux.h"
26
27#include "GuiApplicationNativeEventAware.h"
28#include <Base/Console.h>
29#include <QMainWindow>
30
31#include <QSocketNotifier>
32
33#include <spnav.h>
34
35Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
36: GuiAbstractNativeEvent(app)
37{
38}
39
40Gui::GuiNativeEvent::~GuiNativeEvent()
41{
42if (spnav_close())
43Base::Console().Log("Couldn't disconnect from spacenav daemon\n");
44else
45Base::Console().Log("Disconnected from spacenav daemon\n");
46}
47
48void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window)
49{
50Q_UNUSED(window)
51if (spnav_open() == -1) {
52Base::Console().Log("Couldn't connect to spacenav daemon. Please ignore if you don't have a spacemouse.\n");
53} else {
54Base::Console().Log("Connected to spacenav daemon\n");
55QSocketNotifier* SpacenavNotifier = new QSocketNotifier(spnav_fd(), QSocketNotifier::Read, this);
56connect(SpacenavNotifier, SIGNAL(activated(int)), this, SLOT(pollSpacenav()));
57mainApp->setSpaceballPresent(true);
58}
59}
60
61void Gui::GuiNativeEvent::pollSpacenav()
62{
63spnav_event ev;
64while(spnav_poll_event(&ev))
65{
66switch (ev.type)
67{
68case SPNAV_EVENT_MOTION:
69{
70motionDataArray[0] = -ev.motion.x;
71motionDataArray[1] = -ev.motion.z;
72motionDataArray[2] = -ev.motion.y;
73motionDataArray[3] = -ev.motion.rx;
74motionDataArray[4] = -ev.motion.rz;
75motionDataArray[5] = -ev.motion.ry;
76mainApp->postMotionEvent(motionDataArray);
77break;
78}
79case SPNAV_EVENT_BUTTON:
80{
81mainApp->postButtonEvent(ev.button.bnum, ev.button.press);
82break;
83}
84}
85}
86}
87
88#include "3Dconnexion/moc_GuiNativeEventLinux.cpp"
89