1
/***************************************************************************
2
* Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
# include <Inventor/nodes/SoCamera.h>
27
# include <QApplication>
30
#include "NavigationStyle.h"
31
#include "View3DInventorViewer.h"
36
// ----------------------------------------------------------------------------------
38
/* TRANSLATOR Gui::BlenderNavigationStyle */
40
TYPESYSTEM_SOURCE(Gui::BlenderNavigationStyle, Gui::UserNavigationStyle)
42
BlenderNavigationStyle::BlenderNavigationStyle() : lockButton1(false)
46
BlenderNavigationStyle::~BlenderNavigationStyle() = default;
48
const char* BlenderNavigationStyle::mouseButtons(ViewerMode mode)
51
case NavigationStyle::SELECTION:
52
return QT_TR_NOOP("Press left mouse button");
53
case NavigationStyle::PANNING:
54
return QT_TR_NOOP("Press SHIFT and middle mouse button");
55
case NavigationStyle::DRAGGING:
56
return QT_TR_NOOP("Press middle mouse button");
57
case NavigationStyle::ZOOMING:
58
return QT_TR_NOOP("Scroll mouse wheel");
60
return "No description";
64
SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev)
66
// Events when in "ready-to-seek" mode are ignored, except those
67
// which influence the seek mode itself -- these are handled further
68
// up the inheritance hierarchy.
69
if (this->isSeekMode()) {
70
return inherited::processSoEvent(ev);
72
// Switch off viewing mode (Bug #0000911)
73
if (!this->isSeekMode() && !this->isAnimating() && this->isViewing())
74
this->setViewing(false); // by default disable viewing mode to render the scene
76
const SoType type(ev->getTypeId());
78
const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
79
const SbVec2s pos(ev->getPosition());
80
const SbVec2f posn = normalizePixelPos(pos);
82
const SbVec2f prevnormalized = this->lastmouseposition;
83
this->lastmouseposition = posn;
85
// Set to true if any event processing happened. Note that it is not
86
// necessary to restrict ourselves to only do one "action" for an
87
// event, we only need this flag to see if any processing happened
89
SbBool processed = false;
91
const ViewerMode curmode = this->currentmode;
92
ViewerMode newmode = curmode;
94
// Mismatches in state of the modifier keys happens if the user
95
// presses or releases them outside the viewer window.
98
// give the nodes in the foreground root the chance to handle events (e.g color bar)
99
if (!viewer->isEditing()) {
100
processed = handleEventInForeground(ev);
106
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
107
const auto event = static_cast<const SoKeyboardEvent *>(ev);
108
processed = processKeyboardEvent(event);
111
// Mouse Button / Spaceball Button handling
112
if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
113
const auto * const event = (const SoMouseButtonEvent *) ev;
114
const int button = event->getButton();
115
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
117
//SoDebugError::postInfo("processSoEvent", "button = %d", button);
119
case SoMouseButtonEvent::BUTTON1:
120
this->lockrecenter = true;
121
this->button1down = press;
122
if (press && (this->currentmode == NavigationStyle::SEEK_WAIT_MODE)) {
123
newmode = NavigationStyle::SEEK_MODE;
124
this->seekToPoint(pos); // implicitly calls interactiveCountInc()
127
else if (press && (this->currentmode == NavigationStyle::PANNING ||
128
this->currentmode == NavigationStyle::ZOOMING)) {
129
newmode = NavigationStyle::DRAGGING;
130
saveCursorPosition(ev);
131
this->centerTime = ev->getTime();
134
else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) {
137
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
141
processed = processClickEvent(event);
144
case SoMouseButtonEvent::BUTTON2:
145
// If we are in edit mode then simply ignore the RMB events
146
// to pass the event to the base class.
147
this->lockrecenter = true;
149
// Don't show the context menu after dragging, panning or zooming
150
if (!press && (hasDragged || hasPanned || hasZoomed)) {
153
else if (!press && !viewer->isEditing()) {
154
if (this->currentmode != NavigationStyle::ZOOMING &&
155
this->currentmode != NavigationStyle::PANNING &&
156
this->currentmode != NavigationStyle::DRAGGING) {
157
if (this->isPopupMenuEnabled()) {
158
this->openPopupMenu(event->getPosition());
162
// Alternative way of rotating & zooming
163
if (press && (this->currentmode == NavigationStyle::PANNING ||
164
this->currentmode == NavigationStyle::ZOOMING)) {
165
newmode = NavigationStyle::DRAGGING;
166
saveCursorPosition(ev);
167
this->centerTime = ev->getTime();
170
this->button2down = press;
172
case SoMouseButtonEvent::BUTTON3:
174
this->centerTime = ev->getTime();
175
setupPanningPlane(getCamera());
176
this->lockrecenter = false;
179
SbTime tmp = (ev->getTime() - this->centerTime);
180
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
181
// is it just a middle click?
182
if (tmp.getValue() < dci && !this->lockrecenter) {
187
this->button3down = press;
194
// Mouse Movement handling
195
if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) {
196
this->lockrecenter = true;
197
const auto * const event = (const SoLocation2Event *) ev;
198
if (this->currentmode == NavigationStyle::ZOOMING) {
199
this->zoomByCursor(posn, prevnormalized);
200
newmode = NavigationStyle::SELECTION;
203
else if (this->currentmode == NavigationStyle::PANNING) {
204
float ratio = vp.getViewportAspectRatio();
205
panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
206
newmode = NavigationStyle::SELECTION;
209
else if (this->currentmode == NavigationStyle::DRAGGING) {
210
this->addToLog(event->getPosition(), event->getTime());
212
moveCursorPosition();
217
// Spaceball & Joystick handling
218
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
219
const auto * const event = static_cast<const SoMotion3Event *>(ev);
221
this->processMotionEvent(event);
226
BUTTON1DOWN = 1 << 0,
227
BUTTON3DOWN = 1 << 1,
233
(this->button1down ? BUTTON1DOWN : 0) |
234
(this->button2down ? BUTTON2DOWN : 0) |
235
(this->button3down ? BUTTON3DOWN : 0) |
236
(this->ctrldown ? CTRLDOWN : 0) |
237
(this->shiftdown ? SHIFTDOWN : 0);
241
if (curmode == NavigationStyle::SPINNING) { break; }
242
newmode = NavigationStyle::IDLE;
243
// The left mouse button has been released right now
244
if (this->lockButton1) {
245
this->lockButton1 = false;
246
if (curmode != NavigationStyle::SELECTION) {
252
case CTRLDOWN|BUTTON1DOWN:
253
// make sure not to change the selection when stopping spinning
254
if (curmode == NavigationStyle::SPINNING
255
|| (this->lockButton1 && curmode != NavigationStyle::SELECTION)) {
256
newmode = NavigationStyle::IDLE;
259
newmode = NavigationStyle::SELECTION;
262
case BUTTON1DOWN|BUTTON2DOWN:
263
newmode = NavigationStyle::PANNING;
265
case SHIFTDOWN|BUTTON3DOWN:
266
newmode = NavigationStyle::PANNING;
269
if (newmode != NavigationStyle::DRAGGING) {
270
saveCursorPosition(ev);
272
newmode = NavigationStyle::DRAGGING;
274
case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN:
275
case CTRLDOWN|BUTTON3DOWN:
276
newmode = NavigationStyle::ZOOMING;
283
// If the selection button is pressed together with another button
284
// and the other button is released, don't switch to selection mode.
285
// Process when selection button is pressed together with other buttons that could trigger different actions.
286
if (this->button1down && (this->button2down || this->button3down)) {
287
this->lockButton1 = true;
291
// Prevent interrupting rubber-band selection in sketcher
292
if (viewer->isEditing() && curmode == NavigationStyle::SELECTION && newmode != NavigationStyle::IDLE) {
293
newmode = NavigationStyle::SELECTION;
297
if (newmode != curmode) {
298
this->setViewingMode(newmode);
301
// If not handled in this class, pass on upwards in the inheritance
304
processed = inherited::processSoEvent(ev);