Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Navigation/MaxNavigationStyle.h"
- #include "View3DInventorViewer.h"
- #include <Inventor/nodes/SoCamera.h>
- #include <Inventor/events/SoMouseButtonEvent.h>
- #include <Inventor/events/SoKeyboardEvent.h>
- #include <QApplication>
- using namespace Gui;
- #define inherited UserNavigationStyle
- TYPESYSTEM_SOURCE(Gui::MaxNavigationStyle, Gui::UserNavigationStyle)
- MaxNavigationStyle::MaxNavigationStyle()
- {}
- MaxNavigationStyle::~MaxNavigationStyle() = default;
- std::string MaxNavigationStyle::userFriendlyName() const
- {
- return "3DS Max";
- }
- const char* MaxNavigationStyle::mouseButtons(ViewerMode mode)
- {
- switch (mode) {
- case NavigationStyle::SELECTION: return QT_TR_NOOP("Left mouse button");
- case NavigationStyle::PANNING: return QT_TR_NOOP("Ctrl + Middle mouse button");
- case NavigationStyle::DRAGGING: return QT_TR_NOOP("Alt + Middle mouse button");
- case NavigationStyle::ZOOMING: return QT_TR_NOOP("Ctrl + Alt + Middle mouse button");
- default: return "No description";
- }
- }
- SbBool MaxNavigationStyle::processSoEvent(const SoEvent* const ev)
- {
- if (this->isSeekMode()) {
- return inherited::processSoEvent(ev);
- }
- if (!this->isSeekMode() && !this->isAnimating() && this->isViewing()) {
- this->setViewing(false);
- }
- const SoType type(ev->getTypeId());
- const SbViewportRegion& vp = viewer->getSoRenderManager()->getViewportRegion();
- const SbVec2s pos(ev->getPosition());
- const SbVec2f posn = normalizePixelPos(pos);
- const SbVec2f prevnormalized = this->lastmouseposition;
- this->lastmouseposition = posn;
- SbBool processed = false;
- bool triedSelectionDrag = false;
- const ViewerMode curmode = this->currentmode;
- ViewerMode newmode = curmode;
- syncModifierKeys(ev);
- if (!viewer->isEditing()) {
- processed = handleEventInForeground(ev);
- if (processed) return true;
- }
- if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
- const auto event = static_cast<const SoKeyboardEvent*>(ev);
- processed = processKeyboardEvent(event);
- }
- if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
- const auto* const event = (const SoMouseButtonEvent*)ev;
- const int button = event->getButton();
- const SbBool press = event->getState() == SoButtonEvent::DOWN;
- switch (button) {
- case SoMouseButtonEvent::BUTTON1:
- this->lockrecenter = true;
- this->button1down = press;
- updateSelectionStartPosition(press, pos);
- if (!press && (this->currentmode == NavigationStyle::DRAGGING)) {
- processed = true;
- } else {
- processed = processClickEvent(event);
- }
- break;
- case SoMouseButtonEvent::BUTTON2:
- this->lockrecenter = true;
- if (!press && (hasDragged || hasPanned || hasZoomed)) {
- processed = true;
- } else if (!press && !viewer->isEditing()) {
- if (this->isPopupMenuEnabled()) {
- this->openPopupMenu(event->getPosition());
- }
- }
- this->button2down = press;
- break;
- case SoMouseButtonEvent::BUTTON3:
- this->button3down = press;
- if (press) {
- this->centerTime = ev->getTime();
- setupPanningPlane(getCamera());
- this->lockrecenter = false;
- }
- break;
- }
- }
- if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) {
- this->lockrecenter = true;
- const auto* const event = (const SoLocation2Event*)ev;
- if (this->currentmode == NavigationStyle::ZOOMING) {
- this->zoomByCursor(posn, prevnormalized);
- processed = true;
- }
- else if (this->currentmode == NavigationStyle::PANNING) {
- float ratio = vp.getViewportAspectRatio();
- panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
- processed = true;
- }
- else if (this->currentmode == NavigationStyle::DRAGGING) {
- this->addToLog(event->getPosition(), event->getTime());
- this->spin(posn);
- moveCursorPosition();
- processed = true;
- }
- }
- enum {
- BUTTON1DOWN = 1 << 0,
- BUTTON3DOWN = 1 << 1,
- CTRLDOWN = 1 << 2,
- SHIFTDOWN = 1 << 3,
- BUTTON2DOWN = 1 << 4,
- ALTDOWN = 1 << 5
- };
- unsigned int combo = (this->button1down ? BUTTON1DOWN : 0)
- | (this->button2down ? BUTTON2DOWN : 0) | (this->button3down ? BUTTON3DOWN : 0)
- | (this->ctrldown ? CTRLDOWN : 0) | (this->shiftdown ? SHIFTDOWN : 0)
- | (this->altdown ? ALTDOWN : 0);
- switch (combo) {
- case 0:
- newmode = NavigationStyle::IDLE;
- break;
- case BUTTON1DOWN:
- newmode = NavigationStyle::SELECTION;
- break;
- // Orbit: Alt + Middle Mouse
- case ALTDOWN | BUTTON3DOWN:
- if (newmode != NavigationStyle::DRAGGING) saveCursorPosition(ev);
- newmode = NavigationStyle::DRAGGING;
- break;
- // Pan: Ctrl + Middle Mouse
- case CTRLDOWN | BUTTON3DOWN:
- newmode = NavigationStyle::PANNING;
- break;
- // Zoom: Ctrl + Alt + Middle Mouse
- case CTRLDOWN | ALTDOWN | BUTTON3DOWN:
- newmode = NavigationStyle::ZOOMING;
- break;
- default:
- if ((curmode == NavigationStyle::PANNING || curmode == NavigationStyle::ZOOMING || curmode == NavigationStyle::DRAGGING) && !this->button3down) {
- newmode = NavigationStyle::IDLE;
- }
- break;
- }
- if (newmode != curmode) {
- this->setViewingMode(newmode);
- }
- if (!processed && !triedSelectionDrag) {
- processed = inherited::processSoEvent(ev);
- }
- return processed;
- }
Advertisement
Add Comment
Please, Sign In to add comment