0026978: VIS - Interactive selection is insensitive to swept shell
[occt.git] / src / AIS / AIS_Shape.cxx
index b22bc6e..adfd5cc 100644 (file)
@@ -48,7 +48,6 @@
 #include <Prs3d_ShadingAspect.hxx>
 #include <StdPrs_BndBox.hxx>
 #include <StdPrs_ToolTriangulatedShape.hxx>
-#include <PrsMgr_ModedPresentation.hxx>
 #include <Quantity_Color.hxx>
 #include <Select3D_SensitiveBox.hxx>
 #include <Select3D_SensitiveEntity.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(AIS_Shape,AIS_InteractiveObject)
 
-static Standard_Boolean IsInList(const TColStd_ListOfInteger& LL, const Standard_Integer aMode)
+// Auxiliary macros
+#define replaceAspectWithDef(theMap, theAspect) \
+  if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
+  { \
+    theMap.Bind (myDrawer->theAspect()->Aspect(), myDrawer->Link()->theAspect()->Aspect()); \
+  }
+
+// Auxiliary macros for replaceWithNewOwnAspects()
+#define replaceAspectWithOwn(theMap, theAspect) \
+  if (myDrawer->Link()->theAspect()->Aspect() != myDrawer->theAspect()->Aspect()) \
+  { \
+    theMap.Bind (myDrawer->Link()->theAspect()->Aspect(), myDrawer->theAspect()->Aspect()); \
+  }
+
+//=======================================================================
+//function : replaceWithNewOwnAspects
+//purpose  :
+//=======================================================================
+void AIS_Shape::replaceWithNewOwnAspects()
 {
-  TColStd_ListIteratorOfListOfInteger It(LL);
-  for(;It.More();It.Next()){
-    if(It.Value()==aMode) 
-      return Standard_True;}
-  return Standard_False;
+  Graphic3d_MapOfAspectsToAspects aReplaceMap;
+
+  replaceAspectWithOwn (aReplaceMap, ShadingAspect);
+  replaceAspectWithOwn (aReplaceMap, LineAspect);
+  replaceAspectWithOwn (aReplaceMap, WireAspect);
+  replaceAspectWithOwn (aReplaceMap, FreeBoundaryAspect);
+  replaceAspectWithOwn (aReplaceMap, UnFreeBoundaryAspect);
+  replaceAspectWithOwn (aReplaceMap, SeenLineAspect);
+  replaceAspectWithOwn (aReplaceMap, FaceBoundaryAspect);
+  replaceAspectWithOwn (aReplaceMap, PointAspect);
+
+  replaceAspects (aReplaceMap);
 }
 
 //==================================================
@@ -350,78 +374,9 @@ bool AIS_Shape::setColor (const Handle(Prs3d_Drawer)& theDrawer,
                           const Quantity_Color&       theColor) const
 {
   bool toRecompute = false;
-  if (!theDrawer->HasOwnShadingAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnLineAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnWireAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnPointAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_PLUS, Quantity_NOC_BLACK, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnFreeBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnUnFreeBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnSeenLineAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnFaceBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect();
-    }
-  }
+  toRecompute = theDrawer->SetupOwnShadingAspect() || toRecompute;
+  toRecompute = theDrawer->SetOwnLineAspects() || toRecompute;
+  toRecompute = theDrawer->SetupOwnPointAspect() || toRecompute;
 
   // override color
   theDrawer->ShadingAspect()->SetColor (theColor, myCurrentFacingModel);
@@ -445,52 +400,17 @@ void AIS_Shape::SetColor (const Quantity_Color& theColor)
   const bool toRecompute = setColor (myDrawer, theColor);
   myDrawer->SetColor (theColor);
   hasOwnColor = Standard_True;
-  if (!toRecompute)
+
+  if (!toRecompute
+   || !myDrawer->HasLink())
   {
-    myToRecomputeModes.Clear();
-    myRecomputeEveryPrs = false;
     SynchronizeAspects();
-    return;
   }
-
-  // modify shading presentation without re-computation
-  const PrsMgr_Presentations&        aPrsList     = Presentations();
-  Handle(Graphic3d_AspectFillArea3d) anAreaAspect = myDrawer->ShadingAspect()->Aspect();
-  Handle(Graphic3d_AspectLine3d)     aLineAspect  = myDrawer->LineAspect()->Aspect();
-  Handle(Graphic3d_AspectMarker3d)   aPointAspect = myDrawer->PointAspect()->Aspect();
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
+  else
   {
-    const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
-    if (aPrsModed.Mode() != AIS_Shaded)
-    {
-      continue;
-    }
-
-    const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
-    {
-      const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
-
-      // Check if aspect of given type is set for the group, 
-      // because setting aspect for group with no already set aspect
-      // can lead to loss of presentation data
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
-      {
-        aGroup->SetGroupPrimitivesAspect (anAreaAspect);
-      }
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_LINE))
-      {
-        aGroup->SetGroupPrimitivesAspect (aLineAspect);
-      }
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_MARKER))
-      {
-        aGroup->SetGroupPrimitivesAspect (aPointAspect);
-      }
-    }
+    replaceWithNewOwnAspects();
   }
-
-  LoadRecomputable (AIS_WireFrame);
-  LoadRecomputable (2);
+  recomputeComputed();
 }
 
 //=======================================================================
@@ -502,23 +422,27 @@ void AIS_Shape::UnsetColor()
 {
   if (!HasColor())
   {
-    myToRecomputeModes.Clear();
-    myRecomputeEveryPrs = false;
     return;
   }
 
   hasOwnColor = Standard_False;
   myDrawer->SetColor (myDrawer->HasLink() ? myDrawer->Link()->Color() : Quantity_Color (Quantity_NOC_WHITE));
 
+  Graphic3d_MapOfAspectsToAspects aReplaceMap;
   if (!HasWidth())
   {
-    Handle(Prs3d_LineAspect) anEmptyAsp;
-    myDrawer->SetLineAspect          (anEmptyAsp);
-    myDrawer->SetWireAspect          (anEmptyAsp);
-    myDrawer->SetFreeBoundaryAspect  (anEmptyAsp);
-    myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
-    myDrawer->SetSeenLineAspect      (anEmptyAsp);
-    myDrawer->SetFaceBoundaryAspect  (anEmptyAsp);
+    replaceAspectWithDef (aReplaceMap, LineAspect);
+    replaceAspectWithDef (aReplaceMap, WireAspect);
+    replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
+    replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
+    replaceAspectWithDef (aReplaceMap, SeenLineAspect);
+    replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
+    myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
+    myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
+    myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
+    myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
+    myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
+    myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
   }
   else
   {
@@ -600,10 +524,17 @@ void AIS_Shape::UnsetColor()
   }
   else
   {
+    replaceAspectWithDef (aReplaceMap, ShadingAspect);
     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
   }
-  myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
-  myRecomputeEveryPrs = true;
+  if (myDrawer->HasOwnPointAspect())
+  {
+    replaceAspectWithDef (aReplaceMap, PointAspect);
+    myDrawer->SetPointAspect (Handle(Prs3d_PointAspect)());
+  }
+  replaceAspects (aReplaceMap);
+  SynchronizeAspects();
+  recomputeComputed();
 }
 
 //=======================================================================
@@ -614,61 +545,7 @@ void AIS_Shape::UnsetColor()
 bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
                           const Standard_Real         theLineWidth) const
 {
-  bool toRecompute = false;
-  if (!theDrawer->HasOwnLineAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnWireAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnFreeBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnUnFreeBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnSeenLineAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetSeenLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->SeenLineAspect()->Aspect() = *theDrawer->Link()->SeenLineAspect()->Aspect();
-    }
-  }
-  if (!theDrawer->HasOwnFaceBoundaryAspect())
-  {
-    toRecompute = true;
-    theDrawer->SetFaceBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->FaceBoundaryAspect()->Aspect() = *theDrawer->Link()->FaceBoundaryAspect()->Aspect();
-    }
-  }
+  bool toRecompute = theDrawer->SetOwnLineAspects();
 
   // override width
   theDrawer->LineAspect()->SetWidth (theLineWidth);
@@ -687,17 +564,18 @@ bool AIS_Shape::setWidth (const Handle(Prs3d_Drawer)& theDrawer,
 
 void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
 {
-  myOwnWidth = theLineWidth;
-  if (setWidth (myDrawer, theLineWidth))
+  myOwnWidth = (Standard_ShortReal )theLineWidth;
+
+  if (!setWidth (myDrawer, theLineWidth)
+   || !myDrawer->HasLink())
   {
-    myRecomputeEveryPrs = true;
+    SynchronizeAspects();
   }
   else
   {
-    myRecomputeEveryPrs = false;
-    myToRecomputeModes.Clear();
-    SynchronizeAspects();
+    replaceWithNewOwnAspects();
   }
+  recomputeComputed();
 }
 
 //=======================================================================
@@ -707,24 +585,28 @@ void AIS_Shape::SetWidth (const Standard_Real theLineWidth)
 
 void AIS_Shape::UnsetWidth()
 {
-  if (myOwnWidth == 0.0)
+  if (myOwnWidth == 0.0f)
   {
-    myToRecomputeModes.Clear();
-    myRecomputeEveryPrs = false;
     return;
   }
 
-  myOwnWidth = 0.0;
+  myOwnWidth = 0.0f;
   if (!HasColor())
   {
-    const Handle(Prs3d_LineAspect) anEmptyAsp;
-    myDrawer->SetLineAspect          (anEmptyAsp);
-    myDrawer->SetWireAspect          (anEmptyAsp);
-    myDrawer->SetFreeBoundaryAspect  (anEmptyAsp);
-    myDrawer->SetUnFreeBoundaryAspect(anEmptyAsp);
-    myDrawer->SetSeenLineAspect      (anEmptyAsp);
-    myDrawer->SetFaceBoundaryAspect  (anEmptyAsp);
-    myRecomputeEveryPrs = true;
+    Graphic3d_MapOfAspectsToAspects aReplaceMap;
+    replaceAspectWithDef (aReplaceMap, LineAspect);
+    replaceAspectWithDef (aReplaceMap, WireAspect);
+    replaceAspectWithDef (aReplaceMap, FreeBoundaryAspect);
+    replaceAspectWithDef (aReplaceMap, UnFreeBoundaryAspect);
+    replaceAspectWithDef (aReplaceMap, SeenLineAspect);
+    replaceAspectWithDef (aReplaceMap, FaceBoundaryAspect);
+    myDrawer->SetLineAspect          (Handle(Prs3d_LineAspect)());
+    myDrawer->SetWireAspect          (Handle(Prs3d_LineAspect)());
+    myDrawer->SetFreeBoundaryAspect  (Handle(Prs3d_LineAspect)());
+    myDrawer->SetUnFreeBoundaryAspect(Handle(Prs3d_LineAspect)());
+    myDrawer->SetSeenLineAspect      (Handle(Prs3d_LineAspect)());
+    myDrawer->SetFaceBoundaryAspect  (Handle(Prs3d_LineAspect)());
+    replaceAspects (aReplaceMap);
   }
   else
   {
@@ -741,9 +623,8 @@ void AIS_Shape::UnsetWidth()
     myDrawer->FaceBoundaryAspect()      ->SetWidth (myDrawer->HasLink() ?
       AIS_GraphicTool::GetLineWidth (myDrawer->Link(), AIS_TOA_FaceBoundary) : 1.);
     SynchronizeAspects();
-    myToRecomputeModes.Clear();
-    myRecomputeEveryPrs = false;
   }
+  recomputeComputed();
 }
 
 //=======================================================================
@@ -758,14 +639,7 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
 {
   const Quantity_Color aColor  = theDrawer->ShadingAspect()->Material     (myCurrentFacingModel).Color();
   const Standard_Real  aTransp = theDrawer->ShadingAspect()->Transparency (myCurrentFacingModel);
-  if (!theDrawer->HasOwnShadingAspect())
-  {
-    theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
-    }
-  }
+  theDrawer->SetupOwnShadingAspect();
   theDrawer->ShadingAspect()->SetMaterial (theMaterial, myCurrentFacingModel);
 
   if (theToKeepColor)
@@ -785,37 +659,19 @@ void AIS_Shape::setMaterial (const Handle(Prs3d_Drawer)&     theDrawer,
 
 void AIS_Shape::SetMaterial (const Graphic3d_MaterialAspect& theMat)
 {
+  const bool toRecompute = !myDrawer->HasOwnShadingAspect();
   setMaterial (myDrawer, theMat, HasColor(), IsTransparent());
   hasOwnMaterial = Standard_True;
 
-  // modify shading presentation without re-computation
-  const PrsMgr_Presentations&        aPrsList  = Presentations();
-  Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
+  if (!toRecompute
+   || !myDrawer->HasLink())
   {
-    const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
-    if (aPrsModed.Mode() != AIS_Shaded)
-    {
-      continue;
-    }
-
-    const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
-    {
-      const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
-
-      // Check if aspect of given type is set for the group, 
-      // because setting aspect for group with no already set aspect
-      // can lead to loss of presentation data
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
-      {
-        aGroup->SetGroupPrimitivesAspect (anAreaAsp);
-      }
-    }
+    SynchronizeAspects();
+  }
+  else
+  {
+    replaceWithNewOwnAspects();
   }
-
-  myRecomputeEveryPrs = Standard_False; // no mode to recalculate  :only viewer update
-  myToRecomputeModes.Clear();
 }
 
 //=======================================================================
@@ -848,37 +704,15 @@ void AIS_Shape::UnsetMaterial()
       myDrawer->ShadingAspect()->SetColor        (myDrawer->Color(),        myCurrentFacingModel);
       myDrawer->ShadingAspect()->SetTransparency (myDrawer->Transparency(), myCurrentFacingModel);
     }
+    SynchronizeAspects();
   }
   else
   {
+    Graphic3d_MapOfAspectsToAspects aReplaceMap;
+    replaceAspectWithDef (aReplaceMap, ShadingAspect);
     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
+    replaceAspects (aReplaceMap);
   }
-  hasOwnMaterial = Standard_False;
-
-  // modify shading presentation without re-computation
-  const PrsMgr_Presentations&        aPrsList  = Presentations();
-  Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
-  {
-    const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
-    if (aPrsModed.Mode() != AIS_Shaded)
-    {
-      continue;
-    }
-
-    const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
-    {
-      const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
-      {
-        aGroup->SetGroupPrimitivesAspect (anAreaAsp);
-      }
-    }
-  }
-
-  myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
-  myToRecomputeModes.Clear();  
 }
 
 //=======================================================================
@@ -889,15 +723,7 @@ void AIS_Shape::UnsetMaterial()
 void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
                                  const Standard_Real         theValue) const
 {
-  if (!theDrawer->HasOwnShadingAspect())
-  {
-    theDrawer->SetShadingAspect (new Prs3d_ShadingAspect());
-    if (theDrawer->HasLink())
-    {
-      *theDrawer->ShadingAspect()->Aspect() = *theDrawer->Link()->ShadingAspect()->Aspect();
-    }
-  }
-
+  theDrawer->SetupOwnShadingAspect();
   // override transparency
   theDrawer->ShadingAspect()->SetTransparency (theValue, myCurrentFacingModel);
 }
@@ -909,33 +735,19 @@ void AIS_Shape::setTransparency (const Handle(Prs3d_Drawer)& theDrawer,
 
 void AIS_Shape::SetTransparency (const Standard_Real theValue)
 {
+  const bool toRecompute = !myDrawer->HasOwnShadingAspect();
   setTransparency (myDrawer, theValue);
   myDrawer->SetTransparency ((Standard_ShortReal )theValue);
 
-  // modify shading presentation without re-computation
-  const PrsMgr_Presentations&        aPrsList  = Presentations();
-  Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
+  if (!toRecompute
+   || !myDrawer->HasLink())
   {
-    const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
-    if (aPrsModed.Mode() != AIS_Shaded)
-    {
-      continue;
-    }
-
-    const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
-    {
-      const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
-      {
-        aGroup->SetGroupPrimitivesAspect (anAreaAsp);
-      }
-    }
+    SynchronizeAspects();
+  }
+  else
+  {
+    replaceWithNewOwnAspects();
   }
-
-  myRecomputeEveryPrs = Standard_False; // no mode to recalculate - only viewer update
-  myToRecomputeModes.Clear();
 }
 
 //=======================================================================
@@ -955,48 +767,15 @@ void AIS_Shape::UnsetTransparency()
         || myDrawer->ShadingAspect()->Aspect()->ToMapTexture())
   {
     myDrawer->ShadingAspect()->SetTransparency (0.0, myCurrentFacingModel);
+    SynchronizeAspects();
   }
   else
   {
+    Graphic3d_MapOfAspectsToAspects aReplaceMap;
+    replaceAspectWithDef (aReplaceMap, ShadingAspect);
     myDrawer->SetShadingAspect (Handle(Prs3d_ShadingAspect)());
+    replaceAspects (aReplaceMap);
   }
-
-  // modify shading presentation without re-computation
-  const PrsMgr_Presentations&        aPrsList  = Presentations();
-  Handle(Graphic3d_AspectFillArea3d) anAreaAsp = myDrawer->ShadingAspect()->Aspect();
-  for (Standard_Integer aPrsIt = 1; aPrsIt <= aPrsList.Length(); ++aPrsIt)
-  {
-    const PrsMgr_ModedPresentation& aPrsModed = aPrsList.Value (aPrsIt);
-    if (aPrsModed.Mode() != AIS_Shaded)
-    {
-      continue;
-    }
-
-    const Handle(Prs3d_Presentation)& aPrs = aPrsModed.Presentation()->Presentation();
-    for (Graphic3d_SequenceOfGroup::Iterator aGroupIt (aPrs->Groups()); aGroupIt.More(); aGroupIt.Next())
-    {
-      const Handle(Graphic3d_Group)& aGroup = aGroupIt.Value();
-      if (aGroup->IsGroupPrimitivesAspectSet (Graphic3d_ASPECT_FILL_AREA))
-      {
-        aGroup->SetGroupPrimitivesAspect (anAreaAsp);
-      }
-    }
-  }
-
-  myRecomputeEveryPrs = Standard_False; // no mode to recalculate :only viewer update
-  myToRecomputeModes.Clear();
-}
-
-//=======================================================================
-//function : LoadRecomputable
-//purpose  : 
-//=======================================================================
-
-void AIS_Shape::LoadRecomputable(const Standard_Integer TheMode)
-{
-  myRecomputeEveryPrs = Standard_False;
-  if(!IsInList(myToRecomputeModes,TheMode))
-    myToRecomputeModes.Append(TheMode);
 }
 
 //=======================================================================
@@ -1014,7 +793,7 @@ const Bnd_Box& AIS_Shape::BoundingBox()
   }
 
   if(myCompBB) {
-    BRepBndLib::AddClose(myshape, myBB);
+    BRepBndLib::Add (myshape, myBB, false);
     myCompBB = Standard_False;
   }
   return myBB;
@@ -1085,8 +864,7 @@ Standard_Boolean AIS_Shape::SetOwnHLRDeviationAngle ()
 void AIS_Shape::SetOwnDeviationCoefficient ( const Standard_Real  aCoefficient )
 {
   myDrawer->SetDeviationCoefficient( aCoefficient );
-  SetToUpdate(0) ; // WireFrame
-  SetToUpdate(1) ; // Shadding
+  SetToUpdate();
 }
 
 //=======================================================================
@@ -1105,11 +883,10 @@ void AIS_Shape::SetOwnHLRDeviationCoefficient ( const Standard_Real  aCoefficien
 //purpose  : 
 //=======================================================================
 
-void AIS_Shape::SetOwnDeviationAngle ( const Standard_Real  anAngle )
+void AIS_Shape::SetOwnDeviationAngle (const Standard_Real theAngle)
 {
-
-  myDrawer->SetDeviationAngle(anAngle );
-  SetToUpdate(0) ;   // WireFrame
+  myDrawer->SetDeviationAngle (theAngle);
+  SetToUpdate (AIS_WireFrame);
 }
 //=======================================================================
 //function : SetOwnDeviationAngle
@@ -1123,8 +900,7 @@ void AIS_Shape::SetAngleAndDeviation ( const Standard_Real  anAngle )
   SetOwnDeviationAngle(anAngle) ;
   SetOwnDeviationCoefficient(OutDefl) ;
   myInitAng = anAngle;
-  SetToUpdate(0);
-  SetToUpdate(1);
+  SetToUpdate();
 }
 
 //=======================================================================