0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / AIS / AIS_Trihedron.cxx
index a2d2e1f..5105e83 100644 (file)
@@ -19,7 +19,6 @@
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_TrihedronOwner.hxx>
 #include <Geom_Axis2Placement.hxx>
-#include <Geom_Transformation.hxx>
 #include <gp_Pnt.hxx>
 #include <Graphic3d_ArrayOfPoints.hxx>
 #include <Graphic3d_ArrayOfSegments.hxx>
@@ -32,8 +31,8 @@
 #include <Prs3d_DatumAspect.hxx>
 #include <Prs3d_Drawer.hxx>
 #include <Prs3d_LineAspect.hxx>
+#include <Prs3d_PointAspect.hxx>
 #include <Prs3d_Presentation.hxx>
-#include <Prs3d_Projector.hxx>
 #include <Prs3d_ShadingAspect.hxx>
 #include <Prs3d_Text.hxx>
 #include <Prs3d_TextAspect.hxx>
@@ -43,7 +42,6 @@
 #include <Select3D_SensitivePrimitiveArray.hxx>
 #include <Select3D_SensitiveSegment.hxx>
 #include <Select3D_SensitiveTriangle.hxx>
-#include <SelectBasics_EntityOwner.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <Standard_Type.hxx>
 
@@ -60,6 +58,8 @@ AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
   myTrihDispMode (Prs3d_DM_WireFrame),
   myComponent (theComponent)
 {
+  myAutoHilight = Standard_False;
+
   // selection priorities
   mySelectionPriority.Bind (Prs3d_DP_None,   5); // complete triedron: priority 5 (same as faces)
   mySelectionPriority.Bind (Prs3d_DP_Origin, 8); // origin: priority 8
@@ -71,6 +71,7 @@ AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
   {
     mySelectionPriority.Bind ((Prs3d_DatumParts )aPartIter, 5); // planes: priority: 5
   }
+  myHiddenLineAspect = new Graphic3d_AspectLine3d (Quantity_NOC_WHITE, Aspect_TOL_EMPTY, 1.0f);
 
   // trihedron labels
   myLabel.Bind (Prs3d_DP_XAxis, "X");
@@ -85,7 +86,7 @@ AIS_Trihedron::AIS_Trihedron (const Handle(Geom_Axis2Placement)& theComponent)
 void AIS_Trihedron::SetComponent (const Handle(Geom_Axis2Placement)& theComponent)
 {
   myComponent = theComponent;
-  LoadRecomputable (AIS_WireFrame);
+  SetToUpdate();
 }
 
 //=======================================================================
@@ -103,6 +104,8 @@ void AIS_Trihedron::setOwnDatumAspect()
   if (myDrawer->Link().IsNull())
     return;
 
+  myDrawer->DatumAspect()->SetDrawArrows (myDrawer->Link()->DatumAspect()->ToDrawArrows());
+  myDrawer->DatumAspect()->SetDrawLabels (myDrawer->Link()->DatumAspect()->ToDrawLabels());
   *myDrawer->DatumAspect()->TextAspect()->Aspect() =
                                      *myDrawer->Link()->DatumAspect()->TextAspect()->Aspect();
   *myDrawer->DatumAspect()->PointAspect()->Aspect() =
@@ -133,7 +136,7 @@ void AIS_Trihedron::SetSize(const Standard_Real aValue)
   setOwnDatumAspect();
   myDrawer->DatumAspect()->SetAxisLength(aValue, aValue, aValue);
 
-  Update();
+  SetToUpdate();
   UpdateSelection();
 }
 
@@ -160,7 +163,7 @@ void AIS_Trihedron::UnsetSize()
   }
   else
   {
-    Update();
+    SetToUpdate();
   }
   UpdateSelection();
 }
@@ -195,17 +198,6 @@ void AIS_Trihedron::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsM
   computePresentation (thePrsMgr, thePrs);
 }
 
-//=======================================================================
-//function : Compute
-//purpose  :
-//=======================================================================
-void AIS_Trihedron::Compute (const Handle(Prs3d_Projector)& theProjector,
-                             const Handle(Geom_Transformation)& theTrsf,
-                             const Handle(Prs3d_Presentation)& thePrs)
-{
-  PrsMgr_PresentableObject::Compute (theProjector, theTrsf, thePrs);
-}
-
 //=======================================================================
 //function : ComputeSelection
 //purpose  :
@@ -307,32 +299,37 @@ void AIS_Trihedron::HilightOwnerWithColor (const Handle(PrsMgr_PresentationManag
   aPresentation->Clear();
   const Prs3d_DatumParts aPart = anOwner->DatumPart();
   Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup (aPresentation);
-  Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
   if (aPart >= Prs3d_DP_XOYAxis && aPart <= Prs3d_DP_XOZAxis)
   {
     // planes selection is equal in both shading and wireframe mode
-    aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+    aGroup->SetGroupPrimitivesAspect (theStyle->LineAspect()->Aspect());
   }
   else
   {
     if (myTrihDispMode == Prs3d_DM_Shaded)
     {
-      aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect(aPart)->Aspect());
+      aGroup->SetGroupPrimitivesAspect (theStyle->ShadingAspect()->Aspect());
     }
     else
     {
       if (aPart == Prs3d_DP_Origin)
       {
-        aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
+        aGroup->SetGroupPrimitivesAspect (theStyle->PointAspect()->Aspect());
       }
       else
       {
-        aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect(aPart)->Aspect());
+        aGroup->SetGroupPrimitivesAspect(theStyle->LineAspect()->Aspect());
       }
     }
   }
   aGroup->AddPrimitiveArray (arrayOfPrimitives(aPart));
 
+  const Graphic3d_ZLayerId aLayer = theStyle->ZLayer() != Graphic3d_ZLayerId_UNKNOWN ? theStyle->ZLayer() : myDrawer->ZLayer();
+  if (aPresentation->GetZLayer() != aLayer)
+  {
+    aPresentation->SetZLayer (aLayer);
+  }
+
   aPresentation->Highlight (theStyle);
   thePM->AddToImmediateList (aPresentation);
 }
@@ -349,25 +346,22 @@ void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)&
     return;
   }
 
-  Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
   const bool isShadingMode = myTrihDispMode == Prs3d_DM_Shaded;
 
-  const Handle(Prs3d_Drawer)& aContextSelStyle = GetContext()->SelectionStyle();
-  const Quantity_Color& aSelectionColor = aContextSelStyle->Color();
+  Handle(Prs3d_Drawer) anAspect = !myHilightDrawer.IsNull() ? myHilightDrawer : GetContext()->SelectionStyle();
   for (SelectMgr_SequenceOfOwner::Iterator anIterator (theOwners); anIterator.More(); anIterator.Next())
   {
     const Handle(SelectMgr_EntityOwner)& anOwner = anIterator.Value();
     Handle(AIS_TrihedronOwner) aTrihedronOwner = Handle(AIS_TrihedronOwner)::DownCast(anOwner);
     if (aTrihedronOwner.IsNull())
     {
-      thePM->Color (this, aContextSelStyle, 0);
+      thePM->Color (this, anAspect, 0);
       continue;
     }
       
     const Prs3d_DatumParts aPart = aTrihedronOwner->DatumPart();
     Handle(Graphic3d_Group) aGroup;
-    if (mySelectedParts.Contains (aPart)
-    || !myPartToGroup.Find (aPart, aGroup))
+    if (mySelectedParts.Contains (aPart) || !myPartToGroup.Find (aPart, aGroup))
     {
       continue;
     }
@@ -375,27 +369,23 @@ void AIS_Trihedron::HilightSelected (const Handle(PrsMgr_PresentationManager3d)&
     if (aPart >= Prs3d_DP_XOYAxis
      && aPart <= Prs3d_DP_XOZAxis)
     {
-      getHighlightLineAspect()->SetColor (aSelectionColor);
-      aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+      aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
     }
     else
     {
       if (isShadingMode)
       {
-        getHighlightAspect()->SetColor (aSelectionColor);
-        aGroup->SetGroupPrimitivesAspect (getHighlightAspect()->Aspect());
+        aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect()->Aspect());
       }
       else
       {
         if (aPart == Prs3d_DP_Origin)
         {
-          getHighlightPointAspect()->SetColor (aSelectionColor);
-          aGroup->SetGroupPrimitivesAspect (getHighlightPointAspect()->Aspect());
+          aGroup->SetGroupPrimitivesAspect (anAspect->PointAspect()->Aspect());
         }
         else
         {
-          getHighlightLineAspect()->SetColor (aSelectionColor);
-          aGroup->SetGroupPrimitivesAspect (getHighlightLineAspect()->Aspect());
+          aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect()->Aspect());
         }
       }
     }
@@ -419,9 +409,9 @@ void AIS_Trihedron::ClearSelected()
     if (aPart >= Prs3d_DP_XOYAxis
      && aPart <= Prs3d_DP_XOZAxis)
     {
-      aGroup->SetGroupPrimitivesAspect (anAspect->LineAspect (aPart)->Aspect());
+      aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
     }
-    if (isShadingMode)
+    else if (isShadingMode)
     {
       aGroup->SetGroupPrimitivesAspect (anAspect->ShadingAspect (aPart)->Aspect());
     }
@@ -493,14 +483,14 @@ void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager
       anAxisGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
 
       // draw arrow
-      Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
-      anArrowGroup->SetPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
-
       Prs3d_DatumParts anArrowPart = anAspect->ArrowPartForAxis (aPart);
       if (!anAspect->DrawDatumPart (anArrowPart))
       {
         continue;
       }
+
+      Handle(Graphic3d_Group) anArrowGroup = Prs3d_Root::NewGroup (thePrs);
+      anArrowGroup->SetGroupPrimitivesAspect (anAspect->ArrowAspect()->Aspect());
       anArrowGroup->AddPrimitiveArray (arrayOfPrimitives (anArrowPart));
     }
   }
@@ -546,24 +536,8 @@ void AIS_Trihedron::computePresentation (const Handle(PrsMgr_PresentationManager
     Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup (thePrs);
     myPartToGroup.Bind (aPart, aGroup);
 
-    const Handle(Graphic3d_AspectLine3d)& aLineAspect = anAspect->LineAspect (aPart)->Aspect();
-    aLineAspect->SetType (Aspect_TOL_EMPTY);
-
     aGroup->AddPrimitiveArray (arrayOfPrimitives (aPart));
-    aGroup->SetGroupPrimitivesAspect (aLineAspect);
-  }
-}
-
-//=======================================================================
-//function : LoadRecomputable
-//purpose  :
-//=======================================================================
-void AIS_Trihedron::LoadRecomputable (const Standard_Integer theMode)
-{
-  myRecomputeEveryPrs = Standard_False;
-  if (!myToRecomputeModes.Contains (theMode))
-  {
-    myToRecomputeModes.Append (theMode);
+    aGroup->SetGroupPrimitivesAspect (myHiddenLineAspect);
   }
 }
 
@@ -714,18 +688,37 @@ void AIS_Trihedron::UnsetColor()
   }
 }
 
+//=======================================================================
+//function : ToDrawArrows
+//purpose  :
+//=======================================================================
+Standard_Boolean AIS_Trihedron::ToDrawArrows() const
+{
+  return myDrawer->DatumAspect()->ToDrawArrows();
+}
+
+//=======================================================================
+//function : SetDrawArrows
+//purpose  :
+//=======================================================================
+void AIS_Trihedron::SetDrawArrows (const Standard_Boolean theToDraw)
+{
+  setOwnDatumAspect();
+  myDrawer->DatumAspect()->SetDrawArrows (theToDraw);
+}
+
 //=======================================================================
 //function : createSensitiveEntity
 //purpose  :
 //=======================================================================
-Handle(SelectBasics_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
-                                                   const Handle(SelectBasics_EntityOwner)& theOwner) const
+Handle(Select3D_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const Prs3d_DatumParts thePart,
+                                                   const Handle(SelectMgr_EntityOwner)& theOwner) const
 {
   Handle(Prs3d_DatumAspect) anAspect = myDrawer->DatumAspect();
   Handle(Graphic3d_ArrayOfPrimitives) aPrimitives = arrayOfPrimitives (thePart);
   if (aPrimitives.IsNull())
   {
-    return Handle(SelectBasics_SensitiveEntity)();
+    return Handle(Select3D_SensitiveEntity)();
   }
 
   if (thePart >= Prs3d_DP_XOYAxis
@@ -755,7 +748,7 @@ Handle(SelectBasics_SensitiveEntity) AIS_Trihedron::createSensitiveEntity (const
     const gp_Pnt anXYZ2 = aSegments->Vertice (2);
     return new Select3D_SensitiveSegment (theOwner, anXYZ1, anXYZ2);
   }
-  return Handle(SelectBasics_SensitiveEntity)();
+  return Handle(Select3D_SensitiveEntity)();
 }
 
 // =======================================================================
@@ -921,64 +914,19 @@ void AIS_Trihedron::updatePrimitives(const Handle(Prs3d_DatumAspect)& theAspect,
   }
 }
 
-// =======================================================================
-// function : getHighlightAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_ShadingAspect) AIS_Trihedron::getHighlightAspect()
-{
-  if (!myHighlightAspect.IsNull())
-    return myHighlightAspect;
-
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-
-  myHighlightAspect = new Prs3d_ShadingAspect();
-  myHighlightAspect->Aspect()->SetInteriorStyle (Aspect_IS_SOLID);
-  myHighlightAspect->SetColor (aHighlightColor);
-
-  Graphic3d_MaterialAspect aHighlightMaterial;
-  aHighlightMaterial.SetColor (aHighlightColor);
-  myHighlightAspect->SetMaterial (aHighlightMaterial);
-
-  return myHighlightAspect;
-}
-
-// =======================================================================
-// function : getHighlightLineAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_LineAspect) AIS_Trihedron::getHighlightLineAspect()
-{
-  if (!myHighlightLineAspect.IsNull())
-    return myHighlightLineAspect;
-
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-
-  Handle(Prs3d_DatumAspect) aDatumAspect = Attributes()->DatumAspect();
-  Handle(Prs3d_LineAspect) aLineAspect = aDatumAspect->LineAspect(Prs3d_DP_XAxis);
-  myHighlightLineAspect = new Prs3d_LineAspect (aHighlightColor, aLineAspect->Aspect()->Type(),
-                                                aLineAspect->Aspect()->Width());
-
-  return myHighlightLineAspect;
-}
-
-// =======================================================================
-// function : getHighlightPointAspect
-// purpose  :
-// =======================================================================
-Handle(Prs3d_PointAspect) AIS_Trihedron::getHighlightPointAspect()
+//=======================================================================
+//function : DumpJson
+//purpose  : 
+//=======================================================================
+void AIS_Trihedron::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
 {
-  if (!myHighlightPointAspect.IsNull())
-    return myHighlightPointAspect;
+  OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
 
-  Quantity_Color aHighlightColor = Quantity_NOC_GRAY80;
-  if (!myHilightDrawer.IsNull())
-    aHighlightColor = myHilightDrawer->Color();
-  myHighlightPointAspect = new Prs3d_PointAspect (Aspect_TOM_PLUS, aHighlightColor, 1.0);
+  OCCT_DUMP_BASE_CLASS (theOStream, theDepth, AIS_InteractiveObject)
 
-  return myHighlightPointAspect;
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnSize)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnTextColor)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnArrowColor)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myHasOwnDatumAspect)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myTrihDispMode)
 }