From e3fd3d83dab0e5b1f6c53243ce0dc3e56e2bdef1 Mon Sep 17 00:00:00 2001 From: sshutina Date: Mon, 4 Apr 2022 22:53:18 +0300 Subject: [PATCH] 0032861: Visualization - Separate rotate and move the object behavior in AIS_ViewController Added the flag in Dragging structure that defines perform dragging (ToMove). --- src/AIS/AIS_MouseGesture.hxx | 2 + src/AIS/AIS_ViewController.cxx | 82 +++++++++++++++++++++++---- src/AIS/AIS_ViewController.hxx | 2 + src/AIS/AIS_ViewInputBuffer.hxx | 4 +- tests/v3d/manipulator/drag_in_2d_view | 31 ++++++++++ 5 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 tests/v3d/manipulator/drag_in_2d_view diff --git a/src/AIS/AIS_MouseGesture.hxx b/src/AIS/AIS_MouseGesture.hxx index 121b746c04..b972e84451 100644 --- a/src/AIS/AIS_MouseGesture.hxx +++ b/src/AIS/AIS_MouseGesture.hxx @@ -34,6 +34,8 @@ enum AIS_MouseGesture AIS_MouseGesture_Pan, //!< view panning gesture AIS_MouseGesture_RotateOrbit, //!< orbit rotation gesture AIS_MouseGesture_RotateView, //!< view rotation gesture + AIS_MouseGesture_Drag, //!< object dragging; + //! press button to start, move mouse to define rectangle, release to finish }; //! Map defining mouse gestures. diff --git a/src/AIS/AIS_ViewController.cxx b/src/AIS/AIS_ViewController.cxx index b923079fa4..62cc3d9ea5 100644 --- a/src/AIS/AIS_ViewController.cxx +++ b/src/AIS/AIS_ViewController.cxx @@ -92,6 +92,7 @@ AIS_ViewController::AIS_ViewController() myTouchPanThresholdPx (4.0f), myTouchZoomThresholdPx (6.0f), myTouchZoomRatio (0.13f), + myTouchDraggingThresholdPx (6.0f), // myNbTouchesLast (0), myUpdateStartPointPan (true), @@ -133,6 +134,8 @@ AIS_ViewController::AIS_ViewController() myMouseGestureMap.Bind (Aspect_VKeyMouse_MiddleButton, AIS_MouseGesture_Pan); myMouseGestureMap.Bind (Aspect_VKeyMouse_MiddleButton | Aspect_VKeyFlags_CTRL, AIS_MouseGesture_Pan); + myMouseGestureMapDrag.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Drag); + myXRTeleportHaptic.Duration = 3600.0f; myXRTeleportHaptic.Frequency = 0.1f; myXRTeleportHaptic.Amplitude = 0.2f; @@ -261,12 +264,21 @@ void AIS_ViewController::flushBuffers (const Handle(AIS_InteractiveContext)& , myUI.Dragging.ToStop = false; myGL.Dragging.ToStop = true; } - else if (myUI.Dragging.ToStart) + else { - myUI.Dragging.ToStart = false; - myGL.Dragging.ToStart = true; - myGL.Dragging.PointStart = myUI.Dragging.PointStart; + if (myUI.Dragging.ToStart) + { + myUI.Dragging.ToStart = false; + myGL.Dragging.ToStart = true; + myGL.Dragging.PointStart = myUI.Dragging.PointStart; + } + if (myUI.Dragging.ToMove) + { + myUI.Dragging.ToMove = false; + myGL.Dragging.ToMove = true; + } } + myGL.Dragging.PointTo = myUI.Dragging.PointTo; if (myUI.OrbitRotation.ToStart) @@ -351,6 +363,7 @@ void AIS_ViewController::flushGestures (const Handle(AIS_InteractiveContext)& , const Graphic3d_Vec2d aRotDelta = aTouch.To - myGL.OrbitRotation.PointStart; myGL.OrbitRotation.ToRotate = true; myGL.OrbitRotation.PointTo = myGL.OrbitRotation.PointStart + aRotDelta * aRotAccel; + myGL.Dragging.ToMove = true; myGL.Dragging.PointTo.SetValues ((int )aTouch.To.x(), (int )aTouch.To.y()); } else @@ -358,6 +371,7 @@ void AIS_ViewController::flushGestures (const Handle(AIS_InteractiveContext)& , const Graphic3d_Vec2d aRotDelta = aTouch.To - myGL.ViewRotation.PointStart; myGL.ViewRotation.ToRotate = true; myGL.ViewRotation.PointTo = myGL.ViewRotation.PointStart + aRotDelta * aRotAccel; + myGL.Dragging.ToMove = true; myGL.Dragging.PointTo.SetValues ((int )aTouch.To.x(), (int )aTouch.To.y()); } @@ -780,6 +794,19 @@ bool AIS_ViewController::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, UpdatePolySelection (thePoint, true); break; } + case AIS_MouseGesture_Drag: + { + if (myToAllowDragging) + { + myUI.Dragging.ToStart = true; + myUI.Dragging.PointStart = thePoint; + } + else + { + myMouseActiveGesture = AIS_MouseGesture_NONE; + } + break; + } case AIS_MouseGesture_NONE: { break; @@ -787,12 +814,19 @@ bool AIS_ViewController::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, } } - if (theButtons == Aspect_VKeyMouse_LeftButton - && theModifiers == Aspect_VKeyFlags_NONE - && myToAllowDragging) + AIS_MouseGesture aSecGesture = AIS_MouseGesture_NONE; + if (myMouseGestureMapDrag.Find (theButtons | theModifiers, aSecGesture)) { - myUI.Dragging.ToStart = true; - myUI.Dragging.PointStart = thePoint; + if (aSecGesture == AIS_MouseGesture_Drag + && myToAllowDragging) + { + myUI.Dragging.ToStart = true; + myUI.Dragging.PointStart = thePoint; + if (myMouseActiveGesture == AIS_MouseGesture_NONE) + { + myMouseActiveGesture = aSecGesture; + } + } } } @@ -932,6 +966,8 @@ bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, myUI.ViewRotation.PointTo = Graphic3d_Vec2d (myMousePressPoint.x(), myMousePressPoint.y()) + Graphic3d_Vec2d (aRotDelta.x(), aRotDelta.y()) * aRotAccel; } + + myUI.Dragging.ToMove = true; myUI.Dragging.PointTo = thePoint; myMouseProgressPoint = thePoint; @@ -991,6 +1027,31 @@ bool AIS_ViewController::UpdateMousePosition (const Graphic3d_Vec2i& thePoint, } break; } + case AIS_MouseGesture_Drag: + { + if (!myToAllowDragging) + { + break; + } + + const double aDragTol = theIsEmulated + ? double(myTouchToleranceScale) * myTouchDraggingThresholdPx + : 0.0; + if (double (Abs (aDelta.x()) + Abs (aDelta.y())) > aDragTol) + { + const double aRotAccel = myNavigationMode == AIS_NavigationMode_FirstPersonWalk ? myMouseAccel : myOrbitAccel; + const Graphic3d_Vec2i aRotDelta = thePoint - myMousePressPoint; + myUI.ViewRotation.ToRotate = true; + myUI.ViewRotation.PointTo = Graphic3d_Vec2d (myMousePressPoint.x(), myMousePressPoint.y()) + + Graphic3d_Vec2d (aRotDelta.x(), aRotDelta.y()) * aRotAccel; + myUI.Dragging.ToMove = true; + myUI.Dragging.PointTo = thePoint; + + myMouseProgressPoint = thePoint; + toUpdateView = true; + } + break; + } default: { break; @@ -2913,8 +2974,7 @@ void AIS_ViewController::handleDynamicHighlight (const Handle(AIS_InteractiveCon myGL.OrbitRotation.ToRotate = false; myGL.ViewRotation .ToRotate = false; } - else if (myGL.OrbitRotation.ToRotate - || myGL.ViewRotation.ToRotate) + else if (myGL.Dragging.ToMove) { OnObjectDragged (theCtx, theView, AIS_DragAction_Update); myGL.OrbitRotation.ToRotate = false; diff --git a/src/AIS/AIS_ViewController.hxx b/src/AIS/AIS_ViewController.hxx index 21e9ccdde0..98f1938726 100644 --- a/src/AIS/AIS_ViewController.hxx +++ b/src/AIS/AIS_ViewController.hxx @@ -757,6 +757,7 @@ protected: //! @name mouse input variables Standard_ShortReal myScrollZoomRatio; //!< distance ratio for mapping mouse scroll event to zoom; 15.0 by default AIS_MouseGestureMap myMouseGestureMap; //!< map defining mouse gestures + AIS_MouseGestureMap myMouseGestureMapDrag; //!< secondary map defining mouse gestures for dragging AIS_MouseGesture myMouseActiveGesture; //!< initiated mouse gesture (by pressing mouse button) AIS_MouseSelectionSchemeMap myMouseSelectionSchemes; //!< map defining selection schemes bound to mouse + modifiers @@ -777,6 +778,7 @@ protected: //! @name multi-touch input variables Standard_ShortReal myTouchPanThresholdPx; //!< threshold for starting two-touch panning gesture in pixels; 4 by default Standard_ShortReal myTouchZoomThresholdPx; //!< threshold for starting two-touch zoom (pitch) gesture in pixels; 6 by default Standard_ShortReal myTouchZoomRatio; //!< distance ratio for mapping two-touch zoom (pitch) gesture from pixels to zoom; 0.13 by default + Standard_ShortReal myTouchDraggingThresholdPx; //!< distance for starting one-touch dragging gesture in pixels; 6 by default Aspect_Touch myTouchClick; //!< single touch position for handling clicks OSD_Timer myTouchDoubleTapTimer; //!< timer for handling double tap diff --git a/src/AIS/AIS_ViewInputBuffer.hxx b/src/AIS/AIS_ViewInputBuffer.hxx index 9db6fa4279..afcc4feb0d 100644 --- a/src/AIS/AIS_ViewInputBuffer.hxx +++ b/src/AIS/AIS_ViewInputBuffer.hxx @@ -87,12 +87,13 @@ public: struct _draggingParams { bool ToStart; //!< start dragging + bool ToMove; //!< perform dragging bool ToStop; //!< stop dragging bool ToAbort; //!< abort dragging (restore previous position) Graphic3d_Vec2i PointStart; //!< drag start point Graphic3d_Vec2i PointTo; //!< drag end point - _draggingParams() : ToStart (false), ToStop (false), ToAbort (false) {} + _draggingParams() : ToStart (false), ToMove (false), ToStop (false), ToAbort (false) {} } Dragging; struct _orbitRotation @@ -141,6 +142,7 @@ public: Panning.ToStart = false; Panning.ToPan = false; Dragging.ToStart = false; + Dragging.ToMove = false; Dragging.ToStop = false; Dragging.ToAbort = false; OrbitRotation.ToStart = false; diff --git a/tests/v3d/manipulator/drag_in_2d_view b/tests/v3d/manipulator/drag_in_2d_view new file mode 100644 index 0000000000..9eef222bb6 --- /dev/null +++ b/tests/v3d/manipulator/drag_in_2d_view @@ -0,0 +1,31 @@ +puts "==============================================" +puts "0032861: Visualization - Separate rotate and move the object behavior in AIS_ViewController" +puts "==============================================" +puts "" + +pload MODELING VISUALIZATION + +vinit View1 -2d +box b 10 10 10 +vdisplay b +vaxo +vfit +vzoom 0.5 +vmanipulator m -attach b + +vdump $imagedir/${casename}_1.png + +set mouse_pick {226 214} +set mouse_drag {306 265} + +# note: mouse events cannot be emulated here, so the original bug cannot be reproduced by this test case +vmoveto {*}$mouse_pick +vselect {*}$mouse_pick +vmanipulator m -startTransform {*}$mouse_pick +vmanipulator m -transform {*}$mouse_drag +vmanipulator m -stopTransform +vselect 0 0 +vmoveto {*}$mouse_drag +vdump $imagedir/${casename}_2.png + +set aNewLoc [vlocation b -location]