]> OCCT Git - occt.git/commitdiff
0032879: Visualization, AIS_ViewController - define separate gesture mappings for... CR0-WEEK-30 IR-2023-07-28
authorsshutina <sshutina@opencascade.com>
Mon, 17 Jul 2023 22:14:55 +0000 (23:14 +0100)
committersshutina <sshutina@opencascade.com>
Tue, 18 Jul 2023 15:20:12 +0000 (16:20 +0100)
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
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/manipulator/drag_pan_zoom [new file with mode: 0644]

index 12ad1ef6176b46552a5b45363116d97fab8ed42f..a19519456d928d8c7fcbed5b524a256e96f6d884 100644 (file)
@@ -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();
     }
   }
 }
index 79f59ac43ff7b4d9c43dbb912bfcde14c3cd8ea3..83a3fbabc791b883bd38016693a24268e76af81f 100644 (file)
@@ -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<TCollection_AsciiString, AIS_MouseGesture> 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<TCollection_AsciiString, Standard_UInteger> 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 (file)
index 0000000..36caca9
--- /dev/null
@@ -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