24
#include "PreCompiled.h"
26
# include <Inventor/nodes/SoCamera.h>
27
# include <QApplication>
30
#include "NavigationStyle.h"
31
#include "SoMouseWheelEvent.h"
32
#include "View3DInventorViewer.h"
41
TYPESYSTEM_SOURCE(Gui::InventorNavigationStyle, Gui::UserNavigationStyle)
43
InventorNavigationStyle::InventorNavigationStyle() = default;
45
InventorNavigationStyle::~InventorNavigationStyle() = default;
47
const char* InventorNavigationStyle::mouseButtons(ViewerMode 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");
59
return "No description";
63
std::string InventorNavigationStyle::userFriendlyName() const
66
return "OpenInventor";
69
SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev)
74
if (this->isSeekMode()) {
75
return inherited::processSoEvent(ev);
78
if (!this->isSeekMode()&& !this->isAnimating() && this->isViewing() )
79
this->setViewing(false);
81
const SoType type(ev->getTypeId());
83
const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
84
const SbVec2s pos(ev->getPosition());
85
const SbVec2f posn = normalizePixelPos(pos);
87
const SbVec2f prevnormalized = this->lastmouseposition;
88
this->lastmouseposition = posn;
94
SbBool processed = false;
96
const ViewerMode curmode = this->currentmode;
97
ViewerMode newmode = curmode;
101
syncModifierKeys(ev);
104
if (!viewer->isEditing()) {
105
processed = handleEventInForeground(ev);
111
if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
112
auto event = static_cast<const SoKeyboardEvent *>(ev);
113
processed = processKeyboardEvent(event);
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;
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;
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;
137
if (tmp.getValue() < dci && !this->lockrecenter) {
142
else if (press && (this->currentmode == NavigationStyle::SEEK_WAIT_MODE)) {
143
newmode = NavigationStyle::SEEK_MODE;
144
this->seekToPoint(pos);
146
this->lockrecenter = true;
148
else if (press && (this->currentmode == NavigationStyle::IDLE)) {
149
this->setViewing(true);
151
this->lockrecenter = true;
153
else if (!press && (this->currentmode == NavigationStyle::DRAGGING)) {
154
this->setViewing(false);
156
this->lockrecenter = true;
158
else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
160
this->lockrecenter = true;
163
processed = processClickEvent(event);
166
case SoMouseButtonEvent::BUTTON2:
169
this->lockrecenter = true;
172
if (!press && (hasDragged || hasPanned || hasZoomed)) {
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());
184
this->button2down = press;
186
case SoMouseButtonEvent::BUTTON3:
188
this->centerTime = ev->getTime();
189
setupPanningPlane(getCamera());
190
this->lockrecenter = false;
193
SbTime tmp = (ev->getTime() - this->centerTime);
194
float dci = (float)QApplication::doubleClickInterval()/1000.0f;
196
if (tmp.getValue() < dci && !this->lockrecenter) {
201
this->button3down = press;
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);
216
else if (this->currentmode == NavigationStyle::PANNING) {
217
float ratio = vp.getViewportAspectRatio();
218
panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
221
else if (this->currentmode == NavigationStyle::DRAGGING) {
222
this->addToLog(event->getPosition(), event->getTime());
224
moveCursorPosition();
230
if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
231
const auto event = static_cast<const SoMotion3Event *>(ev);
233
this->processMotionEvent(event);
238
BUTTON1DOWN = 1 << 0,
239
BUTTON3DOWN = 1 << 1,
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);
253
if (curmode == NavigationStyle::SPINNING) { break; }
254
newmode = NavigationStyle::IDLE;
256
if (curmode == NavigationStyle::DRAGGING) {
258
newmode = NavigationStyle::SPINNING;
262
if (curmode == NavigationStyle::SELECTION) { break; }
263
if (newmode != NavigationStyle::DRAGGING) {
264
saveCursorPosition(ev);
266
newmode = NavigationStyle::DRAGGING;
269
case CTRLDOWN|SHIFTDOWN:
270
case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN:
271
newmode = NavigationStyle::PANNING;
274
case CTRLDOWN|BUTTON1DOWN:
276
case SHIFTDOWN|BUTTON1DOWN:
277
newmode = NavigationStyle::SELECTION;
279
case BUTTON1DOWN|BUTTON3DOWN:
280
case CTRLDOWN|BUTTON3DOWN:
281
case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN:
282
newmode = NavigationStyle::ZOOMING;
290
if (this->button1down && (this->button2down || this->button3down)) {
295
if (viewer->isEditing() && curmode == NavigationStyle::SELECTION && newmode != NavigationStyle::IDLE) {
296
newmode = NavigationStyle::SELECTION;
300
if (newmode != curmode) {
301
this->setViewingMode(newmode);
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);