0031652: Visualization - crash on highlighting HLR Computed presentation displayed...
[occt.git] / src / PrsMgr / PrsMgr_PresentationManager.cxx
index ce0a0fd..b1deaba 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <PrsMgr_PresentationManager.hxx>
 
-#include <Geom_Transformation.hxx>
+#include <TopLoc_Datum3D.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
+#include <Prs3d_Drawer.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <Prs3d_PresentationShadow.hxx>
-#include <PrsMgr_ModedPresentation.hxx>
 #include <PrsMgr_PresentableObject.hxx>
 #include <PrsMgr_Presentation.hxx>
-#include <PrsMgr_PresentationManager.hxx>
 #include <PrsMgr_Presentations.hxx>
 #include <Standard_NoSuchObject.hxx>
 #include <Standard_Type.hxx>
 #include <TColStd_ListIteratorOfListOfTransient.hxx>
 #include <V3d_View.hxx>
 
-IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager,MMgt_TShared)
+IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager, Standard_Transient)
 
 // =======================================================================
 // function : PrsMgr_PresentationManager
@@ -35,8 +35,7 @@ IMPLEMENT_STANDARD_RTTIEXT(PrsMgr_PresentationManager,MMgt_TShared)
 // =======================================================================
 PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Graphic3d_StructureManager)& theStructureManager)
 : myStructureManager (theStructureManager),
-  myImmediateModeOn  (0),
-  mySelectionColor   (Quantity_NOC_GRAY99)
+  myImmediateModeOn  (0)
 {
   //
 }
@@ -58,7 +57,7 @@ void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)
 
     if (myImmediateModeOn > 0)
     {
-      AddToImmediateList (aPrs->Presentation());
+      AddToImmediateList (aPrs);
     }
     else
     {
@@ -70,9 +69,12 @@ void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)
     thePrsObj->Compute (this, Handle(Prs3d_Presentation)(), theMode);
   }
 
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Display (anIter.Value(), theMode);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      Display(anIter.Value(), theMode);
+    }
   }
 }
 
@@ -83,28 +85,31 @@ void PrsMgr_PresentationManager::Display (const Handle(PrsMgr_PresentableObject)
 void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)& thePrsObj,
                                         const Standard_Integer                  theMode)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Erase (anIter.Value(), theMode);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      Erase(anIter.Value(), theMode);
+    }
   }
 
   PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
-  for (PrsMgr_Presentations::Iterator anIt (aPrsList); anIt.More();)
+  for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More();)
   {
-    const PrsMgr_ModedPresentation& aModedPrs = anIt.Value();
-    if (aModedPrs.Presentation().IsNull())
+    const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
+    if (aPrs.IsNull())
     {
-      anIt.Next();
+      aPrsIter.Next();
       continue;
     }
 
-    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aModedPrs.Presentation()->PresentationManager();
-    if ((theMode == aModedPrs.Mode() || theMode == -1)
+    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
+    if ((theMode == aPrs->Mode() || theMode == -1)
      && (this == aPrsMgr))
     {
-      aModedPrs.Presentation()->Erase();
+      aPrs->Erase();
 
-      aPrsList.Remove (anIt);
+      aPrsList.Remove (aPrsIter);
 
       if (theMode != -1)
       {
@@ -113,7 +118,7 @@ void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)&
     }
     else
     {
-      anIt.Next();
+      aPrsIter.Next();
     }
   }
 }
@@ -125,9 +130,12 @@ void PrsMgr_PresentationManager::Erase (const Handle(PrsMgr_PresentableObject)&
 void PrsMgr_PresentationManager::Clear (const Handle(PrsMgr_PresentableObject)& thePrsObj,
                                         const Standard_Integer                  theMode)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Clear (anIter.Value(), theMode);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      Clear(anIter.Value(), theMode);
+    }
   }
 
   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
@@ -145,49 +153,22 @@ void PrsMgr_PresentationManager::SetVisibility (const Handle(PrsMgr_PresentableO
                                                 const Standard_Integer theMode,
                                                 const Standard_Boolean theValue)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
-  {
-    SetVisibility (anIter.Value(), theMode, theValue);
-  }
-  if (!thePrsObj->HasOwnPresentations())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    return;
-  }
-
-  Presentation (thePrsObj, theMode)->SetVisible (theValue);
-}
-
-// =======================================================================
-// function : Highlight
-// purpose  :
-// =======================================================================
-void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                            const Standard_Integer                  theMode)
-{
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
-  {
-    Highlight (anIter.Value(), theMode);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      SetVisibility(anIter.Value(), theMode, theValue);
+    }
   }
   if (!thePrsObj->HasOwnPresentations())
   {
     return;
   }
 
-  Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
-  if (aPrs->MustBeUpdated())
-  {
-    Update (thePrsObj, theMode);
-  }
-
-  if (myImmediateModeOn > 0)
-  {
-    Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
-    aShadow->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
-    AddToImmediateList (aShadow);
-  }
-  else
+  Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
+  if (!aPrs.IsNull())
   {
-    aPrs->Highlight (Aspect_TOHM_COLOR, mySelectionColor);
+    aPrs->SetVisible (theValue);
   }
 }
 
@@ -195,18 +176,26 @@ void PrsMgr_PresentationManager::Highlight (const Handle(PrsMgr_PresentableObjec
 // function : Unhighlight
 // purpose  :
 // =======================================================================
-void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                              const Standard_Integer                  theMode)
+void PrsMgr_PresentationManager::Unhighlight (const Handle(PrsMgr_PresentableObject)& thePrsObj)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Unhighlight (anIter.Value(), theMode);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      Unhighlight(anIter.Value());
+    }
   }
 
-  const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
-  if (!aPrs.IsNull())
+  const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
+  for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
   {
-    aPrs->Unhighlight();
+    const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
+    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
+    if (this == aPrsMgr
+    &&  aPrs->IsHighlighted())
+    {
+      aPrs->Unhighlight();
+    }
   }
 }
 
@@ -218,9 +207,12 @@ void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_Present
                                                      const Standard_Integer                  theMode,
                                                      const Standard_Integer                  theNewPrior) const
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    SetDisplayPriority (anIter.Value(), theMode, theNewPrior);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      SetDisplayPriority(anIter.Value(), theMode, theNewPrior);
+    }
   }
 
   const Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode);
@@ -237,12 +229,15 @@ void PrsMgr_PresentationManager::SetDisplayPriority (const Handle(PrsMgr_Present
 Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMgr_PresentableObject)& thePrsObj,
                                                               const Standard_Integer                  theMode) const
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Standard_Integer aPriority = DisplayPriority (anIter.Value(), theMode);
-    if (aPriority != 0)
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
     {
-      return aPriority;
+      Standard_Integer aPriority = DisplayPriority(anIter.Value(), theMode);
+      if (aPriority != 0)
+      {
+        return aPriority;
+      }
     }
   }
 
@@ -259,11 +254,14 @@ Standard_Integer PrsMgr_PresentationManager::DisplayPriority (const Handle(PrsMg
 Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_PresentableObject)& thePrsObj,
                                                           const Standard_Integer                  theMode) const
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    if (IsDisplayed (anIter.Value(), theMode))
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
     {
-      return Standard_True;
+      if (IsDisplayed(anIter.Value(), theMode))
+      {
+        return Standard_True;
+      }
     }
   }
 
@@ -279,11 +277,14 @@ Standard_Boolean PrsMgr_PresentationManager::IsDisplayed (const Handle(PrsMgr_Pr
 Standard_Boolean PrsMgr_PresentationManager::IsHighlighted (const Handle(PrsMgr_PresentableObject)& thePrsObj,
                                                             const Standard_Integer                  theMode) const
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    if (IsHighlighted (anIter.Value(), theMode))
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
     {
-      return Standard_True;
+      if (IsHighlighted(anIter.Value(), theMode))
+      {
+        return Standard_True;
+      }
     }
   }
 
@@ -354,9 +355,9 @@ void PrsMgr_PresentationManager::ClearImmediateDraw()
 // =======================================================================
 void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& theViewer)
 {
-  for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
+  for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
   {
-    const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
+    const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View();
     for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next())
     {
       const Handle(Prs3d_Presentation)& aPrs = anIter.Value();
@@ -367,13 +368,14 @@ void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& the
       Handle(Prs3d_PresentationShadow) aShadowPrs = Handle(Prs3d_PresentationShadow)::DownCast (aPrs);
       if (!aShadowPrs.IsNull() && aView->IsComputed (aShadowPrs->ParentId(), aViewDepPrs))
       {
+        const Graphic3d_ZLayerId aZLayer = aShadowPrs->GetZLayer();
         aShadowPrs.Nullify();
-        aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, 
-                                                   Handle(Prs3d_Presentation)::DownCast (aViewDepPrs));
-        aShadowPrs->SetZLayer (aViewDepPrs->CStructure()->ZLayer());
+
+        aShadowPrs = new Prs3d_PresentationShadow (myStructureManager, aViewDepPrs);
+        aShadowPrs->SetZLayer (aZLayer);
         aShadowPrs->SetClipPlanes (aViewDepPrs->ClipPlanes());
         aShadowPrs->CStructure()->IsForHighlight = 1;
-        aShadowPrs->Highlight (Aspect_TOHM_COLOR, aPrs->HighlightColor());
+        aShadowPrs->Highlight (aPrs->HighlightStyle());
         myViewDependentImmediateList.Append (aShadowPrs);
       }
       // handles custom highlight presentations which were defined in overridden
@@ -471,11 +473,11 @@ Standard_Boolean PrsMgr_PresentationManager::HasPresentation (const Handle(PrsMg
     return Standard_False;
 
   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
   {
-    const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
-    const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
-    if (theMode == aModedPrs.Mode()
+    const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
+    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
+    if (theMode == aPrs->Mode()
      && this    == aPrsMgr)
     {
       return Standard_True;
@@ -494,14 +496,14 @@ Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Hand
                                                                       const Handle(PrsMgr_PresentableObject)& theSelObj) const
 {
   const PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
   {
-    const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
-    const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
-    if (theMode == aModedPrs.Mode()
+    const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
+    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
+    if (theMode == aPrs->Mode()
      && this    == aPrsMgr)
     {
-      return aModedPrs.Presentation();
+      return aPrs;
     }
   }
 
@@ -510,10 +512,10 @@ Handle(PrsMgr_Presentation) PrsMgr_PresentationManager::Presentation (const Hand
     return Handle(PrsMgr_Presentation)();
   }
 
-  Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj);
+  Handle(PrsMgr_Presentation) aPrs = new PrsMgr_Presentation (this, thePrsObj, theMode);
   aPrs->SetZLayer (thePrsObj->ZLayer());
-  aPrs->Presentation()->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
-  thePrsObj->Presentations().Append (PrsMgr_ModedPresentation (aPrs, theMode));
+  aPrs->CStructure()->ViewAffinity = myStructureManager->ObjectAffinity (!theSelObj.IsNull() ? theSelObj : thePrsObj);
+  thePrsObj->Presentations().Append (aPrs);
   thePrsObj->Fill (this, aPrs, theMode);
 
   // set layer index accordingly to object's presentations
@@ -529,11 +531,11 @@ Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(Pr
                                                                  const Standard_Integer                  theMode)
 {
   PrsMgr_Presentations& aPrsList = thePrsObj->Presentations();
-  for (Standard_Integer aPrsIter = 1; aPrsIter <= aPrsList.Length(); ++aPrsIter)
+  for (PrsMgr_Presentations::Iterator aPrsIter (aPrsList); aPrsIter.More(); aPrsIter.Next())
   {
-    const PrsMgr_ModedPresentation&           aModedPrs = aPrsList.Value (aPrsIter);
-    const Handle(PrsMgr_PresentationManager)& aPrsMgr   = aModedPrs.Presentation()->PresentationManager();
-    if (theMode == aPrsList (aPrsIter).Mode()
+    const Handle(PrsMgr_Presentation)& aPrs = aPrsIter.Value();
+    const Handle(PrsMgr_PresentationManager)& aPrsMgr = aPrs->PresentationManager();
+    if (theMode == aPrs->Mode()
      && this    == aPrsMgr)
     {
       aPrsList.Remove (aPrsIter);
@@ -548,12 +550,16 @@ Standard_Boolean PrsMgr_PresentationManager::RemovePresentation (const Handle(Pr
 // purpose  :
 // =======================================================================
 void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                            const Standard_Integer                  theLayerId)
+                                            const Graphic3d_ZLayerId                theLayerId)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    SetZLayer (anIter.Value(), theLayerId);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      SetZLayer(anIter.Value(), theLayerId);
+    }
   }
+
   if (!thePrsObj->HasOwnPresentations())
   {
     return;
@@ -566,7 +572,7 @@ void PrsMgr_PresentationManager::SetZLayer (const Handle(PrsMgr_PresentableObjec
 // function : GetZLayer
 // purpose  :
 // =======================================================================
-Standard_Integer PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
+Graphic3d_ZLayerId PrsMgr_PresentationManager::GetZLayer (const Handle(PrsMgr_PresentableObject)& thePrsObj) const
 {
   return thePrsObj->ZLayer();
 }
@@ -582,7 +588,7 @@ void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)
 {
   Handle(PrsMgr_Presentation) aPrs      = Presentation (thePrsObject,   theMode,      Standard_True);
   Handle(PrsMgr_Presentation) aPrsOther = Presentation (theOtherObject, theOtherMode, Standard_True);
-  aPrs->Connect (aPrsOther);
+  aPrs->Connect (aPrsOther.get(), Graphic3d_TOC_DESCENDANT);
 }
 
 // =======================================================================
@@ -590,26 +596,28 @@ void PrsMgr_PresentationManager::Connect (const Handle(PrsMgr_PresentableObject)
 // purpose  :
 // =======================================================================
 void PrsMgr_PresentationManager::Transform (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                            const Handle(Geom_Transformation)&      theTransformation,
-                                            const Standard_Integer                  theMode)
+                                            const Handle(TopLoc_Datum3D)& theTransformation,
+                                            const Standard_Integer theMode)
 {
   Presentation (thePrsObj, theMode)->SetTransformation (theTransformation);
 }
 
-
 // =======================================================================
 // function : Color
 // purpose  :
 // =======================================================================
 void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                        const Quantity_NameOfColor              theColor,
+                                        const Handle(Prs3d_Drawer)& theStyle,
                                         const Standard_Integer                  theMode,
                                         const Handle(PrsMgr_PresentableObject)& theSelObj,
                                         const Standard_Integer theImmediateStructLayerId)
 {
-  for (PrsMgr_ListOfPresentableObjectsIter anIter (thePrsObj->Children()); anIter.More(); anIter.Next())
+  if (thePrsObj->ToPropagateVisualState())
   {
-    Color (anIter.Value(), theColor, theMode, NULL, theImmediateStructLayerId);
+    for (PrsMgr_ListOfPresentableObjectsIter anIter(thePrsObj->Children()); anIter.More(); anIter.Next())
+    {
+      Color(anIter.Value(), theStyle, theMode, NULL, theImmediateStructLayerId);
+    }
   }
   if (!thePrsObj->HasOwnPresentations())
   {
@@ -624,45 +632,27 @@ void PrsMgr_PresentationManager::Color (const Handle(PrsMgr_PresentableObject)&
 
   if (myImmediateModeOn > 0)
   {
-    Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs->Presentation());
+    Handle(Prs3d_PresentationShadow) aShadow = new Prs3d_PresentationShadow (myStructureManager, aPrs);
     aShadow->SetZLayer (theImmediateStructLayerId);
-    aShadow->SetClipPlanes (aPrs->Presentation()->ClipPlanes());
+    aShadow->SetClipPlanes (aPrs->ClipPlanes());
     aShadow->CStructure()->IsForHighlight = 1;
-    aShadow->Highlight (Aspect_TOHM_COLOR, theColor);
+    aShadow->Highlight (theStyle);
     AddToImmediateList (aShadow);
   }
   else
   {
-    aPrs->Highlight (Aspect_TOHM_COLOR, theColor);
+    aPrs->Highlight (theStyle);
   }
 }
 
-// =======================================================================
-// function : BoundBox
-// purpose  :
-// =======================================================================
-void PrsMgr_PresentationManager::BoundBox (const Handle(PrsMgr_PresentableObject)& thePrsObj,
-                                           const Standard_Integer                  theMode)
-{
-  Handle(PrsMgr_Presentation) aPrs = Presentation (thePrsObj, theMode, Standard_True);
-  if (aPrs->MustBeUpdated())
-  {
-    Update (thePrsObj, theMode);
-  }
-  aPrs->Highlight (Aspect_TOHM_BOUNDBOX, mySelectionColor);
-}
-
 namespace
 {
-  // =======================================================================
-  // function : updatePrsTransformation
-  // purpose  : Internal function that scans thePrsList for shadow presentations
-  //            and applies transformation theTrsf to them in case if parent ID
-  //            of shadow presentation is equal to theRefId
-  // =======================================================================
-  void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
-                                const Standard_Integer theRefId,
-                                const Handle(Geom_Transformation)& theTrsf)
+  //! Internal function that scans thePrsList for shadow presentations
+  //! and applies transformation theTrsf to them in case if parent ID
+  //! of shadow presentation is equal to theRefId
+  static void updatePrsTransformation (const PrsMgr_ListOfPresentations& thePrsList,
+                                       const Standard_Integer theRefId,
+                                       const Handle(TopLoc_Datum3D)& theTrsf)
   {
     for (PrsMgr_ListOfPresentations::Iterator anIter (thePrsList); anIter.More(); anIter.Next())
     {
@@ -691,24 +681,27 @@ void PrsMgr_PresentationManager::UpdateHighlightTrsf (const Handle(V3d_Viewer)&
   if (theObj.IsNull())
     return;
 
-  const Handle(Prs3d_Presentation)& aBasePrs = Presentation (theObj, theMode, Standard_False)->Presentation();
-  const Handle(Prs3d_Presentation)& aParentPrs = theSelObj.IsNull() ?
-    aBasePrs : Presentation (theSelObj, theMode, Standard_False)->Presentation();
-  const Standard_Integer aParentId = aParentPrs->CStructure()->Id;
+  Handle(PrsMgr_Presentation) aPrs = Presentation (!theSelObj.IsNull() ? theSelObj : theObj, theMode, Standard_False);
+  if (aPrs.IsNull())
+  {
+    return;
+  }
 
-  updatePrsTransformation (myImmediateList, aParentId, aBasePrs->CStructure()->Transformation());
+  Handle(TopLoc_Datum3D) aTrsf = theObj->LocalTransformationGeom();
+  const Standard_Integer aParentId = aPrs->CStructure()->Id;
+  updatePrsTransformation (myImmediateList, aParentId, aTrsf);
 
   if (!myViewDependentImmediateList.IsEmpty())
   {
-    for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews())
+    for (V3d_ListOfViewIterator anActiveViewIter (theViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
     {
-      const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View();
+      const Handle(Graphic3d_CView)& aView = anActiveViewIter.Value()->View();
       Handle(Graphic3d_Structure) aViewDepParentPrs;
       if (aView->IsComputed (aParentId, aViewDepParentPrs))
       {
         updatePrsTransformation (myViewDependentImmediateList,
                                  aViewDepParentPrs->CStructure()->Id,
-                                 aBasePrs->CStructure()->Transformation());
+                                 aTrsf);
       }
     }
   }