FreeCAD

Форк
0
/
InventorNavigationStyle.cpp 
316 строк · 11.9 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.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

24
#include "PreCompiled.h"
25
#ifndef _PreComp_
26
# include <Inventor/nodes/SoCamera.h>
27
# include <QApplication>
28
#endif
29

30
#include "NavigationStyle.h"
31
#include "SoMouseWheelEvent.h"
32
#include "View3DInventorViewer.h"
33

34

35
using namespace Gui;
36

37
// ----------------------------------------------------------------------------------
38

39
/* TRANSLATOR Gui::InventorNavigationStyle */
40

41
TYPESYSTEM_SOURCE(Gui::InventorNavigationStyle, Gui::UserNavigationStyle)
42

43
InventorNavigationStyle::InventorNavigationStyle() = default;
44

45
InventorNavigationStyle::~InventorNavigationStyle() = default;
46

47
const char* InventorNavigationStyle::mouseButtons(ViewerMode mode)
48
{
49
    switch (mode) {
50
    case NavigationStyle::SELECTION:
51
        return QT_TR_NOOP("Press CTRL and left mouse button");
52
    case NavigationStyle::PANNING:
53
        return QT_TR_NOOP("Press middle mouse button");
54
    case NavigationStyle::DRAGGING:
55
        return QT_TR_NOOP("Press left mouse button");
56
    case NavigationStyle::ZOOMING:
57
        return QT_TR_NOOP("Scroll middle mouse button");
58
    default:
59
        return "No description";
60
    }
61
}
62

63
std::string InventorNavigationStyle::userFriendlyName() const
64
{
65
    // do not mark this for translation
66
    return "OpenInventor";
67
}
68

69
SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
70
{
71
    // Events when in "ready-to-seek" mode are ignored, except those
72
    // which influence the seek mode itself -- these are handled further
73
    // up the inheritance hierarchy.
74
    if (this->isSeekMode()) {
75
        return inherited::processSoEvent(ev);
76
    }
77
    // Switch off viewing mode (Bug #0000911)
78
    if (!this->isSeekMode()&& !this->isAnimating() && this->isViewing() )
79
        this->setViewing(false); // by default disable viewing mode to render the scene
80

81
    const SoType type(ev->getTypeId());
82

83
    const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
84
    const SbVec2s pos(ev->getPosition());
85
    const SbVec2f posn = normalizePixelPos(pos);
86

87
    const SbVec2f prevnormalized = this->lastmouseposition;
88
    this->lastmouseposition = posn;
89

90
    // Set to true if any event processing happened. Note that it is not
91
    // necessary to restrict ourselves to only do one "action" for an
92
    // event, we only need this flag to see if any processing happened
93
    // at all.
94
    SbBool processed = false;
95

96
    const ViewerMode curmode = this->currentmode;
97
    ViewerMode newmode = curmode;
98

99
    // Mismatches in state of the modifier keys happens if the user
100
    // presses or releases them outside the viewer window.
101
    syncModifierKeys(ev);
102

103
    // give the nodes in the foreground root the chance to handle events (e.g color bar)
104
    if (!viewer->isEditing()) {
105
        processed = handleEventInForeground(ev);
106
        if (processed)
107
            return true;
108
    }
109

110
    // Keyboard handling
111
    if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
112
        auto event = static_cast<const SoKeyboardEvent *>(ev);
113
        processed = processKeyboardEvent(event);
114
    }
115

116
    // Mouse Button / Spaceball Button handling
117
    if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
118
        const auto event = (const SoMouseButtonEvent *) ev;
119
        const int button = event->getButton();
120
        const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
121

122
        // SoDebugError::postInfo("processSoEvent", "button = %d", button);
123
        switch (button) {
124
        case SoMouseButtonEvent::BUTTON1:
125
            this->button1down = press;
126
            if (press && ev->wasShiftDown() &&
127
                (this->currentmode != NavigationStyle::SELECTION)) {
128
                this->centerTime = ev->getTime();
129
                setupPanningPlane(getCamera());
130
                this->lockrecenter = false;
131
            }
132
            else if (!press && ev->wasShiftDown() &&
133
                (this->currentmode != NavigationStyle::SELECTION)) {
134
                SbTime tmp = (ev->getTime() - this->centerTime);
135
                float dci = (float)QApplication::doubleClickInterval()/1000.0f;
136
                // is it just a left click?
137
                if (tmp.getValue() < dci && !this->lockrecenter) {
138
                    lookAtPoint(pos);
139
                    processed = true;
140
                }
141
            }
142
            else if (press && (this->currentmode == NavigationStyle::SEEK_WAIT_MODE)) {
143
                newmode = NavigationStyle::SEEK_MODE;
144
                this->seekToPoint(pos); // implicitly calls interactiveCountInc()
145
                processed = true;
146
                this->lockrecenter = true;
147
            }
148
            else if (press && (this->currentmode == NavigationStyle::IDLE)) {
149
                this->setViewing(true);
150
                processed = true;
151
                this->lockrecenter = true;
152
            }
153
            else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) {
154
                this->setViewing(false);
155
                processed = true;
156
                this->lockrecenter = true;
157
            }
158
            else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
159
                processed = true;
160
                this->lockrecenter = true;
161
            }
162
            else {
163
                processed = processClickEvent(event);
164
            }
165
            break;
166
        case SoMouseButtonEvent::BUTTON2:
167
            // If we are in edit mode then simply ignore the RMB events
168
            // to pass the event to the base class.
169
            this->lockrecenter = true;
170

171
            // Don't show the context menu after dragging, panning or zooming
172
            if (!press && (hasDragged || hasPanned || hasZoomed)) {
173
                processed = true;
174
            }
175
            else if (!press && !viewer->isEditing()) {
176
                if (this->currentmode != NavigationStyle::ZOOMING &&
177
                    this->currentmode != NavigationStyle::PANNING &&
178
                    this->currentmode != NavigationStyle::DRAGGING) {
179
                    if (this->isPopupMenuEnabled()) {
180
                        this->openPopupMenu(event->getPosition());
181
                    }
182
                }
183
            }
184
            this->button2down = press;
185
            break;
186
        case SoMouseButtonEvent::BUTTON3:
187
            if (press) {
188
                this->centerTime = ev->getTime();
189
                setupPanningPlane(getCamera());
190
                this->lockrecenter = false;
191
            }
192
            else {
193
                SbTime tmp = (ev->getTime() - this->centerTime);
194
                float dci = (float)QApplication::doubleClickInterval()/1000.0f;
195
                // is it just a middle click?
196
                if (tmp.getValue() < dci && !this->lockrecenter) {
197
                    lookAtPoint(pos);
198
                    processed = true;
199
                }
200
            }
201
            this->button3down = press;
202
            break;
203
        default:
204
            break;
205
        }
206
    }
207

208
    // Mouse Movement handling
209
    if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) {
210
        this->lockrecenter = true;
211
        const auto event = (const SoLocation2Event *) ev;
212
        if (this->currentmode == NavigationStyle::ZOOMING) {
213
            this->zoomByCursor(posn, prevnormalized);
214
            processed = true;
215
        }
216
        else if (this->currentmode == NavigationStyle::PANNING) {
217
            float ratio = vp.getViewportAspectRatio();
218
            panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
219
            processed = true;
220
        }
221
        else if (this->currentmode == NavigationStyle::DRAGGING) {
222
            this->addToLog(event->getPosition(), event->getTime());
223
            this->spin(posn);
224
            moveCursorPosition();
225
            processed = true;
226
        }
227
    }
228

229
    // Spaceball & Joystick handling
230
    if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
231
        const auto event = static_cast<const SoMotion3Event *>(ev);
232
        if (event)
233
            this->processMotionEvent(event);
234
        processed = true;
235
    }
236

237
    enum {
238
        BUTTON1DOWN = 1 << 0,
239
        BUTTON3DOWN = 1 << 1,
240
        CTRLDOWN =    1 << 2,
241
        SHIFTDOWN =   1 << 3,
242
        BUTTON2DOWN = 1 << 4
243
    };
244
    unsigned int combo =
245
        (this->button1down ? BUTTON1DOWN : 0) |
246
        (this->button2down ? BUTTON2DOWN : 0) |
247
        (this->button3down ? BUTTON3DOWN : 0) |
248
        (this->ctrldown ? CTRLDOWN : 0) |
249
        (this->shiftdown ? SHIFTDOWN : 0);
250

251
    switch (combo) {
252
    case 0:
253
        if (curmode == NavigationStyle::SPINNING) { break; }
254
        newmode = NavigationStyle::IDLE;
255

256
        if (curmode == NavigationStyle::DRAGGING) {
257
            if (doSpin())
258
                newmode = NavigationStyle::SPINNING;
259
        }
260
        break;
261
    case BUTTON1DOWN:
262
        if (curmode == NavigationStyle::SELECTION) { break; }
263
        if (newmode != NavigationStyle::DRAGGING) {
264
            saveCursorPosition(ev);
265
        }
266
        newmode = NavigationStyle::DRAGGING;
267
        break;
268
    case BUTTON3DOWN:
269
    case CTRLDOWN|SHIFTDOWN:
270
    case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN:
271
        newmode = NavigationStyle::PANNING;
272
        break;
273
    case CTRLDOWN:
274
    case CTRLDOWN|BUTTON1DOWN:
275
    case SHIFTDOWN:
276
    case SHIFTDOWN|BUTTON1DOWN:
277
        newmode = NavigationStyle::SELECTION;
278
        break;
279
    case BUTTON1DOWN|BUTTON3DOWN:
280
    case CTRLDOWN|BUTTON3DOWN:
281
    case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN:
282
        newmode = NavigationStyle::ZOOMING;
283
        break;
284

285
    default:
286
        break;
287
    }
288

289
    // Process when selection button is pressed together with other buttons that could trigger different actions.
290
    if (this->button1down && (this->button2down || this->button3down)) {
291
        processed = true;
292
    }
293

294
    // Prevent interrupting rubber-band selection in sketcher
295
    if (viewer->isEditing() && curmode == NavigationStyle::SELECTION && newmode != NavigationStyle::IDLE) {
296
        newmode = NavigationStyle::SELECTION;
297
        processed = false;
298
    }
299

300
    if (newmode != curmode) {
301
        this->setViewingMode(newmode);
302
    }
303

304
    // If not handled in this class, pass on upwards in the inheritance
305
    // hierarchy.
306
    if (ev->isOfType(SoMouseWheelEvent::getClassTypeId()))
307
        processed = inherited::processSoEvent(ev);
308
    else if ((curmode == NavigationStyle::SELECTION ||
309
         newmode == NavigationStyle::SELECTION ||
310
         viewer->isEditing()) && !processed)
311
        processed = inherited::processSoEvent(ev);
312
    else
313
        return true;
314

315
    return processed;
316
}
317

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

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

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

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