0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / V3d / V3d_View.cxx
index 53a1184..7db3ad0 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-/***********************************************************************
-FONCTION :
-----------
-Classe V3d_View :
-HISTORIQUE DES MODIFICATIONS   :
---------------------------------
-00-09-92 : GG  ; Creation.
-02-10-96 : FMN ; Suppression appel Redraw sans MustBeResized()
-05-06-97 : FMN ; Correction FitAll()
-30-06-97 : GG ; Correction + Optimisation de Panning(...)
-On fait la translation + le zoom en une seule
-operation au lieu de 2 precedemment qui etait buggee.
-09-07-97 : FMN ; Correction FitAll() sur le Ratio
-16-07-97 : FMN ; Correction FitAll() sur le calcul de la Box
-22-07-97 : FMN ; Ajout mode RetainMode pour le Transient
-15-12-97 : FMN ; Ajout texture mapping
-17-12-97 : FMN ; CTS19129 Correction FitAll() multiple
-18-12-97 : FMN ; Ajout mode Ajout
-24-12-97 : FMN ; Remplacement de math par MathGra
-24-12-97 : CQO ; BUC50037 Xw_Window -> Aspect_Window
-31-12-97 : CAL ; Remplacement de MathGra par Array2OfReal
-07-01-98 : CAL ; Ajout de la methode DoMapping.
-07-01-98 : CAL ; Retrait de tous les "this->" inutiles
-21-01-98 : CAL ; Remplacement des Window->Position () par Window->Size ()
-27-01-98 : FMN ; PERF: OPTIMISATION LOADER (LOPTIM)
-12-02-98 : GG  ; Reactivation du Redraw dans MustBeResized()
-23-02-98 : FMN ; Remplacement PI par Standard_PI
-25-02-98 : FMN ; PERF.27: Optimisation of view creation from existing view
-11-03-98 : STT ; S3558
-19-03-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
-ne marche pas.
-08-04-98 : STT ; suppr. S3558
-10-04-98 : CAL ; Ajout des methodes RefToPix et PixToRef
-13-06-98 : FMN ; Probleme dans FitAll car la methode WNT_Window::Size(Real,Real)
-ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
-16-08-98 : CAL ; S3892. Ajout grilles 3d.
-09-09-98 : CAL ; S3892. Generalisation de TrsPoint.
-06-10-98 : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
-16-10-98 : CAL ; Retrait d'un TIMER si CSF_GraphicTimer est definie.
-06-11-98 : CAL ; PRO ?????. Probleme dans ZFitAll si un point dans la vue.
-29-OCT-98 : DCB : Adding ScreenCopy () method.
-REMARQUES :
------------
-About  FitAll() multiple. This probleme is caused by missing
-precision of transformation matrices. If it is supposed that
-projection is made in the plane (U,V), there is a difference
-after several Zoom - compared to the exact value (cf ZoomX).
-Don't forget that the matrices work in float and not in double.
-To solve the problem (for lack of a better solution) I make 2 passes.
-************************************************************************/
-/*----------------------------------------------------------------------*/
-/*
-* Includes
-*/
-
-#include <Aspect_ColorScale.hxx>
+#include <V3d_View.hxx>
+
 #include <Aspect_GradientBackground.hxx>
 #include <Aspect_Grid.hxx>
 #include <Aspect_Window.hxx>
@@ -83,6 +29,8 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 #include <Graphic3d_TextureEnv.hxx>
 #include <Graphic3d_Vector.hxx>
 #include <Image_AlienPixMap.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
 #include <NCollection_Array1.hxx>
 #include <Precision.hxx>
 #include <Quantity_Color.hxx>
@@ -93,30 +41,17 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 #include <Standard_ShortReal.hxx>
 #include <Standard_Type.hxx>
 #include <Standard_TypeMismatch.hxx>
+#include <TColgp_Array1OfPnt.hxx>
 #include <TColStd_Array2OfReal.hxx>
 #include <TColStd_HSequenceOfInteger.hxx>
 #include <V3d.hxx>
 #include <V3d_BadValue.hxx>
-#include <V3d_LayerMgr.hxx>
 #include <V3d_Light.hxx>
 #include <V3d_StereoDumpOptions.hxx>
 #include <V3d_UnMapped.hxx>
-#include <V3d_View.hxx>
 #include <V3d_Viewer.hxx>
-#include <Visual3d_Layer.hxx>
-#include <Visual3d_Light.hxx>
-#include <Visual3d_View.hxx>
-#include <Visual3d_ViewManager.hxx>
-
-#define V3d_FLAG_COMPUTATION   0x00000004
 
-// Perspective
-#include <OSD_Environment.hxx>
-
-/*----------------------------------------------------------------------*/
-/*
-* Constant
-*/
+IMPLEMENT_STANDARD_RTTIEXT(V3d_View,MMgt_TShared)
 
 #define DEUXPI (2. * M_PI)
 
@@ -129,205 +64,134 @@ namespace
 //function : Constructor
 //purpose  :
 //=============================================================================
-V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
-  MyViewer(VM.operator->()),
-  MyActiveLights(),
-  MyViewContext (),
-  myActiveLightsIterator(),
-  SwitchSetFront(Standard_False),
+V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType)
+: MyViewer (theViewer.operator->()),
+  SwitchSetFront (Standard_False),
+  myZRotation (Standard_False),
+  myTrihedron (new V3d_Trihedron()),
   MyTrsf (1, 4, 1, 4)
 {
-  myImmediateUpdate = Standard_False;
-  MyView = new Visual3d_View(MyViewer->Viewer());
-
-  // { Begin to retrieve the definition from ViewContext.
-  // Step MyViewContext = MyView->Context() ;
-  // to permit MyView->SetContext to compare
-  // the old and the new context.
-  // No problem for MyViewMapping, MyViewOrientation
-  // as MyView->SetViewMapping and MyView->SetViewOrientation
-  // don't try to optimize the modifications introduced to
-  // viewmapping and vieworientation.
-
-  // Aliasing
-  if ((MyView->Context ()).AliasingIsOn ())
-    MyViewContext.SetAliasingOn ();
-  else
-    MyViewContext.SetAliasingOff ();
-
-  // DepthCueing
-  MyViewContext.SetDepthCueingBackPlane
-    ((MyView->Context ()).DepthCueingBackPlane ());
-  MyViewContext.SetDepthCueingFrontPlane
-    ((MyView->Context ()).DepthCueingFrontPlane ());
-
-  if ((MyView->Context ()).DepthCueingIsOn ())
-    MyViewContext.SetDepthCueingOn ();
-  else
-    MyViewContext.SetDepthCueingOff ();
-
-  // ZClipping
-  MyViewContext.SetZClippingBackPlane
-    ((MyView->Context ()).ZClippingBackPlane ());
-  MyViewContext.SetZClippingFrontPlane
-    ((MyView->Context ()).ZClippingFrontPlane ());
-
-  if ((MyView->Context ()).FrontZClippingIsOn ())
-    MyViewContext.SetFrontZClippingOn ();
-  else
-    MyViewContext.SetFrontZClippingOff ();
-
-  if ((MyView->Context ()).BackZClippingIsOn ())
-    MyViewContext.SetBackZClippingOn ();
-  else
-    MyViewContext.SetBackZClippingOff ();
-
-  // Visualization and Shading Model
-  MyViewContext.SetModel ((MyView->Context ()).Model ());
-  MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
+  myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
 
-  // Texture Mapping
-  MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
-  MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
-  // } End of retrieval of the definition of ViewContext.
+  myView->SetBackground         (theViewer->GetBackgroundColor());
+  myView->SetGradientBackground (theViewer->GetGradientBackground());
 
-  MyBackground = VM->GetBackgroundColor() ;
-  MyGradientBackground = VM->GetGradientBackground() ;
+  ChangeRenderingParams() = theViewer->DefaultRenderingParams();
 
   // camera init
   Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
   aCamera->SetFOVy (45.0);
   aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
   aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
-  SetCamera (aCamera);
+  aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
+    ? Graphic3d_Camera::Projection_Orthographic
+    : Graphic3d_Camera::Projection_Perspective);
 
+  myDefaultCamera = new Graphic3d_Camera();
+
+  myImmediateUpdate = Standard_False;
+  SetAutoZFitMode (Standard_True, 1.0);
+  SetBackFacingModel (V3d_TOBM_AUTOMATIC);
+  SetCamera (aCamera);
   SetAxis (0.,0.,0.,1.,1.,1.);
-  SetVisualization (VM->DefaultVisualization());
-  SetShadingModel (VM->DefaultShadingModel());
-  SetSurfaceDetail (VM->DefaultSurfaceDetail());
+  SetVisualization (theViewer->DefaultVisualization());
+  SetShadingModel (theViewer->DefaultShadingModel());
   SetTwist (0.);
   SetAt (0.,0.,0.);
-  SetProj (VM->DefaultViewProj());
-  SetSize (VM->DefaultViewSize());
-  Standard_Real zsize = VM->DefaultViewSize();
+  SetProj (theViewer->DefaultViewProj());
+  SetSize (theViewer->DefaultViewSize());
+  Standard_Real zsize = theViewer->DefaultViewSize();
   SetZSize (2.*zsize);
-  SetZClippingDepth (0.);
-  SetZClippingWidth (zsize);
-  SetZCueingDepth (0.);
-  SetZCueingWidth (zsize);
-  SetDepth (VM->DefaultViewSize()/2.0);
+  SetDepth (theViewer->DefaultViewSize() / 2.0);
   SetViewMappingDefault();
   SetViewOrientationDefault();
-  VM->AddView (this);
+  theViewer->AddView (this);
   Init();
   myImmediateUpdate = Standard_True;
-
-  aCamera->SetProjectionType ((Type == V3d_ORTHOGRAPHIC)
-    ? Graphic3d_Camera::Projection_Orthographic
-    : Graphic3d_Camera::Projection_Perspective);
 }
 
 //=============================================================================
 //function : Constructor
 //purpose  :
 //=============================================================================
-V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) :
-  MyViewer(theVM.operator->()),
-  MyActiveLights(),
-  MyViewContext (),
-  myActiveLightsIterator(),
+V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView)
+: MyViewer (theViewer.operator->()),
   SwitchSetFront(Standard_False),
+  myZRotation (Standard_False),
   MyTrsf (1, 4, 1, 4)
 {
-  Handle(Visual3d_View) aFromView = theView->View();
+  myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
 
-  myImmediateUpdate = Standard_False;
-  MyView = new Visual3d_View (MyViewer->Viewer());
-
-  for (theView->InitActiveLights(); theView->MoreActiveLights(); theView->NextActiveLights())
-  {
-    MyActiveLights.Append (theView->ActiveLight());
-  }
-
-  MyViewContext = aFromView->Context() ;
-
-  SetCamera (new Graphic3d_Camera (theView->Camera()));
-  View()->SetAutoZFitMode (theView->View()->AutoZFitMode(), theView->View()->AutoZFitScaleFactor());
-
-  MyBackground = aFromView->Background() ;
-  MyGradientBackground = aFromView->GradientBackground();
+  myView->CopySettings (theView->View());
 
-  MyView->SetContext (MyViewContext) ;
+  myDefaultCamera = new Graphic3d_Camera();
 
+  myImmediateUpdate = Standard_False;
+  SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
   SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
-
   SetViewMappingDefault();
   SetViewOrientationDefault();
-  theVM->AddView (this);
-
+  theViewer->AddView (this);
   Init();
-
   myImmediateUpdate = Standard_True;
 }
 
 //=============================================================================
-//function : SetMagnify
+//function : Destructor
 //purpose  :
 //=============================================================================
-void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
-                          const Handle(V3d_View)& aPreviousView,
-                          const Standard_Integer x1,
-                          const Standard_Integer y1,
-                          const Standard_Integer x2,
-                          const Standard_Integer y2)
-{
-  if( !MyView->IsDefined() ) {
-    Standard_Real a,b,c,d;
-    aPreviousView->Convert(x1,y1,a,b);
-    aPreviousView->Convert(x2,y2,c,d);
-    MyView->SetWindow(TheWindow) ;
-    FitAll(TheWindow,a,b,c,d);
-    MyView->SetContext(MyViewContext) ;
-    MyView->SetBackground(MyBackground) ;
-    MyViewer->SetViewOn(this) ;
-    MyWindow = TheWindow;
-    MyView->Redraw() ;
-    SetViewMappingDefault();
+V3d_View::~V3d_View()
+{
+  if (!myView->IsRemoved())
+  {
+    myView->Remove();
   }
 }
 
 //=============================================================================
-//function : SetWindow
+//function : SetMagnify
 //purpose  :
 //=============================================================================
-void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
+void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow,
+                           const Handle(V3d_View)& thePreviousView,
+                           const Standard_Integer theX1,
+                           const Standard_Integer theY1,
+                           const Standard_Integer theX2,
+                           const Standard_Integer theY2)
 {
-  MyView->SetWindow(TheWindow) ;
-  // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
-  MyWindow = TheWindow;
-  // SetWindow carries out SetRatio and modifies
-  MyView->SetContext(MyViewContext) ;
-  MyView->SetBackground(MyBackground) ;
-  MyViewer->SetViewOn(this) ;
-  MyView->Redraw() ;
+  if (!myView->IsRemoved() && !myView->IsDefined())
+  {
+    Standard_Real aU1, aV1, aU2, aV2;
+    thePreviousView->Convert (theX1, theY1, aU1, aV1);
+    thePreviousView->Convert (theX2, theY2, aU2, aV2);
+    myView->SetWindow (theWindow);
+    FitAll (aU1, aV1, aU2, aV2);
+    MyViewer->SetViewOn (this);
+    MyWindow = theWindow;
+    SetRatio();
+    Redraw();
+    SetViewMappingDefault();
+  }
 }
 
 //=============================================================================
 //function : SetWindow
 //purpose  :
 //=============================================================================
-void V3d_View::SetWindow(const Handle(Aspect_Window)&      aWindow,
-                         const Aspect_RenderingContext     aContext,
-                         const Aspect_GraphicCallbackProc& aDisplayCB,
-                         const Standard_Address            aClientData)
+void V3d_View::SetWindow (const Handle(Aspect_Window)&  theWindow,
+                          const Aspect_RenderingContext theContext)
 {
+  if (myView->IsRemoved())
+  {
+    return;
+  }
+
   // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
-  MyWindow = aWindow;
-  MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
-  MyView->SetContext(MyViewContext) ;
-  MyView->SetBackground(MyBackground) ;
-  MyViewer->SetViewOn(this) ;
-  MyView->Redraw() ;
+  MyWindow = theWindow;
+  myView->SetWindow (theWindow, theContext);
+  MyViewer->SetViewOn (this);
+  SetRatio();
+  Redraw();
 }
 
 //=============================================================================
@@ -337,7 +201,7 @@ void V3d_View::SetWindow(const Handle(Aspect_Window)&      aWindow,
 void V3d_View::Remove() const
 {
   MyViewer->DelView (this);
-  MyView->Remove();
+  myView->Remove();
   Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
   aWin.Nullify();
 }
@@ -348,7 +212,15 @@ void V3d_View::Remove() const
 //=============================================================================
 void V3d_View::Update() const
 {
-  if( MyView->IsDefined() )  MyView->Update (Aspect_TOU_ASAP) ;
+  if (!myView->IsDefined()
+   || !myView->IsActive())
+  {
+    return;
+  }
+
+  myView->Update();
+  myView->Compute();
+  myView->Redraw();
 }
 
 //=============================================================================
@@ -357,7 +229,31 @@ void V3d_View::Update() const
 //=============================================================================
 void V3d_View::Redraw() const
 {
-  if( MyView->IsDefined() ) MyView->Redraw() ;
+  if (!myView->IsDefined()
+   || !myView->IsActive())
+  {
+    return;
+  }
+
+  Handle(Graphic3d_GraphicDriver)    aGraphicDriver = MyViewer->Driver();
+  Handle(Graphic3d_StructureManager) aStructureMgr  = MyViewer->StructureManager();
+  for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
+  {
+    if (aGraphicDriver->IsDeviceLost())
+    {
+      aStructureMgr->RecomputeStructures();
+      aGraphicDriver->ResetDeviceLostFlag();
+    }
+
+    AutoZFit();
+
+    myView->Redraw();
+
+    if (!aGraphicDriver->IsDeviceLost())
+    {
+      return;
+    }
+  }
 }
 
 //=============================================================================
@@ -366,10 +262,13 @@ void V3d_View::Redraw() const
 //=============================================================================
 void V3d_View::RedrawImmediate() const
 {
-  if (MyView->IsDefined())
+  if (!myView->IsDefined()
+   || !myView->IsActive())
   {
-    MyView->RedrawImmediate();
+    return;
   }
+
+  myView->RedrawImmediate();
 }
 
 //=============================================================================
@@ -378,10 +277,12 @@ void V3d_View::RedrawImmediate() const
 //=============================================================================
 void V3d_View::Invalidate() const
 {
-  if (MyView->IsDefined())
+  if (!myView->IsDefined())
   {
-    MyView->Invalidate();
+    return;
   }
+
+  myView->Invalidate();
 }
 
 //=============================================================================
@@ -390,36 +291,64 @@ void V3d_View::Invalidate() const
 //=============================================================================
 Standard_Boolean V3d_View::IsInvalidated() const
 {
-  return !MyView->IsDefined()
-       || MyView->IsInvalidated();
+  return !myView->IsDefined()
+       || myView->IsInvalidated();
 }
 
-//=============================================================================
-//function : AutoZFit
-//purpose  :
-//=============================================================================
-void V3d_View::AutoZFit()
+// ========================================================================
+// function : SetAutoZFitMode
+// purpose  :
+// ========================================================================
+void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
+                                const Standard_Real    theScaleFactor)
 {
-  View()->AutoZFit();
+  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+  myAutoZFitScaleFactor = theScaleFactor;
+  myAutoZFitIsOn = theIsOn;
+}
+
+// ========================================================================
+// function : AutoZFitMode
+// purpose  :
+// ========================================================================
+Standard_Boolean V3d_View::AutoZFitMode() const
+{
+  return myAutoZFitIsOn;
+}
+
+// ========================================================================
+// function : AutoZFitScaleFactor
+// purpose  :
+// ========================================================================
+Standard_Real V3d_View::AutoZFitScaleFactor() const
+{
+  return myAutoZFitScaleFactor;
 }
 
 //=============================================================================
-//function : ZFitAll
+//function : AutoZFit
 //purpose  :
 //=============================================================================
-void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
+void V3d_View::AutoZFit() const
 {
-  View()->ZFitAll (theScaleFactor);
+  if (!AutoZFitMode())
+  {
+    return;
+  }
+
+  ZFitAll (myAutoZFitScaleFactor);
 }
 
 //=============================================================================
-//function : Redraw
+//function : ZFitAll
 //purpose  :
 //=============================================================================
-void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
-                      const Standard_Integer width,const Standard_Integer height) const
+void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const
 {
-  if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
+  Bnd_Box aMinMaxBox   = myView->MinMaxValues (Standard_False); // applicative min max boundaries
+  Bnd_Box aGraphicBox  = myView->MinMaxValues (Standard_True);  // real graphical boundaries (not accounting infinite flag).
+
+  myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
 }
 
 //=============================================================================
@@ -429,8 +358,8 @@ void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
 Standard_Boolean V3d_View::IsEmpty() const
 {
   Standard_Boolean TheStatus = Standard_True ;
-  if( MyView->IsDefined() ) {
-    Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+  if( myView->IsDefined() ) {
+    Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
     if( Nstruct > 0 ) TheStatus = Standard_False ;
   }
   return (TheStatus) ;
@@ -442,7 +371,12 @@ Standard_Boolean V3d_View::IsEmpty() const
 //=============================================================================
 void V3d_View::UpdateLights() const
 {
-  MyView->SetContext(MyViewContext);
+  Graphic3d_ListOfCLight aLights;
+  for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
+  {
+    aLights.Append (anActiveLightIter.Value()->Light());
+  }
+  myView->SetLights (aLights);
   Update();
 }
 
@@ -452,9 +386,12 @@ void V3d_View::UpdateLights() const
 //=============================================================================
 void V3d_View::DoMapping()
 {
-  if( MyView->IsDefined() ) {
-    (MyView->Window())->DoMapping() ;
+  if (!myView->IsDefined())
+  {
+    return;
   }
+
+  myView->Window()->DoMapping();
 }
 
 //=============================================================================
@@ -463,118 +400,109 @@ void V3d_View::DoMapping()
 //=============================================================================
 void V3d_View::MustBeResized()
 {
-  if ( !MyLayerMgr.IsNull() )
-    MyLayerMgr->Resized();
-
-  if( MyView->IsDefined() ) {
-    MyView->Resized() ;
-    MyView->Redraw();
+  if (!myView->IsDefined())
+  {
+    return;
   }
-}
 
-//=============================================================================
-//function : SetBackgroundColor
-//purpose  :
-//=============================================================================
-void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
-{
-  Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
-  Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 );
-  Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 );
+  myView->Resized();
 
-  Quantity_Color C( V1, V2, V3, Type );
-  SetBackgroundColor( C );
+  SetRatio();
+
+  Redraw();
 }
 
 //=============================================================================
 //function : SetBackgroundColor
 //purpose  :
 //=============================================================================
-void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
+void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
+                                   const Standard_Real theV1,
+                                   const Standard_Real theV2,
+                                   const Standard_Real theV3)
 {
-  MyBackground.SetColor( Color );
-  if ( MyView->IsDefined() )
-    MyView->SetBackground( MyBackground );
-  //szv: Why?
-  if ( !MyLayerMgr.IsNull() )
-    MyLayerMgr->Resized();
+  Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0);
+  Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0);
+  Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0);
+
+  SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
 }
 
 //=============================================================================
 //function : SetBackgroundColor
 //purpose  :
 //=============================================================================
-void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
+void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
 {
-  Quantity_Color C( Name );
-  SetBackgroundColor( C );
-}
+  myView->SetBackground (Aspect_Background (theColor));
 
-//=============================================================================
-//function : SetBgGradientColors
-//purpose  :
-//=============================================================================
-void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
-                                    const Quantity_Color& Color2,
-                                    const Aspect_GradientFillMethod FillStyle,
-                                    const Standard_Boolean status)
-{
-  MyGradientBackground.SetColors(Color1, Color2, FillStyle);
-  if ( MyView->IsDefined() )
-    MyView->SetGradientBackground( MyGradientBackground, status );
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
 //function : SetBgGradientColors
 //purpose  :
 //=============================================================================
-void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
-                                    const Quantity_NameOfColor Color2,
-                                    const Aspect_GradientFillMethod FillStyle,
-                                    const Standard_Boolean status )
+void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
+                                    const Quantity_Color& theColor2,
+                                    const Aspect_GradientFillMethod theFillStyle,
+                                    const Standard_Boolean theToUpdate)
 {
-  Quantity_Color C1( Color1 );
-  Quantity_Color C2( Color2 );
-  MyGradientBackground.SetColors( C1, C2, FillStyle );
-  if ( MyView->IsDefined() )
-    MyView->SetGradientBackground( MyGradientBackground, status );
+  Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
+
+  myView->SetGradientBackground (aGradientBg);
+
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
 //function : SetBgGradientStyle
 //purpose  :
 //=============================================================================
-void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
-                                   const Standard_Boolean update)
+void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate)
 {
-  Quantity_Color Color1, Color2;
-  MyGradientBackground.Colors( Color1, Color2 );
-  MyGradientBackground.SetColors( Color1, Color2, FillStyle );
-  if( MyView->IsDefined() )
-    MyView->SetBgGradientStyle( FillStyle, update ) ;
+  Quantity_Color aColor1;
+  Quantity_Color aColor2;
+  GradientBackground().Colors (aColor1, aColor2);
+
+  SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
 }
 
 //=============================================================================
 //function : SetBackgroundImage
 //purpose  :
 //=============================================================================
-void V3d_View::SetBackgroundImage( const Standard_CString FileName,
-                                   const Aspect_FillMethod FillStyle,
-                                   const Standard_Boolean update )
+void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
+                                   const Aspect_FillMethod theFillStyle,
+                                   const Standard_Boolean theToUpdate)
 {
-  if( MyView->IsDefined() )
-    MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
+  myView->SetBackgroundImage (theFileName);
+  myView->SetBackgroundImageStyle (theFillStyle);
+
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
 //function : SetBgImageStyle
 //purpose  :
 //=============================================================================
-void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
-                                const Standard_Boolean update )
+void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
 {
-  if( MyView->IsDefined() )
-    MyView->SetBgImageStyle( FillStyle, update ) ;
+  myView->SetBackgroundImageStyle (theFillStyle);
+
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
@@ -596,40 +524,37 @@ void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Stand
 //function : SetShadingModel
 //purpose  :
 //=============================================================================
-void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model)
+void V3d_View::SetShadingModel (const V3d_TypeOfShadingModel theShadingModel)
 {
-  MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
-  MyView->SetContext(MyViewContext) ;
-}
-
-//=============================================================================
-//function : SetSurfaceDetail
-//purpose  :
-//=============================================================================
-void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model)
-{
-  MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
-  MyView->SetContext(MyViewContext) ;
+  myView->SetShadingModel (static_cast<Graphic3d_TypeOfShadingModel> (theShadingModel));
 }
 
 //=============================================================================
 //function : SetTextureEnv
 //purpose  :
 //=============================================================================
-void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
+void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
 {
-  MyViewContext.SetTextureEnv(ATexture) ;
-  MyView->SetContext(MyViewContext) ;
+  myView->SetTextureEnv (theTexture);
+
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
 //function : SetVisualization
 //purpose  :
 //=============================================================================
-void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode)
+void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
 {
-  MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
-  MyView->SetContext(MyViewContext) ;
+  myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
+
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
 //=============================================================================
@@ -645,14 +570,22 @@ void V3d_View::SetFront()
   a.YDirection().Coord(xu,yu,zu);
   a.Location().Coord(xo,yo,zo);
 
-  myCamera->SetCenter (gp_Pnt (xo, yo, zo));
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  aCamera->SetCenter (gp_Pnt (xo, yo, zo));
+
   if(SwitchSetFront)
-    myCamera->SetDirection (gp_Dir (vx, vy, vz));
+  {
+    aCamera->SetDirection (gp_Dir (vx, vy, vz));
+  }
   else
-    myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
-  myCamera->SetUp (gp_Dir (xu, yu, zu));
+  {
+    aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
+  }
+
+  aCamera->SetUp (gp_Dir (xu, yu, zu));
 
-  View()->AutoZFit();
+  AutoZFit();
 
   SwitchSetFront = !SwitchSetFront;
 
@@ -679,16 +612,18 @@ void V3d_View::Rotate (const Standard_Real ax,
   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if (Start)
   {
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   // rotate camera around 3 initial axes
   gp_Dir aBackDir (gp_Vec (myCamStartOpCenter, myCamStartOpEye));
@@ -704,9 +639,9 @@ void V3d_View::Rotate (const Standard_Real ax,
   aTrsf.Multiply (aRot[1]);
   aTrsf.Multiply (aRot[2]);
 
-  myCamera->Transform (aTrsf);
+  aCamera->Transform (aTrsf);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -730,25 +665,27 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan
   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if (Start)
   {
     myGravityReferencePoint.SetCoord (X, Y, Z);
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
   const Graphic3d_Vertex& aVref = myGravityReferencePoint;
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   // rotate camera around 3 initial axes
   gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
 
-  gp_Dir aZAxis (myCamera->Direction().Reversed());
-  gp_Dir aYAxis (myCamera->Up());
+  gp_Dir aZAxis (aCamera->Direction().Reversed());
+  gp_Dir aYAxis (aCamera->Up());
   gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); 
 
   gp_Trsf aRot[3], aTrsf;
@@ -759,9 +696,9 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan
   aTrsf.Multiply (aRot[1]);
   aTrsf.Multiply (aRot[2]);
 
-  myCamera->Transform (aTrsf);
+  aCamera->Transform (aTrsf);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -797,12 +734,14 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if (Start)
   {
     myGravityReferencePoint.SetCoord (X, Y, Z);
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
 
     switch (Axe) {
     case V3d_X :
@@ -816,16 +755,16 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
       break ;
     }
 
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
   const Graphic3d_Vertex& aVref = myGravityReferencePoint;
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   // rotate camera around passed axis
   gp_Trsf aRotation;
@@ -835,9 +774,10 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
                   (Axe == V3d_Z) ? 1.0 : 0.0);
 
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
-  myCamera->Transform (aRotation);
 
-  View()->AutoZFit();
+  aCamera->Transform (aRotation);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -853,26 +793,29 @@ void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if( Start ) {
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
   const Graphic3d_Vertex& aPnt = MyDefaultViewPoint;
   const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   gp_Trsf aRotation;
   gp_Pnt aRCenter (aPnt.X(), aPnt.Y(), aPnt.Z());
   gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
-  myCamera->Transform (aRotation);
 
-  View()->AutoZFit();
+  aCamera->Transform (aRotation);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -894,20 +837,22 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa
   if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if( Start ) {
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   // rotate camera around 3 initial axes
-  gp_Pnt aRCenter = myCamera->Eye();
-  gp_Dir aZAxis (myCamera->Direction().Reversed());
-  gp_Dir aYAxis (myCamera->Up());
+  gp_Pnt aRCenter = aCamera->Eye();
+  gp_Dir aZAxis (aCamera->Direction().Reversed());
+  gp_Dir aYAxis (aCamera->Up());
   gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); 
 
   gp_Trsf aRot[3], aTrsf;
@@ -918,9 +863,9 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa
   aTrsf.Multiply (aRot[1]);
   aTrsf.Multiply (aRot[2]);
 
-  myCamera->Transform (aTrsf);
+  aCamera->Transform (aTrsf);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -955,25 +900,28 @@ void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if( Start ) {
-    myCamStartOpUp = myCamera->Up();
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
-  myCamera->SetUp (myCamStartOpUp);
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
   const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
 
   gp_Trsf aRotation;
-  gp_Pnt aRCenter = myCamera->Eye();
+  gp_Pnt aRCenter = aCamera->Eye();
   gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
   aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
-  myCamera->Transform (aRotation);
 
-  View()->AutoZFit();
+  aCamera->Transform (aRotation);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -990,7 +938,9 @@ void V3d_View::SetTwist(const Standard_Real angle)
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
-  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_Dir aReferencePlane (aCamera->Direction().Reversed());
   gp_Dir anUp;
 
   anUp = gp_Dir (0.0, 0.0, 1.0);
@@ -1010,8 +960,8 @@ void V3d_View::SetTwist(const Standard_Real angle)
 
   V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
   
-  gp_Pnt aRCenter = myCamera->Center();
-  gp_Dir aZAxis (myCamera->Direction().Reversed());
+  gp_Pnt aRCenter = aCamera->Center();
+  gp_Dir aZAxis (aCamera->Direction().Reversed());
 
   gp_Trsf aTrsf;
   aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
@@ -1019,10 +969,10 @@ void V3d_View::SetTwist(const Standard_Real angle)
   Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
   myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
 
-  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
-  myCamera->Transform (aTrsf);
+  aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+  aCamera->Transform (aTrsf);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1037,10 +987,13 @@ void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard
 
   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  myCamera->SetEye (gp_Pnt (X, Y, Z));
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  aCamera->SetEye (gp_Pnt (X, Y, Z));
+
   SetTwist (aTwistBefore);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1055,22 +1008,24 @@ void V3d_View::SetDepth(const Standard_Real Depth)
 {
   V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if( Depth > 0. )
   {
     // Move eye using center (target) as anchor.
-    myCamera->SetDistance (Depth);
+    aCamera->SetDistance (Depth);
   }
   else
   {
     // Move the view ref point instead of the eye.
-    gp_Vec aDir (myCamera->Direction());
-    gp_Pnt aCameraEye = myCamera->Eye();
+    gp_Vec aDir (aCamera->Direction());
+    gp_Pnt aCameraEye = aCamera->Eye();
     gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
 
-    myCamera->SetCenter (aCameraCenter);
+    aCamera->SetCenter (aCameraCenter);
   }
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1088,11 +1043,11 @@ void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Sta
 
   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
+  Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
 
   SetTwist(aTwistBefore);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1123,18 +1078,20 @@ void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
   const Graphic3d_Vector& aBck = V3d::GetProjAxis (Orientation);
 
   // retain camera panning from origin when switching projection
-  gp_Pnt anOriginVCS = myCamera->ConvertWorld2View (gp::Origin());
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_Pnt anOriginVCS  = aCamera->ConvertWorld2View (gp::Origin());
   Standard_Real aPanX = anOriginVCS.X();
   Standard_Real aPanY = anOriginVCS.Y();
 
-  myCamera->SetCenter (gp_Pnt (0, 0, 0));
-  myCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed());
-  myCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn));
-  myCamera->OrthogonalizeUp();
+  aCamera->SetCenter (gp_Pnt (0, 0, 0));
+  aCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed());
+  aCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn));
+  aCamera->OrthogonalizeUp();
 
   Panning (aPanX, aPanY);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1149,11 +1106,11 @@ void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_
 
   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  myCamera->SetCenter (gp_Pnt (X, Y, Z));
+  Camera()->SetCenter (gp_Pnt (X, Y, Z));
 
   SetTwist (aTwistBefore);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -1170,7 +1127,9 @@ void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standar
   V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
     "V3d_View::SetUp, nullUp vector");
 
-  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_Dir aReferencePlane (aCamera->Direction().Reversed());
   gp_Dir anUp (Vx, Vy, Vz);
 
   TheStatus = ScreenAxis(aReferencePlane,anUp,
@@ -1195,9 +1154,9 @@ void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standar
   Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
   myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
 
-  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+  aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1210,7 +1169,9 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
 {
   Standard_Boolean TheStatus ;
 
-  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_Dir aReferencePlane (aCamera->Direction().Reversed());
   gp_Dir anUp;
 
   const Graphic3d_Vector& aViewReferenceUp = V3d::GetProjAxis(Orientation) ;
@@ -1238,9 +1199,9 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
   Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
   myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
 
-  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+  aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1251,9 +1212,16 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
 //=============================================================================
 void V3d_View::SetViewOrientationDefault()
 {
-  MyView->SetViewOrientationDefault() ;
+  myDefaultCamera->CopyOrientationData (Camera());
+}
 
-  ImmediateUpdate();
+//=======================================================================
+//function : SetViewMappingDefault
+//purpose  :
+//=======================================================================
+void V3d_View::SetViewMappingDefault()
+{
+  myDefaultCamera->CopyMappingData (Camera());
 }
 
 //=============================================================================
@@ -1262,7 +1230,22 @@ void V3d_View::SetViewOrientationDefault()
 //=============================================================================
 void V3d_View::ResetViewOrientation()
 {
-  MyView->ViewOrientationReset() ;
+  Camera()->CopyOrientationData (myDefaultCamera);
+
+  AutoZFit();
+
+  ImmediateUpdate();
+}
+
+//=======================================================================
+//function : ResetViewMapping
+//purpose  :
+//=======================================================================
+void V3d_View::ResetViewMapping()
+{
+  Camera()->CopyMappingData (myDefaultCamera);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1271,21 +1254,18 @@ void V3d_View::ResetViewOrientation()
 //function : Reset
 //purpose  :
 //=============================================================================
-void V3d_View::Reset( const Standard_Boolean update )
+void V3d_View::Reset (const Standard_Boolean theToUpdate)
 {
-  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
+  Camera()->Copy (myDefaultCamera);
 
-  if (!aDefaultCamera.IsNull())
-  {
-    myCamera->CopyMappingData (aDefaultCamera);
-    myCamera->CopyOrientationData (aDefaultCamera);
-
-    View()->AutoZFit();
-  }
+  AutoZFit();
 
   SwitchSetFront = Standard_False;
 
-  if( myImmediateUpdate || update ) Update();
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Update();
+  }
 }
 
 //=======================================================================
@@ -1297,7 +1277,7 @@ void V3d_View::SetCenter (const Standard_Integer theXp,
 {
   Standard_Real aXv, aYv;
   Convert (theXp, theYp, aXv, aYv);
-  Translate (myCamera, aXv, aYv);
+  Translate (Camera(), aXv, aYv);
 
   ImmediateUpdate();
 }
@@ -1310,9 +1290,11 @@ void V3d_View::SetSize (const Standard_Real theSize)
 {
   V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
 
-  myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize);
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1321,19 +1303,19 @@ void V3d_View::SetSize (const Standard_Real theSize)
 //function : SetZSize
 //purpose  :
 //=============================================================================
-void V3d_View::SetZSize(const Standard_Real Size)
+void V3d_View::SetZSize (const Standard_Real theSize)
 {
-  Standard_Real Zmax = Size/2.;
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  Standard_Real aDistance = myCamera->Distance();
+  Standard_Real Zmax = theSize / 2.;
 
-  if( Size <= 0. ) {
+  Standard_Real aDistance = aCamera->Distance();
+
+  if (theSize <= 0.)
+  {
     Zmax = aDistance;
   }
 
-  Standard_Real Front = MyViewContext.ZClippingFrontPlane();
-  Standard_Real Back  = MyViewContext.ZClippingBackPlane();
-
   // ShortReal precision factor used to add meaningful tolerance to
   // ZNear, ZFar values in order to avoid equality after type conversion
   // to ShortReal matrices type.
@@ -1344,7 +1326,7 @@ void V3d_View::SetZSize(const Standard_Real Size)
   aZNear              -= Abs (aZNear) * aPrecision;
   aZFar               += Abs (aZFar)  * aPrecision;
 
-  if (!myCamera->IsOrthographic())
+  if (!aCamera->IsOrthographic())
   {
     if (aZFar < aPrecision)
     {
@@ -1365,14 +1347,11 @@ void V3d_View::SetZSize(const Standard_Real Size)
     aZFar = aZNear + Abs (aZFar) * aPrecision;
   }
 
-  myCamera->SetZRange (aZNear, aZFar);
+  aCamera->SetZRange (aZNear, aZFar);
 
-  if (MyViewContext.FrontZClippingIsOn()  ||
-      MyViewContext.BackZClippingIsOn())
+  if (myImmediateUpdate)
   {
-    MyViewContext.SetZClippingFrontPlane (Front);
-    MyViewContext.SetZClippingBackPlane (Back);
-    MyView->SetContext (MyViewContext);
+    Redraw();
   }
 }
 
@@ -1380,42 +1359,45 @@ void V3d_View::SetZSize(const Standard_Real Size)
 //function : SetZoom
 //purpose  :
 //=============================================================================
-void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
+void V3d_View::SetZoom (const Standard_Real theCoef,const Standard_Boolean theToStart)
 {
-  V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
+  V3d_BadValue_Raise_if (theCoef <= 0., "V3d_View::SetZoom, bad coefficient");
 
-  if (Start)
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  if (theToStart)
   {
-    myCamStartOpEye    = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
-  Standard_Real aViewWidth  = myCamera->ViewDimensions().X();
-  Standard_Real aViewHeight = myCamera->ViewDimensions().Y();
+  Standard_Real aViewWidth  = aCamera->ViewDimensions().X();
+  Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
 
   // ensure that zoom will not be too small or too big
-  Standard_Real coef = Coef;
-  if (aViewWidth < coef * Precision::Confusion())
+  Standard_Real aCoef = theCoef;
+  if (aViewWidth < aCoef * Precision::Confusion())
   {
-    coef = aViewWidth / Precision::Confusion();
+    aCoef = aViewWidth / Precision::Confusion();
   }
-  else if (aViewWidth > coef * 1e12)
+  else if (aViewWidth > aCoef * 1e12)
   {
-    coef = aViewWidth / 1e12;
+    aCoef = aViewWidth / 1e12;
   }
-  if (aViewHeight < coef * Precision::Confusion())
+  if (aViewHeight < aCoef * Precision::Confusion())
   {
-    coef = aViewHeight / Precision::Confusion();
+    aCoef = aViewHeight / Precision::Confusion();
   }
-  else if (aViewHeight > coef * 1e12)
+  else if (aViewHeight > aCoef * 1e12)
   {
-    coef = aViewHeight / 1e12;
+    aCoef = aViewHeight / 1e12;
   }
 
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
-  myCamera->SetScale (myCamera->Scale() / Coef);
-  View()->AutoZFit();
+  aCamera->SetEye (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetScale (aCamera->Scale() / aCoef);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1428,21 +1410,13 @@ void V3d_View::SetScale( const Standard_Real Coef )
 {
   V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
 
-  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  // Strange behavior for the sake of compatibility.
-  if (!aDefaultCamera.IsNull())
-  {
-    myCamera->SetAspect (aDefaultCamera->Aspect());
-    Standard_Real aDefaultScale = aDefaultCamera->Scale();
-    myCamera->SetScale (aDefaultScale / Coef);
-  } 
-  else
-  {
-    myCamera->SetScale (myCamera->Scale() / Coef);
-  }
+  Standard_Real aDefaultScale = myDefaultCamera->Scale();
+  aCamera->SetAspect (myDefaultCamera->Aspect());
+  aCamera->SetScale (aDefaultScale / Coef);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -1455,8 +1429,33 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co
 {
   V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
 
-  myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
-  View()->AutoZFit();
+  Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
+
+  AutoZFit();
+}
+
+//=============================================================================
+//function : SetRatio
+//purpose  :
+//=============================================================================
+void V3d_View::SetRatio()
+{
+  if (MyWindow.IsNull())
+  {
+    return;
+  }
+
+  Standard_Integer aWidth  = 0;
+  Standard_Integer aHeight = 0;
+  MyWindow->Size (aWidth, aHeight);
+  if (aWidth > 0 && aHeight > 0)
+  {
+    Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
+                           static_cast<Standard_Real> (aHeight);
+
+    Camera()       ->SetAspect (aRatio);
+    myDefaultCamera->SetAspect (aRatio);
+  }
 }
 
 //=============================================================================
@@ -1465,7 +1464,7 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co
 //=============================================================================
 void V3d_View::FitAll (const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate)
 {
-  FitAll (MyView->MinMaxValues(), theMargin, theToUpdate);
+  FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
 }
 
 //=============================================================================
@@ -1476,17 +1475,17 @@ void V3d_View::FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMarg
 {
   Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
 
-  if (MyView->NumberOfDisplayedStructures() == 0)
+  if (myView->NumberOfDisplayedStructures() == 0)
   {
     return;
   }
 
-  if (!FitMinMax (myCamera, theBox, theMargin, 10.0 * Precision::Confusion()))
+  if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
   {
     return;
   }
 
-  View()->AutoZFit();
+  AutoZFit();
 
   if (myImmediateUpdate || theToUpdate)
   {
@@ -1505,46 +1504,46 @@ void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
   Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
   Standard_Real Dx,Dy,Dz,Size;
 
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+  Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
 
   if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
     ImmediateUpdate();
     return ;
   }
 
-  Bnd_Box aBox = MyView->MinMaxValues();
+  Bnd_Box aBox = myView->MinMaxValues();
   if (aBox.IsVoid())
   {
     ImmediateUpdate();
     return ;
   }
     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
-    MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
-    MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
+    Project (Xmin,Ymin,Zmin,U,V,W) ;
+    Project (Xmax,Ymax,Zmax,U1,V1,W1) ;
     Umin = Min(U,U1) ; Umax = Max(U,U1) ;
     Vmin = Min(V,V1) ; Vmax = Max(V,V1) ;
     Wmin = Min(W,W1) ; Wmax = Max(W,W1) ;
-    MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
+    Project (Xmin,Ymin,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
+    Project (Xmax,Ymin,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
+    Project (Xmax,Ymin,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
+    Project (Xmax,Ymax,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
+    Project (Xmin,Ymax,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
+    Project (Xmin,Ymax,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
@@ -1565,18 +1564,6 @@ void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
     ImmediateUpdate();
 }
 
-//=============================================================================
-//function : FitAll
-//purpose  :
-//=============================================================================
-void V3d_View::FitAll(const Standard_Real theMinXv,
-                      const Standard_Real theMinYv,
-                      const Standard_Real theMaxXv,
-                      const Standard_Real theMaxYv)
-{
-  FitAll (MyWindow, theMinXv, theMinYv, theMaxXv, theMaxYv);
-}
-
 //=============================================================================
 //function : WindowFitAll
 //purpose  :
@@ -1600,14 +1587,16 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp,
 {
   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  if (!myCamera->IsOrthographic())
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  if (!aCamera->IsOrthographic())
   {
     // normalize view coordinates
     Standard_Integer aWinWidth, aWinHeight;
     MyWindow->Size (aWinWidth, aWinHeight);
 
     // z coordinate of camera center
-    Standard_Real aDepth = myCamera->Project (myCamera->Center()).Z();
+    Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
 
     // camera projection coordinate are in NDC which are normalized [-1, 1]
     Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp  - 1.0;
@@ -1618,22 +1607,22 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp,
     // compute camera panning
     gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
     gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
-    gp_Pnt aPanTo = myCamera->ConvertProj2View (aFitCenter);
-    gp_Pnt aPanFrom = myCamera->ConvertProj2View (aScreenCenter);
+    gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter);
+    gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
     gp_Vec aPanVec (aPanFrom, aPanTo);
 
     // compute section size
     gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
     gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
-    gp_Pnt aViewBotLeft = myCamera->ConvertProj2View (aFitBotLeft);
-    gp_Pnt aViewTopRight = myCamera->ConvertProj2View (aFitTopRight);
+    gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
+    gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
 
     Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
     Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
 
-    Translate (myCamera, aPanVec.X(), -aPanVec.Y());
-    Scale (myCamera, aUSize, aVSize);
-    View()->AutoZFit();
+    Translate (aCamera, aPanVec.X(), -aPanVec.Y());
+    Scale (aCamera, aUSize, aVSize);
+    AutoZFit();
   }
   else
   {
@@ -1648,28 +1637,6 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp,
   ImmediateUpdate();
 }
 
-//=======================================================================
-//function : SetViewMappingDefault
-//purpose  :
-//=======================================================================
-void V3d_View::SetViewMappingDefault()
-{
-  MyView->SetViewMappingDefault();
-
-  ImmediateUpdate();
-}
-
-//=======================================================================
-//function : ResetViewMapping
-//purpose  :
-//=======================================================================
-void V3d_View::ResetViewMapping()
-{
-  MyView->ViewMappingReset();
-
-  Update();
-}
-
 //=======================================================================
 //function : ConvertToGrid
 //purpose  :
@@ -1720,12 +1687,12 @@ Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
 {
   Standard_Integer aDxw, aDyw ;
 
-  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
   MyWindow->Size (aDxw, aDyw);
   Standard_Real aValue;
 
-  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
   aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
 
   return aValue;
@@ -1742,12 +1709,12 @@ void V3d_View::Convert(const Standard_Integer Xp,
 {
   Standard_Integer aDxw, aDyw;
 
-  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
   MyWindow->Size (aDxw, aDyw);
 
   gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
-  aPoint = myCamera->ConvertProj2View (aPoint);
+  aPoint = Camera()->ConvertProj2View (aPoint);
 
   Xv = aPoint.X();
   Yv = aPoint.Y();
@@ -1759,12 +1726,12 @@ void V3d_View::Convert(const Standard_Integer Xp,
 //=======================================================================
 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
 {
-  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
   Standard_Integer aDxw, aDyw;
   MyWindow->Size (aDxw, aDyw);
 
-  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
   Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
 
   return aValue;
@@ -1779,13 +1746,13 @@ void V3d_View::Convert(const Standard_Real Xv,
                        Standard_Integer& Xp,
                        Standard_Integer& Yp) const
 {
-  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
   Standard_Integer aDxw, aDyw;
   MyWindow->Size (aDxw, aDyw);
 
   gp_Pnt aPoint (Xv, Yv, 0.0);
-  aPoint = myCamera->ConvertView2Proj (aPoint);
+  aPoint = Camera()->ConvertView2Proj (aPoint);
   aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
 
   Xp = RealToInt (aPoint.X());
@@ -1802,7 +1769,7 @@ void V3d_View::Convert(const Standard_Integer Xp,
                        Standard_Real& Y,
                        Standard_Real& Z) const
 {
-  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
   Standard_Integer aHeight, aWidth;
   MyWindow->Size (aWidth, aHeight);
 
@@ -1810,7 +1777,7 @@ void V3d_View::Convert(const Standard_Integer Xp,
   Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0;
   Standard_Real  aZ = 2.0 * 0.0 - 1.0;
 
-  gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+  gp_Pnt aResult = Camera()->UnProject (gp_Pnt (anX, anY, aZ));
 
   X = aResult.X();
   Y = aResult.Y();
@@ -1830,7 +1797,7 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp,
                                Standard_Real& Dy,
                                Standard_Real& Dz) const
 {
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
   Standard_Integer aHeight, aWidth;
   MyWindow->Size (aWidth, aHeight);
 
@@ -1838,7 +1805,9 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp,
   Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0;
   Standard_Real  aZ = 2.0 * 0.0 - 1.0;
 
-  gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_Pnt aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
 
   X = aResult.X();
   Y = aResult.Y();
@@ -1847,7 +1816,7 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp,
   Graphic3d_Vertex aVrp;
   aVrp.SetCoord (X, Y, Z);
 
-  aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
+  aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
 
   Graphic3d_Vec3d aNormDir;
   aNormDir.x() = X - aResult.X();
@@ -1870,11 +1839,11 @@ void V3d_View::Convert(const Standard_Real X,
                        Standard_Integer& Xp,
                        Standard_Integer& Yp) const
 {
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
   Standard_Integer aHeight, aWidth;
   MyWindow->Size (aWidth, aHeight);
 
-  gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z));
+  gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
 
   Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
   Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
@@ -1884,14 +1853,40 @@ void V3d_View::Convert(const Standard_Real X,
 //function : Project
 //purpose  :
 //=======================================================================
-void V3d_View::Project(const Standard_Real X,
-                       const Standard_Real Y,
-                       const Standard_Real Z,
-                       Standard_Real &Xp,
-                       Standard_Real &Yp) const
+void V3d_View::Project (const Standard_Real theX,
+                        const Standard_Real theY,
+                        const Standard_Real theZ,
+                        Standard_Real& theXp,
+                        Standard_Real& theYp) const
+{
+  Standard_Real aZp;
+  Project (theX, theY, theZ, theXp, theYp, aZp);
+}
+
+//=======================================================================
+//function : Project
+//purpose  :
+//=======================================================================
+void V3d_View::Project (const Standard_Real theX,
+                        const Standard_Real theY,
+                        const Standard_Real theZ,
+                        Standard_Real& theXp,
+                        Standard_Real& theYp,
+                        Standard_Real& theZp) const
 {
-  Standard_Real Zp;
-  MyView->Projects (X, Y, Z, Xp, Yp, Zp);
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
+  Standard_Real aXSize = aViewSpaceDimensions.X();
+  Standard_Real aYSize = aViewSpaceDimensions.Y();
+  Standard_Real aZSize = aViewSpaceDimensions.Z();
+
+  gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
+
+  // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
+  theXp = aPoint.X() * aXSize * 0.5;
+  theYp = aPoint.Y() * aYSize * 0.5;
+  theZp = aPoint.Z() * aZSize * 0.5;
 }
 
 //=======================================================================
@@ -1913,16 +1908,16 @@ void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
 //=======================================================================
 Quantity_Color V3d_View::BackgroundColor() const
 {
-  return MyBackground.Color() ;
+  return myView->Background().Color() ;
 }
 
 //=======================================================================
 //function : GradientBackgroundColors
 //purpose  :
 //=======================================================================
-void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const
+void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
 {
-  MyGradientBackground.Colors(Color1, Color2);
+  myView->GradientBackground().Colors (theColor1, theColor2);
 }
 
 //=======================================================================
@@ -1931,7 +1926,7 @@ void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& C
 //=======================================================================
 Aspect_GradientBackground V3d_View::GradientBackground() const
 {
-   return MyGradientBackground;
+  return myView->GradientBackground();
 }
 
 //=======================================================================
@@ -1940,22 +1935,7 @@ Aspect_GradientBackground V3d_View::GradientBackground() const
 //=======================================================================
 Standard_Real V3d_View::Scale() const
 {
-  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
-
-  Standard_Real aCameraScale;
-
-  // Strange behavior for the sake of compatibility.
-  if (!aDefaultCamera.IsNull())
-  {
-    Standard_Real aDefaultScale = aDefaultCamera->Scale();
-    aCameraScale = aDefaultScale / myCamera->Scale();
-  } 
-  else
-  {
-    aCameraScale = myCamera->Scale();
-  }
-
-  return aCameraScale;
+  return myDefaultCamera->Scale() / Camera()->Scale();
 }
 
 //=======================================================================
@@ -1964,7 +1944,7 @@ Standard_Real V3d_View::Scale() const
 //=======================================================================
 void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
 {
-  gp_Pnt anAxialScale = myCamera->AxialScale();
+  gp_Pnt anAxialScale = Camera()->AxialScale();
   Sx = anAxialScale.X();
   Sy = anAxialScale.Y();
   Sz = anAxialScale.Z();
@@ -1976,7 +1956,7 @@ void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& S
 //=======================================================================
 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
 {
-  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
 
   Width = aViewDims.X();
   Height = aViewDims.Y();
@@ -1988,7 +1968,7 @@ void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
 //=======================================================================
 Standard_Real V3d_View::ZSize() const
 {
-  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
 
   return aViewDims.Z();
 }
@@ -2005,34 +1985,34 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
   Standard_Real Wmin,Wmax,U,V,W ;
   Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ;
   // CAL 6/11/98
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+  Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
 
   if( Nstruct ) {
-    Bnd_Box aBox = MyView->MinMaxValues();
+    Bnd_Box aBox = myView->MinMaxValues();
     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
-    MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
-    MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
-    MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
+    Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
+    Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
+    Project (Xmin,Ymin,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
+    Project (Xmax,Ymin,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
+    Project (Xmax,Ymin,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
+    Project (Xmax,Ymax,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
+    Project (Xmin,Ymax,Zmax,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
+    Project (Xmin,Ymax,Zmin,U,V,W) ;
     Umin = Min(U,Umin) ; Umax = Max(U,Umax) ;
     Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ;
     Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
@@ -2053,10 +2033,10 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
 {
   // CAL 6/11/98
   // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+  Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
 
   if( Nstruct ) {
-    Bnd_Box aBox = MyView->MinMaxValues();
+    Bnd_Box aBox = myView->MinMaxValues();
     aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
   }
   return Nstruct ;
@@ -2071,7 +2051,7 @@ void V3d_View::Gravity (Standard_Real& theX,
                         Standard_Real& theZ) const
 {
   Graphic3d_MapOfStructure aSetOfStructures;
-  MyView->DisplayedStructures (aSetOfStructures);
+  myView->DisplayedStructures (aSetOfStructures);
 
   Standard_Boolean hasSelection = Standard_False;
   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
@@ -2093,21 +2073,31 @@ void V3d_View::Gravity (Standard_Real& theX,
   {
     const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
     if (!aStruct->IsVisible()
-    || (hasSelection && !aStruct->IsHighlighted())
-    ||  aStruct->IsEmpty())
+      || aStruct->IsInfinite()
+      || (hasSelection && !aStruct->IsHighlighted()))
     {
       continue;
     }
 
-    Bnd_Box aBox = aStruct->MinMaxValues();
-    if (aBox.IsVoid() || aStruct->IsInfinite())
+    const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
+    if (!aBox.IsValid())
+    {
+      continue;
+    }
+
+    // skip transformation-persistent objects
+    if (!aStruct->TransformPersistence().IsNull())
     {
       continue;
     }
 
     // use camera projection to find gravity point
-    aBox.Get (Xmin, Ymin, Zmin,
-              Xmax, Ymax, Zmax);
+    Xmin = aBox.CornerMin().x();
+    Ymin = aBox.CornerMin().y();
+    Zmin = aBox.CornerMin().z();
+    Xmax = aBox.CornerMax().x();
+    Ymax = aBox.CornerMax().y();
+    Zmax = aBox.CornerMax().z();
     gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
     {
       gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
@@ -2119,7 +2109,7 @@ void V3d_View::Gravity (Standard_Real& theX,
     for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
     {
       const gp_Pnt& aBndPnt    = aPnts[aPntIt];
-      const gp_Pnt  aProjected = myCamera->Project (aBndPnt);
+      const gp_Pnt  aProjected = Camera()->Project (aBndPnt);
       if (Abs (aProjected.X()) <= 1.0
        && Abs (aProjected.Y()) <= 1.0)
       {
@@ -2131,21 +2121,10 @@ void V3d_View::Gravity (Standard_Real& theX,
 
   if (aNbPoints == 0)
   {
-    for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
-         aStructIter.More(); aStructIter.Next())
+    // fallback - just use bounding box of entire scene
+    Bnd_Box aBox = myView->MinMaxValues();
+    if (!aBox.IsVoid())
     {
-      const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
-      if (aStruct->IsEmpty())
-      {
-        continue;
-      }
-
-      Bnd_Box aBox = aStruct->MinMaxValues();
-      if (aBox.IsVoid() || aStruct->IsInfinite())
-      {
-        continue;
-      }
-
       aBox.Get (Xmin, Ymin, Zmin,
                 Xmax, Ymax, Zmax);
       gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
@@ -2180,7 +2159,7 @@ void V3d_View::Gravity (Standard_Real& theX,
 //=======================================================================
 void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
 {
-  gp_Pnt aCameraEye = myCamera->Eye();
+  gp_Pnt aCameraEye = Camera()->Eye();
   X = aCameraEye.X();
   Y = aCameraEye.Y();
   Z = aCameraEye.Z();
@@ -2230,7 +2209,7 @@ void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
 //=============================================================================
 Standard_Real V3d_View::Depth() const
 {
-  return myCamera->Distance();
+  return Camera()->Distance();
 }
 
 //=============================================================================
@@ -2239,7 +2218,7 @@ Standard_Real V3d_View::Depth() const
 //=============================================================================
 void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
 {
-  gp_Dir aCameraDir = myCamera->Direction().Reversed();
+  gp_Dir aCameraDir = Camera()->Direction().Reversed();
   Dx = aCameraDir.X();
   Dy = aCameraDir.Y();
   Dz = aCameraDir.Z();
@@ -2251,7 +2230,7 @@ void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) con
 //=============================================================================
 void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
 {
-  gp_Pnt aCameraCenter = myCamera->Center();
+  gp_Pnt aCameraCenter = Camera()->Center();
   X = aCameraCenter.X();
   Y = aCameraCenter.Y();
   Z = aCameraCenter.Z();
@@ -2263,7 +2242,7 @@ void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
 //=============================================================================
 void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
 {
-  gp_Dir aCameraUp = myCamera->Up();
+  gp_Dir aCameraUp = Camera()->Up();
   Vx = aCameraUp.X();
   Vy = aCameraUp.Y();
   Vz = aCameraUp.Z();
@@ -2280,7 +2259,7 @@ Standard_Real V3d_View::Twist() const
   Graphic3d_Vector Xaxis,Yaxis,Zaxis ;
   Standard_Boolean TheStatus ;
 
-  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  gp_Dir aReferencePlane (Camera()->Direction().Reversed());
   gp_Dir anUp;
 
   Proj(Xpn,Ypn,Zpn);
@@ -2322,18 +2301,7 @@ Standard_Real V3d_View::Twist() const
 //=============================================================================
 V3d_TypeOfShadingModel V3d_View::ShadingModel() const
 {
-  V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
-  return SM ;
-}
-
-//=============================================================================
-//function : SurfaceDetail
-//purpose  :
-//=============================================================================
-V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const
-{
-  V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
-  return SM ;
+  return static_cast<V3d_TypeOfShadingModel> (myView->ShadingModel());
 }
 
 //=============================================================================
@@ -2342,8 +2310,7 @@ V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const
 //=============================================================================
 Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
 {
-  Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
-  return SM ;
+  return myView->TextureEnv();
 }
 
 //=============================================================================
@@ -2352,19 +2319,7 @@ Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
 //=============================================================================
 V3d_TypeOfVisualization V3d_View::Visualization() const
 {
-  V3d_TypeOfVisualization V =
-    (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
-  return V ;
-}
-
-//=============================================================================
-//function : Antialiasing
-//purpose  :
-//=============================================================================
-Standard_Boolean V3d_View::Antialiasing() const
-{
-  Standard_Boolean A = MyViewContext.AliasingIsOn() ;
-  return A ;
+  return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
 }
 
 //=============================================================================
@@ -2373,7 +2328,7 @@ Standard_Boolean V3d_View::Antialiasing() const
 //=============================================================================
 Handle(V3d_Viewer) V3d_View::Viewer() const
 {
-  return MyViewer ;
+  return MyViewer;
 }
 
 //=============================================================================
@@ -2382,8 +2337,7 @@ Handle(V3d_Viewer) V3d_View::Viewer() const
 //=============================================================================
 Standard_Boolean V3d_View::IfWindow() const
 {
-  Standard_Boolean TheStatus = MyView->IsDefined() ;
-  return TheStatus ;
+  return myView->IsDefined();
 }
 
 //=============================================================================
@@ -2401,7 +2355,7 @@ Handle(Aspect_Window) V3d_View::Window() const
 //=============================================================================
 V3d_TypeOfView V3d_View::Type() const
 {
-  return myCamera->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
+  return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
 }
 
 //=============================================================================
@@ -2410,14 +2364,16 @@ V3d_TypeOfView V3d_View::Type() const
 //=============================================================================
 void V3d_View::SetFocale( const Standard_Real focale )
 {
-  if (myCamera->IsOrthographic())
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  if (aCamera->IsOrthographic())
   {
     return;
   }
 
-  Standard_Real aFOVyRad = ATan (focale / (myCamera->Distance() * 2.0));
+  Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
 
-  myCamera->SetFOVy (aFOVyRad * (360 / M_PI));
+  aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
 
   ImmediateUpdate();
 }
@@ -2428,21 +2384,23 @@ void V3d_View::SetFocale( const Standard_Real focale )
 //=============================================================================
 Standard_Real V3d_View::Focale() const
 {
-  if (myCamera->IsOrthographic())
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  if (aCamera->IsOrthographic())
   {
     return 0.0;
   }
 
-  return myCamera->Distance() * 2.0 * Tan(myCamera->FOVy() * M_PI / 360.0);
+  return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
 }
 
 //=============================================================================
 //function : View
 //purpose  :
 //=============================================================================
-Handle(Visual3d_View) V3d_View::View() const
+Handle(Graphic3d_CView) V3d_View::View() const
 {
-  return MyView ;
+  return myView;
 }
 
 //=============================================================================
@@ -2531,20 +2489,22 @@ void V3d_View::Panning (const Standard_Real theDXv,
 {
   Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if (theToStart)
   {
-    myCamStartOpEye = myCamera->Eye();
-    myCamStartOpCenter = myCamera->Center();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
   Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  gp_Pnt aViewDims = aCamera->ViewDimensions();
 
-  myCamera->SetEye (myCamStartOpEye);
-  myCamera->SetCenter (myCamStartOpCenter);
-  Translate (myCamera, -theDXv, -theDYv);
-  Scale (myCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
+  aCamera->SetEye (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+  Translate (aCamera, -theDXv, -theDYv);
+  Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -2599,8 +2559,10 @@ void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
 
   V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
 
-  Standard_Real aViewWidth  = myCamera->ViewDimensions().X();
-  Standard_Real aViewHeight = myCamera->ViewDimensions().Y();
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  Standard_Real aViewWidth  = aCamera->ViewDimensions().X();
+  Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
 
   // ensure that zoom will not be too small or too big.
   Standard_Real aCoef = aDZoom;
@@ -2628,10 +2590,10 @@ void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
   V3d_Coordinate aDxv = aZoomAtPointXv / aCoef;
   V3d_Coordinate aDyv = aZoomAtPointYv / aCoef;
 
-  myCamera->SetScale (myCamera->Scale() / aCoef);
-  Translate (myCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
+  aCamera->SetScale (aCamera->Scale() / aCoef);
+  Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
 
-  View()->AutoZFit();
+  AutoZFit();
 
   SetImmediateUpdate (wasUpdateEnabled);
 
@@ -2662,32 +2624,30 @@ void V3d_View::AxialScale (const Standard_Integer Dx,
 //function : FitAll
 //purpose  :
 //=============================================================================
-void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
-                      const Standard_Real Xmin,
-                      const Standard_Real Ymin,
-                      const Standard_Real Xmax,
-                      const Standard_Real Ymax)
+void V3d_View::FitAll(const Standard_Real theXmin,
+                      const Standard_Real theYmin,
+                      const Standard_Real theXmax,
+                      const Standard_Real theYmax)
 {
-  Standard_Integer aWinWidth, aWinHeight;
-  aWindow->Size (aWinWidth, aWinHeight);
+  Handle(Graphic3d_Camera) aCamera = Camera();
+  Standard_Real anAspect = aCamera->Aspect();
 
-  Standard_Real aWinAspect = (Standard_Real)aWinWidth / aWinHeight;
-  Standard_Real aFitSizeU  = Abs (Xmax - Xmin);
-  Standard_Real aFitSizeV  = Abs (Ymax - Ymin);
+  Standard_Real aFitSizeU  = Abs (theXmax - theXmin);
+  Standard_Real aFitSizeV  = Abs (theYmax - theYmin);
   Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
-  if (aFitAspect >= aWinAspect)
+  if (aFitAspect >= anAspect)
   {
-    aFitSizeV = aFitSizeU / aWinAspect;
+    aFitSizeV = aFitSizeU / anAspect;
   }
   else
   {
-    aFitSizeU = aFitSizeV * aWinAspect;
+    aFitSizeU = aFitSizeV * anAspect;
   }
 
-  myCamera->SetAspect (aWinAspect);
-  Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5);
-  Scale (myCamera, aFitSizeU, aFitSizeV);
-  View()->AutoZFit();
+  Translate (aCamera, (theXmin + theXmax) * 0.5, (theYmin + theYmax) * 0.5);
+  Scale (aCamera, aFitSizeU, aFitSizeV);
+
+  AutoZFit();
 
   ImmediateUpdate();
 }
@@ -2696,7 +2656,6 @@ void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
 //function : StartRotation
 //purpose  :
 //=============================================================================
-static Standard_Boolean zRotation = Standard_False;
 void V3d_View::StartRotation(const Standard_Integer X,
                              const Standard_Integer Y,
                              const Quantity_Ratio zRotationThreshold)
@@ -2708,13 +2667,13 @@ void V3d_View::StartRotation(const Standard_Integer X,
   ry = Standard_Real(Convert(y));
   Gravity(gx,gy,gz);
   Rotate(0.,0.,0.,gx,gy,gz,Standard_True);
-  zRotation = Standard_False;
+  myZRotation = Standard_False;
   if( zRotationThreshold > 0. ) {
     Standard_Real dx = Abs(sx - rx/2.);
     Standard_Real dy = Abs(sy - ry/2.);
-    //  if( dx > rx/3. || dy > ry/3. ) zRotation = Standard_True;
+    //  if( dx > rx/3. || dy > ry/3. ) myZRotation = Standard_True;
     Standard_Real dd = zRotationThreshold * (rx + ry)/2.;
-    if( dx > dd || dy > dd ) zRotation = Standard_True;
+    if( dx > dd || dy > dd ) myZRotation = Standard_True;
   }
 
 }
@@ -2731,7 +2690,7 @@ void V3d_View::Rotation(const Standard_Integer X,
     return;
   }
   Standard_Real dx=0.,dy=0.,dz=0.;
-  if( zRotation ) {
+  if( myZRotation ) {
     dz = atan2(Standard_Real(X)-rx/2., ry/2.-Standard_Real(Y)) -
       atan2(sx-rx/2.,ry/2.-sy);
   } else {
@@ -2746,19 +2705,19 @@ void V3d_View::Rotation(const Standard_Integer X,
 //function : SetComputedMode
 //purpose  :
 //=============================================================================
-void V3d_View::SetComputedMode (const Standard_Boolean aMode)
+void V3d_View::SetComputedMode (const Standard_Boolean theMode)
 {
-  if (aMode)
+  if (theMode)
   {
     if (myComputedMode)
     {
-      MyView->SetComputedMode (Standard_True);
+      myView->SetComputedMode (Standard_True);
       Update();
     }
-  } 
-  else 
+  }
+  else
   {
-    MyView->SetComputedMode (Standard_False);
+    myView->SetComputedMode (Standard_False);
     Update();
   }
 }
@@ -2769,16 +2728,16 @@ void V3d_View::SetComputedMode (const Standard_Boolean aMode)
 //=============================================================================
 Standard_Boolean V3d_View::ComputedMode() const
 {
-  return MyView->ComputedMode();
+  return myView->ComputedMode();
 }
 
 //=============================================================================
 //function : SetBackFacingModel
 //purpose  :
 //=============================================================================
-void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
+void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel theModel)
 {
-  MyView->SetBackFacingModel (Visual3d_TypeOfBackfacingModel(aModel));
+  myView->SetBackfacingModel (static_cast<Graphic3d_TypeOfBackfacingModel> (theModel));
   Redraw();
 }
 
@@ -2788,17 +2747,33 @@ void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
 //=============================================================================
 V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
 {
-  return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
+  return static_cast<V3d_TypeOfBackfacingModel> (myView->BackfacingModel());
 }
 
+//=============================================================================
+//function : Init
+//purpose  :
+//=============================================================================
 void V3d_View::Init()
 {
   myComputedMode = MyViewer->ComputedMode();
-  if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
-    SetComputedMode(Standard_False);
+  if (!myComputedMode || !MyViewer->DefaultComputedMode())
+  {
+    SetComputedMode (Standard_False);
   }
 }
 
+//=============================================================================
+//function : Export
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::Export (const Standard_CString theFileName,
+                                   const Graphic3d_ExportFormat theFormat,
+                                   const Graphic3d_SortType theSortType)
+{
+  return myView->Export (theFileName, theFormat, theSortType);
+}
+
 //=============================================================================
 //function : Dump
 //purpose  :
@@ -2818,85 +2793,131 @@ Standard_Boolean V3d_View::Dump (const Standard_CString      theFile,
 //purpose  :
 //=============================================================================
 Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
-                                     const Standard_Integer      theWidth,
-                                     const Standard_Integer      theHeight,
-                                     const Graphic3d_BufferType& theBufferType,
-                                     const Standard_Boolean      theToKeepAspect,
-                                     const V3d_StereoDumpOptions theStereoOptions)
-{
-  Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
-
-  // always prefer hardware accelerated offscreen buffer
-  Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
-  Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
-  Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0);
-  Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
-  if (aPrevFBOPtr != NULL)
-  {
-    MyView->FBOGetDimensions (aPrevFBOPtr,
-                              aPrevFBOVPSizeX, aPrevFBOVPSizeY,
-                              aPrevFBOSizeXMax, aPrevFBOSizeYMax);
-    if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax)
+                                     const V3d_ImageDumpOptions& theParams)
+{
+  Graphic3d_Vec2i aTargetSize (theParams.Width, theParams.Height);
+  if (aTargetSize.x() != 0
+   && aTargetSize.y() != 0)
+  {
+    // allocate image buffer for dumping
+    if (theImage.IsEmpty()
+     || theImage.SizeX() != Standard_Size(aTargetSize.x())
+     || theImage.SizeY() != Standard_Size(aTargetSize.y()))
     {
-      MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
-      aFBOPtr = aPrevFBOPtr;
+      Image_Format aFormat = Image_Format_UNKNOWN;
+      switch (theParams.BufferType)
+      {
+        case Graphic3d_BT_RGB:                 aFormat = Image_Format_RGB;   break;
+        case Graphic3d_BT_RGBA:                aFormat = Image_Format_RGBA;  break;
+        case Graphic3d_BT_Depth:               aFormat = Image_Format_GrayF; break;
+        case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF;  break;
+      }
+
+      if (!theImage.InitZero (aFormat, Standard_Size(aTargetSize.x()), Standard_Size(aTargetSize.y())))
+      {
+        Message::DefaultMessenger()->Send (TCollection_AsciiString ("Fail to allocate an image ") + aTargetSize.x() + "x" + aTargetSize.y()
+                                                                 + " for view dump", Message_Fail);
+        return Standard_False;
+      }
     }
   }
+  if (theImage.IsEmpty())
+  {
+    Message::DefaultMessenger()->Send (TCollection_AsciiString ("V3d_View::ToPixMap() has been called without image dimensions"), Message_Fail);
+    return Standard_False;
+  }
+  aTargetSize.x() = (Standard_Integer )theImage.SizeX();
+  aTargetSize.y() = (Standard_Integer )theImage.SizeY();
+
+  Handle(Standard_Transient) aFBOPtr;
+  Handle(Standard_Transient) aPrevFBOPtr = myView->FBO();
+  Graphic3d_Vec2i aFBOVPSize = aTargetSize;
 
-  if (aFBOPtr == NULL)
+  bool isTiling = false;
+  if (theParams.TileSize > 0)
   {
-    // Try to create hardware accelerated buffer
-    aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY);
-    if (aFBOPtr != NULL)
+    if (aFBOVPSize.x() > theParams.TileSize
+     || aFBOVPSize.y() > theParams.TileSize)
     {
-      MyView->FBOGetDimensions (aFBOPtr,
-                                aFBOVPSizeX,  aFBOVPSizeY,
-                                aFBOSizeXMax, aFBOSizeYMax);
-      // reduce viewport in case of hardware limits
-      if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax;
-      if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax;
-      MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY);
+      aFBOVPSize.x() = Min (aFBOVPSize.x(), theParams.TileSize);
+      aFBOVPSize.y() = Min (aFBOVPSize.y(), theParams.TileSize);
+      isTiling = true;
     }
   }
-  cView->ptrFBO = aFBOPtr;
 
-  // If hardware accelerated buffer - try to use onscreen buffer
-  // Results may be bad!
-  if (aFBOPtr == NULL)
+  Graphic3d_Vec2i aPrevFBOVPSize;
+  if (!aPrevFBOPtr.IsNull())
   {
-    // retrieve window sizes
-    Standard_Integer aWinWidth, aWinHeight;
-    MyWindow->Size (aWinWidth, aWinHeight);
+    Graphic3d_Vec2i aPrevFBOSizeMax;
+    myView->FBOGetDimensions (aPrevFBOPtr,
+                              aPrevFBOVPSize.x(),  aPrevFBOVPSize.y(),
+                              aPrevFBOSizeMax.x(), aPrevFBOSizeMax.y());
+    if (aFBOVPSize.x() <= aPrevFBOSizeMax.x()
+     && aFBOVPSize.y() <= aPrevFBOSizeMax.y())
+    {
+      aFBOPtr = aPrevFBOPtr;
+    }
+  }
 
-    // technically we can reduce existing viewport...
-    // but currently allow only dumping the window itself
-    if (aFBOVPSizeX != aWinWidth || aFBOVPSizeY != aWinHeight)
+  if (aFBOPtr.IsNull())
+  {
+    Standard_Integer aMaxTexSize = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxTextureSize);
+    if (theParams.TileSize > aMaxTexSize)
     {
+      Message::DefaultMessenger()->Send (TCollection_AsciiString ("Image dump can not be performed - specified tile size (")
+                                                                 + theParams.TileSize + ") exceeds hardware limits (" + aMaxTexSize + ")", Message_Fail);
       return Standard_False;
     }
+
+    if (aFBOVPSize.x() > aMaxTexSize
+     || aFBOVPSize.y() > aMaxTexSize)
+    {
+      aFBOVPSize.x() = Min (aFBOVPSize.x(), aMaxTexSize);
+      aFBOVPSize.y() = Min (aFBOVPSize.y(), aMaxTexSize);
+      isTiling = true;
+    }
+
+    // Try to create hardware accelerated buffer
+    aFBOPtr = myView->FBOCreate (aFBOVPSize.x(), aFBOVPSize.y());
   }
+  myView->SetFBO (aFBOPtr);
 
-  Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
+  if (aFBOPtr.IsNull())
+  {
+    // try to use on-screen buffer
+    Graphic3d_Vec2i aWinSize;
+    MyWindow->Size (aWinSize.x(), aWinSize.y());
+    if (aFBOVPSize.x() != aWinSize.x()
+     || aFBOVPSize.y() != aWinSize.y())
+    {
+      isTiling = true;
+    }
+    aFBOVPSize = aWinSize;
 
-  aStoreMapping->Copy (myCamera);
+    Message::DefaultMessenger()->Send (TCollection_AsciiString ("Warning, on screen buffer is used for image dump - content might be invalid"), Message_Warning);
+  }
 
-  if (myCamera->IsStereo())
+  // backup camera parameters
+  Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
+  Handle(Graphic3d_Camera) aCamera = Camera();
+  aStoreMapping->Copy (aCamera);
+  if (aCamera->IsStereo())
   {
-    switch (theStereoOptions)
+    switch (theParams.StereoOptions)
     {
       case V3d_SDO_MONO:
       {
-        myCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
         break;
       }
       case V3d_SDO_LEFT_EYE:
       {
-        myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
         break;
       }
       case V3d_SDO_RIGHT_EYE:
       {
-        myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
         break;
       }
       case V3d_SDO_BLENDED:
@@ -2905,74 +2926,114 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
       }
     }
   }
-
-  // render immediate structures into back buffer rather than front
-  Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver());
-  const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False);
-
-  const Standard_Boolean toAutoUpdate = myImmediateUpdate;
-  myImmediateUpdate = Standard_False;
-  View()->AutoZFit();
-  myImmediateUpdate = toAutoUpdate;
-
-  if (theToKeepAspect)
+  if (theParams.ToAdjustAspect)
   {
-    myCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY);
+    aCamera->SetAspect (Standard_Real(aTargetSize.x()) / Standard_Real(aTargetSize.y()));
   }
+  AutoZFit();
 
-  //workaround for rendering list of Over and Under Layers
-  if (!MyLayerMgr.IsNull())
-  {
-    MyLayerMgr->Compute();
-  }
-
-  Redraw();
-
-  if (!aDriver.IsNull())
-  {
-    aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode);
-  }
-
-  myCamera->Copy (aStoreMapping);
+  // render immediate structures into back buffer rather than front
+  const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
 
   Standard_Boolean isSuccess = Standard_True;
-
-  // allocate image buffer for dumping
-  if (theImage.IsEmpty()
-   || (Standard_Size )aFBOVPSizeX != theImage.SizeX()
-   || (Standard_Size )aFBOVPSizeY != theImage.SizeY())
+  if (!isTiling)
   {
-    bool isBigEndian = Image_PixMap::IsBigEndianHost();
-    Image_PixMap::ImgFormat aFormat = Image_PixMap::ImgUNKNOWN;
-    switch (theBufferType)
+    if (!aFBOPtr.IsNull())
     {
-      case Graphic3d_BT_RGB:   aFormat = isBigEndian ? Image_PixMap::ImgRGB  : Image_PixMap::ImgBGR;  break;
-      case Graphic3d_BT_RGBA:  aFormat = isBigEndian ? Image_PixMap::ImgRGBA : Image_PixMap::ImgBGRA; break;
-      case Graphic3d_BT_Depth: aFormat = Image_PixMap::ImgGrayF; break;
+      myView->FBOChangeViewport (aFBOPtr, aTargetSize.x(), aTargetSize.y());
     }
+    Redraw();
+    isSuccess = isSuccess && myView->BufferDump (theImage, theParams.BufferType);
+  }
+  else
+  {
+    Image_PixMap aTilePixMap;
+    aTilePixMap.SetTopDown (theImage.IsTopDown());
 
-    isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY);
+    Graphic3d_Vec2i anOffset (0, 0);
+    for (; anOffset.y() < aTargetSize.y(); anOffset.y() += aFBOVPSize.y())
+    {
+      anOffset.x() = 0;
+      for (; anOffset.x() < aTargetSize.x(); anOffset.x() += aFBOVPSize.x())
+      {
+        Graphic3d_CameraTile aTile;
+        aTile.Offset    = anOffset;
+        aTile.TotalSize = aTargetSize;
+        aTile.TileSize  = aFBOVPSize;
+        if (!aFBOPtr.IsNull())
+        {
+          // crop corners in case of FBO
+          // (no API to resize viewport of on-screen buffer - keep uncropped in this case)
+          aTile = aTile.Cropped();
+        }
+        if (aTile.TileSize.x() < 1
+         || aTile.TileSize.y() < 1)
+        {
+          continue;
+        }
+
+        const Standard_Integer aLeft   = aTile.Offset.x();
+        Standard_Integer       aBottom = aTile.Offset.y();
+        if (theImage.IsTopDown())
+        {
+          const Standard_Integer aTop = aTile.Offset.y() + aTile.TileSize.y();
+          aBottom = aTargetSize.y() - aTop;
+        }
+        aTilePixMap.InitWrapper (theImage.Format(), theImage.ChangeData()
+                               + theImage.SizeRowBytes() * aBottom + theImage.SizePixelBytes() * aLeft,
+                                 aTile.TileSize.x(), aTile.TileSize.y(),
+                                 theImage.SizeRowBytes());
+
+        aCamera->SetTile (aTile);
+        if (!aFBOPtr.IsNull())
+        {
+          myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
+        }
+        Redraw();
+        isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
+        if (!isSuccess)
+        {
+          break;
+        }
+      }
+      if (!isSuccess)
+      {
+        break;
+      }
+    }
   }
-  isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType);
 
-  // FBO now useless, free resources
+  // restore state
+  myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
+  aCamera->Copy (aStoreMapping);
   if (aFBOPtr != aPrevFBOPtr)
   {
-    MyView->FBORelease (aFBOPtr);
+    myView->FBORelease (aFBOPtr);
   }
-  else if (aPrevFBOPtr != NULL)
+  else if (!aPrevFBOPtr.IsNull())
   {
-    MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
+    myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSize.x(), aPrevFBOVPSize.y());
   }
-  cView->ptrFBO = aPrevFBOPtr;
+  myView->SetFBO (aPrevFBOPtr);
   return isSuccess;
 }
 
+//=============================================================================
+//function : ImmediateUpdate
+//purpose  :
+//=============================================================================
 void V3d_View::ImmediateUpdate() const
 {
-  if (myImmediateUpdate) Update();
+  if (myImmediateUpdate)
+  {
+    Update();
+  }
 }
 
+//=============================================================================
+//function : SetImmediateUpdate
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
 {
   Standard_Boolean aPreviousMode = myImmediateUpdate;
@@ -2986,11 +3047,9 @@ Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmedia
 // =======================================================================
 void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
 {
-  Standard_ASSERT_RAISE (!theCamera.IsNull(), "Void camera is not allowed");
-
-  myCamera = theCamera;
+  myView->SetCamera (theCamera);
 
-  MyView->SetCamera (theCamera);
+  ImmediateUpdate();
 }
 
 // =======================================================================
@@ -2999,7 +3058,7 @@ void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
 // =======================================================================
 const Handle(Graphic3d_Camera)& V3d_View::Camera() const
 {
-  return myCamera;
+  return myView->Camera();
 }
 
 // =======================================================================
@@ -3076,10 +3135,10 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
   // 4) Determine new zooming in view space.
 
   // 1. Determine normalized projection asymmetry (if any).
-  Standard_Real anAssymX = Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction()))
-                         - Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction()));
-  Standard_Real anAssymY = Tan ( aCamUp.Angle   (aFrustumPlane (3).Axis().Direction()))
-                         - Tan (-aCamUp.Angle   (aFrustumPlane (4).Axis().Direction()));
+  Standard_Real anAssymX = Tan (( aCamSide).Angle (aFrustumPlane (1).Axis().Direction()))
+                         - Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction()));
+  Standard_Real anAssymY = Tan (( aCamUp)  .Angle (aFrustumPlane (3).Axis().Direction()))
+                         - Tan ((-aCamUp)  .Angle (aFrustumPlane (4).Axis().Direction()));
 
   // 2. Determine how far should be the frustum planes placed from center
   //    of bounding box, in order to match the bounding box closely.
@@ -3119,12 +3178,12 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
   //                            \//
   //                            //
   //                      (frustum plane)
-  aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan ( aCamSide.Angle (aFrustumPlane (1).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan (-aCamSide.Angle (aFrustumPlane (2).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan ( aCamUp.Angle   (aFrustumPlane (3).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan (-aCamUp.Angle   (aFrustumPlane (4).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan ( aCamDir.Angle  (aFrustumPlane (5).Axis().Direction())), 2.0));
-  aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan (-aCamDir.Angle  (aFrustumPlane (6).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (1) *= Sqrt(1 + Pow (Tan (  aCamSide .Angle (aFrustumPlane (1).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (2) *= Sqrt(1 + Pow (Tan ((-aCamSide).Angle (aFrustumPlane (2).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (3) *= Sqrt(1 + Pow (Tan (  aCamUp   .Angle (aFrustumPlane (3).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (4) *= Sqrt(1 + Pow (Tan ((-aCamUp)  .Angle (aFrustumPlane (4).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (5) *= Sqrt(1 + Pow (Tan (  aCamDir  .Angle (aFrustumPlane (5).Axis().Direction())), 2.0));
+  aFitDistance.ChangeValue (6) *= Sqrt(1 + Pow (Tan ((-aCamDir) .Angle (aFrustumPlane (6).Axis().Direction())), 2.0));
 
   Standard_Real aViewSizeXv = aFitDistance (1) + aFitDistance (2);
   Standard_Real aViewSizeYv = aFitDistance (3) + aFitDistance (4);
@@ -3159,7 +3218,11 @@ Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
     aViewSizeYv = aViewSizeZv;
   }
 
-  Scale (theCamera, aViewSizeXv * (1.0 + theMargin), aViewSizeYv * (1.0 + theMargin));
+  Scale (theCamera, aViewSizeXv, aViewSizeYv);
+
+  const Standard_Real aZoomCoef = myView->ConsiderZoomPersistenceObjects();
+
+  Scale (theCamera, theCamera->ViewDimensions().X() * (aZoomCoef + theMargin), theCamera->ViewDimensions().Y() * (aZoomCoef + theMargin));
 
   return Standard_True;
 }
@@ -3211,8 +3274,7 @@ void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
 // =======================================================================
 Standard_Boolean V3d_View::IsCullingEnabled() const
 {
-  Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
-  return aView->IsCullingEnabled;
+  return myView->IsCullingEnabled();
 }
 
 // =======================================================================
@@ -3221,6 +3283,33 @@ Standard_Boolean V3d_View::IsCullingEnabled() const
 // =======================================================================
 void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip)
 {
-  Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView();
-  aView->IsCullingEnabled = theToClip;
+  myView->SetCullingEnabled (theToClip);
+}
+
+// =======================================================================
+// function : DiagnosticInformation
+// purpose  :
+// =======================================================================
+void V3d_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
+                                      Graphic3d_DiagnosticInfo theFlags) const
+{
+  myView->DiagnosticInformation (theDict, theFlags);
+}
+
+//=============================================================================
+//function : RenderingParams
+//purpose  :
+//=============================================================================
+const Graphic3d_RenderingParams& V3d_View::RenderingParams() const
+{
+  return myView->RenderingParams();
+}
+
+//=============================================================================
+//function : ChangeRenderingParams
+//purpose  :
+//=============================================================================
+Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams()
+{
+  return myView->ChangeRenderingParams();
 }