Guest User

Untitled

a guest
Aug 12th, 2026
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. #include "Navigation/MaxNavigationStyle.h"
  2. #include "View3DInventorViewer.h"
  3. #include <Inventor/nodes/SoCamera.h>
  4. #include <Inventor/events/SoMouseButtonEvent.h>
  5. #include <Inventor/events/SoKeyboardEvent.h>
  6. #include <QApplication>
  7.  
  8. using namespace Gui;
  9.  
  10. #define inherited UserNavigationStyle
  11.  
  12. TYPESYSTEM_SOURCE(Gui::MaxNavigationStyle, Gui::UserNavigationStyle)
  13.  
  14. MaxNavigationStyle::MaxNavigationStyle()
  15. {}
  16.  
  17. MaxNavigationStyle::~MaxNavigationStyle() = default;
  18.  
  19. std::string MaxNavigationStyle::userFriendlyName() const
  20. {
  21. return "3DS Max";
  22. }
  23.  
  24. const char* MaxNavigationStyle::mouseButtons(ViewerMode mode)
  25. {
  26. switch (mode) {
  27. case NavigationStyle::SELECTION: return QT_TR_NOOP("Left mouse button");
  28. case NavigationStyle::PANNING: return QT_TR_NOOP("Ctrl + Middle mouse button");
  29. case NavigationStyle::DRAGGING: return QT_TR_NOOP("Alt + Middle mouse button");
  30. case NavigationStyle::ZOOMING: return QT_TR_NOOP("Ctrl + Alt + Middle mouse button");
  31. default: return "No description";
  32. }
  33. }
  34.  
  35. SbBool MaxNavigationStyle::processSoEvent(const SoEvent* const ev)
  36. {
  37. if (this->isSeekMode()) {
  38. return inherited::processSoEvent(ev);
  39. }
  40. if (!this->isSeekMode() && !this->isAnimating() && this->isViewing()) {
  41. this->setViewing(false);
  42. }
  43.  
  44. const SoType type(ev->getTypeId());
  45. const SbViewportRegion& vp = viewer->getSoRenderManager()->getViewportRegion();
  46. const SbVec2s pos(ev->getPosition());
  47. const SbVec2f posn = normalizePixelPos(pos);
  48. const SbVec2f prevnormalized = this->lastmouseposition;
  49. this->lastmouseposition = posn;
  50.  
  51. SbBool processed = false;
  52. bool triedSelectionDrag = false;
  53. const ViewerMode curmode = this->currentmode;
  54. ViewerMode newmode = curmode;
  55.  
  56. syncModifierKeys(ev);
  57.  
  58. if (!viewer->isEditing()) {
  59. processed = handleEventInForeground(ev);
  60. if (processed) return true;
  61. }
  62.  
  63. if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
  64. const auto event = static_cast<const SoKeyboardEvent*>(ev);
  65. processed = processKeyboardEvent(event);
  66. }
  67.  
  68. if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
  69. const auto* const event = (const SoMouseButtonEvent*)ev;
  70. const int button = event->getButton();
  71. const SbBool press = event->getState() == SoButtonEvent::DOWN;
  72.  
  73. switch (button) {
  74. case SoMouseButtonEvent::BUTTON1:
  75. this->lockrecenter = true;
  76. this->button1down = press;
  77. updateSelectionStartPosition(press, pos);
  78. if (!press && (this->currentmode == NavigationStyle::DRAGGING)) {
  79. processed = true;
  80. } else {
  81. processed = processClickEvent(event);
  82. }
  83. break;
  84. case SoMouseButtonEvent::BUTTON2:
  85. this->lockrecenter = true;
  86. if (!press && (hasDragged || hasPanned || hasZoomed)) {
  87. processed = true;
  88. } else if (!press && !viewer->isEditing()) {
  89. if (this->isPopupMenuEnabled()) {
  90. this->openPopupMenu(event->getPosition());
  91. }
  92. }
  93. this->button2down = press;
  94. break;
  95. case SoMouseButtonEvent::BUTTON3:
  96. this->button3down = press;
  97. if (press) {
  98. this->centerTime = ev->getTime();
  99. setupPanningPlane(getCamera());
  100. this->lockrecenter = false;
  101. }
  102. break;
  103. }
  104. }
  105.  
  106. if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) {
  107. this->lockrecenter = true;
  108. const auto* const event = (const SoLocation2Event*)ev;
  109. if (this->currentmode == NavigationStyle::ZOOMING) {
  110. this->zoomByCursor(posn, prevnormalized);
  111. processed = true;
  112. }
  113. else if (this->currentmode == NavigationStyle::PANNING) {
  114. float ratio = vp.getViewportAspectRatio();
  115. panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
  116. processed = true;
  117. }
  118. else if (this->currentmode == NavigationStyle::DRAGGING) {
  119. this->addToLog(event->getPosition(), event->getTime());
  120. this->spin(posn);
  121. moveCursorPosition();
  122. processed = true;
  123. }
  124. }
  125.  
  126. enum {
  127. BUTTON1DOWN = 1 << 0,
  128. BUTTON3DOWN = 1 << 1,
  129. CTRLDOWN = 1 << 2,
  130. SHIFTDOWN = 1 << 3,
  131. BUTTON2DOWN = 1 << 4,
  132. ALTDOWN = 1 << 5
  133. };
  134.  
  135. unsigned int combo = (this->button1down ? BUTTON1DOWN : 0)
  136. | (this->button2down ? BUTTON2DOWN : 0) | (this->button3down ? BUTTON3DOWN : 0)
  137. | (this->ctrldown ? CTRLDOWN : 0) | (this->shiftdown ? SHIFTDOWN : 0)
  138. | (this->altdown ? ALTDOWN : 0);
  139.  
  140. switch (combo) {
  141. case 0:
  142. newmode = NavigationStyle::IDLE;
  143. break;
  144. case BUTTON1DOWN:
  145. newmode = NavigationStyle::SELECTION;
  146. break;
  147. // Orbit: Alt + Middle Mouse
  148. case ALTDOWN | BUTTON3DOWN:
  149. if (newmode != NavigationStyle::DRAGGING) saveCursorPosition(ev);
  150. newmode = NavigationStyle::DRAGGING;
  151. break;
  152. // Pan: Ctrl + Middle Mouse
  153. case CTRLDOWN | BUTTON3DOWN:
  154. newmode = NavigationStyle::PANNING;
  155. break;
  156. // Zoom: Ctrl + Alt + Middle Mouse
  157. case CTRLDOWN | ALTDOWN | BUTTON3DOWN:
  158. newmode = NavigationStyle::ZOOMING;
  159. break;
  160. default:
  161. if ((curmode == NavigationStyle::PANNING || curmode == NavigationStyle::ZOOMING || curmode == NavigationStyle::DRAGGING) && !this->button3down) {
  162. newmode = NavigationStyle::IDLE;
  163. }
  164. break;
  165. }
  166.  
  167. if (newmode != curmode) {
  168. this->setViewingMode(newmode);
  169. }
  170.  
  171. if (!processed && !triedSelectionDrag) {
  172. processed = inherited::processSoEvent(ev);
  173. }
  174.  
  175. return processed;
  176. }
Advertisement
Add Comment
Please, Sign In to add comment