0032861: Visualization - Separate rotate and move the object behavior in AIS_ViewCont...
authorsshutina <sshutina@opencascade.com>
Mon, 4 Apr 2022 19:53:18 +0000 (22:53 +0300)
committersmoskvin <smoskvin@opencascade.com>
Wed, 6 Apr 2022 00:16:12 +0000 (03:16 +0300)
Added the flag in Dragging structure that defines perform dragging (ToMove).

src/AIS/AIS_MouseGesture.hxx
src/AIS/AIS_ViewController.cxx
src/AIS/AIS_ViewController.hxx
src/AIS/AIS_ViewInputBuffer.hxx
tests/v3d/manipulator/drag_in_2d_view [new file with mode: 0644]

index 121b746..b972e84 100644 (file)
@@ -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.
index b923079..62cc3d9 100644 (file)
@@ -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;
index 21e9ccd..98f1938 100644 (file)
@@ -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
index 9db6fa4..afcc4fe 100644 (file)
@@ -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 (file)
index 0000000..9eef222
--- /dev/null
@@ -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]