From 342132316488a6e7cf28fc1980b86e2a2cf9f970 Mon Sep 17 00:00:00 2001 From: sshutina Date: Mon, 17 Jul 2023 23:14:55 +0100 Subject: [PATCH] 0032879: Visualization, AIS_ViewController - define separate gesture mappings for dragging Fixed problem of usage of objects dragging during zoom and pan Added new draw command to change gesture for muse buttons Added test --- src/AIS/AIS_ViewController.cxx | 19 +++-- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 75 ++++++++++++++++++++ tests/v3d/manipulator/drag_pan_zoom | 43 +++++++++++ 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 tests/v3d/manipulator/drag_pan_zoom diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index 12ad1ef617..a19519456d 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -1047,11 +1047,13 @@ bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, : 0.0; if (double (Abs (aDelta.x())) > aZoomTol) { - if (UpdateZoom (Aspect_ScrollDelta (aDelta.x()))) - { - toUpdateView = true; - } + UpdateZoom (Aspect_ScrollDelta (aDelta.x())); + + myUI.Dragging.ToMove = true; + myUI.Dragging.PointTo = thePoint; + myMouseProgressPoint = thePoint; + toUpdateView = true; } break; } @@ -1075,7 +1077,6 @@ bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, } aDelta.y() = -aDelta.y(); - myMouseProgressPoint = thePoint; if (myUI.Panning.ToPan) { myUI.Panning.Delta += aDelta; @@ -1085,6 +1086,12 @@ bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, myUI.Panning.ToPan = true; myUI.Panning.Delta = aDelta; } + + myUI.Dragging.ToMove = true; + myUI.Dragging.PointTo = thePoint; + + myMouseProgressPoint = thePoint; + toUpdateView = true; } break; @@ -3053,6 +3060,8 @@ void AIS_ViewController::handleDynamicHighlight (const Handle(AIS_InteractiveCon OnObjectDragged (theCtx, theView, AIS_DragAction_Update); myGL.OrbitRotation.ToRotate = false; myGL.ViewRotation .ToRotate = false; + myGL.Panning .ToPan = false; + myGL.ZoomActions.Clear(); } } } diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index 79f59ac43f..83a3fbabc7 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -13910,6 +13910,73 @@ static int VSelBvhBuild (Draw_Interpretor& /*theDI*/, Standard_Integer theNbArgs return 0; } +//======================================================================= +//function : VChangeMouseGesture +//purpose : +//======================================================================= +static int VChangeMouseGesture (Draw_Interpretor&, + Standard_Integer theArgsNb, + const char** theArgVec) +{ + Handle(V3d_View) aView = ViewerTest::CurrentView(); + if (aView.IsNull()) + { + Message::SendFail ("Error: no active viewer"); + return 1; + } + + NCollection_DoubleMap aGestureMap; + { + aGestureMap.Bind ("none", AIS_MouseGesture_NONE); + aGestureMap.Bind ("selectrectangle", AIS_MouseGesture_SelectRectangle); + aGestureMap.Bind ("selectlasso", AIS_MouseGesture_SelectLasso); + aGestureMap.Bind ("zoom", AIS_MouseGesture_Zoom); + aGestureMap.Bind ("zoomwindow", AIS_MouseGesture_ZoomWindow); + aGestureMap.Bind ("pan", AIS_MouseGesture_Pan); + aGestureMap.Bind ("rotateorbit", AIS_MouseGesture_RotateOrbit); + aGestureMap.Bind ("rotateview", AIS_MouseGesture_RotateView); + aGestureMap.Bind ("drag", AIS_MouseGesture_Drag); + } + NCollection_DoubleMap aMouseButtonMap; + { + aMouseButtonMap.Bind ("none", (Standard_UInteger )Aspect_VKeyMouse_NONE); + aMouseButtonMap.Bind ("left", (Standard_UInteger )Aspect_VKeyMouse_LeftButton); + aMouseButtonMap.Bind ("middle", (Standard_UInteger )Aspect_VKeyMouse_MiddleButton); + aMouseButtonMap.Bind ("right", (Standard_UInteger )Aspect_VKeyMouse_RightButton); + } + + Standard_UInteger aButton = (Standard_UInteger )Aspect_VKeyMouse_LeftButton; + AIS_MouseGesture aGesture = AIS_MouseGesture_RotateOrbit; + for (Standard_Integer anArgIter = 1; anArgIter < theArgsNb; ++anArgIter) + { + Standard_CString anArg = theArgVec[anArgIter]; + TCollection_AsciiString anArgCase (anArg); + anArgCase.LowerCase(); + if (anArgCase == "-button") + { + TCollection_AsciiString aButtonStr = theArgVec[++anArgIter]; + aButtonStr.LowerCase(); + aButton = aMouseButtonMap.Find1 (aButtonStr); + } + else if (anArgCase == "-gesture") + { + TCollection_AsciiString aGestureStr = theArgVec[++anArgIter]; + aGestureStr.LowerCase(); + aGesture = aGestureMap.Find1 (aGestureStr); + } + else + { + Message::SendFail() << "Error: unknown argument '" << anArg << "'"; + return 1; + } + } + + Handle(ViewerTest_EventManager) aViewMgr = ViewerTest::CurrentEventManager(); + aViewMgr->ChangeMouseGestureMap().Bind (aButton, aGesture); + + return 0; +} + //======================================================================= //function : ViewerTest_ExitProc //purpose : @@ -14927,4 +14994,12 @@ Turns on/off prebuilding of BVH within background thread(s). -nbThreads number of threads, 1 by default; if < 1 then used (NbLogicalProcessors - 1); -wait waits for building all of BVH. )" /* [vselbvhbuild] */); + + addCmd ("vchangemousegesture", VChangeMouseGesture, /* [vchangemousegesture] */ R"( +vchangemousegesture -button {none|left|middle|right}=left + -gesture {none|selectRectangle|selectLasso|zoom|zoomWindow|pan|rotateOrbit|rotateView|drag}=rotateOrbit +Changes the gesture for the mouse button. + -button the mouse button; + -gesture the new gesture for the button. +)" /* [vchangemousegesture] */); } diff --git a/tests/v3d/manipulator/drag_pan_zoom b/tests/v3d/manipulator/drag_pan_zoom new file mode 100644 index 0000000000..36caca9b74 --- /dev/null +++ b/tests/v3d/manipulator/drag_pan_zoom @@ -0,0 +1,43 @@ +puts "==============================================" +puts "0032879: Visualization - Separate pan/zoom and move the object behavior in AIS_ViewController" +puts "==============================================" +puts "" + +pload MODELING VISUALIZATION + +vinit View1 +pcylinder c1 5 10 +vdisplay c1 +vsetdispmode 1 +vmanipulator m -attach c1 -adjustPosition 1 -adjustSize 0 -enableModes 1 -size 40 +vfit + +# note: mouse events cannot be emulated here, so the original bug cannot be reproduced by this test case + +# pan for the left mouse button +vchangemousegesture -button left -gesture pan + +set mouse_pick {204 194} +set mouse_drag {369 35} + +vmoveto {*}$mouse_pick +vselect {*}$mouse_pick +vmanipulator m -startTransform {*}$mouse_pick +vmanipulator m -transform {*}$mouse_drag +vmanipulator m -stopTransform +vselect 0 0 +vdump $imagedir/${casename}_pan.png + +# zoom for the left mouse button +vchangemousegesture -button left -gesture zoom + +set mouse_pick {206 32} +set mouse_drag {365 330} + +vmoveto {*}$mouse_pick +vselect {*}$mouse_pick +vmanipulator m -startTransform {*}$mouse_pick +vmanipulator m -transform {*}$mouse_drag +vmanipulator m -stopTransform +vselect 0 0 +vdump $imagedir/${casename}_zoom.png