0028010: Visualization, Prs3d_Arrow - add Shading presentation builder
[occt.git] / src / AIS / AIS_Manipulator.cxx
index 370ec76..ff0746c 100644 (file)
 #include <Geom_Line.hxx>
 #include <Geom_Plane.hxx>
 #include <Geom_Transformation.hxx>
+#include <Prs3d_Arrow.hxx>
 #include <Prs3d_Root.hxx>
 #include <Prs3d_ShadingAspect.hxx>
+#include <Prs3d_ToolDisk.hxx>
+#include <Prs3d_ToolSphere.hxx>
 #include <Select3D_SensitiveCircle.hxx>
 #include <Select3D_SensitivePoint.hxx>
 #include <Select3D_SensitiveSegment.hxx>
 #include <Select3D_SensitiveTriangulation.hxx>
+#include <Select3D_SensitivePrimitiveArray.hxx>
 #include <SelectMgr_SequenceOfOwner.hxx>
-#include <StdPrs_ToolDisk.hxx>
-#include <StdPrs_ToolCylinder.hxx>
-#include <StdPrs_ToolSphere.hxx>
 #include <TColgp_Array1OfPnt.hxx>
 #include <V3d_View.hxx>
 
@@ -640,10 +641,11 @@ void AIS_Manipulator::updateTransformation()
     aTrsf.SetTransformation (gp_Ax2 (gp::Origin(), aVDir, aXDir), gp::XOY());
   }
 
-  AIS_InteractiveObject::SetLocalTransformation (aTrsf);
-
-  Handle(Geom_Transformation) aGeomTrsf = new Geom_Transformation (this->Transformation());
-
+  Handle(Geom_Transformation) aGeomTrsf = new Geom_Transformation (aTrsf);
+  // we explicitly call here setLocalTransformation() of the base class
+  // since AIS_Manipulator::setLocalTransformation() implementation throws exception
+  // as protection from external calls
+  AIS_InteractiveObject::setLocalTransformation (aGeomTrsf);
   for (Standard_Integer anIt = 0; anIt < 3; ++anIt)
   {
     myAxes[anIt].Transform (aGeomTrsf);
@@ -651,10 +653,11 @@ void AIS_Manipulator::updateTransformation()
 
   if (myIsZoomPersistentMode)
   {
-    if (!(GetTransformPersistenceMode () == Graphic3d_TMF_ZoomPers
-       && GetTransformPersistencePoint().IsEqual (myPosition.Location(), 0.)))
+    if (TransformPersistence().IsNull()
+    ||  TransformPersistence()->Mode() != Graphic3d_TMF_ZoomPers
+    || !TransformPersistence()->AnchorPoint().IsEqual (myPosition.Location(), 0.0))
     {
-      setTransformPersistence (Graphic3d_TMF_ZoomPers, myPosition.Location());
+      setTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_ZoomPers, myPosition.Location()));
     }
   }
 }
@@ -734,7 +737,7 @@ void AIS_Manipulator::SetZoomPersistence (const Standard_Boolean theToEnable)
 
   if (!theToEnable)
   {
-    setTransformPersistence (Graphic3d_TMF_None, gp::Origin());
+    setTransformPersistence (Handle(Graphic3d_TransformPers)());
   }
 
   updateTransformation();
@@ -742,40 +745,39 @@ void AIS_Manipulator::SetZoomPersistence (const Standard_Boolean theToEnable)
 
 //=======================================================================
 //function : SetTransformPersistence
-//purpose  : 
+//purpose  :
 //=======================================================================
-void AIS_Manipulator::SetTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint)
+void AIS_Manipulator::SetTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
 {
   Standard_ASSERT_RETURN (!myIsZoomPersistentMode,
     "AIS_Manipulator::SetTransformPersistence: "
-    "Custom settings are not supported by this class in ZoomPersistence mode",);
+    "Custom settings are not allowed by this class in ZoomPersistence mode",);
 
-  setTransformPersistence (theFlag, thePoint);
+  setTransformPersistence (theTrsfPers);
 }
 
 //=======================================================================
 //function : setTransformPersistence
 //purpose  : 
 //=======================================================================
-void AIS_Manipulator::setTransformPersistence (const Graphic3d_TransModeFlags& theFlag, const gp_Pnt& thePoint)
+void AIS_Manipulator::setTransformPersistence (const Handle(Graphic3d_TransformPers)& theTrsfPers)
 {
-  AIS_InteractiveObject::SetTransformPersistence (theFlag, thePoint);
+  AIS_InteractiveObject::SetTransformPersistence (theTrsfPers);
 
   for (Standard_Integer anIt = 0; anIt < 3; ++anIt)
   {
-    myAxes[anIt].SetTransformPersistence (theFlag, thePoint);
+    myAxes[anIt].SetTransformPersistence (theTrsfPers);
   }
 }
 
 //=======================================================================
-//function : SetLocalTransformation
-//purpose  : 
+//function : setLocalTransformation
+//purpose  :
 //=======================================================================
-void AIS_Manipulator::SetLocalTransformation (const gp_Trsf& /*theTransformation*/)
+void AIS_Manipulator::setLocalTransformation (const Handle(Geom_Transformation)& /*theTrsf*/)
 {
-  Standard_ASSERT_INVOKE (
-    "AIS_Manipulator::SetLocalTransformation: "
-    "Custom transformation is not supported by this class");
+  Standard_ASSERT_INVOKE ("AIS_Manipulator::setLocalTransformation: "
+                          "Custom transformation is not supported by this class");
 }
 
 //=======================================================================
@@ -814,8 +816,7 @@ void AIS_Manipulator::Compute (const Handle(PrsMgr_PresentationManager3d)& thePr
     anAspectAx->SetColor (myAxes[anIt].Color());
     aGroup->SetGroupPrimitivesAspect (anAspectAx->Aspect());
     myAxes[anIt].Compute (thePrsMgr, thePrs, anAspectAx);
-    myAxes[anIt].SetTransformPersistence (GetTransformPersistenceMode(),
-                                          GetTransformPersistencePoint());
+    myAxes[anIt].SetTransformPersistence (TransformPersistence());
   }
 
   updateTransformation();
@@ -840,12 +841,12 @@ void AIS_Manipulator::HilightSelected (const Handle(PrsMgr_PresentationManager3d
 
   if (!theSeq (1)->IsKind (STANDARD_TYPE (AIS_ManipulatorOwner)))
   {
-    thePM->Color (this, GetContext()->HilightColor(), 0);
+    thePM->Color (this, GetContext()->HighlightStyle(), 0);
     return;
   }
 
   Handle(AIS_ManipulatorOwner) anOwner = Handle(AIS_ManipulatorOwner)::DownCast (theSeq (1));
-  myHighlightAspect->Aspect()->SetInteriorColor (GetContext()->HilightColor());
+  myHighlightAspect->Aspect()->SetInteriorColor (GetContext()->HighlightStyle()->Color());
   Handle(Graphic3d_Group) aGroup = getGroup (anOwner->Index(), anOwner->Mode());
   if (aGroup.IsNull())
   {
@@ -871,7 +872,9 @@ void AIS_Manipulator::ClearSelected()
 //function : HilightOwnerWithColor
 //purpose  : 
 //=======================================================================
-void AIS_Manipulator::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM, const Quantity_NameOfColor theColor, const Handle(SelectMgr_EntityOwner)& theOwner)
+void AIS_Manipulator::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManager3d)& thePM,
+                                             const Handle(Graphic3d_HighlightStyle)& theStyle,
+                                             const Handle(SelectMgr_EntityOwner)& theOwner)
 {
   Handle(AIS_ManipulatorOwner) anOwner = Handle(AIS_ManipulatorOwner)::DownCast (theOwner);
   Handle(Prs3d_Presentation) aPresentation = getHighlightPresentation (anOwner);
@@ -879,7 +882,7 @@ void AIS_Manipulator::HilightOwnerWithColor (const Handle(PrsMgr_PresentationMan
   {
     return;
   }
-  aPresentation->Highlight (Aspect_TOHM_COLOR, theColor);
+  aPresentation->Highlight (theStyle);
   for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aPresentation->Groups());
        aGroupIter.More(); aGroupIter.Next())
   {
@@ -923,7 +926,7 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe
   {
     anOwner = new SelectMgr_EntityOwner (this, 5);
   }
-  Handle(Select3D_SensitiveTriangulation) aTri;
+
   if (aMode == AIS_MM_Translation || aMode == AIS_MM_None)
   {
     for (Standard_Integer anIt = 0; anIt < 3; ++anIt)
@@ -937,12 +940,10 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe
       Handle(Select3D_SensitiveSegment) aLine = new Select3D_SensitiveSegment (anOwner, gp::Origin(), anAxis.TranslatorTipPosition());
       aLine->SetSensitivityFactor (15);
       theSelection->Add (aLine);
+
       // enlarge sensitivity by triangulation
-      aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorCylinder().Triangulation(), TopLoc_Location(), Standard_True);
-      theSelection->Add (aTri);
-      aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorArrow().Triangulation(), TopLoc_Location(), Standard_True);
-      theSelection->Add (aTri);
-      aTri = new Select3D_SensitiveTriangulation (anOwner, anAxis.TranslatorArrowBottom().Triangulation(), TopLoc_Location(), Standard_True);
+      Handle(Select3D_SensitivePrimitiveArray) aTri = new Select3D_SensitivePrimitiveArray (anOwner);
+      aTri->InitTriangulation (anAxis.TriangleArray()->Attributes(), anAxis.TriangleArray()->Indices(), TopLoc_Location());
       theSelection->Add (aTri);
     }
   }
@@ -962,7 +963,7 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe
       aCircle->SetSensitivityFactor (15);
       theSelection->Add (aCircle);
       // enlarge sensitivity by triangulation
-      aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].RotatorDisk().Triangulation(), TopLoc_Location(), Standard_True);
+      Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].RotatorDisk().Triangulation(), TopLoc_Location(), Standard_True);
       theSelection->Add (aTri);
     }
   }
@@ -980,35 +981,12 @@ void AIS_Manipulator::ComputeSelection (const Handle(SelectMgr_Selection)& theSe
       aPnt->SetSensitivityFactor (15);
       theSelection->Add (aPnt);
       // enlarge sensitivity by triangulation
-      aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].ScalerCube().Triangulation(), TopLoc_Location(), Standard_True);
+      Handle(Select3D_SensitiveTriangulation) aTri = new Select3D_SensitiveTriangulation (anOwner, myAxes[anIt].ScalerCube().Triangulation(), TopLoc_Location(), Standard_True);
       theSelection->Add (aTri);
     }
   }
 }
 
-//=======================================================================
-//class    : Cylinder
-//function : Init
-//purpose  : 
-//=======================================================================
-void AIS_Manipulator::Cylinder::Init (const Standard_ShortReal theBotRad, const Standard_ShortReal theTopRad,
-                                      const Standard_ShortReal theHeight,
-                                      const Standard_Integer theSlicesNb, const Standard_Integer theStacksNb,
-                                      const gp_Ax1& thePosition)
-{
-  myPosition = thePosition;
-  myBottomRad = theBotRad;
-  myTopRad = theTopRad;
-  myHeight = theHeight;
-
-  StdPrs_ToolCylinder aTool (myBottomRad, myTopRad, myHeight, theSlicesNb, theStacksNb);
-  gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction());
-  gp_Trsf aTrsf;
-  aTrsf.SetTransformation (aSystem, gp_Ax3());
-
-  aTool.FillArray (myArray, myTriangulation, aTrsf);
-}
-
 //=======================================================================
 //class    : Disk
 //function : Init
@@ -1024,7 +1002,7 @@ void AIS_Manipulator::Disk::Init (const Standard_ShortReal theInnerRadius,
   myInnerRad = theInnerRadius;
   myOuterRad = theOuterRadius;
 
-  StdPrs_ToolDisk aTool (theInnerRadius, theOuterRadius, theSlicesNb, theStacksNb);
+  Prs3d_ToolDisk aTool (theInnerRadius, theOuterRadius, theSlicesNb, theStacksNb);
   gp_Ax3 aSystem (myPosition.Location(), myPosition.Direction());
   gp_Trsf aTrsf;
   aTrsf.SetTransformation (aSystem, gp_Ax3());
@@ -1044,7 +1022,7 @@ void AIS_Manipulator::Sphere::Init (const Standard_ShortReal theRadius,
   myPosition = thePosition;
   myRadius = theRadius;
 
-  StdPrs_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb);
+  Prs3d_ToolSphere aTool (theRadius, theSlicesNb, theStacksNb);
   gp_Trsf aTrsf;
   aTrsf.SetTranslation (gp_Vec(gp::Origin(), thePosition));
   aTool.FillArray (myArray, myTriangulation, aTrsf);
@@ -1151,44 +1129,39 @@ AIS_Manipulator::Axis::Axis (const gp_Ax1& theAxis,
 //=======================================================================
 //class    : Axis
 //function : Compute
-//purpose  : 
+//purpose  :
 //=======================================================================
-void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d& thePrsMgr,
+
+void AIS_Manipulator::Axis::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
                                      const Handle(Prs3d_Presentation)& thePrs,
                                      const Handle(Prs3d_ShadingAspect)& theAspect)
 {
-  Handle(Graphic3d_Group) aGroup;
-
   if (myHasTranslation)
   {
-    const Standard_ShortReal anArrowLength = 0.25f * myLength;
-    const Standard_ShortReal aCylinderLength = myLength - anArrowLength;
-
-    myCylinder.Init (myAxisRadius, myAxisRadius, aCylinderLength, myFacettesNumber, 2, gp_Ax1 (gp::Origin(), myReferenceAxis.Direction()));
-
-    gp_Pnt anArrowBottom (0.0, 0.0, 0.0);
-    anArrowBottom.Translate (myReferenceAxis.Direction().XYZ() * aCylinderLength);
-
-    myArrow.Init (myAxisRadius * 1.5f, 0.0f, anArrowLength, myFacettesNumber, 2, gp_Ax1 (anArrowBottom, myReferenceAxis.Direction()));
-    myArrowBottom.Init (myAxisRadius, myAxisRadius * 1.5f, gp_Ax1 (anArrowBottom, myReferenceAxis.Direction()), myFacettesNumber);
-    myArrowTipPos = anArrowBottom;
-
+    const Standard_Real anArrowLength   = 0.25 * myLength;
+    const Standard_Real aCylinderLength = myLength - anArrowLength;
+    myArrowTipPos = gp_Pnt (0.0, 0.0, 0.0).Translated (myReferenceAxis.Direction().XYZ() * aCylinderLength);
+
+    myTriangleArray = Prs3d_Arrow::DrawShaded (gp_Ax1(gp::Origin(), myReferenceAxis.Direction()),
+                                               myAxisRadius,
+                                               myLength,
+                                               myAxisRadius * 1.5,
+                                               anArrowLength,
+                                               myFacettesNumber);
     myTranslatorGroup = Prs3d_Root::NewGroup (thePrs);
     myTranslatorGroup->SetGroupPrimitivesAspect (theAspect->Aspect());
-    myTranslatorGroup->AddPrimitiveArray (myCylinder.Array());
-    myTranslatorGroup->AddPrimitiveArray (myArrow.Array());
-    myTranslatorGroup->AddPrimitiveArray (myArrowBottom.Array());
+    myTranslatorGroup->AddPrimitiveArray (myTriangleArray);
 
     if (myHighlightTranslator.IsNull())
     {
       myHighlightTranslator = new Prs3d_Presentation (thePrsMgr->StructureManager());
     }
-
-    myHighlightTranslator->Clear();
-    aGroup = Prs3d_Root::CurrentGroup (myHighlightTranslator);
-    aGroup->AddPrimitiveArray (myCylinder.Array());
-    aGroup->AddPrimitiveArray (myArrow.Array());
-    aGroup->AddPrimitiveArray (myArrowBottom.Array());
+    else
+    {
+      myHighlightTranslator->Clear();
+    }
+    Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightTranslator);
+    aGroup->AddPrimitiveArray (myTriangleArray);
   }
 
   if (myHasScaling)
@@ -1204,9 +1177,11 @@ void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d&
     {
       myHighlightScaler = new Prs3d_Presentation (thePrsMgr->StructureManager());
     }
-
-    myHighlightScaler->Clear();
-    aGroup = Prs3d_Root::CurrentGroup (myHighlightScaler);
+    else
+    {
+      myHighlightScaler->Clear();
+    }
+    Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightScaler);
     aGroup->AddPrimitiveArray (myCube.Array());
   }
 
@@ -1222,9 +1197,11 @@ void AIS_Manipulator::Axis::Compute (const Handle_PrsMgr_PresentationManager3d&
     {
       myHighlightRotator = new Prs3d_Presentation (thePrsMgr->StructureManager());
     }
-
-    myHighlightRotator->Clear();
-    aGroup = Prs3d_Root::CurrentGroup (myHighlightRotator);
+    else
+    {
+      myHighlightRotator->Clear();
+    }
+    Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (myHighlightRotator);
     Prs3d_Root::CurrentGroup (myHighlightRotator)->AddPrimitiveArray (myCircle.Array());
   }
 }