0024047: Exception in TPrsStd_AISPresentation during destruction of TDocStd_Document
[occt.git] / src / AIS / AIS_InteractiveObject.cxx
index b36791e..d6289ae 100755 (executable)
@@ -28,9 +28,6 @@
 //                     instead a restricted object NameOfColor. 
 //                     Add SetCurrentFacingModel() method
 
-#define G003           //EUG/GG 260100 DEgenerate mode support
-//                     Add SetDegenerateModel() methods
-
 #define IMP020200      //GG Add SetTransformation() method
 
 #define IMP140200      //GG Add HasPresentation() and Presentation() methods
@@ -57,6 +54,9 @@
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
 #include <AIS_GraphicTool.hxx>
 #include <Graphic3d_AspectFillArea3d.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_AspectText3d.hxx>
 #include <Graphic3d_Group.hxx>
 #include <Graphic3d_Structure.hxx>
 
@@ -155,6 +155,8 @@ Handle(AIS_InteractiveContext) AIS_InteractiveObject::GetContext() const
 void AIS_InteractiveObject::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
 {
   myCTXPtr = aCtx.operator->();
+  if( aCtx.IsNull())
+    return;
   if (myDrawer.IsNull()) {
     myDrawer = new AIS_Drawer;
 #ifdef DEB
@@ -553,43 +555,6 @@ void AIS_InteractiveObject::SetInfiniteState(const Standard_Boolean aFlag)
       P->SetInfiniteState(myInfiniteState);}
 }
 
-#ifdef G003
-//=======================================================================
-//function : SetDegenerateModel
-//purpose  : 
-//=======================================================================
-void AIS_InteractiveObject::SetDegenerateModel(
-               const Aspect_TypeOfDegenerateModel aModel,
-               const Quantity_Ratio aRatio ) {
-  if( !HasColor() && !IsTransparent() && !HasMaterial() ) {
-    myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
-  }
-
-  myDrawer->ShadingAspect()->Aspect()->SetDegenerateModel(aModel,aRatio);
-
-  if(!GetContext().IsNull()){
-    if( GetContext()->MainPrsMgr()->HasPresentation(this,1)){
-      Handle(Prs3d_Presentation) P = 
-       GetContext()->MainPrsMgr()->CastPresentation(this,1)->Presentation();
-      Handle(Graphic3d_AspectFillArea3d) a4bis = 
-                               myDrawer->ShadingAspect()->Aspect();
-      P->SetPrimitivesAspect(a4bis);
-    }
-  }
-}
-
-//=======================================================================
-//function : DegenerateModel
-//purpose  : 
-//=======================================================================
-
-Aspect_TypeOfDegenerateModel AIS_InteractiveObject::DegenerateModel( 
-                       Quantity_Ratio& aRatio) const
-{
-  return myDrawer->ShadingAspect()->Aspect()->DegenerateModel(aRatio);
-}
-#endif
-
 #ifdef IMP020200
 //=======================================================================
 //function : SetTransformation
@@ -746,9 +711,9 @@ void AIS_InteractiveObject::SetAspect(const Handle(Prs3d_BasicAspect)& anAspect,
 //function : SetPolygonOffsets 
 //purpose  : 
 //======================================================================= 
-void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode,
-                                              const Standard_Real    aFactor,
-                                              const Standard_Real    aUnits) 
+void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer    aMode,
+                                              const Standard_ShortReal  aFactor,
+                                              const Standard_ShortReal  aUnits) 
 {
   if ( !HasPolygonOffsets() )
     myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
@@ -762,8 +727,27 @@ void AIS_InteractiveObject::SetPolygonOffsets(const Standard_Integer aMode,
       Handle(PrsMgr_Presentation3d)::DownCast( myPresentations(i).Presentation() );
     if ( !aPrs3d.IsNull() ) {
       aStruct = Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
-      if( !aStruct.IsNull() )
+      if( !aStruct.IsNull() ) {
         aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() );
+        // Workaround for issue 23115: Need to update also groups, because their
+        // face aspect ALWAYS overrides the structure's.
+        const Graphic3d_SequenceOfGroup& aGroups = aStruct->Groups();
+        Standard_Integer aGroupIndex = 1, aGroupNb = aGroups.Length();
+        for ( ; aGroupIndex <= aGroupNb; aGroupIndex++ ) {
+          Handle(Graphic3d_Group) aGrp = aGroups.Value(aGroupIndex);
+          if ( !aGrp.IsNull() && aGrp->IsGroupPrimitivesAspectSet(Graphic3d_ASPECT_FILL_AREA) ) {
+            Handle(Graphic3d_AspectFillArea3d) aFaceAsp = new Graphic3d_AspectFillArea3d();
+            Handle(Graphic3d_AspectLine3d) aLineAsp = new Graphic3d_AspectLine3d();
+            Handle(Graphic3d_AspectMarker3d) aPntAsp = new Graphic3d_AspectMarker3d();
+            Handle(Graphic3d_AspectText3d) aTextAsp = new Graphic3d_AspectText3d();
+            // TODO: Add methods for retrieving individual aspects from Graphic3d_Group
+            aGrp->GroupPrimitivesAspect(aLineAsp, aTextAsp, aPntAsp, aFaceAsp);
+            aFaceAsp->SetPolygonOffsets(aMode, aFactor, aUnits);
+            // TODO: Issue 23118 - This line kills texture data in the group...
+            aGrp->SetGroupPrimitivesAspect(aFaceAsp);
+          }
+        }
+      }
     }
   }
 }
@@ -784,45 +768,11 @@ Standard_Boolean AIS_InteractiveObject::HasPolygonOffsets() const
 //function : PolygonOffsets 
 //purpose  : 
 //=======================================================================
-void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode,
-                                           Standard_Real&    aFactor,
-                                           Standard_Real&    aUnits) const 
+void AIS_InteractiveObject::PolygonOffsets(Standard_Integer&    aMode,
+                                           Standard_ShortReal&  aFactor,
+                                           Standard_ShortReal&  aUnits) const 
 {
   if( HasPolygonOffsets() )
     myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits );
 }
-
-void AIS_InteractiveObject::Fill(const Handle(PrsMgr_PresentationManager)& aPresentationManager,
-                                 const Handle(PrsMgr_Presentation)& aPresentation,
-                                 const Standard_Integer aMode)
-{
-  PrsMgr_PresentableObject::Fill(aPresentationManager, aPresentation, aMode);
-
-  // Update polygon offsets for <aPresentation> using <myDrawer> data
-  if ( !myDrawer->ShadingAspect().IsNull() )
-  {
-    Standard_Integer aMode1 = Aspect_POM_Fill;
-    Standard_Real aFactor = 1., aUnits = 0.;
-    myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode1, aFactor, aUnits );
-
-    // Here we force this object to have default polygon offsets , if they are not 
-    // turned on for this object explicitly
-    if ( ( aMode1 & Aspect_POM_None ) == Aspect_POM_None )
-    {
-      aMode1 = Aspect_POM_Fill;
-      aFactor = 1.;
-      aUnits = 0.;
-      myDrawer->ShadingAspect()->Aspect()->SetPolygonOffsets( aMode1, aFactor, aUnits );
-    }
-  }
-
-  Handle(PrsMgr_Presentation3d) aPrs3d =
-    Handle(PrsMgr_Presentation3d)::DownCast( aPresentation );
-  if ( !aPrs3d.IsNull() ) {
-    Handle(Graphic3d_Structure) aStruct = 
-      Handle(Graphic3d_Structure)::DownCast( aPrs3d->Presentation() );
-    if( !aStruct.IsNull() )
-      aStruct->SetPrimitivesAspect( myDrawer->ShadingAspect()->Aspect() );
-  }
-}
 // OCC4895 SAN 22/03/04 High-level interface for controlling polygon offsets