0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / TPrsStd / TPrsStd_AISPresentation.cxx
index 0accc61..5da1459 100644 (file)
@@ -5,8 +5,8 @@
 //
 // This file is part of Open CASCADE Technology software library.
 //
-// This library is free software; you can redistribute it and / or modify it
-// under the terms of the GNU Lesser General Public version 2.1 as published
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
 // by the Free Software Foundation, with special exception defined in the file
 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
 // distribution for complete text of the license and disclaimer of any warranty.
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-// Lastly modified by :
-// +---------------------------------------------------------------------------+
-// !      ivan ! SetMode                                 ! 5-04-2001! 3.0-00-1!
-// +---------------------------------------------------------------------------+
-#include <TPrsStd_AISPresentation.ixx>
 
-#include <TDF_DefaultDeltaOnRemoval.hxx>
+#include <AIS_InteractiveContext.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <Standard_GUID.hxx>
+#include <Standard_NullObject.hxx>
+#include <Standard_NoMoreObject.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDF_Attribute.hxx>
+#include <TDF_AttributeDelta.hxx>
 #include <TDF_DefaultDeltaOnModification.hxx>
+#include <TDF_DefaultDeltaOnRemoval.hxx>
 #include <TDF_DeltaOnAddition.hxx>
+#include <TDF_Label.hxx>
+#include <TDF_RelocationTable.hxx>
 #include <TDF_Tool.hxx>
-#include <TCollection_ExtendedString.hxx>
+#include <TPrsStd_AISPresentation.hxx>
+#include <TColStd_ListOfInteger.hxx>
+#include <TColStd_ListIteratorOfListOfInteger.hxx>
+#include <TDataXtd_Presentation.hxx>
 #include <TPrsStd_AISViewer.hxx>
-#include <AIS_InteractiveContext.hxx>
-#include <AIS_InteractiveObject.hxx>
 #include <TPrsStd_Driver.hxx>
 #include <TPrsStd_DriverTable.hxx>
 
+IMPLEMENT_STANDARD_RTTIEXT(TPrsStd_AISPresentation,TDF_Attribute)
 
-#define BUC60917
-#define BUC61050
-
-#define OCC1029
-#define OCC1030
-#define OCC1031
-#define OCC1032
-#define OCC1033
-#define OCC1034
+#define NO_MORE_OBJECT "TPrsStd_AISPresentation has no associated TDataXtd_PresentationData"
 
 //=======================================================================
-//function : Set
-//purpose  : 
+//function : TPrsStd_AISPresentation
+//purpose  : Constructor
 //=======================================================================
-Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set(const TDF_Label& L,const Standard_GUID& driver) 
-{   
-
-  Handle(TPrsStd_AISPresentation) P; 
-
-  if (!L.FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
-    P = new TPrsStd_AISPresentation ();  
-    L.AddAttribute(P);
-  }
-  P->SetDriverGUID(driver);   
-  return P;
+TPrsStd_AISPresentation::TPrsStd_AISPresentation ()
+{
 }
 
 
 //=======================================================================
-//function : Unset
+//function : Set
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::Unset (const TDF_Label& L)
-{   
-  Handle(TPrsStd_AISPresentation) P;  
-
-  if (L.FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
-    L.ForgetAttribute(P);
+Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set
+             ( const TDF_Label& theLabel, const Standard_GUID& theDriver )
+{
+  Handle(TPrsStd_AISPresentation) aPresentation;
+  // create associated data (unless already there)
+  Handle(TDataXtd_Presentation) aData = TDataXtd_Presentation::Set (theLabel, theDriver);
+  if(aData.IsNull())
+    throw Standard_NoMoreObject(NO_MORE_OBJECT);
+  if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) )
+  {
+    aPresentation = new TPrsStd_AISPresentation();
+    theLabel.AddAttribute(aPresentation);
   }
-}
 
+  return aPresentation;
+}
 
 //=======================================================================
 //function : Set
 //purpose  : 
 //=======================================================================
-Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set (const Handle(TDF_Attribute)& master) 
-{  
-  Handle(TPrsStd_AISPresentation) P;  
-
-  if (!master->Label().FindAttribute(TPrsStd_AISPresentation::GetID(),P)) { 
-    P = new TPrsStd_AISPresentation ();  
-    master->Label().AddAttribute(P);
-  }   
-
-  P->SetDriverGUID( master->ID() );
-
-  return P;
+Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set(const Handle(TDF_Attribute)& theMaster)
+{
+  return TPrsStd_AISPresentation::Set(theMaster->Label(), theMaster->ID());
 }
 
+//=======================================================================
+//function : Unset
+//purpose  : 
+//=======================================================================
+void TPrsStd_AISPresentation::Unset (const TDF_Label& theLabel)
+{
+  Handle(TPrsStd_AISPresentation) aPresentation;
+  if ( theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) )
+    theLabel.ForgetAttribute(aPresentation);
 
-
+  // remove associated data
+  TDataXtd_Presentation::Unset (theLabel);
+}
 
 //=======================================================================
-//function : GetID
+//function : getData
 //purpose  : 
 //=======================================================================
-const Standard_GUID& TPrsStd_AISPresentation::GetID() 
+Handle(TDataXtd_Presentation) TPrsStd_AISPresentation::getData () const
 {
-  static Standard_GUID TPrsStd_AISPresentationID("04fb4d00-5690-11d1-8940-080009dc3333");
-  return TPrsStd_AISPresentationID;
+  Handle(TDataXtd_Presentation) aData;
+  if (!Label().FindAttribute(TDataXtd_Presentation::GetID(), aData))
+      throw Standard_NoMoreObject(NO_MORE_OBJECT);
+  return aData;
 }
 
-
 //=======================================================================
-//function : TPrsStd_AISPresentation
+//function : GetID
 //purpose  : 
 //=======================================================================
-TPrsStd_AISPresentation::TPrsStd_AISPresentation () : 
-myDriverGUID("00000000-0000-0000-0000-000000000000"),
-myTransparency(0.),
-myColor(Quantity_NOC_WHITE),
-myMaterial(Graphic3d_NOM_BRASS),
-myWidth(0.),
-#ifdef BUC61050
-myMode(0),
-mySelectionMode(0),
-#endif
-isDisplayed(Standard_False),
-hasOwnColor(Standard_False),
-hasOwnMaterial(Standard_False),
-hasOwnTransparency(Standard_False),
-hasOwnWidth(Standard_False)
-#ifdef BUC61050
-,hasOwnMode(Standard_False),
-hasOwnSelectionMode(Standard_False)
-#endif
-{}
-
+const Standard_GUID& TPrsStd_AISPresentation::GetID()
+{
+  static Standard_GUID TPrsStd_AISPresentationID("3680ac6c-47ae-4366-bb94-26abb6e07341");
+  return TPrsStd_AISPresentationID;
+}
 
 //=======================================================================
 //function : Display
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::Display (const Standard_Boolean update)
+void TPrsStd_AISPresentation::Display(const Standard_Boolean theIsUpdate)
 {
-   
-  if( update || myAIS.IsNull() ) {
+  if ( theIsUpdate || myAIS.IsNull() )
     AISUpdate();
-  }
-  AISDisplay();     
-}
 
+  AISDisplay();
+}
 
 //=======================================================================
 //function : Erase
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::Erase (const Standard_Boolean remove)
-{  
-  if( isDisplayed ) AISErase(remove);   
+void TPrsStd_AISPresentation::Erase(const Standard_Boolean theIsRemove)
+{
+  if ( IsDisplayed() )
+  {
+    AISErase(theIsRemove);
+  }
 }
 
 //=======================================================================
 //function : Update
 //purpose  : 
 //=======================================================================
-void  TPrsStd_AISPresentation::Update ()
-{  
+void TPrsStd_AISPresentation::Update()
+{
   AISUpdate();
 }
 
-
 //=======================================================================
 //function : IsDisplayed
 //purpose  : 
 //=======================================================================
-Standard_Boolean TPrsStd_AISPresentation::IsDisplayed () const
+Standard_Boolean TPrsStd_AISPresentation::IsDisplayed() const
 {
-  return isDisplayed;
+  return getData()->IsDisplayed();
 }
 
+//=======================================================================
+//function : SetDisplayed
+//purpose  : 
+//=======================================================================
+void TPrsStd_AISPresentation::SetDisplayed(const Standard_Boolean theIsDisplayed)
+{
+  // this method can be called by AISUpdate() in the process of removal,
+  // while data attribute may be already removed
+  Backup();
+  getData()->SetDisplayed(theIsDisplayed);
+}
 
 //=======================================================================
 //function :SetDriverGUID
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetDriverGUID(const Standard_GUID& guid) 
+void TPrsStd_AISPresentation::SetDriverGUID(const Standard_GUID& theGUID)
 {
-  // OCC2932 correction
-  if(myDriverGUID == guid) return;
-
-  Backup(); 
-  myDriverGUID = guid;
+  Backup();
+  getData()->SetDriverGUID (theGUID);
 }
 
-
 //=======================================================================
 //function :GetDriverGUID
 //purpose  : 
 //=======================================================================
 Standard_GUID TPrsStd_AISPresentation::GetDriverGUID() const
 {
-  return myDriverGUID;
+  return getData()->GetDriverGUID();
 }
 
-
 //=======================================================================
 //function :Material
 //purpose  : 
 //=======================================================================
 Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const
 {
-  return myMaterial; 
+  return (Graphic3d_NameOfMaterial)getData()->MaterialIndex();
 }
 
 //=======================================================================
@@ -214,99 +204,102 @@ Graphic3d_NameOfMaterial TPrsStd_AISPresentation::Material() const
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnMaterial() const
 {
-  return hasOwnMaterial;
+  return getData()->HasOwnMaterial();
 }
 
 //=======================================================================
-//function :UnsetMaterial
+//function : UnsetMaterial
 //purpose  : 
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetMaterial()
 {
-  // OCC2932 correction
-  if(hasOwnMaterial == Standard_False && !myAIS.IsNull()) {
-      if(!myAIS->HasMaterial())
-       return;
-  }
-    
-  Backup();
-  hasOwnMaterial = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() &&  myAIS->HasMaterial() ) {
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
-    if( !ctx.IsNull() )   
-      ctx->UnsetMaterial(myAIS, Standard_False);
-    else  
+  if ( !getData()->HasOwnMaterial() && !myAIS.IsNull() && !myAIS->HasMaterial() )
+    return;
+
+  getData()->UnsetMaterial();
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() && myAIS->HasMaterial() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->UnsetMaterial(myAIS, Standard_False);
+    else
       myAIS->UnsetMaterial();
   }
 }
 
+
 //=======================================================================
-//function :SetMaterial
+//function : SetMaterial
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial aName) 
+void TPrsStd_AISPresentation::SetMaterial(const Graphic3d_NameOfMaterial theName)
 {
-  // OCC2932 correction
-  if(myMaterial == aName && hasOwnMaterial == Standard_True && !myAIS.IsNull()) {
-      if(myAIS->HasMaterial() && myAIS->Material() == aName)
-       return;
-  }
-
   Backup();
-  myMaterial = aName;
-  hasOwnMaterial = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) { 
-    if( myAIS->HasMaterial() && myAIS->Material() == aName ) return;   // AIS has already had that material     
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
-    if( !ctx.IsNull() )   
-      ctx->SetMaterial(myAIS, aName,  Standard_False);
-    else  
-      myAIS->SetMaterial(aName);
+  if ( getData()->HasOwnMode() && getData()->MaterialIndex() == theName )
+    if ( !myAIS.IsNull() && myAIS->HasMaterial() && myAIS->Material() == theName )
+      return;
+
+  getData()->SetMaterialIndex(theName);
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() )
+  {
+    if ( myAIS->HasMaterial() && myAIS->Material() == theName )
+      return;   // AIS has already had that material
+
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->SetMaterial(myAIS, theName,  Standard_False);
+    else
+      myAIS->SetMaterial(theName);
   }
 }
 
-
 //=======================================================================
-//function :SetTransparency
+//function :Transparency
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetTransparency(const Standard_Real aValue) 
+Standard_Real TPrsStd_AISPresentation::Transparency() const
 {
-  // OCC2932 correction
-  if(hasOwnTransparency == Standard_True && myTransparency == aValue && !myAIS.IsNull())
-      if(myAIS->Transparency() == aValue)
-       return;
-
-  Backup();
-  myTransparency = aValue;
-  hasOwnTransparency = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate(); 
-  if( !myAIS.IsNull() ) { 
-    if( myAIS->Transparency() == aValue ) return;   // AIS has already had that transparency 
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
-    if( !ctx.IsNull() )  
-      ctx->SetTransparency(myAIS, aValue, Standard_False);
-    else 
-      myAIS->SetTransparency(aValue);
-  }
+  return getData()->Transparency();
 }
 
-
 //=======================================================================
-//function :Transparency
+//function :SetTransparency
 //purpose  : 
 //=======================================================================
-Standard_Real TPrsStd_AISPresentation::Transparency() const
+void TPrsStd_AISPresentation::SetTransparency(const Standard_Real theValue)
 {
-  return myTransparency;
+  Backup();
+  if (getData()->HasOwnTransparency() && getData()->Transparency() == theValue)
+    if ( !myAIS.IsNull() && myAIS->Transparency() == theValue )
+      return;
+
+  getData()->SetTransparency(theValue);
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() )
+  {
+    if ( myAIS->Transparency() == theValue )
+      return;   // AIS has already had that transparency 
+
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->SetTransparency(myAIS, theValue, Standard_False);
+    else
+      myAIS->SetTransparency(theValue);
+  }
 }
 
 //=======================================================================
@@ -315,316 +308,314 @@ Standard_Real TPrsStd_AISPresentation::Transparency() const
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetTransparency()
 {
-  // OCC2932 correction
-  if(!hasOwnTransparency)
+  if (!getData()->HasOwnTransparency())
     return;
 
-  Backup(); 
-  hasOwnTransparency = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) {
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
-    if( !ctx.IsNull() )   
-      ctx->UnsetTransparency(myAIS, Standard_False);
-    else  
+  getData()->UnsetTransparency();
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if( !aContext.IsNull() )
+      aContext->UnsetTransparency(myAIS, Standard_False);
+    else
       myAIS->UnsetTransparency();
   }
 }
 
 //=======================================================================
-//function :HasTransparency
+//function : HasTransparency
 //purpose  : 
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnTransparency() const
 {
-  return hasOwnTransparency;
+  return getData()->HasOwnTransparency();
 }
 
 //=======================================================================
-//function :Color
+//function : Color
 //purpose  : 
 //=======================================================================
 Quantity_NameOfColor TPrsStd_AISPresentation::Color() const
 {
-  return myColor;
+  return getData()->Color();
 }
 
 //=======================================================================
-//function :HasColor
+//function : HasOwnColor
 //purpose  : 
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnColor() const
 {
-  return hasOwnColor;
+  return getData()->HasOwnColor();
 }
 
 //=======================================================================
-//function :UnsetColor
+//function : UnsetColor
 //purpose  : 
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetColor()
 {
-  // OCC2932 correction
-  if(!hasOwnColor && !myAIS.IsNull()) 
-      if(!myAIS->HasColor())
-       return;
-  
-  Backup();
-  hasOwnColor = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() &&  myAIS->HasColor() ) {
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
-    if( !ctx.IsNull() )   
-      ctx->UnsetColor(myAIS, Standard_False);
-    else  
+  if (!getData()->HasOwnColor() && ! myAIS.IsNull() && !myAIS->HasColor())
+    return;
+  getData()->UnsetColor();
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() && myAIS->HasColor() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->UnsetColor(myAIS, Standard_False);
+    else
       myAIS->UnsetColor();
   }
 }
 
 //=======================================================================
-//function :SetColor
+//function : SetColor
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor aColor) 
+void TPrsStd_AISPresentation::SetColor(const Quantity_NameOfColor theColor)
 {
-  // OCC2932 correction
-  if(hasOwnColor && myColor == aColor && ! myAIS.IsNull()) 
-    if(myAIS->HasColor() && myAIS->Color() == aColor ) 
-      return;
-  
   Backup();
-  myColor = aColor;
-  hasOwnColor = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) {
-    if( myAIS->HasColor() && myAIS->Color() == aColor ) return;   // AIS has already had that color     
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
-    if( !ctx.IsNull() )  
-      ctx->SetColor(myAIS, aColor, Standard_False);
+  if ( getData()->HasOwnColor() && getData()->Color() == theColor )
+  {
+    if (!myAIS.IsNull() && myAIS->HasColor())
+    {
+      Quantity_Color aColor;
+      myAIS->Color (aColor);
+      if (aColor.Name() == theColor)
+      {
+        return;
+      }
+    }
+  }
+
+  getData()->SetColor(theColor);
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() )
+  {
+    if (myAIS->HasColor())
+    {
+      Quantity_Color aColor;
+      myAIS->Color (aColor);
+      if (aColor.Name() == theColor)
+      {
+        return;   // AIS has already had that color
+      }
+    }
+
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if( !aContext.IsNull() )
+      aContext->SetColor(myAIS, theColor, Standard_False);
     else 
-      myAIS->SetColor(aColor);
+      myAIS->SetColor(theColor);
   }
 }
 
-
 //=======================================================================
 //function :Width
 //purpose  : 
 //=======================================================================
 Standard_Real TPrsStd_AISPresentation::Width() const
 {
-   return myWidth;
+  return getData()->Width();
 }
 
 //=======================================================================
-//function :HasWidth
+//function : HasWidth
 //purpose  : 
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnWidth() const
 {
-  return hasOwnWidth;
+  return getData()->HasOwnWidth();
 }
 
 //=======================================================================
-//function :SetWidth
+//function : SetWidth
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetWidth(const Standard_Real aWidth) 
+void TPrsStd_AISPresentation::SetWidth(const Standard_Real theWidth)
 {
-  // OCC2932 correction
-  if(hasOwnWidth && myWidth == aWidth && myAIS.IsNull()) 
-    if(myAIS->HasWidth() && myAIS->Width() == aWidth ) 
+  Backup();
+  if ( getData()->HasOwnWidth() && getData()->Width() == theWidth )
+    if ( !myAIS.IsNull() && myAIS->HasWidth() && myAIS->Width() == theWidth )
       return;
 
-  Backup();
-  myWidth = aWidth;
-  hasOwnWidth = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) {
-    if( myAIS->HasWidth() && myAIS->Width() == aWidth ) return;   // AIS has already had that width     
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
-    if( !ctx.IsNull() )  
-      ctx->SetWidth(myAIS, aWidth, Standard_False);
+  getData()->SetWidth(theWidth);
+
+  if( !myAIS.IsNull() )
+  {
+    if ( myAIS->HasWidth() && myAIS->Width() == theWidth )
+      return;   // AIS has already had that width
+
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if( !aContext.IsNull() )
+      aContext->SetWidth(myAIS, theWidth, Standard_False);
     else 
-      myAIS->SetWidth(aWidth);
+      myAIS->SetWidth(theWidth);
   }
 }
 
 //=======================================================================
-//function :UnsetWidth
+//function : UnsetWidth
 //purpose  : 
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetWidth()
 {
-  // OCC2932 correction
-  if(!hasOwnWidth && !myAIS.IsNull())
-    if(!myAIS->HasWidth())
+  if ( !getData()->HasOwnWidth() )
+    if ( !myAIS.IsNull() && !myAIS->HasWidth() )
       return;
 
-  Backup();
-  hasOwnWidth = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() &&  myAIS->HasWidth() ) {
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext(); 
-    if( !ctx.IsNull() )   
-      ctx->UnsetWidth(myAIS, Standard_False);
-    else  
+  getData()->UnsetWidth();
+
+  if( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() && myAIS->HasWidth() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->UnsetWidth(myAIS, Standard_False);
+    else
       myAIS->UnsetWidth();
   }
 }
 
-
-
 //=======================================================================
 //function : Mode
 //purpose  : 
 //=======================================================================
-
 Standard_Integer TPrsStd_AISPresentation::Mode() const
 {
-   return myMode;
+  return getData()->Mode();
 }
 
 //=======================================================================
-//function :HasOwnMode
+//function : HasOwnMode
 //purpose  : 
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnMode() const
 {
-  return hasOwnMode;
+  return getData()->HasOwnMode();
 }
 
 //=======================================================================
-//function :SetMode
+//function : SetMode
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode) 
+void TPrsStd_AISPresentation::SetMode(const Standard_Integer theMode)
 {
-  // OCC2932 correction
-  if(hasOwnMode && myMode == theMode && !myAIS.IsNull()) 
-    if(myAIS->DisplayMode() == theMode ) 
+  Backup();
+  if ( getData()->HasOwnMode() && getData()->Mode() == theMode )
+    if ( !myAIS.IsNull() && myAIS->DisplayMode() == theMode )
       return;
 
-  Backup();
-  myMode = theMode;
-  hasOwnMode = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) {
-    if(  myAIS->DisplayMode() == theMode ) return;   // AIS has already had that mode    
-    Handle(AIS_InteractiveContext) ctx;
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) )
-      ctx = viewer->GetInteractiveContext();
-    if( !ctx.IsNull() )  
-      ctx->SetDisplayMode(myAIS, theMode, Standard_False);
+  getData()->SetMode(theMode);
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if ( !myAIS.IsNull() )
+  {
+    if (  myAIS->DisplayMode() == theMode )
+      return;   // AIS has already had that mode
+
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if( !aContext.IsNull() )
+      aContext->SetDisplayMode(myAIS, theMode, Standard_False);
     else 
       myAIS->SetDisplayMode(theMode);
   }
 }
 
 //=======================================================================
-//function :UnsetMode
+//function : UnsetMode
 //purpose  : 
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetMode()
 {
-  // OCC2932 correction
-  if(HasOwnMode() == Standard_False && myAIS.IsNull() == Standard_False)
-    if(!myAIS->HasDisplayMode())
+  if ( !getData()->HasOwnMode() )
+    if ( !myAIS.IsNull() && !myAIS->HasDisplayMode() )
       return;
 
-  Backup();
-  hasOwnMode = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() &&  myAIS->HasDisplayMode() ) {
-       Handle(AIS_InteractiveContext) ctx;
-       Handle(TPrsStd_AISViewer) viewer;
-       if( TPrsStd_AISViewer::Find(Label(), viewer) )
-       ctx = viewer->GetInteractiveContext(); 
-       if( !ctx.IsNull() )
-        ctx->UnsetDisplayMode(myAIS, Standard_False);
-    else  
-               myAIS->UnsetDisplayMode();
+  getData()->UnsetMode();
+
+  if ( myAIS.IsNull() )
+    AISUpdate();
+
+  if( !myAIS.IsNull() &&  myAIS->HasDisplayMode() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
+
+    if ( !aContext.IsNull() )
+      aContext->UnsetDisplayMode(myAIS, Standard_False);
+    else
+      myAIS->UnsetDisplayMode();
   }
 }
 
-#ifdef BUC61050
 //=======================================================================
 //function : SelectionMode
 //purpose  : 
 //=======================================================================
-
 Standard_Integer TPrsStd_AISPresentation::SelectionMode() const
 {
-   return mySelectionMode;
+  return getData()->SelectionMode();
 }
 
 //=======================================================================
-//function :HasOwnSelectionMode
+//function : HasOwnSelectionMode
 //purpose  : 
 //=======================================================================
 Standard_Boolean TPrsStd_AISPresentation::HasOwnSelectionMode() const
 {
-  return hasOwnSelectionMode;
+  return getData()->HasOwnSelectionMode();
 }
 
 //=======================================================================
-//function :SetSelectionMode
+//function : SetSelectionMode
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelectionMode) 
+void TPrsStd_AISPresentation::SetSelectionMode(const Standard_Integer theSelectionMode)
 {
-  // OCC2932 correction
-  if(hasOwnSelectionMode && mySelectionMode == theSelectionMode && !myAIS.IsNull())
-    if(myAIS->SelectionMode() == theSelectionMode )
-      return;
-
   Backup();
-  mySelectionMode = theSelectionMode;
-  hasOwnSelectionMode = Standard_True;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() ) {
-    if(  myAIS->SelectionMode() == theSelectionMode ) return;
-    myAIS->SetSelectionMode(theSelectionMode);
-  }
+  getData()->SetSelectionMode (theSelectionMode);
+  AISUpdate();
 }
 
 //=======================================================================
-//function :UnsetSelectionMode
+//function : UnsetSelectionMode
 //purpose  : 
 //=======================================================================
 void TPrsStd_AISPresentation::UnsetSelectionMode()
 {
-  if(!hasOwnSelectionMode && !myAIS.IsNull())
-    if(!myAIS->HasSelectionMode())
-      return;
-
-  Backup();
-  hasOwnSelectionMode = Standard_False;
-  if( myAIS.IsNull() ) AISUpdate();
-  if( !myAIS.IsNull() &&  myAIS->HasSelectionMode() ) {
-    myAIS->UnsetSelectionMode();
-  }
+  getData()->UnsetSelectionMode ();
+  AISUpdate();
 }
-#endif
-
 
 //=======================================================================
 //function : ID
 //purpose  : 
 //=======================================================================
-const Standard_GUID& TPrsStd_AISPresentation::ID() const { return GetID(); }
-
+const Standard_GUID& TPrsStd_AISPresentation::ID() const
+{
+  return GetID();
+}
 
 //=======================================================================
 //function : BackupCopy
@@ -632,27 +623,7 @@ const Standard_GUID& TPrsStd_AISPresentation::ID() const { return GetID(); }
 //=======================================================================
 Handle(TDF_Attribute) TPrsStd_AISPresentation::BackupCopy() const 
 {
-  Handle(TPrsStd_AISPresentation) copy = new TPrsStd_AISPresentation;
-  copy->myTransparency = myTransparency;
-  copy->myColor = myColor;
-  copy->myMode= myMode;
-#ifdef BUC60917
-  copy->myWidth= myWidth;
-#endif
-  copy->myMaterial = myMaterial;
-  copy->hasOwnColor = hasOwnColor;
-  copy->hasOwnMaterial = hasOwnMaterial;
-  copy->hasOwnWidth = hasOwnWidth;
-  copy->hasOwnMode=hasOwnMode;
-  copy->hasOwnTransparency = hasOwnTransparency;
-  copy->myAIS.Nullify();
-  copy->isDisplayed = isDisplayed;
-  copy->myDriverGUID = myDriverGUID;
-#ifdef BUC61050
-  copy->mySelectionMode= mySelectionMode;
-  copy->hasOwnSelectionMode = hasOwnSelectionMode;
-#endif
-  return copy; 
+  return new TPrsStd_AISPresentation;
 }
 
 
@@ -662,146 +633,42 @@ Handle(TDF_Attribute) TPrsStd_AISPresentation::BackupCopy() const
 //=======================================================================
 Handle(TDF_Attribute) TPrsStd_AISPresentation::NewEmpty() const
 {   
-  return new TPrsStd_AISPresentation ();
+  return new TPrsStd_AISPresentation();
 }
 
 //=======================================================================
-//function : Restore
+//function : Paste
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::Restore (const Handle(TDF_Attribute)& With) 
-{ 
-  Handle(TPrsStd_AISPresentation) with = Handle(TPrsStd_AISPresentation)::DownCast(With);
-
+void TPrsStd_AISPresentation::Restore(const Handle(TDF_Attribute)& /*theWith*/)
+{
   myAIS.Nullify();
-
-  if(!with->HasOwnMaterial()) hasOwnMaterial = Standard_False;
-  else { 
-#ifndef OCC1031
-    myMaterial = with->Material();
-#endif
-    hasOwnMaterial = Standard_True;
-  }
-#ifdef OCC1031
-  myMaterial = with->Material();
-#endif
-
-  if(!with->HasOwnColor()) hasOwnColor = Standard_False;
-  else { 
-#ifndef OCC1030
-    myColor = with->Color(); 
-#endif
-    hasOwnColor = Standard_True;
-  }
-#ifdef OCC1030
-  myColor = with->Color(); 
-#endif
-
-  if(!with->HasOwnWidth()) hasOwnWidth = Standard_False;
-  else { 
-#ifndef OCC1032
-    myWidth = with->Width();
-#endif
-    hasOwnWidth = Standard_True;
-  }
-#ifdef OCC1032
-  myWidth = with->Width();
-#endif
-
- if(!with->HasOwnMode()) hasOwnMode = Standard_False;
-  else { 
-#ifndef OCC1033
-    myMode = with->Mode();
-#endif
-    hasOwnMode = Standard_True;
-  }
-#ifdef OCC1033
-  myMode = with->Mode();
-#endif
-  
-#ifdef BUC61050
-  if(!with->HasOwnSelectionMode()) hasOwnSelectionMode = Standard_False;
-  else { 
-#ifndef OCC1034
-    mySelectionMode = with->SelectionMode();
-#endif
-    hasOwnSelectionMode = Standard_True;
-  }
-#ifdef OCC1034
-  mySelectionMode = with->SelectionMode();
-#endif
-#endif
-
-  if(!with->HasOwnTransparency()) hasOwnTransparency = Standard_False;
-  else { 
-#ifndef OCC1029
-    myTransparency = with->Transparency();
-#endif
-    hasOwnTransparency = Standard_True;
-  }
-#ifdef OCC1029
-  myTransparency = with->Transparency();
-#endif
-
-  isDisplayed = with->IsDisplayed();
-  myDriverGUID  = with->GetDriverGUID();
 }
 
 //=======================================================================
 //function : Paste
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& Into,
-                                    const Handle(TDF_RelocationTable)& ) const
-{  
-  Handle(TPrsStd_AISPresentation) into = Handle(TPrsStd_AISPresentation)::DownCast(Into);
-  
-  into->Backup();
-
-  if(!hasOwnMaterial) into->hasOwnMaterial = Standard_False;
-  else {
-    into->myMaterial = myMaterial;
-    into->hasOwnMaterial = Standard_True;
-  }
-
-  if(!hasOwnColor) into->hasOwnColor = Standard_False;
-  else {
-    into->myColor = myColor; 
-    into->hasOwnColor = Standard_True;
-  }
-
-  if(!hasOwnWidth) into->hasOwnWidth = Standard_False;
-  else {
-    into->myWidth = myWidth;
-    into->hasOwnWidth = Standard_True;
-  }
- if(!hasOwnMode) into->hasOwnMode = Standard_False;
-  else {
-    into->myMode = myMode;
-    into->hasOwnMode = Standard_True;
-  }
-
-#ifdef BUC61050
- if(!hasOwnSelectionMode) into->hasOwnSelectionMode = Standard_False;
-  else {
-    into->mySelectionMode = mySelectionMode;
-    into->hasOwnSelectionMode = Standard_True;
-  }
-#endif
+void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& theInto,
+                                     const Handle(TDF_RelocationTable)& ) const
+{
+  Handle(TPrsStd_AISPresentation) anInto =
+    Handle(TPrsStd_AISPresentation)::DownCast(theInto);
 
-  if(!hasOwnTransparency) into->hasOwnTransparency = Standard_False;
-  else {
-    into->myTransparency = myTransparency;
-    into->hasOwnTransparency = Standard_True;
+  anInto->Backup();
+  if (!anInto->myAIS.IsNull())
+  {
+    // Save displayed flag.
+    Standard_Boolean displayed = anInto->IsDisplayed();
+    // Erase the interactive object.
+    anInto->AISErase(Standard_True);
+    // Restore the displayed flag.
+    if (displayed)
+      anInto->SetDisplayed(displayed);
   }
-
-  if (into->isDisplayed)
-    into->AISErase(Standard_True);
-
-  into->isDisplayed = isDisplayed;   
-  into->myDriverGUID = myDriverGUID;
-
-  into->myAIS.Nullify();
+  // Nullify the interactive object.
+  // It will be restored on the next call to AISUpdate().
+  anInto->myAIS.Nullify();
 }
 
 //=======================================================================
@@ -809,7 +676,7 @@ void TPrsStd_AISPresentation::Paste (const Handle(TDF_Attribute)& Into,
 //purpose  : erase if displayed
 //=======================================================================
 void TPrsStd_AISPresentation::AfterAddition() 
-{ 
+{
   AfterResume();
 }
 
@@ -818,8 +685,8 @@ void TPrsStd_AISPresentation::AfterAddition()
 //purpose  : erase if displayed
 //=======================================================================
 void TPrsStd_AISPresentation::BeforeRemoval() 
-{ 
-   BeforeForget();
+{
+  BeforeForget();
 }
 
 //=======================================================================
@@ -828,232 +695,303 @@ void TPrsStd_AISPresentation::BeforeRemoval()
 //=======================================================================
 void TPrsStd_AISPresentation::BeforeForget() 
 { 
-  if( !myAIS.IsNull() ) {
-    AISErase(Standard_True);   //Remove AISObject from context
+  if ( !myAIS.IsNull() )
+  { // Remove AISObject from context.
+    AISErase(Standard_True);
     myAIS.Nullify();
   }
 }
 
-
 //=======================================================================
 //function : AfterResume
 //purpose  : display if displayed
 //=======================================================================
-void TPrsStd_AISPresentation::AfterResume() 
+void TPrsStd_AISPresentation::AfterResume()
 {
   AISUpdate();
-  if( IsDisplayed() ) AISDisplay();
-  else AISErase();
+  if ( IsDisplayed() )
+    AISDisplay();
+  else
+    AISErase();
 }
 
 //=======================================================================
 //function : BeforeUndo
 //purpose  : le NamedShape associe doit etre present
 //=======================================================================
-
 Standard_Boolean TPrsStd_AISPresentation::BeforeUndo (const Handle(TDF_AttributeDelta)& AD,
-                                                     const Standard_Boolean ) 
+                                                                             const Standard_Boolean ) 
 {
   Handle(TPrsStd_AISPresentation) P;
-  AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P); 
+  AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P);
 
-  if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {    
-    if( !P.IsNull() ) P->BeforeForget();
+  if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition)))
+  {
+    if ( !P.IsNull() )
+      P->BeforeForget();
   }
   else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) {
-  }  
-  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) {
-    if( !P.IsNull() ) P->BeforeForget();
-  } 
+  }
+  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification)))
+  {
+    if ( !P.IsNull() )
+      P->BeforeForget();
+  }
 
   return Standard_True;
 }
 
-
 //=======================================================================
 //function : AfterUndo
 //purpose  : le NamedShape associe doit etre present
 //=======================================================================
-
 Standard_Boolean TPrsStd_AISPresentation::AfterUndo (const Handle(TDF_AttributeDelta)& AD,
-                                                    const Standard_Boolean ) 
+                                                     const Standard_Boolean ) 
 { 
   Handle(TPrsStd_AISPresentation) P;
   AD->Label().FindAttribute(TPrsStd_AISPresentation::GetID(), P);
 
-  if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition))) {
+  if (AD->IsKind(STANDARD_TYPE(TDF_DeltaOnAddition)))
+  {}
+  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval)))
+  {
+    if ( !P.IsNull() )
+      P->AfterAddition();
   }
-  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnRemoval))) {  
-    if( !P.IsNull() ) P->AfterAddition();
-  }  
-  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification))) {
-    if( !P.IsNull() ) P->AfterResume();
+  else if (AD->IsKind(STANDARD_TYPE(TDF_DefaultDeltaOnModification)))
+  {
+    if ( !P.IsNull() )
+      P->AfterResume();
   }
 
   return Standard_True;
 }
 
-
-
 //=======================================================================
 //function : AISUpdate
 //purpose  : 
 //=======================================================================
-
-void TPrsStd_AISPresentation::AISUpdate ()
-{ 
+void TPrsStd_AISPresentation::AISUpdate()
+{
   Backup();
-
-  Handle(AIS_InteractiveContext) ctx;
-  if(!Label().IsNull()) {  
-    Handle(TPrsStd_AISViewer) viewer;
-    if( TPrsStd_AISViewer::Find(Label(), viewer) ) ctx = viewer->GetInteractiveContext();
-
-    Handle(TPrsStd_Driver) driver;
-    if (TPrsStd_DriverTable::Get()->FindDriver(GetDriverGUID(), driver)) {
-      if (myAIS.IsNull()) {              // build a new  AIS
-       Handle(AIS_InteractiveObject) newais;
-       if (driver->Update (Label(), newais))  {
-         myAIS = newais;
-         newais->SetOwner(this);
-       }
+  getData()->Backup();
+  Handle(AIS_InteractiveContext) aContext;
+  if ( !Label().IsNull() )
+  {
+    aContext = getAISContext();
+
+    Handle(TPrsStd_Driver) aDriver;
+    if ( TPrsStd_DriverTable::Get()->FindDriver(GetDriverGUID(), aDriver) )
+    {
+      // Build a new  AIS.
+      if ( myAIS.IsNull() )
+      {
+        Handle(AIS_InteractiveObject) aNewObj;
+        if ( aDriver->Update(Label(), aNewObj) )
+        {
+                       myAIS = aNewObj;
+          aNewObj->SetOwner(this);
+        }
       }
-      else {
-       Handle(AIS_InteractiveObject) theais = myAIS;
-       if (driver->Update (Label(), theais)) {
-         if (! (theais ==  myAIS)) {    
-           if(!ctx.IsNull()) ctx->Remove(myAIS);
-           myAIS = theais;               //Driver has built new AIS
-           theais->SetOwner(this);
-         }
-       }
+      else
+      {
+        Handle(AIS_InteractiveObject) anObj = myAIS;
+        if ( aDriver->Update(Label(), anObj) )
+          if ( !(anObj ==  myAIS) )
+          {
+            if ( !aContext.IsNull() )
+              aContext->Remove (myAIS, Standard_True);
+
+            // Driver has built new AIS.
+            myAIS = anObj;
+            anObj->SetOwner(this);
+          }
       }
     }
   }
   else return;
 
-//Apply the visualization settings
-  if( !myAIS.IsNull() ) {
-
-    if( hasOwnColor ) { 
-      if( !(myAIS->HasColor()) || (myAIS->HasColor() && myAIS->Color() != myColor) ) {
-       if(!ctx.IsNull()) ctx->SetColor(myAIS, myColor, Standard_False);
-       else myAIS->SetColor(myColor);  
+  // Apply the visualization settings.
+  if ( !myAIS.IsNull() )
+  {
+    if ( HasOwnColor() )
+    {
+      Quantity_NameOfColor aColor = Color();
+      Quantity_Color aPrsColor;
+      myAIS->Color (aPrsColor);
+      if ( !(myAIS->HasColor()) || (myAIS->HasColor() && aPrsColor.Name() != aColor) )
+      {
+        if ( !aContext.IsNull() )
+          aContext->SetColor(myAIS, aColor, Standard_False);
+        else
+          myAIS->SetColor(aColor);
       }
-    } 
+    }
 
-    if( hasOwnMaterial ) { 
-      if( !(myAIS->HasMaterial()) || (myAIS->HasMaterial() && myAIS->Material() != myMaterial) ) {
-       if(!ctx.IsNull()) ctx->SetMaterial(myAIS, myMaterial, Standard_False );
-       else myAIS->SetMaterial(myMaterial);  
+    if ( HasOwnMaterial() )
+    {
+      Graphic3d_NameOfMaterial aMaterial = Material();
+      if ( !(myAIS->HasMaterial()) || (myAIS->HasMaterial() && myAIS->Material() != aMaterial) )
+      {
+        if ( !aContext.IsNull() )
+          aContext->SetMaterial(myAIS, aMaterial, Standard_False );
+        else
+          myAIS->SetMaterial(aMaterial);
       }
-    } 
-    
-    if( hasOwnTransparency ) {
-      if(  myAIS->Transparency() != myTransparency )  {
-       if(!ctx.IsNull()) ctx->SetTransparency(myAIS, myTransparency, Standard_False);
-       else myAIS->SetTransparency(myTransparency);  
+    }
+
+    if ( HasOwnTransparency() )
+    {
+      const Standard_Real aTransparency = Transparency();
+      if ( myAIS->Transparency() != aTransparency )
+      {
+        if( !aContext.IsNull() )
+          aContext->SetTransparency(myAIS, aTransparency, Standard_False);
+        else
+          myAIS->SetTransparency(aTransparency);
       }
     }
 
-    if( hasOwnWidth ) { 
-      if( !(myAIS->HasWidth()) || (myAIS->HasWidth() && myAIS->Width() != myWidth) ) {
-       if(!ctx.IsNull()) ctx->SetWidth(myAIS, myWidth, Standard_False);
-       else myAIS->SetWidth(myWidth); 
+    if ( HasOwnWidth() )
+    {
+      const Standard_Real aWidth = Width();
+      if ( !(myAIS->HasWidth()) || (myAIS->HasWidth() && myAIS->Width() != aWidth) )
+      {
+        if ( !aContext.IsNull() )
+          aContext->SetWidth(myAIS, aWidth, Standard_False);
+        else
+          myAIS->SetWidth(aWidth);
       }
     }
 
-    if( hasOwnMode) { 
-      if(  myAIS->DisplayMode() != myMode ) {
-         myAIS->SetDisplayMode(myMode); 
-      } 
-     
-           
+    if ( HasOwnMode() )
+    {
+      const Standard_Integer aMode = Mode();
+      if ( myAIS->DisplayMode() != aMode )
+        myAIS->SetDisplayMode(aMode);
     }
 
-#ifdef BUC61050
-    if (hasOwnSelectionMode) { 
-      if (myAIS->SelectionMode() != mySelectionMode ) {
-       myAIS->SetSelectionMode(mySelectionMode); 
+    if ( !aContext.IsNull() && IsDisplayed() )
+      aContext->Redisplay(myAIS, Standard_False);
+
+    if (HasOwnSelectionMode()) {
+      if (!aContext.IsNull())
+      {
+        TColStd_ListOfInteger anActivatedModes;
+        aContext->ActivatedModes (myAIS, anActivatedModes);
+        Standard_Boolean isActivated = Standard_False;
+        Standard_Integer aSelectionMode = SelectionMode();
+        if (aSelectionMode == -1)
+        {
+          aContext->Deactivate(myAIS);
+        }
+        else
+        {
+          for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
+          {
+            if (aModeIter.Value() == aSelectionMode)
+            {
+              isActivated = Standard_True;
+              break;
+            }
+          }
+          if (!isActivated)
+            aContext->Activate (myAIS, aSelectionMode, Standard_False);
+        }
       } 
     }
-#endif
 
   }
   
-  if( isDisplayed && !ctx.IsNull() ) ctx->Redisplay(myAIS, Standard_False);
-  return;
+  if (IsDisplayed() && !aContext.IsNull())
+    aContext->Redisplay(myAIS, Standard_False);
 }
 
 //=======================================================================
 //function : AISDisplay
 //purpose  : 
 //=======================================================================
+void TPrsStd_AISPresentation::AISDisplay()
+{
+  if ( !Label().IsNull() )
+  {
+    Handle(AIS_InteractiveContext) aContext = getAISContext();
 
-void TPrsStd_AISPresentation::AISDisplay ()
-{   
-  
-  if (!Label().IsNull()) {  
-    Handle(TPrsStd_AISViewer) viewer;
-    if( !TPrsStd_AISViewer::Find(Label(), viewer) ) return;   
-    Handle(AIS_InteractiveContext) ctx = viewer->GetInteractiveContext();
-    if( ctx.IsNull() ) return;
+    if ( aContext.IsNull() )
+      return;
 
-    if (!myAIS.IsNull()) { 
+    if ( !myAIS.IsNull() )
+    {
+      if ( !(myAIS->GetContext()).IsNull() && (myAIS->GetContext()) != aContext )
+        myAIS->GetContext()->Remove (myAIS, Standard_False);
 
-      if( !(myAIS->GetContext()).IsNull() && (myAIS->GetContext()) != ctx ) myAIS->GetContext()->Remove(myAIS);
-      
-      if( isDisplayed && ctx->IsDisplayed(myAIS) ) return;
+      if ( IsDisplayed() && aContext->IsDisplayed(myAIS) )
+        return;
 
-      ctx->Display(myAIS, Standard_False);
-      
-      if( ctx->IsDisplayed(myAIS) ) SetDisplayed(Standard_True); 
+      aContext->Display(myAIS, Standard_False);
+
+      if ( aContext->IsDisplayed(myAIS) )
+        SetDisplayed(Standard_True);
     }
   }
 }
 
-
 //=======================================================================
 //function : AISErase
 //purpose  : 
 //=======================================================================
+void TPrsStd_AISPresentation::AISErase(const Standard_Boolean theIsRemove)
+{  
+  Handle(AIS_InteractiveContext) aContext, anOwnContext;
 
-void TPrsStd_AISPresentation::AISErase (const Standard_Boolean remove)
-{   
-  SetDisplayed(Standard_False);  
-  Handle(AIS_InteractiveContext) ctx, ownctx;
+  if ( !myAIS.IsNull() )
+  {
+    Backup();
+    if ( !Label().IsNull() )
+    {
+      if (IsAttribute(TDataXtd_Presentation::GetID()))
+        SetDisplayed(Standard_False); 
 
-  if ( !myAIS.IsNull() ) {   
-    
-    if ( !Label().IsNull()) {  
       Handle(TPrsStd_AISViewer) viewer;
-      if( !TPrsStd_AISViewer::Find(Label(), viewer) ) return;  
-      ownctx = myAIS->GetContext();
-      ctx = viewer->GetInteractiveContext();
-      if( remove ) {
-       if( !ctx.IsNull() ) ctx->Remove (myAIS,Standard_False); 
-       if( !ownctx.IsNull() && ownctx != ctx ) ownctx->Remove (myAIS,Standard_False);
+      if( !TPrsStd_AISViewer::Find(Label(), viewer) )
+        return;
+      anOwnContext = myAIS->GetContext();
+      aContext = viewer->GetInteractiveContext();
+
+      if ( theIsRemove )
+      {
+        if ( !aContext.IsNull() )
+          aContext->Remove(myAIS, Standard_False);
+        if ( !anOwnContext.IsNull() && anOwnContext != aContext )
+          anOwnContext->Remove(myAIS, Standard_False);
+
         myAIS->SetToUpdate();
       }
-      else {
-       if( !ctx.IsNull() ) ctx->Erase (myAIS,Standard_False); 
-       if( !ownctx.IsNull() && ownctx != ctx ) ownctx->Erase (myAIS,Standard_False);
+      else
+      {
+        if ( !aContext.IsNull() )
+          aContext->Erase(myAIS, Standard_False);
+        if ( !anOwnContext.IsNull() && anOwnContext != aContext )
+          anOwnContext->Erase(myAIS, Standard_False);
       }
     }
-    else {
-     if( remove ) {
-      if( !ownctx.IsNull() ) {
-       ownctx->Remove (myAIS,Standard_False);
-       myAIS->SetToUpdate();
+    else
+    {
+      if ( theIsRemove )
+      {
+        if ( !anOwnContext.IsNull() )
+        {
+          anOwnContext->Remove(myAIS, Standard_False);
+          myAIS->SetToUpdate();
+        }
       }
-     } else
-      if( !ownctx.IsNull() ) ownctx->Erase (myAIS,Standard_False); 
+      else
+        if( !anOwnContext.IsNull() )
+          anOwnContext->Erase(myAIS, Standard_False);
     }
   }
 }
 
-
 //=======================================================================
 //function :GetAIS
 //purpose  : 
@@ -1063,14 +1001,15 @@ Handle(AIS_InteractiveObject) TPrsStd_AISPresentation::GetAIS() const
   return myAIS;
 }
 
-
 //=======================================================================
-//function :SetDisplayed
+//function : getAISContext
 //purpose  : 
 //=======================================================================
-void TPrsStd_AISPresentation::SetDisplayed(const Standard_Boolean B) 
+Handle(AIS_InteractiveContext) TPrsStd_AISPresentation::getAISContext() const
 {
-  Backup();
-  isDisplayed = B;
-}
+  Handle(TPrsStd_AISViewer) aViewer;
+  if ( TPrsStd_AISViewer::Find(Label(), aViewer) )
+    return aViewer->GetInteractiveContext();
 
+  return Handle_AIS_InteractiveContext();
+}