0024276: Memory leak due to a static variable
[occt.git] / src / AIS / AIS_InteractiveContext.cxx
index 53c278b..bc7c438 100755 (executable)
@@ -1,19 +1,28 @@
-// File:        AIS_InteractiveContext.cxx
-// Created:     Fri Jan 17 13:36:48 1997
-// Author:      Robert COUBLANC
+// Created on: 1997-01-17
+// Created by: Robert COUBLANC
+// Copyright (c) 1997-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
 // Modified by  XAB & Serguei Dec 97 (angle &deviation coeffts)
-//              <rob@robox.paris1.matra-dtv.fr>
 
 #define BUC60577        //GG_101099     Enable to compute correctly
 //                      transparency with more than one object in the view.
 
-#define GER61351        //GG_171199     Enable to set an object RGB color
-//                              instead a restricted object NameOfColor. 
-
-#define G003            //EUG_26/01/00 Degenerate support (G003)
-
-#define IMP140200       //GG Add SetSelectedAspect() method.
-
 #define BUC60632        //GG 15/03/00 Add protection on SetDisplayMode()
 //                      method, compute only authorized presentation.
 
 #define OCC172          //SAV clear static map before destroying context.
 
 #define OCC204          //SAV 26/02/02 : pass <updateviewer> flag to 
-                        // AddOrRemoveCurrentObject method from ClearGlobal.
+// AddOrRemoveCurrentObject method from ClearGlobal.
 
 #define OCC4373         //SAN 10/11/03 : improve display mode management in
-                        // Display( IO, updateviewer ) and 
-                        // SetDisplayMode( IO, mode, updateviewer ) methods
+// Display( IO, updateviewer ) and 
+// SetDisplayMode( IO, mode, updateviewer ) methods
 
 #include <AIS_InteractiveContext.ixx>
 
@@ -57,6 +66,7 @@
 #include <Prs3d_DatumAspect.hxx>
 #include <Prs3d_PlaneAspect.hxx>
 #include <PrsMgr_PresentableObject.hxx>
+#include <Standard_Atomic.hxx>
 #include <UnitsAPI.hxx>
 
 #include <AIS_Trihedron.hxx>
@@ -69,7 +79,7 @@
 // is always equal to 0 if it is -1.
 #define BUC61051
 
-// On close the local context the method ::ResetOriginalState() sets the selection mode equal to 0
+// The local context is closed the method ::ResetOriginalState() sets the selection mode equal to 0
 // in spite of the selection mode of the interactive object in Natural Point.
 #define OCC166
 
@@ -91,28 +101,23 @@ static Standard_Boolean AISDebugModeOn()
   return (isDebugMode != 0);
 }
 
-static TCollection_AsciiString AIS_Context_NewSelName()
+namespace
 {
-  static Standard_Integer index_sel = 1;
-  TCollection_AsciiString name("AIS_SelContext_");
-  TCollection_AsciiString theind(index_sel);
-  name += theind;
-  index_sel++;
-  return name;
-}
+  static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
+  static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
 
-static TCollection_AsciiString AIS_Context_NewCurName()
-{
-  static Standard_Integer index_cur = 1;
-  TCollection_AsciiString name("AIS_CurContext_");
-  TCollection_AsciiString theind(index_cur);
-  name += theind;
-  index_cur++;
-  return name;
-}
-
-static TColStd_ListIteratorOfListOfInteger ItL;
+  static TCollection_AsciiString AIS_Context_NewSelName()
+  {
+    return TCollection_AsciiString ("AIS_SelContext_")
+         + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
+  }
 
+  static TCollection_AsciiString AIS_Context_NewCurName()
+  {
+    return TCollection_AsciiString ("AIS_CurContext_")
+         + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
+  }
+};
 
 //=======================================================================
 //function : AIS_InteractiveContext
@@ -124,7 +129,6 @@ mgrSelector(new SelectMgr_SelectionManager()),
 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
 myMainVwr(MainViewer),
 myMainSel(new StdSelect_ViewerSelector3d()),
-myIsCollClosed(Standard_True),
 myToHilightSelected( Standard_False ),
 myFilters(new SelectMgr_OrFilter()),
 myDefaultDrawer(new Prs3d_Drawer()),
@@ -143,49 +147,11 @@ myIsAutoActivateSelMode( Standard_True )
   InitAttributes();
 }
 
-
-//=======================================================================
-//function : AIS_InteractiveContext
-//purpose  : 
-//=======================================================================
-
-AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer,
-                                             const Handle(V3d_Viewer)& Collector):
-mgrSelector(new SelectMgr_SelectionManager()),
-myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
-myMainVwr(MainViewer),
-myMainSel(new StdSelect_ViewerSelector3d()),
-myCollectorPM(new PrsMgr_PresentationManager3d(Collector->Viewer())),
-myCollectorVwr(Collector),
-myCollectorSel(new StdSelect_ViewerSelector3d()),
-myIsCollClosed(Standard_False),
-myToHilightSelected( Standard_False ),
-myFilters(new SelectMgr_OrFilter()),
-myDefaultDrawer(new Prs3d_Drawer()),
-myDefaultColor(Quantity_NOC_GOLDENROD),
-myHilightColor(Quantity_NOC_CYAN1),
-mySelectionColor(Quantity_NOC_GRAY80),
-myPreselectionColor(Quantity_NOC_GREEN),
-mySubIntensity(Quantity_NOC_GRAY40),
-myDisplayMode(0),
-myCurLocalIndex(0),
-#ifdef IMP051001
-myZDetectionFlag(0),
-#endif
-myIsAutoActivateSelMode( Standard_True )
-{
-  InitAttributes();
-  mgrSelector->Add(myCollectorSel);
-#ifdef BUC60688
-  SetSensitivity();
-#else
-  myCollectorSel->Set(4);
-#endif
-
-}
-
 void AIS_InteractiveContext::Delete() const
 {
+  //Clear the static current selection. Else the memory
+  //is not release
+  AIS_Selection::ClearCurrentSelection();
 #ifdef OCC172
   // to avoid an exception
   if ( AIS_Selection::Find( mySelectionName.ToCString() ) )
@@ -199,6 +165,16 @@ void AIS_InteractiveContext::Delete() const
   // be performed when mgrSelector will be destroyed but anyway...
   mgrSelector->Remove( myMainSel );
 #endif
+  AIS_ListOfInteractive aList;
+  
+  AIS_DataMapIteratorOfDataMapOfIOStatus anIt(myObjects);
+  Handle(AIS_InteractiveContext) aNullContext;
+  for(; anIt.More() ; anIt.Next())
+  {
+    Handle(AIS_InteractiveObject) anObj = anIt.Key();
+    anObj->SetContext(aNullContext);
+    
+  }
   MMgt_TShared::Delete();
 }
 
@@ -227,13 +203,6 @@ void AIS_InteractiveContext::UpdateCurrentViewer()
     myMainVwr->Update();
 }
 
-void AIS_InteractiveContext::OpenCollector()
-{
-  myIsCollClosed =Standard_True;
-  // a completer....
-}
-
-
 
 //=======================================================================
 //function : DomainOfMainViewer
@@ -267,7 +236,7 @@ void AIS_InteractiveContext::DisplayedObjects(AIS_ListOfInteractive& aListOfIO,
   }
   else{
     TColStd_MapOfTransient theMap;
-    // point neutre
+    // neutral point
     for(;It.More();It.Next()){
       if(It.Value()->GraphicStatus()==AIS_DS_Displayed)
         theMap.Add(It.Key());
@@ -276,7 +245,7 @@ void AIS_InteractiveContext::DisplayedObjects(AIS_ListOfInteractive& aListOfIO,
     cout<<"\tFrom Neutral Point : "<<theMap.Extent()<<endl;
 #endif
 
-    //balayons tous les contextes locaux...
+    //parse all local contexts...
     Standard_Integer NbDisp;
     for(AIS_DataMapIteratorOfDataMapOfILC it1(myLocalContexts);it1.More();it1.Next()){
       const Handle(AIS_LocalContext)& LC = it1.Value();
@@ -308,50 +277,6 @@ void AIS_InteractiveContext::DisplayedObjects(const AIS_KindOfInteractive TheKin
   ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_Displayed, aListOfIO );
 }
 
-//=======================================================================
-//function : UpdateCollector
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::UpdateCollector()
-{
-  if (!myCollectorVwr.IsNull())
-    myCollectorVwr->Update();
-}
-
-//=======================================================================
-//function : DomainOfCollector
-//purpose  : 
-//=======================================================================
-
-Standard_CString AIS_InteractiveContext::DomainOfCollector() const 
-{
-  if(myCollectorVwr.IsNull()) return "";
-  return  myCollectorVwr->Domain();
-}
-
-//=======================================================================
-//function : ObjectsInCollector
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::ObjectsInCollector(AIS_ListOfInteractive& aListOfIO) const 
-{
-  ObjectsByDisplayStatus( AIS_DS_Erased, aListOfIO );
-}
-
-//=======================================================================
-//function : ObjectsInCollector
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::ObjectsInCollector(const AIS_KindOfInteractive TheKind,
-                                                const Standard_Integer TheSign,
-                                                AIS_ListOfInteractive& aListOfIO) const 
-{
-  ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_Erased, aListOfIO );
-}
-
 //=======================================================================
 //function : ErasedObjects
 //purpose  : 
@@ -359,7 +284,7 @@ void AIS_InteractiveContext::ObjectsInCollector(const AIS_KindOfInteractive TheK
 
 void AIS_InteractiveContext::ErasedObjects(AIS_ListOfInteractive& theListOfIO) const 
 {
-  ObjectsByDisplayStatus( AIS_DS_FullErased, theListOfIO );
+  ObjectsByDisplayStatus( AIS_DS_Erased, theListOfIO );
 }
 
 //=======================================================================
@@ -371,7 +296,7 @@ void AIS_InteractiveContext::ErasedObjects(const AIS_KindOfInteractive TheKind,
                                            const Standard_Integer TheSign,
                                            AIS_ListOfInteractive& theListOfIO) const 
 {
-  ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_FullErased, theListOfIO );
+  ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_Erased, theListOfIO );
 }
 
 //=======================================================================
@@ -461,15 +386,14 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj
   if(!anIObj->HasInteractiveContext()) 
     anIObj->SetContext(aThis);
   
-  //PAS DE CONTEXTE LOCAL OUVERT
+  //NO LOCAL CONTEXT OPEN
   if(!HasOpenedContext()) {
 #ifndef OCC4373
     // SAN : Do not return here. Perform advanced display mode analysis a bit later...
     if(IsDisplayed(anIObj)) return;
 #endif
-    Standard_Boolean updcol = Standard_False;
-    
-    // il n'existait pas encore
+
+    // it did not yet exist
     if(!myObjects.IsBound(anIObj)){
       
       Handle(AIS_GlobalStatus) STATUS= 
@@ -489,41 +413,20 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj
         
      if(updateviewer) myMainVwr->Update();
     }
-    // il est quelque part ailleurs....
+    // it is somewhere else...
     else {
       // CLE
       // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
       Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
       // ENDCLE
-      switch (STATUS->GraphicStatus()){
-      case AIS_DS_Erased:{
-        if(STATUS->IsHilighted())
-          myCollectorPM->Unhighlight(anIObj,HiMod);
-        myCollectorPM->Erase(anIObj,HiMod);
-        mgrSelector->Deactivate(anIObj,myCollectorSel);
-        updcol = updateviewer;
-                         }// attention on fait expres de ne pas mettre de break..
-      case AIS_DS_FullErased:{
-        for (ItL.Initialize(STATUS->DisplayedModes());ItL.More();ItL.Next()){
-          myMainPM->Display(anIObj,ItL.Value());
-          if(STATUS->IsSubIntensityOn())
-            myMainPM->Color(anIObj,mySubIntensity,ItL.Value());
-        }
-        if( myIsAutoActivateSelMode )        
-            for (ItL.Initialize(STATUS->SelectionModes());ItL.More();ItL.Next())
-                mgrSelector->Activate(anIObj,ItL.Value(),myMainSel);
-        STATUS->SetGraphicStatus(AIS_DS_Displayed);
-        if(STATUS->IsHilighted())
-          myMainPM->Highlight(anIObj,HiMod);
-        break;
-                             }
-#ifdef OCC4373
-      // SAN : erase presentations for all display modes different from <DispMode>;
-      //       then make sure <DispMode> is displayed and maybe highlighted;
-      //       Finally, activate selection mode <SelMode> if not yet activated.
-      case AIS_DS_Displayed:{
+      if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
+      {
+        // SAN : erase presentations for all display modes different from <DispMode>;
+        //       then make sure <DispMode> is displayed and maybe highlighted;
+        //       Finally, activate selection mode <SelMode> if not yet activated.
         TColStd_ListOfInteger aModesToRemove;
-        for(ItL.Initialize(STATUS->DisplayedModes());ItL.More();ItL.Next()){
+        TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
+        for(;ItL.More();ItL.Next()){
 
           Standard_Integer OldMode = ItL.Value();
 
@@ -542,6 +445,10 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj
           STATUS->AddDisplayMode(DispMode);
 
         myMainPM->Display(anIObj,DispMode);
+        if (STATUS->GraphicStatus() == AIS_DS_Erased)
+        {
+          STATUS->SetGraphicStatus(AIS_DS_Displayed);
+        }
         if(STATUS->IsHilighted()){
           myMainPM->Highlight(anIObj,HiMod);
         }
@@ -552,22 +459,15 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj
            if(!mgrSelector->IsActivated(anIObj,SelMode))
               mgrSelector->Activate(anIObj,SelMode,myMainSel);
         }
-
-        break;
-                            }
-#endif
-      default:
-        break;
       }
     } 
     
     if(anIObj->IsTransparent() && !myMainVwr->Viewer()->Transparency())
       myMainVwr->Viewer()->SetTransparency(Standard_True);
     if(updateviewer) myMainVwr->Update();
-    if(updcol && !myCollectorVwr.IsNull()) myCollectorVwr->Update();
   }
   
-  //  CONTEXTE LOCAL OUVERT
+  //  LOCAL CONTEXT OPEN
   else
   {
     myLocalContexts(myCurLocalIndex)->Display(anIObj,DispMode,anIObj->AcceptShapeDecomposition(),SelMode);
@@ -595,7 +495,7 @@ void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj
 
   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
   
-  // si aucun contexte local...
+  // if no local context...
   if(!HasOpenedContext()) {
     //    if(!anIObj->HasDisplayMode())
     //      anIObj->SetDisplayMode(aDisplayMode);
@@ -659,7 +559,7 @@ void AIS_InteractiveContext::Load(const Handle(AIS_InteractiveObject)& anIObj,
       
       GetDefModes(anIObj,DispMode,HiMod,SelModeDef);
       Handle(AIS_GlobalStatus) STATUS= 
-        new AIS_GlobalStatus(AIS_DS_FullErased,DispMode,SelModeDef);
+        new AIS_GlobalStatus(AIS_DS_Erased,DispMode,SelModeDef);
       myObjects.Bind (anIObj,STATUS);      
       return;
     }
@@ -674,8 +574,7 @@ void AIS_InteractiveContext::Load(const Handle(AIS_InteractiveObject)& anIObj,
 //=======================================================================
 
 void AIS_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anIObj, 
-                                   const Standard_Boolean updateviewer, 
-                                   const Standard_Boolean PutInCollector)
+                                   const Standard_Boolean updateviewer)
 {
   if(anIObj.IsNull()) return;
   
@@ -683,13 +582,12 @@ void AIS_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anIObj,
     anIObj->ClearSelected();
   
   if(!HasOpenedContext()){
-    EraseGlobal(anIObj,updateviewer,PutInCollector);
+    EraseGlobal(anIObj,updateviewer);
   }
   else
     {
-      // d'abors on regarde si on peut effacer dans le contexte local courant
-      // ensuite, on essaye d'effacer dans les autres contextes locaux,
-      // s'ils le permettent...
+      // First it is checked if it is possible to remove in the current local context
+      // then one tries to remove in other local contexts, if they allow it...
       
       Standard_Boolean WasInCtx = myLocalContexts(myCurLocalIndex)->Erase(anIObj);
 //      if(!WasInCtx) {
@@ -704,62 +602,31 @@ void AIS_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anIObj,
       }
       
       if(!WasInCtx)
-        EraseGlobal(anIObj,updateviewer,PutInCollector);
+        EraseGlobal(anIObj,updateviewer);
       else
         if(updateviewer) myMainVwr->Update();
     }
 }
-//=======================================================================
-//function : Erase
-//purpose  : 
-//=======================================================================
-
-void AIS_InteractiveContext::EraseMode(const Handle(AIS_InteractiveObject)& anIObj,
-                                  const Standard_Integer aMode,
-                                  const Standard_Boolean /*updateviewer*/)
-{
-  if(anIObj.IsNull()) return;
-
-  if(!myObjects.IsBound(anIObj)) return;
-  
-  if(anIObj->HasDisplayMode()){
-    if(anIObj->DisplayMode()==aMode) return;
-  }
-  else if(myDisplayMode==aMode) return;
-  // CLE
-  // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
-  Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
-  // ENDCLE
-  if(STATUS->GraphicStatus()!=AIS_DS_Displayed) return;
-  
-  
-//  if(STATUS->IsDModeIn(aMode)) {}
-}
-
-
 
 //=======================================================================
 //function : EraseAll
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::EraseAll(const Standard_Boolean PutInCollector,
-                                      const Standard_Boolean updateviewer)
+void AIS_InteractiveContext::EraseAll(const Standard_Boolean updateviewer)
 {
-  if(!HasOpenedContext()){
-    AIS_DataMapIteratorOfDataMapOfIOStatus ItM(myObjects);
-    
-    for(;ItM.More();ItM.Next()){
+  if(!HasOpenedContext())
+  {
+    for (AIS_DataMapIteratorOfDataMapOfIOStatus ItM(myObjects); ItM.More(); ItM.Next())
+    {
       if(ItM.Value()->GraphicStatus() == AIS_DS_Displayed)
-        Erase(ItM.Key(),Standard_False,PutInCollector);
+        Erase(ItM.Key(),Standard_False);
     }
-    if(updateviewer){
+    if(updateviewer)
+    {
       myMainVwr->Update();
-      if (PutInCollector && !myCollectorVwr.IsNull()) 
-        myCollectorVwr->Update();
     }
   }
-  
 }
 
 //=======================================================================
@@ -767,27 +634,23 @@ void AIS_InteractiveContext::EraseAll(const Standard_Boolean PutInCollector,
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::DisplayAll(const Standard_Boolean OnlyFromCollector,
-                                      const Standard_Boolean updateviewer)
+void AIS_InteractiveContext::DisplayAll(const Standard_Boolean updateviewer)
 {
   if(!HasOpenedContext()){
-    Standard_Boolean FoundInCollector(Standard_False);
-    AIS_DisplayStatus aDStatus = OnlyFromCollector ? AIS_DS_Erased : AIS_DS_FullErased,TheStatus;
 
-    if(!HasOpenedContext()){
-      AIS_DataMapIteratorOfDataMapOfIOStatus ItM(myObjects);
-      
-      for(;ItM.More();ItM.Next()){
-        TheStatus = ItM.Value()->GraphicStatus();
-        if(TheStatus == aDStatus)
+    AIS_DisplayStatus aStatus;
+
+    if (!HasOpenedContext())
+    {
+      for (AIS_DataMapIteratorOfDataMapOfIOStatus ItM (myObjects); ItM.More(); ItM.Next())
+      {
+        aStatus = ItM.Value()->GraphicStatus();
+        if (aStatus == AIS_DS_Erased)
           Display(ItM.Key(),Standard_False);
-        if(TheStatus == AIS_DS_Erased)
-          FoundInCollector = Standard_True;
       }
-      if(updateviewer){
+      if(updateviewer)
+      {
         myMainVwr->Update();
-        if(FoundInCollector && !myCollectorVwr.IsNull())
-          myCollectorVwr->Update();
       }
     }
   }
@@ -802,20 +665,20 @@ void AIS_InteractiveContext::DisplayAll(const Standard_Boolean OnlyFromCollector
 void AIS_InteractiveContext::DisplaySelected(const Standard_Boolean updateviewer)
 {
   
-  if(!HasOpenedContext()){
+  if (!HasOpenedContext())
+  {
     Standard_Boolean found = Standard_False;
     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
     Handle(AIS_InteractiveObject) iObj;
-    for (sel->Init();sel->More();sel->Next()) {
+    for (sel->Init(); sel->More(); sel->Next())
+    {
       iObj = Handle(AIS_InteractiveObject)::DownCast(sel->Value());
       Display(iObj,Standard_False);
       found = Standard_True;
     }
-    if(found && updateviewer) {
+    if (found && updateviewer)
+    {
       myMainVwr->Update();
-      if(!(myIsCollClosed && myCollectorVwr.IsNull())) 
-       
-        myCollectorVwr->Update();
     }
   }
 }
@@ -826,23 +689,22 @@ void AIS_InteractiveContext::DisplaySelected(const Standard_Boolean updateviewer
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::EraseSelected(const Standard_Boolean PutInCollector,
-                                           const Standard_Boolean updateviewer)
+void AIS_InteractiveContext::EraseSelected(const Standard_Boolean updateviewer)
 {
-  
-  if(!HasOpenedContext()){
+  if (!HasOpenedContext())
+  {
     Standard_Boolean found = Standard_False;
     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
     Handle(AIS_InteractiveObject) iObj;
-    for(sel->Init();sel->More();sel->Next()) {
+    for (sel->Init();sel->More();sel->Next())
+    {
       iObj = Handle(AIS_InteractiveObject)::DownCast(sel->Value());
-      Erase(iObj,Standard_False,PutInCollector);
+      Erase(iObj,Standard_False);
       found = Standard_True;
     }
-    if(found && updateviewer) {
+    if(found && updateviewer)
+    {
       myMainVwr->Update();
-      if(PutInCollector && !myCollectorVwr.IsNull())
-        myCollectorVwr->Update();
     }
   }
 }
@@ -1068,42 +930,28 @@ void AIS_InteractiveContext::Hilight(const Handle(AIS_InteractiveObject)& anIObj
 
   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
   if (!HasOpenedContext())
-    {
-      if(!myObjects.IsBound(anIObj)) return;
+  {
+    if(!myObjects.IsBound(anIObj)) return;
 
-      // CLE
-      // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
-      // const TColStd_ListOfInteger& LL = STATUS->DisplayedModes();
-      Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
+    // CLE
+    // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
+    // const TColStd_ListOfInteger& LL = STATUS->DisplayedModes();
+    Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
 
-      // ENDCLE
-      STATUS->SetHilightStatus (Standard_True);
-      
-      switch(STATUS->GraphicStatus()){
-      case AIS_DS_Displayed:
-        {
-          Standard_Integer DispMode,HiMode,SelMode;
-          GetDefModes(anIObj,DispMode,HiMode,SelMode);
-//        if(!STATUS->IsDModeIn(HiMode)){
-//          myMainPM->Display(anIObj,HiMode);
-//        }
-          myMainPM->Highlight(anIObj,HiMode);
-          if(updateviewer) myMainVwr->Update();
-          break;
-        }
-      case AIS_DS_Erased:
-        {
-          Standard_Integer HiMode = anIObj->HasHilightMode()? anIObj->HilightMode():0;
-          myCollectorPM->Highlight(anIObj,HiMode);
-          if(updateviewer) myCollectorVwr->Update();
-          break;
-        }
-      default:
-        break;
-      }
+    // ENDCLE
+    STATUS->SetHilightStatus (Standard_True);
+
+    if (STATUS->GraphicStatus() == AIS_DS_Displayed)
+    {
+      Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
+      myMainPM->Highlight (anIObj, aHilightMode);
     }
+  }
   else
+  {
     myLocalContexts(myCurLocalIndex)->Hilight(anIObj);
+  }
+
   if(updateviewer) myMainVwr->Update();
 }
 //=======================================================================
@@ -1120,38 +968,23 @@ void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject
   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
 
   if (!HasOpenedContext())
-    {
-      if(!myObjects.IsBound(anIObj)) return;
+  {
+    if(!myObjects.IsBound(anIObj)) return;
 
-      const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
-      STATUS->SetHilightStatus (Standard_True);
-      
-      switch(STATUS->GraphicStatus()){
-      case AIS_DS_Displayed:
-        {
-          Standard_Integer DispMode,HiMode,SelMode;
-          GetDefModes(anIObj,DispMode,HiMode,SelMode);
-//        if(!STATUS->IsDModeIn(HiMode)){
-//          myMainPM->Display(anIObj,HiMode);
-//        }
-          myMainPM->Color(anIObj,aCol,HiMode);
-          STATUS->SetHilightColor(aCol);
-          if(updateviewer) myMainVwr->Update();
-          break;
-        }
-      case AIS_DS_Erased:
-        {
-          Standard_Integer HiMode = anIObj->HasHilightMode()? anIObj->HilightMode():0;
-          myCollectorPM->Color(anIObj,aCol,HiMode);
-          if(updateviewer) myCollectorVwr->Update();
-          break;
-        }
-      default:
-        break;  
-      }
+    const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
+    STATUS->SetHilightStatus (Standard_True);
+
+    if (STATUS->GraphicStatus() == AIS_DS_Displayed)
+    {
+      Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
+      myMainPM->Color (anIObj, aCol, aHilightMode);
+      STATUS->SetHilightColor (aCol);
     }
+  }
   else
+  {
     myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
+  }
   if(updateviewer) myMainVwr->Update();
 }
 
@@ -1165,37 +998,23 @@ void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIO
   if(anIObj.IsNull()) return;
 
   if (!HasOpenedContext())
-    {
-      if(!myObjects.IsBound(anIObj)) return;
+  {
+    if(!myObjects.IsBound(anIObj)) return;
 
-      const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
-      STATUS->SetHilightStatus (Standard_False);
-      STATUS->SetHilightColor(Quantity_NOC_WHITE);
-      
-      switch(STATUS->GraphicStatus()){
-      case AIS_DS_Displayed:
-        {
-          Standard_Integer DispMode,HiMode,SelMode;
-          GetDefModes(anIObj,DispMode,HiMode,SelMode);
-          myMainPM->Unhighlight(anIObj,HiMode);
-//        if(!STATUS->IsDModeIn(HiMode))
-//          myMainPM->Erase(anIObj,HiMode);
-          if(updateviewer) myMainVwr->Update();
-          break;
-        }
-      case AIS_DS_Erased:
-        {
-          Standard_Integer HiMode = anIObj->HasHilightMode()? anIObj->HilightMode():0;
-          myCollectorPM->Unhighlight(anIObj,HiMode);
-          if(updateviewer) myCollectorVwr->Update();
-          break;
-        }
-      default:
-        break;  
-      }
+    const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
+    STATUS->SetHilightStatus (Standard_False);
+    STATUS->SetHilightColor(Quantity_NOC_WHITE);
+
+    if (STATUS->GraphicStatus() == AIS_DS_Displayed)
+    {
+      Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
+      myMainPM->Unhighlight (anIObj, aHilightMode);
     }
+  }
   else
+  {
     myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
+  }
   if(updateviewer) myMainVwr->Update();
 }
 
@@ -1275,21 +1094,6 @@ Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_Interactiv
   return Standard_False;
   
 }
-//=======================================================================
-//function : IsDisplayed
-//purpose  : 
-//=======================================================================
-
-Standard_Boolean AIS_InteractiveContext::IsInCollector(const Handle(AIS_InteractiveObject)& anIObj) const 
-{
-  if(anIObj.IsNull()) return Standard_False;
-
-
-  if(myObjects.IsBound(anIObj)) 
-    return (myObjects(anIObj)->GraphicStatus()==AIS_DS_Erased);
-  return Standard_False;
-}
-
 
 //=======================================================================
 //function : IsDisplayed
@@ -1325,25 +1129,16 @@ Standard_Integer AIS_InteractiveContext::
 DisplayPriority(const Handle(AIS_InteractiveObject)& anIObj) const 
 {
   if(anIObj.IsNull()) return -1;
-  if(myObjects.IsBound(anIObj)){
-    // CLE
-    // const Handle(AIS_GlobalStatus) & STATUS = myObjects(anIObj);
+
+  if (myObjects.IsBound(anIObj))
+  {
     Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
-    // ENDCLE
-    Standard_Integer DM,HM,SM ;
-    GetDefModes(anIObj,DM,HM,SM);
-    switch(STATUS->GraphicStatus()){
-    case AIS_DS_Displayed:
-      {
-        return myMainPM->DisplayPriority(anIObj,DM);
-        break;
-      }
-    case AIS_DS_Erased:
-      return myCollectorPM->DisplayPriority(anIObj,HM);
-    default:
-      break;
+    if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
+    {
+      Standard_Integer aDispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : 
+                                   (anIObj->AcceptDisplayMode(myDisplayMode)? myDisplayMode : 0);
+      return myMainPM->DisplayPriority (anIObj, aDispMode);
     }
-    return 0;
   }
   return 0;
 }
@@ -1359,30 +1154,21 @@ void AIS_InteractiveContext::SetDisplayPriority(const Handle(AIS_InteractiveObje
     return;
   if(!anIObj->HasInteractiveContext())
     anIObj->SetContext(this);
-  if(myObjects.IsBound(anIObj)){
-    // CLE
-    // const Handle(AIS_GlobalStatus) & STATUS = myObjects(anIObj);
+  if(myObjects.IsBound(anIObj))
+  {
     Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
-    // ENDCLE
-    Standard_Integer DM,HM,SM ;
-    GetDefModes(anIObj,DM,HM,SM);
-    switch(STATUS->GraphicStatus()){
-    case AIS_DS_Displayed:
-      {
-        myMainPM->SetDisplayPriority(anIObj,DM,aPriority);
-        break;
-      }
-    case AIS_DS_Erased:
-      {
-        myCollectorPM->SetDisplayPriority(anIObj,HM,aPriority);
-        break;
-      }
-    default:
-      break;
+
+    if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
+    {
+      Standard_Integer aDisplayMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : 
+                                      (anIObj->AcceptDisplayMode(myDisplayMode)? myDisplayMode : 0);
+      myMainPM->SetDisplayPriority (anIObj, aDisplayMode, aPriority);
     }
   }
   else if (HasOpenedContext())
-    {myLocalContexts(myCurLocalIndex)->SetDisplayPriority(anIObj,aPriority);}
+  {
+    myLocalContexts(myCurLocalIndex)->SetDisplayPriority(anIObj,aPriority);
+  }
 }
 
 //=======================================================================
@@ -1412,7 +1198,7 @@ void AIS_InteractiveContext::Redisplay(const AIS_KindOfInteractive KOI,
                                        const Standard_Integer /*Sign*/,
                                       const Standard_Boolean updateviewer)
 {
-  Standard_Boolean found_viewer(Standard_False),found_coll(Standard_False);
+  Standard_Boolean found_viewer(Standard_False);
   // update
   for(AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);It.More();It.Next()){
     // CLE
@@ -1425,24 +1211,16 @@ void AIS_InteractiveContext::Redisplay(const AIS_KindOfInteractive KOI,
 //        ((IO->Signature()==Sign)? Standard_True:Standard_False);
 #endif
       Redisplay(IO,Standard_False);
-      switch(It.Value()->GraphicStatus()){
-      case AIS_DS_Displayed:
+      if (It.Value()->GraphicStatus() == AIS_DS_Displayed)
+      {
         found_viewer = Standard_True;
-        break;
-      case AIS_DS_Erased:
-        found_coll = Standard_True;
-        break;
-      default:
-        break;
       }
     }
   }
   // update viewer...
-  if(updateviewer){
-    if(found_viewer)
-      myMainVwr->Update();
-    if(found_coll)
-      myCollectorVwr->Update();
+  if(updateviewer && found_viewer)
+  {
+    myMainVwr->Update();
   }
 }
 
@@ -1458,26 +1236,16 @@ void AIS_InteractiveContext::RecomputePrsOnly(const Handle(AIS_InteractiveObject
 {
   if(anIObj.IsNull()) return;
   anIObj->Update(allmodes);
-  
-  if(updateviewer)  {
-    if(HasOpenedContext())
-      myMainVwr->Update();
-    else{
-      if(myObjects.IsBound(anIObj)){
-        switch(myObjects(anIObj)->GraphicStatus()){
-        case AIS_DS_Displayed:
-          myMainVwr->Update();
-          break;
-        case AIS_DS_Erased:
-          {
-            if(!myCollectorVwr.IsNull())
-              myCollectorVwr->Update();
-          }
-        default:
-          break;
-        }
-      }
-    }
+
+  if (!updateviewer)
+  {
+    return;
+  }
+
+  if (HasOpenedContext() ||
+     (myObjects.IsBound(anIObj) && myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed))
+  {
+    myMainVwr->Update();
   }
 }
 //=======================================================================
@@ -1490,30 +1258,20 @@ void AIS_InteractiveContext::RecomputeSelectionOnly(const Handle(AIS_Interactive
   mgrSelector->RecomputeSelection(anIObj);
 
 
-  // A VOIR SI ENCORE UTILE...
+
   TColStd_ListOfInteger LI;
   TColStd_ListIteratorOfListOfInteger Lit;
   ActivatedModes(anIObj,LI);
   if(!HasOpenedContext()){
     if(!myObjects.IsBound(anIObj)) return;
-    switch(myObjects(anIObj)->GraphicStatus())
+
+    if (myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
+    {
+      for(Lit.Initialize(LI);Lit.More();Lit.Next())
       {
-      case AIS_DS_Displayed:
-        {
-          for(Lit.Initialize(LI);Lit.More();Lit.Next())
-            mgrSelector->Activate(anIObj,Lit.Value(),myMainSel);
-          break;
-        }
-      case AIS_DS_Erased:
-        {
-          for(Lit.Initialize(LI);Lit.More();Lit.Next())
-            mgrSelector->Activate(anIObj,Lit.Value(),myCollectorSel);
-          
-          break;
-        }
-      default:
-        break;
+        mgrSelector->Activate(anIObj,Lit.Value(),myMainSel);
       }
+    }
   }
 }
 
@@ -1549,9 +1307,6 @@ void AIS_InteractiveContext::Update(const Handle(AIS_InteractiveObject)& anIObj,
     case AIS_DS_Temporary:
       myMainVwr->Update();
       break;
-    case AIS_DS_Erased:
-      myCollectorVwr->Update();
-      break;
     default:
       break;
     }
@@ -1578,7 +1333,7 @@ void AIS_InteractiveContext::SetLocation(const Handle(AIS_InteractiveObject)& an
   }
   if(aLoc.IsIdentity()) return ;
 
-  // d'abord faire un reset de la precedente location pour tout nettoyer proprement...
+  // first reset the previous location to properly clean everything...
   if(anIObj->HasLocation())
     anIObj->ResetLocation();
 
@@ -1653,8 +1408,8 @@ void AIS_InteractiveContext::SetDeviationAngle(const Standard_Real anAngle)
 
 Standard_Real AIS_InteractiveContext::DeviationAngle() const
 {
-  return PI/180.0e0 ;
-  //  return myDefaultDrawer->DeviationAngle();
+  //return M_PI/180.0e0 ;
+    return myDefaultDrawer->DeviationAngle();
 }
 
 //=======================================================================
@@ -1757,7 +1512,7 @@ void AIS_InteractiveContext::SetDisplayMode(const AIS_DisplayMode aMode,
           STATUS->AddDisplayMode(aMode);
           
           if(STATUS->GraphicStatus()== AIS_DS_Displayed){
-            myMainPM->Erase(anObj, myDisplayMode);
+            myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
             myMainPM->Display(anObj, aMode);
             if(STATUS->IsSubIntensityOn())
               myMainPM->Color(anObj,mySubIntensity,aMode);
@@ -1787,37 +1542,17 @@ void AIS_InteractiveContext::SetDisplayMode(const Handle(AIS_InteractiveObject)&
     
     if(!myObjects.IsBound(anIObj)) 
       anIObj->SetDisplayMode(aMode);
-#ifdef BUC60632
     else if( anIObj->AcceptDisplayMode(aMode) ) 
-#else
-    else
-#endif
     {
       // CLE
       // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
       Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
       // ENDCLE
-#ifndef OCC4373      
-      // the interactive object has no mode : OldMode = Mode Session
-      //                    already has a mode : OldMode = old mode Propre
-
-      Standard_Integer OldMode = anIObj->HasDisplayMode() ?  anIObj->DisplayMode(): myDisplayMode;
-      
-      if(STATUS->IsDModeIn(OldMode))
-        STATUS->RemoveDisplayMode(OldMode);
-      STATUS->AddDisplayMode(aMode);
-      
-      if(STATUS->GraphicStatus()==AIS_DS_Displayed){
-        if(aMode!=OldMode ){
-          if(myMainPM->IsHighlighted(anIObj,OldMode))
-            myMainPM->Unhighlight(anIObj,OldMode);
-          
-          myMainPM->Erase(anIObj,OldMode);
-#else
       // SAN : erase presentations for all display modes different from <aMode>
       if(STATUS->GraphicStatus()==AIS_DS_Displayed){
         TColStd_ListOfInteger aModesToRemove;
-        for(ItL.Initialize(STATUS->DisplayedModes());ItL.More();ItL.Next()){
+        TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
+        for(;ItL.More();ItL.Next()){
 
           Standard_Integer OldMode = ItL.Value();
 
@@ -1825,7 +1560,7 @@ void AIS_InteractiveContext::SetDisplayMode(const Handle(AIS_InteractiveObject)&
             aModesToRemove.Append(OldMode);
             if(myMainPM->IsHighlighted(anIObj,OldMode))
               myMainPM->Unhighlight(anIObj,OldMode);
-            myMainPM->Erase(anIObj,OldMode);
+            myMainPM->SetVisibility (anIObj, OldMode, Standard_False);
           }
         }
 
@@ -1834,8 +1569,7 @@ void AIS_InteractiveContext::SetDisplayMode(const Handle(AIS_InteractiveObject)&
 
         if(!STATUS->IsDModeIn(aMode))
           STATUS->AddDisplayMode(aMode);
-#endif
-        
+
         myMainPM->Display(anIObj,aMode);
         Standard_Integer DM,HM,SM;
         GetDefModes(anIObj,DM,HM,SM);
@@ -1849,9 +1583,6 @@ void AIS_InteractiveContext::SetDisplayMode(const Handle(AIS_InteractiveObject)&
           myMainVwr->Viewer()->SetTransparency(Standard_True);
         
         if(updateviewer) myMainVwr->Update();
-#ifndef OCC4373 
-        }
-#endif
       }
       anIObj->SetDisplayMode(aMode);
     }
@@ -1883,7 +1614,7 @@ UnsetDisplayMode(const Handle(AIS_InteractiveObject)& anIObj,
       if(STATUS->GraphicStatus()==AIS_DS_Displayed){
         if(myMainPM->IsHighlighted(anIObj,OldMode))
           myMainPM->Unhighlight(anIObj,OldMode);
-        myMainPM->Erase(anIObj,OldMode);
+        myMainPM->SetVisibility (anIObj, OldMode, Standard_False);
         myMainPM->Display(anIObj,myDisplayMode);
         Standard_Integer DM,HM,SM;
         GetDefModes(anIObj,DM,HM,SM);
@@ -1905,15 +1636,13 @@ UnsetDisplayMode(const Handle(AIS_InteractiveObject)& anIObj,
 //purpose  : 
 //=======================================================================
 
-#ifdef GER61351
 void AIS_InteractiveContext::SetCurrentFacingModel(
                         const Handle(AIS_InteractiveObject)& anIObj,
-                        const Aspect_TypeOfFacingModel aModel) { 
- if (  !anIObj.IsNull ()  ) {
-   anIObj->SetCurrentFacingModel(aModel);
- }
+                        const Aspect_TypeOfFacingModel aModel)
+{
+  if (  !anIObj.IsNull ()  )
+    anIObj->SetCurrentFacingModel(aModel);
 }
-#endif
 
 //=======================================================================
 //function : SetColor
@@ -1923,7 +1652,6 @@ void AIS_InteractiveContext::SetCurrentFacingModel(
 void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIObj, 
                                      const Quantity_NameOfColor aColor,
                                      const Standard_Boolean updateviewer)
-#ifdef GER61351
 {
   SetColor(anIObj,Quantity_Color(aColor),updateviewer);
 }
@@ -1931,7 +1659,6 @@ void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIOb
 void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIObj, 
                                      const Quantity_Color &aColor,
                                      const Standard_Boolean updateviewer)
-#endif
 {
   if(anIObj.IsNull()) return ;
  
@@ -1951,7 +1678,7 @@ void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIOb
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
 
@@ -1965,7 +1692,7 @@ void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIOb
 //     gp_Dir D =Tr->Component()->XDirection();
 //     gp_Pnt O = Tr->Component()->Location();
 //     gp_Vec V(D);V*=Lx/5.;
-//     T.SetRotation(gp_Ax1(O,D),PI/6.);
+//     T.SetRotation(gp_Ax1(O,D),M_PI/6.);
 //     T.SetTranslationPart(V);
 //     TopLoc_Location L,IncLoc(T);
    
@@ -2026,7 +1753,7 @@ void AIS_InteractiveContext::SetDeviationCoefficient(
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
   if(updateviewer) UpdateCurrentViewer();
@@ -2070,7 +1797,7 @@ void AIS_InteractiveContext::SetHLRDeviationCoefficient(
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
   if(updateviewer) UpdateCurrentViewer();
@@ -2092,7 +1819,7 @@ void AIS_InteractiveContext::SetDeviationAngle(
  
   if(!anIObj->HasInteractiveContext())
     anIObj->SetContext(this);
-// To be modified after the related methods of AIS_Shape are passed to InteractiveObject
+  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
   if(anIObj->Type()!=AIS_KOI_Shape) return;
   if(anIObj->Signature()!=0) return;
   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnDeviationAngle(anAngle);
@@ -2113,7 +1840,7 @@ void AIS_InteractiveContext::SetDeviationAngle(
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
   if(updateviewer) UpdateCurrentViewer();
@@ -2130,11 +1857,11 @@ void AIS_InteractiveContext::SetAngleAndDeviation(
 {
 //  cout<<" Angle:"<< anAngle <<endl;
   if(anIObj.IsNull()) return ;
-//   Standard_Real anAngleRad = PI*anAngle/180; test rob...
+//   Standard_Real anAngleRad = M_PI*anAngle/180; test rob...
   if(!anIObj->HasInteractiveContext())
     anIObj->SetContext(this);
 
-// To be modified after the related methods of AIS_Shape are passed to InteractiveObject
+  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
   if(anIObj->Type()!=AIS_KOI_Shape) return;
   if(anIObj->Signature()!=0) return;
   (*((Handle(AIS_Shape)*)&anIObj))->SetAngleAndDeviation(anAngle);
@@ -2162,7 +1889,7 @@ void AIS_InteractiveContext::SetHLRAngleAndDeviation(
    if(!anIObj->HasInteractiveContext())
     anIObj->SetContext(this);
 
-// To be modified after the related methods of AIS_Shape are passed to InteractiveObject
+  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
   if(anIObj->Type()!=AIS_KOI_Shape) return;
   if(anIObj->Signature()!=0) return;
   (*((Handle(AIS_Shape)*)&anIObj))->SetHLRAngleAndDeviation(anAngle);
@@ -2184,7 +1911,7 @@ void AIS_InteractiveContext::SetHLRAngleAndDeviation(
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
   if(updateviewer) UpdateCurrentViewer();
@@ -2205,7 +1932,7 @@ void AIS_InteractiveContext::SetHLRDeviationAngle(
  
   if(!anIObj->HasInteractiveContext())
     anIObj->SetContext(this);
-// To be modified after the related methods of AIS_Shape are passed to InteractiveObject
+  // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
   if( anIObj->Type()!=AIS_KOI_Shape) return;
   if(anIObj->Signature()!=0) return;
   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnHLRDeviationAngle(anAngle);
@@ -2226,7 +1953,7 @@ void AIS_InteractiveContext::SetHLRDeviationAngle(
         }
       anIObj->SetRecomputeOk();
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
     }
   if(updateviewer) UpdateCurrentViewer();
@@ -2254,7 +1981,7 @@ void AIS_InteractiveContext::UnsetColor(const Handle(AIS_InteractiveObject)& anI
           NbDisp++;
         }
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
       anIObj->SetRecomputeOk();
     }
@@ -2283,13 +2010,11 @@ Quantity_NameOfColor AIS_InteractiveContext::Color(const Handle(AIS_InteractiveO
   return anIObj->Color();
 }
 
-#ifdef GER61351
 void AIS_InteractiveContext::Color(const Handle(AIS_InteractiveObject)& anIObj,
-                                             Quantity_Color &aColor) const 
+                                   Quantity_Color &aColor) const
 {
   anIObj->Color(aColor);
 }
-#endif
 
 //=======================================================================
 //function : Width
@@ -2327,7 +2052,7 @@ void AIS_InteractiveContext::SetWidth(const Handle(AIS_InteractiveObject)& anIOb
           NbDisp++;
         }
 #ifdef DEB
-      cout<<"nb de modes a recalculer : "<<NbDisp<<endl;
+      cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
 #endif
       anIObj->SetRecomputeOk();
     }
@@ -2493,46 +2218,6 @@ void AIS_InteractiveContext::UnsetTransparency(const Handle(AIS_InteractiveObjec
     UpdateCurrentViewer();
 }
 
-//=======================================================================
-//function : SetDegenerateModel
-//purpose  : 
-//=======================================================================
-
-#ifdef G003
-void AIS_InteractiveContext :: SetDegenerateModel (
-                          const Handle( AIS_InteractiveObject )& anObject,
-                          const Aspect_TypeOfDegenerateModel   aModel,
-                          const Quantity_Ratio                 aRatio
-                               ) {
- if (  !anObject.IsNull ()  ) {
-  if (  !anObject -> HasInteractiveContext ()  ) 
-                                anObject -> SetContext ( this );
-  anObject->SetDegenerateModel(aModel,aRatio);
-
- }  // end if
-}  // end AIS_InteractiveContext :: SetDegenerateModel
-
-void AIS_InteractiveContext :: SetDegenerateModel (
-                           const Aspect_TypeOfDegenerateModel aModel,
-                           const Quantity_Ratio            aRatio
-                               ) {
-
- AIS_DataMapIteratorOfDataMapOfIOStatus it ( myObjects );
-
- while (  it.More ()  ) {
-
-  Handle( AIS_InteractiveObject ) obj = it.Key ();
-
-  obj->SetDegenerateModel(aModel,aRatio);
-
-  it.Next ();
-
- }  // end while
-
-}  // end AIS_InteractiveContext :: SetDegenerateModel
-#endif
-
-#ifdef IMP140200
 //=======================================================================
 //function : SetSelectedAspect
 //purpose  : 
@@ -2540,7 +2225,8 @@ void AIS_InteractiveContext :: SetDegenerateModel (
 void AIS_InteractiveContext::SetSelectedAspect(
                                 const Handle(Prs3d_BasicAspect)& anAspect,
                                 const Standard_Boolean globalChange,
-                                const Standard_Boolean updateViewer) {
+                                const Standard_Boolean updateViewer)
+{
   if( !HasOpenedContext() ) {
     Standard_Boolean found = Standard_False;
     Handle(AIS_Selection) sel = 
@@ -2553,12 +2239,9 @@ void AIS_InteractiveContext::SetSelectedAspect(
     }
     if( found && updateViewer) {
       myMainVwr->Update();
-      if( !(myIsCollClosed && myCollectorVwr.IsNull()) ) 
-                                        myCollectorVwr->Update();
     }
   }
 }
-#endif
 
 //=======================================================================
 //function : SetLocalAttributes
@@ -2617,16 +2300,12 @@ void AIS_InteractiveContext::Status(const Handle(AIS_InteractiveObject)& anIObj,
         astatus +="\t| -->Erased\n";
         break;
       }
-    case AIS_DS_FullErased:
-      {
-        astatus +="\t| -->Full Erased\n";
-        break;
-      }
     default:
       break;
     }
     astatus += "\t| Active Display Modes in the MainViewer :\n";
-    for(ItL.Initialize(ST->DisplayedModes());ItL.More();ItL.Next()){
+    TColStd_ListIteratorOfListOfInteger ItL (ST->DisplayedModes());
+    for(;ItL.More();ItL.Next()){
       astatus += "\t|\t Mode ";
       astatus += TCollection_AsciiString(ItL.Value());
       astatus+="\n";
@@ -2675,8 +2354,7 @@ void AIS_InteractiveContext::GetDefModes(const Handle(AIS_InteractiveObject)& an
 //=======================================================================
 
 void AIS_InteractiveContext::EraseGlobal(const Handle(AIS_InteractiveObject)& anIObj, 
-                                         const Standard_Boolean updateviewer, 
-                                         const Standard_Boolean PutInCollector)
+                                         const Standard_Boolean updateviewer)
 {
   if(anIObj.IsNull()) return ;
   if(!myObjects.IsBound(anIObj)) return;
@@ -2688,33 +2366,20 @@ void AIS_InteractiveContext::EraseGlobal(const Handle(AIS_InteractiveObject)& an
   Standard_Integer Dmode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
   if(STATUS->GraphicStatus()==AIS_DS_Displayed){
     
-    for(ItL.Initialize(STATUS->DisplayedModes());ItL.More();ItL.Next()){
+    TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
+    for(;ItL.More();ItL.Next()){
       if(myMainPM->IsHighlighted(anIObj,ItL.Value()))
         myMainPM->Unhighlight(anIObj,ItL.Value());
-      myMainPM->Erase(anIObj,ItL.Value());
+      myMainPM->SetVisibility (anIObj, ItL.Value(), Standard_False);
     }
     if(IsCurrent(anIObj) && !STATUS->IsDModeIn(Dmode))
-      myMainPM->Erase(anIObj,Dmode);
+      myMainPM->SetVisibility (anIObj, Dmode, Standard_False);
     
     for(ItL.Initialize(STATUS->SelectionModes());ItL.More();ItL.Next())
       mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
     if(updateviewer) myMainVwr->Update();
   }
-  if(PutInCollector && !myCollectorPM.IsNull()){
-    myCollectorPM->Display(anIObj,Dmode);
-#ifdef OCC328
-    Standard_Integer SMode = anIObj->SelectionMode();
-    mgrSelector->Activate(anIObj,SMode,myCollectorSel);
-#else
-    mgrSelector->Activate(anIObj,0,myCollectorSel);
-#endif
-    if(STATUS->IsHilighted())
-      myCollectorPM->Highlight(anIObj,Dmode);
-    STATUS->SetGraphicStatus(AIS_DS_Erased);
-    if(updateviewer) myCollectorVwr->Update();
-  }
-  else
-    STATUS->SetGraphicStatus(AIS_DS_FullErased);
+  STATUS->SetGraphicStatus(AIS_DS_Erased);
   
 }
 
@@ -2732,7 +2397,8 @@ void AIS_InteractiveContext::ClearGlobal(const Handle(AIS_InteractiveObject)& an
   // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
   Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
   // ENDCLE
-   for(ItL.Initialize(STATUS->DisplayedModes());ItL.More();ItL.Next()){
+   TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
+   for(;ItL.More();ItL.Next()){
      if(STATUS->IsHilighted()){
        if(IsCurrent(anIObj))
 #ifdef OCC204
@@ -2762,13 +2428,8 @@ void AIS_InteractiveContext::ClearGlobal(const Handle(AIS_InteractiveObject)& an
       myAISDetectedSeq.Remove( i );
   }
 
-  if(myWasLastMain && !myLastinMain.IsNull())
-    if(myLastinMain == anIObj)
-      myLastinMain.Nullify();
-  else 
-    if(!myWasLastMain && !myLastinColl.IsNull())
-      if(myLastinColl == anIObj)
-        myLastinColl.Nullify();
+  if(myLastinMain == anIObj)
+    myLastinMain.Nullify();
 
   if(myLastPicked == anIObj)
     myLastPicked.Nullify();
@@ -2777,26 +2438,11 @@ void AIS_InteractiveContext::ClearGlobal(const Handle(AIS_InteractiveObject)& an
   // to avoid memory leaks
   mgrSelector->Remove(anIObj);
 
-  switch(STATUS->GraphicStatus()){
-  case AIS_DS_Erased:
-     { 
-       Standard_Integer DM = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0; 
-       if(STATUS->IsHilighted()){
-         myCollectorPM->Unhighlight(anIObj,DM);
-       }
-       myCollectorPM->Erase(anIObj,DM);
-       myCollectorPM->Clear(anIObj,DM);
-       if(updateviewer) myCollectorVwr->Update();
-       break;
-     }
-   case AIS_DS_Displayed:
-     {
-       if(updateviewer) myMainVwr->Update();
-       break;
-     }
-   default:
-     break;
-   }
+  if (updateviewer && (STATUS->GraphicStatus() == AIS_DS_Displayed))
+  {
+    myMainVwr->Update();
+  }
+
   myObjects.UnBind(anIObj);
   
 }
@@ -2823,17 +2469,8 @@ void AIS_InteractiveContext::ClearGlobalPrs(const Handle(AIS_InteractiveObject)&
     myMainPM->Clear(anIObj,aMode);
   }
   
-  if(STATUS->GraphicStatus()== AIS_DS_Erased)
-    {
-      if(DM==aMode){
-        if(STATUS->IsHilighted())
-          myCollectorPM->Unhighlight(anIObj,aMode);
-        myCollectorPM->Erase(anIObj,DM);
-        myCollectorPM->Clear(anIObj,DM);
-      }
-      if(updateviewer) myCollectorVwr->Update();
-    }
-  else if(STATUS->GraphicStatus()==AIS_DS_Displayed && updateviewer)
+
+  if(STATUS->GraphicStatus()==AIS_DS_Displayed && updateviewer)
     myMainVwr->Update();
 }
 
@@ -2963,7 +2600,32 @@ void AIS_InteractiveContext::UnsetSelectionMode(const Handle_AIS_InteractiveObje
 {
 }
 
-#ifdef BUC60688
+//=======================================================================
+//function : SetSensitivityMode
+//purpose  : 
+//=======================================================================
+
+void AIS_InteractiveContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) {
+
+  if( HasOpenedContext() )
+        myLocalContexts(myCurLocalIndex)->SetSensitivityMode(aMode);
+  else {
+    myMainSel->SetSensitivityMode(aMode);
+  }
+}
+
+//=======================================================================
+//function : SensitivityMode
+//purpose  : 
+//=======================================================================
+
+StdSelect_SensitivityMode AIS_InteractiveContext::SensitivityMode() const {
+
+  if( HasOpenedContext() )
+        return myLocalContexts(myCurLocalIndex)->SensitivityMode();
+  return myMainSel->SensitivityMode();
+}
+
 //=======================================================================
 //function : SetSensitivity
 //purpose  : 
@@ -2975,25 +2637,46 @@ void AIS_InteractiveContext::SetSensitivity(const Standard_Real aPrecision) {
         myLocalContexts(myCurLocalIndex)->SetSensitivity(aPrecision);
   else {
     myMainSel->SetSensitivity(aPrecision);
-    if( !myCollectorSel.IsNull() ) myCollectorSel->SetSensitivity(aPrecision);
   }
 }
 
 //=======================================================================
-//function : SetSensitivity
+//function : Sensitivity
 //purpose  : 
 //=======================================================================
 
-void AIS_InteractiveContext::SetSensitivity(const Standard_Integer aPrecision) {
+Standard_Real AIS_InteractiveContext::Sensitivity() const {
 
   if( HasOpenedContext() )
-        myLocalContexts(myCurLocalIndex)->SetSensitivity(aPrecision);
+        return myLocalContexts(myCurLocalIndex)->Sensitivity();
+  return myMainSel->Sensitivity();
+}
+
+//=======================================================================
+//function : SetPixelTolerance
+//purpose  : 
+//=======================================================================
+
+void AIS_InteractiveContext::SetPixelTolerance(const Standard_Integer aPrecision) {
+
+  if( HasOpenedContext() )
+        myLocalContexts(myCurLocalIndex)->SetPixelTolerance(aPrecision);
   else {
-    myMainSel->Set(aPrecision);
-    if( !myCollectorSel.IsNull() ) myCollectorSel->Set(aPrecision);
+    myMainSel->SetPixelTolerance(aPrecision);
   }
 }
-#endif
+
+//=======================================================================
+//function : PixelTolerance
+//purpose  : 
+//=======================================================================
+
+Standard_Integer AIS_InteractiveContext::PixelTolerance() const {
+
+  if( HasOpenedContext() )
+        return myLocalContexts(myCurLocalIndex)->PixelTolerance();
+  return myMainSel->PixelTolerance();
+}
 
 //=======================================================================
 //function : IsInLocal
@@ -3049,11 +2732,7 @@ void AIS_InteractiveContext::InitAttributes()
   HLA->SetTypeOfLine(Aspect_TOL_DASH);
 
   // tolerance to 4 pixels...
-#ifdef BUC60688
-  SetSensitivity();
-#else
-  myMainSel->Set(4);
-#endif
+  SetPixelTolerance();
 
   // Customizing the drawer for trihedrons and planes...
 
@@ -3149,3 +2828,49 @@ Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
 {
   return myIsAutoActivateSelMode;
 }
+
+//=======================================================================
+//function : SetZLayer
+//purpose  : 
+//=======================================================================
+
+void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
+                                        const Standard_Integer theLayerId)
+{
+  if (theIObj.IsNull ())
+    return;
+
+  if (myObjects.IsBound (theIObj))
+  {
+    if (myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed || myObjects (theIObj)->GraphicStatus() == AIS_DS_Erased)
+    {
+      theIObj->SetZLayer (myMainPM, theLayerId);
+    }
+  }
+  else if (HasOpenedContext ())
+  {
+    myLocalContexts (myCurLocalIndex)->SetZLayer (theIObj, theLayerId);
+  }
+}
+
+//=======================================================================
+//function : GetZLayer
+//purpose  : 
+//=======================================================================
+
+Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
+{
+  if (theIObj.IsNull ())
+    return -1;
+
+  if (myObjects.IsBound (theIObj))
+  {
+    return theIObj->GetZLayer (myMainPM);
+  }
+  else if (HasOpenedContext ())
+  {
+    return myLocalContexts (myCurLocalIndex)->GetZLayer (theIObj);
+  }
+
+  return -1;
+}