FreeCAD

Форк
0
/
GuiNativeEventLinux.cpp 
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

35
Gui::GuiNativeEvent::GuiNativeEvent(Gui::GUIApplicationNativeEventAware *app)
36
: GuiAbstractNativeEvent(app)
37
{
38
}
39

40
Gui::GuiNativeEvent::~GuiNativeEvent()
41
{
42
    if (spnav_close())
43
        Base::Console().Log("Couldn't disconnect from spacenav daemon\n");
44
    else
45
        Base::Console().Log("Disconnected from spacenav daemon\n");
46
}
47

48
void Gui::GuiNativeEvent::initSpaceball(QMainWindow *window)
49
{
50
    Q_UNUSED(window)
51
    if (spnav_open() == -1) {
52
        Base::Console().Log("Couldn't connect to spacenav daemon. Please ignore if you don't have a spacemouse.\n");
53
    } else {
54
        Base::Console().Log("Connected to spacenav daemon\n");
55
        QSocketNotifier* SpacenavNotifier = new QSocketNotifier(spnav_fd(), QSocketNotifier::Read, this);
56
        connect(SpacenavNotifier, SIGNAL(activated(int)), this, SLOT(pollSpacenav()));
57
        mainApp->setSpaceballPresent(true);
58
    }
59
}
60

61
void Gui::GuiNativeEvent::pollSpacenav()
62
{
63
    spnav_event ev;
64
    while(spnav_poll_event(&ev))
65
    {
66
        switch (ev.type)
67
        {
68
            case SPNAV_EVENT_MOTION:
69
            {
70
                motionDataArray[0] = -ev.motion.x;
71
                motionDataArray[1] = -ev.motion.z;
72
                motionDataArray[2] = -ev.motion.y;
73
                motionDataArray[3] = -ev.motion.rx;
74
                motionDataArray[4] = -ev.motion.rz;
75
                motionDataArray[5] = -ev.motion.ry;
76
                mainApp->postMotionEvent(motionDataArray);
77
                break;
78
            }
79
            case SPNAV_EVENT_BUTTON:
80
            {
81
                mainApp->postButtonEvent(ev.button.bnum, ev.button.press);
82
                break;
83
            }
84
        }
85
    }
86
}
87

88
#include "3Dconnexion/moc_GuiNativeEventLinux.cpp"
89

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.