0025147: Visualization, TKOpenGl - support EGL as alternative to GLX
[occt.git] / src / Visual3d / Visual3d_View.cxx
index 305b948..35c4a9a 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-/***********************************************************************
-
-     FONCTION :
-     ----------
-        Classe Visual3d_View.cxx :
-
-
-        Declaration of variables specific to views.
-
-        A view is defined by :
-                -  ViewManager
-                -  ContextView
-
-     HISTORIQUE DES MODIFICATIONS   :
-     --------------------------------
-      Mars 1992 : NW,JPB,CAL ; Creation.
-      04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
-      22-04-97  : CAL ; Ajout du Plot.
-      03-06-97  : FMN ; Correction calcul SetRatio
-      06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
-      28-07-97  : PCT ; Ajout lumiere frontale headlight.
-      19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
-      17-10-97  : CAL ; Le Projects nouveau est arrive. (NewProjects)
-      24-10-97  : CAL ; Retrait de DownCast.
-      24-10-97  : CAL ; Retrait des DataStructure (Vieille maquette inutilisee).
-      17-11-97  : FMN ; Ajout DoResize dans Resized()
-      20-11-97  : CAL ; Disparition de la dependance avec math
-      ??-11-97  : CAL ; Retrait de la dependance avec math. Calcul developpe.
-      ??-11-97  : CAL ; Ajout de NumberOfDisplayedStructures
-      07-08-97  : PCT ; ajout support texture mapping
-      15-01-98  : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset
-      15-01-98  : CAL ; Ajout de la transformation d'une TOS_COMPUTED
-      26-01-98  : CAL ; Ajout de la methode HaveTheSameOwner
-      06-02-98  : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner.
-      05-03-98  : CAL ; GraphicTransform que si Trsf non invalidante
-      27-03-98  : CAL ; Ajout de TheStructure = devant Compute (...) !!!!
-      16-04-98  : CAL ; Remise a ID de la Trsf sur la COMPUTED
-      20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
-      24-06-98  : CAL ; PRO14526 SetTransparency sur une vue non active.
-      17-07-98  : CAL ; PRO14872 test sur aTrsf dans ::SetTransform.
-      16-09-98  : BGN ; Points d'entree du Triedre (S3819, Phase 1)
-      22-09-98  : BGN ; S3989 (anciennement S3819)
-                        TypeOfTriedron* from Aspect (pas Visual3d)
-      06-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
-      16-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
-      02-11-98  : CAL ; Retrait de OSD::SetSignal.
-      18-11-98  : FMN ; Correction sur la gestion de la perspective
-      02-12-98  : CAL ; S4062. Ajout des layers.
-      13-09-99  : GG  ; GER61454 Adds LightLimit() and PlaneLimit() methods
-      10-11-99  : GG  ; PRO19603 Add Redraw( area ) method
-      14-01-00  : GG  ; IMP140100 Add ViewManager( ) method
-      22-10-01  : SAV ; Added EnableDepthTest() method.
-      30-04-02  : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance
-                        in data access when a lot of objects are used)
-                        Will improve performance of selection mechanisms
-
-************************************************************************/
-
-#define BUC60572        //GG_03-08-99    Add protection on Zclipping & Zcueing planes
-//              positions.
-
-#define GER61454        //GG 14-09-99 Activates model clipping planes
-
-#define RIC120302       //GG Add a NEW SetWindow method which enable
-//                      to connect a graphic widget and context to OGL.
-
-//BUC61044 25/10/01 SAV ; added functionality to control gl depth testing from higher API
-//BUC61045 25/10/01 SAV ; added functionality to control gl lighting from higher API
-
-//OCC1188 SAV Added methods to set background image
-
-/*----------------------------------------------------------------------*/
-/*
- * Constantes
- */
-
-#define NO_DEBUG
-#define NO_DESTROY
-#define NO_TRACE
-#define NO_TRACE_ACCEPT
-#define NO_TRACE_CLEAR
-#define NO_TRACE_CONNECT
-#define NO_TRACE_HIGH
-#define NO_TRACE_COMP
-#define NO_TRACE_TRSF
-#define NO_TRACE_DISPLAY
-#define NO_TRACE_ISCOMP
-#define NO_TRACE_LENGTH
-#define NO_TRACE_LAYER
-
-/*----------------------------------------------------------------------*/
-/*
- * Includes
- */
-
-#ifdef WNT
-#include <windows.h>
+#ifdef _WIN32
+  #include <windows.h>
 #endif
 
-// for the class
 #include <Visual3d_View.ixx>
-#include <Visual3d_View.pxx>
-#include <Visual3d_DepthCueingDefinitionError.hxx>
-#include <Visual3d_ZClippingDefinitionError.hxx>
-
-#ifdef OLD_METHOD
-#include <math_Vector.hxx>
-#endif /* OLD_METHOD */
-
-#include <OSD.hxx>
 
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_MapOfStructure.hxx>
-#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 #include <Graphic3d_DataStructureManager.hxx>
-
 #include <Graphic3d_GraphicDriver.hxx>
-
+#include <Graphic3d_MapOfStructure.hxx>
+#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_TextureEnv.hxx>
 #include <Graphic3d_Vector.hxx>
 #include <Graphic3d_Vertex.hxx>
-
+#include <Visual3d_DepthCueingDefinitionError.hxx>
 #include <Visual3d_Light.hxx>
-#include <Visual3d_SetOfLight.hxx>
-#include <Visual3d_HSetOfLight.hxx>
-#include <Visual3d_SetIteratorOfSetOfLight.hxx>
-
-#include <Visual3d_SetIteratorOfSetOfView.hxx>
-
-#include <Graphic3d_TextureEnv.hxx>
-
+#include <Visual3d_HSequenceOfView.hxx>
+#include <Visual3d_ZClippingDefinitionError.hxx>
+#include <OSD.hxx>
 #include <TColStd_HArray2OfReal.hxx>
 
-#if (defined(_WIN32) || defined(__WIN32__))
+#if defined(_WIN32)
   #include <WNT_Window.hxx>
 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
   #include <Cocoa_Window.hxx>
 
 #include <float.h>
 
-//-Aliases
-
-//-Global data definitions
-
-//-Constructors
-
-Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
-MyContext (),
-MyTOCOMPUTESequence (),
-MyCOMPUTEDSequence (),
-MyDisplayedStructure ()
+// =======================================================================
+// function : Visual3d_View
+// purpose  :
+// =======================================================================
+Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& theMgr)
+: myViewManager         (theMgr.operator->()),
+  myIsInComputedMode    (Standard_False),
+  myAutoZFitIsOn        (Standard_True),
+  myAutoZFitScaleFactor (1.0),
+  myStructuresUpdated   (Standard_True)
 {
+  MyCView.ViewId                  = theMgr->Identification (this);
+  MyCView.Active                  = 0;
+  MyCView.IsDeleted               = 0;
+  MyCView.WsId                    = -1;
+  MyCView.DefWindow.IsDefined     = 0;
+  MyCView.Context.NbActiveLight   = 0;
+  MyCView.Context.ZBufferActivity = -1;
 
-        MyPtrViewManager        = AManager.operator->();
-        MyCView.ViewId          = int (AManager->Identification (this));
-        MyCView.Active          = 0;
-        MyCView.IsDeleted       = 0;
-
-        MyCView.WsId                  = -1;
-        MyCView.DefWindow.IsDefined   = 0;
-
-        MyCView.Context.NbActiveLight = 0;
-
-        MyCView.Context.ZBufferActivity = -1;
-
-        IsInitialized = Standard_False;
-        ComputedModeIsActive      = Standard_False;
-        MyCView.Backfacing        = 0;
-
-        MyCView.ptrUnderLayer = 0;
-        MyCView.ptrOverLayer = 0;
-        MyCView.GContext = 0;
-        MyCView.GDisplayCB = 0;
-        MyCView.GClientData = 0;
-
-        MyGraphicDriver = MyViewManager->GraphicDriver();
+  MyCView.Backfacing    = 0;
+  MyCView.ptrUnderLayer = 0;
+  MyCView.ptrOverLayer  = 0;
+  MyCView.GContext      = 0;
+  MyCView.GDisplayCB    = 0;
+  MyCView.GClientData   = 0;
 
+  myGraphicDriver = myViewManager->GraphicDriver();
 }
 
-//-Methods, in order
-// RIC120302
-void Visual3d_View::SetWindow (const Handle(Aspect_Window)&      AWindow,
-                               const Aspect_RenderingContext     AContext,
-                               const Aspect_GraphicCallbackProc& ADisplayCB,
-                               const Standard_Address            AClientData)
+// =======================================================================
+// function : SetWindow
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetWindow (const Handle(Aspect_Window)&      theWindow,
+                               const Aspect_RenderingContext     theContext,
+                               const Aspect_GraphicCallbackProc& theDisplayCB,
+                               const Standard_Address            theClientData)
 {
-  if (IsDeleted ()) return;
-
-  if (IsDefined ())
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (IsDefined())
+  {
     Visual3d_ViewDefinitionError::Raise ("Window already defined");
+  }
 
-  MyCView.GContext        = AContext;
-  MyCView.GDisplayCB      = ADisplayCB;
-  MyCView.GClientData     = AClientData;
-  SetWindow(AWindow);
+  MyCView.GContext    = theContext;
+  MyCView.GDisplayCB  = theDisplayCB;
+  MyCView.GClientData = theClientData;
+  SetWindow (theWindow);
 }
-// RIC120302
 
+// =======================================================================
+// function : SetWindow
+// purpose  :
+// =======================================================================
 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
 {
-  if (IsDeleted ()) return;
-
-  if (IsDefined ())
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (IsDefined())
   {
     Visual3d_ViewDefinitionError::Raise ("Window already defined");
   }
@@ -224,157 +114,152 @@ void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
   MyWindow = theWindow;
   MyCView.WsId = MyCView.ViewId;
   MyCView.DefWindow.IsDefined = 1;
-#if (defined(_WIN32) || defined(__WIN32__))
-  const Handle(WNT_Window) aWin   = Handle(WNT_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = (HWND )(aWin->HWindow());
-  MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
-  WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
-  aWinData->WNT_WDriver_Ptr = (void* )this;
-  aWinData->WNT_VMgr        = (void* )MyPtrViewManager;
-#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
-  const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = (Aspect_Drawable )aWin->HView();
-  MyCView.DefWindow.XParentWindow = NULL;
-  //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
-#else
-  const Handle(Xw_Window) aWin    = Handle(Xw_Window)::DownCast (theWindow);
-  MyCView.DefWindow.XWindow       = aWin->XWindow();
-  //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
-#endif
-
-        Standard_Integer Width, Height;
-        theWindow->Size (Width, Height);
-
-        MyCView.DefWindow.dx    = float( Width );
-        MyCView.DefWindow.dy    = float( Height );
-
-        Standard_Real R, G, B;
-        MyBackground    = MyWindow->Background ();
-        (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
-        MyCView.DefWindow.Background.r  = float (R);
-        MyCView.DefWindow.Background.g  = float (G);
-        MyCView.DefWindow.Background.b  = float (B);
-
-        UpdateView ();
-        if (! MyGraphicDriver->View (MyCView))
-                Visual3d_ViewDefinitionError::Raise ("Association failed");
-
-        MyGradientBackground = MyWindow->GradientBackground();
-        SetGradientBackground(MyGradientBackground,1);
-
-        Standard_Boolean AWait = Standard_False;        // => immediate update
-        MyGraphicDriver->SetVisualisation (MyCView);
-        MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
-        MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
-        MyGraphicDriver->ClipLimit (MyCView, AWait);
-        MyGraphicDriver->Environment(MyCView);
+  MyCView.DefWindow.XWindow       = theWindow->NativeHandle();
+  MyCView.DefWindow.XParentWindow = theWindow->NativeParentHandle();
+
+  Standard_Integer Width, Height;
+  theWindow->Size (Width, Height);
+  MyCView.DefWindow.dx = float(Width);
+  MyCView.DefWindow.dy = float(Height);
+
+  Standard_Real R, G, B;
+  MyBackground = MyWindow->Background ();
+  MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
+  MyCView.DefWindow.Background.r = float (R);
+  MyCView.DefWindow.Background.g = float (G);
+  MyCView.DefWindow.Background.b = float (B);
+
+  UpdateView();
+  if (!myGraphicDriver->View (MyCView))
+  {
+    Visual3d_ViewDefinitionError::Raise ("Association failed");
+  }
 
-        // Make view manager z layer list consistent with the view's list.
-        MyViewManager->InstallZLayers (this);
+  MyGradientBackground = MyWindow->GradientBackground();
+  SetGradientBackground(MyGradientBackground,1);
 
-        // Update planses of model clipping
-        UpdatePlanes ();
+  Standard_Boolean AWait = Standard_False; // => immediate update
+  myGraphicDriver->SetVisualisation (MyCView);
+  myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
+  myGraphicDriver->DepthCueing  (MyCView, MyContext.DepthCueingIsOn());
+  myGraphicDriver->ClipLimit    (MyCView, AWait);
+  myGraphicDriver->Environment  (MyCView);
 
-        // Update light sources
-        UpdateLights ();
+  // Make view manager z layer list consistent with the view's list.
+  myViewManager->InstallZLayers (this);
 
-        /*
-         * Association view-window does not cause the display
-         * of structures that can be displayed in the new view.
-         * In fact, association view-window is done, but the
-         * display is produced only if the view is activated (Activate).
-         */
+  // Update planses of model clipping
+  UpdatePlanes();
 
-        SetRatio ();
+  // Update light sources
+  UpdateLights();
 
+  // Association view-window does not cause the display
+  // of structures that can be displayed in the new view.
+  // In fact, association view-window is done, but the
+  // display is produced only if the view is activated (Activate).
+  SetRatio();
 }
 
-Handle(Aspect_Window) Visual3d_View::Window () const {
-
-        if (! IsDefined ())
-                Visual3d_ViewDefinitionError::Raise ("Window not defined");
-
-        return (MyWindow);
-
+// =======================================================================
+// function : Window
+// purpose  :
+// =======================================================================
+Handle(Aspect_Window) Visual3d_View::Window() const
+{
+  if (!IsDefined())
+  {
+    Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
+  return MyWindow;
 }
 
-Standard_Boolean Visual3d_View::IsDefined () const {
-
-        if (MyCView.DefWindow.IsDefined)
-                return (Standard_True);
-        else
-                return (Standard_False);
-
+// =======================================================================
+// function : IsDefined
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::IsDefined() const
+{
+  return MyCView.DefWindow.IsDefined != 0;
 }
 
-Standard_Boolean Visual3d_View::IsDeleted () const {
-
-        if (MyCView.IsDeleted)
-                return (Standard_True);
-        else
-                return (Standard_False);
-
+// =======================================================================
+// function : IsDeleted
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::IsDeleted() const
+{
+  return MyCView.IsDeleted != 0;
 }
 
-void Visual3d_View::Destroy () {
-
-#ifdef DESTROY
-        cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
-#endif
-
-        // Since MyPtrViewManager can be already distroyed,
-        // avoid attempts to access it in SetBackground()
-        MyPtrViewManager = 0;
-        Remove ();
-
+// =======================================================================
+// function : Destroy
+// purpose  :
+// =======================================================================
+void Visual3d_View::Destroy()
+{
+  // Since myViewManager can be already destroyed,
+  // avoid attempts to access it in SetBackground()
+  myViewManager = NULL;
+  Remove();
 }
 
-void Visual3d_View::Remove () {
-
-#ifdef DESTROY
-        cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
-#endif
-
-        if (IsDeleted ()) return;
-        if (! IsDefined ()) return;
-
-        MyTOCOMPUTESequence.Clear ();
-        MyCOMPUTEDSequence.Clear ();
-        MyDisplayedStructure.Clear ();
-
-        Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
-        Aspect_Background BlackBackground (BlackColor);
-        SetBackground (BlackBackground);
-
-        Aspect_GradientBackground BlackGradBackground;
-        SetGradientBackground (BlackGradBackground,0);
+// =======================================================================
+// function : Remove
+// purpose  :
+// =======================================================================
+void Visual3d_View::Remove()
+{
+  if (IsDeleted()
+  || !IsDefined())
+  {
+    return;
+  }
 
-       if (MyPtrViewManager)
-         MyPtrViewManager->UnIdentification( MyCView.ViewId );
+  myStructsToCompute.Clear();
+  myStructsComputed .Clear();
+  myStructsDisplayed.Clear();
 
-        MyGraphicDriver->RemoveView (MyCView);
+  Aspect_GradientBackground aBlackGrad;
+  SetBackground (Aspect_Background (Quantity_NOC_BLACK));
+  SetGradientBackground (aBlackGrad, Standard_False);
 
-        MyCView.WsId            = -1;
-        MyCView.IsDeleted       = 1;
-        MyCView.DefWindow.IsDefined     = 0;
+  if (myViewManager != NULL)
+  {
+    myViewManager->UnIdentification (MyCView.ViewId);
+  }
 
-        IsInitialized = Standard_False;
+  myGraphicDriver->RemoveView (MyCView);
 
-        MyWindow.Nullify ();
+  MyCView.WsId                = -1;
+  MyCView.IsDeleted           = 1;
+  MyCView.DefWindow.IsDefined = 0;
 
+  MyWindow.Nullify();
 }
 
-void Visual3d_View::Resized () {
-
-        if (IsDeleted ()) return;
-
-        if (! IsDefined ())
-                Visual3d_ViewDefinitionError::Raise ("Window not defined");
-        MyWindow->DoResize() ;
-        SetRatio ();
-
+// =======================================================================
+// function : Resized
+// purpose  :
+// =======================================================================
+void Visual3d_View::Resized()
+{
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (!IsDefined())
+  {
+    Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
+  MyWindow->DoResize();
+  SetRatio();
 }
 
+// =======================================================================
+// function : SetRatio
+// purpose  :
+// =======================================================================
 void Visual3d_View::SetRatio()
 {
   if (IsDeleted())
@@ -382,26 +267,22 @@ void Visual3d_View::SetRatio()
     return;
   }
 
-  Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode();
-
-  MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);
+  const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
+  myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
 
   Standard_Integer aWidth, aHeight;
-
   MyWindow->Size (aWidth, aHeight);
-
-  if( aWidth > 0 && aHeight > 0 )
+  if (aWidth > 0 && aHeight > 0)
   {
     Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight; 
 
     MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
     MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
 
-    MyGraphicDriver->RatioWindow (MyCView);
+    myGraphicDriver->RatioWindow (MyCView);
 
     // Update camera aspect
-    Handle(Graphic3d_Camera) aCamera = MyCView.Context.Camera;
-
+    const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
     if (!aCamera.IsNull())
     {
       aCamera->SetAspect (aRatio);
@@ -413,11 +294,14 @@ void Visual3d_View::SetRatio()
     }
   }
 
-  MyViewManager->SetUpdateMode (UpdateMode);
-  if (UpdateMode == Aspect_TOU_ASAP)
-    Update();
+  myViewManager->SetUpdateMode (anUpdateMode);
+  Update (anUpdateMode);
 }
 
+// =======================================================================
+// function : UpdateLights
+// purpose  :
+// =======================================================================
 void Visual3d_View::UpdateLights()
 {
   if (IsDeleted()
@@ -436,16 +320,16 @@ void Visual3d_View::UpdateLights()
 
     MyCView.Context.NbActiveLight = 1;
     MyCView.Context.ActiveLight   = &aCLight;
-    MyGraphicDriver->SetLight (MyCView);
+    myGraphicDriver->SetLight (MyCView);
     MyCView.Context.ActiveLight   = NULL;
     return;
   }
 
   MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
-                                       MyGraphicDriver->InquireLightLimit());
+                                       myGraphicDriver->InquireLightLimit());
   if (MyCView.Context.NbActiveLight < 1)
   {
-    MyGraphicDriver->SetLight (MyCView);
+    myGraphicDriver->SetLight (MyCView);
     return;
   }
 
@@ -455,11 +339,15 @@ void Visual3d_View::UpdateLights()
   {
     MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
   }
-  MyGraphicDriver->SetLight (MyCView);
+  myGraphicDriver->SetLight (MyCView);
   delete[] MyCView.Context.ActiveLight;
   MyCView.Context.ActiveLight = NULL;
 }
 
+// =======================================================================
+// function : UpdatePlanes
+// purpose  :
+// =======================================================================
 void Visual3d_View::UpdatePlanes()
 {
   MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
@@ -468,114 +356,155 @@ void Visual3d_View::UpdatePlanes()
     return;
   }
 
-  MyGraphicDriver->SetClipPlanes (MyCView);
+  myGraphicDriver->SetClipPlanes (MyCView);
 }
 
-void Visual3d_View::SetBackground (const Aspect_Background& ABack) {
-
-        if (IsDeleted ()) return;
-
-        if (! IsDefined ())
-                Visual3d_ViewDefinitionError::Raise ("Window not defined");
-
-        // At this level, only GL can update the background.
-        // It is not necessary to call MyWindow->SetBackground (ABack); as
-        // this method starts update of window background by X
-        // (if the windowing is X)
+// =======================================================================
+// function : SetBackground
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetBackground (const Aspect_Background& theBack)
+{
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (!IsDefined())
+  {
+    Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-        Standard_Real R, G, B;
-        MyBackground    = ABack;
-        (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
-        MyCView.DefWindow.Background.r  = float (R);
-        MyCView.DefWindow.Background.g  = float (G);
-        MyCView.DefWindow.Background.b  = float (B);
+  // At this level, only GL can update the background.
+  // It is not necessary to call MyWindow->SetBackground (ABack); as
+  // this method starts update of window background by X
+  // (if the windowing is X)
 
-        MyGraphicDriver->Background (MyCView);
+  Standard_Real R, G, B;
+  MyBackground = theBack;
+  MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
+  MyCView.DefWindow.Background.r = float (R);
+  MyCView.DefWindow.Background.g = float (G);
+  MyCView.DefWindow.Background.b = float (B);
 
-        if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
-          Update ();
+  myGraphicDriver->Background (MyCView);
 
+  if (myViewManager != NULL)
+  {
+    Update (myViewManager->UpdateMode());
+  }
 }
 
-void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
+// =======================================================================
+// function : SetGradientBackground
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
+                                           const Standard_Boolean           theToUpdate)
 {
-
-  if (IsDeleted ()) return;
-
-  if (! IsDefined ())
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (!IsDefined())
+  {
     Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-  MyGradientBackground = ABack;
-  Quantity_Color aCol1,aCol2;
-  MyGradientBackground.Colors(aCol1,aCol2);
-  MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
+  MyGradientBackground = theBack;
+  Quantity_Color aCol1, aCol2;
+  MyGradientBackground.Colors (aCol1, aCol2);
+  myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
 
-  if ( update )
-     Update ();
-  else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
-    Update();
+  if (theToUpdate)
+  {
+     Update (Aspect_TOU_ASAP);
+  }
+  else if (myViewManager != NULL)
+  {
+    Update (myViewManager->UpdateMode());
+  }
 }
 
-void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
-                                        const Aspect_FillMethod FillStyle,
-                                        const Standard_Boolean update )
+// =======================================================================
+// function : SetBackgroundImage
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetBackgroundImage (const Standard_CString  theFileName,
+                                        const Aspect_FillMethod theFillStyle,
+                                        const Standard_Boolean  theToUpdate)
 {
-  if ( IsDeleted() )
+  if (IsDeleted())
+  {
     return;
-  if ( !IsDefined() )
+  }
+  if (!IsDefined())
+  {
     Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-  MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );
+  myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
 
-  if ( update )
-    Update();
-  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
-    Update();
+  Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
 }
 
-void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
-                                     const Standard_Boolean update )
+// =======================================================================
+// function : SetBgImageStyle
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
+                                     const Standard_Boolean  theToUpdate)
 {
-  if ( IsDeleted() )
+  if (IsDeleted())
+  {
     return;
-  if ( !IsDefined() )
+  }
+  if (!IsDefined())
+  {
     Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-  MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );
+  myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
 
-  if ( update )
-    Update();
-  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
-    Update();
+  Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
 }
 
-Aspect_Background Visual3d_View::Background () const {
-
-        return (MyBackground);
-
+// =======================================================================
+// function : Background
+// purpose  :
+// =======================================================================
+Aspect_Background Visual3d_View::Background() const
+{
+  return MyBackground;
 }
 
-void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
-                                        const Standard_Boolean update )
+// =======================================================================
+// function : SetBgGradientStyle
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
+                                        const Standard_Boolean          theToUpdate)
 {
-  if ( IsDeleted() )
+  if (IsDeleted())
+  {
     return;
-  if ( !IsDefined() )
+  }
+  else if (!IsDefined())
+  {
     Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-  MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );
-
-  if ( update )
-    Update();
-  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
-    Update();
+  myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
 
+  Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
 }
 
-Aspect_GradientBackground Visual3d_View::GradientBackground () const {
-
-        return MyGradientBackground;
-
+// =======================================================================
+// function : GradientBackground
+// purpose  :
+// =======================================================================
+Aspect_GradientBackground Visual3d_View::GradientBackground() const
+{
+  return MyGradientBackground;
 }
 
 // =======================================================================
@@ -591,7 +520,10 @@ const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
 // function : Camera
 // purpose  :
 // =======================================================================
-const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const{  return MyCView.Context.Camera;}
+const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
+{
+  return MyCView.Context.Camera;
+}
 
 // =======================================================================
 // function : SetCamera
@@ -601,19 +533,16 @@ void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
 {
   MyCView.Context.Camera = theCamera;
 
-  MyGraphicDriver->SetCamera (MyCView);
+  myGraphicDriver->SetCamera (MyCView);
 
-  if (MyViewManager->UpdateMode() == Aspect_TOU_ASAP)
-  {
-    Update();
-  }
+  Update (myViewManager->UpdateMode());
 }
 
 // =======================================================================
 // function : SetViewOrientationDefault
 // purpose  :
 // =======================================================================
-void Visual3d_View::SetViewOrientationDefault ()
+void Visual3d_View::SetViewOrientationDefault()
 {
   if (myDefaultCamera.IsNull())
   {
@@ -627,7 +556,7 @@ void Visual3d_View::SetViewOrientationDefault ()
 // function : ViewOrientationReset
 // purpose  :
 // =======================================================================
-void Visual3d_View::ViewOrientationReset ()
+void Visual3d_View::ViewOrientationReset()
 {
   if (IsDeleted())
   {
@@ -639,10 +568,7 @@ void Visual3d_View::ViewOrientationReset ()
     MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
   }
 
-  if (MyViewManager->UpdateMode() == Aspect_TOU_ASAP)
-  {
-    Update();
-  }
+  Update (myViewManager->UpdateMode());
 }
 
 // =======================================================================
@@ -662,9 +588,9 @@ void Visual3d_View::SetViewMappingDefault()
 // function : ViewMappingReset
 // purpose  :
 // =======================================================================
-void Visual3d_View::ViewMappingReset ()
+void Visual3d_View::ViewMappingReset()
 {
-  if (IsDeleted ())
+  if (IsDeleted())
   {
     return;
   }
@@ -674,1056 +600,1103 @@ void Visual3d_View::ViewMappingReset ()
     MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
   }
 
-  if (MyViewManager->UpdateMode() == Aspect_TOU_ASAP)
-  {
-    Update();
-  }
+  Update (myViewManager->UpdateMode());
 }
 
-void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {
-
-        if (IsDeleted ()) return;
+// =======================================================================
+// function : SetContext
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
+{
+  if (IsDeleted())
+  {
+    return;
+  }
 
-Visual3d_TypeOfVisualization OldVisualMode;
-Visual3d_TypeOfVisualization NewVisualMode;
+  // To manage display only in case of change of visualisation mode
+  const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
+  const bool isModelChanged   = theViewCtx.Model()         != MyContext.Model();
 
-        // To manage display only in case of
-        // change of visualisation mode.
-        OldVisualMode   = MyContext.Visualization ();
-        NewVisualMode   = CTX.Visualization ();
+  // To manage antialiasing only in case of change
+  const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
+  const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
 
-Visual3d_TypeOfModel OldModel;
-Visual3d_TypeOfModel NewModel;
+  // To manage the depth cueing only in case of change
+  const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
+  const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
 
-        // To manage change of visualisation only in case
-        // of change of mode of visualisation or of type of shading.
-        OldModel        = MyContext.Model ();
-        NewModel        = CTX.Model ();
+  const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
+  const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
+  const Standard_Real aDepthCueingBackPlaneOld  = MyContext.DepthCueingBackPlane();
+  const Standard_Real aDepthCueingBackPlaneNew  = theViewCtx.DepthCueingBackPlane();
 
-Standard_Boolean OldAliasingMode;
-Standard_Boolean NewAliasingMode;
+  // To manage the Zclipping only in case of change
+  const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
+  const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
+  const Standard_Boolean aBackZClippingModeOld  = MyContext.BackZClippingIsOn();
+  const Standard_Boolean aBackZClippingModeNew  = theViewCtx.BackZClippingIsOn();
 
-        // To manage antialiasing only in case of change.
-        OldAliasingMode = MyContext.AliasingIsOn ();
-        NewAliasingMode = CTX.AliasingIsOn ();
+  const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
+  const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
+  const Standard_Real aZClippingBackPlaneOld  = MyContext.ZClippingBackPlane();
+  const Standard_Real aZClippingBackPlaneNew  = theViewCtx.ZClippingBackPlane();
 
-Standard_Boolean OldDepthCueingMode;
-Standard_Boolean NewDepthCueingMode;
+  const bool isTextEnvChanged    = theViewCtx.TextureEnv()    != MyContext.TextureEnv();
+  const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
 
-Standard_Real OldDepthCueingFrontPlane;
-Standard_Real NewDepthCueingFrontPlane;
-Standard_Real OldDepthCueingBackPlane;
-Standard_Real NewDepthCueingBackPlane;
+  MyContext = theViewCtx;
 
-        // To manage the depth cueing only in case of change.
-        OldDepthCueingMode              = MyContext.DepthCueingIsOn ();
-        NewDepthCueingMode              = CTX.DepthCueingIsOn ();
+  UpdateView();
 
-        OldDepthCueingFrontPlane        = MyContext.DepthCueingFrontPlane ();
-        NewDepthCueingFrontPlane        = CTX.DepthCueingFrontPlane ();
-        OldDepthCueingBackPlane         = MyContext.DepthCueingBackPlane ();
-        NewDepthCueingBackPlane         = CTX.DepthCueingBackPlane ();
+  Standard_Boolean toWait = Standard_False; // => immediate update
+  if (IsDefined())
+  {
+    // management of visualization modes and types of shading.
+    if (isVisModeChanged
+     || isModelChanged)
+    {
+      myGraphicDriver->SetVisualisation (MyCView);
+    }
 
-Standard_Boolean OldFrontZClippingMode;
-Standard_Boolean NewFrontZClippingMode;
-Standard_Boolean OldBackZClippingMode;
-Standard_Boolean NewBackZClippingMode;
+    // management of antialiasing
+    if (anAliasingModeOld != anAliasingModeNew)
+    {
+      myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
+    }
 
-Standard_Real OldZClippingFrontPlane;
-Standard_Real NewZClippingFrontPlane;
-Standard_Real OldZClippingBackPlane;
-Standard_Real NewZClippingBackPlane;
+    // management of depth_cueing
+    if (aDepthCueingModeOld       != aDepthCueingModeNew
+     || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
+     || aDepthCueingBackPlaneOld  != aDepthCueingBackPlaneNew)
+    {
+      if (aDepthCueingModeNew
+      &&  aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
+      {
+        Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
+      }
+      myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
+    }
 
-        // To manage the Zclipping only in case of change.
-        OldFrontZClippingMode   = MyContext.FrontZClippingIsOn ();
-        NewFrontZClippingMode   = CTX.FrontZClippingIsOn ();
-        OldBackZClippingMode    = MyContext.BackZClippingIsOn ();
-        NewBackZClippingMode    = CTX.BackZClippingIsOn ();
+    // management of Zclipping
+    if (aFrontZClippingModeOld  != aFrontZClippingModeNew
+     || aBackZClippingModeOld   != aBackZClippingModeNew
+     || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
+     || aZClippingBackPlaneOld  != aZClippingBackPlaneNew)
+    {
+      if (aBackZClippingModeNew
+       && aFrontZClippingModeNew
+       && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
+      {
+        Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
+      }
 
-        OldZClippingFrontPlane  = MyContext.ZClippingFrontPlane ();
-        NewZClippingFrontPlane  = CTX.ZClippingFrontPlane ();
-        OldZClippingBackPlane   = MyContext.ZClippingBackPlane ();
-        NewZClippingBackPlane   = CTX.ZClippingBackPlane ();
+      myGraphicDriver->ClipLimit (MyCView, toWait);
+    }
 
-        Handle(Graphic3d_TextureEnv) aTexEnvOld = MyContext.TextureEnv();
-        Handle(Graphic3d_TextureEnv) aTexEnvNew = CTX.TextureEnv();
+    // management of textures
+    if (isTextEnvChanged
+     || isSurfDetailChanged)
+    {
+      myGraphicDriver->Environment (MyCView);
+    }
 
-        Visual3d_TypeOfSurfaceDetail OldSurfaceDetail = MyContext.SurfaceDetail();
-        Visual3d_TypeOfSurfaceDetail NewSurfaceDetail = CTX.SurfaceDetail();
+    UpdatePlanes(); // Update of planes of model clipping
+    UpdateLights(); // Update of light sources
+  }
 
-        MyContext       = CTX;
+  if (isVisModeChanged)
+  {
+    // Change of context =>
+    // Remove structures that cannot be displayed in the new visualisation mode.
+    // It is not necessary to warn ViewManager as this structure should not disappear from
+    // the list of structures displayed in it.
+    NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
+    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
+    {
+      const Handle(Graphic3d_Structure)& aStruct  = aStructIter.Key();
+      const Visual3d_TypeOfAnswer        anAnswer = AcceptDisplay (aStruct);
+      if (anAnswer == Visual3d_TOA_NO
+       || anAnswer == Visual3d_TOA_COMPUTE)
+      {
+        aStructs.Append (aStruct);
+      }
+    }
+    for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
+    {
+      Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
+    }
+    aStructs.Clear();
+
+    // Change of context =>
+    // Display structures that can be displayed with the new visualisation mode.
+    // All structures with status Displayed are removed from the ViewManager
+    // and displayed in the view directly, if the structure is not already
+    // displayed and if the view accepts it in its context.
+    Graphic3d_MapOfStructure aMapDisplayed;
+    myViewManager->DisplayedStructures (aMapDisplayed);
+    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
+    {
+      const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+      if (IsDisplayed (aStruct))
+      {
+        continue;
+      }
 
-        UpdateView ();
+      const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
+      if (anAnswer == Visual3d_TOA_YES
+       || anAnswer == Visual3d_TOA_COMPUTE)
+      {
+        aStructs.Append (aStruct);
+      }
+    }
 
-Standard_Boolean AWait = Standard_False;        // => immediate update
-        if (IsDefined ()) {
-                // management of visualization modes and types of shading.
-                if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
-                        MyGraphicDriver->SetVisualisation (MyCView);
+    for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
+    {
+      Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
+    }
+  }
 
-                // management of antialiasing.
-                if (OldAliasingMode != NewAliasingMode)
-                MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);
-
-                // management of depth_cueing.
-                if ((OldDepthCueingMode != NewDepthCueingMode) ||
-                    (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
-                    (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
-#ifdef BUC60572
-                    if( NewDepthCueingMode &&
-                        (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
-                        Visual3d_DepthCueingDefinitionError::Raise
-                        ("Bad value for DepthCueingPlanes position");
-#endif
-                        MyGraphicDriver->DepthCueing
-                                (MyCView, NewDepthCueingMode);
-                }
-
-                // management of Zclipping
-                if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
-                    (OldBackZClippingMode != NewBackZClippingMode) ||
-                    (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
-                    (OldZClippingBackPlane != NewZClippingBackPlane)) {
-#ifdef BUC60572
-                    if( NewBackZClippingMode && NewFrontZClippingMode &&
-                        (NewZClippingBackPlane >= NewZClippingFrontPlane) )
-                        Visual3d_ZClippingDefinitionError::Raise
-                        ("Bad value for ZClippingPlanes position");
-#endif
-                        MyGraphicDriver->ClipLimit (MyCView, AWait);
-                }
-
-                // management of textures
-                if ((aTexEnvOld != aTexEnvNew) || (OldSurfaceDetail != NewSurfaceDetail))
-                {
-                  MyGraphicDriver->Environment(MyCView);
-                }
-
-                // Update of planes of model clipping
-                UpdatePlanes ();
-
-                // Update of light sources
-                UpdateLights ();
-        }
-
-        if (OldVisualMode != NewVisualMode) {
-
-                /*
-                 * Change of context =>
-                 * Remove structures that cannot be displayed
-                 * in the new visualisation mode.
-                 * It is not necessary to warn ViewManager as
-                 * this structure should not disappear from
-                 * the list of structures displayed in it.
-                 */
-Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
-Visual3d_TypeOfAnswer Answer;
-
-                Standard_Integer i      = MyDisplayedStructure.Extent ();
-
-Graphic3d_SequenceOfStructure FooSequence;
-
-                while (S1Iterator.More ()) {
-                        Answer  = AcceptDisplay (S1Iterator.Key ());
-                        // If the structure can't be displayed in the
-                        // new context of the view, it is removed.
-                        if ((Answer == Visual3d_TOA_NO) ||
-                            (Answer == Visual3d_TOA_COMPUTE))
-                                //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
-                                FooSequence.Append (S1Iterator.Key ());
-
-                        // S1Iterator.Next () is located on the next structure
-                        S1Iterator.Next ();
-                }
-
-Standard_Integer Length = FooSequence.Length ();
-                // The stored structures are removed
-                for (i=1; i<=Length; i++)
-                        Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
-                if (Length != 0) FooSequence.Clear ();
-
-                /*
-                 * Change of context =>
-                 * Display structures that can be displayed
-                 * with the new visualisation mode.
-                 * All structures with status Displayed are removed from the ViewManager
-                 * and displayed in the view directly, if the structure is not already
-                 * displayed and if the view accepts it in its context.
-                 */
-
-                i       = MyViewManager->NumberOfDisplayedStructures ();
-                Graphic3d_MapOfStructure Map;
-                MyViewManager->DisplayedStructures(Map);
-                Graphic3d_MapIteratorOfMapOfStructure it(Map);
-
-                for (; it.More(); it.Next()) {
-                  Handle(Graphic3d_Structure) SG = it.Key();
-                    if (! IsDisplayed (SG)) {
-                      Answer = AcceptDisplay(SG);
-                        // If the structure can be displayed in the
-                        // new context of the view, it is displayed.
-                        if ((Answer == Visual3d_TOA_YES) ||
-                            (Answer == Visual3d_TOA_COMPUTE))
-                            //Display (MyViewManager->DisplayedStructure (j),
-                                //Aspect_TOU_WAIT);
-                        FooSequence.Append (SG);
-                    }
-                }
-
-                Length  = FooSequence.Length ();
-                // The stored structures are displayed
-                for (i=1; i<=Length; i++)
-                        Display (FooSequence.Value (i), Aspect_TOU_WAIT);
-                if (Length != 0) FooSequence.Clear ();
-        }
-
-        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
+  Update (myViewManager->UpdateMode());
+}
 
+// =======================================================================
+// function : Context
+// purpose  :
+// =======================================================================
+const Visual3d_ContextView& Visual3d_View::Context() const
+{
+  return MyContext;
 }
 
-const Visual3d_ContextView& Visual3d_View::Context () const {
-
-        return (MyContext);
+// =======================================================================
+// function : DisplayedStructures
+// purpose  :
+// =======================================================================
+void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
+{
+  if (IsDeleted())
+  {
+    return;
+  }
 
+  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
+  {
+    theStructures.Add (aStructIter.Key());
+  }
 }
 
-void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
+// =======================================================================
+// function : Activate
+// purpose  :
+// =======================================================================
+void Visual3d_View::Activate()
 {
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (!IsDefined())
+  {
+    Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-  if (IsDeleted ()) return;
-
-  Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
+  if (!IsActive())
+  {
+    myGraphicDriver->ActivateView (MyCView);
+    myGraphicDriver->Background   (MyCView);
+    myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
+
+    MyCView.Active = 1;
+
+    // Activation of a new view =>
+    // Display structures that can be displayed in this new view.
+    // All structures with status
+    // Displayed in ViewManager are returned and displayed in
+    // the view directly, if the structure is not already
+    // displayed and if the view accepts it in its context.
+    Graphic3d_MapOfStructure aDisplayedStructs;
+    myViewManager->DisplayedStructures (aDisplayedStructs);
+    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
+    {
+      const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+      if (IsDisplayed (aStruct))
+      {
+        continue;
+      }
 
-  while (Iterator.More ()) {
-    SG.Add (Iterator.Key ());
+      // If the structure can be displayed in the new context of the view, it is displayed.
+      const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
+      if (anAnswer == Visual3d_TOA_YES
+       || anAnswer == Visual3d_TOA_COMPUTE)
+      {
+        Display (aStruct, Aspect_TOU_WAIT);
+      }
+    }
+  }
 
-    // Iterator.Next () is located on the next structure
-    Iterator.Next ();
+  // If the activation/desactivation of ZBuffer should be automatic
+  // depending on the presence or absence of facets.
+  if (myViewManager->ZBufferAuto())
+  {
+    const Standard_Boolean containsFacet = ContainsFacet();
+    const Standard_Boolean hasZBuffer    = ZBufferIsActivated();
+    if (containsFacet && !hasZBuffer)
+    {
+      SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
+    }
+    else if (!containsFacet && hasZBuffer)
+    {
+      SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
+    }
   }
 
+  Update (myViewManager->UpdateMode());
 }
 
-void Visual3d_View::Activate () {
-
-        if (IsDeleted ()) return;
-
-        if (! IsDefined ())
-                Visual3d_ViewDefinitionError::Raise ("Window not defined");
-
-        if (! IsActive ()) {
-
-                MyGraphicDriver->ActivateView (MyCView);
-                MyGraphicDriver->Background (MyCView);
-                MyGraphicDriver->Transparency
-                        (MyCView, MyViewManager->Transparency ());
-
-                MyCView.Active  = 1;
-
-                /*
-                 * Activation of a new view =>
-                 * Display structures that can be displayed in this new view.
-                 * All structures with status
-                 * Displayed in ViewManager are returned and displayed in
-                 * the view directly, if the structure is not already
-                 * displayed and if the view accepts it in its context.
-                 */
-
-               Visual3d_TypeOfAnswer Answer;
-                Graphic3d_MapOfStructure Map;
-                MyViewManager->DisplayedStructures(Map);
-                Graphic3d_MapIteratorOfMapOfStructure it(Map);
-
-                for (; it.More(); it.Next()) {
-                  Handle(Graphic3d_Structure) SG = it.Key();
-                    if (! IsDisplayed (SG)) {
-                      Answer    = AcceptDisplay(SG);
-                        // If the structure can be displayed in the
-                        // new context of the view, it is displayed.
-                        if ((Answer == Visual3d_TOA_YES) ||
-                            (Answer == Visual3d_TOA_COMPUTE))
-                        Display (SG,Aspect_TOU_WAIT);
-                    }
-                }
-
-        }
-
-        // If the activation/desactivation of ZBuffer should be automatic
-        // depending on the presence or absence of facets.
-        if (MyViewManager->ZBufferAuto ()) {
-Standard_Boolean BContainsFacet = ContainsFacet ();
-Standard_Boolean BZBuffer       = ZBufferIsActivated ();
-                // If the view contains facets
-                // and if ZBuffer is not active
-                if (BContainsFacet && ! BZBuffer)
-                        SetZBufferActivity (1);
-                // If the view does not contain facets
-                // and if ZBuffer is active
-                if (! BContainsFacet && BZBuffer)
-                        SetZBufferActivity (0);
-        }
-
-        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
-
+// =======================================================================
+// function : IsActive
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::IsActive() const
+{
+  return !IsDeleted()
+      &&  MyCView.Active;
 }
 
-Standard_Boolean Visual3d_View::IsActive () const {
+// =======================================================================
+// function : Deactivate
+// purpose  :
+// =======================================================================
+void Visual3d_View::Deactivate()
+{
+  if (IsDeleted())
+  {
+    return;
+  }
+  else if (!IsDefined())
+  {
+    Visual3d_ViewDefinitionError::Raise ("Window not defined");
+  }
 
-        if (IsDeleted ()) return (Standard_False);
+  if (IsActive())
+  {
+    myGraphicDriver->DeactivateView (MyCView);
+
+    // Deactivation of a view =>
+    // Removal of structures displayed in this view.
+    // All structures with status
+    // Displayed in ViewManager are returned and removed from
+    // the view directly, if the structure is not already
+    // displayed and if the view accepts it in its context.
+    Graphic3d_MapOfStructure aDisplayedStructs;
+    myViewManager->DisplayedStructures (aDisplayedStructs);
+    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
+    {
+      const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+      if (IsDisplayed (aStruct))
+      {
+        continue;
+      }
 
-        if (MyCView.Active)
-                return (Standard_True);
-        else
-                return (Standard_False);
+      const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
+      if (anAnswer == Visual3d_TOA_YES
+       || anAnswer == Visual3d_TOA_COMPUTE)
+      {
+        Erase (aStruct, Aspect_TOU_WAIT);
+      }
+    }
 
+    Update (myViewManager->UpdateMode());
+    MyCView.Active = 0; // No action currently possible in the view
+  }
 }
 
-void Visual3d_View::Deactivate () {
-
-        if (IsDeleted ()) return;
-
-        if (! IsDefined ())
-                Visual3d_ViewDefinitionError::Raise ("Window not defined");
-
-        if (IsActive ()) {
-
-                MyGraphicDriver->DeactivateView (MyCView);
-
-                /*
-                 * Deactivation of a view =>
-                 * Removal of structures displayed in this view.
-                 * All structures with status
-                 * Displayed in ViewManager are returned and removed from
-                 * the view directly, if the structure is not already
-                 * displayed and if the view accepts it in its context.
-                */
-
-               Visual3d_TypeOfAnswer Answer;
-                Graphic3d_MapOfStructure Map;
-                MyViewManager->DisplayedStructures(Map);
-                Graphic3d_MapIteratorOfMapOfStructure it(Map);
-
-                for (; it.More(); it.Next()) {
-                  Handle(Graphic3d_Structure) SG = it.Key();
-                    if (! IsDisplayed (SG)) {
-                        Answer  = AcceptDisplay(SG);
-                        // If the structure was displayed it is removed.
-                        if ((Answer == Visual3d_TOA_YES) ||
-                            (Answer == Visual3d_TOA_COMPUTE))
-                                Erase (SG,Aspect_TOU_WAIT);
-                    }
-                }
-
-                if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
-
-                // No action currently possible in the view
-                MyCView.Active  = 0;
-        }
-
+// =======================================================================
+// function : Redraw
+// purpose  :
+// =======================================================================
+void Visual3d_View::Redraw()
+{
+  Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
 }
 
-void Visual3d_View::Redraw () {
-
-        Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
-
+// =======================================================================
+// function : Redraw
+// purpose  :
+// =======================================================================
+void Visual3d_View::Redraw (const Standard_Integer theX,
+                            const Standard_Integer theY,
+                            const Standard_Integer theWidth,
+                            const Standard_Integer theHeight)
+{
+  Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
+          theX, theY, theWidth, theHeight);
 }
 
-void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
-
-        Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
+// =======================================================================
+// function : Redraw
+// purpose  :
+// =======================================================================
+void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
+                            const Handle(Visual3d_Layer)& theOverLayer)
+{
+  Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
 }
 
-void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
-
-        if (IsDeleted ()) return;
+// =======================================================================
+// function : Redraw
+// purpose  :
+// =======================================================================
+void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
+                            const Handle(Visual3d_Layer)& theOverLayer,
+                            const Standard_Integer        theX,
+                            const Standard_Integer        theY,
+                            const Standard_Integer        theWidth,
+                            const Standard_Integer        theHeight)
+{
+  if (IsDeleted()
+   || !IsDefined()
+   || !IsActive()
+   || !MyWindow->IsMapped())
+  {
+    return;
+  }
 
-        if ((! IsDefined ()) || (! IsActive ())) return;
+  Aspect_CLayer2d anOverCLayer, anUnderCLayer;
+  anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
+  if (!theOverLayer .IsNull()) anOverCLayer  = theOverLayer ->CLayer();
+  if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
 
-        if (! MyWindow->IsMapped ()) return;
+  for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
+  {
+    if (myGraphicDriver->IsDeviceLost())
+    {
+      myViewManager->RecomputeStructures();
+      myViewManager->RecomputeStructures (myImmediateStructures);
+      myGraphicDriver->ResetDeviceLostFlag();
+    }
 
-        // san - 14/04/2004 - set up Z buffer state before redrawing
-       // If the activation/desactivation of ZBuffer should be automatic
-        // depending on the presence or absence of facets.
-        if (MyViewManager->ZBufferAuto ()) {
-                Standard_Boolean BContainsFacet = ContainsFacet ();
-                Standard_Boolean BZBuffer       = ZBufferIsActivated ();
-                // If the view contains facets
-                // and if ZBuffer is not active
-                if (BContainsFacet && ! BZBuffer)
-                        SetZBufferActivity (1);
-                // If the view contains only facets
-                // and if ZBuffer is active
-                if (! BContainsFacet && BZBuffer)
-                        SetZBufferActivity (0);
-        }
+    // set up Z buffer state before redrawing
+    if (myViewManager->ZBufferAuto())
+    {
+      const Standard_Boolean hasFacet   = ContainsFacet();
+      const Standard_Boolean hasZBuffer = ZBufferIsActivated();
+      // if the view contains facets and if ZBuffer is not active
+      if (hasFacet && !hasZBuffer)
+      {
+        SetZBufferActivity (1);
+      }
+      // if the view contains only facets and if ZBuffer is active
+      if (!hasFacet && hasZBuffer)
+      {
+        SetZBufferActivity (0);
+      }
+    }
 
-        Aspect_CLayer2d OverCLayer;
-        Aspect_CLayer2d UnderCLayer;
-        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
-        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
-        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
-        MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);
+    if (myStructuresUpdated)
+    {
+      AutoZFit();
+      myStructuresUpdated = Standard_False;
+    }
 
+    myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
+    if (!myGraphicDriver->IsDeviceLost())
+    {
+      return;
+    }
+  }
 }
 
-void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {
-
-        if (IsDeleted ()) return;
-
-        if ((! IsDefined ()) || (! IsActive ())) return;
-
-        if (! MyWindow->IsMapped ()) return;
-
-        // san - 14/04/2004 - set up Z buffer state before redrawing
-          // If activation/desactivation of ZBuffer should be automatic
-        // depending on the presence or absence of facets.
-        if (MyViewManager->ZBufferAuto ()) {
-        Standard_Boolean BContainsFacet = ContainsFacet ();
-        Standard_Boolean BZBuffer       = ZBufferIsActivated ();
-                // If the view contains facets
-                // and if ZBuffer is not active
-                if (BContainsFacet && ! BZBuffer)
-                        SetZBufferActivity (1);
-                // If the view contains only facets
-                // and if ZBuffer is active
-                if (! BContainsFacet && BZBuffer)
-                        SetZBufferActivity (0);
-        }
-
-        Aspect_CLayer2d OverCLayer;
-        Aspect_CLayer2d UnderCLayer;
-        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
-        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
-        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
-        MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);
-
+// =======================================================================
+// function : RedrawImmediate
+// purpose  :
+// =======================================================================
+void Visual3d_View::RedrawImmediate()
+{
+  RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
 }
 
-void Visual3d_View::Update () 
+// =======================================================================
+// function : RedrawImmediate
+// purpose  :
+// =======================================================================
+void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
+                                     const Handle(Visual3d_Layer)& theOverLayer)
 {
-  IsInitialized = Standard_True;
-
-  Compute ();
+  if (IsDeleted()
+   || !IsDefined()
+   || !IsActive()
+   || !MyWindow->IsMapped())
+  {
+    return;
+  }
 
-  Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());
+  Aspect_CLayer2d anOverCLayer, anUnderCLayer;
+  anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
+  if (!theOverLayer .IsNull()) anOverCLayer  = theOverLayer ->CLayer();
+  if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
+  myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
 }
 
-void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {
-
-        if (IsDeleted ()) return;
-
-        if ((! IsDefined ()) || (! IsActive ())) return;
-
-        if (! MyWindow->IsMapped ()) return;
-
-        if (MyGraphicDriver->IsDeviceLost())
-        {
-          MyViewManager->RecomputeStructures();
-          MyGraphicDriver->ResetDeviceLostFlag();
-        }
-
-        // If activation/desactivation of ZBuffer should be automatic
-        // depending on the presence or absence of facets.
-        if (MyViewManager->ZBufferAuto ()) {
-Standard_Boolean BContainsFacet = ContainsFacet ();
-Standard_Boolean BZBuffer       = ZBufferIsActivated ();
-                // If the view contains facets
-                // and if ZBuffer is not active
-                        if (BContainsFacet && ! BZBuffer)
-                        SetZBufferActivity (1);
-                   // If the view does not contain facets
-                // and if ZBuffer is active
-                if (! BContainsFacet && BZBuffer)
-                        SetZBufferActivity (0);
-        }
-
-Aspect_CLayer2d OverCLayer;
-Aspect_CLayer2d UnderCLayer;
-        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
-        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
-        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
-        //OSD::SetSignal (Standard_False);
-        MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
-        //OSD::SetSignal (Standard_True);
-
-}
-
-Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {
-
-// Return type of visualization of the view
-Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
-
-// Return type of visualization of the structure
-Graphic3d_TypeOfStructure StructType = AStructure->Visual ();
-
-Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;
-
-        if (StructType == Graphic3d_TOS_ALL)
-                // The structure accepts any type of view
-                Result  = Visual3d_TOA_YES;
-        else {
-                if ((StructType == Graphic3d_TOS_SHADING)
-                        && (ViewType == Visual3d_TOV_SHADING))
-                        Result  = Visual3d_TOA_YES;
-                if ((StructType == Graphic3d_TOS_WIREFRAME)
-                        && (ViewType == Visual3d_TOV_WIREFRAME))
-                        Result  = Visual3d_TOA_YES;
-                if ((StructType == Graphic3d_TOS_COMPUTED)
-                        && (ViewType == Visual3d_TOV_WIREFRAME))
-                        Result  = Visual3d_TOA_COMPUTE;
-                if ((StructType == Graphic3d_TOS_COMPUTED)
-                        && (ViewType == Visual3d_TOV_SHADING))
-                        Result  = Visual3d_TOA_COMPUTE;
-        }
-
-#ifdef TRACE_ACCEPT
-        if (Result == Visual3d_TOA_YES)
-        cout << "YES = Visual3d_View" << MyCView.ViewId
-             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
-        if (Result == Visual3d_TOA_NO)
-        cout << "NO = Visual3d_View" << MyCView.ViewId
-             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
-        if (Result == Visual3d_TOA_COMPUTE)
-        cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
-             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
-        cout << flush;
-#endif
-
-        return (Result);
-
+// =======================================================================
+// function : Invalidate
+// purpose  :
+// =======================================================================
+void Visual3d_View::Invalidate()
+{
+  myGraphicDriver->Invalidate (MyCView);
 }
 
-void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer /*OldPriority*/, const Standard_Integer NewPriority) {
-
-        if (IsDeleted ()) return;
-        if (! IsDefined ()) return;
-        if (! IsActive ()) return;
-        if (! IsDisplayed (AStructure)) return;
-
-Standard_Integer Index = IsComputed (AStructure);
-        if (Index != 0 && ComputedMode())
-        {
-#ifdef TRACE
-       Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
-        cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
-             << AStructure->Identification () << "/" << StructId
-             << ", " << OldPriority << ", " << NewPriority << ")\n";
-        cout << flush;
-#endif
-                MyGraphicDriver->EraseStructure   (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()));
-                MyGraphicDriver->DisplayStructure (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()), NewPriority);
-        }
-        else
-        {
-#ifdef TRACE
-        Standard_Integer StructId = AStructure->Identification ();
-        cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
-             << AStructure->Identification () << "/" << StructId
-             << ", " << OldPriority << ", " << NewPriority << ")\n";
-        cout << flush;
-#endif
-                MyGraphicDriver->EraseStructure   (MyCView, *(AStructure->CStructure()));
-                MyGraphicDriver->DisplayStructure (MyCView, *(AStructure->CStructure()), NewPriority);
-        }
-
+// =======================================================================
+// function : Update
+// purpose  :
+// =======================================================================
+void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
+{
+  myStructuresUpdated = Standard_True;
+  if (theUpdateMode == Aspect_TOU_ASAP)
+  {
+    Compute();
+    Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
+  }
 }
 
-void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
-
-#ifdef TRACE_CLEAR
-        cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
-             << AStructure->Identification () << ")\n";
-        cout << flush;
-#endif
-
-Standard_Integer Index = IsComputed (AStructure);
-        if (Index != 0) {
-#ifdef TRACE_CLEAR
-        cout << "Structure " << AStructure->Identification ()
-             << " calculated in the view "
-             << Identification () << ", by structure "
-             << MyCOMPUTEDSequence.Value (Index)->Identification ()
-             << " is emptied.\n";
-        cout << flush;
-#endif
-                MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
-                MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
-        }
-
+// =======================================================================
+// function : Update
+// purpose  :
+// =======================================================================
+void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
+                            const Handle(Visual3d_Layer)& theOverLayer)
+{
+  Compute();
+  myStructuresUpdated = Standard_True;
+  Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
 }
 
-void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
-
-#ifdef TRACE_CONNECT
-        cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
-             << AMother->Identification ()
-             << ADaughter->Identification () << ")\n";
-        cout << flush;
-#endif
-
-Standard_Integer IndexM = IsComputed (AMother);
-Standard_Integer IndexD = IsComputed (ADaughter);
-
-        if (IndexM != 0 && IndexD != 0) {
-#ifdef TRACE_CONNECT
-        cout << "Structure " << AMother->Identification ()
-             << " is connected to structure "
-             << ADaughter->Identification () << endl;
-        cout << "These structures are calculated.\n";
-        cout << "In the view " << Identification ()
-             << "Structure "
-             << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
-             << " is connected to the structure "
-             << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
-             << endl;
-#endif
-                MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
-        }
-
+// ========================================================================
+// function : SetAutoZFitMode
+// purpose  :
+// ========================================================================
+void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
+                                     const Standard_Real    theScaleFactor)
+{
+  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+  myAutoZFitScaleFactor = theScaleFactor;
+  myAutoZFitIsOn = theIsOn;
 }
 
-void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
-
-#ifdef TRACE_CONNECT
-        cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
-             << AMother->Identification ()
-             << ADaughter->Identification () << ")\n";
-        cout << flush;
-#endif
-
-Standard_Integer IndexM = IsComputed (AMother);
-Standard_Integer IndexD = IsComputed (ADaughter);
-
-        if (IndexM != 0 && IndexD != 0) {
-#ifdef TRACE_CONNECT
-        cout << "Structure " << AMother->Identification ()
-             << " is disconnected from the structure "
-             << ADaughter->Identification () << endl;
-        cout << "These structures are calculated.\n";
-        cout << "In the view " << Identification ()
-             << "Structure "
-             << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
-             << " is disconnected from the structure "
-             << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
-             << endl;
-#endif
-                MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
-        }
-
+// ========================================================================
+// function : AutoZFitMode
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::AutoZFitMode() const
+{
+  return myAutoZFitIsOn;
 }
 
-void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure) {
-
-        Display (AStructure, MyViewManager->UpdateMode ());
-
+// ========================================================================
+// function : AutoZFitScaleFactor
+// purpose  :
+// ========================================================================
+Standard_Real Visual3d_View::AutoZFitScaleFactor() const
+{
+  return myAutoZFitScaleFactor;
 }
 
-void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
-
-        if (IsDeleted ()) return;
-        if (! IsDefined ()) return;
-        if (! IsActive ()) return;
-
-        // If Display on a structure present in the list
-        // of calculated structures while it is not
-        // or more, of calculated type =>
-        // - removes it as well as the associated old computed
-        // THis happens when hlhsr becomes again of type e
-        // non computed after SetVisual.
-Standard_Integer Index = IsComputed (AStructure);
-
-        if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {
-                MyTOCOMPUTESequence.Remove (Index);
-                MyCOMPUTEDSequence.Remove (Index);
-                Index = 0;
-        }
-
-       Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
-
-        if (Answer == Visual3d_TOA_NO) {
-                return;
-        }
-
-        if (!ComputedMode())
-        {
-          Answer = Visual3d_TOA_YES;
-        }
-
-        if (Answer == Visual3d_TOA_YES ) {
-                if (IsDisplayed (AStructure)) return;
-                MyGraphicDriver->DisplayStructure (MyCView, *(AStructure->CStructure()), AStructure->DisplayPriority());
-                MyDisplayedStructure.Add (AStructure);
-                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
-        }
-
-        if (Answer == Visual3d_TOA_COMPUTE) {
-            if (Index != 0) {
-                // Already computed, is COMPUTED still valid?
-Standard_Integer OldStructId =
-        MyCOMPUTEDSequence.Value (Index)->Identification ();
-
-                // Case COMPUTED valide
-                if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
-                    // to be displayed
-                    if (! IsDisplayed (AStructure)) {
-                        MyDisplayedStructure.Add (AStructure);
-                        MyGraphicDriver->DisplayStructure (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()), AStructure->DisplayPriority ());
-                        if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
-                    }
-                    return;
-                }
-
-                // Case COMPUTED invalid
-                else {
-                    // Is there another valid representation ?
-                    // Find in the sequence of already calculated structures
-                    // 1/ Structure having the same Owner as <AStructure>
-                    // 2/ That is not <AStructure>
-                    // 3/ The COMPUTED which of is valid
-                    Standard_Integer NewIndex = HaveTheSameOwner (AStructure);
-
-                    // Case of COMPUTED invalid, WITH a valid of replacement
-                    if (NewIndex != 0) {
-                        // to be displayed
-                        if (! IsDisplayed (AStructure)) {
-                            MyCOMPUTEDSequence.SetValue
-                                (Index, MyCOMPUTEDSequence.Value (NewIndex));
-                            OldStructId = MyCOMPUTEDSequence.Value (NewIndex)->
-                                                        Identification ();
-                            MyDisplayedStructure.Add (AStructure);
-                            MyGraphicDriver->DisplayStructure (MyCView, *(MyCOMPUTEDSequence.Value (NewIndex)->CStructure()), AStructure->DisplayPriority ());
-                            if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
-                        }
-                        return;
-                    }
-
-                    // Cas COMPUTED invalid, WITHOUT a valid of replacement
-                    else {
-                        // COMPUTED is removed if displayed
-                        if (IsDisplayed (AStructure))
-                            MyGraphicDriver->EraseStructure (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()));
-                    }
-                }
-            } // if (Index != 0)
-
-            // Compute + Validation
-#ifdef OLD
-Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
-#else
-Handle(Graphic3d_Structure) TheStructure;
-TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
-            AStructure->Transform (ATrsf);
-            if (Index != 0) {
-TColStd_Array2OfReal Ident (0, 3, 0, 3);
-Standard_Integer ii, jj;
-        for (ii=0; ii<=3; ii++)
-            for (jj=0; jj<=3; jj++)
-                Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
-                TheStructure = MyCOMPUTEDSequence.Value (Index);
-                TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
-                if (AStructure->IsTransformed ()) {
-                    AStructure->Compute (this, ATrsf, TheStructure);
-                }
-                else {
-                    AStructure->Compute (this, TheStructure);
-                }
-            }
-            else {
-                if (AStructure->IsTransformed ()) {
-                    TheStructure = AStructure->Compute (this, ATrsf);
-                }
-                else {
-                    TheStructure = AStructure->Compute (this);
-                }
-            }
-#endif
-            TheStructure->SetHLRValidation (Standard_True);
-
-            // TOCOMPUTE and COMPUTED associated to sequences are added
-            MyTOCOMPUTESequence.Append (AStructure);
-            MyCOMPUTEDSequence.Append (TheStructure);
-
-            // The previous are removed if necessary
-            if (Index != 0) {
-                MyTOCOMPUTESequence.Remove (Index);
-                MyCOMPUTEDSequence.Remove (Index);
-            }
+// ========================================================================
+// function : AutoZFit
+// purpose  :
+// ========================================================================
+void Visual3d_View::AutoZFit()
+{
+  if (!AutoZFitMode())
+  {
+    return;
+  }
 
-// Return type of visualisation of the view
-Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
+  ZFitAll (myAutoZFitScaleFactor);
+}
 
-// Of which type will be the computed ?
-Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
-                (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
+// ========================================================================
+// function : ZFitAll
+// purpose  :
+// ========================================================================
+void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
+{
+  Standard_Real aMinMax[6];    // applicative min max boundaries
+  MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
+    aMinMax[3], aMinMax[4], aMinMax[5],
+    Standard_False);
 
-Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
-                (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
+  Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
+  MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
+    aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
+    Standard_True);
 
-            if (ComputeWireframe)
-                TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
-            if (ComputeShading)
-                TheStructure->SetVisual (Graphic3d_TOS_SHADING);
+  Bnd_Box aMinMaxBox;
+  Bnd_Box aGraphicBox;
 
-            if (! ComputeShading && ! ComputeWireframe)
-                Answer = Visual3d_TOA_NO;
-            else
-                Answer = AcceptDisplay (TheStructure);
+  aMinMaxBox.Update (aMinMax[0], aMinMax[1], aMinMax[2],
+    aMinMax[3], aMinMax[4], aMinMax[5]);
 
-            if (AStructure->IsHighlighted()) {
-                TheStructure->SetHighlightColor (AStructure->HighlightColor ());
-                TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
-            }
+  aGraphicBox.Update (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
+    aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]);
 
-            // It is displayed only if the calculated structure
-            // has a proper type corresponding to the one of the view.
-            if (Answer != Visual3d_TOA_NO) {
-                if (! IsDisplayed (AStructure))
-                        MyDisplayedStructure.Add (AStructure);
-                MyGraphicDriver->DisplayStructure (MyCView, *(TheStructure->CStructure()), AStructure->DisplayPriority ());
-                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
-            }
-        } // Visual3d_TOA_COMPUTE
+  const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
+  aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
 }
 
-void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure) {
-
-        if (IsDeleted ()) return;
-
-        Erase (AStructure, MyViewManager->UpdateMode ());
-
+// ========================================================================
+// function : AcceptDisplay
+// purpose  :
+// ========================================================================
+Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
+{
+  const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
+  switch (theStruct->Visual())
+  {
+    case Graphic3d_TOS_ALL:
+    {
+      return Visual3d_TOA_YES; // The structure accepts any type of view
+    }
+    case Graphic3d_TOS_SHADING:
+    {
+      return ViewType == Visual3d_TOV_SHADING
+           ? Visual3d_TOA_YES
+           : Visual3d_TOA_NO;
+    }
+    case Graphic3d_TOS_WIREFRAME:
+    {
+      return ViewType == Visual3d_TOV_WIREFRAME
+           ? Visual3d_TOA_YES
+           : Visual3d_TOA_NO;
+    }
+    case Graphic3d_TOS_COMPUTED:
+    {
+      return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
+           ?  Visual3d_TOA_COMPUTE
+           :  Visual3d_TOA_NO;
+    }
+  }
+  return Visual3d_TOA_NO;
 }
 
-void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {
-
-Standard_Integer StructId;
-
-        if (IsDeleted ()) return;
-
-        // No test on window as the structure is displayed only if
-        // the window exists, so only one test is enough.
-        if (IsDisplayed (AStructure)) {
-Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);
+// ========================================================================
+// function : ChangeDisplayPriority
+// purpose  :
+// ========================================================================
+void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
+                                           const Standard_Integer           /*theOldPriority*/,
+                                           const Standard_Integer             theNewPriority)
+{
+  if (IsDeleted()
+  || !IsDefined()
+  || !IsActive()
+  || !IsDisplayed (theStruct))
+  {
+    return;
+  }
 
-                if (!ComputedMode())
-                {
-                  Answer = Visual3d_TOA_YES;
-                }
+  if (!myIsInComputedMode)
+  {
+    myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
+    return;
+  }
 
-                if (Answer != Visual3d_TOA_COMPUTE) {
-                        MyGraphicDriver->EraseStructure (MyCView, *(AStructure->CStructure()));
-                }
+  const Standard_Integer      anIndex  = IsComputed (theStruct);
+  const Graphic3d_CStructure& aCStruct = anIndex != 0
+                                       ? *(myStructsComputed.Value (anIndex)->CStructure())
+                                       : *theStruct->CStructure();
+  myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
+}
 
-                if (Answer == Visual3d_TOA_COMPUTE) {
-Standard_Integer Index = IsComputed (AStructure);
-#ifdef TRACE_COMP
-        cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
-             << AStructure->Identification () << ");\n";
-        cout << "Index : " << Index << "\n";
-        cout << flush;
-#endif
+// ========================================================================
+// function : Clear
+// purpose  :
+// ========================================================================
+void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
+                           const Standard_Boolean             theWithDestruction)
+{
+  const Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex != 0)
+  {
+    const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
+    aCompStruct->GraphicClear (theWithDestruction);
+    aCompStruct->SetHLRValidation (Standard_False);
+  }
+}
 
-                    if (Index != 0 && ComputedMode())
-                    {
-                        StructId =
-                        MyCOMPUTEDSequence.Value (Index)->Identification ();
-#ifdef TRACE_COMP
-        cout << "Structure " << AStructure->Identification ()
-             << " calculated, in the view "
-             << Identification () << ", by the structure "
-             << StructId << " is removed. \n";
-        cout << flush;
-#endif
-                        MyGraphicDriver->EraseStructure (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()));
-                    }
-                    // else is impossible
-                }
-                MyDisplayedStructure.Remove (AStructure);
-                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
-        }
+// ========================================================================
+// function : Connect
+// purpose  :
+// ========================================================================
+void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
+                             const Handle(Graphic3d_Structure)& theDaughter)
+{
+  Standard_Integer anIndexM = IsComputed (theMother);
+  Standard_Integer anIndexD = IsComputed (theDaughter);
+  if (anIndexM != 0
+   && anIndexD != 0)
+  {
+    const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
+    const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
+    aStructM->GraphicConnect (aStructD);
+  }
+}
 
+// ========================================================================
+// function : Disconnect
+// purpose  :
+// ========================================================================
+void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
+                                const Handle(Graphic3d_Structure)& theDaughter)
+{
+  Standard_Integer anIndexM = IsComputed (theMother);
+  Standard_Integer anIndexD = IsComputed (theDaughter);
+  if (anIndexM != 0
+   && anIndexD != 0)
+  {
+    const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
+    const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
+    aStructM->GraphicDisconnect (aStructD);
+  }
 }
 
-void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
+// ========================================================================
+// function : DisplayImmediate
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
+                                                  const Standard_Boolean             theIsSingleView)
+{
+  if (!myImmediateStructures.Add (theStructure))
+  {
+    return Standard_False;
+  }
 
-#ifdef TRACE_HIGH
-        cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
-             << AStructure->Identification () << ")\n";
-        cout << flush;
-#endif
+  if (theIsSingleView)
+  {
+    Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
 
-Standard_Integer Index = IsComputed (AStructure);
-        if (Index != 0) {
-#ifdef TRACE_HIGH
-        cout << "Structure " << AStructure->Identification ()
-             << " calculated, in the view "
-             << Identification () << ", by the structure "
-             << MyCOMPUTEDSequence.Value (Index)->Identification ()
-             << " passes in highlight mode.\n";
-        cout << flush;
-#endif
-                (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
-                        (AStructure->HighlightColor ());
-                (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
-        }
+    for (int i=1;i<=aViews->Length();i++)
+    {
+      if (aViews->Value(i).Access() != this)
+      {
+        aViews->Value(i)->EraseImmediate (theStructure);
+      }
+    }
+  }
 
+  myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
+  return Standard_True;
 }
 
-void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
-
-#ifdef TRACE_TRSF
-        cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
-             << AStructure->Identification () << ")\n";
-        cout << flush;
-#endif
-
-Standard_Integer Index = IsComputed (AStructure);
-        if (Index != 0) {
-#ifdef TRACE_TRSF
-        cout << "The structure " << AStructure->Identification ()
-             << " calculated, in the view "
-             << Identification () << ", by the structure "
-             << MyCOMPUTEDSequence.Value (Index)->Identification ()
-             << " is transformed.\n";
-        cout << flush;
-#endif
-                // Test is somewhat light !
-                // trsf is transferred only if it is :
-                // a translation
-                // a scale
-                if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
-                 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
-                 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
-                    ReCompute (AStructure);
-                else
-                    MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
-        }
+// ========================================================================
+// function : EraseImmediate
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
+{
+  const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
+  if (isErased)
+  {
+    myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
+  }
 
+  return isErased;
 }
 
-void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
+// ========================================================================
+// function : ClearImmediate
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::ClearImmediate()
+{
+  if (myImmediateStructures.IsEmpty())
+  {
+    return Standard_False;
+  }
 
-#ifdef TRACE_HIGH
-        cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
-             << AStructure->Identification () << ")\n";
-        cout << flush;
-#endif
+  for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
+  {
+    myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
+  }
+  myImmediateStructures.Clear();
+  return Standard_True;
+}
 
-Standard_Integer Index = IsComputed (AStructure);
-        if (Index != 0) {
-#ifdef TRACE_HIGH
-        cout << "Structure " << AStructure->Identification ()
-             << " calculated, in the view "
-             << Identification () << ", by the structure "
-             << MyCOMPUTEDSequence.Value (Index)->Identification ()
-             << " passes in unhighlight mode.\n";
-        cout << flush;
-#endif
-                MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
-        }
+// ========================================================================
+// function : Display
+// purpose  :
+// ========================================================================
+void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
+{
+  Display (theStruct, myViewManager->UpdateMode());
+}
 
+// ========================================================================
+// function : Display
+// purpose  :
+// ========================================================================
+void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
+                             const Aspect_TypeOfUpdate          theUpdateMode)
+{
+  if (IsDeleted()
+  || !IsDefined()
+  || !IsActive())
+  {
+    return;
+  }
 
-}
+  // If Display on a structure present in the list of calculated structures while it is not
+  // or more, of calculated type =>
+  // - removes it as well as the associated old computed
+  // THis happens when hlhsr becomes again of type e non computed after SetVisual.
+  Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex != 0
+   && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
+  {
+    myStructsToCompute.Remove (anIndex);
+    myStructsComputed .Remove (anIndex);
+    anIndex = 0;
+  }
 
-Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {
+  Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
+  if (anAnswer == Visual3d_TOA_NO)
+  {
+    return;
+  }
 
-Standard_Integer StrId = AStructure->Identification ();
+  if (!ComputedMode())
+  {
+    anAnswer = Visual3d_TOA_YES;
+  }
 
-Standard_Integer Result = 0;
-Standard_Integer Length = MyTOCOMPUTESequence.Length ();
+  if (anAnswer == Visual3d_TOA_YES)
+  {
+    if (IsDisplayed (theStruct))
+    {
+      return;
+    }
 
-        // Recherche de la structure <AStructure> dans la
-        // sequence des structures deja calculees
-        for (Standard_Integer i=1; i<=Length && Result==0; i++)
-                if ((MyTOCOMPUTESequence.Value (i))->Identification ()
-                        == StrId) Result        = i;
-#ifdef TRACE_ISCOMP
-        cout << "\n In the view " << Identification () << " the structure ";
-        if (Result != 0)
-                cout << StrId << " is calculated by "
-                     << MyCOMPUTEDSequence.Value (Result)->Identification ()
-                     << "\n" << flush;
-        else
-                cout << StrId << " is not calculated\n" << flush;
-#endif
+    theStruct->CalculateBoundBox();
+    myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
+    myStructsDisplayed.Add (theStruct);
+    Update (theUpdateMode);
+    return;
+  }
+  else if (anAnswer != Visual3d_TOA_COMPUTE)
+  {
+    return;
+  }
 
-#ifdef TRACE_LENGTH
-        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
-                cout << "In Visual3d_View::IsComputed, ";
-                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
-                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
-                     << "\n" << flush;
+  if (anIndex != 0)
+  {
+    // Already computed, is COMPUTED still valid?
+    const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
+    if (anOldStruct->HLRValidation())
+    {
+      // Case COMPUTED valid
+      // to be displayed
+      if (!IsDisplayed (theStruct))
+      {
+        myStructsDisplayed.Add (theStruct);
+        myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
+        Update (theUpdateMode);
+      }
+      return;
+    }
+    else
+    {
+      // Case COMPUTED invalid
+      // Is there another valid representation?
+      // Find in the sequence of already calculated structures
+      // 1/ Structure having the same Owner as <AStructure>
+      // 2/ That is not <AStructure>
+      // 3/ The COMPUTED which of is valid
+      const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
+      if (aNewIndex != 0)
+      {
+        // Case of COMPUTED invalid, WITH a valid of replacement
+        // to be displayed
+        if (!IsDisplayed (theStruct))
+        {
+          const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
+          myStructsComputed.SetValue (anIndex, aNewStruct);
+          myStructsDisplayed.Add (theStruct);
+          myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
+          Update (theUpdateMode);
         }
-#endif
+        return;
+      }
+      else
+      {
+        // Case COMPUTED invalid, WITHOUT a valid of replacement
+        // COMPUTED is removed if displayed
+        if (IsDisplayed (theStruct))
+        {
+          myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
+        }
+      }
+    }
+  }
 
-        return (Result);
+  // Compute + Validation
+  Handle(Graphic3d_Structure) aStruct;
+  TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
+  theStruct->Transform (aTrsf);
+  if (anIndex != 0)
+  {
+    TColStd_Array2OfReal anIdent (0, 3, 0, 3);
+    for (Standard_Integer ii = 0; ii <= 3; ++ii)
+    {
+      for (Standard_Integer jj = 0; jj <= 3; ++jj)
+      {
+        anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
+      }
+    }
 
-}
+    aStruct = myStructsComputed.Value (anIndex);
+    aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
+    if (theStruct->IsTransformed())
+    {
+      theStruct->Compute (this, aTrsf, aStruct);
+    }
+    else
+    {
+      theStruct->Compute (this, aStruct);
+    }
+  }
+  else
+  {
+    aStruct = theStruct->IsTransformed()
+            ? theStruct->Compute (this, aTrsf)
+            : theStruct->Compute (this);
+  }
 
-Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {
+  aStruct->SetHLRValidation (Standard_True);
 
-Standard_Boolean Result = Standard_False;
+  // TOCOMPUTE and COMPUTED associated to sequences are added
+  myStructsToCompute.Append (theStruct);
+  myStructsComputed .Append (aStruct);
 
-        if (IsDeleted ()) return Result;
+  // The previous are removed if necessary
+  if (anIndex != 0)
+  {
+    myStructsToCompute.Remove (anIndex);
+    myStructsComputed .Remove (anIndex);
+  }
 
-        Result  = MyDisplayedStructure.Contains (AStructure);
+  // Of which type will be the computed?
+  const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
+  const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
+                                           && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
+  const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
+                                           && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
+  if (!toComputeShading && !toComputeWireframe)
+  {
+    anAnswer = Visual3d_TOA_NO;
+  }
+  else
+  {
+    aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
+    anAnswer = AcceptDisplay (aStruct);
+  }
 
-        return Result;
+  if (theStruct->IsHighlighted())
+  {
+    aStruct->SetHighlightColor (theStruct->HighlightColor());
+    aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
+  }
 
+  // It is displayed only if the calculated structure
+  // has a proper type corresponding to the one of the view.
+  if (anAnswer != Visual3d_TOA_NO)
+  {
+    if (!IsDisplayed (theStruct))
+    {
+      myStructsDisplayed.Add (theStruct);
+    }
+    myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
+    Update (theUpdateMode);
+  }
 }
 
-#ifdef IMPLEMENTED
-Standard_Boolean Visual3d_View::ContainsComputedStructure () const {
-
-Standard_Boolean Result = Standard_False;
-
-        if (MyDisplayedStructure.IsEmpty ()) return Result;
-
-Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);
-
-        Standard_Integer i      = MyDisplayedStructure.Extent ();
-
-        // Stop at the first structure of type TOS_COMPUTED
-        while (! Result && Iterator.More ()) {
-                Result  =
-                (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);
+// ========================================================================
+// function : Erase
+// purpose  :
+// ========================================================================
+void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
+{
+  if (!IsDeleted())
+  {
+    Erase (theStruct, myViewManager->UpdateMode());
+  }
+}
 
-                // Iterator.Next () is located on the
-                // next structure
-                Iterator.Next ();
-        }
+// ========================================================================
+// function : Erase
+// purpose  :
+// ========================================================================
+void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
+                           const Aspect_TypeOfUpdate          theUpdateMode)
+{
+  if (IsDeleted()
+  || !IsDisplayed (theStruct))
+  {
+    return;
+  }
 
-        return Result;
+  Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
+  if (!ComputedMode())
+  {
+    anAnswer = Visual3d_TOA_YES;
+  }
 
+  if (anAnswer != Visual3d_TOA_COMPUTE)
+  {
+    myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
+  }
+  else if (anAnswer == Visual3d_TOA_COMPUTE
+       && myIsInComputedMode)
+  {
+    const Standard_Integer anIndex = IsComputed (theStruct);
+    if (anIndex != 0)
+    {
+      const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
+      myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
+    }
+  }
+  myStructsDisplayed.Remove (theStruct);
+  Update (theUpdateMode);
 }
-#endif
-
-Standard_Boolean Visual3d_View::ContainsFacet () const {
-
-        return ContainsFacet (MyDisplayedStructure);
 
+// ========================================================================
+// function : Highlight
+// purpose  :
+// ========================================================================
+void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
+                               const Aspect_TypeOfHighlightMethod theMethod)
+{
+  const Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex != 0)
+  {
+    const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
+    aCompStruct->SetHighlightColor (theStruct->HighlightColor());
+    aCompStruct->GraphicHighlight (theMethod);
+  }
 }
 
-Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {
+// ========================================================================
+// function : SetTransform
+// purpose  :
+// ========================================================================
+void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
+                                  const TColStd_Array2OfReal&        theTrsf)
+{
+  const Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex != 0)
+  {
+    // Test is somewhat light !
+    // trsf is transferred only if it is :
+    // a translation
+    // a scale
+    if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
+     || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
+     || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
+    {
+      ReCompute (theStruct);
+    }
+    else
+    {
+      const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
+      aCompStruct->GraphicTransform (theTrsf);
+    }
+  }
 
-Standard_Boolean Result = Standard_False;
+  theStruct->CalculateBoundBox();
+  if (!theStruct->IsMutable()
+   && !theStruct->CStructure()->IsForHighlight
+   && !theStruct->CStructure()->IsInfinite)
+  {
+    const Standard_Integer aLayerId = theStruct->GetZLayer();
+    myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
+  }
+}
 
-        if (ASet.IsEmpty ()) return Result;
+// ========================================================================
+// function : UnHighlight
+// purpose  :
+// ========================================================================
+void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
+{
+  Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex != 0)
+  {
+    const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
+    aCompStruct->GraphicUnHighlight();
+  }
+}
 
-Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);
+// ========================================================================
+// function : IsComputed
+// purpose  :
+// ========================================================================
+Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
+{
+  const Standard_Integer aStructId  = theStruct->Identification();
+  const Standard_Integer aNbStructs = myStructsToCompute.Length();
+  for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
+  {
+    const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
+    if (aStruct->Identification() == aStructId)
+    {
+      return aStructIter;
+    }
+  }
+  return 0;
+}
 
-        // Stop at the first structure containing a facet
-        for ( Iterator.Initialize (ASet);
-              Iterator.More () && ! Result;
-              Iterator.Next ())
-                Result  = (Iterator.Key ())->ContainsFacet ();
+// ========================================================================
+// function : IsDisplayed
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
+{
+  return !IsDeleted()
+      &&  myStructsDisplayed.Contains (theStruct);
+}
 
-        return Result;
+// ========================================================================
+// function : ContainsFacet
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::ContainsFacet() const
+{
+  return ContainsFacet (myStructsDisplayed);
+}
 
+// ========================================================================
+// function : ContainsFacet
+// purpose  :
+// ========================================================================
+Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
+{
+  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
+  {
+    if (aStructIter.Key()->ContainsFacet())
+    {
+      return Standard_True;
+    }
+  }
+  return Standard_False;
 }
 
-//=============================================================================
-//function : MinMaxValues
-//purpose  :
-//=============================================================================
+// ========================================================================
+// function : MinMaxValues
+// purpose  :
+// ========================================================================
 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
                                   Standard_Real& theYMin,
                                   Standard_Real& theZMin,
@@ -1732,16 +1705,16 @@ void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
                                   Standard_Real& theZMax,
                                   const Standard_Boolean theToIgnoreInfiniteFlag) const
 {
-  MinMaxValues (MyDisplayedStructure,
+  MinMaxValues (myStructsDisplayed,
                 theXMin, theYMin, theZMin,
                 theXMax, theYMax, theZMax,
                 theToIgnoreInfiniteFlag);
 }
 
-//=============================================================================
-//function : MinMaxValues
-//purpose  :
-//=============================================================================
+// ========================================================================
+// function : MinMaxValues
+// purpose  :
+// ========================================================================
 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
                                   Standard_Real& theXMin,
                                   Standard_Real& theYMin,
@@ -1778,6 +1751,9 @@ void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
     {
       const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
 
+      if (!aStructure->IsVisible())
+        continue;
+
       if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
       {
         //XMin, YMin .... ZMax are initialized by means of infinite line data
@@ -1836,26 +1812,26 @@ void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
   }
 }
 
-//=============================================================================
-//function : MinMaxValues
-//purpose  :
-//=============================================================================
+// ========================================================================
+// function : MinMaxValues
+// purpose  :
+// ========================================================================
 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
                                   Standard_Real& theYMin,
                                   Standard_Real& theXMax,
                                   Standard_Real& theYMax,
                                   const Standard_Boolean theToIgnoreInfiniteFlag) const
 {
-  MinMaxValues (MyDisplayedStructure,
+  MinMaxValues (myStructsDisplayed,
                 theXMin, theYMin,
                 theXMax, theYMax,
                 theToIgnoreInfiniteFlag);
 }
 
-//=============================================================================
-//function : MinMaxValues
-//purpose  :
-//=============================================================================
+// ========================================================================
+// function : MinMaxValues
+// purpose  :
+// ========================================================================
 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
                                   Standard_Real& theXMin,
                                   Standard_Real& theYMin,
@@ -1880,18 +1856,19 @@ void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
   if (theYMax < theYMin) { aYp = theYMax; theYMax = theYMin; theYMin = aYp; }
 }
 
-Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {
-
-Standard_Integer Result = MyDisplayedStructure.Extent ();
-
-        return (Result);
-
+// =======================================================================
+// function : NumberOfDisplayedStructures
+// purpose  :
+// =======================================================================
+Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
+{
+  return myStructsDisplayed.Extent();
 }
 
-//=======================================================================
-//function : Projects
-//purpose  :
-//=======================================================================
+// =======================================================================
+// function : Projects
+// purpose  :
+// =======================================================================
 void Visual3d_View::Projects (const Standard_Real theX,
                               const Standard_Real theY,
                               const Standard_Real theZ,
@@ -1914,959 +1891,828 @@ void Visual3d_View::Projects (const Standard_Real theX,
   thePZ = aPoint.Z() * aZSize * 0.5;
 }
 
-Standard_Integer Visual3d_View::Identification () const {
-
-        return (Standard_Integer (MyCView.ViewId));
-
+// =======================================================================
+// function : Identification
+// purpose  :
+// =======================================================================
+Standard_Integer Visual3d_View::Identification() const
+{
+  return MyCView.ViewId;
 }
 
+// =======================================================================
+// function : ZBufferIsActivated
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::ZBufferIsActivated() const
+{
+  if (IsDeleted()
+  || !IsDefined()
+  || !IsActive())
+  {
+    return Standard_False;
+  }
 
-Standard_Boolean Visual3d_View::ZBufferIsActivated () const {
-
-        if (IsDeleted ()) return (Standard_False);
-
-        if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);
-
-// -1 => not forced by the programmer => depends on the type of visualisation
-//  0 ou 1 => forced by the programmer
-
-        if (MyCView.Context.ZBufferActivity == -1)
-                if (MyContext.Visualization () == Visual3d_TOV_SHADING)
-                        return (Standard_True);
-                else
-                        return (Standard_False);
-        else
-                if (MyCView.Context.ZBufferActivity)
-                        return (Standard_True);
-                else
-                        return (Standard_False);
-
+  if (MyCView.Context.ZBufferActivity == -1)
+  {
+    // not forced by the programmer => depends on the type of visualisation
+    return MyContext.Visualization () == Visual3d_TOV_SHADING;
+  }
+  return MyCView.Context.ZBufferActivity != 0; //  0 or 1 => forced by the programmer
 }
 
-void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {
-
-        if (IsDeleted ()) return;
-
-        if ((! IsDefined ()) || (! IsActive ())) return;
-
-        MyGraphicDriver->Transparency (MyCView, AnActivity);
+// =======================================================================
+// function : SetTransparency
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
+{
+  if (IsDeleted()
+  || !IsDefined()
+  || !IsActive())
+  {
+    return;
+  }
 
+  myGraphicDriver->Transparency (MyCView, theActivity);
 }
 
-void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {
-
-        if (MyCView.Context.ZBufferActivity == AnActivity) return;
-
-        if (IsDeleted ()) return;
-
-        if ((! IsDefined ()) || (! IsActive ())) return;
-
-        MyCView.Context.ZBufferActivity = AnActivity;
-        MyGraphicDriver->SetVisualisation (MyCView);
+// =======================================================================
+// function : SetZBufferActivity
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
+{
+  if (IsDeleted()
+  ||  MyCView.Context.ZBufferActivity == theActivity
+  || !IsDefined()
+  || !IsActive())
+  {
+    return;
+  }
 
+  MyCView.Context.ZBufferActivity = theActivity;
+  myGraphicDriver->SetVisualisation (MyCView);
 }
 
-void Visual3d_View::UpdateView () {
-
-        MyCView.Context.Aliasing        = (MyContext.AliasingIsOn () ? 1:0);
-        MyCView.Context.BackZClipping   =
-                (MyContext.BackZClippingIsOn () ? 1:0);
-        MyCView.Context.FrontZClipping  =
-                (MyContext.FrontZClippingIsOn() ? 1:0);
-        MyCView.Context.DepthCueing     =
-                (MyContext.DepthCueingIsOn () ? 1:0);
-
-        MyCView.Context.ZClipFrontPlane =
-                                float (MyContext.ZClippingFrontPlane ());
-        MyCView.Context.ZClipBackPlane          =
-                                float (MyContext.ZClippingBackPlane ());
-        MyCView.Context.DepthFrontPlane =
-                                float (MyContext.DepthCueingFrontPlane ());
-        MyCView.Context.DepthBackPlane          =
-                                float (MyContext.DepthCueingBackPlane ());
+// =======================================================================
+// function : UpdateView
+// purpose  :
+// =======================================================================
+void Visual3d_View::UpdateView()
+{
+  MyCView.Context.Aliasing        = MyContext.AliasingIsOn();
+  MyCView.Context.BackZClipping   = MyContext.BackZClippingIsOn();
+  MyCView.Context.FrontZClipping  = MyContext.FrontZClippingIsOn();
+  MyCView.Context.DepthCueing     = MyContext.DepthCueingIsOn();
 
-        MyCView.Context.Model           = int (MyContext.Model ());
-        MyCView.Context.Visualization   = int (MyContext.Visualization ());
+  MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
+  MyCView.Context.ZClipBackPlane  = float (MyContext.ZClippingBackPlane());
+  MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
+  MyCView.Context.DepthBackPlane  = float (MyContext.DepthCueingBackPlane());
 
-        MyCView.Context.TextureEnv    = MyContext.TextureEnv();
-        MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
+  MyCView.Context.Model           = MyContext.Model();
+  MyCView.Context.Visualization   = MyContext.Visualization();
 
+  MyCView.Context.TextureEnv      = MyContext.TextureEnv();
+  MyCView.Context.SurfaceDetail   = MyContext.SurfaceDetail();
 }
 
-void Visual3d_View::Compute () {
-
-Standard_Integer i;
-Standard_Integer Length = MyCOMPUTEDSequence.Length ();
-        for (i=1; i<=Length; i++)
-            (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);
-
-        if (!ComputedMode())
-        {
-          return;
-        }
-
-        /*
-         * Force HLRValidation to False on all structures
-         * calculated in the view.
-         */
-#ifdef TRACE_LENGTH
-        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
-                cout << "In Visual3d_View::Compute, ";
-                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
-                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
-                     << "\n" << flush;
-        }
-#endif
-
-        /*
-         * Change of orientation or of projection type =>
-         * Remove structures that were calculated for the
-         * previous orientation.
-         * Recalculation of new structures.
-         */
-Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
-Visual3d_TypeOfAnswer Answer;
-
-        i       = MyDisplayedStructure.Extent ();
-
-Graphic3d_SequenceOfStructure FooSequence;
-
-        while (S1Iterator.More ()) {
-                Answer  = AcceptDisplay (S1Iterator.Key ());
-                // If the structure was calculated, it is recalculated.
-                if (Answer == Visual3d_TOA_COMPUTE) {
-#ifdef TRACE
-                        cout << "AcceptDisplay ("
-                             << (S1Iterator.Key ())->Identification ()
-                             << ") == Visual3d_TOA_COMPUTE;\n";
-                        cout << flush;
-#endif
-                        //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
-                        FooSequence.Append (S1Iterator.Key ());
-                }
+// =======================================================================
+// function : Compute
+// purpose  :
+// =======================================================================
+void Visual3d_View::Compute()
+{
+  // force HLRValidation to False on all structures calculated in the view
+  const Standard_Integer aNbCompStructs = myStructsComputed.Length();
+  for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
+  {
+    myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
+  }
 
-                // S1Iterator.Next () is located on the next structure
-                S1Iterator.Next ();
-        }
+  if (!ComputedMode())
+  {
+    return;
+  }
 
-        Length  = FooSequence.Length ();
-        // All stored structures are displayed
-        for (i=1; i<=Length; i++)
-                Display (FooSequence.Value (i), Aspect_TOU_WAIT);
-        if (Length != 0) FooSequence.Clear ();
+  // Change of orientation or of projection type =>
+  // Remove structures that were calculated for the previous orientation.
+  // Recalculation of new structures.
+  NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
+  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
+  {
+    const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
+    if (anAnswer == Visual3d_TOA_COMPUTE)
+    {
+      aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
+    }
+  }
 
+  for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
+  {
+    Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
+  }
 }
 
-void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
-        if (!ComputedMode()) return;
-
-        if (IsDeleted ()) return;
-
-        if ((! IsDefined ()) || (! IsActive ())) return;
-
-        if (! MyWindow->IsMapped ()) return;
-
-        if (! AStructure->IsDisplayed ()) return;
-
-Visual3d_TypeOfAnswer Answer;
+// =======================================================================
+// function : ReCompute
+// purpose  :
+// =======================================================================
+void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
+{
+  theStruct->CalculateBoundBox();
+  if (!theStruct->IsMutable()
+   && !theStruct->CStructure()->IsForHighlight
+   && !theStruct->CStructure()->IsInfinite)
+  {
+    const Standard_Integer aLayerId = theStruct->DisplayPriority();
+    myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
+  }
 
-        Answer  = AcceptDisplay (AStructure);
+  if (!ComputedMode()
+   ||  IsDeleted()
+   || !IsDefined()
+   || !IsActive()
+   || !MyWindow->IsMapped()
+   || !theStruct->IsDisplayed())
+  {
+    return;
+  }
 
-        if (Answer == Visual3d_TOA_COMPUTE) {
-Standard_Integer Index = IsComputed (AStructure);
-                if (Index == 0) {
-#ifdef TRACE_COMP
-        cout << "Structure " << AStructure->Identification ()
-             << " is not calculated in the view "
-             << Identification () << "\n";
-        cout << flush;
-#endif
-                }
-                else {
-                 Standard_Integer OldStructId, NewStructId;
-                        OldStructId =
-                        MyCOMPUTEDSequence.Value (Index)->Identification ();
-#ifdef TRACE_COMP
-       Standard_Integer StructId = AStructure->Identification ();
-        cout << "Structure " << StructId
-             << " calculated, in the view "
-             << Identification () << ", by the structure "
-             << OldStructId << " is recalculated.\n";
-        cout << flush;
-#endif
+  const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
+  if (anAnswer != Visual3d_TOA_COMPUTE)
+  {
+    return;
+  }
 
-        // Compute + Validation
-#ifdef OLD
-Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
-#else
-Handle(Graphic3d_Structure) TheStructure;
-TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
-        AStructure->Transform (ATrsf);
-        if (Index != 0) {
-TColStd_Array2OfReal Ident (0, 3, 0, 3);
-Standard_Integer ii, jj;
-        for (ii=0; ii<=3; ii++)
-            for (jj=0; jj<=3; jj++)
-                Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
-            TheStructure = MyCOMPUTEDSequence.Value (Index);
-            TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
-            if (AStructure->IsTransformed ()) {
-                AStructure->Compute (this, ATrsf, TheStructure);
-            }
-            else {
-                AStructure->Compute (this, TheStructure);
-            }
-        }
-        else {
-            if (AStructure->IsTransformed ()) {
-                TheStructure = AStructure->Compute (this, ATrsf);
-            }
-            else {
-                TheStructure = AStructure->Compute (this);
-            }
-        }
-#endif
-        TheStructure->SetHLRValidation (Standard_True);
-
-// Return type of visualisation of the view
-Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
-
-// Of which type will be the computed ?
-Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
-        (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));
-
-Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
-        (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));
-
-                        if (ComputeWireframe)
-                            TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
-                        if (ComputeShading)
-                            TheStructure->SetVisual (Graphic3d_TOS_SHADING);
-
-                        if (AStructure->IsHighlighted ()) {
-                            TheStructure->SetHighlightColor
-                                (AStructure->HighlightColor ());
-                            TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
-                        }
-
-                        // Ot is ranged
-                        // Find structure <AStructure>
-                        // in the sequence of structures to be calculated.
-                        NewStructId = TheStructure->Identification ();
-
-                        // The previous calculation is removed and the new one is dislayed
-                        MyGraphicDriver->EraseStructure   (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()));
-                        MyGraphicDriver->DisplayStructure (MyCView, *(TheStructure->CStructure()), AStructure->DisplayPriority());
-
-#ifdef TRACE_LENGTH
-        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
-                cout << "In Visual3d_View::ReCompute, ";
-                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
-                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
-                     << "\n" << flush;
-        }
-#endif
+  const Standard_Integer anIndex = IsComputed (theStruct);
+  if (anIndex == 0)
+  {
+    return;
+  }
 
-                          // hlhsr and the new associated compute are added
-                          MyTOCOMPUTESequence.Append (AStructure);
-                          MyCOMPUTEDSequence.Append (TheStructure);
+  // compute + validation
+  TColStd_Array2OfReal anIdent (0, 3, 0, 3);
+  for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
+  {
+    for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
+    {
+      anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
+    }
+  }
+  TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
+  theStruct->Transform (aTrsf);
+
+  Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
+  Handle(Graphic3d_Structure) aCompStruct    = aCompStructOld;
+  aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
+  theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
+                             : theStruct->Compute (this,        aCompStruct);
+  aCompStruct->SetHLRValidation (Standard_True);
+
+  // of which type will be the computed?
+  const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
+  const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
+                                           && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
+  const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
+                                           && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
+  if (toComputeWireframe)
+  {
+    aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
+  }
+  else if (toComputeShading)
+  {
+    aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
+  }
 
-#ifdef TRACE_LENGTH
-        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
-                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
-                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
-                     << "\n" << flush;
-#endif
+  if (theStruct->IsHighlighted())
+  {
+    aCompStruct->SetHighlightColor (theStruct->HighlightColor());
+    aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
+  }
 
-                          // hlhsr and the new associated compute are removed
+  // The previous calculation is removed and the new one is dislayed
+  myGraphicDriver->EraseStructure   (MyCView, *aCompStructOld->CStructure());
+  myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
 
-                          MyTOCOMPUTESequence.Remove (Index);
-                          MyCOMPUTEDSequence.Remove (Index);
+  // why not just replace existing items?
+  //myStructsToCompute.ChangeValue (anIndex) = theStruct;
+  //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
 
-#ifdef TRACE_LENGTH
-        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
-                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
-                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
-                     << "\n" << flush;
-#endif
-                }
-        }
+  // hlhsr and the new associated compute are added
+  myStructsToCompute.Append (theStruct);
+  myStructsComputed .Append (aCompStruct);
 
+  // hlhsr and the new associated compute are removed
+  myStructsToCompute.Remove (anIndex);
+  myStructsComputed .Remove (anIndex);
 }
 
-const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver () const {
-
-        return MyGraphicDriver;
-
+// =======================================================================
+// function : GraphicDriver
+// purpose  :
+// =======================================================================
+const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
+{
+  return myGraphicDriver;
 }
 
-void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& thePlotter) const
+// =======================================================================
+// function : HaveTheSameOwner
+// purpose  :
+// =======================================================================
+Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
 {
-  for (Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure); S1Iterator.More(); S1Iterator.Next())
+  // Find in the sequence of already calculated structures
+  // 1/ Structure with the same Owner as <AStructure>
+  // 2/ Which is not <AStructure>
+  // 3/ COMPUTED which of is valid
+  const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
+  for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
   {
-    Standard_Integer Index = IsComputed (S1Iterator.Key ());
-    // displayed structure is plotted as if it was not calculated
-    if (Index == 0)
-      (S1Iterator.Key ())->Plot (thePlotter);
-    else
-      (MyCOMPUTEDSequence.Value (Index))->Plot (thePlotter);
+    const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
+    if (aStructToComp->Owner()          == theStruct->Owner()
+     && aStructToComp->Identification() != theStruct->Identification())
+    {
+      const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
+      if (aStructComp->HLRValidation())
+      {
+        return aStructIter;
+      }
+    }
   }
+  return 0;
 }
 
-Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {
-
-Standard_Integer Result = 0;
-Standard_Integer Length = MyTOCOMPUTESequence.Length ();
-
-        // Find in the sequence of already calculated structures
-        // 1/ Structure with the same Owner as <AStructure>
-        // 2/ Which is not <AStructure>
-        // 3/ COMPUTED which of is valid
-        for (Standard_Integer i=1; i<=Length && Result==0; i++)
-           if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
-            && (MyTOCOMPUTESequence.Value (i)->Identification () !=
-                                                AStructure->Identification ())
-            && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result   = i;
-
-        return (Result);
-
-}
-
-Standard_Address Visual3d_View::CView () const {
-
-        return Standard_Address (&MyCView);
-
-}
-
-
-// Triedron methods : the Triedron is a non-zoomable object.
-
-void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
-                                    const Quantity_NameOfColor YColor,
-                                    const Quantity_NameOfColor ZColor,
-                                    const Standard_Real        SizeRatio,
-                                    const Standard_Real        AxisDiametr,
-                                    const Standard_Integer     NbFacettes) {
-  MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
-                                        SizeRatio, AxisDiametr, NbFacettes);
-}
-
-
-
-void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
- const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {
-
-        MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);
-
+// =======================================================================
+// function : CView
+// purpose  :
+// =======================================================================
+Standard_Address Visual3d_View::CView() const
+{
+  return Standard_Address (&MyCView);
 }
 
-void Visual3d_View::TriedronErase () {
-
-        MyGraphicDriver->TriedronErase (MyCView);
-
+// =======================================================================
+// function : ZBufferTriedronSetup
+// purpose  :
+// =======================================================================
+void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
+                                          const Quantity_NameOfColor theYColor,
+                                          const Quantity_NameOfColor theZColor,
+                                          const Standard_Real        theSizeRatio,
+                                          const Standard_Real        theAxisDiametr,
+                                          const Standard_Integer     theNbFacettes)
+{
+  myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
+                                         theSizeRatio, theAxisDiametr, theNbFacettes);
+}
 
+// =======================================================================
+// function : TriedronDisplay
+// purpose  :
+// =======================================================================
+void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
+                                     const Quantity_NameOfColor          theColor,
+                                     const Standard_Real                 theScale,
+                                     const Standard_Boolean              theAsWireframe)
+{
+  myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
 }
 
-void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {
+// =======================================================================
+// function : TriedronErase
+// purpose  :
+// =======================================================================
+void Visual3d_View::TriedronErase()
+{
+  myGraphicDriver->TriedronErase (MyCView);
+}
 
-        MyGraphicDriver->TriedronEcho (MyCView,AType);
+// =======================================================================
+// function : TriedronEcho
+// purpose  :
+// =======================================================================
+void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
+{
+  myGraphicDriver->TriedronEcho (MyCView, theType);
+}
 
+static Standard_Boolean checkFloat (const Standard_Real theValue)
+{
+  return theValue > -FLT_MAX
+      && theValue <  FLT_MAX;
 }
 
-static Standard_Boolean checkFloat(const Standard_Real value)
+static void SetMinMaxValuesCallback (Visual3d_View* theView)
 {
-    return value > -FLT_MAX && value < FLT_MAX;
+  Graphic3d_Vec3d aMin, aMax;
+  theView->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
+                         aMax.x(), aMax.y(), aMax.z());
+  if (checkFloat (aMin.x()) && checkFloat (aMin.y()) && checkFloat (aMin.z())
+   && checkFloat (aMax.x()) && checkFloat (aMax.y()) && checkFloat (aMax.z()))
+  {
+    const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
+    aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.x(), (Standard_ShortReal )aMin.y(), (Standard_ShortReal )aMin.z(),
+                                             (Standard_ShortReal )aMax.x(), (Standard_ShortReal )aMax.y(), (Standard_ShortReal )aMax.z());
+  }
 }
 
-static void SetMinMaxValuesCallback(Visual3d_View* theView)
+// =======================================================================
+// function : GetGraduatedTrihedron
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
+                                                       TCollection_ExtendedString& theYName,
+                                                       TCollection_ExtendedString& theZName,
+                                                       Standard_Boolean&           theToDrawXName,
+                                                       Standard_Boolean&           theToDrawYName,
+                                                       Standard_Boolean&           theToDrawZName,
+                                                       Standard_Boolean&           theToDrawXValues,
+                                                       Standard_Boolean&           theToDrawYValues,
+                                                       Standard_Boolean&           theToDrawZValues,
+                                                       Standard_Boolean&           theToDrawGrid,
+                                                       Standard_Boolean&           theToDrawAxes,
+                                                       Standard_Integer&           theNbX,
+                                                       Standard_Integer&           theNbY,
+                                                       Standard_Integer&           theNbZ,
+                                                       Standard_Integer&           theXOffset,
+                                                       Standard_Integer&           theYOffset,
+                                                       Standard_Integer&           theZOffset,
+                                                       Standard_Integer&           theXAxisOffset,
+                                                       Standard_Integer&           theYAxisOffset,
+                                                       Standard_Integer&           theZAxisOffset,
+                                                       Standard_Boolean&           theToDrawXTickMarks,
+                                                       Standard_Boolean&           theToDrawYTickMarks,
+                                                       Standard_Boolean&           theToDrawZTickMarks,
+                                                       Standard_Integer&           theXTickMarkLength,
+                                                       Standard_Integer&           theYTickMarkLength,
+                                                       Standard_Integer&           theZTickMarkLength,
+                                                       Quantity_Color&             theGridColor,
+                                                       Quantity_Color&             theXNameColor,
+                                                       Quantity_Color&             theYNameColor,
+                                                       Quantity_Color&             theZNameColor,
+                                                       Quantity_Color&             theXColor,
+                                                       Quantity_Color&             theYColor,
+                                                       Quantity_Color&             theZColor,
+                                                       TCollection_AsciiString&    theFontOfNames,
+                                                       Font_FontAspect&            theStyleOfNames,
+                                                       Standard_Integer&           theSizeOfNames,
+                                                       TCollection_AsciiString&    theFontOfValues,
+                                                       Font_FontAspect&            theStyleOfValues,
+                                                       Standard_Integer&           theSizeOfValues) const
 {
-    Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;
-    theView->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);
+  if (!MyGTrihedron.ptrVisual3dView)
+  {
+    return Standard_False;
+  }
 
-    if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
-        checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
-    {
-        Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(theView->GraphicDriver());
-        driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
-                                               (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
-    }
+  theXName = MyGTrihedron.xname;
+  theYName = MyGTrihedron.yname;
+  theZName = MyGTrihedron.zname;
+  theToDrawXName   = MyGTrihedron.xdrawname;
+  theToDrawYName   = MyGTrihedron.ydrawname;
+  theToDrawZName   = MyGTrihedron.zdrawname;
+  theToDrawXValues = MyGTrihedron.xdrawvalues;
+  theToDrawYValues = MyGTrihedron.ydrawvalues;
+  theToDrawZValues = MyGTrihedron.zdrawvalues;
+  theToDrawGrid    = MyGTrihedron.drawgrid;
+  theToDrawAxes    = MyGTrihedron.drawaxes;
+  theNbX = MyGTrihedron.nbx;
+  theNbY = MyGTrihedron.nby;
+  theNbZ = MyGTrihedron.nbz;
+  theXOffset     = MyGTrihedron.xoffset;
+  theYOffset     = MyGTrihedron.yoffset;
+  theZOffset     = MyGTrihedron.zoffset;
+  theXAxisOffset = MyGTrihedron.xaxisoffset;
+  theYAxisOffset = MyGTrihedron.yaxisoffset;
+  theZAxisOffset = MyGTrihedron.zaxisoffset;
+  theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
+  theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
+  theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
+  theXTickMarkLength  = MyGTrihedron.xtickmarklength;
+  theYTickMarkLength  = MyGTrihedron.ytickmarklength;
+  theZTickMarkLength  = MyGTrihedron.ztickmarklength;
+  theGridColor  = MyGTrihedron.gridcolor;
+  theXNameColor = MyGTrihedron.xnamecolor;
+  theYNameColor = MyGTrihedron.ynamecolor;
+  theZNameColor = MyGTrihedron.znamecolor;
+  theXColor     = MyGTrihedron.xcolor;
+  theYColor     = MyGTrihedron.ycolor;
+  theZColor     = MyGTrihedron.zcolor;
+  theFontOfNames   = MyGTrihedron.fontOfNames;
+  theStyleOfNames  = MyGTrihedron.styleOfNames;
+  theSizeOfNames   = MyGTrihedron.sizeOfNames;
+  theFontOfValues  = MyGTrihedron.fontOfValues;
+  theStyleOfValues = MyGTrihedron.styleOfValues;
+  theSizeOfValues  = MyGTrihedron.sizeOfValues;
+  return Standard_True;
 }
 
-Standard_Boolean Visual3d_View::GetGraduatedTrihedron
-    (/* Names of axes */
-     TCollection_ExtendedString& xname,
-     TCollection_ExtendedString& yname,
-     TCollection_ExtendedString& zname,
-     /* Draw names */
-     Standard_Boolean& xdrawname,
-     Standard_Boolean& ydrawname,
-     Standard_Boolean& zdrawname,
-     /* Draw values */
-     Standard_Boolean& xdrawvalues,
-     Standard_Boolean& ydrawvalues,
-     Standard_Boolean& zdrawvalues,
-     /* Draw grid */
-     Standard_Boolean& drawgrid,
-     /* Draw axes */
-     Standard_Boolean& drawaxes,
-     /* Number of splits along axes */
-     Standard_Integer& nbx,
-     Standard_Integer& nby,
-     Standard_Integer& nbz,
-     /* Offset for drawing values */
-     Standard_Integer& xoffset,
-     Standard_Integer& yoffset,
-     Standard_Integer& zoffset,
-     /* Offset for drawing names of axes */
-     Standard_Integer& xaxisoffset,
-     Standard_Integer& yaxisoffset,
-     Standard_Integer& zaxisoffset,
-     /* Draw tickmarks */
-     Standard_Boolean& xdrawtickmarks,
-     Standard_Boolean& ydrawtickmarks,
-     Standard_Boolean& zdrawtickmarks,
-     /* Length of tickmarks */
-     Standard_Integer& xtickmarklength,
-     Standard_Integer& ytickmarklength,
-     Standard_Integer& ztickmarklength,
-     /* Grid color */
-     Quantity_Color& gridcolor,
-     /* Colors of axis names */
-     Quantity_Color& xnamecolor,
-     Quantity_Color& ynamecolor,
-     Quantity_Color& znamecolor,
-     /* Colors of axis and values */
-     Quantity_Color& xcolor,
-     Quantity_Color& ycolor,
-     Quantity_Color& zcolor,
-     /* Name of font for names of axes */
-     TCollection_AsciiString& fontOfNames,
-     /* Style of names of axes */
-     Font_FontAspect& styleOfNames,
-     /* Size of names of axes */
-     Standard_Integer& sizeOfNames,
-     /* Name of font for values */
-     TCollection_AsciiString& fontOfValues,
-     /* Style of values */
-     Font_FontAspect& styleOfValues,
-     /* Size of values */
-     Standard_Integer& sizeOfValues) const
-{
-    if (!MyGTrihedron.ptrVisual3dView)
-        return Standard_False;
-
-    /* Names of axes */
-    xname = MyGTrihedron.xname;
-    yname = MyGTrihedron.yname;
-    zname = MyGTrihedron.zname;
-    /* Draw names */
-    xdrawname = MyGTrihedron.xdrawname;
-    ydrawname = MyGTrihedron.ydrawname;
-    zdrawname = MyGTrihedron.zdrawname;
-    /* Draw values */
-    xdrawvalues = MyGTrihedron.xdrawvalues;
-    ydrawvalues = MyGTrihedron.ydrawvalues;
-    zdrawvalues = MyGTrihedron.zdrawvalues;
-    /* Draw grid */
-    drawgrid = MyGTrihedron.drawgrid;
-    /* Draw axes */
-    drawaxes = MyGTrihedron.drawaxes;
-    /* Number of splits along axes */
-    nbx = MyGTrihedron.nbx;
-    nby = MyGTrihedron.nby;
-    nbz = MyGTrihedron.nbz;
-    /* Offset for drawing values */
-    xoffset = MyGTrihedron.xoffset;
-    yoffset = MyGTrihedron.yoffset;
-    zoffset = MyGTrihedron.zoffset;
-    /* Offset for drawing names of axes */
-    xaxisoffset = MyGTrihedron.xaxisoffset;
-    yaxisoffset = MyGTrihedron.yaxisoffset;
-    zaxisoffset = MyGTrihedron.zaxisoffset;
-    /* Draw tickmarks */
-    xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
-    ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
-    zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
-    /* Length of tickmarks */
-    xtickmarklength = MyGTrihedron.xtickmarklength;
-    ytickmarklength = MyGTrihedron.ytickmarklength;
-    ztickmarklength = MyGTrihedron.ztickmarklength;
-    /* Grid color */
-    gridcolor = MyGTrihedron.gridcolor;
-    /* Colors of axis names */
-    xnamecolor = MyGTrihedron.xnamecolor;
-    ynamecolor = MyGTrihedron.ynamecolor;
-    znamecolor = MyGTrihedron.znamecolor;
-    /* Colors of axis and values */
-    xcolor = MyGTrihedron.xcolor;
-    ycolor = MyGTrihedron.ycolor;
-    zcolor = MyGTrihedron.zcolor;
-    /* Name of font for names of axes */
-    fontOfNames = MyGTrihedron.fontOfNames;
-    /* Style of names of axes */
-    styleOfNames = MyGTrihedron.styleOfNames;
-    /* Size of names of axes */
-    sizeOfNames = MyGTrihedron.sizeOfNames;
-    /* Name of font for values */
-    fontOfValues = MyGTrihedron.fontOfValues;
-    /* Style of values */
-    styleOfValues = MyGTrihedron.styleOfValues;
-    /* Size of values */
-    sizeOfValues = MyGTrihedron.sizeOfValues;
-
-    return Standard_True;
-}
-
-void Visual3d_View::GraduatedTrihedronDisplay
-    (/* Names of axes */
-     const TCollection_ExtendedString &xname,
-     const TCollection_ExtendedString &yname,
-     const TCollection_ExtendedString &zname,
-     /* Draw names */
-     const Standard_Boolean xdrawname,
-     const Standard_Boolean ydrawname,
-     const Standard_Boolean zdrawname,
-     /* Draw values */
-     const Standard_Boolean xdrawvalues,
-     const Standard_Boolean ydrawvalues,
-     const Standard_Boolean zdrawvalues,
-     /* Draw grid */
-     const Standard_Boolean drawgrid,
-     /* Draw axes */
-     const Standard_Boolean drawaxes,
-     /* Number of splits along axes */
-     const Standard_Integer nbx,
-     const Standard_Integer nby,
-     const Standard_Integer nbz,
-     /* Offset for drawing values */
-     const Standard_Integer xoffset,
-     const Standard_Integer yoffset,
-     const Standard_Integer zoffset,
-     /* Offset for drawing names of axes */
-     const Standard_Integer xaxisoffset,
-     const Standard_Integer yaxisoffset,
-     const Standard_Integer zaxisoffset,
-     /* Draw tickmarks */
-     const Standard_Boolean xdrawtickmarks,
-     const Standard_Boolean ydrawtickmarks,
-     const Standard_Boolean zdrawtickmarks,
-     /* Length of tickmarks */
-     const Standard_Integer xtickmarklength,
-     const Standard_Integer ytickmarklength,
-     const Standard_Integer ztickmarklength,
-     /* Grid color */
-     const Quantity_Color& gridcolor,
-     /* Colors of axis names */
-     const Quantity_Color& xnamecolor,
-     const Quantity_Color& ynamecolor,
-     const Quantity_Color& znamecolor,
-     /* Colors of axis and values */
-     const Quantity_Color& xcolor,
-     const Quantity_Color& ycolor,
-     const Quantity_Color& zcolor,
-     /* Name of font for names of axes */
-     const TCollection_AsciiString &fontOfNames,
-     /* Style of names of axes */
-     const Font_FontAspect styleOfNames,
-     /* Size of names of axes */
-     const Standard_Integer sizeOfNames,
-     /* Name of font for values */
-     const TCollection_AsciiString &fontOfValues,
-     /* Style of values */
-     const Font_FontAspect styleOfValues,
-     /* Size of values */
-     const Standard_Integer sizeOfValues)
-{
-    /* Names of axes */
-    MyGTrihedron.xname = xname;
-    MyGTrihedron.yname = yname;
-    MyGTrihedron.zname = zname;
-    /* Draw names */
-    MyGTrihedron.xdrawname = xdrawname;
-    MyGTrihedron.ydrawname = ydrawname;
-    MyGTrihedron.zdrawname = zdrawname;
-    /* Draw values */
-    MyGTrihedron.xdrawvalues = xdrawvalues;
-    MyGTrihedron.ydrawvalues = ydrawvalues;
-    MyGTrihedron.zdrawvalues = zdrawvalues;
-    /* Draw grid */
-    MyGTrihedron.drawgrid = drawgrid;
-    /* Draw axes */
-    MyGTrihedron.drawaxes = drawaxes;
-    /* Number of splits along axes */
-    MyGTrihedron.nbx = nbx;
-    MyGTrihedron.nby = nby;
-    MyGTrihedron.nbz = nbz;
-    /* Offset for drawing values */
-    MyGTrihedron.xoffset = xoffset;
-    MyGTrihedron.yoffset = yoffset;
-    MyGTrihedron.zoffset = zoffset;
-    /* Offset for drawing names of axes */
-    MyGTrihedron.xaxisoffset = xaxisoffset;
-    MyGTrihedron.yaxisoffset = yaxisoffset;
-    MyGTrihedron.zaxisoffset = zaxisoffset;
-    /* Draw tickmarks */
-    MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
-    MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
-    MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
-    /* Length of tickmarks */
-    MyGTrihedron.xtickmarklength = xtickmarklength;
-    MyGTrihedron.ytickmarklength = ytickmarklength;
-    MyGTrihedron.ztickmarklength = ztickmarklength;
-    /* Grid color */
-    MyGTrihedron.gridcolor = gridcolor;
-    /* Colors of axis names */
-    MyGTrihedron.xnamecolor = xnamecolor;
-    MyGTrihedron.ynamecolor = ynamecolor;
-    MyGTrihedron.znamecolor = znamecolor;
-    /* Colors of axis and values */
-    MyGTrihedron.xcolor = xcolor;
-    MyGTrihedron.ycolor = ycolor;
-    MyGTrihedron.zcolor = zcolor;
-    /* Name of font for names of axes */
-    MyGTrihedron.fontOfNames = fontOfNames;
-    /* Style of names of axes */
-    MyGTrihedron.styleOfNames = styleOfNames;
-    /* Size of names of axes */
-    MyGTrihedron.sizeOfNames = sizeOfNames;
-    /* Name of font for values */
-    MyGTrihedron.fontOfValues = fontOfValues;
-    /* Style of values */
-    MyGTrihedron.styleOfValues = styleOfValues;
-    /* Size of values */
-    MyGTrihedron.sizeOfValues = sizeOfValues;
-
-    MyGTrihedron.ptrVisual3dView = this;
-    MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
-    MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
+// =======================================================================
+// function : GraduatedTrihedronDisplay
+// purpose  :
+// =======================================================================
+void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
+                                               const TCollection_ExtendedString& theYName,
+                                               const TCollection_ExtendedString& theZName,
+                                               const Standard_Boolean theToDrawXName,
+                                               const Standard_Boolean theToDrawYName,
+                                               const Standard_Boolean theToDrawZName,
+                                               const Standard_Boolean theToDrawXValues,
+                                               const Standard_Boolean theToDrawYValues,
+                                               const Standard_Boolean theToDrawZValues,
+                                               const Standard_Boolean theToDrawGrid,
+                                               const Standard_Boolean theToDrawAxes,
+                                               const Standard_Integer theNbX,
+                                               const Standard_Integer theNbY,
+                                               const Standard_Integer theNbZ,
+                                               const Standard_Integer theXOffset,
+                                               const Standard_Integer theYOffset,
+                                               const Standard_Integer theZOffset,
+                                               const Standard_Integer theXAxisOffset,
+                                               const Standard_Integer theYAxisOffset,
+                                               const Standard_Integer theZAxisOffset,
+                                               const Standard_Boolean theToDrawXTickMarks,
+                                               const Standard_Boolean theToDrawYTickMarks,
+                                               const Standard_Boolean theToDrawZTickMarks,
+                                               const Standard_Integer theXTickMarkLength,
+                                               const Standard_Integer theYTickMarkLength,
+                                               const Standard_Integer theZTickMarkLength,
+                                               const Quantity_Color&  theGridColor,
+                                               const Quantity_Color&  theXNameColor,
+                                               const Quantity_Color&  theYNameColor,
+                                               const Quantity_Color&  theZNameColor,
+                                               const Quantity_Color&  theXColor,
+                                               const Quantity_Color&  theYColor,
+                                               const Quantity_Color&  theZColor,
+                                               const TCollection_AsciiString& theFontOfNames,
+                                               const Font_FontAspect  theStyleOfNames,
+                                               const Standard_Integer theSizeOfNames,
+                                               const TCollection_AsciiString& theFontOfValues,
+                                               const Font_FontAspect  theStyleOfValues,
+                                               const Standard_Integer theSizeOfValues)
+{
+  MyGTrihedron.xname = theXName;
+  MyGTrihedron.yname = theYName;
+  MyGTrihedron.zname = theZName;
+  MyGTrihedron.xdrawname = theToDrawXName;
+  MyGTrihedron.ydrawname = theToDrawYName;
+  MyGTrihedron.zdrawname = theToDrawZName;
+  MyGTrihedron.xdrawvalues = theToDrawXValues;
+  MyGTrihedron.ydrawvalues = theToDrawYValues;
+  MyGTrihedron.zdrawvalues = theToDrawZValues;
+  MyGTrihedron.drawgrid = theToDrawGrid;
+  MyGTrihedron.drawaxes = theToDrawAxes;
+  MyGTrihedron.nbx = theNbX;
+  MyGTrihedron.nby = theNbY;
+  MyGTrihedron.nbz = theNbZ;
+  MyGTrihedron.xoffset = theXOffset;
+  MyGTrihedron.yoffset = theYOffset;
+  MyGTrihedron.zoffset = theZOffset;
+  MyGTrihedron.xaxisoffset = theXAxisOffset;
+  MyGTrihedron.yaxisoffset = theYAxisOffset;
+  MyGTrihedron.zaxisoffset = theZAxisOffset;
+  MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
+  MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
+  MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
+  MyGTrihedron.xtickmarklength = theXTickMarkLength;
+  MyGTrihedron.ytickmarklength = theYTickMarkLength;
+  MyGTrihedron.ztickmarklength = theZTickMarkLength;
+  MyGTrihedron.gridcolor  = theGridColor;
+  MyGTrihedron.xnamecolor = theXNameColor;
+  MyGTrihedron.ynamecolor = theYNameColor;
+  MyGTrihedron.znamecolor = theZNameColor;
+  MyGTrihedron.xcolor = theXColor;
+  MyGTrihedron.ycolor = theYColor;
+  MyGTrihedron.zcolor = theZColor;
+  MyGTrihedron.fontOfNames   = theFontOfNames;
+  MyGTrihedron.styleOfNames  = theStyleOfNames;
+  MyGTrihedron.sizeOfNames   = theSizeOfNames;
+  MyGTrihedron.fontOfValues  = theFontOfValues;
+  MyGTrihedron.styleOfValues = theStyleOfValues;
+  MyGTrihedron.sizeOfValues  = theSizeOfValues;
+
+  MyGTrihedron.ptrVisual3dView = this;
+  MyGTrihedron.cbCubicAxes     = SetMinMaxValuesCallback;
+  myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
 }
 
+// =======================================================================
+// function : GraduatedTrihedronErase
+// purpose  :
+// =======================================================================
 void Visual3d_View::GraduatedTrihedronErase()
 {
-    MyGTrihedron.ptrVisual3dView = NULL;
-    MyGraphicDriver->GraduatedTrihedronErase(MyCView);
+  MyGTrihedron.ptrVisual3dView = NULL;
+  myGraphicDriver->GraduatedTrihedronErase (MyCView);
 }
 
-const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer () const {
-
-        return (MyViewManager->UnderLayer ());
-
+// =======================================================================
+// function : UnderLayer
+// purpose  :
+// =======================================================================
+const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
+{
+  return myViewManager->UnderLayer();
 }
 
-const Handle(Visual3d_Layer)& Visual3d_View::OverLayer () const {
-
-        return (MyViewManager->OverLayer ());
-
+// =======================================================================
+// function : OverLayer
+// purpose  :
+// =======================================================================
+const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
+{
+  return myViewManager->OverLayer();
 }
 
-Standard_Integer Visual3d_View::LightLimit() const {
-
-        Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
-//      printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
-        return maxlight;
+// =======================================================================
+// function : LightLimit
+// purpose  :
+// =======================================================================
+Standard_Integer Visual3d_View::LightLimit() const
+{
+  return myGraphicDriver->InquireLightLimit();
 }
 
-Standard_Integer Visual3d_View::PlaneLimit() const {
-
-        Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
-//      printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
-        return maxplane;
+// =======================================================================
+// function : PlaneLimit
+// purpose  :
+// =======================================================================
+Standard_Integer Visual3d_View::PlaneLimit() const
+{
+  return myGraphicDriver->InquirePlaneLimit();
 }
 
+// =======================================================================
+// function : ViewManager
+// purpose  :
+// =======================================================================
 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
 {
-  return MyPtrViewManager;
+  return myViewManager;
 }
 
-void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode )
+// =======================================================================
+// function : SetComputedMode
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
 {
-  if ((aMode &&  ComputedModeIsActive) ||
-     (!aMode && !ComputedModeIsActive))
+  if (( theMode &&  myIsInComputedMode)
+   || (!theMode && !myIsInComputedMode))
   {
     return;
   }
 
- Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
- Visual3d_TypeOfAnswer                 Answer;
- Standard_Integer                      StructId;
- Standard_Integer                      i = MyDisplayedStructure.Extent ();
- ComputedModeIsActive = aMode;
- if (!ComputedModeIsActive) {
-
-  while (  S1Iterator.More ()  ) {
-
-   Answer = AcceptDisplay (  S1Iterator.Key ()  );
-
-   if ( Answer == Visual3d_TOA_COMPUTE ) {
-
-    Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );
-
-    if ( Index != 0 ) {
-
-     StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
-
-     MyGraphicDriver->EraseStructure   (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()));
-     MyGraphicDriver->DisplayStructure (MyCView, *(S1Iterator.Key()->CStructure()), S1Iterator.Key()->DisplayPriority());
-    }  // end if ( Index != 0 ) . . .
-
-   }  // end if ( Answer . . . )
-
-   S1Iterator.Next ();
-
-  }  // end while
-
- } else {
-
-  while (  S1Iterator.More ()  ) {
-
-   Answer = AcceptDisplay (  S1Iterator.Key ()  );
-
-   if ( Answer == Visual3d_TOA_COMPUTE ) {
-
-    Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );
-
-    if ( Index != 0 ) {
-
-     StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();
-
-     MyGraphicDriver->EraseStructure   (MyCView, *(S1Iterator.Key()->CStructure()));
-     MyGraphicDriver->DisplayStructure (MyCView, *(MyCOMPUTEDSequence.Value (Index)->CStructure()), S1Iterator.Key()->DisplayPriority());
-
-     Display (  S1Iterator.Key (), Aspect_TOU_WAIT  );
-
-     if (  S1Iterator.Key () -> IsHighlighted ()  ) {
-
-      if (  !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted ()  ) {
-
-       MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
-                                              S1Iterator.Key () ->
-                                               HighlightColor ()
-                                             );
-       MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
-                                              Aspect_TOHM_COLOR
-                                             );
-      }  // end if
-
-     }  // end if
-
-    } else {
-
-     Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
-#ifdef OLD
-     Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
-#else
-     Handle( Graphic3d_Structure ) TheStructure;
-     TColStd_Array2OfReal          ATrsf ( 0, 3, 0, 3 );
-
-     AStructure -> Transform ( ATrsf );
-
-     if ( Index != 0 ) {
-
-      TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
-      Standard_Integer     ii, jj;
-
-      for ( ii = 0; ii <= 3; ++ii )
-
-       for ( jj = 0; jj <= 3; ++jj  )
-
-        Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );
-
-      TheStructure = MyCOMPUTEDSequence.Value ( Index );
-
-      TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );
-
-      if (  AStructure->IsTransformed ()  )
-
-       AStructure -> Compute ( this, ATrsf, TheStructure );
-
-      else
-
-       AStructure -> Compute ( this, TheStructure );
-
-     } else {
-
-      if ( AStructure -> IsTransformed ()  )
-
-       TheStructure = AStructure -> Compute ( this, ATrsf );
-
-      else
-
-       TheStructure = AStructure -> Compute ( this );
-
-     }  // end else
-#endif  // OLD
-     TheStructure -> SetHLRValidation ( Standard_True );
-
-     Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();
-
-     Standard_Boolean ComputeWireframe =
-      (  ( ViewType == Visual3d_TOV_WIREFRAME ) &&
-             (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING  )
-      );
-
-     Standard_Boolean ComputeShading =
-      (  ( ViewType == Visual3d_TOV_SHADING ) &&
-             (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME  )
-      );
-
-     if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
-     if ( ComputeShading   ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING   );
-
-     if (  S1Iterator.Key () -> IsHighlighted ()  ) {
-
-      TheStructure -> SetHighlightColor (
-                       S1Iterator.Key () -> HighlightColor ()
-                      );
-      TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );
-
-     }  // end if
-
-     Standard_Integer Result = 0;
-     Standard_Integer Length = MyTOCOMPUTESequence.Length ();
-     StructId = S1Iterator.Key () -> Identification ();
-
-     for ( i = 1; i <= Length && Result == 0; ++i )
-
-      if (  MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId  )
-
-       Result = i;
-
-     if ( Result )
-
-      MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;
-
-     else {
-
-      MyTOCOMPUTESequence.Append (  S1Iterator.Key ()  );
-      MyCOMPUTEDSequence.Append  ( TheStructure );
-
-     }  // end else
-
-     MyGraphicDriver->EraseStructure   (MyCView, *(S1Iterator.Key()->CStructure()));
-     MyGraphicDriver->DisplayStructure (MyCView, *(TheStructure->CStructure()), S1Iterator.Key()->DisplayPriority());
-    }  // end else
-
-   }  // end if
-
-   S1Iterator.Next ();
-
-  }  // end while
-
-  if (  MyViewManager -> UpdateMode () == Aspect_TOU_ASAP  ) Update ();
-
- }  // end else
-
-}  // end Visual3d_View :: SetComputedMode
-
-Standard_Boolean Visual3d_View :: ComputedMode () const {
-
- return ComputedModeIsActive;
-
-}  // end Visual3d_View :: ComputedMode
-
-void Visual3d_View :: SetBackFacingModel (
-                       const Visual3d_TypeOfBackfacingModel aModel
-                      ) {
- switch ( aModel ) {
-
-  default:
-  case Visual3d_TOBM_AUTOMATIC:
-   MyCView.Backfacing = 0;
-   break;
-
-  case Visual3d_TOBM_FORCE:
-   MyCView.Backfacing = 1;
-   break;
-
-  case Visual3d_TOBM_DISABLE:
-   MyCView.Backfacing = -1;
-   break;
+  myIsInComputedMode = theMode;
+  if (!myIsInComputedMode)
+  {
+    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
+    {
+      const Handle(Graphic3d_Structure)& aStruct  = aStructIter.Key();
+      const Visual3d_TypeOfAnswer        anAnswer = AcceptDisplay (aStruct);
+      if (anAnswer != Visual3d_TOA_COMPUTE)
+      {
+        continue;
+      }
 
- }  // end switch
+      const Standard_Integer anIndex = IsComputed (aStruct);
+      if (anIndex != 0)
+      {
+        const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
+        myGraphicDriver->EraseStructure   (MyCView, *aStructComp->CStructure());
+        myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
+      }
+    }
+    return;
+  }
 
- MyGraphicDriver -> SetBackFacingModel ( MyCView );
+  for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
+  {
+    Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
+    const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
+    if (anAnswer != Visual3d_TOA_COMPUTE)
+    {
+      continue;
+    }
 
-}  // end Visual3d_View :: SetBackFacingModel
+    const Standard_Integer anIndex = IsComputed (aStruct);
+    if (anIndex != 0)
+    {
+      myGraphicDriver->EraseStructure   (MyCView, *aStruct->CStructure());
+      myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
 
-Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {
+      Display (aStruct, Aspect_TOU_WAIT);
+      if (aStruct->IsHighlighted())
+      {
+        const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
+        if (!aCompStruct->IsHighlighted())
+        {
+          aCompStruct->SetHighlightColor (aStruct->HighlightColor());
+          aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
+        }
+      }
+    }
+    else
+    {
+      TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
+      aStruct->Transform (aTrsf);
+      Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
+      aCompStruct->SetHLRValidation (Standard_True);
+
+      const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
+      const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
+                                                && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
+      const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
+                                                && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
+      if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
+      if (toComputeShading  ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
+
+      if (aStruct->IsHighlighted())
+      {
+        aCompStruct->SetHighlightColor (aStruct->HighlightColor());
+        aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
+      }
 
- switch ( MyCView.Backfacing ) {
+      Standard_Boolean hasResult = Standard_False;
+      const Standard_Integer aNbToCompute = myStructsToCompute.Length();
+      const Standard_Integer aStructId    = aStruct->Identification();
+      for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
+      {
+        if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
+        {
+          hasResult = Standard_True;
+          myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
+          break;
+        }
+      }
 
-  case 0:
-   return Visual3d_TOBM_AUTOMATIC;
+      if (!hasResult)
+      {
+        myStructsToCompute.Append (aStruct);
+        myStructsComputed .Append (aCompStruct);
+      }
 
-  case 1:
-   return Visual3d_TOBM_FORCE;
+      myGraphicDriver->EraseStructure   (MyCView, *aStruct->CStructure());
+      myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
+    }
+  }
+  Update (myViewManager->UpdateMode());
+}
 
- }  // end switch
+// =======================================================================
+// function : ComputedMode
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::ComputedMode() const
+{
+  return myIsInComputedMode;
+}
 
- return Visual3d_TOBM_DISABLE;
+// =======================================================================
+// function : SetBackFacingModel
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
+{
+  switch (theModel)
+  {
+    default:
+    case Visual3d_TOBM_AUTOMATIC:
+      MyCView.Backfacing = 0;
+      break;
+    case Visual3d_TOBM_FORCE:
+      MyCView.Backfacing = 1;
+      break;
+    case Visual3d_TOBM_DISABLE:
+      MyCView.Backfacing = -1;
+      break;
+  }
+  myGraphicDriver->SetBackFacingModel (MyCView);
+}
 
-}  // end Visual3d_View :: BackFacingModel
+// =======================================================================
+// function : BackFacingModel
+// purpose  :
+// =======================================================================
+Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
+{
+  switch (MyCView.Backfacing)
+  {
+    case 0: return Visual3d_TOBM_AUTOMATIC;
+    case 1: return Visual3d_TOBM_FORCE;
+  }
+  return Visual3d_TOBM_DISABLE;
+}
 
-void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
+// =======================================================================
+// function : EnableDepthTest
+// purpose  :
+// =======================================================================
+void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
 {
-  MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
+  myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
 }
 
+// =======================================================================
+// function : IsDepthTestEnabled
+// purpose  :
+// =======================================================================
 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
 {
-  return MyGraphicDriver->IsDepthTestEnabled( MyCView );
+  return myGraphicDriver->IsDepthTestEnabled (MyCView);
 }
 
-void Visual3d_View::ReadDepths(const Standard_Integer x,
-                               const Standard_Integer y,
-                               const Standard_Integer width,
-                               const Standard_Integer height,
-                               const Standard_Address buffer) const
+// =======================================================================
+// function : ReadDepths
+// purpose  :
+// =======================================================================
+void Visual3d_View::ReadDepths (const Standard_Integer theX,
+                                const Standard_Integer theY,
+                                const Standard_Integer theWidth,
+                                const Standard_Integer theHeight,
+                                const Standard_Address theBuffer) const
 {
-  MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
+  myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
 }
 
+// =======================================================================
+// function : FBOCreate
+// purpose  :
+// =======================================================================
 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
                                                   const Standard_Integer theHeight)
 {
-  return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
+  return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
 }
 
+// =======================================================================
+// function : FBORelease
+// purpose  :
+// =======================================================================
 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
 {
-  MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
+  myGraphicDriver->FBORelease( MyCView, theFBOPtr );
 }
 
+// =======================================================================
+// function : FBOGetDimensions
+// purpose  :
+// =======================================================================
 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
                                      Standard_Integer& theWidth,    Standard_Integer& theHeight,
                                      Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
 {
-  MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
+  myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
                                      theWidth, theHeight,
                                      theWidthMax, theHeightMax );
 }
 
+// =======================================================================
+// function : FBOChangeViewport
+// purpose  :
+// =======================================================================
 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
                                       const Standard_Integer theWidth, const Standard_Integer theHeight)
 {
-  MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
+  myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
                                      theWidth, theHeight );
 }
 
+// =======================================================================
+// function : BufferDump
+// purpose  :
+// =======================================================================
 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap&               theImage,
                                             const Graphic3d_BufferType& theBufferType)
 {
-  return MyGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
+  return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
 }
 
+// =======================================================================
+// function : EnableGLLight
+// purpose  :
+// =======================================================================
 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
 {
-  MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
+  myGraphicDriver->SetGLLightEnabled( MyCView, enable );
 }
 
-
+// =======================================================================
+// function : IsGLLightEnabled
+// purpose  :
+// =======================================================================
 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
 {
-  return MyGraphicDriver->IsGLLightEnabled( MyCView );
+  return myGraphicDriver->IsGLLightEnabled( MyCView );
 }
 
+// =======================================================================
+// function : Export
+// purpose  :
+// =======================================================================
 Standard_Boolean Visual3d_View::Export (const Standard_CString       theFileName,
                                         const Graphic3d_ExportFormat theFormat,
                                         const Graphic3d_SortType     theSortType,
@@ -2874,8 +2720,8 @@ Standard_Boolean Visual3d_View::Export (const Standard_CString       theFileName
                                         const Standard_Address       theProgressBarFunc,
                                         const Standard_Address       theProgressObject) const
 {
-  Handle(Visual3d_Layer) anUnderLayer = MyViewManager->UnderLayer();
-  Handle(Visual3d_Layer) anOverLayer  = MyViewManager->OverLayer();
+  Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
+  Handle(Visual3d_Layer) anOverLayer  = myViewManager->OverLayer();
 
   Aspect_CLayer2d anOverCLayer;
   Aspect_CLayer2d anUnderCLayer;
@@ -2889,38 +2735,92 @@ Standard_Boolean Visual3d_View::Export (const Standard_CString       theFileName
   Standard_Integer aWidth, aHeight;
   Window()->Size (aWidth, aHeight);
 
-  return MyGraphicDriver->Export (theFileName, theFormat, theSortType,
+  return myGraphicDriver->Export (theFileName, theFormat, theSortType,
                                   aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
                                   thePrecision, theProgressBarFunc, theProgressObject);
 }
 
-//=======================================================================
-//function : AddZLayer
-//purpose  :
-//=======================================================================
+// =======================================================================
+// function : SetZLayerSettings
+// purpose  :
+// =======================================================================
+void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
+                                       const Graphic3d_ZLayerSettings& theSettings)
+{
+  myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
+}
 
+// =======================================================================
+// function : AddZLayer
+// purpose  :
+// =======================================================================
 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
 {
-  MyGraphicDriver->AddZLayer (MyCView, theLayerId);
+  myGraphicDriver->AddZLayer (MyCView, theLayerId);
 }
 
-//=======================================================================
-//function : RemoveZLayer
-//purpose  :
-//=======================================================================
-
+// =======================================================================
+// function : RemoveZLayer
+// purpose  :
+// =======================================================================
 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
 {
-  MyGraphicDriver->RemoveZLayer (MyCView, theLayerId);
+  myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
 }
 
-//=======================================================================
-//function : ChangeZLayer
-//purpose  :
-//=======================================================================
-
+// =======================================================================
+// function : ChangeZLayer
+// purpose  :
+// =======================================================================
 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
                                   const Standard_Integer theLayerId)
 {
-  MyGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
+  myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
+}
+
+// =======================================================================
+// function : Print
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::Print (const Aspect_Handle    thePrintDC, 
+                                       const Standard_Boolean theToShowBackground,
+                                       const Standard_CString theFilename,
+                                       const Aspect_PrintAlgo thePrintAlgorithm,
+                                       const Standard_Real    theScaleFactor) const
+{
+  return Print (myViewManager->UnderLayer(),
+                myViewManager->OverLayer(),
+                thePrintDC, theToShowBackground,
+                theFilename, thePrintAlgorithm, 
+                theScaleFactor);
+}
+
+// =======================================================================
+// function : Print
+// purpose  :
+// =======================================================================
+Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
+                                       const Handle(Visual3d_Layer)& theOverLayer,
+                                       const Aspect_Handle           thePrintDC,
+                                       const Standard_Boolean        theToShowBackground,
+                                       const Standard_CString        theFilename,
+                                       const Aspect_PrintAlgo        thePrintAlgorithm,
+                                       const Standard_Real           theScaleFactor) const
+{
+  if (IsDeleted()
+  || !IsDefined()
+  || !IsActive()
+  || !MyWindow->IsMapped())
+  {
+    return Standard_False;
+  }
+
+  Aspect_CLayer2d anOverCLayer;
+  Aspect_CLayer2d anUnderCLayer;
+  anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
+  if (!theOverLayer.IsNull())  anOverCLayer  = theOverLayer->CLayer();
+  if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
+  return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
+                                 thePrintDC, theToShowBackground, theFilename,
+                                 thePrintAlgorithm, theScaleFactor);
 }