]> OCCT Git - occt.git/commitdiff
Visualization - AIS_Manipulator is unusable when attaching to objects with Graphic3d_...
authorZernova Marina <36417100+mzernova@users.noreply.github.com>
Fri, 31 Jan 2025 11:26:31 +0000 (11:26 +0000)
committerGitHub <noreply@github.com>
Fri, 31 Jan 2025 11:26:31 +0000 (11:26 +0000)
Recalculation of manipulator position if attached object has zoom transform persistence
  as well as set its anchor point in Transformation.

src/AIS/AIS_Manipulator.cxx
src/AIS/AIS_Manipulator.hxx
src/ViewerTest/ViewerTest_ViewerCommands.cxx
tests/v3d/bugs/bug32116 [new file with mode: 0644]

index 6cedd5c7af55e8be55542704b7cf7fa7c75c2129..13fb9fec20fa170fb3c75d9866bde1b234a5dbb4 100644 (file)
@@ -331,6 +331,15 @@ void AIS_Manipulator::EnableMode(const AIS_ManipulatorMode theMode)
 
 //=================================================================================================
 
+void AIS_Manipulator::attachToPoint(const gp_Pnt& thePoint)
+{
+  gp_Ax2 aPosition = gp::XOY();
+  aPosition.SetLocation(thePoint);
+  SetPosition(aPosition);
+}
+
+//=================================================================================================
+
 void AIS_Manipulator::attachToBox(const Bnd_Box& theBox)
 {
   if (theBox.IsVoid())
@@ -392,7 +401,15 @@ void AIS_Manipulator::Attach(const Handle(AIS_ManipulatorObjectSequence)& theObj
 
   if (theOptions.AdjustPosition)
   {
-    attachToBox(aBox);
+    const Handle(Graphic3d_TransformPers)& aTransPers = aCurObject->TransformPersistence();
+    if (!aTransPers.IsNull() && (aTransPers->IsZoomOrRotate() || aTransPers->IsAxial()))
+    {
+      attachToPoint(aTransPers->AnchorPoint());
+    }
+    else
+    {
+      attachToBox(aBox);
+    }
   }
 
   if (theOptions.AdjustSize)
@@ -746,9 +763,18 @@ void AIS_Manipulator::Transform(const gp_Trsf& theTrsf)
     NCollection_Sequence<gp_Trsf>::Iterator aTrsfIter(myStartTrsfs);
     for (; anObjIter.More(); anObjIter.Next(), aTrsfIter.Next())
     {
-      const Handle(AIS_InteractiveObject)& anObj       = anObjIter.ChangeValue();
-      const gp_Trsf&                       anOldTrsf   = aTrsfIter.Value();
-      const Handle(TopLoc_Datum3D)&        aParentTrsf = anObj->CombinedParentTransformation();
+      const Handle(AIS_InteractiveObject)&   anObj      = anObjIter.ChangeValue();
+      const Handle(Graphic3d_TransformPers)& aTransPers = anObj->TransformPersistence();
+      if (!aTransPers.IsNull() && (aTransPers->IsZoomOrRotate() || aTransPers->IsAxial()))
+      {
+        gp_XYZ aNewAnchorPoint = aTransPers->AnchorPoint().XYZ() - myPosition.Location().XYZ();
+        aNewAnchorPoint += myStartPosition.Location().Transformed(theTrsf).XYZ();
+        aTransPers->SetAnchorPoint(aNewAnchorPoint);
+        continue;
+      }
+
+      const gp_Trsf&                anOldTrsf   = aTrsfIter.Value();
+      const Handle(TopLoc_Datum3D)& aParentTrsf = anObj->CombinedParentTransformation();
       if (!aParentTrsf.IsNull() && aParentTrsf->Form() != gp_Identity)
       {
         // recompute local transformation relative to parent transformation
index 5220702e9e99d19e3fd756e5d8852ffbf4a61918..47c18b307f1954c4a5f3e36f81397486e8329c3b 100644 (file)
@@ -416,6 +416,8 @@ protected:
   Standard_EXPORT Handle(Graphic3d_Group) getGroup(const Standard_Integer    theIndex,
                                                    const AIS_ManipulatorMode theMode) const;
 
+  Standard_EXPORT void attachToPoint(const gp_Pnt& thePoint);
+
   Standard_EXPORT void attachToBox(const Bnd_Box& theBox);
 
   Standard_EXPORT void adjustSize(const Bnd_Box& theBox);
index 1a65e32729d595c51e1322be7bf95469224680ef..089d8b56711d0f0f45bfd5fcfe25883b5de72b85 100644 (file)
@@ -12083,7 +12083,8 @@ static int VManipulator(Draw_Interpretor& theDi, Standard_Integer theArgsNb, con
   NCollection_Sequence<ManipAxisModeOnOff> aParts;
   gp_XYZ aLocation(RealLast(), RealLast(), RealLast()), aVDir, anXDir;
   //
-  bool                              toDetach = false;
+  bool                              toDetach    = false;
+  bool                              toAddObject = false;
   AIS_Manipulator::OptionsForAttach anAttachOptions;
   Handle(AIS_InteractiveObject)     anAttachObject;
   Handle(V3d_View)                  aViewAffinity;
@@ -12273,6 +12274,10 @@ static int VManipulator(Draw_Interpretor& theDi, Standard_Integer theArgsNb, con
       aTrsf.SetRotation(gp_Ax1(gp_Pnt(aRotPnt), gp_Dir(aRotAxis)), aTmpReal);
     }
     //
+    else if (anArg == "-addobject")
+    {
+      toAddObject = true;
+    }
     else if (anArg == "-detach")
     {
       toDetach = true;
@@ -12430,7 +12435,16 @@ static int VManipulator(Draw_Interpretor& theDi, Standard_Integer theArgsNb, con
 
   if (!anAttachObject.IsNull())
   {
-    aManipulator->Attach(anAttachObject, anAttachOptions);
+    if (toAddObject && aManipulator->IsAttached())
+    {
+      Handle(AIS_ManipulatorObjectSequence) anAttachObjects = aManipulator->Objects();
+      anAttachObjects->Append(anAttachObject);
+      aManipulator->Attach(anAttachObjects, anAttachOptions);
+    }
+    else
+    {
+      aManipulator->Attach(anAttachObject, anAttachOptions);
+    }
   }
   if (!aViewAffinity.IsNull())
   {
@@ -14490,6 +14504,7 @@ Options:
  '-enableModes    {0|1}'             enable modes when attaching
  '-view  {active | [name of view]}'  display manipulator only in defined view,
                                      by default it is displayed in all views of the current viewer
+ '-addObject                         allows attach manipulator to multiple objects (replace by default)
  '-detach'                           detach manipulator
  '-startTransform mouse_x mouse_y' - invoke start of transformation
  '-transform      mouse_x mouse_y' - invoke transformation
diff --git a/tests/v3d/bugs/bug32116 b/tests/v3d/bugs/bug32116
new file mode 100644 (file)
index 0000000..7cda1ca
--- /dev/null
@@ -0,0 +1,41 @@
+puts "============"
+puts "0032116: Visualization - AIS_Manipulator is unusable when attaching to objects with Graphic3d_TMF_ZoomPers"
+puts "============"
+puts ""
+
+pload MODELING VISUALIZATION
+
+box b1 10 10 10 10 20 30
+box b2 50 50 50 10 20 30
+
+vinit View1
+vdisplay b1 -dispmode 1 -trsfPers zoom -trsfPersPos 0 0 0
+vdisplay b2 -dispmode 1 -trsfPers zoom -trsfPersPos 10 10 10
+vfit
+
+vmanipulator m -attach b1 -addObject
+vmanipulator m -attach b2 -addObject
+
+set mouse_pick {90 225}
+set mouse_drag {90 150}
+
+vmoveto {*}$mouse_pick
+vselect {*}$mouse_pick
+vmanipulator m -startTransform {*}$mouse_pick
+vmanipulator m -transform {*}$mouse_drag
+vmanipulator m -stopTransform
+vmoveto {*}$mouse_drag
+
+if { [vreadpixel {*}$mouse_drag -rgb -name] != "CYAN" } { puts "Error: wrong manipulator position" }
+if { [vreadpixel 115 170 -rgb -name] != "DARKGOLDENROD" } { puts "Error: wrong b1 tranformation" }
+if { [vreadpixel 400 10 -rgb -name] != "DARKGOLDENROD" } { puts "Error: wrong b2 tranformation" }
+
+vdump ${imagedir}/${casename}_1.png
+
+vmoveto 0 0
+vzoom 0.2
+
+if { [vreadpixel 210 170 -rgb -name] != "DARKGOLDENROD" } { puts "Error: wrong b1 tranformation" }
+if { [vreadpixel 310 120 -rgb -name] != "DARKGOLDENROD" } { puts "Error: wrong b2 tranformation" }
+
+vdump ${imagedir}/${casename}_2.png