0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / AIS / AIS_ColoredShape.cxx
index ef8b54a..ec68acf 100644 (file)
 #include <BRep_Builder.hxx>
 #include <BRepTools.hxx>
 #include <BRepMesh_IncrementalMesh.hxx>
-#include <gp_Pnt2d.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
 #include <Graphic3d_AspectLine3d.hxx>
 #include <Graphic3d_ArrayOfTriangles.hxx>
 #include <Graphic3d_ArrayOfSegments.hxx>
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_StructureManager.hxx>
-#include <Graphic3d_Texture2Dmanual.hxx>
 #include <Precision.hxx>
-#include <Prs3d.hxx>
-#include <Prs3d_LineAspect.hxx>
-#include <Prs3d_IsoAspect.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <Prs3d_ShadingAspect.hxx>
-#include <Prs3d_Root.hxx>
-#include <PrsMgr_PresentationManager3d.hxx>
-#include <Standard_ErrorHandler.hxx>
+#include <PrsMgr_PresentationManager.hxx>
 #include <StdSelect_BRepSelectionTool.hxx>
 #include <StdPrs_ShadedShape.hxx>
 #include <StdPrs_ToolTriangulatedShape.hxx>
 #include <StdPrs_WFShape.hxx>
 #include <TopExp_Explorer.hxx>
-#include <TopoDS.hxx>
 #include <TopoDS_Compound.hxx>
 #include <TopoDS_Iterator.hxx>
 
@@ -124,8 +116,7 @@ Handle(AIS_ColoredDrawer) AIS_ColoredShape::CustomAspects (const TopoDS_Shape& t
   {
     aDrawer = new AIS_ColoredDrawer (myDrawer);
     myShapeColors.Bind (theShape, aDrawer);
-    LoadRecomputable (AIS_WireFrame);
-    LoadRecomputable (AIS_Shaded);
+    SetToUpdate();
   }
   return aDrawer;
 }
@@ -141,8 +132,7 @@ void AIS_ColoredShape::ClearCustomAspects()
     return;
   }
   myShapeColors.Clear();
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
+  SetToUpdate();
 }
 
 //=======================================================================
@@ -157,8 +147,7 @@ void AIS_ColoredShape::UnsetCustomAspects (const TopoDS_Shape&    theShape,
     return;
   }
 
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
+  SetToUpdate();
   if (theToUnregister)
   {
     myShapeColors.UnBind (theShape);
@@ -183,8 +172,6 @@ void AIS_ColoredShape::SetCustomColor (const TopoDS_Shape&   theShape,
   const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
   setColor (aDrawer, theColor);
   aDrawer->SetOwnColor (theColor);
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
 }
 
 //=======================================================================
@@ -202,8 +189,6 @@ void AIS_ColoredShape::SetCustomTransparency (const TopoDS_Shape& theShape,
   const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
   setTransparency (aDrawer, theTransparency);
   aDrawer->SetOwnTransparency (theTransparency);
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
 }
 
 //=======================================================================
@@ -221,8 +206,6 @@ void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
   const Handle(AIS_ColoredDrawer)& aDrawer = CustomAspects (theShape);
   setWidth (aDrawer, theLineWidth);
   aDrawer->SetOwnWidth (theLineWidth);
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
 }
 
 //=======================================================================
@@ -232,11 +215,6 @@ void AIS_ColoredShape::SetCustomWidth (const TopoDS_Shape& theShape,
 
 void AIS_ColoredShape::SetColor (const Quantity_Color&  theColor)
 {
-  setColor (myDrawer, theColor);
-  myDrawer->SetColor (theColor);
-  hasOwnColor = Standard_True;
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
   for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
   {
     const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
@@ -262,6 +240,7 @@ void AIS_ColoredShape::SetColor (const Quantity_Color&  theColor)
       aDrawer->FaceBoundaryAspect()->SetColor (theColor);
     }
   }
+  AIS_Shape::SetColor (theColor);
 }
 
 //=======================================================================
@@ -271,10 +250,6 @@ void AIS_ColoredShape::SetColor (const Quantity_Color&  theColor)
 
 void AIS_ColoredShape::SetWidth (const Standard_Real    theLineWidth)
 {
-  setWidth (myDrawer, theLineWidth);
-  myOwnWidth = theLineWidth;
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
   for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
   {
     const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
@@ -296,6 +271,16 @@ void AIS_ColoredShape::SetWidth (const Standard_Real    theLineWidth)
       aDrawer->FaceBoundaryAspect()->SetWidth (theLineWidth);
     }
   }
+  AIS_Shape::SetWidth (theLineWidth);
+}
+
+//=======================================================================
+//function : UnsetWidth
+//purpose  :
+//=======================================================================
+void AIS_ColoredShape::UnsetWidth()
+{
+  SetWidth (1.0f);
 }
 
 //=======================================================================
@@ -305,10 +290,6 @@ void AIS_ColoredShape::SetWidth (const Standard_Real    theLineWidth)
 
 void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
 {
-  setTransparency (myDrawer, theValue);
-  myDrawer->SetTransparency ((Standard_ShortReal )theValue);
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (AIS_Shaded);
   for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
   {
     const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
@@ -322,6 +303,7 @@ void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
       aDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
     }
   }
+  AIS_Shape::SetTransparency (theValue);
 }
 
 //=======================================================================
@@ -330,27 +312,7 @@ void AIS_ColoredShape::SetTransparency (const Standard_Real theValue)
 //=======================================================================
 void AIS_ColoredShape::UnsetTransparency()
 {
-  myDrawer->SetTransparency (0.0f);
-  if (myDrawer->HasOwnShadingAspect())
-  {
-    myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
-    if (!HasColor()
-     && !HasMaterial()
-     && !myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
-    {
-      myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
-    }
-  }
-
-  for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
-  {
-    const Handle(Prs3d_Drawer)& aDrawer = anIter.Value();
-    if (aDrawer->HasOwnShadingAspect())
-    {
-      aDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
-    }
-  }
-  SynchronizeAspects();
+  SetTransparency (0.0f);
 }
 
 //=======================================================================
@@ -360,28 +322,29 @@ void AIS_ColoredShape::UnsetTransparency()
 
 void AIS_ColoredShape::SetMaterial (const Graphic3d_MaterialAspect& theMaterial)
 {
-  setMaterial (myDrawer, theMaterial, HasColor(), IsTransparent());
-  //myOwnMaterial = theMaterial;
-  hasOwnMaterial = Standard_True;
-  LoadRecomputable (AIS_Shaded);
   for (AIS_DataMapOfShapeDrawer::Iterator anIter (myShapeColors); anIter.More(); anIter.Next())
   {
     const Handle(AIS_ColoredDrawer)& aDrawer = anIter.Value();
-    //if (aDrawer->HasOwnMaterial()) continue;
+    if (aDrawer->HasOwnMaterial())
+    {
+      continue;
+    }
+
     if (aDrawer->HasOwnShadingAspect())
     {
       setMaterial (aDrawer, theMaterial, aDrawer->HasOwnColor(), aDrawer->HasOwnTransparency());
     }
   }
+  AIS_Shape::SetMaterial (theMaterial);
 }
 
 //=======================================================================
 //function : Compute
 //purpose  :
 //=======================================================================
-void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
-                                const Handle(Prs3d_Presentation)&           thePrs,
-                                const Standard_Integer                      theMode)
+void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager)& thePrsMgr,
+                                const Handle(Prs3d_Presentation)& thePrs,
+                                const Standard_Integer theMode)
 {
   if (myshape.IsNull())
   {
@@ -401,7 +364,7 @@ void AIS_ColoredShape::Compute (const Handle(PrsMgr_PresentationManager3d)& theP
 
       // After this call if type of deflection is relative
       // computed deflection coefficient is stored as absolute.
-      Prs3d::GetDeflection (myshape, myDrawer);
+      StdPrs_ToolTriangulatedShape::GetDeflection (myshape, myDrawer);
       break;
     }
     case AIS_Shaded:
@@ -519,8 +482,8 @@ void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theS
   }
 
   const TopAbs_ShapeEnum aTypOfSel   = AIS_Shape::SelectionType (theMode);
-  const Standard_Real    aDeflection = Prs3d::GetDeflection (myshape, myDrawer);
-  const Standard_Real    aDeviationAngle = myDrawer->HLRAngle();
+  const Standard_Real    aDeflection = StdPrs_ToolTriangulatedShape::GetDeflection (myshape, myDrawer);
+  const Standard_Real    aDeviationAngle = myDrawer->DeviationAngle();
   const Standard_Integer aPriority   = StdSelect_BRepSelectionTool::GetStandardPriority (myshape, aTypOfSel);
   if (myDrawer->IsAutoTriangulation()
   && !BRepTools::Triangulation (myshape, Precision::Infinite()))
@@ -545,11 +508,9 @@ void AIS_ColoredShape::ComputeSelection (const Handle(SelectMgr_Selection)& theS
   Handle(SelectMgr_SelectableObject) aThis (this);
   for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
   {
-    Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelEntIter.Value()->BaseSensitive()->OwnerId());
-    anOwner->Set (aThis);
+    const Handle(SelectMgr_EntityOwner)& anOwner = aSelEntIter.Value()->BaseSensitive()->OwnerId();
+    anOwner->SetSelectable (aThis);
   }
-
-  StdSelect_BRepSelectionTool::PreBuildBVH (theSelection);
 }
 
 //=======================================================================
@@ -610,7 +571,7 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
                                                  const DataMapOfDrawerCompd& theDrawerClosedFaces,
                                                  const Standard_Integer theMode)
 {
-  Handle(Graphic3d_Group) anOpenGroup, aClosedGroup;
+  Handle(Graphic3d_Group) anOpenGroup, aClosedGroup, anEdgesGroup;
   for (size_t aShType = 0; aShType <= (size_t )TopAbs_SHAPE; ++aShType)
   {
     const Standard_Boolean isClosed = aShType == TopAbs_SHAPE;
@@ -664,7 +625,7 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
         {
           if (aShadedGroup.IsNull())
           {
-            aShadedGroup = Prs3d_Root::NewGroup (thePrs);
+            aShadedGroup = thePrs->NewGroup();
             aShadedGroup->SetClosed (isClosed);
           }
           aShadedGroup->SetPrimitivesAspect (aDrawer->ShadingAspect()->Aspect());
@@ -673,18 +634,15 @@ void AIS_ColoredShape::addShapesWithCustomProps (const Handle(Prs3d_Presentation
 
         if (aDrawer->FaceBoundaryDraw())
         {
-          Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw);
-          if (!aBndSegments.IsNull())
+          if (Handle(Graphic3d_ArrayOfSegments) aBndSegments = StdPrs_ShadedShape::FillFaceBoundaries (aShapeDraw, aDrawer->FaceBoundaryUpperContinuity()))
           {
-            if (aShadedGroup.IsNull())
+            if (anEdgesGroup.IsNull())
             {
-              aShadedGroup = Prs3d_Root::NewGroup (thePrs);
-              aShadedGroup->SetClosed (isClosed);
+              anEdgesGroup = thePrs->NewGroup();
             }
 
-            Handle(Graphic3d_AspectLine3d) aBoundaryAspect = aDrawer->FaceBoundaryAspect()->Aspect();
-            aShadedGroup->SetPrimitivesAspect (aBoundaryAspect);
-            aShadedGroup->AddPrimitiveArray (aBndSegments);
+            anEdgesGroup->SetPrimitivesAspect (aDrawer->FaceBoundaryAspect()->Aspect());
+            anEdgesGroup->AddPrimitiveArray (aBndSegments);
           }
         }
       }