]> OCCT Git - occt.git/commitdiff
0033746: Visualization - Unexpected moving with AIS_ViewCube CR33746
authormzernova <mzernova@opencascade.com>
Wed, 17 Jul 2024 12:21:43 +0000 (13:21 +0100)
committermzernova <mzernova@opencascade.com>
Fri, 19 Jul 2024 09:20:10 +0000 (10:20 +0100)
Fixed angle calculation for view rotation.
Added draw command vmousebutton to test mouse button events.

src/AIS/AIS_ViewController.cxx
src/V3d/V3d_View.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/bugs/bug33746 [new file with mode: 0644]

index 78e70074715c324d7c0caa53c61efcd7951d0e40..ecd76d02039b90b91206e8f3bf62e4f842a735f3 100644 (file)
@@ -1827,12 +1827,26 @@ void AIS_ViewController::handleViewRotation (const Handle(V3d_View)& theView,
   }
   if (myGL.ViewRotation.ToStart)
   {
+    gp_Dir aCamDirection = aCam->Direction();
+    if (aCam->OrthogonalizedUp().IsParallel (gp::DY(), Precision::Angular()))
+    {
+      aCamDirection = aCamDirection.Dot (gp::DZ()) > 0
+                    ? gp::DZ()
+                    : gp::DZ().Reversed();
+    }
+
     gp_Trsf aTrsf;
-    aTrsf.SetTransformation (gp_Ax3 (gp::Origin(), aCam->OrthogonalizedUp(), aCam->Direction()),
+    aTrsf.SetTransformation (gp_Ax3 (gp::Origin(), aCam->OrthogonalizedUp(), aCamDirection),
                              gp_Ax3 (gp::Origin(), gp::DZ(), gp::DX()));
     const gp_Quaternion aRot = aTrsf.GetRotation();
     double aRollDummy = 0.0;
     aRot.GetEulerAngles (gp_YawPitchRoll, myRotateStartYawPitchRoll[0], myRotateStartYawPitchRoll[1], aRollDummy);
+    if (aCamDirection.IsParallel (gp::DZ(), Precision::Angular()))
+    {
+      myRotateStartYawPitchRoll[0] = aCamDirection.IsEqual (gp::DZ(), Precision::Angular())
+                                   ? aRollDummy
+                                   : -aRollDummy;
+    }
   }
   if (toRotateAnyway)
   {
index 93804995a4b8632ba59c575d50acd268ea751a9b..e33752a949e9c95a61349cf3818caf0f4dc19ffb 100644 (file)
@@ -857,7 +857,7 @@ public:
                              const Graphic3d_BufferType& theBufferType     = Graphic3d_BT_RGB,
                              const Standard_Boolean      theToAdjustAspect = Standard_True,
                              const Graphic3d_ZLayerId    theTargetZLayerId = Graphic3d_ZLayerId_BotOSD,
-                             const Standard_Integer      theIsSingleLayer  = Standard_False,
+                             const Standard_Boolean      theIsSingleLayer  = Standard_False,
                              const V3d_StereoDumpOptions theStereoOptions  = V3d_SDO_MONO,
                              const Standard_CString      theLightName = "")
   {
index 630ac437f4c09d3c56c5cd05c0b14e3d8ace9d15..c6807a92b8853765f3f844880149eace0c7c060b 100644 (file)
@@ -1,4 +1,4 @@
-// Created on: 1998-09-01
+// Created on: 1998-09-01
 // Created by: Robert COUBLANC
 // Copyright (c) 1998-1999 Matra Datavision
 // Copyright (c) 1999-2014 OPEN CASCADE SAS
@@ -6547,6 +6547,106 @@ static Standard_Integer VMoveTo (Draw_Interpretor& theDI,
   return 0;
 }
 
+//=======================================================================
+//function : VMouseButton
+//purpose  : Emulates mouse button event
+//=======================================================================
+static Standard_Integer VMouseButton (Draw_Interpretor& /*theDI*/,
+                                      Standard_Integer theNbArgs,
+                                      const char**     theArgVec)
+{
+  const Handle(AIS_InteractiveContext)& aContext = ViewerTest::GetAISContext();
+  const Handle(V3d_View)&               aView = ViewerTest::CurrentView();
+  if (aContext.IsNull())
+  {
+    Message::SendFail ("Error: no active viewer");
+    return 1;
+  }
+
+  if (theNbArgs < 6)
+  {
+    Message::SendFail ("Syntax error: wrong number arguments");
+    return 1;
+  }
+
+  Aspect_VKeyMouse aButton = Aspect_VKeyMouse_LeftButton;
+  Standard_Boolean isPressButton = false;
+
+  Graphic3d_Vec2i aMousePos (IntegerLast(), IntegerLast());
+  for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
+  {
+    TCollection_AsciiString anArgStr (theArgVec[anArgIter]);
+    anArgStr.LowerCase();
+    if (anArgStr == "-button")
+    {
+      if (anArgIter + 1 < theNbArgs)
+      {
+        ++anArgIter;
+        TCollection_AsciiString aButtonStr (theArgVec[anArgIter]);
+        if (aButtonStr == "left")
+        {
+          aButton = Aspect_VKeyMouse_LeftButton;
+        }
+        else if (aButtonStr == "right")
+        {
+          aButton = Aspect_VKeyMouse_RightButton;
+        }
+        else if (aButtonStr == "middle")
+        {
+          aButton = Aspect_VKeyMouse_MiddleButton;
+        }
+      }
+    }
+    else if (anArgStr == "-up")
+    {
+      isPressButton = false;
+    }
+    else if (anArgStr == "-down")
+    {
+      isPressButton = true;
+    }
+    else if (aMousePos.x() == IntegerLast()
+          && anArgStr.IsIntegerValue())
+    {
+      aMousePos.x() = anArgStr.IntegerValue();
+    }
+    else if (aMousePos.y() == IntegerLast()
+          && anArgStr.IsIntegerValue())
+    {
+      aMousePos.y() = anArgStr.IntegerValue();
+    }
+    else
+    {
+      Message::SendFail() << "Syntax error at '" << theArgVec[anArgIter] << "'";
+      return 1;
+    }
+  }
+
+  if (aMousePos.x() == IntegerLast()
+   || aMousePos.y() == IntegerLast())
+  {
+    Message::SendFail ("Syntax error: wrong number of arguments");
+    return 1;
+  }
+
+  if (isPressButton)
+  {
+    ViewerTest::CurrentEventManager()->ResetPreviousMoveTo();
+    ViewerTest::CurrentEventManager()->PressMouseButton (aMousePos, aButton, Aspect_VKeyFlags_NONE, false);
+    ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
+    ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
+  }
+  else
+  {
+    ViewerTest::CurrentEventManager()->UpdateMousePosition (aMousePos, Aspect_VKeyMouse_NONE, Aspect_VKeyFlags_NONE, false);
+    ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
+    ViewerTest::CurrentEventManager()->ReleaseMouseButton (aMousePos, aButton, Aspect_VKeyFlags_NONE, false);
+    ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), aView, true);
+  }
+  
+  return 0;
+}
+
 //=======================================================================
 //function : VSelectByAxis
 //purpose  :
@@ -14515,6 +14615,14 @@ Emulate cursor movement to pixel position (x,y).
  -reset resets current highlighting.
 )" /* [vmoveto] */);
 
+  addCmd("vmousebutton", VMouseButton, /* [vmousebutton] */ R"(
+vmousebutton x y -button right|left|middle -up|-down
+Emulate mouse button events.
+ -button choose button;
+ -down   press button;
+ -up     release button.
+)" /* [vmousebutton] */);
+
   addCmd ("vselaxis", VSelectByAxis, /* [vselaxis] */ R"(
 vselaxis x y z dx dy dz [-onlyTop 0|1] [-display Name] [-showNormal 0|1]"
 Provides intersection by given axis and print result intersection points.
diff --git a/tests/v3d/bugs/bug33746 b/tests/v3d/bugs/bug33746
new file mode 100644 (file)
index 0000000..5c2f708
--- /dev/null
@@ -0,0 +1,30 @@
+puts "============"
+puts "0033746: Visualization - Unexpected moving with AIS_ViewCube"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+vclear
+vinit View1
+
+box b 0 0 -100 100 20 10
+vdisplay -dispMode 1 b
+
+vviewcube c
+vcamera -navmode fly
+
+vtop
+vfit
+vmousebutton 200 200 -button left -down
+vmousebutton 201 200 -button left -up
+if { [vreadpixel 100 200 -rgb -name] == "BLACK" } { puts "Error: wrong transformation" }
+
+vdump $::imagedir/${::casename}_top.png
+
+vbottom
+vfit
+vmousebutton 200 200 -button left -down
+vmousebutton 201 200 -button left -up
+if { [vreadpixel 100 200 -rgb -name] == "BLACK" } { puts "Error: wrong transformation" }
+
+vdump $::imagedir/${::casename}_bottom.png