[HELP] Maya navigation style

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

[HELP] Maya navigation style

Post by pablogil »

Hi,

I'm creating a new navigation mode similar to 3D modeling software Autodesk Maya or Unity 3D. It goes as follows:
  • orbit: ALT + left mouse button
  • zoom: ALT + right mouse button
  • pan: ALT + middle mouse button
I'm not a coder but I read the structure of the navigation modes and was able to, from the Blender one, create a copy a modify it so I have now a Maya navigation mode =)
I have played with it so that now it almost works perfectly, in fact, I was able to configure so that if I release the mouse buttons but still pushing ALT it finishes the orbit/zoom/pan action which is highly useful and confortable.
The only problem relays with the left mouse button, if I'm orbiting with the pointer inside the part, when I release the button it changes my preselection, and that's not fun, hehehe.

I have seen in other navigation modes that coders had to solve this problem earlier but I can't get it to work with this new Maya one, could you help? here is the full MayaNavigationStyle.cpp:

Code: Select all

/***************************************************************************
 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "PreCompiled.h"
#ifndef _PreComp_
# include <cfloat>
# include "InventorAll.h"
# include <QAction>
# include <QActionGroup>
# include <QApplication>
# include <QByteArray>
# include <QCursor>
# include <QList>
# include <QMenu>
# include <QMetaObject>
# include <QRegExp>
#endif

#include <Inventor/sensors/SoTimerSensor.h>

#include <App/Application.h>
#include "NavigationStyle.h"
#include "View3DInventorViewer.h"
#include "Application.h"
#include "MenuManager.h"
#include "MouseSelection.h"

using namespace Gui;

// ----------------------------------------------------------------------------------

/* TRANSLATOR Gui::MayaNavigationStyle */

TYPESYSTEM_SOURCE(Gui::MayaNavigationStyle, Gui::UserNavigationStyle);

MayaNavigationStyle::MayaNavigationStyle() : lockButton1(FALSE)
{
}

MayaNavigationStyle::~MayaNavigationStyle()
{
}

const char* MayaNavigationStyle::mouseButtons(ViewerMode mode)
{
    switch (mode) {
    case NavigationStyle::SELECTION:
        return QT_TR_NOOP("Press left mouse button");
    case NavigationStyle::PANNING:
        return QT_TR_NOOP("Press ALT and middle mouse button");
    case NavigationStyle::DRAGGING:
        return QT_TR_NOOP("Press ALT and left mouse button");
    case NavigationStyle::ZOOMING:
        return QT_TR_NOOP("Press ALT and right mouse button");
    default:
        return "No description";
    }
}

SbBool MayaNavigationStyle::processSoEvent(const SoEvent * const ev)
{
    // Events when in "ready-to-seek" mode are ignored, except those
    // which influence the seek mode itself -- these are handled further
    // up the inheritance hierarchy.
    if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
    // Switch off viewing mode (Bug #0000911)
    if (!this->isSeekMode() && !this->isAnimating() && this->isViewing())
        this->setViewing(false); // by default disable viewing mode to render the scene

    const SoType type(ev->getTypeId());

    const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
    const SbVec2s size(vp.getViewportSizePixels());
    const SbVec2f prevnormalized = this->lastmouseposition;
    const SbVec2s pos(ev->getPosition());
    const SbVec2f posn((float) pos[0] / (float) std::max((int)(size[0] - 1), 1),
                       (float) pos[1] / (float) std::max((int)(size[1] - 1), 1));

    this->lastmouseposition = posn;

    // Set to TRUE if any event processing happened. Note that it is not
    // necessary to restrict ourselves to only do one "action" for an
    // event, we only need this flag to see if any processing happened
    // at all.
    SbBool processed = FALSE;

    const ViewerMode curmode = this->currentmode;
    ViewerMode newmode = curmode;

    // Mismatches in state of the modifier keys happens if the user
    // presses or releases them outside the viewer window.
    if (this->ctrldown != ev->wasCtrlDown()) {
        this->ctrldown = ev->wasCtrlDown();
    }
    if (this->shiftdown != ev->wasShiftDown()) {
        this->shiftdown = ev->wasShiftDown();
    }
    if (this->altdown != ev->wasAltDown()) {
        this->altdown = ev->wasAltDown();
    }

    // give the nodes in the foreground root the chance to handle events (e.g color bar)
    if (!processed && !viewer->isEditing()) {
        processed = handleEventInForeground(ev);
        if (processed)
            return TRUE;
    }

    // Keyboard handling
    if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
        const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
        const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
        switch (event->getKey()) {
        case SoKeyboardEvent::LEFT_CONTROL:
        case SoKeyboardEvent::RIGHT_CONTROL:
            this->ctrldown = press;
            break;
        case SoKeyboardEvent::LEFT_SHIFT:
        case SoKeyboardEvent::RIGHT_SHIFT:
            this->shiftdown = press;
            break;
        case SoKeyboardEvent::LEFT_ALT:
        case SoKeyboardEvent::RIGHT_ALT:
            this->altdown = press;
            break;
        case SoKeyboardEvent::H:
            processed = TRUE;
            viewer->saveHomePosition();
            break;
        case SoKeyboardEvent::S:
        case SoKeyboardEvent::HOME:
        case SoKeyboardEvent::LEFT_ARROW:
        case SoKeyboardEvent::UP_ARROW:
        case SoKeyboardEvent::RIGHT_ARROW:
        case SoKeyboardEvent::DOWN_ARROW:
            if (!this->isViewing())
                this->setViewing(true);
            break;
        default:
            break;
        }
    }

    // Mouse Button / Spaceball Button handling
    if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
        const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev;
        const int button = event->getButton();
        const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;

        //SoDebugError::postInfo("processSoEvent", "button = %d", button);
        switch (button) {
        case SoMouseButtonEvent::BUTTON1:
            this->lockrecenter = TRUE;
            this->button1down = press;
            if (press && (this->currentmode == NavigationStyle::SEEK_WAIT_MODE)) {
                newmode = NavigationStyle::SEEK_MODE;
                this->seekToPoint(pos); // implicitly calls interactiveCountInc()
                processed = TRUE;
            }
            //else if (press && (this->currentmode == NavigationStyle::IDLE)) {
            //    this->setViewing(true);
            //    processed = TRUE;
            //}
            else if (press && (this->currentmode == NavigationStyle::PANNING ||
                               this->currentmode == NavigationStyle::ZOOMING)) {
                newmode = NavigationStyle::DRAGGING;
                saveCursorPosition(ev);
                this->centerTime = ev->getTime();
                processed = TRUE;
            }
            else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) {
                processed = TRUE;
            }
            break;
        case SoMouseButtonEvent::BUTTON2:
            // If we are in edit mode then simply ignore the RMB events
            // to pass the event to the base class.
            this->lockrecenter = TRUE;
            if (!viewer->isEditing()) {
                // If we are in zoom or pan mode ignore RMB events otherwise
                // the canvas doesn't get any release events 
                if (this->currentmode != NavigationStyle::ZOOMING && 
                    this->currentmode != NavigationStyle::PANNING &&
                    this->currentmode != NavigationStyle::DRAGGING) {
                    if (this->isPopupMenuEnabled()) {
                        if (!press) { // release right mouse button
                            this->openPopupMenu(event->getPosition());
                        }
                    }
                }
            }
            // Alternative way of rotating & zooming
            if (press && (this->currentmode == NavigationStyle::PANNING ||
                          this->currentmode == NavigationStyle::ZOOMING)) {
                newmode = NavigationStyle::DRAGGING;
                saveCursorPosition(ev);
                this->centerTime = ev->getTime();
                processed = TRUE;
            }
            this->button2down = press;
            break;
        case SoMouseButtonEvent::BUTTON3:
            if (press) {
                this->centerTime = ev->getTime();
                float ratio = vp.getViewportAspectRatio();
                SbViewVolume vv = viewer->getSoRenderManager()->getCamera()->getViewVolume(ratio);
                this->panningplane = vv.getPlane(viewer->getSoRenderManager()->getCamera()->focalDistance.getValue());
                this->lockrecenter = FALSE;
            }
            else {
                SbTime tmp = (ev->getTime() - this->centerTime);
                float dci = (float)QApplication::doubleClickInterval()/1000.0f;
                // is it just a middle click?
                if (tmp.getValue() < dci && !this->lockrecenter) {
                    if (!this->lookAtPoint(pos)) {
                        panToCenter(panningplane, posn);
                        this->interactiveCountDec();
                    }
                    processed = TRUE;
                }
            }
            this->button3down = press;
            break;
        case SoMouseButtonEvent::BUTTON4:
            doZoom(viewer->getSoRenderManager()->getCamera(), TRUE, posn);
            processed = TRUE;
            break;
        case SoMouseButtonEvent::BUTTON5:
            doZoom(viewer->getSoRenderManager()->getCamera(), FALSE, posn);
            processed = TRUE;
            break;
        default:
            break;
        }
    }

    // Mouse Movement handling
    if (type.isDerivedFrom(SoLocation2Event::getClassTypeId())) {
        this->lockrecenter = TRUE;
        const SoLocation2Event * 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;
        }
    }

    // Spaceball & Joystick handling
    if (type.isDerivedFrom(SoMotion3Event::getClassTypeId())) {
        const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
        if (event)
            this->processMotionEvent(event);
        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:
        if (curmode == NavigationStyle::DRAGGING) { break; }
        newmode = NavigationStyle::IDLE;
        // The left mouse button has been released right now but
        // we want to avoid that the event is procesed elsewhere
        if (this->lockButton1) {
            this->lockButton1 = FALSE;
            processed = TRUE;
        }

        //if (curmode == NavigationStyle::DRAGGING) {
        //    if (doSpin())
        //        newmode = NavigationStyle::SPINNING;
        //}

        break;

    case ALTDOWN|BUTTON1DOWN:
        newmode = NavigationStyle::DRAGGING;
        break;

    case ALTDOWN|BUTTON2DOWN:
        newmode = NavigationStyle::ZOOMING;
        break;

    case ALTDOWN|BUTTON3DOWN:
        newmode = NavigationStyle::PANNING;
        break;

    case BUTTON1DOWN:
        // make sure not to change the selection when stopping dragging
        if (curmode == NavigationStyle::DRAGGING || this->lockButton1)
            newmode = NavigationStyle::IDLE;
        else
            newmode = NavigationStyle::SELECTION;
        break;

    case ALTDOWN:
            newmode = NavigationStyle::IDLE;
        break;

    default:
        break;
    }

    if (newmode != curmode) {
        this->setViewingMode(newmode);
    }

    // If for dragging the buttons 1 and 3 are pressed
    // but then button 3 is relaesed we shouldn't switch
    // into selection mode.
    if (this->button1down && this->button3down)
        this->lockButton1 = TRUE;

    // If not handled in this class, pass on upwards in the inheritance
    // hierarchy.
    if (/*(curmode == NavigationStyle::SELECTION || viewer->isEditing()) && */!processed)
        processed = inherited::processSoEvent(ev);
    else
        return TRUE;

    return processed;
}
PS - wmayer, I think you can help in here once again... =)

Thanks!
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: [HELP] Maya navigation style

Post by DeepSOIC »

Hi! To keep preselection from kicking in, make sure you keep the viewer mode in either PANNING or SPINNING or ZOOMING. If this is not the cause, absorb the mousemove events by returning true and not propagating the events to inherited.
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [HELP] Maya navigation style

Post by pablogil »

Thanks, seem logical what you say but the problem is that I don't know how to code it... I was asking for someone to fix my code (probably with what you have just suggested...)
Anyone?
Thank you!
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [HELP] Maya navigation style

Post by pablogil »

I finally got it! well, partially... I was able to modify GestureNavigationStyle.cpp into a Maya-Unity navigation style but when I duplicate the file into MayaGestureNavigationStyle.cpp, change all references to GestureNavigationStyle to MayaGestureNavigationStyle, add the corresponding new style to NavigationStyle.h, SoFCDB.cpp and finally compile it, it gives me 2 errors...

I think the best and easier option is just to share with you the modified GestureNavigationStyle.cpp and ask you to correctly duplicate it:

Code: Select all

/***************************************************************************
 *   Copyright (c) Victor Titov (DeepSOIC)                                 *
 *                                           (vv.titov@gmail.com) 2015     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

/*
 *A few notes on this style. (by DeepSOIC)
 *
 * In this style, LMB serves dual purpose. It is selecting objects, as well as
 * spinning the view. The trick that enables it is as follows: The mousedown
 * event is consumed an saved, but otherwise remains unprocessed. If a drag is
 * detected while the button is down, the event is finally consumed (the saved
 * one is discarded), and spinning starts. If there is no drag detected before
 * the button is released, the saved mousedown is propagated to inherited,
 * followed by the mouseup. The same trick is used for RMB, so up to two
 * mousedown can be postponed.
 *
 * This navigation style does not exactly follow the structure of other
 * navigation styles, it does not fill many of the global variables defined in
 * NavigationStyle.
 *
 * This mode does not support locking cursor position on screen when
 * navigating, since with absolute pointing devices like pen and touch it makes
 * no sense (this style was specifically crafted for such devices).
 *
 * In this style, setViewing is not used (because I could not figure out how to
 * use it properly, and it seems to just work without it).
 *
 * This style wasn't tested with space during development (I don't have one).
 */

#include "PreCompiled.h"
#ifndef _PreComp_
# include <cfloat>
# include <QAction>
# include <QActionGroup>
# include <QApplication>
# include <QByteArray>
# include <QCursor>
# include <QList>
# include <QMenu>
# include <QMetaObject>
# include <QRegExp>
#endif

#include <Inventor/sensors/SoTimerSensor.h>

#include <App/Application.h>
#include <Base/Console.h>
#include "NavigationStyle.h"
#include "View3DInventorViewer.h"
#include "Application.h"
#include "MenuManager.h"
#include "MouseSelection.h"
#include "SoTouchEvents.h"

using namespace Gui;

// ----------------------------------------------------------------------------------

/* TRANSLATOR Gui::GestureNavigationStyle */

TYPESYSTEM_SOURCE(Gui::GestureNavigationStyle, Gui::UserNavigationStyle);

GestureNavigationStyle::GestureNavigationStyle()
{
    mouseMoveThreshold = QApplication::startDragDistance();
    mouseMoveThresholdBroken = false;
    mousedownConsumedCount = 0;
    thisClickIsComplex = false;
    inGesture = false;
}

GestureNavigationStyle::~GestureNavigationStyle()
{
}

const char* GestureNavigationStyle::mouseButtons(ViewerMode mode)
{
    switch (mode) {
    case NavigationStyle::SELECTION:
        return QT_TR_NOOP("Tap. Or click left mouse button.");
    case NavigationStyle::PANNING:
        return QT_TR_NOOP("Drag screen with two fingers. Or press right mouse button.");
    case NavigationStyle::DRAGGING:
        return QT_TR_NOOP("Drag the screen with one finger. Or press left mouse button. In Sketcher and other edit modes, hold Alt in addition.");
    case NavigationStyle::ZOOMING:
        return QT_TR_NOOP("Pinch (put two fingers on the screen and drag them apart/to each other). Or scroll middle mouse button. Or PgUp/PgDown on keyboard.");
    default:
        return "No description";
    }
}

/*!
 * \brief GestureNavigationStyle::testMoveThreshold tests if the mouse has moved far enough to constder it a drag.
 * \param currentPos current position of mouse cursor, in local pixel coordinates.
 * \return true if the mouse was moved far enough. False if it's within the boundary. Ignores GestureNavigationStyle::mouseMoveThresholdBroken flag.
 */
bool GestureNavigationStyle::testMoveThreshold(const SbVec2s currentPos) const {
    SbVec2s movedBy = currentPos - this->mousedownPos;
    return SbVec2f(movedBy).length() >= this->mouseMoveThreshold;
}

SbBool GestureNavigationStyle::processSoEvent(const SoEvent * const ev)
{
    // Events when in "ready-to-seek" mode are ignored, except those
    // which influence the seek mode itself -- these are handled further
    // up the inheritance hierarchy.
    if (this->isSeekMode()) { return inherited::processSoEvent(ev); }
    // Switch off viewing mode (Bug #0000911)
    if (!this->isSeekMode()&& !this->isAnimating() && this->isViewing() )
        this->setViewing(false); // by default disable viewing mode to render the scene
    //setViewing() is never used in this style, so the previous if is very unlikely to be hit.

    const SoType type(ev->getTypeId());
    //define some shortcuts...
    bool evIsButton = type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId());
    bool evIsKeyboard = type.isDerivedFrom(SoKeyboardEvent::getClassTypeId());
    bool evIsLoc2 = type.isDerivedFrom(SoLocation2Event::getClassTypeId());//mouse movement
    bool evIsLoc3 = type.isDerivedFrom(SoMotion3Event::getClassTypeId());//spaceball/joystick movement
    bool evIsGesture = type.isDerivedFrom(SoGestureEvent::getClassTypeId());//touchscreen gesture

    const SbVec2f prevnormalized = this->lastmouseposition;
    const SbVec2s pos(ev->getPosition());//not valid for gestures
    const SbVec2f posn = this->normalizePixelPos(pos);
    //pos: local coordinates of event, in pixels
    //posn: normalized local coordinates of event ((0,0) = lower left corner, (1,1) = upper right corner)
    float ratio = viewer->getSoRenderManager()->getViewportRegion().getViewportAspectRatio();

    if (evIsButton || evIsLoc2){
        this->lastmouseposition = posn;
    }

    const ViewerMode curmode = this->currentmode;
    //ViewerMode newmode = curmode;

    //make a unified mouse+modifiers state value (combo)
    enum {
        BUTTON1DOWN = 1 << 0,
        BUTTON2DOWN = 1 << 1,
        BUTTON3DOWN = 1 << 2,
        CTRLDOWN =    1 << 3,
        SHIFTDOWN =   1 << 4,
        ALTDOWN =     1 << 5,
        MASKBUTTONS = BUTTON1DOWN | BUTTON2DOWN | BUTTON3DOWN,
        MASKMODIFIERS = CTRLDOWN | SHIFTDOWN | ALTDOWN
    };
    unsigned int comboBefore = //before = state before this event
        (this->button1down ? BUTTON1DOWN : 0) |
        (this->button2down ? BUTTON2DOWN : 0) |
        (this->button3down ? BUTTON3DOWN : 0) |
        (this->ctrldown ? CTRLDOWN : 0) |
        (this->shiftdown ? SHIFTDOWN : 0) |
        (this->altdown ? ALTDOWN : 0);

    //test for complex clicks
    int cntMBBefore = (comboBefore & BUTTON1DOWN ? 1 : 0 ) //cntMBBefore = how many buttons were down when this event arrived?
                  +(comboBefore & BUTTON2DOWN ? 1 : 0 )
                  +(comboBefore & BUTTON3DOWN ? 1 : 0 );
    if (cntMBBefore>=2) this->thisClickIsComplex = true;
    if (cntMBBefore==0) {//a good chance to reset some click-related stuff
        this->thisClickIsComplex = false;
        this->mousedownConsumedCount = 0;//shouldn't be necessary, just a fail-safe.
    }

    // Mismatches in state of the modifier keys happens if the user
    // presses or releases them outside the viewer window.
    this->ctrldown = ev->wasCtrlDown();
    this->shiftdown = ev->wasShiftDown();
    this->altdown = ev->wasAltDown();
    //before this block, mouse button states in NavigationStyle::buttonXdown reflected those before current event arrived.
    //track mouse button states
    if (evIsButton) {
        const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev;
        const int button = event->getButton();
        const SbBool press //the button was pressed (if false -> released)
                = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
        switch (button) {
        case SoMouseButtonEvent::BUTTON1:
            this->button1down = press;
            break;
        case SoMouseButtonEvent::BUTTON2:
            this->button2down = press;
            break;
        case SoMouseButtonEvent::BUTTON3:
            this->button3down = press;
            break;
        //whatever else, we don't track
        }
    }
    //after this block, the new states of the buttons are already in.

    unsigned int comboAfter = //after = state after this event (current, essentially)
        (this->button1down ? BUTTON1DOWN : 0) |
        (this->button2down ? BUTTON2DOWN : 0) |
        (this->button3down ? BUTTON3DOWN : 0) |
        (this->ctrldown ? CTRLDOWN : 0) |
        (this->shiftdown ? SHIFTDOWN : 0) |
        (this->altdown ? ALTDOWN : 0);

    //test for complex clicks (again)
    int cntMBAfter = (comboAfter & BUTTON1DOWN ? 1 : 0 ) //cntMBAfter = how many buttons were down when this event arrived?
                  +(comboAfter & BUTTON2DOWN ? 1 : 0 )
                  +(comboAfter & BUTTON3DOWN ? 1 : 0 );
    if (cntMBAfter>=2) this->thisClickIsComplex = true;
    //if (cntMBAfter==0) this->thisClickIsComplex = false;//don't reset the flag now, we need to know that this mouseUp was an end of a click that was complex. The flag will reset by the before-check in the next event.

    //test for move detection
    if (evIsLoc2 || evIsButton){
        this->mouseMoveThresholdBroken |= this->testMoveThreshold(pos);
    }

    //track gestures
    if (evIsGesture) {
        const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
        switch(gesture->state) {
        case SoGestureEvent::SbGSStart:
            //assert(!inGesture);//start of another gesture before the first finished? Happens all the time for Pan gesture... No idea why!  --DeepSOIC
            inGesture = true;
        break;
        case SoGestureEvent::SbGSUpdate:
            assert(inGesture);//gesture update without start?
            inGesture = true;
        break;
        case SoGestureEvent::SbGSEnd:
            assert(inGesture);//gesture ended without starting?
            inGesture = false;
        break;
        case SoGestureEvent::SbGsCanceled:
            assert(inGesture);//gesture canceled without starting?
            inGesture=false;
        break;
        default:
            assert(0);//shouldn't happen
            inGesture = false;
        }
    }
    if (evIsButton) {
        if(inGesture){
            inGesture = false;//reset the flag when mouse clicks are received, to ensure enabling mouse navigation back.
            setViewingMode(NavigationStyle::SELECTION);//exit navigation asap, to proceed with regular processing of the click
        }
    }

    bool suppressLMBDrag = false;
    if(viewer->isEditing()){
        //in edit mode, disable lmb dragging (spinning). Holding Alt enables it.
        suppressLMBDrag = !(comboAfter & ALTDOWN);
    }

    //----------all this were preparations. Now comes the event handling! ----------

    SbBool processed = FALSE;//a return value for the  BlahblahblahNavigationStyle::processSoEvent
    bool propagated = false;//an internal flag indicating that the event has been already passed to inherited, to suppress the automatic doing of this at the end.
    //goto finalize = return processed. Might be important to do something before done (none now).

    // give the nodes in the foreground root the chance to handle events (e.g color bar)
    if (!viewer->isEditing()) {
        processed = handleEventInForeground(ev);
    }
    if (processed)
        goto finalize;

    // Mode-independent keyboard handling
    if (evIsKeyboard) {
        const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
        const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
        switch (event->getKey()) {
        case SoKeyboardEvent::H:
            processed = TRUE;
            if(!press){
                SbBool ret = NavigationStyle::lookAtPoint(event->getPosition());
                if(!ret){
                    Base::Console().Warning(
                        "No object under cursor! Can't set new center of rotation.\n");
                }
            }
            break;
        }
    }
    if (processed)
        goto finalize;

    //mode-independent spaceball/joystick handling
    if (evIsLoc3) {
        const SoMotion3Event * const event = static_cast<const SoMotion3Event * const>(ev);
        if (event)
            this->processMotionEvent(event);
        processed = TRUE;
    }
    if (processed)
        goto finalize;

    //all mode-dependent stuff is within this switch.
    switch(curmode){
    case NavigationStyle::IDLE:
    case NavigationStyle::SELECTION:
    case NavigationStyle::INTERACT: {
        //idle and interaction

        //keyboard
        if (evIsKeyboard) {
            const SoKeyboardEvent * const event = (const SoKeyboardEvent *) ev;
            const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;

            switch(event->getKey()){
            case SoKeyboardEvent::S:
            case SoKeyboardEvent::HOME:
            case SoKeyboardEvent::LEFT_ARROW:
            case SoKeyboardEvent::UP_ARROW:
            case SoKeyboardEvent::RIGHT_ARROW:
            case SoKeyboardEvent::DOWN_ARROW:
                processed = inherited::processSoEvent(ev);
                propagated = true;
                break;
            case SoKeyboardEvent::PAGE_UP:
                if(press){
                    doZoom(viewer->getSoRenderManager()->getCamera(), TRUE, posn);
                }
                processed = TRUE;
                break;
            case SoKeyboardEvent::PAGE_DOWN:
                if(press){
                    doZoom(viewer->getSoRenderManager()->getCamera(), FALSE, posn);
                }
                processed = TRUE;
                break;
            }//switch key
        }
        if (processed)
            goto finalize;


        // Mouse Button / Spaceball Button handling
        if (evIsButton) {
            const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev;
            const int button = event->getButton();
            const SbBool press //the button was pressed (if false -> released)
                    = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
            switch(button){
            case SoMouseButtonEvent::BUTTON1:
            case SoMouseButtonEvent::BUTTON2:
                if(press){
                    if(this->thisClickIsComplex && this->mouseMoveThresholdBroken){
                        //this should prevent re-attempts to enter navigation when doing more clicks after a move.
                    } else {
                        //on LMB-down or RMB-down, we don't know yet if we should propagate it or process it. Save the event to be refired later, when it becomes clear.
                        //reset/start move detection machine
                        this->mousedownPos = pos;
                        this->mouseMoveThresholdBroken = false;
                        pan(viewer->getSoRenderManager()->getCamera());//set up panningplane
                        int &cnt = this->mousedownConsumedCount;
                        this->mousedownConsumedEvent[cnt] = *event;//hopefully, a shallow copy is enough. There are no pointers stored in events, apparently. Will loose a subclass, though.
                        cnt++;
                        assert(cnt<=2);
                        if(cnt>sizeof(mousedownConsumedEvent)){
                            cnt=sizeof(mousedownConsumedEvent);//we are in trouble
                        }
                        processed = true;//just consume this event, and wait for the move threshold to be broken to start dragging/panning
                    }
                } else {//release
                    if (button == SoMouseButtonEvent::BUTTON2 && !this->thisClickIsComplex) {
                        if (!viewer->isEditing() && this->isPopupMenuEnabled()) {
                            processed=true;
                            this->openPopupMenu(event->getPosition());
                        }
                    }
                    if(! processed) {
                        //re-synthesize all previously-consumed mouseDowns, if any. They might have been re-synthesized already when threshold was broken.
                        for( int i=0;   i < this->mousedownConsumedCount;   i++ ){
                            inherited::processSoEvent(& (this->mousedownConsumedEvent[i]));//simulate the previously-comsumed mousedown.
                        }
                        this->mousedownConsumedCount = 0;
                        processed = inherited::processSoEvent(ev);//explicitly, just for clarity that we are sending a full click sequence.
                        propagated = true;
                    }
                }
                break;
            case SoMouseButtonEvent::BUTTON3://press the wheel
                // starts PANNING mode
                if(press & this->altdown){
                    setViewingMode(NavigationStyle::PANNING);
                } else if(press){ 
                    // if not PANNING then look at point
                    SbBool ret = NavigationStyle::lookAtPoint(event->getPosition());
                    if(!ret){
                        Base::Console().Warning(
                            "No object under cursor! Can't set new center of rotation.\n");
                    }
                }
                processed = TRUE;
                break;
            case SoMouseButtonEvent::BUTTON4: //(wheel?)
                doZoom(viewer->getSoRenderManager()->getCamera(), TRUE, posn);
                processed = TRUE;
                break;
            case SoMouseButtonEvent::BUTTON5: //(wheel?)
                doZoom(viewer->getSoRenderManager()->getCamera(), FALSE, posn);
                processed = TRUE;
                break;
            }
        }

        //mouse moves - test for move threshold breaking
        if (evIsLoc2) {
            if (this->mouseMoveThresholdBroken && (this->button1down || this->button2down) && mousedownConsumedCount > 0) {
                //mousemovethreshold has JUST been broken

                //test if we should enter navigation
                if ((this->button1down && !suppressLMBDrag && this->altdown) || (this->button2down && this->altdown)) {
                    //yes, we are entering navigation.
                    //throw away consumed mousedowns.
                    this->mousedownConsumedCount = 0;

                    setViewingMode(this->button1down ? NavigationStyle::DRAGGING : NavigationStyle::ZOOMING);
                    processed = true;
                } else {
                    //no, we are not entering navigation.
                    //re-synthesize all previously-consumed mouseDowns, if any, and propagate this mousemove.
                    for( int i=0;   i < this->mousedownConsumedCount;   i++ ){
                        inherited::processSoEvent(& (this->mousedownConsumedEvent[i]));//simulate the previously-comsumed mousedown.
                    }
                    this->mousedownConsumedCount = 0;
                    processed = inherited::processSoEvent(ev);//explicitly, just for clarity that we are sending a full click sequence.
                    propagated = true;
                }
            }
            if (mousedownConsumedCount  > 0)
                processed = true;//if we are still deciding if it's a drag or not, consume mouseMoves.
        }

        //gesture start
        if (evIsGesture && /*!this->button1down &&*/ !this->button2down){//ignore gestures when mouse buttons are down. Button1down check was disabled because of wrong state after doubleclick on sketcher constraint to edit datum
            const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
            if (gesture->state == SoGestureEvent::SbGSStart
                    || gesture->state == SoGestureEvent::SbGSUpdate) {//even if we didn't get a start, assume the first update is a start (sort-of fail-safe).
                if (type.isDerivedFrom(SoGesturePanEvent::getClassTypeId())) {
                    pan(viewer->getSoRenderManager()->getCamera());//set up panning plane
                    setViewingMode(NavigationStyle::PANNING);
                    processed = true;
                } else if (type.isDerivedFrom(SoGesturePinchEvent::getClassTypeId())) {
                    pan(viewer->getSoRenderManager()->getCamera());//set up panning plane
                    setViewingMode(NavigationStyle::DRAGGING);
                    processed = true;
                } //all other gestures - ignore!
            }
        }

        //loc2 (mousemove) - ignore.

    } break;//end of idle and interaction
    case NavigationStyle::DRAGGING:
    case NavigationStyle::ZOOMING:
    case NavigationStyle::PANNING:{
        //actual navigation

        //no keyboard.

        // Mouse Button / Spaceball Button handling
        if (evIsButton) {
            const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev;
            const int button = event->getButton();
            const SbBool press //the button was pressed (if false -> released)
                    = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
            switch(button){
                case SoMouseButtonEvent::BUTTON1:
                case SoMouseButtonEvent::BUTTON2:
                case SoMouseButtonEvent::BUTTON3: // allows to release button3 into SELECTION mode
                    if(comboAfter & BUTTON1DOWN || comboAfter & BUTTON2DOWN) {
                        //don't leave navigation till all buttons have been released
                        setViewingMode((comboAfter & BUTTON1DOWN) ? NavigationStyle::DRAGGING : NavigationStyle::PANNING);
                        processed = true;
                    } else { //all buttons are released
                        //end of dragging/panning/whatever
                        setViewingMode(NavigationStyle::SELECTION);
                        processed = true;
                    } //else of if (some bottons down)
                break;
            } //switch(button)
        } //if(evIsButton)

        //the essence part 1!
        //mouse movement into camera motion. Suppress if in gesture. Ignore until threshold is surpassed.
        if (evIsLoc2 && ! this->inGesture && this->mouseMoveThresholdBroken) {
            const SoLocation2Event * const event = (const SoLocation2Event *) ev;
            if (curmode == NavigationStyle::ZOOMING) {//doesn't happen
                this->zoomByCursor(posn, prevnormalized);
                processed = TRUE;
            } else if (curmode == NavigationStyle::PANNING) {
                panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, posn, prevnormalized);
                processed = TRUE;
            } else if (curmode == NavigationStyle::DRAGGING) {
                if (comboAfter & BUTTON1DOWN && comboAfter & BUTTON2DOWN) {
                    //two mouse buttons down - tilting!
                    NavigationStyle::doRotate(viewer->getSoRenderManager()->getCamera(),
                                              (posn - prevnormalized)[0]*(-2),
                                              SbVec2f(0.5,0.5));
                    processed = TRUE;
                } else {//one mouse button - normal spinning
                    //this will also handle the single-finger drag (there's no gesture used, pseudomouse is enough)
                    //this->addToLog(event->getPosition(), event->getTime());
                    this->spin_simplified(viewer->getSoRenderManager()->getCamera(),
                                          posn, prevnormalized);
                    processed = TRUE;
                }
            }
        }

        //the essence part 2!
        //gesture into camera motion
        if (evIsGesture){
            const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
            assert(gesture);
            if (gesture->state == SoGestureEvent::SbGSEnd) {
                setViewingMode(NavigationStyle::SELECTION);
                processed=true;
            } else if (gesture->state == SoGestureEvent::SbGSUpdate){
                if(type.isDerivedFrom(SoGesturePinchEvent::getClassTypeId())){
                    const SoGesturePinchEvent* const event = static_cast<const SoGesturePinchEvent* const>(ev);
                    if (this->zoomAtCursor){
                        //this is just dealing with the pan part of pinch gesture. Taking care of zooming to pos is done in doZoom.
                        SbVec2f panDist = this->normalizePixelPos(event->deltaCenter.getValue());
                        NavigationStyle::panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, panDist, SbVec2f(0,0));
                    }
                    NavigationStyle::doZoom(viewer->getSoRenderManager()->getCamera(),-logf(event->deltaZoom),this->normalizePixelPos(event->curCenter));
                    if (event->deltaAngle != 0)
                        NavigationStyle::doRotate(viewer->getSoRenderManager()->getCamera(),event->deltaAngle,this->normalizePixelPos(event->curCenter));
                    processed = true;
                }
                if(type.isDerivedFrom(SoGesturePanEvent::getClassTypeId())){
                    const SoGesturePanEvent* const event = static_cast<const SoGesturePanEvent* const>(ev);
                        //this is just dealing with the pan part of pinch gesture. Taking care of zooming to pos is done in doZoom.
                    SbVec2f panDist = this->normalizePixelPos(event->deltaOffset);
                    NavigationStyle::panCamera(viewer->getSoRenderManager()->getCamera(), ratio, this->panningplane, panDist, SbVec2f(0,0));
                    processed = true;
                }
            } else {
                //shouldn't happen. Gestures are not expected to start in the middle of navigation.
                //we'll consume it, without reacting.
                processed=true;
                //This does, unfortunately, happen on regular basis for pan gesture on Windows8.1+Qt4.8
            }
        }

    } break;//end of actual navigation
    case NavigationStyle::SEEK_WAIT_MODE:{
        if (evIsButton) {
            const SoMouseButtonEvent * const event = (const SoMouseButtonEvent *) ev;
            const int button = event->getButton();
            const SbBool press = event->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
            if (button == SoMouseButtonEvent::BUTTON1 && press) {
                this->seekToPoint(pos); // implicitly calls interactiveCountInc()
                this->setViewingMode(NavigationStyle::SEEK_MODE);
                processed = true;
            }
        }
    } ; //not end of SEEK_WAIT_MODE. Fall through by design!!!
    case NavigationStyle::SPINNING:
    case NavigationStyle::SEEK_MODE: {
        //animation modes
        if (!processed) {
            if (evIsButton || evIsGesture || evIsKeyboard || evIsLoc3)
                setViewingMode(NavigationStyle::SELECTION);
        }
    } break; //end of animation modes
    case NavigationStyle::BOXZOOM:
    default:
        //all the rest - will be pass on to inherited, later.
        break;
    }

    if (! processed && ! propagated) {
        processed = inherited::processSoEvent(ev);
        propagated = true;
    }

    //-----------------------end of event handling---------------------
finalize:
    return processed;
}
Do you think it would be possible?
Thank you very much
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [HELP] Maya navigation style

Post by pablogil »

Hi,

DeepSOIC himself (original developer of the Gesture Navitation Style) suggested me to show you the errors I'm getting with my Maya-Gesture navigation style so that you can help me.

Once again, what I did was:
  1. I modified directly GestureNavigationStyle.cpp in order to quickly modify and get the control scheme I wanted: Maya-Unity navigation style (ALT + mouse buttons to orbit, pan or zoom)
  2. When I got it working (it does perfectly :D ) I decided to move it to a new file: MayaGestureNavigationStyle.cpp
  3. To have it correctly working as a separate navigation style I also had to update NavigationStyle.h, SoFCDB.cpp and CMakeLists.txt
  4. When compiling I get 2 errors related with undeclared identifier...
Here is the compile log:

Code: Select all

-- prefix: /usr/local
-- datadir: data
-- docdir: doc
-- includedir: include
-- libdir: /usr/local/lib
-- Detected Homebrew install at /usr/local
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   filesystem
--   program_options
--   regex
--   signals
--   system
--   thread
-- Found Xerces-C: /usr/local/lib/libxerces-c.dylib
-- PyCXX found:
--   Headers:  /Users/pablo/FreeCAD_full_style/free-cad-code/src
--   Sources:  /Users/pablo/FreeCAD_full_style/free-cad-code/src/CXX
-- -- OpenCASCADE Community Edition has been found.
-- -- Found OCE/OpenCASCADE version: 6.8.0
-- -- OCE/OpenCASCADE include directory: /usr/local/Cellar/oce/0.17/OCE.framework/Versions/0.17/Resources/../../../../include/oce
-- -- OCE/OpenCASCADE shared libraries directory: 
-- Could NOT find Spnav (missing:  SPNAV_LIBRARY SPNAV_INCLUDE_DIR) 
-- libshiboken built for Release
-- Found PySide Tools: /usr/local/bin/pyside-uic, /usr/local/bin/pyside-rcc
-- matplotlib not found, Plot module won't be available!
-- Platform is 64-bit, set -D_OCC64
-- Build type: Release
git
/Users/pablo/FreeCAD_full_style/build_master/src/Build/Version.h written
-- Note: Doxygen docs will look better with graphviz's dot installed.
-- Configuring done
CMake Warning (dev):
  Policy CMP0042 is not set: MACOSX_RPATH is enabled by default.  Run "cmake
  --help-policy CMP0042" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

  MACOSX_RPATH is not specified for the following targets:

   Complete
   CompleteGui
   Drawing
   DrawingGui
   Driver
   DriverDAT
   DriverSTL
   DriverUNV
   Fem
   FemGui
   FreeCADApp
   FreeCADBase
   FreeCADGui
   FreeCADGuiPy
   FreeCADMainPy
   Image
   ImageGui
   Import
   ImportGui
   Inspection
   InspectionGui
   MEFISTO2
   Mesh
   MeshGui
   MeshPart
   MeshPartGui
   Part
   PartDesign
   PartDesignGui
   PartGui
   Points
   PointsGui
   QtUnitGui
   Raytracing
   RaytracingGui
   ReverseEngineering
   ReverseEngineeringGui
   SMDS
   SMESH
   SMESHDS
   Sketcher
   SketcherGui
   Spreadsheet
   SpreadsheetGui
   Start
   StartGui
   StdMeshers
   Web
   WebGui

This warning is for project developers.  Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /Users/pablo/FreeCAD_full_style/build_master
[  1%] Built target Driver
[  2%] Built target MEFISTO2
[  2%] Built target Test
[  2%] Built target Material
[  2%] Built target MaterialLib
[  3%] Built target WizardShaft
[  4%] Built target Draft
[  6%] Built target Idf
[  7%] Built target SMDS
[  8%] Built target ImportPy
[  9%] Built target Arch
[ 11%] Built target Ship
[ 12%] Built target OpenSCAD
[ 13%] Built target Plot
[ 13%] Built target Example_data
[ 13%] [ 13%] Built target DriverSTL
Built target DriverDAT
[ 14%] Built target SMESHDS
[ 15%] Built target DriverUNV
Scanning dependencies of target FreeCADBase
[ 16%] Built target SMESH
[ 18%] Built target StdMeshers
[ 18%] Building CXX object src/Base/CMakeFiles/FreeCADBase.dir/swigpyrun.cpp.o
Linking CXX shared library ../../lib/libFreeCADBase.dylib
[ 23%] Built target FreeCADBase
Scanning dependencies of target FreeCADApp
[ 23%] Building CXX object src/App/CMakeFiles/FreeCADApp.dir/Application.cpp.o
Linking CXX shared library ../../lib/libFreeCADApp.dylib
[ 25%] Built target FreeCADApp
Linking CXX executable ../../bin/FreeCADCmd
Linking CXX shared library ../../lib/FreeCAD.so
[ 25%] Built target FreeCADMainCmd
[ 25%] Built target FreeCADMainPy
Linking CXX shared library ../../../../Mod/Complete/Complete.so
[ 25%] Built target Complete
Linking CXX shared library ../../../../Mod/Image/Image.so
Linking CXX shared library ../../../../Mod/Points/Points.so
[ 25%] Built target Image
[ 25%] Built target Points
Linking CXX shared library ../../../../Mod/Mesh/Mesh.so
[ 31%] Built target Mesh
Linking CXX shared library ../../../../Mod/Web/Web.so
[ 32%] Built target Web
Linking CXX shared library ../../../../Mod/Start/Start.so
[ 33%] Built target Start
Linking CXX shared library ../../../../Mod/Spreadsheet/Spreadsheet.so
[ 34%] Built target Spreadsheet
Linking CXX shared library ../../../../Mod/Part/Part.so
[ 40%] Built target Part
Scanning dependencies of target FreeCADGui
Linking CXX shared library ../../../../Mod/Sketcher/Sketcher.so
[ 42%] Built target Sketcher
Linking CXX shared library ../../../../Mod/PartDesign/_PartDesign.so
Linking CXX shared library ../../../../Mod/Raytracing/Raytracing.so
[ 43%] Built target Raytracing
[ 45%] Built target PartDesign
Linking CXX shared library ../../../../Mod/ReverseEngineering/ReverseEngineering.so
[ 45%] Built target ReverseEngineering
Linking CXX shared library ../../../../Mod/MeshPart/MeshPart.so
Linking CXX shared library ../../../../Mod/Drawing/Drawing.so
[ 45%] Built target MeshPart
[ 46%] Built target Drawing
Linking CXX shared library ../../../../Mod/Inspection/Inspection.so
Linking CXX shared library ../../../../Mod/Import/Import.so
[ 46%] Built target Inspection
[ 46%] Built target Import
Linking CXX shared library ../../../../Mod/Fem/Fem.so
[ 48%] Built target Fem
[ 48%] [ 48%] [ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/CommandDoc.cpp.o
Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/CommandView.cpp.o
Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/DlgSettings3DViewImp.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/DlgSettingsUnitsImp.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/SoFCDB.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/NavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/InventorNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/CADNavigationStyle.cpp.o
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/NavigationStyle.cpp:798:9: warning: using integer absolute value function 'abs' when argument is
      of floating point type [-Wabsolute-value]
    if (abs(logfactor)>4.0)
        ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/NavigationStyle.cpp:798:9: note: use function 'std::abs' instead
    if (abs(logfactor)>4.0)
        ^~~
        std::abs
1 warning generated.
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/BlenderNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/MayaNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/MayaGestureNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/OpenCascadeNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/TouchpadNavigationStyle.cpp.o
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:286:17: warning: 108 enumeration values not handled in switch:
      'ANY', 'UNDEFINED', 'SPACE'... [-Wswitch]
        switch (event->getKey()) {
                ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:324:20: warning: 101 enumeration values not handled in switch:
      'ANY', 'UNDEFINED', 'SPACE'... [-Wswitch]
            switch(event->getKey()){
                   ^
2 warnings generated.
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/GestureNavigationStyle.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/SplitView3DInventor.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/View3DInventor.cpp.o
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/GestureNavigationStyle.cpp:286:17: warning: 108 enumeration values not handled in switch: 'ANY',
      'UNDEFINED', 'SPACE'... [-Wswitch]
        switch (event->getKey()) {
                ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/GestureNavigationStyle.cpp:324:20: warning: 101 enumeration values not handled in switch: 'ANY',
      'UNDEFINED', 'SPACE'... [-Wswitch]
            switch(event->getKey()){
                   ^
2 warnings generated.
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/View3DInventorViewer.cpp.o
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/View3DPy.cpp.o
Linking CXX shared library ../../lib/libFreeCADGui.dylib
Undefined symbols for architecture x86_64:
  "Gui::MayaGestureNavigationStyle::init()", referenced from:
      Gui::SoFCDB::init() in SoFCDB.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib/libFreeCADGui.dylib] Error 1
make[1]: *** [src/Gui/CMakeFiles/FreeCADGui.dir/all] Error 2
make: *** [all] Error 2
MacBook-Pro-de-Pablo:build_master pablo$ make -j3
[  1%] Built target Driver
[  2%] Built target MEFISTO2
[  2%] Built target Test
[  2%] Built target Material
[  2%] Built target MaterialLib
[  3%] Built target WizardShaft
[  4%] Built target Draft
[  5%] Built target SMDS
[  7%] Built target Idf
[  8%] Built target ImportPy
[  9%] Built target Arch
[ 11%] Built target Ship
[ 12%] Built target OpenSCAD
[ 13%] Built target Plot
[ 13%] Built target Example_data
[ 13%] Built target DriverDAT
[ 13%] Built target DriverSTL
[ 14%] Built target SMESHDS
[ 15%] Built target DriverUNV
[ 16%] Built target SMESH
[ 21%] Built target FreeCADBase
[ 23%] Built target StdMeshers
[ 25%] Built target FreeCADApp
[ 25%] [ 25%] Built target FreeCADMainCmd
Built target FreeCADMainPy
[ 25%] Built target Complete
[ 25%] Built target Image
[ 25%] Built target Points
[ 31%] Built target Mesh
[ 32%] Built target Web
[ 33%] Built target Start
[ 34%] Built target Spreadsheet
[ 40%] Built target Part
Scanning dependencies of target FreeCADGui
[ 42%] Built target Sketcher
[ 43%] Built target Raytracing
[ 45%] Built target PartDesign
[ 45%] Built target ReverseEngineering
[ 45%] Built target MeshPart
[ 46%] Built target Drawing
[ 46%] Built target Inspection
[ 46%] Built target Import
[ 48%] Built target Fem
[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/MayaGestureNavigationStyle.cpp.o
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:85:5: error: use of undeclared identifier 'mouseMoveThreshold'
    mouseMoveThreshold = QApplication::startDragDistance();
    ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:86:5: error: use of undeclared identifier
      'mouseMoveThresholdBroken'
    mouseMoveThresholdBroken = false;
    ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:87:5: error: use of undeclared identifier
      'mousedownConsumedCount'
    mousedownConsumedCount = 0;
    ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:88:5: error: use of undeclared identifier 'thisClickIsComplex'
    thisClickIsComplex = false;
    ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:89:5: error: use of undeclared identifier 'inGesture'
    inGesture = false;
    ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:117:34: error: out-of-line definition of 'testMoveThreshold' does
      not match any declaration in 'Gui::MayaGestureNavigationStyle'
bool MayaGestureNavigationStyle::testMoveThreshold(const SbVec2s currentPos) const {
                                 ^~~~~~~~~~~~~~~~~
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:118:42: error: no member named 'mousedownPos' in
      'Gui::MayaGestureNavigationStyle'
    SbVec2s movedBy = currentPos - this->mousedownPos;
                                   ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:119:47: error: no member named 'mouseMoveThreshold' in
      'Gui::MayaGestureNavigationStyle'
    return SbVec2f(movedBy).length() >= this->mouseMoveThreshold;
                                        ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:178:31: error: no member named 'thisClickIsComplex' in
      'Gui::MayaGestureNavigationStyle'
    if (cntMBBefore>=2) this->thisClickIsComplex = true;
                        ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:180:15: error: no member named 'thisClickIsComplex' in
      'Gui::MayaGestureNavigationStyle'
        this->thisClickIsComplex = false;
        ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:181:15: error: no member named 'mousedownConsumedCount' in
      'Gui::MayaGestureNavigationStyle'
        this->mousedownConsumedCount = 0;//shouldn't be necessary, just a fail-safe.
        ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:223:30: error: no member named 'thisClickIsComplex' in
      'Gui::MayaGestureNavigationStyle'
    if (cntMBAfter>=2) this->thisClickIsComplex = true;
                       ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:228:15: error: no member named 'mouseMoveThresholdBroken' in
      'Gui::MayaGestureNavigationStyle'
        this->mouseMoveThresholdBroken |= this->testMoveThreshold(pos);
        ~~~~  ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:237:13: error: use of undeclared identifier 'inGesture'; did you
      mean 'gesture'?
            inGesture = true;
            ^~~~~~~~~
            gesture
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:233:31: note: 'gesture' declared here
        const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
                              ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:237:23: error: assigning to 'const SoGestureEvent *' from
      incompatible type 'bool'
            inGesture = true;
                      ^ ~~~~
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:241:13: error: use of undeclared identifier 'inGesture'; did you
      mean 'gesture'?
            inGesture = true;
            ^~~~~~~~~
            gesture
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:233:31: note: 'gesture' declared here
        const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
                              ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:241:23: error: assigning to 'const SoGestureEvent *' from
      incompatible type 'bool'
            inGesture = true;
                      ^ ~~~~
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:245:13: error: use of undeclared identifier 'inGesture'; did you
      mean 'gesture'?
            inGesture = false;
            ^~~~~~~~~
            gesture
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:233:31: note: 'gesture' declared here
        const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
                              ^
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:249:13: error: use of undeclared identifier 'inGesture'; did you
      mean 'gesture'?
            inGesture=false;
            ^~~~~~~~~
            gesture
/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:233:31: note: 'gesture' declared here
        const SoGestureEvent* gesture = static_cast<const SoGestureEvent*>(ev);
                              ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [src/Gui/CMakeFiles/FreeCADGui.dir/MayaGestureNavigationStyle.cpp.o] Error 1
make[1]: *** [src/Gui/CMakeFiles/FreeCADGui.dir/all] Error 2
make: *** [all] Error 2
I'm not an expert programmer so I have no idea how to fix them but, I think they are related with duplicated variables, clases, etc because GestureNavigationStyle.cpp and MayaGestureNavigationStyle.cpp are almost similar...

Thank you very much

PS- of course, the final credits will go to DeepSOIC because the modifications I did to turn it into Maya-Unity style are very small compared with the great gesture navigation style
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [HELP] Maya navigation style

Post by wmayer »

Is there a reason why you use GestureNavigationStyle.cpp as template? This is much more complex than the others and I recommend you to use a simpler one like Blender or Touchpad and then make the changes needed for Maya navigation.
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [HELP] Maya navigation style

Post by pablogil »

Hi wmayer,

The reason is that with Blender or Touchpad navigation style I arrive to the same problem: pressing ALT + left mouse button it orbits as I want but when I release the button it changes the selection, that it, if I have anything selected when I release the left mouse button it acts as a click so modifies the previous selection...

I have tried modifying some navigation styles but with the only one I got it perfectly working was with Gesture one. Of course it is much more complex but DeepSOIC has solved all this problems (multiple button presses, etc).

Probably the other solution would be to continue modifying Blender or Touchpad navigation style in order to solve the problem I told you but, sadly, I'm not an experienced coder and I found this problem is out of my possibilities...
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: [HELP] Maya navigation style

Post by DeepSOIC »

pablogil wrote:[ 48%] Building CXX object src/Gui/CMakeFiles/FreeCADGui.dir/MayaGestureNavigationStyle.cpp.o/Users/pablo/FreeCAD_full_style/free-cad-code/src/Gui/MayaGestureNavigationStyle.cpp:85:5: error: use of undeclared identifier 'mouseMoveThreshold' mouseMoveThreshold = QApplication::startDragDistance();
That looks like you have modified the NavigationStyle.h file incorrectly. I suspect you had copied declaration of another class, with different member list... Can you set up a FreeCAD branch on github, so that you don't have to copy-paste code? That is required anyway if you want your new style to be merged into master...
User avatar
pablogil
Posts: 882
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

Re: [HELP] Maya navigation style

Post by pablogil »

DeepSOIC wrote:That looks like you have modified the NavigationStyle.h file incorrectly. I suspect you had copied declaration of another class, with different member list... Can you set up a FreeCAD branch on github, so that you don't have to copy-paste code? That is required anyway if you want your new style to be merged into master...
You were right! I copied another class declaration on NavigationStyle.h... now it works perfectly.

It's ready to be uploaded but with the SF server down, should I wait or move to GitHub one?
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
wmayer
Founder
Posts: 20319
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [HELP] Maya navigation style

Post by wmayer »

You should anyway make a branch to upload your changes. Then it's much easier to merge it into master later.
Post Reply