Draft WB breaks Mouse Model "Gesture"

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
UR_
Posts: 1189
Joined: Tue Jan 03, 2017 8:42 pm

Re: Draft WB breaks Mouse Model "Gesture"

Postby UR_ » Thu Jan 16, 2020 7:27 pm

Sorry, no custom shortcuts.
A while ago found, that
Edit->Preferences->Draft->General settings->In-Command shortcuts for Wipe command was set to "H" by default.
Changed this to "I" , but didn't help.


BTW, resetting .cfg-files didn't helped too.
triplus
Posts: 9475
Joined: Mon Dec 12, 2011 4:45 pm

Re: Draft WB breaks Mouse Model "Gesture"

Postby triplus » Thu Jan 16, 2020 11:16 pm

Don't have more ideas. Maybe you could try out MayaGesture style and to observe if the same issue happens on your side or not.
chrisb
Posts: 27037
Joined: Tue Mar 17, 2015 9:14 am

Re: Draft WB breaks Mouse Model "Gesture"

Postby chrisb » Fri Jan 17, 2020 12:01 am

Works here. When resetting the config, did you remove the whole config directory? Perhaps some addon interferes.

OS: macOS High Sierra (10.13)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19285 (Git)
Build type: Release
Branch: master
Hash: 8b2e318f15ee6304e8d89f48b2ac45af3bf61aed
Python version: 3.8.1
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.4.0
Locale: English/Germany (en_DE)
UR_
Posts: 1189
Joined: Tue Jan 03, 2017 8:42 pm

Re: Draft WB breaks Mouse Model "Gesture"

Postby UR_ » Fri Jan 17, 2020 6:37 am

chrisb wrote:
Fri Jan 17, 2020 12:01 am
... did you remove the whole config directory?
Not removed but renamed to C:\Users\aio\AppData\Roaming\FreeCADold
Still no luck.
UR_
Posts: 1189
Joined: Tue Jan 03, 2017 8:42 pm

Re: Draft WB breaks Mouse Model "Gesture"

Postby UR_ » Fri Jan 17, 2020 7:05 am

triplus wrote:
Thu Jan 16, 2020 11:16 pm
Maybe you could try out MayaGesture style and to observe if the same issue happens on your side or not.
MayaGesture's H-key is not affected by Draft WB.

Funny observation while Gesture model is activated.
Before activating DraftWB temporarily, one can use H-key and Shift-H alternatively obtaining same function (rotation focus).
After activating DraftWB temporarily, only Shift-H keeps working.

The Shift-H-key thingy isn't mentioned on wiki at all. Hidden feature or bug?
wmayer
Site Admin
Posts: 16301
Joined: Thu Feb 19, 2009 10:32 am

Re: Draft WB breaks Mouse Model "Gesture"

Postby wmayer » Fri Jan 17, 2020 10:45 am

When things work correctly then the event handling comes through GestureNavigationStyle::processSoEvent() where the actual handling is forwarded to the method NS::IdleState::react() that is based on boost's state machine framework.

Inside this function there is the block

Code: Select all

        //keyboard
        if(ev.isKeyboardEvent()){
            auto const &kbev = ev.asKeyboardEvent();
            ev.flags->processed = true;
            bool press = (kbev->getState() == SoKeyboardEvent::DOWN);
            switch (kbev->getKey()) {
                case SoKeyboardEvent::H:
                    if (press)
                        ns.onSetRotationCenter(kbev->getPosition());
                break;
to set the rotation center.

Now after switching to Draft and back the above code block always claims that press is false and thus the H key is not handled at all. So, when clicking the H key (which is separated into a press and release event) then only the release event comes through.

Now going further up the call stack there is the Quarter function to translate a Qt event into an OpenInventor event and even there no key press event comes through for certain keys.
Before switching to Draft you get a press and release event for A,C,D,F,G,H,I,J,K,... while for B,E,T,V,W,Z only a release event is handled. This behaviour I think is because the latter keys are part of the global shortcuts.

When switching to Draft and back a lot of new shortcuts are set and thus the list of filtered letters is extended by F, G, H, J, O, P, R, S, U, ...
wmayer
Site Admin
Posts: 16301
Joined: Thu Feb 19, 2009 10:32 am

Re: Draft WB breaks Mouse Model "Gesture"

Postby wmayer » Fri Jan 17, 2020 11:46 am

So, this issue is related to how Qt works and I wonder why people have different behavior. Either there is a system specific behaviour on different OSes or the behaviour is different depending on the Qt version.

Anyway, Qt offers a way to make sure the 3D view (when it has the focus) gets the event beforehand. When pressing a shortcut then Qt first sends an event of type QEvent::ShortcutOverride and whoever claims to handle the event will receive the corresponding key event directly.

Accordingly the method below can be implemented:

Code: Select all

bool View3DInventor::event(QEvent* e)
{
    if (e && e->type() == QEvent::ShortcutOverride) {
        QKeyEvent * kevent = static_cast<QKeyEvent*>(e);
        if (kevent->modifiers() == Qt::NoModifier ||
            kevent->modifiers() == Qt::ShiftModifier ||
            kevent->modifiers() == Qt::KeypadModifier) {
            switch (kevent->key()) {
                case Qt::Key_H:
                case Qt::Key_PageDown:
                case Qt::Key_PageUp:
                    kevent->accept();
                default:
                    break;
            }
        }
    }
    return MDIView::event(e);
}
This however has two drawbacks:
  1. Its implementation depends on the implementation details of the navigation styles which shortcuts are used
  2. As said above in Draft there are shortcuts that uses the "H" as first character but when the 3d view now handles the event instead it won't be possible any more to invoke the affected Draft command as long as the 3d view has the focus.
That's why I prefer to change the implementation of the Gesture style not to handle the key press but the key release events.
DeepSOIC wrote: ping
User avatar
DeepSOIC
Posts: 7799
Joined: Fri Aug 29, 2014 12:45 am
Location: Saint-Petersburg, Russia

Re: Draft WB breaks Mouse Model "Gesture"

Postby DeepSOIC » Fri Jan 17, 2020 1:20 pm

wmayer wrote:
Fri Jan 17, 2020 11:46 am
That's why I prefer to change the implementation of the Gesture style not to handle the key press but the key release events.
Shouldn't be a problem. Do you want me to create a PR?

A better solution is to avoid the conflict altogether. It is also in conflict with shortcut for H-constraint in Sketcher. So maybe there is a better key to bind it to. Best is of course to make it customizable.
wmayer
Site Admin
Posts: 16301
Joined: Thu Feb 19, 2009 10:32 am

Re: Draft WB breaks Mouse Model "Gesture"

Postby wmayer » Fri Jan 17, 2020 1:48 pm

DeepSOIC wrote:
Fri Jan 17, 2020 1:20 pm
Shouldn't be a problem. Do you want me to create a PR?
Not needed. I wanted to be sure that this can be changed.
A better solution is to avoid the conflict altogether. It is also in conflict with shortcut for H-constraint in Sketcher.
I see. But IMO this is not a big issue because the ambiguity only exists when the sketcher is edited and then it's probably rather uncommon to set the rotation center.
So maybe there is a better key to bind it to. Best is of course to make it customizable.
In this case I think it's best to separate this part from navigation style classes and put it into Command classes.
wmayer
Site Admin
Posts: 16301
Joined: Thu Feb 19, 2009 10:32 am

Re: Draft WB breaks Mouse Model "Gesture"

Postby wmayer » Fri Jan 17, 2020 2:11 pm

wmayer wrote:
Fri Jan 17, 2020 1:48 pm
I see. But IMO this is not a big issue because the ambiguity only exists when the sketcher is edited and then it's probably rather uncommon to set the rotation center.
After changing it the behaviour is a bit funny now because when pressing the H key then it performs both operations. For the press event the horizontal constraint is set and for its release event the rotation center is set.