Rotation Managing: AIS_ViewCube with Left Mouse Click & Camera Rotation with Right Click

Hello,

I've implemented mouse click operation mapper to Aspect_VKeyFlags's bitmasks below:

 Aspect_VKeyMouse mouseButtonsToVirtualKeys (Qt::MouseButtons button)
{
    Aspect_VKeyMouse button_ = Aspect_VKeyMouse_NONE;
    if ((button & Qt::LeftButton) != 0)
    {
        button_ |= Aspect_VKeyMouse_MiddleButton;
    }
    if ((button & Qt::RightButton) != 0)
    {
        button_ |= Aspect_VKeyMouse_LeftButton;
    }
    return button_;
}

My intention was managing the rotation operations with Right-mouse click. However, I've lost to manage the AIS_ViewCube() with left mouse clicks according to above implementation. If I would like to manage the rotations with right-mouse click and AIS_ViewCube() clicking operations with left mouse click, how I can handle this implementation?

Should I use AIS_ViewCubeOwner class, or is there another method?

Thank you in advance!

Kirill Gavrilov's picture

You are trying to "fool" AIS_ViewController by swapping mouse buttons in events - this is not a good idea. Instead of swapping events it is better changing gesture map

AIS_ViewController& theController;
AIS_MouseGestureMap& aMouseGestures = theController.ChangeMouseGestureMap();

// clear map from defaults
aMouseGestures.Clear();

// map rotation to the right button instead of default left
//aMouseGestures.Bind (Aspect_VKeyMouse_LeftButton,    AIS_MouseGesture_RotateOrbit);
//aMouseGestures.Bind (Aspect_VKeyMouse_RightButton,   AIS_MouseGesture_Zoom);
aMouseGestures.Bind (Aspect_VKeyMouse_RightButton,   AIS_MouseGesture_RotateOrbit);

// default
aMouseGestures.Bind (Aspect_VKeyMouse_RightButton | Aspect_VKeyFlags_CTRL,  AIS_MouseGesture_RotateOrbit);

// defaults
aMouseGestures.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_CTRL,   AIS_MouseGesture_Zoom);
aMouseGestures.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_SHIFT,  AIS_MouseGesture_Pan);
aMouseGestures.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_ALT,    AIS_MouseGesture_SelectRectangle);
aMouseGestures.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_ALT | Aspect_VKeyFlags_SHIFT, AIS_MouseGesture_SelectRectangle);

aMouseGestures.Bind (Aspect_VKeyMouse_MiddleButton,                         AIS_MouseGesture_Pan);
aMouseGestures.Bind (Aspect_VKeyMouse_MiddleButton | Aspect_VKeyFlags_CTRL, AIS_MouseGesture_Pan);


// configure selection buttons (as used for AIS_ViewCube, for instance)
AIS_MouseSelectionSchemeMap& aMouseSelScheme = theController.ChangeMouseSelectionSchemes();
//aMouseSelScheme.Clear();
//aMouseSelScheme.Bind (Aspect_VKeyMouse_LeftButton,                          AIS_SelectionScheme_Replace);
//aMouseSelScheme.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_ALT,   AIS_SelectionScheme_Replace);
//aMouseSelScheme.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_SHIFT, AIS_SelectionScheme_XOR);
//aMouseSelScheme.Bind (Aspect_VKeyMouse_LeftButton | Aspect_VKeyFlags_ALT | Aspect_VKeyFlags_SHIFT, AIS_SelectionScheme_XOR);
Nezihe Sözen's picture

These code samples help a lot and they are very useful. Many thank to you for information and detailed samples that include nearly all use-cases.

Kirill Gavrilov's picture

That not a sample - this is just a snippet copied from AIS_ViewController constructor with a couple of amendments. Don't be afraid to look into OCCT source code - it might bring many answers.