0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / AIS / AIS_Shape.cxx
index c2721c5..1d3cdfc 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <AIS_Shape.hxx>
 
 #include <AIS_GraphicTool.hxx>
 #include <AIS_InteractiveContext.hxx>
-#include <AIS_Shape.hxx>
 #include <Aspect_TypeOfLine.hxx>
 #include <Bnd_Box.hxx>
 #include <BRep_Builder.hxx>
@@ -70,8 +70,6 @@
 
 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
 
-static Standard_Boolean myFirstCompute;
-
 static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
 {
   TColStd_ListIteratorOfListOfInteger It(LL);
@@ -92,9 +90,6 @@ AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant),
 myInitAng(0.)
 {
   Set (shap);
-  myFirstCompute = Standard_True;
-  SetHilightMode(0);
-  myDrawer->SetShadingAspectGlobal(Standard_False);
 }
 
 //=======================================================================
@@ -125,9 +120,8 @@ Standard_Boolean AIS_Shape::AcceptShapeDecomposition() const
 //=======================================================================
 void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentationManager*/,
                         const Handle(Prs3d_Presentation)& aPrs,
-                        const Standard_Integer aMode)
+                        const Standard_Integer theMode)
 {  
-  aPrs->Clear();
   if(myshape.IsNull()) return;
 
   // wire,edge,vertex -> pas de HLR + priorite display superieure
@@ -147,13 +141,14 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
 
   if (IsInfinite())
   {
-    aPrs->SetInfiniteState (Standard_True); //not taken in account duting FITALL
+    aPrs->SetInfiniteState (Standard_True); //not taken in account during FITALL
   }
 
-  switch (aMode)
+  switch (theMode)
   {
     case AIS_WireFrame:
     {
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       try
       {
         OCC_CATCH_SIGNALS
@@ -172,25 +167,13 @@ void AIS_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& /*aPresentat
     }
     case AIS_Shaded:
     {
-      if (myDrawer->IsAutoTriangulation())
-      {
-        Standard_Real anAnglePrev, anAngleNew, aCoeffPrev, aCoeffNew;
-        Standard_Boolean isOwnDeviationAngle       = OwnDeviationAngle      (anAngleNew, anAnglePrev);
-        Standard_Boolean isOwnDeviationCoefficient = OwnDeviationCoefficient(aCoeffNew,  aCoeffPrev);
-        if ((isOwnDeviationAngle       && Abs (anAngleNew - anAnglePrev) > Precision::Angular())
-         || (isOwnDeviationCoefficient && Abs (aCoeffNew  - aCoeffPrev)  > Precision::Confusion()))
-        {
-          BRepTools::Clean (myshape);
-        }
-      }
-
+      StdPrs_ToolTriangulatedShape::ClearOnOwnDeflectionChange (myshape, myDrawer, Standard_True);
       if ((Standard_Integer) myshape.ShapeType() > 4)
       {
         StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
       }
       else
       {
-        myDrawer->SetShadingAspectGlobal (Standard_False);
         if (IsInfinite())
         {
           StdPrs_WFShape::Add (aPrs, myshape, myDrawer);
@@ -398,8 +381,7 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
       return;
   }
 
-  static TopAbs_ShapeEnum TypOfSel;
-  TypOfSel = AIS_Shape::SelectionType(aMode);
+  TopAbs_ShapeEnum TypOfSel = AIS_Shape::SelectionType(aMode);
   TopoDS_Shape shape = myshape;
 
 // POP protection against crash in low layers
@@ -429,12 +411,6 @@ void AIS_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
   StdSelect::SetDrawerForBRepOwner(aSelection,myDrawer);
 }
 
-Quantity_NameOfColor AIS_Shape::Color() const {
-Quantity_Color aColor;
-  Color(aColor);
-  return aColor.Name();
-}
-
 void AIS_Shape::Color( Quantity_Color& aColor ) const {
   aColor = myDrawer->ShadingAspect()->Color(myCurrentFacingModel);
 }
@@ -447,16 +423,6 @@ Standard_Real AIS_Shape::Transparency() const {
   return myDrawer->ShadingAspect()->Transparency(myCurrentFacingModel);
 }
 
-//=======================================================================
-//function : SetColor
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::SetColor(const Quantity_NameOfColor aCol)
-{
-  SetColor(Quantity_Color(aCol));
-}
-
 //=======================================================================
 //function : setColor
 //purpose  :
@@ -524,7 +490,6 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
 
   // override color
   theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
-  theDrawer->SetShadingAspectGlobal (Standard_False);
   theDrawer->LineAspect()->SetColor (theColor);
   theDrawer->WireAspect()->SetColor (theColor);
   theDrawer->PointAspect()->SetColor (theColor);
@@ -541,7 +506,7 @@ void AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
 void AIS_Shape::SetColor (const Quantity_Color& theColor)
 {
   setColor (myDrawer, theColor);
-  myOwnColor  = theColor;
+  myDrawer->SetColor (theColor);
   hasOwnColor = Standard_True;
 
   // modify shading presentation without re-computation
@@ -558,13 +523,6 @@ void AIS_Shape::SetColor (const Quantity_Color& theColor)
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-
-    // Set aspects for presentation
-    aPrs->SetPrimitivesAspect (anAreaAspect);
-    aPrs->SetPrimitivesAspect (aLineAspect);
-    aPrs->SetPrimitivesAspect (aPointAspect);
-
-    // Go through all groups to change color for all primitives
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -668,7 +626,7 @@ void AIS_Shape::UnsetColor()
     if (IsTransparent())
     {
       Standard_Real aTransp = myDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
-      mat.SetTransparency (aTransp);
+      mat.SetTransparency (Standard_ShortReal(aTransp));
     }
     myDrawer->ShadingAspect()->SetMaterial (mat ,myCurrentFacingModel);
   }
@@ -691,10 +649,6 @@ void AIS_Shape::UnsetColor()
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-
-    aPrs->SetPrimitivesAspect (anAreaAsp);
-    aPrs->SetPrimitivesAspect (aLineAsp);
-
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -860,16 +814,6 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
   }
 }
 
-//=======================================================================
-//function : SetMaterial
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::SetMaterial(const Graphic3d_NameOfMaterial aMat)
-{
-  SetMaterial(Graphic3d_MaterialAspect(aMat));
-}
-
 //=======================================================================
 //function : SetMaterial
 //purpose  :
@@ -892,7 +836,6 @@ void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -933,8 +876,8 @@ void AIS_Shape::UnsetMaterial()
     }
     if (HasColor())
     {
-      myDrawer->ShadingAspect()->SetColor        (myOwnColor,     myCurrentFacingModel);
-      myDrawer->ShadingAspect()->SetTransparency (myTransparency, myCurrentFacingModel);
+      myDrawer->ShadingAspect()->SetColor        (myDrawer->Color(),        myCurrentFacingModel);
+      myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
     }
   }
   else
@@ -955,7 +898,6 @@ void AIS_Shape::UnsetMaterial()
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -999,7 +941,7 @@ void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
 void AIS_Shape::SetTransparency (const Standard_Real theValue)
 {
   setTransparency (myDrawer, theValue);
-  myTransparency = theValue;
+  myDrawer->SetTransparency ((Standard_ShortReal )theValue);
 
   // modify shading presentation without re-computation
   const PrsMgr_Presentations&        aPrsList  = Presentations();
@@ -1013,8 +955,6 @@ void AIS_Shape::SetTransparency (const Standard_Real theValue)
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
-    aPrs->SetDisplayPriority (10); // force highest priority for translucent objects
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -1036,7 +976,7 @@ void AIS_Shape::SetTransparency (const Standard_Real theValue)
 
 void AIS_Shape::UnsetTransparency()
 {
-  myTransparency = 0.0;
+  myDrawer->SetTransparency (0.0f);
   if (!myDrawer->HasOwnShadingAspect())
   {
     return;
@@ -1062,7 +1002,6 @@ void AIS_Shape::UnsetTransparency()
     }
 
     const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    aPrs->SetPrimitivesAspect (anAreaAsp);
     for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
     {
       const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
@@ -1071,7 +1010,6 @@ void AIS_Shape::UnsetTransparency()
         aGroup->SetGroupPrimitivesAspect (anAreaAsp);
       }
     }
-    aPrs->ResetDisplayPriority();
   }
 
   myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update