| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <Inventor/nodes/SoCamera.h> |
| | #include <QApplication> |
| |
|
| |
|
| | #include "Navigation/NavigationStyle.h" |
| | #include "View3DInventorViewer.h" |
| |
|
| |
|
| | using namespace Gui; |
| |
|
| | |
| |
|
| | |
| |
|
| | TYPESYSTEM_SOURCE(Gui::OpenSCADNavigationStyle, Gui::UserNavigationStyle) |
| |
|
| | OpenSCADNavigationStyle::OpenSCADNavigationStyle() = default; |
| |
|
| | OpenSCADNavigationStyle::~OpenSCADNavigationStyle() = default; |
| |
|
| | const char* OpenSCADNavigationStyle::mouseButtons(ViewerMode mode) |
| | { |
| | switch (mode) { |
| | case NavigationStyle::SELECTION: |
| | return QT_TR_NOOP("Press left mouse button"); |
| | case NavigationStyle::PANNING: |
| | return QT_TR_NOOP("Press right mouse button and move mouse"); |
| | case NavigationStyle::DRAGGING: |
| | return QT_TR_NOOP("Press left mouse button and move mouse"); |
| | case NavigationStyle::ZOOMING: |
| | return QT_TR_NOOP("Press middle mouse button or SHIFT and right mouse button"); |
| | default: |
| | return "No description"; |
| | } |
| | } |
| |
|
| | SbBool OpenSCADNavigationStyle::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; |
| |
|
| | 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 event = (const SoMouseButtonEvent*)ev; |
| | const int button = event->getButton(); |
| | const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; |
| |
|
| | switch (button) { |
| | case SoMouseButtonEvent::BUTTON1: |
| | this->lockrecenter = true; |
| | this->button1down = press; |
| | if (press && (curmode == NavigationStyle::SEEK_WAIT_MODE)) { |
| | newmode = NavigationStyle::SEEK_MODE; |
| | this->seekToPoint(pos); |
| | processed = true; |
| | } |
| | else if (!press && (curmode == NavigationStyle::ZOOMING)) { |
| | newmode = NavigationStyle::IDLE; |
| | processed = true; |
| | } |
| | else if (!press && (curmode == NavigationStyle::DRAGGING)) { |
| | this->setViewing(false); |
| | processed = true; |
| | } |
| | else if (viewer->isEditing() && (curmode == NavigationStyle::SPINNING)) { |
| | processed = true; |
| | } |
| | else { |
| | processed = processClickEvent(event); |
| | } |
| | break; |
| | case SoMouseButtonEvent::BUTTON2: |
| | |
| | |
| | this->lockrecenter = true; |
| | this->button2down = press; |
| |
|
| | |
| | if (!press && (hasDragged || hasPanned || hasZoomed)) { |
| | processed = true; |
| | } |
| | else if (!press && !viewer->isEditing()) { |
| | if (this->currentmode != NavigationStyle::ZOOMING |
| | && this->currentmode != NavigationStyle::DRAGGING) { |
| | if (this->isPopupMenuEnabled()) { |
| | this->openPopupMenu(event->getPosition()); |
| | } |
| | } |
| | } |
| | |
| | if (press |
| | && (curmode == NavigationStyle::PANNING || curmode == NavigationStyle::ZOOMING)) { |
| | newmode = NavigationStyle::DRAGGING; |
| | saveCursorPosition(ev); |
| | this->centerTime = ev->getTime(); |
| | processed = true; |
| | } |
| | else if (!press && (curmode == NavigationStyle::DRAGGING)) { |
| | newmode = NavigationStyle::IDLE; |
| | processed = true; |
| | } |
| | break; |
| | case SoMouseButtonEvent::BUTTON3: |
| | this->button3down = press; |
| | if (press) { |
| | this->centerTime = ev->getTime(); |
| | setupPanningPlane(getCamera()); |
| | this->lockrecenter = false; |
| | } |
| | else if (curmode == NavigationStyle::PANNING) { |
| | newmode = NavigationStyle::IDLE; |
| | processed = true; |
| | } |
| | break; |
| | default: |
| | break; |
| | } |
| | } |
| |
|
| | |
| | if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) { |
| | this->lockrecenter = true; |
| | const auto event = (const SoLocation2Event*)ev; |
| | if (!viewer->isEditing() && curmode == NavigationStyle::SELECTION) { |
| | if (button1down && isDraggerUnderCursor(ev->getPosition())) { |
| | newmode = NavigationStyle::INTERACT; |
| | } |
| | else { |
| | newmode = NavigationStyle::DRAGGING; |
| | saveCursorPosition(ev); |
| | this->centerTime = ev->getTime(); |
| | } |
| | } |
| | else if (curmode == NavigationStyle::ZOOMING) { |
| | |
| | |
| | float value = (posn[1] - prevnormalized[1]) * 10.0f; |
| | if (this->invertZoom) { |
| | value = -value; |
| | } |
| | zoom(viewer->getSoRenderManager()->getCamera(), value); |
| | processed = true; |
| | } |
| | else if (curmode == NavigationStyle::PANNING) { |
| | float ratio = vp.getViewportAspectRatio(); |
| | panCamera( |
| | viewer->getSoRenderManager()->getCamera(), |
| | ratio, |
| | this->panningplane, |
| | posn, |
| | prevnormalized |
| | ); |
| | processed = true; |
| | } |
| | else if (curmode == NavigationStyle::DRAGGING) { |
| | this->addToLog(event->getPosition(), event->getTime()); |
| | this->spin(posn); |
| | moveCursorPosition(); |
| | processed = true; |
| | } |
| | } |
| |
|
| | |
| | if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) { |
| | const auto event = static_cast<const SoMotion3Event*>(ev); |
| | if (event) { |
| | this->processMotionEvent(event); |
| | } |
| | processed = true; |
| | } |
| |
|
| | enum |
| | { |
| | BUTTON1DOWN = 1 << 0, |
| | BUTTON3DOWN = 1 << 1, |
| | CTRLDOWN = 1 << 2, |
| | SHIFTDOWN = 1 << 3, |
| | BUTTON2DOWN = 1 << 4 |
| | }; |
| | unsigned int combo = (this->button1down ? BUTTON1DOWN : 0) |
| | | (this->button2down ? BUTTON2DOWN : 0) | (this->button3down ? BUTTON3DOWN : 0) |
| | | (this->ctrldown ? CTRLDOWN : 0) | (this->shiftdown ? SHIFTDOWN : 0); |
| |
|
| | switch (combo) { |
| | case 0: |
| | if (curmode == NavigationStyle::SPINNING) { |
| | break; |
| | } |
| | newmode = NavigationStyle::IDLE; |
| | break; |
| | case BUTTON1DOWN: |
| | if (newmode != NavigationStyle::DRAGGING && newmode != NavigationStyle::INTERACT) { |
| | newmode = NavigationStyle::SELECTION; |
| | } |
| | break; |
| | case BUTTON2DOWN: |
| | newmode = NavigationStyle::PANNING; |
| | break; |
| | case BUTTON3DOWN: |
| | case SHIFTDOWN | BUTTON2DOWN: |
| | case SHIFTDOWN | BUTTON3DOWN: |
| | newmode = NavigationStyle::ZOOMING; |
| | break; |
| | default: |
| | break; |
| | } |
| |
|
| | |
| | |
| | if (this->button1down && (this->button2down || this->button3down)) { |
| | processed = true; |
| | } |
| |
|
| | |
| | if (viewer->isEditing() && curmode == NavigationStyle::SELECTION |
| | && newmode != NavigationStyle::IDLE) { |
| | newmode = NavigationStyle::SELECTION; |
| | processed = false; |
| | } |
| |
|
| | |
| | if (newmode == IDLE && !button1down && !button2down && !button3down) { |
| | hasPanned = false; |
| | hasDragged = false; |
| | hasZoomed = false; |
| | } |
| |
|
| | if (newmode != curmode) { |
| | this->setViewingMode(newmode); |
| | } |
| |
|
| | |
| | |
| | if (!processed) { |
| | processed = inherited::processSoEvent(ev); |
| | } |
| | return processed; |
| | } |
| |
|