0030644: Coding - inline trivial methods of V3d_View class
[occt.git] / src / V3d / V3d_View.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 4dc97ec..af34004
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-/***********************************************************************
-
-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.
-24-09-98 : CAL ; Ajout d'un parametre a V3d_View::SetPlotter.
-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.
-13-06-98 : FMN ; PRO14896: Correction sur la gestion de la perspective (cf Programming Guinde)
-29-OCT-98 : DCB : Adding ScreenCopy () method.
-22-12-98 : FMN ; Rename CSF_WALKTHROW en CSF_WALKTHROUGH
-10-11-99 : GG ; PRO19603 Add Redraw( area ) method
-IMP130100 : GG
--> Don't increase too much the ZSize.
--> Initialize correctly the Z clipping and D cueing
-planes.
-IMP100701 : SZV ; Add ToPixMap() 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.
-
-************************************************************************/
-
-#define GER61351  //GG_15/12/99 Add SetBackgroundColor()
-//              and BackgroundColor() methods
-
-
-#define IMP240100 //GG
-//      -> Remove PixToRef() method ,use
-//        instead the equivalent Convert() method.
-//      -> Rename RefToPix() to Convert() method.
-//            -> Remove the grid computation in Convert()
-//        method. Use instead the NEW ConvertToGrid() methods.
-//        Reason is the Convert() method is call by
-//        StdSelect_ViewSelector3d_Pick() from
-//        AIS_InteractiveContext() and it's not possible
-//        to select an object vertex when the grid is active!
-//      -> Remove grid echo marker definition
-//        (reported in the viewer)
-//      -> Add SetProjModel() methods.
-
-#define G003    //EUG 04-10-99
-//      -> computed mode management
-//         Add SetComputedMode(..) method
-//      -> animation mode management
-//         Add SetAnimationMode()
-//      -> backfacing management
-//         Add SetBackFacingModel() method
-
-#define G004    //VKH 15-11-99
-//      -> Add Dump() methods
-//      -> GG 07/03/00 Use the new MMSize()
-//         method from Aspect_Window class.
-
-#define IMP210200       //GG Add Transparency() method
-
-#define IMP250200 //GG With SetDepth() method, when the requested
-//      depth is < 0.,
-//      move the view ref point and the eye,instead
-//      only the eye.
-
-#define IMP020300 //GG Don't use ZFitAll in during Rotation
-//      for perf improvment
-
-#define IMP210600 //GG Avoid to have infinite loop when call Rotation() method
-//      without call before StartRotation().
-//      This problem occurs when CTRL MB3 is maintain press betwwen 2 views.
-
-#define IMP250900 //GG Enable rotation around screen Z axis when
-//      rotation begin far the center of the screen.
-//      Thanks to Patrick REGINSTER (SAMTECH)
-//      GG 21/12/00 Due to a regression on the previous specifications
-//      this new functionnality is right now deactivated
-//      by default (see StartRotation(...,zRotationThreshold)
-//      method.
-
-#define BUC60952  //GG Enable to rotate around the view axis
-//      and the required view point
-
-#define RIC120302 //GG Add a NEW SetWindow method which enable
-//      to connect a graphic widget and context to OGL.
-
-#define IMP260302 //GG To avoid conflicting in Window destructor
-//      nullify this handle in Remove method
-
-#define OCC280          //SAV fix for FitAll problem in the perspective view.
-
-#define OCC1188         //SAV Added methods to set background image
-
-/*----------------------------------------------------------------------*/
-/*
-* Includes
-*/
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
-#include <Standard_TypeMismatch.hxx>
-#include <Visual3d_ViewManager.hxx>
-#include <Visual3d_Light.hxx>
-#include <Visual3d_ClipPlane.hxx>
-#include <Graphic3d_Structure.hxx>
+#include <V3d_View.hxx>
+
+#include <Aspect_GradientBackground.hxx>
+#include <Aspect_Grid.hxx>
+#include <Aspect_Window.hxx>
+#include <Bnd_Box.hxx>
+#include <gp_Ax3.hxx>
+#include <gp_Dir.hxx>
+#include <gp_Pln.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_Group.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 #include <Graphic3d_MapOfStructure.hxx>
+#include <Graphic3d_Structure.hxx>
 #include <Graphic3d_TextureEnv.hxx>
-#include <Image_PixMap.hxx>
-#include <V3d.hxx>
-#include <V3d_View.ixx>
-#include <Viewer_BadValue.hxx>
+#include <Image_AlienPixMap.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
+#include <NCollection_Array1.hxx>
+#include <Precision.hxx>
+#include <Quantity_Color.hxx>
+#include <Standard_Assert.hxx>
+#include <Standard_DivideByZero.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_MultiplyDefined.hxx>
 #include <Standard_ShortReal.hxx>
-#include <gp_Dir.hxx>
+#include <Standard_Type.hxx>
+#include <Standard_TypeMismatch.hxx>
+#include <TColgp_Array1OfPnt.hxx>
 #include <TColStd_Array2OfReal.hxx>
-#include <Visual3d_TransientManager.hxx>
-#include <Precision.hxx>
+#include <TColStd_HSequenceOfInteger.hxx>
+#include <V3d.hxx>
+#include <V3d_BadValue.hxx>
+#include <V3d_Light.hxx>
+#include <V3d_StereoDumpOptions.hxx>
+#include <V3d_UnMapped.hxx>
+#include <V3d_Viewer.hxx>
 
-// S3892
-#include <Graphic3d_AspectMarker3d.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(V3d_View,Standard_Transient)
 
-// S3603
-#include <Aspect_GenericColorMap.hxx>
-#include <Aspect_TypeMap.hxx>
-#include <Aspect_WidthMap.hxx>
-#include <Aspect_MarkMap.hxx>
-#include <Aspect_FontMap.hxx>
-#include <PlotMgt_ImageDriver.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
-#ifdef WNT
-# include <WNT_WDriver.hxx>
-#else
-# include <Xw_Driver.hxx>
-#endif
-
-#ifdef G003
-# define V3d_FLAG_ANIMATION     0x00000001
-# define V3d_FLAG_DEGENERATION  0x00000002
-# define V3d_FLAG_COMPUTATION   0x00000004
-#endif  // G003
-
-// Tumble
-#include <OSD_Timer.hxx>
-static OSD_Timer FullTimer;
-
-// Perspective
-#include <OSD_Environment.hxx>
-
-/*----------------------------------------------------------------------*/
-/*
-* Constant
-*/
-
-#define Zmargin 1.
 #define DEUXPI (2. * M_PI)
 
-// in case of NO_TRACE_ECHO and NO_TRACE_POINTS, in V3d_View_4.cxx and in
-// V3d_View.cxx, change MyGridEchoStructure and MyGridEchoGroup in cdl
-#define NO_TRACE_ECHO
-#define NO_TRACE_POINTS
-
-/*----------------------------------------------------------------------*/
-/*
-* Local data definitions
-*/
+namespace
+{
+  static const Standard_Integer THE_NB_BOUND_POINTS = 8;
+}
+
+//=============================================================================
+//function : Constructor
+//purpose  :
+//=============================================================================
+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)
+{
+  myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
 
+  myView->SetBackground         (theViewer->GetBackgroundColor());
+  myView->SetGradientBackground (theViewer->GetGradientBackground());
 
-static Standard_Real MyXwindowCenter ;
-static Standard_Real MyYwindowCenter ;
-static Standard_Real MyWindowWidth ;
-static Standard_Real MyWindowHeight ;
+  ChangeRenderingParams() = theViewer->DefaultRenderingParams();
 
-#define LOPTIM
-#ifndef LOPTIM
-static Graphic3d_Vector MyXscreenAxis ;
-static Graphic3d_Vector MyYscreenAxis ;
-static Graphic3d_Vector MyZscreenAxis ;
-static Graphic3d_Vector MyViewReferencePlane ;
-static Graphic3d_Vector MyViewReferenceUp ;
-static Graphic3d_Vector MyViewAxis ;
-static Graphic3d_Vertex MyViewReferencePoint ;
-static Graphic3d_Vertex MyGravityReferencePoint ;
-static Graphic3d_Vertex MyProjReferencePoint ;
-#else
-static Graphic3d_Vector& _MyXscreenAxis() {
-  static Graphic3d_Vector MyXscreenAxis;
-  return MyXscreenAxis;
-}
-#define MyXscreenAxis _MyXscreenAxis()
+  // 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);
+  aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC)
+    ? Graphic3d_Camera::Projection_Orthographic
+    : Graphic3d_Camera::Projection_Perspective);
 
-static Graphic3d_Vector& _MyYscreenAxis() {
-  static Graphic3d_Vector MyYscreenAxis;
-  return MyYscreenAxis;
-}
-#define MyYscreenAxis _MyYscreenAxis()
+  myDefaultCamera = new Graphic3d_Camera();
 
-static Graphic3d_Vector& _MyZscreenAxis() {
-  static Graphic3d_Vector MyZscreenAxis;
-  return MyZscreenAxis;
+  myImmediateUpdate = Standard_False;
+  SetAutoZFitMode (Standard_True, 1.0);
+  SetBackFacingModel (V3d_TOBM_AUTOMATIC);
+  SetCamera (aCamera);
+  SetAxis (0.,0.,0.,1.,1.,1.);
+  SetVisualization (theViewer->DefaultVisualization());
+  SetShadingModel (theViewer->DefaultShadingModel());
+  SetTwist (0.);
+  SetAt (0.,0.,0.);
+  SetProj (theViewer->DefaultViewProj());
+  SetSize (theViewer->DefaultViewSize());
+  Standard_Real zsize = theViewer->DefaultViewSize();
+  SetZSize (2.*zsize);
+  SetDepth (theViewer->DefaultViewSize() / 2.0);
+  SetViewMappingDefault();
+  SetViewOrientationDefault();
+  theViewer->AddView (this);
+  Init();
+  myImmediateUpdate = Standard_True;
 }
-#define MyZscreenAxis _MyZscreenAxis()
 
-static Graphic3d_Vector& _MyViewReferencePlane() {
-  static Graphic3d_Vector MyViewReferencePlane;
-  return MyViewReferencePlane;
-}
-#define MyViewReferencePlane _MyViewReferencePlane()
+//=============================================================================
+//function : Constructor
+//purpose  :
+//=============================================================================
+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)
+{
+  myView = theViewer->Driver()->CreateView (theViewer->StructureManager());
 
-static Graphic3d_Vector& _MyViewReferenceUp() {
-  static Graphic3d_Vector MyViewReferenceUp;
-  return MyViewReferenceUp;
-}
-#define MyViewReferenceUp _MyViewReferenceUp()
+  myView->CopySettings (theView->View());
+  myDefaultViewPoint = theView->myDefaultViewPoint;
+  myDefaultViewAxis  = theView->myDefaultViewAxis;
 
-static Graphic3d_Vector& _MyViewAxis() {
-  static Graphic3d_Vector MyViewAxis;
-  return MyViewAxis;
-}
-#define MyViewAxis _MyViewAxis()
+  myDefaultCamera = new Graphic3d_Camera (theView->DefaultCamera());
 
-static Graphic3d_Vertex& _MyViewReferencePoint() {
-  static Graphic3d_Vertex MyViewReferencePoint;
-  return MyViewReferencePoint;
+  myImmediateUpdate = Standard_False;
+  SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor());
+  theViewer->AddView (this);
+  Init();
+  myImmediateUpdate = Standard_True;
 }
-#define MyViewReferencePoint _MyViewReferencePoint()
 
-static Graphic3d_Vertex& _MyGravityReferencePoint() {
-  static Graphic3d_Vertex MyGravityReferencePoint;
-  return MyGravityReferencePoint;
+//=============================================================================
+//function : Destructor
+//purpose  :
+//=============================================================================
+V3d_View::~V3d_View()
+{
+  if (!myView->IsRemoved())
+  {
+    myView->Remove();
+  }
 }
-#define MyGravityReferencePoint _MyGravityReferencePoint()
 
-static Graphic3d_Vertex& _MyProjReferencePoint() {
-  static Graphic3d_Vertex MyProjReferencePoint;
-  return MyProjReferencePoint;
+//=============================================================================
+//function : SetMagnify
+//purpose  :
+//=============================================================================
+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)
+{
+  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();
+  }
 }
-#define MyProjReferencePoint _MyProjReferencePoint()
-#endif // LOPTIM
 
-/*----------------------------------------------------------------------*/
-//-Constructors
-
-V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
-MyType ( Type ),
-MyViewer(VM.operator->()),
-MyActiveLights(),
-MyActivePlanes(),
-MyViewContext (),
-myActiveLightsIterator(),
-myActivePlanesIterator(),
-SwitchSetFront(Standard_False),
-MyTrsf (1, 4, 1, 4),                                    // S3892
-MyProjModel(V3d_TPM_SCREEN)
-#if defined(TRACE_POINTS)
-,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())),  // S3892
-MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure))            // S3892
-#endif
+//=============================================================================
+//function : SetWindow
+//purpose  :
+//=============================================================================
+void V3d_View::SetWindow (const Handle(Aspect_Window)&  theWindow,
+                          const Aspect_RenderingContext theContext)
 {
+  if (myView->IsRemoved())
+  {
+    return;
+  }
 
-  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 ();
-
-  // Visualisation and Shading Model
-  MyViewContext.SetModel ((MyView->Context ()).Model ());
-  MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
-
-  // Texture Mapping
-  MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ());
-  MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ());
-  // } End of retrieval of the definition of ViewContext.
-
-  MyViewMapping = MyView->ViewMapping() ;
-  MyViewOrientation = MyView->ViewOrientation() ;
-  MyBackground = VM->GetBackgroundColor() ;
-  MyGradientBackground = VM->GetGradientBackground() ;
-
-  SetAxis(0.,0.,0.,1.,1.,1.) ;
-  SetVisualization(VM->DefaultVisualization()) ;
-  SetShadingModel(VM->DefaultShadingModel()) ;
-  SetSurfaceDetail(VM->DefaultSurfaceDetail()) ;
-  SetTwist(0.) ;
-  SetAt(0.,0.,0.) ;
-  SetProj(VM->DefaultViewProj()) ;
-  SetSize(VM->DefaultViewSize()) ;
-  Standard_Real zsize = VM->DefaultViewSize();
-  SetZSize(2.*zsize+zsize*Zmargin) ;
-  SetZClippingDepth(0.);
-  SetZClippingWidth(zsize);
-  SetZCueingDepth(0.);
-  SetZCueingWidth(zsize);
-  SetDepth(VM->DefaultViewSize()/2.) ;
-  SetCenter(0.,0.) ;
-  SetViewMappingDefault();
-  VM->AddView(this) ;
-  Init();
-  myImmediateUpdate = Standard_True;
-
-  // S3892
-#ifndef IMP240100
-#if defined(TRACE_POINTS)
-  Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
-  MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
-  MarkerAttrib->SetScale (3.0);
-  MarkerAttrib->SetType (Aspect_TOM_STAR);
-  MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
-#endif
-#endif  //IMP240100
-
-#ifdef G003
-  MyAnimationFlags = 0;
-#endif  // G003
-
-#ifdef IMP210200
-  MyTransparencyFlag = Standard_False;
-#endif
-
+  // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw()
+  MyWindow = theWindow;
+  myView->SetWindow (theWindow, theContext);
+  MyViewer->SetViewOn (this);
+  SetRatio();
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
-MyType ( Type ),
-MyViewer(VM.operator->()),
-MyActiveLights(),
-MyActivePlanes(),
-MyViewContext (),
-myActiveLightsIterator(),
-myActivePlanesIterator(),
-SwitchSetFront(Standard_False),
-MyTrsf (1, 4, 1, 4),                                    // S3892
-MyProjModel(V3d_TPM_SCREEN)
-#if defined(TRACE_POINTS)
-,MyGridEchoStructure (new Graphic3d_Structure (VM->Viewer ())),  // S3892
-MyGridEchoGroup (new Graphic3d_Group (MyGridEchoStructure))      // S3892
-#endif
+//=============================================================================
+//function : Remove
+//purpose  :
+//=============================================================================
+void V3d_View::Remove() const
 {
+  if (!MyGrid.IsNull())
+  {
+    MyGrid->Erase();
+  }
+  if (!myTrihedron.IsNull())
+  {
+    myTrihedron->Erase();
+  }
 
-  Handle(Visual3d_View) FromView = V->View() ;
+  MyViewer->DelView (this);
+  myView->Remove();
+  Handle(Aspect_Window)& aWin = const_cast<Handle(Aspect_Window)&> (MyWindow);
+  aWin.Nullify();
+}
 
-  myImmediateUpdate = Standard_False;
-  MyView = new Visual3d_View(MyViewer->Viewer());
+//=============================================================================
+//function : Update
+//purpose  :
+//=============================================================================
+void V3d_View::Update() const
+{
+  if (!myView->IsDefined()
+   || !myView->IsActive())
+  {
+    return;
+  }
 
-  for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
-    MyActiveLights.Append(V->ActiveLight());}
-  for (V->InitActivePlanes();V->MoreActivePlanes();V->NextActivePlanes()){
-    MyActivePlanes.Append(V->ActivePlane());}
+  myView->Update();
+  myView->Compute();
+  myView->Redraw();
+}
 
-  MyViewContext = FromView->Context() ;
+//=============================================================================
+//function : Redraw
+//purpose  :
+//=============================================================================
+void V3d_View::Redraw() const
+{
+  if (!myView->IsDefined()
+   || !myView->IsActive())
+  {
+    return;
+  }
 
-  MyViewMapping = FromView->ViewMapping() ;
-  MyViewOrientation = FromView->ViewOrientation() ;
-  MyBackground = FromView->Background() ;
-  MyGradientBackground = FromView->GradientBackground();
+  Handle(Graphic3d_StructureManager) aStructureMgr  = MyViewer->StructureManager();
+  for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
+  {
+    if (aStructureMgr->IsDeviceLost())
+    {
+      aStructureMgr->RecomputeStructures();
+    }
 
-  MyView->SetContext(MyViewContext) ;
+    AutoZFit();
 
-  SetAxis(0.,0.,0.,1.,1.,1.) ;
-  VM->AddView(this) ;
-  Init();
-  myImmediateUpdate = Standard_True;
+    myView->Redraw();
 
-  // S3892
-#ifndef IMP240100
-#if defined(TRACE_ECHO)
-  Handle(Graphic3d_AspectMarker3d) MarkerAttrib = new Graphic3d_AspectMarker3d ();
-  MarkerAttrib->SetColor (Quantity_Color (Quantity_NOC_GRAY90));
-  MarkerAttrib->SetScale (3.0);
-  MarkerAttrib->SetType (Aspect_TOM_STAR);
-  MyGridEchoStructure->SetPrimitivesAspect (MarkerAttrib);
-#endif
-#endif  //IMP240100
-
-#ifdef G003
-  MyAnimationFlags = 0;
-#endif
-
-}
-
-/*----------------------------------------------------------------------*/
-
-//-Methods, in order
-
-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->SetViewOrientation(MyViewOrientation) ;
-    MyView->SetBackground(MyBackground) ;
-    MyViewer->SetViewOn(this) ;
-    MyWindow = TheWindow;
-    MyView->Redraw() ;
-    SetViewMappingDefault();
+    if (!aStructureMgr->IsDeviceLost())
+    {
+      return;
+    }
   }
-
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
+//=============================================================================
+//function : RedrawImmediate
+//purpose  :
+//=============================================================================
+void V3d_View::RedrawImmediate() const
 {
+  if (!myView->IsDefined()
+   || !myView->IsActive())
+  {
+    return;
+  }
 
-  Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
-    "V3d_View::SetWindow, window of view already defined");
-
-  MyView->SetWindow(TheWindow) ;
-  // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
-  // calling Redraw(). Otherwise it is impossible to call certain methods of
-  // V3d_View like Convert() inside the context of Redraw(),
-  // particularly in class NIS_View.
-  MyWindow = TheWindow;
-  // SetWindow carries out SetRatio and modifies
-  // ViewMapping and ViewMappingDefault of MyView.
-  MyViewMapping = MyView->ViewMapping() ;
-  MyView->SetContext(MyViewContext) ;
-  MyView->SetViewMapping(MyViewMapping) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  MyView->SetBackground(MyBackground) ;
-  MyViewer->SetViewOn(this) ;
-#ifdef TRACE_POINTS
-  MyGridEchoStructure->SetInfiniteState (Standard_True);        // S3892
-  MyGridEchoStructure->Display ();                              // S3892
-#endif
-  MyView->Redraw() ;
-
+  myView->RedrawImmediate();
 }
 
-// RIC120302
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetWindow(const Handle(Aspect_Window)&      aWindow,
-                         const Aspect_RenderingContext     aContext,
-                         const Aspect_GraphicCallbackProc& aDisplayCB,
-                         const Standard_Address            aClientData)
+//=============================================================================
+//function : Invalidate
+//purpose  :
+//=============================================================================
+void V3d_View::Invalidate() const
 {
+  if (!myView->IsDefined())
+  {
+    return;
+  }
 
-  Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
-    "V3d_View::SetWindow, "
-    "window of view already defined");
-  // AGV: Method V3d_View::SetWindow() should assign the field MyWindow before
-  // calling Redraw(). Otherwise it is impossible to call certain methods of
-  // V3d_View like Convert() inside the context of Redraw(),
-  // particularly in class NIS_View.
-  MyWindow = aWindow;
-  MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ;
-  MyViewMapping = MyView->ViewMapping() ;
-  MyView->SetContext(MyViewContext) ;
-  MyView->SetViewMapping(MyViewMapping) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  MyView->SetBackground(MyBackground) ;
-  MyViewer->SetViewOn(this) ;
-  MyView->Redraw() ;
-
+  myView->Invalidate();
 }
-// RIC120302
-
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Remove() const  {
-
-  MyViewer->DelView(this) ;
-  MyView->Remove() ;
-#ifdef IMP260303
-  MyWindow.Nullify();
-#endif
 
+//=============================================================================
+//function : IsInvalidated
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::IsInvalidated() const
+{
+  return !myView->IsDefined()
+       || myView->IsInvalidated();
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Update()  const {
-  if( MyView->IsDefined() )  MyView->Update() ;
+// ========================================================================
+// function : SetAutoZFitMode
+// purpose  :
+// ========================================================================
+void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
+                                const Standard_Real    theScaleFactor)
+{
+  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+  myAutoZFitScaleFactor = theScaleFactor;
+  myAutoZFitIsOn = theIsOn;
 }
 
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : AutoZFit
+//purpose  :
+//=============================================================================
+void V3d_View::AutoZFit() const
+{
+  if (!AutoZFitMode())
+  {
+    return;
+  }
 
-void V3d_View::Redraw() const {
-  if( MyView->IsDefined() ) MyView->Redraw() ;
+  ZFitAll (myAutoZFitScaleFactor);
 }
-/*----------------------------------------------------------------------*/
 
-void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
-                      const Standard_Integer width,const Standard_Integer height) const
+//=============================================================================
+//function : ZFitAll
+//purpose  :
+//=============================================================================
+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).
 
-Standard_Boolean V3d_View::IsEmpty() const {
+  myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
+}
 
+//=============================================================================
+//function : IsEmpty
+//purpose  :
+//=============================================================================
+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) ;
-
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::UpdateLights() const {
-  MyView->SetContext(MyViewContext);
-  Update();
+//=============================================================================
+//function : UpdateLights
+//purpose  :
+//=============================================================================
+void V3d_View::UpdateLights() const
+{
+  Handle(Graphic3d_LightSet) aLights = new Graphic3d_LightSet();
+  for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
+  {
+    aLights->Add (anActiveLightIter.Value());
+  }
+  myView->SetLights (aLights);
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::DoMapping() {
-  if( MyView->IsDefined() ) {
-    (MyView->Window())->DoMapping() ;
+//=============================================================================
+//function : DoMapping
+//purpose  :
+//=============================================================================
+void V3d_View::DoMapping()
+{
+  if (!myView->IsDefined())
+  {
+    return;
   }
-}
 
-/*----------------------------------------------------------------------*/
+  myView->Window()->DoMapping();
+}
 
-void V3d_View::MustBeResized() {
+//=============================================================================
+//function : MustBeResized
+//purpose  :
+//=============================================================================
+void V3d_View::MustBeResized()
+{
+  if (!myView->IsDefined())
+  {
+    return;
+  }
 
-  if ( !MyLayerMgr.IsNull() )
-    MyLayerMgr->Resized();
+  myView->Resized();
 
-  if( MyView->IsDefined() ) {
-    MyView->Resized() ;
-    MyViewMapping = MyView->ViewMapping();
-    MyView->Redraw();
+  SetRatio();
+  if (myImmediateUpdate)
+  {
+    Redraw();
   }
-
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
+//=============================================================================
+//function : SetBackgroundColor
+//purpose  :
+//=============================================================================
+void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType,
+                                   const Standard_Real theV1,
+                                   const Standard_Real theV2,
+                                   const Standard_Real theV3)
 {
-  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 );
+  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);
 
-  Quantity_Color C( V1, V2, V3, Type );
-#ifdef GER61351
-  SetBackgroundColor( C );
-#else
-  MyBackground.SetColor( C );
-  if ( MyView->IsDefined() )
-    MyView->SetBackground( MyBackground );
-  if ( !MyLayerMgr.IsNull() )
-    MyLayerMgr->Resized();
-#endif
+  SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType));
 }
 
-#ifdef GER61351
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
+//=============================================================================
+//function : SetBackgroundColor
+//purpose  :
+//=============================================================================
+void V3d_View::SetBackgroundColor (const Quantity_Color& theColor)
 {
-  MyBackground.SetColor( Color );
-  if ( MyView->IsDefined() )
-    MyView->SetBackground( MyBackground );
-  //szv: Why?
-  if ( !MyLayerMgr.IsNull() )
-    MyLayerMgr->Resized();
-}
-#endif
+  myView->SetBackground (Aspect_Background (theColor));
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
-{
-  Quantity_Color C( Name );
-#ifdef GER61351
-  SetBackgroundColor( C );
-#else
-  MyBackground.SetColor( C );
-  if ( MyView->IsDefined() )
-    MyView->SetBackground( MyBackground );
-  if ( !MyColorScale.IsNull() )
-    MyColorScale->Resized();
-#endif
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
-                                    const Quantity_Color& Color2,
-                                    const Aspect_GradientFillMethod FillStyle,
-                                    const Standard_Boolean status)
+//=============================================================================
+//function : SetBgGradientColors
+//purpose  :
+//=============================================================================
+void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1,
+                                    const Quantity_Color& theColor2,
+                                    const Aspect_GradientFillMethod theFillStyle,
+                                    const Standard_Boolean theToUpdate)
 {
+  Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle);
 
-  MyGradientBackground.SetColors(Color1, Color2, FillStyle);
-  if ( MyView->IsDefined() )
-    MyView->SetGradientBackground( MyGradientBackground, status );
+  myView->SetGradientBackground (aGradientBg);
 
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
-                                    const Quantity_NameOfColor Color2,
-                                    const Aspect_GradientFillMethod FillStyle,
-                                    const Standard_Boolean status )
+//=============================================================================
+//function : SetBgGradientStyle
+//purpose  :
+//=============================================================================
+void V3d_View::SetBgGradientStyle (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 );
-}
-
-/*----------------------------------------------------------------------*/
+  Quantity_Color aColor1;
+  Quantity_Color aColor2;
+  GradientBackground().Colors (aColor1, aColor2);
 
-void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
-                                   const Standard_Boolean update)
-{
-  Quantity_Color Color1, Color2;
-  MyGradientBackground.Colors( Color1, Color2 );
-  MyGradientBackground.SetColors( Color1, Color2, FillStyle );
-  if( MyView->IsDefined() )
-    MyView->SetBgGradientStyle( FillStyle, update ) ;
+  SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate);
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetBackgroundImage( const Standard_CString FileName,
-                                   const Aspect_FillMethod FillStyle,
-                                   const Standard_Boolean update )
+//=============================================================================
+//function : SetBackgroundImage
+//purpose  :
+//=============================================================================
+void V3d_View::SetBackgroundImage (const Standard_CString theFileName,
+                                   const Aspect_FillMethod theFillStyle,
+                                   const Standard_Boolean theToUpdate)
 {
-#ifdef OCC1188
-  if( MyView->IsDefined() )
-    MyView->SetBackgroundImage( FileName, FillStyle, update ) ;
-#endif
-}
-
-/*----------------------------------------------------------------------*/
+  myView->SetBackgroundImage (theFileName);
+  myView->SetBackgroundImageStyle (theFillStyle);
 
-void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
-                                const Standard_Boolean update )
-{
-#ifdef OCC1188
-  if( MyView->IsDefined() )
-    MyView->SetBgImageStyle( FillStyle, update ) ;
-#endif
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) {
-
-  Standard_Real D,Nx = Vx,Ny = Vy,Nz = Vz ;
-
-  D = Sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) ;
-  Viewer_BadValue_Raise_if ( D <= 0. , "V3d_View::SetAxis, bad axis");
-  Nx /= D ; Ny /= D ; Nz /= D ;
-  MyDefaultViewPoint.SetCoord(X,Y,Z) ;
-  MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
-  MyDefaultViewAxis.Normalize() ;
+//=============================================================================
+//function : SetBgImageStyle
+//purpose  :
+//=============================================================================
+void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate)
+{
+  myView->SetBackgroundImageStyle (theFillStyle);
 
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) {
-
-  MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
-  MyView->SetContext(MyViewContext) ;
-
+//=============================================================================
+//function : SetAxis
+//purpose  :
+//=============================================================================
+void V3d_View::SetAxis (const Standard_Real theX,  const Standard_Real theY,  const Standard_Real theZ,
+                        const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
+{
+  myDefaultViewPoint.SetCoord (theX, theY, theZ);
+  myDefaultViewAxis.SetCoord (theVx, theVy, theVz);
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) {
-
-  MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
-  MyView->SetContext(MyViewContext) ;
-
+//=============================================================================
+//function : SetShadingModel
+//purpose  :
+//=============================================================================
+void V3d_View::SetShadingModel (const Graphic3d_TypeOfShadingModel theShadingModel)
+{
+  myView->SetShadingModel (theShadingModel);
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) {
-
-  MyViewContext.SetTextureEnv(ATexture) ;
-  MyView->SetContext(MyViewContext) ;
+//=============================================================================
+//function : SetTextureEnv
+//purpose  :
+//=============================================================================
+void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture)
+{
+  myView->SetTextureEnv (theTexture);
 
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) {
-
-  MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
-  MyView->SetContext(MyViewContext) ;
+//=============================================================================
+//function : SetVisualization
+//purpose  :
+//=============================================================================
+void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType)
+{
+  myView->SetVisualizationType (static_cast <Graphic3d_TypeOfVisualization> (theType));
 
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::SetFront() {
-
+//=============================================================================
+//function : SetFront
+//purpose  :
+//=============================================================================
+void V3d_View::SetFront()
+{
   gp_Ax3 a = MyViewer->PrivilegedPlane();
-  Standard_Real xo,yo,zo,vx,vy,vz,xu,yu,zu;
+  Standard_Real xo, yo, zo, vx, vy, vz, xu, yu, zu;
 
   a.Direction().Coord(vx,vy,vz);
   a.YDirection().Coord(xu,yu,zu);
   a.Location().Coord(xo,yo,zo);
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  aCamera->SetCenter (gp_Pnt (xo, yo, zo));
+
   if(SwitchSetFront)
-    MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
+  {
+    aCamera->SetDirection (gp_Dir (vx, vy, vz));
+  }
   else
-    MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
+  {
+    aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
+  }
 
-  SwitchSetFront = !SwitchSetFront;
+  aCamera->SetUp (gp_Dir (xu, yu, zu));
 
-  MyViewOrientation.SetViewReferenceUp(Graphic3d_Vector(xu,yu,zu));
-  MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(xo,yo,zo));
+  AutoZFit();
 
-  MyView->SetViewOrientation(MyViewOrientation) ;
+  SwitchSetFront = !SwitchSetFront;
 
   ImmediateUpdate();
-
 }
 
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
+void V3d_View::Rotate (const Standard_Real ax, 
+                       const Standard_Real ay, 
+                       const Standard_Real az, 
+                       const Standard_Boolean Start)
+{
+  Standard_Real Ax = ax;
+  Standard_Real Ay = ay;
+  Standard_Real Az = az;
 
-void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start) {
+  if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI;
+  else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI;
+  if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI;
+  else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI;
+  if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI;
+  else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI;
 
-  Standard_Real Ax = ax ;
-  Standard_Real Ay = ay ;
-  Standard_Real Az = az ;
-  Graphic3d_Vector Vpn,Vup ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
-  TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
-  else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
-  if( Ay > 0. ) while ( Ay > DEUXPI ) Ay -= DEUXPI ;
-  else if( Ay < 0. ) while ( Ay < -DEUXPI ) Ay += DEUXPI ;
-  if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ;
-  else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
+  if (Start)
+  {
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
 
-  if( Start ) {
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
-      Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
-  }
-
-  InitMatrix(Matrix) ;
-
-  if( Ax != 0. ) RotAxis(MyViewReferencePoint,MyYscreenAxis,-Ax,Matrix);
-  if( Ay != 0. ) {
-    RotAxis(MyViewReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  if( Az != 0. ) {
-    RotAxis(MyViewReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferencePlane(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  ImmediateUpdate();
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
-}
+  // rotate camera around 3 initial axes
+  gp_Dir aBackDir (gp_Vec (myCamStartOpCenter, myCamStartOpEye));
+  gp_Dir aXAxis (myCamStartOpUp.Crossed (aBackDir));
+  gp_Dir aYAxis (aBackDir.Crossed (aXAxis));
+  gp_Dir aZAxis (aXAxis.Crossed (aYAxis));
 
-/*----------------------------------------------------------------------*/
+  gp_Trsf aRot[3], aTrsf;
+  aRot[0].SetRotation (gp_Ax1 (myCamStartOpCenter, aYAxis), -Ax);
+  aRot[1].SetRotation (gp_Ax1 (myCamStartOpCenter, aXAxis), Ay);
+  aRot[2].SetRotation (gp_Ax1 (myCamStartOpCenter, aZAxis), Az);
+  aTrsf.Multiply (aRot[0]);
+  aTrsf.Multiply (aRot[1]);
+  aTrsf.Multiply (aRot[2]);
 
+  aCamera->Transform (aTrsf);
+
+  AutoZFit();
+
+  ImmediateUpdate();
+}
+
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
 void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az,
                       const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
 {
@@ -882,10 +644,6 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan
   Standard_Real Ax = ax ;
   Standard_Real Ay = ay ;
   Standard_Real Az = az ;
-  Graphic3d_Vector Vpn,Vup ;
-  Graphic3d_Vertex Vrp ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
-  TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
 
   if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
   else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
@@ -894,45 +652,50 @@ 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 ;
 
-  if( Start ) {
-    MyGravityReferencePoint.SetCoord(X,Y,Z) ;
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
-      Viewer_BadValue::Raise ("V3d_View::Rotate, alignment of Eye,At,Up");
-  }
-
-  InitMatrix(Matrix) ;
-
-  if( Ax != 0. ) RotAxis(MyGravityReferencePoint,MyYscreenAxis,-Ax,Matrix);
-  if( Ay != 0. ) {
-    RotAxis(MyGravityReferencePoint,MyXscreenAxis,Ay,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  if( Az != 0. ) {
-    RotAxis(MyGravityReferencePoint,MyZscreenAxis,Az,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
-  MyViewOrientation.SetViewReferencePoint(Vrp) ;
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferencePlane(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  ImmediateUpdate();
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-}
+  if (Start)
+  {
+    myGravityReferencePoint.SetCoord (X, Y, Z);
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
+
+  const Graphic3d_Vertex& aVref = myGravityReferencePoint;
+
+  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 (aCamera->Direction().Reversed());
+  gp_Dir aYAxis (aCamera->Up());
+  gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); 
+
+  gp_Trsf aRot[3], aTrsf;
+  aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
+  aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
+  aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
+  aTrsf.Multiply (aRot[0]);
+  aTrsf.Multiply (aRot[1]);
+  aTrsf.Multiply (aRot[2]);
+
+  aCamera->Transform (aTrsf);
 
-/*----------------------------------------------------------------------*/
+  AutoZFit();
 
-void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start) {
+  ImmediateUpdate();
+}
 
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
+void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
+{
   switch (Axe) {
   case V3d_X :
     Rotate(angle,0.,0.,Start);
@@ -944,104 +707,107 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const
     Rotate(0.,0.,angle,Start);
     break ;
   }
-
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle,
-                      const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Standard_Boolean Start)
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
+void V3d_View::Rotate (const V3d_TypeOfAxe theAxe, const Standard_Real theAngle,
+                       const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, const Standard_Boolean theStart)
 {
+  Standard_Real anAngle = theAngle;
 
-  Standard_Real Angle = angle ;
-  Graphic3d_Vector Vpn,Vup ;
-  Graphic3d_Vertex Vrp ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
+  if (anAngle > 0.0) while (anAngle > DEUXPI) anAngle -= DEUXPI;
+  else if (anAngle < 0.0) while (anAngle < -DEUXPI) anAngle += DEUXPI;
 
-  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) ;
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    switch (Axe) {
-    case V3d_X :
-      MyViewAxis.SetCoord(1.,0.,0.) ;
-      break ;
-    case V3d_Y :
-      MyViewAxis.SetCoord(0.,1.,0.) ;
-      break ;
-    case V3d_Z :
-      MyViewAxis.SetCoord(0.,0.,1.) ;
-      break ;
+  if (theStart)
+  {
+    myGravityReferencePoint.SetCoord (theX, theY, theZ);
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+
+    switch (theAxe)
+    {
+      case V3d_X: myViewAxis = gp::DX(); break;
+      case V3d_Y: myViewAxis = gp::DY(); break;
+      case V3d_Z: myViewAxis = gp::DZ(); break;
     }
+
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
 
-  RotAxis(MyGravityReferencePoint,MyViewAxis,Angle,Matrix) ;
-  Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
-  MyViewOrientation.SetViewReferencePoint(Vrp) ;
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferencePlane(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  ImmediateUpdate();
+  const Graphic3d_Vertex& aVref = myGravityReferencePoint;
 
-}
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
 
-/*----------------------------------------------------------------------*/
+  // rotate camera around passed axis
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
+  gp_Dir aRAxis ((theAxe == V3d_X) ? 1.0 : 0.0,
+                 (theAxe == V3d_Y) ? 1.0 : 0.0,
+                 (theAxe == V3d_Z) ? 1.0 : 0.0);
 
-void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) {
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), anAngle);
 
-  Standard_Real Angle = angle ;
-  Graphic3d_Vector Vpn,Vup ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
+  aCamera->Transform (aRotation);
+
+  AutoZFit();
+
+  ImmediateUpdate();
+}
+
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
+void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
+{
+  Standard_Real Angle = 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 ) {
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-  }
-
-  RotAxis(MyDefaultViewPoint,MyDefaultViewAxis,Angle,Matrix) ;
-#ifdef BUC60952
-  Graphic3d_Vertex Vrp ;
-  Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
-  MyViewOrientation.SetViewReferencePoint(Vrp) ;
-#endif
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferencePlane(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  ImmediateUpdate();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
 
-}
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter (myDefaultViewPoint);
+  gp_Dir aRAxis (myDefaultViewAxis);
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
 
-/*----------------------------------------------------------------------*/
+  aCamera->Transform (aRotation);
+
+  AutoZFit();
+
+  ImmediateUpdate();
+}
 
+//=============================================================================
+//function : Turn
+//purpose  :
+//=============================================================================
 void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
 {
-
-  Standard_Real Ax = ax ;
-  Standard_Real Ay = ay ;
-  Standard_Real Az = az ;
-  Graphic3d_Vertex Vrp,Eye ;
-  Graphic3d_Vector Vpn,Vup ;
-  Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
-  TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
+  Standard_Real Ax = ax;
+  Standard_Real Ay = ay;
+  Standard_Real Az = az;
 
   if( Ax > 0. ) while ( Ax > DEUXPI ) Ax -= DEUXPI ;
   else if( Ax < 0. ) while ( Ax < -DEUXPI ) Ax += DEUXPI ;
@@ -1050,59 +816,45 @@ 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 ) {
-    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
-      Viewer_BadValue::Raise ("V3d_View::Turn, alignment of Eye,At,Up");
-  }
-
-  InitMatrix(Matrix) ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
-  Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
-  Eye.SetCoord(Xeye,Yeye,Zeye) ;
-  if( Ax != 0. ) RotAxis(Eye,MyYscreenAxis,-Ax,Matrix) ;
-  if( Ay != 0. ) {
-    RotAxis(Eye,MyXscreenAxis,Ay,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  if( Az != 0. ) {
-    RotAxis(Eye,MyZscreenAxis,Az,Rmatrix) ;
-    Multiply(Matrix, Rmatrix, Matrix);
-  }
-  Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
-  MyViewOrientation.SetViewReferencePoint(Vrp) ;
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#else
-  // Check ZClipping planes
-  Standard_Real Zmax ;
-  Vrp.Coord(Xat,Yat,Zat) ;
-  Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat) ;
-  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
-    MyProjModel == V3d_TPM_SCREEN ) {
-      SetZSize(2.*Zmax+Zmax*Zmargin) ;
-    }
-#endif
-    ImmediateUpdate();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
 
-}
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+
+  // rotate camera around 3 initial axes
+  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;
+  aRot[0].SetRotation (gp_Ax1 (aRCenter, aYAxis), -Ax);
+  aRot[1].SetRotation (gp_Ax1 (aRCenter, aXAxis), Ay);
+  aRot[2].SetRotation (gp_Ax1 (aRCenter, aZAxis), Az);
+  aTrsf.Multiply (aRot[0]);
+  aTrsf.Multiply (aRot[1]);
+  aTrsf.Multiply (aRot[2]);
+
+  aCamera->Transform (aTrsf);
 
-/*----------------------------------------------------------------------*/
+  AutoZFit();
 
+  ImmediateUpdate();
+}
+
+//=============================================================================
+//function : Turn
+//purpose  :
+//=============================================================================
 void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
 {
-
   switch (Axe) {
   case V3d_X :
     Turn(angle,0.,0.,Start);
@@ -1116,950 +868,604 @@ void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const St
   }
 }
 
-void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) {
+//=============================================================================
+//function : Turn
+//purpose  :
+//=============================================================================
+void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start)
+{
   Standard_Real Angle = angle ;
-  Graphic3d_Vertex Vrp,Eye ;
-  Graphic3d_Vector Vpn,Vup ;
-  Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat,Xeye,Yeye,Zeye ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
 
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
   if( Start ) {
-    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-  }
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
-  Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
-  Eye.SetCoord(Xeye,Yeye,Zeye) ;
-  RotAxis(Eye,MyDefaultViewAxis,Angle,Matrix) ;
-  Vrp = TrsPoint(MyViewReferencePoint,Matrix) ;
-  MyViewOrientation.SetViewReferencePoint(Vrp) ;
-  Vpn = TrsPoint(MyViewReferencePlane,Matrix) ;
-  MyViewOrientation.SetViewReferencePlane(Vpn) ;
-  Vup = TrsPoint(MyViewReferenceUp,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(Vup) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#else
-  // Check ZClipping planes
-  Standard_Real Zmax ;
-  Vrp.Coord(Xat,Yat,Zat) ;
-  Zmax = Sqrt( Xat*Xat + Yat*Yat + Zat*Zat ) ;
-  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
-    MyProjModel == V3d_TPM_SCREEN ) {
-      SetZSize(2.*Zmax+Zmax*Zmargin) ;
-    }
-#endif
-    ImmediateUpdate();
+    myCamStartOpUp     = aCamera->Up();
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
 
-}
+  aCamera->SetUp     (myCamStartOpUp);
+  aCamera->SetEye    (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter = aCamera->Eye();
+  gp_Dir aRAxis (myDefaultViewAxis);
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
+
+  aCamera->Transform (aRotation);
 
-void V3d_View::SetTwist(const Standard_Real angle) {
+  AutoZFit();
 
+  ImmediateUpdate();
+}
+
+//=============================================================================
+//function : SetTwist
+//purpose  :
+//=============================================================================
+void V3d_View::SetTwist(const Standard_Real angle)
+{
   Standard_Real Angle = angle ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
-  Standard_Boolean TheStatus ;
 
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  MyViewReferenceUp.SetCoord(0.,0.,1.) ;
-  TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-    MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  Viewer_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
-
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
-  MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  ImmediateUpdate();
+  const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
+  if (!screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
+  {
+    throw V3d_BadValue ("V3d_ViewSetTwist, alignment of Eye,At,Up,");
+  }
+  
+  gp_Pnt aRCenter = aCamera->Center();
+  gp_Dir aZAxis (aCamera->Direction().Reversed());
 
-}
+  gp_Trsf aTrsf;
+  aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
 
-#ifdef IMP240100
-void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
-{
+  aCamera->SetUp (gp_Dir (myYscreenAxis));
+  aCamera->Transform (aTrsf);
 
-  MyProjModel = aModel;
+  AutoZFit();
 
+  ImmediateUpdate();
 }
 
-V3d_TypeOfProjectionModel V3d_View::ProjModel() const {
+//=============================================================================
+//function : SetEye
+//purpose  :
+//=============================================================================
+void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
+{
+  Standard_Real aTwistBefore = Twist();
 
-  return MyProjModel;
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-}
-#endif
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
+  aCamera->SetEye (gp_Pnt (X, Y, Z));
 
-  Standard_Real Angle,Xat,Yat,Zat,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn ;
-  Angle = Twist() ;
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-  Xpn = X - Xat ; Ypn = Y - Yat ; Zpn = Z - Zat ;
-  Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
-  Viewer_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
+  SetTwist (aTwistBefore);
 
-  Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
-  MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
-  MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
-  MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-  MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
+  AutoZFit();
 
-  Standard_Boolean update = myImmediateUpdate;
-  myImmediateUpdate = Standard_False;
-  if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
-    //FMN desactivation temp SetTwist(Angle) ;
-    // Set infos.
-    MyView->SetViewOrientation(MyViewOrientation) ;
-    MyView->SetViewMapping(MyViewMapping) ;
-  } else {
-    SetTwist(Angle) ;
-  }
-#ifdef IMP020300
-  SetZSize(0.) ;
-#else
-  // Check ZClipping planes
-  Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
-  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
-    MyProjModel == V3d_TPM_SCREEN ) {
-      SetZSize(2.*Zmax+Zmax*Zmargin) ;
-    } else {
-      if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
-      MyView->SetViewMapping(MyViewMapping);
-    }
-#endif
-    myImmediateUpdate = update;
-    ImmediateUpdate();
+  SetImmediateUpdate (wasUpdateEnabled);
 
+  ImmediateUpdate();
 }
 
-void V3d_View::SetDepth(const Standard_Real Depth) {
+//=============================================================================
+//function : SetDepth
+//purpose  :
+//=============================================================================
+void V3d_View::SetDepth(const Standard_Real Depth)
+{
+  V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
 
-  Standard_Real Xrp,Yrp,Zrp ;
-#ifdef IMP250200
-  Viewer_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
-#else
-  Viewer_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
-#endif
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-#ifdef DEB
-  Standard_Real twist =
-#endif
-    Twist();
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-#ifdef IMP250200
   if( Depth > 0. )
-#endif
-  {
-    Zrp = Depth;
-    MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-    MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
-  }
-
-  // Check ZClipping planes
-  Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xeye,Yeye,Zeye ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
-#ifdef IMP250200
-  if( Depth < 0. ) {  // Move the view ref point instead of the eye.
-    Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
-    Zrp = Abs(Depth) ;
-    Xat = Xeye - Xpn*Zrp ; Yat = Yeye - Ypn*Zrp ; Zat = Zeye - Zpn*Zrp;
-    MyViewReferencePoint.SetCoord(Xat,Yat,Zat) ;
-    MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-    MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
-    MyView->SetViewOrientation(MyViewOrientation);
-  }
-#endif
-#ifdef IMP020300
-  MyView->SetViewMapping(MyViewMapping) ;
-  SetZSize(0.) ;
-#else
-  Xeye = Xpn*Zrp + Xat ; Yeye = Ypn*Zrp + Yat ; Zeye = Zpn*Zrp + Zat ;
-  Standard_Real Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
-
-  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
-    MyProjModel == V3d_TPM_SCREEN ) {
-      SetZSize(2.*Zmax+Zmax*Zmargin) ;
-    } else {
-      if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
-#ifdef IMP250200
-      if( Depth > 0. )
-#endif
-        MyView->SetViewMapping(MyViewMapping) ;
-    }
-#endif
+  {
+    // Move eye using center (target) as anchor.
+    aCamera->SetDistance (Depth);
+  }
+  else
+  {
+    // Move the view ref point instead of the eye.
+    gp_Vec aDir (aCamera->Direction());
+    gp_Pnt aCameraEye = aCamera->Eye();
+    gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
 
-    ImmediateUpdate();
+    aCamera->SetCenter (aCameraCenter);
+  }
 
-}
+  AutoZFit();
 
+  ImmediateUpdate();
+}
 
+//=============================================================================
+//function : SetProj
+//purpose  :
+//=============================================================================
 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
 {
+  V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
+    "V3d_View::SetProj, null projection vector");
 
-  Standard_Real Angle ;
+  Standard_Real aTwistBefore = Twist();
 
-  Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
-    "V3d_View::SetProj, null projection vector");
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  Angle = Twist() ;
-  MyViewReferencePlane.SetCoord(Vx,Vy,Vz) ;
-  MyViewReferencePlane.Normalize() ;
-  MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
-  Standard_Boolean update = myImmediateUpdate;
-  myImmediateUpdate = Standard_False;
-  if( MyProjModel == V3d_TPM_SCREEN ) SetTwist(Angle) ;
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  myImmediateUpdate = update;
-  ImmediateUpdate();
+  Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
 
-}
+  SetTwist(aTwistBefore);
 
-void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) {
+  AutoZFit();
+
+  SetImmediateUpdate (wasUpdateEnabled);
+
+  ImmediateUpdate();
+}
 
-  MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
-  MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
-  // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
-  MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex(0,0,0));
+//=============================================================================
+//function : SetProj
+//purpose  :
+//=============================================================================
+void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
+{
   Standard_Real Xpn=0;
   Standard_Real Ypn=0;
   Standard_Real Zpn=0;
 
   switch (Orientation) {
   case V3d_Zpos :
-    Ypn = 1. ;
-    break ;
+    Ypn = 1.;
+    break;
   case V3d_Zneg :
-    Ypn = -1. ;
-    break ;
+    Ypn = -1.;
+    break;
   default:
     Zpn = 1.;
   }
-  SetUp(Xpn,Ypn,Zpn);
-#ifdef IMP020300
-  SetZSize(0.) ;
-#endif
-  ImmediateUpdate();
 
-}
+  const gp_Dir aBck = V3d::GetProjAxis (Orientation);
 
-void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z) {
-
-  Standard_Real Angle,Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
-  Standard_Real Xeye,Yeye,Zeye ;
-
-  Angle = Twist() ;
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat ;
-  Xpn = Xeye - X ; Ypn = Yeye - Y ; Zpn = Zeye - Z ;
-  Zrp = Sqrt(Xpn*Xpn + Ypn*Ypn + Zpn*Zpn) ;
-  Viewer_BadValue_Raise_if( Zrp <= 0.,
-    "V3d_View::SetAt, Eye,At are Confused");
-
-  Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
-  MyViewReferencePoint.SetCoord(X,Y,Z) ;
-  MyViewOrientation.SetViewReferencePoint(MyViewReferencePoint) ;
-  MyViewReferencePlane.SetCoord(Xpn,Ypn,Zpn) ;
-  MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
-  MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-  MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
-  Standard_Boolean update = myImmediateUpdate;
-  myImmediateUpdate = Standard_False;
-  if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
-    //FMN desactivation temp SetTwist(Angle) ;
-    // Set infos.
-    MyView->SetViewOrientation(MyViewOrientation) ;
-    MyView->SetViewMapping(MyViewMapping) ;
-  } else {
-    SetTwist(Angle) ;
-  }
-#ifdef IMP020300
-  MyView->SetViewMapping(MyViewMapping);
-  SetZSize(0.) ;
-#else
-  ImmediateUpdate();
-  // Check ZClipping planes
-  Standard_Real Zmax = Sqrt( X*X + Y*Y + Z*Z ) ;
-  if( Zmax > MyViewMapping.FrontPlaneDistance() &&
-    MyProjModel == V3d_TPM_SCREEN ) {
-      SetZSize(2.*Zmax+Zmax*Zmargin) ;
-    } else {
-      if( MyType == V3d_PERSPECTIVE ) SetFocale(focale) ;
-      MyView->SetViewMapping(MyViewMapping);
-    }
-#endif
-    myImmediateUpdate = update;
-    ImmediateUpdate();
+  // retain camera panning from origin when switching projection
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-}
+  gp_Pnt anOriginVCS  = aCamera->ConvertWorld2View (gp::Origin());
+  Standard_Real aPanX = anOriginVCS.X();
+  Standard_Real aPanY = anOriginVCS.Y();
 
-void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz) {
+  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();
 
-  Standard_Boolean TheStatus ;
-  Viewer_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
-    "V3d_View::SetUp, nullUp vector");
+  Panning (aPanX, aPanY);
 
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
-  MyViewReferenceUp.Normalize() ;
-  TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-    MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,0.,1.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  Viewer_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
+  AutoZFit();
 
-  MyViewReferenceUp = MyYscreenAxis ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
   ImmediateUpdate();
-
 }
 
-void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) {
-
-  Standard_Boolean TheStatus ;
+//=============================================================================
+//function : SetAt
+//purpose  :
+//=============================================================================
+void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
+{
+  Standard_Real aTwistBefore = Twist();
 
-  MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-    MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,0.,1.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
-  }
-  Viewer_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  MyViewReferenceUp = MyYscreenAxis ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  ImmediateUpdate();
+  Camera()->SetCenter (gp_Pnt (X, Y, Z));
 
-}
+  SetTwist (aTwistBefore);
 
-void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
-{
-  MyViewOrientation = VO;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  ImmediateUpdate();
-}
+  AutoZFit();
 
-void V3d_View::SetViewOrientationDefault() {
+  SetImmediateUpdate (wasUpdateEnabled);
 
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  MyView->SetViewOrientationDefault() ;
   ImmediateUpdate();
 }
 
-void V3d_View::ResetViewOrientation() {
-
-  MyView->ViewOrientationReset() ;
-  MyViewOrientation = MyView->ViewOrientation() ;
-  ImmediateUpdate();
-}
+//=============================================================================
+//function : SetUp
+//purpose  :
+//=============================================================================
+void V3d_View::SetUp (const Standard_Real theVx, const Standard_Real theVy, const Standard_Real theVz)
+{
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
+  const gp_Dir anUp (theVx, theVy, theVz);
+  if (!screenAxis (aReferencePlane, anUp,     myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
+  {
+    throw V3d_BadValue ("V3d_View::Setup, alignment of Eye,At,Up");
+  }
 
-void V3d_View::Reset( const Standard_Boolean update ) {
+  aCamera->SetUp (gp_Dir (myYscreenAxis));
 
-  MyView->ViewOrientationReset() ;
-  MyViewOrientation = MyView->ViewOrientation() ;
-  MyView->ViewMappingReset();
-  MyViewMapping = MyView->ViewMapping() ;
+  AutoZFit();
 
-  ZFitAll (Zmargin);
-  SwitchSetFront = Standard_False;
-#ifdef IMP020300
-  if( !myImmediateUpdate && update ) Update();
-#else
   ImmediateUpdate();
-#endif
-
 }
 
-void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
+//=============================================================================
+//function : SetUp
+//purpose  :
+//=============================================================================
+void V3d_View::SetUp (const V3d_TypeOfOrientation theOrientation)
 {
+  Handle(Graphic3d_Camera) aCamera = Camera();
+
+  const gp_Dir aReferencePlane (aCamera->Direction().Reversed());
+  const gp_Dir anUp = V3d::GetProjAxis (theOrientation);
+  if (!screenAxis (aReferencePlane, anUp,     myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DZ(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DY(), myXscreenAxis, myYscreenAxis, myZscreenAxis)
+   && !screenAxis (aReferencePlane, gp::DX(), myXscreenAxis, myYscreenAxis, myZscreenAxis))
+  {
+    throw V3d_BadValue ("V3d_View::SetUp, alignment of Eye,At,Up");
+  }
 
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
-  Viewer_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
+  aCamera->SetUp (gp_Dir (myYscreenAxis));
 
-  if( Start ) {
-    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-    MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-    MyXwindowCenter = (Umin + Umax)/2. ;
-    MyYwindowCenter = (Vmin + Vmax)/2. ;
-    MyWindowWidth = Abs(Umax - Umin) ;
-    MyWindowHeight = Abs(Vmax - Vmin) ;
-    Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
-      "V3d_View::Panning, Window Size is NULL");
-  }
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  Xrp = MyXwindowCenter - Dx ;
-  Yrp = MyYwindowCenter - Dy ;
-  Dxv = MyWindowWidth/aZoomFactor ; Dyv = MyWindowHeight/aZoomFactor ;
-  Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
-  Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  if( MyType != V3d_PERSPECTIVE ) {
-    MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-    MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
-  }
-  MyView->SetViewMapping(MyViewMapping) ;
-  ImmediateUpdate();
+  AutoZFit();
 
+  ImmediateUpdate();
 }
-void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y) {
-  Standard_Real x,y;
-  Convert(X,Y,x,y);
-  SetCenter(x,y);
+
+//=============================================================================
+//function : SetViewOrientationDefault
+//purpose  :
+//=============================================================================
+void V3d_View::SetViewOrientationDefault()
+{
+  myDefaultCamera->CopyOrientationData (Camera());
 }
 
-void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc){
+//=======================================================================
+//function : SetViewMappingDefault
+//purpose  :
+//=======================================================================
+void V3d_View::SetViewMappingDefault()
+{
+  myDefaultCamera->CopyMappingData (Camera());
+}
 
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
+//=============================================================================
+//function : ResetViewOrientation
+//purpose  :
+//=============================================================================
+void V3d_View::ResetViewOrientation()
+{
+  Camera()->CopyOrientationData (myDefaultCamera);
 
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  MyXwindowCenter = Xrp = Xc ; MyYwindowCenter = Yrp = Yc ;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  MyWindowWidth = Abs(Umax - Umin) ; MyWindowHeight = Abs(Vmax - Vmin) ;
-  Viewer_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
-    "V3d_View::SetCenter, Window Size is NULL");
+  AutoZFit();
 
-  Umin = Xc - MyWindowWidth/2. ; Vmin = Yc - MyWindowHeight/2. ;
-  Umax = Xc + MyWindowWidth/2. ; Vmax = Yc + MyWindowHeight/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  if( MyType != V3d_PERSPECTIVE ) {
-    MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-    MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint) ;
-  }
-  MyView->SetViewMapping(MyViewMapping) ;
   ImmediateUpdate();
-
 }
 
-void V3d_View::SetSize(const Standard_Real Size)
+//=======================================================================
+//function : ResetViewMapping
+//purpose  :
+//=======================================================================
+void V3d_View::ResetViewMapping()
 {
+  Camera()->CopyMappingData (myDefaultCamera);
 
-  Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
-
-  Viewer_BadValue_Raise_if(  Size  <= 0.,
-    "V3d_View::SetSize, Window Size is NULL");
+  AutoZFit();
 
-
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  MyWindowWidth = Abs(Umax - Umin) ;
-  MyWindowHeight = Abs(Vmax - Vmin) ;
-  MyXwindowCenter = (Umin + Umax)/2. ;
-  MyYwindowCenter = (Vmin + Vmax)/2. ;
-  Rap = MyWindowWidth/MyWindowHeight ;
-  if( MyWindowWidth >= MyWindowHeight ) {
-    MyWindowWidth = Size ; MyWindowHeight = Size/Rap ;
-  } else {
-    MyWindowHeight = Size ; MyWindowWidth = Size*Rap ;
-  }
-  Umin = MyXwindowCenter - MyWindowWidth/2. ;
-  Vmin = MyYwindowCenter - MyWindowHeight/2. ;
-  Umax = MyXwindowCenter + MyWindowWidth/2. ;
-  Vmax = MyYwindowCenter + MyWindowHeight/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  MyView->SetViewMapping(MyViewMapping) ;
   ImmediateUpdate();
-
 }
 
-void V3d_View::SetZSize(const Standard_Real Size)
+//=============================================================================
+//function : Reset
+//purpose  :
+//=============================================================================
+void V3d_View::Reset (const Standard_Boolean theToUpdate)
 {
+  Camera()->Copy (myDefaultCamera);
 
-  Standard_Real Zmax = Size/2.;
-
-#ifdef IMP020300
-  if( Size <= 0. ) {
-    Standard_Real Xat,Yat,Zat,Xpn,Ypn,Zpn,Xrp,Yrp,Zrp,Xeye,Yeye,Zeye;
-    MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-    MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-    MyViewReferencePlane.Coord(Xpn,Ypn,Zpn) ;
-    Xeye = Zrp*Xpn + Xat ; Yeye = Zrp*Ypn + Yat ; Zeye = Zrp*Zpn + Zat;
-    Zmax = Sqrt( Xeye*Xeye + Yeye*Yeye + Zeye*Zeye );
-    if( Zmax <= MyViewMapping.FrontPlaneDistance() ) return;
-  }
-#else
-  Viewer_BadValue_Raise_if(  Size  <= 0.,
-    "V3d_View::SetZSize, Window ZSize is NULL");
-#endif
-
-  Standard_Real Front = MyViewContext.ZClippingFrontPlane() ;
-  Standard_Real Back  = MyViewContext.ZClippingBackPlane() ;
-  Standard_Real focale= Focale();
+  AutoZFit();
 
-  MyViewMapping.SetFrontPlaneDistance(Zmax) ;
-  MyViewMapping.SetBackPlaneDistance(-Zmax) ;
+  SwitchSetFront = Standard_False;
 
-  // OCC18942
-  if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
-    MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Update();
   }
+}
 
-  MyView->SetViewMapping(MyViewMapping) ;
-  if( MyViewContext.FrontZClippingIsOn()  ||
-    MyViewContext.BackZClippingIsOn() ) {
-      MyViewContext.SetZClippingFrontPlane(Front) ;
-      MyViewContext.SetZClippingBackPlane(Back) ;
-      MyView->SetContext(MyViewContext) ;
-    }
+//=======================================================================
+//function : SetCenter
+//purpose  :
+//=======================================================================
+void V3d_View::SetCenter (const Standard_Integer theXp,
+                          const Standard_Integer theYp)
+{
+  Standard_Real aXv, aYv;
+  Convert (theXp, theYp, aXv, aYv);
+  Translate (Camera(), aXv, aYv);
 
+  ImmediateUpdate();
 }
 
-void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
+//=============================================================================
+//function : SetSize
+//purpose  :
+//=============================================================================
+void V3d_View::SetSize (const Standard_Real theSize)
 {
+  V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
 
-  Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
-  Viewer_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  if( Start ) {
-    MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-    MyXwindowCenter = (Umin + Umax)/2. ;
-    MyYwindowCenter = (Vmin + Vmax)/2. ;
-    MyWindowWidth = Abs(Umax - Umin) ;
-    MyWindowHeight = Abs(Vmax - Vmin) ;
-  }
+  aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize);
+
+  AutoZFit();
 
-  // ensure that zoom will not be too small or too big
-  Standard_Real coef = Coef;
-  if ( MyWindowWidth < coef * Precision::Confusion() )
-    coef = MyWindowWidth / Precision::Confusion();
-  else if ( MyWindowWidth > coef * 1e12 )
-    coef = MyWindowWidth / 1e12;
-  if ( MyWindowHeight < coef * Precision::Confusion() )
-    coef = MyWindowHeight / Precision::Confusion();
-  else if ( MyWindowHeight > coef * 1e12 )
-    coef = MyWindowHeight / 1e12;
-
-  Dxv = MyWindowWidth/coef;
-  Dyv = MyWindowHeight/coef;
-  Umin = MyXwindowCenter - Dxv/2. ; Umax = MyXwindowCenter + Dxv/2. ;
-  Vmin = MyYwindowCenter - Dyv/2. ; Vmax = MyYwindowCenter + Dyv/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  MyView->SetViewMapping(MyViewMapping) ;
   ImmediateUpdate();
 }
 
-void V3d_View::SetScale( const Standard_Real Coef ) {
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
-  Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
-
-  Viewer_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
-
-  VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Dxv = Abs(Umax - Umin) ; Dyv = Abs(Vmax - Vmin) ;
-  Dxv /= Coef ; Dyv /= Coef ;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
-  Umin = Xrp - Dxv/2. ; Umax = Xrp + Dxv/2. ;
-  Vmin = Yrp - Dyv/2. ; Vmax = Yrp + Dyv/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  MyView->SetViewMapping(MyViewMapping) ;
-  ImmediateUpdate();
+//=============================================================================
+//function : SetZSize
+//purpose  :
+//=============================================================================
+void V3d_View::SetZSize (const Standard_Real theSize)
+{
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-}
+  Standard_Real Zmax = theSize / 2.;
 
-void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz ) {
+  Standard_Real aDistance = aCamera->Distance();
 
-  Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
-  Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
-  Viewer_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
+  if (theSize <= 0.)
+  {
+    Zmax = aDistance;
+  }
 
-  MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
-  Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
-  MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
-  MyView->SetViewOrientation(MyViewOrientation);
-  MyView->ViewManager()->SetUpdateMode(updateMode);
+  // ShortReal precision factor used to add meaningful tolerance to
+  // ZNear, ZFar values in order to avoid equality after type conversion
+  // to ShortReal matrices type.
+  const Standard_Real aPrecision = 1.0 / Pow (10.0, ShortRealDigits() - 1);
 
-  MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
+  Standard_Real aZFar  =  Zmax  + aDistance * 2.0;
+  Standard_Real aZNear = -Zmax  + aDistance;
+  aZNear              -= Abs (aZNear) * aPrecision;
+  aZFar               += Abs (aZFar)  * aPrecision;
 
-  Standard_Real LIM = ShortRealLast() -1.;
-  if     (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
-    ||  Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
-      return;
+  if (!aCamera->IsOrthographic())
+  {
+    if (aZFar < aPrecision)
+    {
+      // Invalid case when both values are negative
+      aZNear = aPrecision;
+      aZFar  = aPrecision * 2.0;
     }
+    else if (aZNear < Abs (aZFar) * aPrecision)
+    {
+      // Z is less than 0.0, try to fix it using any appropriate z-scale
+      aZNear = Abs (aZFar) * aPrecision;
+    }
+  }
 
-    MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
-    MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
-    Umax = Max(Umin,Umax) ; Vmax = Max(Vmin,Vmax) ;
-    MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
-    Umax = Max(Umax,U) ; Vmax = Max(Vmax,V) ;
-    Umax = Max(Umax,Vmax) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
-    Wmax = Max(Abs(Umax),Abs(Wmax)) ;
+  // If range is too small
+  if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
+  {
+    aZFar = aZNear + Abs (aZFar) * aPrecision;
+  }
 
-    if( Wmax > 0. ) {
-      SetZSize(2.*Wmax + Wmax) ;
-    }
+  aCamera->SetZRange (aZNear, aZFar);
 
+  if (myImmediateUpdate)
+  {
+    Redraw();
+  }
 }
 
-void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
-                      const Standard_Boolean update)
+//=============================================================================
+//function : SetZoom
+//purpose  :
+//=============================================================================
+void V3d_View::SetZoom (const Standard_Real theCoef,const Standard_Boolean theToStart)
 {
-  Standard_Real Umin, Umax, Vmin, Vmax, Xrp, Yrp, Zrp, U, V, W, U1, V1, W1;
-  Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
-  Standard_Real DxvOld, DyvOld, DxvNew, DyvNew;
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures();
+  V3d_BadValue_Raise_if (theCoef <= 0., "V3d_View::SetZoom, bad coefficient");
 
-  if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
-  {
-#ifndef IMP020300
-    ImmediateUpdate();
-#endif
-    return;
-  }
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-  MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
-  if (MyView->IsDefined())
+  if (theToStart)
   {
-    Standard_Integer Xpixel, Ypixel;
-    MyWindow->Size (Xpixel, Ypixel);
-    DxvOld = Xpixel;
-    DyvOld = Ypixel;
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
   }
-  else
+
+  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 = theCoef;
+  if (aViewWidth < aCoef * Precision::Confusion())
   {
-    MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
-    DxvOld = Abs (Umax - Umin);
-    DyvOld = Abs (Vmax - Vmin);
+    aCoef = aViewWidth / Precision::Confusion();
   }
-  if ((DxvOld == 0.0) || (DyvOld == 0.0))
+  else if (aViewWidth > aCoef * 1e12)
   {
-    return;
+    aCoef = aViewWidth / 1e12;
   }
-
-  Standard_Real aWinRatio = DxvOld / DyvOld;
-
-  // retrieve min / max values for current displayed objects
-  MyView->MinMaxValues (Xmin, Ymin, Zmin,
-                        Xmax, Ymax, Zmax);
-
-  Standard_Real LIM = ShortRealLast() - 1.0;
-  if  (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
-    || Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM)
+  if (aViewHeight < aCoef * Precision::Confusion())
   {
-#ifndef IMP020300
-    ImmediateUpdate();
-#endif
-    return;
+    aCoef = aViewHeight / Precision::Confusion();
   }
-
-  // eliminate fluctuations between sequential FitAll() calls
-  MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
-  if (MyType != V3d_PERSPECTIVE)
+  else if (aViewHeight > aCoef * 1e12)
   {
-    MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
-    MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
+    aCoef = aViewHeight / 1e12;
   }
-  MyView->SetViewMapping (MyViewMapping);
-
-  // iterate 2 times to find optimal view plane size
-  // (use view plane values computed on previous iteration)
-  for (Standard_Integer aIteration = 2; aIteration > 0; --aIteration)
-  {
-    MyView->Projects (Xmin, Ymin, Zmin,  U,  V,  W);
-    MyView->Projects (Xmax, Ymax, Zmax, U1, V1, W1);
-    Umin = Min (U, U1); Umax = Max (U, U1);
-    Vmin = Min (V, V1); Vmax = Max (V, V1);
 
-    MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  aCamera->SetEye (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+  aCamera->SetScale (aCamera->Scale() / aCoef);
 
-    MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  AutoZFit();
 
-    MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  ImmediateUpdate();
+}
 
-    MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+//=============================================================================
+//function : SetScale
+//purpose  :
+//=============================================================================
+void V3d_View::SetScale( const Standard_Real Coef )
+{
+  V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient");
 
-    MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-    MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  Standard_Real aDefaultScale = myDefaultCamera->Scale();
+  aCamera->SetAspect (myDefaultCamera->Aspect());
+  aCamera->SetScale (aDefaultScale / Coef);
 
-    DxvNew = Abs (Umax - Umin);
-    DyvNew = Abs (Vmax - Vmin);
+  AutoZFit();
 
-    if (DyvNew < 10.0 * Precision::Confusion())
-    {
-      if (DxvNew < 10.0 * Precision::Confusion())
-      {
-        // whole scene projected to point
-        DxvNew = Max (Abs (Zmax - Zmin), (Max (Abs (Xmax - Xmin), Abs (Ymax - Ymin))));
-        if (DxvNew < 10.0 * Precision::Confusion())
-        {
-          // this is really just one (!) point and zooming has no any effect
-          // just center the view
-          DyvNew = DyvOld;
-          DxvNew = DxvOld;
-        }
-        else
-        {
-          // we look along some line
-          // fit view like that to see whole scene on rotation
-          DxvNew += Coef * DxvNew;
-          DyvNew = DxvNew / aWinRatio;
-        }
-      }
-      else
-      {
-        // whole scene projected to horizontal line
-        DxvNew += Coef * DxvNew;
-        DyvNew = DxvNew / aWinRatio;
-      }
-    }
-    else
-    {
-      // general case (or DxvNew == 0.0 - vertical line)
-      // safe original ratio
-      Standard_Real aFitRatio = DxvNew / DyvNew;
-      if (aFitRatio >= aWinRatio)
-      {
-        DxvNew += Coef * DxvNew;
-        DyvNew = DxvNew / aWinRatio;
-      }
-      else
-      {
-        DyvNew += Coef * DyvNew;
-        DxvNew = DyvNew * aWinRatio;
-      }
-    }
+  ImmediateUpdate();
+}
 
-    // new scene center
-    Xrp = 0.5 * (Umin + Umax);
-    Yrp = 0.5 * (Vmin + Vmax);
+//=============================================================================
+//function : SetAxialScale
+//purpose  :
+//=============================================================================
+void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
+{
+  V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
 
-    // new window limits
-    Umin = Xrp - 0.5 * DxvNew;
-    Umax = Xrp + 0.5 * DxvNew;
-    Vmin = Yrp - 0.5 * DyvNew;
-    Vmax = Yrp + 0.5 * DyvNew;
-    MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
+  Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
 
-    if (MyType != V3d_PERSPECTIVE)
-    {
-      // center the view
-      MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
-      MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
-    }
-    MyView->SetViewMapping (MyViewMapping);
-  }
+  AutoZFit();
+}
 
-  if (FitZ)
-  {
-    ZFitAll (Zmargin);
-#ifdef IMP020300
-  }
-  else
+//=============================================================================
+//function : SetRatio
+//purpose  :
+//=============================================================================
+void V3d_View::SetRatio()
+{
+  if (MyWindow.IsNull())
   {
-    ImmediateUpdate();
-#endif
+    return;
   }
-#ifdef IMP020300
-  if (!myImmediateUpdate && update)
+
+  Standard_Integer aWidth  = 0;
+  Standard_Integer aHeight = 0;
+  MyWindow->Size (aWidth, aHeight);
+  if (aWidth > 0 && aHeight > 0)
   {
-    Update();
+    Standard_Real aRatio = static_cast<Standard_Real> (aWidth) /
+                           static_cast<Standard_Real> (aHeight);
+
+    Camera()       ->SetAspect (aRatio);
+    myDefaultCamera->SetAspect (aRatio);
   }
-#endif
 }
 
-void V3d_View::ZFitAll(const Standard_Real Coef) {
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
+void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate)
+{
+  FitAll (myView->MinMaxValues(), theMargin, theToUpdate);
+}
 
-  Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
-  Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
-  // CAL 6/11/98
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
+void V3d_View::FitAll (const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Boolean theToUpdate)
+{
+  Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
 
-  if( MyType == V3d_PERSPECTIVE ) {
-    ImmediateUpdate();
-    return ;
+  if (myView->NumberOfDisplayedStructures() == 0)
+  {
+    return;
   }
 
-  if( (Nstruct <= 0) || (Coef < 0.) ) {
-    ImmediateUpdate();
-    return ;
+  if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion()))
+  {
+    return;
   }
 
-  MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
-
-  Standard_Real LIM = ShortRealLast() -1.;
-  if   (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
-    ||  Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
-      ImmediateUpdate();
-      return ;
-    }
+  AutoZFit();
 
-    // CAL 6/11/98
-    // Case when view contains only a point
-    if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
-      ImmediateUpdate();
-      return ;
-    }
-    MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ;
-    MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ;
-    MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
-    Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ;
-    Wmax = Max(Abs(Wmin),Abs(Wmax)) ;
-    if( Wmax > 0. ) {
-      SetZSize(2.*Wmax + Coef * Wmax) ;
-    }
-    ImmediateUpdate();
+  if (myImmediateUpdate || theToUpdate)
+  {
+    Update();
+  }
 }
 
-void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
-                           const Quantity_Coefficient Margin)
+//=============================================================================
+//function : DepthFitAll
+//purpose  :
+//=============================================================================
+void V3d_View::DepthFitAll(const Standard_Real Aspect,
+                           const Standard_Real Margin)
 {
   Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W,U1,V1,W1 ;
   Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
-  Standard_Real Xrp,Yrp,Zrp,Dx,Dy,Dz,Size;
+  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.)) {
+  if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) {
     ImmediateUpdate();
     return ;
   }
 
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-
-  MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
-
-  Standard_Real LIM = ShortRealLast() -1.;
-  if     (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
-    ||  Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM ) {
-      ImmediateUpdate();
-      return ;
-    }
-
-    if (Xmin == Xmax && Ymin == Ymax && Zmin == Zmax) {
-      ImmediateUpdate();
-      return ;
-    }
-    MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
-    MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ;
+  Bnd_Box aBox = myView->MinMaxValues();
+  if (aBox.IsVoid())
+  {
+    ImmediateUpdate();
+    return ;
+  }
+    aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
+    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) ;
@@ -2080,308 +1486,436 @@ void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
     ImmediateUpdate();
 }
 
-void V3d_View::FitAll(const Standard_Real Xmin, const Standard_Real Ymin, const Standard_Real Xmax, const Standard_Real Ymax) {
-  FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
-#ifndef IMP020300
-  ImmediateUpdate();
-#endif
-}
-
-void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
-  WindowFit(Xmin,Ymin,Xmax,Ymax);
-
-}
-void V3d_View::WindowFit(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax) {
-  Standard_Real x1,y1,x2,y2;
-  Convert(Xmin,Ymin,x1,y1);
-  Convert(Xmax,Ymax,x2,y2);
-  FitAll(x1,y1,x2,y2);
-}
-
-void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
+//=======================================================================
+//function : WindowFit
+//purpose  :
+//=======================================================================
+void V3d_View::WindowFit (const Standard_Integer theMinXp,
+                          const Standard_Integer theMinYp,
+                          const Standard_Integer theMaxXp,
+                          const Standard_Integer theMaxYp)
 {
-  MyViewMapping = VM;
-  // ajust view type according to mapping projection
-  // NOTE: Might be dangerous, potentially conflicts with the C++ view class
-  // (orthographic or perspective)! Use with care!
-  if ( VM.Projection() == Visual3d_TOP_PERSPECTIVE )
-    MyType = V3d_PERSPECTIVE;
-  else MyType = V3d_ORTHOGRAPHIC;
-
-  MyView->SetViewMapping(MyViewMapping) ;
-  ImmediateUpdate();
-}
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-void V3d_View::SetViewMappingDefault() {
-  MyView->SetViewMapping(MyViewMapping) ;
-  MyView->SetViewMappingDefault();
-  ImmediateUpdate();
-}
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-void V3d_View::ResetViewMapping() {
+  if (!aCamera->IsOrthographic())
+  {
+    // normalize view coordinates
+    Standard_Integer aWinWidth, aWinHeight;
+    MyWindow->Size (aWinWidth, aWinHeight);
 
-  MyView->ViewMappingReset();
-  MyViewMapping = MyView->ViewMapping() ;
-#ifdef IMP020300
-  ZFitAll (Zmargin);
-  Update();
-#else
-  ImmediateUpdate();
-#endif
-}
+    // z coordinate of camera center
+    Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z();
 
-Standard_Real V3d_View::Convert(const Standard_Integer Vp) const {
-  Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
-  Standard_Integer Dxw,Dyw ;
+    // camera projection coordinate are in NDC which are normalized [-1, 1]
+    Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp  - 1.0;
+    Standard_Real aUMax = (2.0 / aWinWidth) * theMaxXp  - 1.0;
+    Standard_Real aVMin = (2.0 / aWinHeight) * theMinYp - 1.0;
+    Standard_Real aVMax = (2.0 / aWinHeight) * theMaxYp - 1.0;
 
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+    // 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 = aCamera->ConvertProj2View (aFitCenter);
+    gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter);
+    gp_Vec aPanVec (aPanFrom, aPanTo);
 
-  MyWindow->Size(Dxw,Dyw);
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Dxv = Umax - Umin ;
-  Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
+    // compute section size
+    gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
+    gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
+    gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft);
+    gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight);
 
-  return Vv ;
-}
+    Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
+    Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
 
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const {
-  Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Dyv ;
-  Standard_Integer Dxw,Dyw ;
+    Translate (aCamera, aPanVec.X(), -aPanVec.Y());
+    Scale (aCamera, aUSize, aVSize);
+    AutoZFit();
+  }
+  else
+  {
+    Standard_Real aX1, aY1, aX2, aY2;
+    Convert (theMinXp, theMinYp, aX1, aY1);
+    Convert (theMaxXp, theMaxYp, aX2, aY2);
+    FitAll (aX1, aY1, aX2, aY2);
+  }
 
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  SetImmediateUpdate (wasUpdateEnabled);
 
-  MyWindow->Size(Dxw,Dyw);
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Dxv = Umax - Umin ; Dyv = Vmax - Vmin ;
-  Xv = Umin + Dxv*(Standard_Real)Xp/(Standard_Real)Dxw ;
-  Yv = Vmin + Dyv*(Standard_Real)(Dyw-Yp)/(Standard_Real)Dyw ;
+  ImmediateUpdate();
 }
 
-Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
+//=======================================================================
+//function : ConvertToGrid
+//purpose  :
+//=======================================================================
+void V3d_View::ConvertToGrid(const Standard_Integer Xp,
+                             const Standard_Integer Yp,
+                             Standard_Real& Xg,
+                             Standard_Real& Yg,
+                             Standard_Real& Zg) const
 {
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
-
-  Standard_Integer Dxw, Dyw;
-  MyWindow->Size(Dxw,Dyw);
+  Graphic3d_Vertex aVrp;
+  Standard_Real anX, anY, aZ;
+  Convert (Xp, Yp, anX, anY, aZ);
+  aVrp.SetCoord (anX, anY, aZ);
 
-  Standard_Real Umin,Umax,Vmin,Vmax;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Standard_Real Dxv = Umax - Umin;
-  return RealToInt ( Dxw * Vv / Dxv );
+  if( MyViewer->Grid()->IsActive() ) {
+    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
+    aNewVrp.Coord (Xg,Yg,Zg) ;
+  } else
+    aVrp.Coord (Xg,Yg,Zg) ;
+}
+
+//=======================================================================
+//function : ConvertToGrid
+//purpose  :
+//=======================================================================
+void V3d_View::ConvertToGrid(const Standard_Real X,
+                             const Standard_Real Y,
+                             const Standard_Real Z,
+                             Standard_Real& Xg,
+                             Standard_Real& Yg,
+                             Standard_Real& Zg) const
+{
+  if( MyViewer->Grid()->IsActive() ) {
+    Graphic3d_Vertex aVrp (X,Y,Z) ;
+    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
+    aNewVrp.Coord(Xg,Yg,Zg) ;
+  } else {
+    Xg = X; Yg = Y; Zg = Z;
+  }
 }
 
-void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
 {
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
-
-  Standard_Integer Dxw, Dyw;
-  MyWindow->Size(Dxw,Dyw);
+  Standard_Integer aDxw, aDyw ;
 
-  Standard_Real Umin,Umax,Vmin,Vmax;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Standard_Real Dxv = Umax - Umin;
-  Standard_Real Dyv = Vmax - Vmin;
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
-  // CAL 15/12/93 warning:  double  assigned to  int
-  Xp = RealToInt (Dxw*(Xv - Umin)/Dxv);
-  // CAL 15/12/93 warning:  double  assigned to  int
-  Yp = Dyw - RealToInt (Dyw*(Yv - Vmin)/Dyv);
-}
+  MyWindow->Size (aDxw, aDyw);
+  Standard_Real aValue;
 
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
+  aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
 
-  Graphic3d_Vertex Vrp ;
-  Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
-  Vrp.Coord(X,Y,Z) ;
-#ifndef IMP240100
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(X,Y,Z) ;
-  }
-#endif
+  return aValue;
 }
 
-void V3d_View::ConvertWithProj(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+void V3d_View::Convert(const Standard_Integer Xp,
+                       const Standard_Integer Yp,
+                       Standard_Real& Xv,
+                       Standard_Real& Yv) const
 {
-  Graphic3d_Vertex Vrp ;
-  Graphic3d_Vector Proj ;
-  (MyViewer->Viewer())->ConvertCoordWithProj(MyWindow,Xp,Yp, Vrp, Proj) ;
-  Vrp.Coord(X,Y,Z) ;
-  Proj.Coord(Dx,Dy,Dz) ;
-#ifndef IMP240100
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(X,Y,Z) ;
-  }
-#endif
-}
+  Standard_Integer aDxw, aDyw;
 
-#ifdef IMP240100
-void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
-  Graphic3d_Vertex Vrp ;
-  Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(Xg,Yg,Zg) ;
-  } else
-    Vrp.Coord(Xg,Yg,Zg) ;
-}
+  MyWindow->Size (aDxw, aDyw);
 
-void V3d_View::ConvertToGrid(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const {
+  gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
+  aPoint = Camera()->ConvertProj2View (aPoint);
 
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex Vrp(X,Y,Z) ;
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(Xg,Yg,Zg) ;
-  } else {
-    Xg = X; Yg = Y; Zg = Z;
-  }
+  Xv = aPoint.X();
+  Yv = aPoint.Y();
 }
-#endif
 
-#ifndef IMP240100
-void V3d_View::PixToRef(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
+{
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
-  Graphic3d_Vertex Vrp ;
-  Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
-  Vrp.Coord(X,Y,Z) ;
-  if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(X,Y,Z) ;
-  }
-}
-#endif
+  Standard_Integer aDxw, aDyw;
+  MyWindow->Size (aDxw, aDyw);
 
-#ifdef IMP240100
-void V3d_View::Convert(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
-#else
-void V3d_View::RefToPix(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Integer& Xp, Standard_Integer& Yp) const {
-#endif
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
+  Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
 
-  Graphic3d_Vertex Vrp(X,Y,Z) ;
-  (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
+  return aValue;
 }
 
-void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+void V3d_View::Convert(const Standard_Real Xv,
+                       const Standard_Real Yv,
+                       Standard_Integer& Xp,
+                       Standard_Integer& Yp) const
 {
-  if ( MyType != V3d_PERSPECTIVE )
-  {
-    // use old implementation
-    Standard_Real Zp;
-    MyView->Projects( X, Y, Z, Xp, Yp, Zp );
-  }
-  else
-  {
-    // NKV - Using raster projection
-    Standard_Integer Xpx, Ypx;
-    Convert(X, Y, Z, Xpx, Ypx);
-    Convert(Xpx, Ypx, Xp, Yp);
-  }
-}
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
 
-void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3)const  {
+  Standard_Integer aDxw, aDyw;
+  MyWindow->Size (aDxw, aDyw);
 
-#ifdef GER61351
-  Quantity_Color C = BackgroundColor() ;
-#else
-  Quantity_Color C ;
-  C = MyBackground.Color() ;
-#endif
-  C.Values(V1,V2,V3,Type) ;
+  gp_Pnt aPoint (Xv, Yv, 0.0);
+  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());
+  Yp = RealToInt (aPoint.Y());
 }
 
-#ifdef GER61351
-Quantity_Color V3d_View::BackgroundColor() const  {
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+void V3d_View::Convert(const Standard_Integer Xp,
+                       const Standard_Integer Yp,
+                       Standard_Real& X,
+                       Standard_Real& Y,
+                       Standard_Real& Z) const
+{
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
+  Standard_Integer aHeight, aWidth;
+  MyWindow->Size (aWidth, aHeight);
+
+  Standard_Real anX = 2.0 * Xp / aWidth - 1.0;
+  Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0;
+  Standard_Real  aZ = 2.0 * 0.0 - 1.0;
+
+  gp_Pnt aResult = Camera()->UnProject (gp_Pnt (anX, anY, aZ));
+
+  X = aResult.X();
+  Y = aResult.Y();
+  Z = aResult.Z();
+}
+
+//=======================================================================
+//function : ConvertWithProj
+//purpose  :
+//=======================================================================
+void V3d_View::ConvertWithProj(const Standard_Integer theXp,
+                               const Standard_Integer theYp,
+                               Standard_Real& theX,
+                               Standard_Real& theY,
+                               Standard_Real& theZ,
+                               Standard_Real& theDx,
+                               Standard_Real& theDy,
+                               Standard_Real& theDz) const
+{
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
+  Standard_Integer aHeight = 0, aWidth = 0;
+  MyWindow->Size (aWidth, aHeight);
+
+  const Standard_Real anX = 2.0 * theXp / aWidth - 1.0;
+  const Standard_Real anY = 2.0 * (aHeight - 1 - theYp) / aHeight - 1.0;
+  const Standard_Real  aZ = 2.0 * 0.0 - 1.0;
+
+  const Handle(Graphic3d_Camera)& aCamera = Camera();
+  const gp_Pnt aResult1 = aCamera->UnProject (gp_Pnt (anX, anY, aZ));
+  const gp_Pnt aResult2 = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
+
+  theX = aResult1.X();
+  theY = aResult1.Y();
+  theZ = aResult1.Z();
+  Graphic3d_Vec3d aNormDir (theX - aResult2.X(),
+                            theY - aResult2.Y(),
+                            theZ - aResult2.Z());
+  aNormDir.Normalize();
+
+  theDx = aNormDir.x();
+  theDy = aNormDir.y();
+  theDz = aNormDir.z();
+}
+
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+void V3d_View::Convert(const Standard_Real X,
+                       const Standard_Real Y,
+                       const Standard_Real Z,
+                       Standard_Integer& Xp,
+                       Standard_Integer& Yp) const
+{
+  V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window");
+  Standard_Integer aHeight, aWidth;
+  MyWindow->Size (aWidth, aHeight);
 
-  return MyBackground.Color() ;
-}
-#endif
+  gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z));
 
-void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const{
-  MyGradientBackground.Colors(Color1, Color2);
+  Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
+  Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight);
 }
 
-Aspect_GradientBackground V3d_View::GradientBackground() const {
-   return MyGradientBackground;
-}
+//=======================================================================
+//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) 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
+{
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-Standard_Real V3d_View::Scale()const  {
-  Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
-  Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
-  Standard_Real S = 0. ;
+  gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
+  Standard_Real aXSize = aViewSpaceDimensions.X();
+  Standard_Real aYSize = aViewSpaceDimensions.Y();
+  Standard_Real aZSize = aViewSpaceDimensions.Z();
 
-  VMD.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Dxv = Umax - Umin ;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  if( Umax > Umin && Vmax > Vmin ) S = Dxv/(Umax - Umin) ;
-  return S ;
-}
+  gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
 
-void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz)const  {
-  MyViewOrientation.AxialScale( Sx, Sy, Sz );
+  // 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;
 }
 
-void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const {
-
-  Standard_Real Umin,Vmin,Umax,Vmax ;
+//=======================================================================
+//function : BackgroundColor
+//purpose  :
+//=======================================================================
+void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,
+                               Standard_Real& V1,
+                               Standard_Real& V2,
+                               Standard_Real& V3) const
+{
+  Quantity_Color C = BackgroundColor() ;
+  C.Values(V1,V2,V3,Type) ;
+}
 
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Xc = (Umin + Umax)/2. ;
-  Yc = (Vmin + Vmax)/2. ;
+//=======================================================================
+//function : BackgroundColor
+//purpose  :
+//=======================================================================
+Quantity_Color V3d_View::BackgroundColor() const
+{
+  return myView->Background().Color() ;
 }
 
-void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const {
+//=======================================================================
+//function : GradientBackgroundColors
+//purpose  :
+//=======================================================================
+void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const
+{
+  myView->GradientBackground().Colors (theColor1, theColor2);
+}
 
-  Standard_Real Umin,Vmin,Umax,Vmax ;
+//=======================================================================
+//function : GradientBackground
+//purpose  :
+//=======================================================================
+Aspect_GradientBackground V3d_View::GradientBackground() const
+{
+  return myView->GradientBackground();
+}
 
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Width = Umax - Umin ;
-  Height = Vmax - Vmin ;
+//=======================================================================
+//function : Scale
+//purpose  :
+//=======================================================================
+Standard_Real V3d_View::Scale() const
+{
+  return myDefaultCamera->Scale() / Camera()->Scale();
 }
 
-Standard_Real V3d_View::ZSize() const {
+//=======================================================================
+//function : AxialScale
+//purpose  :
+//=======================================================================
+void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
+{
+  gp_Pnt anAxialScale = Camera()->AxialScale();
+  Sx = anAxialScale.X();
+  Sy = anAxialScale.Y();
+  Sz = anAxialScale.Z();
+}
 
-  Standard_Real Wmin,Wmax,Depth ;
+//=======================================================================
+//function : Size
+//purpose  :
+//=======================================================================
+void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
+{
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
 
-  Wmax = MyViewMapping.FrontPlaneDistance() ;
-  Wmin = MyViewMapping.BackPlaneDistance() ;
-  Depth = 2. * Max(Wmin,Wmax) ;
-  return (Depth) ;
+  Width = aViewDims.X();
+  Height = aViewDims.Y();
 }
 
-Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const {
+//=======================================================================
+//function : ZSize
+//purpose  :
+//=======================================================================
+Standard_Real V3d_View::ZSize() const
+{
+  gp_Pnt aViewDims = Camera()->ViewDimensions();
+
+  return aViewDims.Z();
+}
 
+//=======================================================================
+//function : MinMax
+//purpose  :
+//=======================================================================
+Standard_Integer V3d_View::MinMax(Standard_Real& Umin,
+                                  Standard_Real& Vmin,
+                                  Standard_Real& Umax,
+                                  Standard_Real& Vmax) const
+{
   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 ) {
-    MyView->MinMaxValues(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) ;
+    Bnd_Box aBox = myView->MinMaxValues();
+    aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
+    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) ;
@@ -2389,666 +1923,531 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Stan
   return Nstruct ;
 }
 
-Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Standard_Real& Zmin, Standard_Real& Xmax, Standard_Real& Ymax, Standard_Real& Zmax) const {
+//=======================================================================
+//function : MinMax
+//purpose  :
+//=======================================================================
+Standard_Integer V3d_View::MinMax(Standard_Real& Xmin,
+                                  Standard_Real& Ymin,
+                                  Standard_Real& Zmin,
+                                  Standard_Real& Xmax,
+                                  Standard_Real& Ymax,
+                                  Standard_Real& Zmax) const
+{
   // CAL 6/11/98
   // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ;
-  Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ;
+  Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ;
 
   if( Nstruct ) {
-    MyView->MinMaxValues(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax) ;
+    Bnd_Box aBox = myView->MinMaxValues();
+    aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax);
   }
   return Nstruct ;
 }
 
-Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
-
-  Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
-  Standard_Real Umin,Vmin,Umax,Vmax ;
-  Standard_Integer Nstruct,Npoint ;
-  Graphic3d_MapOfStructure MySetOfStructures;
-
-  MyView->DisplayedStructures (MySetOfStructures);
-  Nstruct = MySetOfStructures.Extent() ;
-
-  Graphic3d_MapIteratorOfMapOfStructure MyIterator(MySetOfStructures) ;
-
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Npoint = 0 ; X = Y = Z = 0. ;
-  for( ; MyIterator.More(); MyIterator.Next()) {
-    if (!(MyIterator.Key())->IsEmpty()) {
-      (MyIterator.Key())->MinMaxValues(Xmin,Ymin,Zmin,
-        Xmax,Ymax,Zmax) ;
-
-      Standard_Real LIM = ShortRealLast() -1.;
-      if (!    (Abs(Xmin) > LIM || Abs(Ymin) > LIM || Abs(Zmin) > LIM
-        ||  Abs(Xmax) > LIM || Abs(Ymax) > LIM || Abs(Zmax) > LIM )) {
-
-          MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmin ;
-          }
-          MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmin ;
-          }
-          MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmin ;
-          }
-          MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmin ;
-          }
-          MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmin ; Y += Ymin ; Z += Zmax ;
-          }
-          MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmax ; Y += Ymin ; Z += Zmax ;
-          }
-          MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmin ; Y += Ymax ; Z += Zmax ;
-          }
-          MyView->Projects(Xmax,Ymax,Zmax,U,V,W) ;
-          if( U >= Umin && U <= Umax && V >= Vmin && V <= Vmax ) {
-            Npoint++ ; X += Xmax ; Y += Ymax ; Z += Zmax ;
-          }
-        }
+//=======================================================================
+//function : Gravity
+//purpose  :
+//=======================================================================
+void V3d_View::Gravity (Standard_Real& theX,
+                        Standard_Real& theY,
+                        Standard_Real& theZ) const
+{
+  Graphic3d_MapOfStructure aSetOfStructures;
+  myView->DisplayedStructures (aSetOfStructures);
+
+  Standard_Boolean hasSelection = Standard_False;
+  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
+       aStructIter.More(); aStructIter.Next())
+  {
+    if (aStructIter.Key()->IsHighlighted()
+     && aStructIter.Key()->IsVisible())
+    {
+      hasSelection = Standard_True;
+      break;
     }
   }
-  if( Npoint > 0 ) {
-    X /= Npoint ; Y /= Npoint ; Z /= Npoint ;
-  }
 
-  return Nstruct ;
-}
+  Standard_Real Xmin, Ymin, Zmin, Xmax, Ymax, Zmax;
+  Standard_Integer aNbPoints = 0;
+  gp_XYZ aResult (0.0, 0.0, 0.0);
+  for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures);
+       aStructIter.More(); aStructIter.Next())
+  {
+    const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
+    if (!aStruct->IsVisible()
+      || aStruct->IsInfinite()
+      || (hasSelection && !aStruct->IsHighlighted()))
+    {
+      continue;
+    }
 
-void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
-  Graphic3d_Vertex Prp ;
-  Graphic3d_Vector Vpn ;
-  Standard_Real Xrp,Yrp,Zrp,Xpn,Ypn,Zpn,Xat,Yat,Zat ;
+    const Graphic3d_BndBox3d& aBox = aStruct->CStructure()->BoundingBox();
+    if (!aBox.IsValid())
+    {
+      continue;
+    }
 
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  MyViewReferencePoint.Coord(Xat,Yat,Zat) ;
-  Prp = MyViewMapping.ProjectionReferencePoint() ;
-  Prp.Coord(Xrp,Yrp,Zrp) ;
-  Vpn = MyViewOrientation.ViewReferencePlane() ;
-  Vpn.Coord(Xpn,Ypn,Zpn) ;
-  X = Zrp*Xpn + Xat; Y = Zrp*Ypn + Yat; Z = Zrp*Zpn + Zat;
-}
+    // skip transformation-persistent objects
+    if (!aStruct->TransformPersistence().IsNull())
+    {
+      continue;
+    }
 
-void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const {
+    // use camera projection to find gravity point
+    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),
+      gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
+      gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
+      gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
+    };
 
-  Graphic3d_Vertex PRP,VRPoint;
-  Graphic3d_Vector VRPlane;
-  Standard_Real FPD,Xprp,Yprp,Zprp;
-  Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
+    for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
+    {
+      const gp_Pnt& aBndPnt    = aPnts[aPntIt];
+      const gp_Pnt  aProjected = Camera()->Project (aBndPnt);
+      if (Abs (aProjected.X()) <= 1.0
+       && Abs (aProjected.Y()) <= 1.0)
+      {
+        aResult += aBndPnt.XYZ();
+        ++aNbPoints;
+      }
+    }
+  }
+
+  if (aNbPoints == 0)
+  {
+    // fallback - just use bounding box of entire scene
+    Bnd_Box aBox = myView->MinMaxValues();
+    if (!aBox.IsVoid())
+    {
+      aBox.Get (Xmin, Ymin, Zmin,
+                Xmax, Ymax, Zmax);
+      gp_Pnt aPnts[THE_NB_BOUND_POINTS] =
+      {
+        gp_Pnt (Xmin, Ymin, Zmin), gp_Pnt (Xmin, Ymin, Zmax),
+        gp_Pnt (Xmin, Ymax, Zmin), gp_Pnt (Xmin, Ymax, Zmax),
+        gp_Pnt (Xmax, Ymin, Zmin), gp_Pnt (Xmax, Ymin, Zmax),
+        gp_Pnt (Xmax, Ymax, Zmin), gp_Pnt (Xmax, Ymax, Zmax)
+      };
+
+      for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt)
+      {
+        const gp_Pnt& aBndPnt = aPnts[aPntIt];
+        aResult += aBndPnt.XYZ();
+        ++aNbPoints;
+      }
+    }
+  }
 
-  if ( MyType == V3d_PERSPECTIVE ) {
-    PRP = MyViewMapping.ProjectionReferencePoint() ;
-    FPD = MyViewMapping.FrontPlaneDistance();
-    PRP.Coord(Xprp,Yprp,Zprp);
-    VRPoint = MyViewOrientation.ViewReferencePoint();
-    VRPoint.Coord(Xvrp,Yvrp,Zvrp);
-    VRPlane = MyViewOrientation.ViewReferencePlane();
-    VRPlane.Coord(DXvrp,DYvrp,DZvrp);
-    X = (FPD + Zprp) * DXvrp + Xvrp;
-    Y = (FPD + Zprp) * DYvrp + Yvrp;
-    Z = (FPD + Zprp) * DZvrp + Zvrp;
+  if (aNbPoints > 0)
+  {
+    aResult /= aNbPoints;
   }
-  else Eye(X,Y,Z);
+  theX = aResult.X();
+  theY = aResult.Y();
+  theZ = aResult.Z();
 }
 
-void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, const Standard_Integer Ypix, Standard_Real& XP, Standard_Real& YP, Standard_Real& ZP, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ) const {
-
+//=======================================================================
+//function : Eye
+//purpose  :
+//=======================================================================
+void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
+{
+  gp_Pnt aCameraEye = Camera()->Eye();
+  X = aCameraEye.X();
+  Y = aCameraEye.Y();
+  Z = aCameraEye.Z();
+}
+
+//=============================================================================
+//function : ProjReferenceAxe
+//purpose  :
+//=============================================================================
+void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix,
+                                const Standard_Integer Ypix,
+                                Standard_Real& XP,
+                                Standard_Real& YP,
+                                Standard_Real& ZP,
+                                Standard_Real& VX,
+                                Standard_Real& VY,
+                                Standard_Real& VZ) const
+{
   Standard_Real Xo,Yo,Zo;
 
-  Convert(Xpix,Ypix,XP,YP,ZP);
-  if ( MyType == V3d_PERSPECTIVE ) {
-    FocalReferencePoint(Xo,Yo,Zo);
+  Convert (Xpix, Ypix, XP, YP, ZP);
+  if ( Type() == V3d_PERSPECTIVE ) 
+  {
+    FocalReferencePoint (Xo,Yo,Zo);
     VX = Xo - XP;
     VY = Yo - YP;
     VZ = Zo - ZP;
   }
-  else {
-    Proj(VX,VY,VZ);
+  else 
+  {
+    Proj (VX,VY,VZ);
   }
 }
 
-
-Standard_Real V3d_View::Depth() const {
-  Graphic3d_Vertex Prp ;
-  Standard_Real Xrp,Yrp,Zrp ;
-
-  Prp = MyViewMapping.ProjectionReferencePoint() ;
-  Prp.Coord(Xrp,Yrp,Zrp) ;
-  return Zrp ;
+//=============================================================================
+//function : Depth
+//purpose  :
+//=============================================================================
+Standard_Real V3d_View::Depth() const
+{
+  return Camera()->Distance();
 }
 
-void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const {
-  Graphic3d_Vector Vpn ;
-
-  Vpn = MyViewOrientation.ViewReferencePlane() ;
-  Vpn.Coord(Dx,Dy,Dz) ;
+//=============================================================================
+//function : Proj
+//purpose  :
+//=============================================================================
+void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const
+{
+  gp_Dir aCameraDir = Camera()->Direction().Reversed();
+  Dx = aCameraDir.X();
+  Dy = aCameraDir.Y();
+  Dz = aCameraDir.Z();
 }
 
-void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
-  Graphic3d_Vertex Vrp ;
-
-  Vrp = MyViewOrientation.ViewReferencePoint() ;
-  Vrp.Coord(X,Y,Z) ;
+//=============================================================================
+//function : At
+//purpose  :
+//=============================================================================
+void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const
+{
+  gp_Pnt aCameraCenter = Camera()->Center();
+  X = aCameraCenter.X();
+  Y = aCameraCenter.Y();
+  Z = aCameraCenter.Z();
 }
 
-void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const {
-  Graphic3d_Vector Vup ;
-
-  Vup = MyViewOrientation.ViewReferenceUp() ;
-  Vup.Coord(Vx,Vy,Vz) ;
+//=============================================================================
+//function : Up
+//purpose  :
+//=============================================================================
+void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const
+{
+  gp_Dir aCameraUp = Camera()->Up();
+  Vx = aCameraUp.X();
+  Vy = aCameraUp.Y();
+  Vz = aCameraUp.Z();
 }
 
-Standard_Real V3d_View::Twist()const  {
-  Standard_Real Xup,Yup,Zup,Xpn,Ypn,Zpn,X0,Y0,Z0 ;
-  Standard_Real pvx,pvy,pvz,pvn,sca,angle ;
-  Graphic3d_Vector Vpn,Vup,Xaxis,Yaxis,Zaxis ;
-  Standard_Boolean TheStatus ;
-
-  Vpn = MyViewOrientation.ViewReferencePlane() ;
-  Vpn.Coord(Xpn,Ypn,Zpn) ;
-  Vup.SetCoord(0.,0.,1.) ;
-  TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
-  if( !TheStatus ) {
-    Vup.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
-  }
-  if( !TheStatus ) {
-    Vup.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
-  }
-  Yaxis.Coord(X0,Y0,Z0) ;
-  Vup = MyViewOrientation.ViewReferenceUp() ;
-  Vup.Coord(Xup,Yup,Zup) ;
-  /* Compute Cross Vector From Up & Origin */
-  pvx = Y0*Zup - Z0*Yup ;
-  pvy = Z0*Xup - X0*Zup ;
-  pvz = X0*Yup - Y0*Xup ;
-  pvn = pvx*pvx + pvy*pvy + pvz*pvz ;
-  sca = X0*Xup + Y0*Yup + Z0*Zup ;
-  /* Compute Angle */
-  angle = Sqrt(pvn) ;
-  if( angle > 1. ) angle = 1. ;
-  else if( angle < -1. ) angle = -1. ;
-  angle = asin(angle) ;
-  if( sca < 0. ) angle = M_PI - angle ;
-  if( angle > 0. && angle < M_PI ) {
-    sca = pvx*Xpn + pvy*Ypn + pvz*Zpn ;
-    if( sca < 0. ) angle = DEUXPI - angle ;
+//=============================================================================
+//function : Twist
+//purpose  :
+//=============================================================================
+Standard_Real V3d_View::Twist() const
+{
+  gp_Vec Xaxis, Yaxis, Zaxis;
+  const gp_Dir aReferencePlane (Camera()->Direction().Reversed());
+  if (!screenAxis (aReferencePlane, gp::DZ(), Xaxis, Yaxis, Zaxis)
+   && !screenAxis (aReferencePlane, gp::DY(), Xaxis, Yaxis, Zaxis)
+   && !screenAxis (aReferencePlane, gp::DX(), Xaxis, Yaxis, Zaxis))
+  {
+    //
   }
-  return angle ;
-}
-
-V3d_TypeOfShadingModel V3d_View::ShadingModel()const  {
-  V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
-  return SM ;
-}
-
-V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail()const  {
-  V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
-  return SM ;
-}
-
-
-Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const {
-  Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
-  return SM ;
-}
 
-V3d_TypeOfVisualization V3d_View::Visualization()const  {
-  V3d_TypeOfVisualization V =
-    (V3d_TypeOfVisualization)MyViewContext.Visualization() ;
-  return V ;
-}
-
-Standard_Boolean V3d_View::Antialiasing()const  {
-  Standard_Boolean A = MyViewContext.AliasingIsOn() ;
-  return A ;
-}
-
-Handle(V3d_Viewer) V3d_View::Viewer() const {
-  return MyViewer ;
-}
-
-Standard_Boolean V3d_View::IfWindow() const {
-  Standard_Boolean TheStatus = MyView->IsDefined() ;
-  return TheStatus ;
-}
-
-Handle(Aspect_Window) V3d_View::Window() const {
-  return MyWindow;
-}
-
-V3d_TypeOfView V3d_View::Type() const {
-
-  return (MyType) ;
-}
-
-void V3d_View::SetFocale( const Standard_Real focale ) {
+  // Compute Cross Vector From Up & Origin
+  const gp_Dir aCameraUp = Camera()->Up();
+  const gp_XYZ aP = Yaxis.XYZ().Crossed (aCameraUp.XYZ());
 
-  Standard_TypeMismatch_Raise_if (MyType != V3d_PERSPECTIVE,
-    "the view is not a perspective view");
-  Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
-  Graphic3d_Vertex Prp ;
-  Prp = MyViewMapping.ProjectionReferencePoint() ;
-  Prp.Coord(Xrp,Yrp,Zrp) ;
-  if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
-    ViewPlane = Zrp - focale ;
-  } else {
-    FrontPlane = MyViewMapping.FrontPlaneDistance() ;
-    ViewPlane = FrontPlane + Zrp - focale ;
+  // compute Angle
+  Standard_Real anAngle = ASin (Max (Min (aP.Modulus(), 1.0), -1.0));
+  if (Yaxis.Dot (aCameraUp.XYZ()) < 0.0)
+  {
+    anAngle = M_PI - anAngle;
   }
-  MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
-  MyView->SetViewMapping(MyViewMapping) ;
-
-  ImmediateUpdate();
-}
-
-Standard_Real V3d_View::Focale( ) const {
-  Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
-  Standard_Real focale = 0.0 ;
-  Graphic3d_Vertex Prp ;
-
-  if( MyType == V3d_PERSPECTIVE ) {
-    Prp = MyViewMapping.ProjectionReferencePoint() ;
-    Prp.Coord(Xrp,Yrp,Zrp) ;
-    ViewPlane = MyViewMapping.ViewPlaneDistance() ;
-    if( MyProjModel == V3d_TPM_WALKTHROUGH ) {
-      focale = Zrp - ViewPlane ;
-    } else {
-      FrontPlane = MyViewMapping.FrontPlaneDistance() ;
-      focale = FrontPlane + Zrp - ViewPlane ;
+  if (anAngle > 0.0
+   && anAngle < M_PI)
+  {
+    const gp_Dir aProjDir = Camera()->Direction().Reversed();
+    if (aP.Dot (aProjDir.XYZ()) < 0.0)
+    {
+      anAngle = DEUXPI - anAngle;
     }
   }
-  return (focale) ;
+  return anAngle;
 }
 
-void V3d_View::SetViewingVolume(const Standard_Real Left, const Standard_Real Right,
-                                const Standard_Real Bottom, const Standard_Real Top,
-                                const Standard_Real ZNear, const Standard_Real ZFar)
+//=============================================================================
+//function : ShadingModel
+//purpose  :
+//=============================================================================
+Graphic3d_TypeOfShadingModel V3d_View::ShadingModel() const
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
-
-  Viewer_BadValue_Raise_if ( ZNear <= 0. || ZFar <= 0. || ZNear >= ZFar, "V3d_View::SetVolume, bad distances");
-
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  Zrp = ZNear;
-
-  Standard_Real size = (ZFar - ZNear) / 2.;
-
-  MyViewMapping.SetFrontPlaneDistance(size);
-  MyViewMapping.SetBackPlaneDistance(-size);
-
-  // keep view plane at front plane distance
-  MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : size);
-
-  // set window limits
-  Umin = Left; Umax = Right;
-  Vmin = Bottom; Vmax = Top;
-  MyViewMapping.SetWindowLimit(Left, Bottom, Right, Top);
-
-  // Update window center
-  if ( MyType == V3d_PERSPECTIVE ) {
-    Xrp = Yrp = 0.0;
-  }
-  else {
-    Xrp = (Umin + Umax)/2. ; Yrp = (Vmin + Vmax)/2. ;
-  }
-  MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-  MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
-
-  MyView->SetViewMapping(MyViewMapping) ;
-  //  SetZSize(0.);
-  ImmediateUpdate();
+  return myView->ShadingModel();
 }
 
-Handle(Visual3d_View) V3d_View::View() const
+//=============================================================================
+//function : TextureEnv
+//purpose  :
+//=============================================================================
+Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
 {
-  return MyView ;
+  return myView->TextureEnv();
 }
 
-Visual3d_ViewMapping V3d_View::ViewMapping() const
+//=============================================================================
+//function : Visualization
+//purpose  :
+//=============================================================================
+V3d_TypeOfVisualization V3d_View::Visualization() const
 {
-  return MyViewMapping;
+  return static_cast<V3d_TypeOfVisualization> (myView->VisualizationType());
 }
 
-Visual3d_ViewOrientation V3d_View::ViewOrientation() const
+//=============================================================================
+//function : IfWindow
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::IfWindow() const
 {
-  return MyViewOrientation;
+  return myView->IsDefined();
 }
 
-Standard_Boolean V3d_View::ScreenAxis( const Graphic3d_Vector &Vpn, const Graphic3d_Vector &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe) {
-  Standard_Real Xpn,Ypn,Zpn,Xup,Yup,Zup ;
-  Standard_Real dx1,dy1,dz1,dx2,dy2,dz2,xx,yy,zz ;
-
-  Vpn.Coord(Xpn,Ypn,Zpn) ;
-  Vup.Coord(Xup,Yup,Zup) ;
-  xx = Yup*Zpn - Zup*Ypn ;
-  yy = Zup*Xpn - Xup*Zpn ;
-  zz = Xup*Ypn - Yup*Xpn ;
-  Xaxe.SetCoord(xx,yy,zz) ;
-  if( Xaxe.LengthZero() ) return Standard_False;
-  Xaxe.Normalize() ; Xaxe.Coord(dx1,dy1,dz1) ;
-  xx = Ypn*dz1 - Zpn*dy1 ;
-  yy = Zpn*dx1 - Xpn*dz1 ;
-  zz = Xpn*dy1 - Ypn*dx1 ;
-  Yaxe.SetCoord(xx,yy,zz) ;
-  if( Yaxe.LengthZero() ) return Standard_False;
-  Yaxe.Normalize() ; Yaxe.Coord(dx2,dy2,dz2) ;
-  xx = dy1*dz2 - dz1*dy2 ;
-  yy = dz1*dx2 - dx1*dz2 ;
-  zz = dx1*dy2 - dy1*dx2 ;
-  Zaxe.SetCoord(xx,yy,zz) ;
-  if( Zaxe.LengthZero() ) return Standard_False;
-  Zaxe.Normalize() ;
-  return Standard_True ;
+//=============================================================================
+//function : Type
+//purpose  :
+//=============================================================================
+V3d_TypeOfView V3d_View::Type() const
+{
+  return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
 }
 
-void V3d_View::InitMatrix( TColStd_Array2OfReal& Matrix ) {
-  Standard_Integer LR = Matrix.LowerRow() ;
-  Standard_Integer UR = Matrix.UpperRow() ;
-  Standard_Integer LC = Matrix.LowerCol() ;
-  Standard_Integer UC = Matrix.UpperCol() ;
-  Standard_Integer I,J ;
+//=============================================================================
+//function : SetFocale
+//purpose  :
+//=============================================================================
+void V3d_View::SetFocale( const Standard_Real focale )
+{
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  for( I=LR ; I<=UR ; I++ ) {
-    for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
+  if (aCamera->IsOrthographic())
+  {
+    return;
   }
-  for( I=LR,J=LC ; I<=UR ; I++,J++ ) Matrix(I,J) = 1. ;
-}
 
-Standard_Boolean V3d_View::Multiply (const TColStd_Array2OfReal& Left, const TColStd_Array2OfReal& Right, TColStd_Array2OfReal& Matrix) {
+  Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0));
 
-  Standard_Integer llr = Left.LowerRow ();
-  Standard_Integer llc = Left.LowerCol ();
-  Standard_Integer luc = Left.UpperCol ();
+  aCamera->SetFOVy (aFOVyRad * (360 / M_PI));
 
-  Standard_Integer rlr = Right.LowerRow ();
-  Standard_Integer rur = Right.UpperRow ();
-  Standard_Integer rlc = Right.LowerCol ();
+  ImmediateUpdate();
+}
 
-  Standard_Integer mlr = Matrix.LowerRow ();
-  Standard_Integer mur = Matrix.UpperRow ();
-  Standard_Integer mlc = Matrix.LowerCol ();
-  Standard_Integer muc = Matrix.UpperCol ();
+//=============================================================================
+//function : Focale
+//purpose  :
+//=============================================================================
+Standard_Real V3d_View::Focale() const
+{
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-  TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
+  if (aCamera->IsOrthographic())
+  {
+    return 0.0;
+  }
 
-  InitMatrix (Result);
+  return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0);
+}
 
-  // Left et Right incompatibles
-  if (luc - llc + 1 != rur - rlr + 1)
+//=============================================================================
+//function : screenAxis
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::screenAxis (const gp_Dir& theVpn, const gp_Dir& theVup,
+                                       gp_Vec& theXaxe, gp_Vec& theYaxe, gp_Vec& theZaxe)
+{
+  theXaxe = theVup.XYZ().Crossed (theVpn.XYZ());
+  if (theXaxe.Magnitude() <= gp::Resolution())
+  {
     return Standard_False;
-
-  Standard_Integer i, j, k;
-
-  Standard_Real Som;
-  Standard_Integer I1 = llr;
-
-  for (i=mlr; i<=mur; i++) {
-    Standard_Integer J2 = rlc;
-    for (j=mlc; j<=muc; j++) {
-      Som = 0.0;
-      Standard_Integer J1 = llc;
-      Standard_Integer I2 = rlr;
-      for (k=llc; k<=luc; k++) {
-        Som = Som + Left (I1, J1) * Right (I2, J2);
-        J1++;
-        I2++;
-      }
-      Result (i, j) = Som;
-      J2++;
-    }
-    I1++;
   }
+  theXaxe.Normalize();
 
-  for (i=mlr; i<=mur; i++)
-    for (j=mlc; j<=muc; j++)
-      Matrix (i, j) = Result (i, j);
+  theYaxe = theVpn.XYZ().Crossed (theXaxe.XYZ());
+  if (theYaxe.Magnitude() <= gp::Resolution())
+  {
+    return Standard_False;
+  }
+  theYaxe.Normalize();
 
+  theZaxe = theVpn.XYZ();
+  theZaxe.Normalize();
   return Standard_True;
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::RotAxis( const Graphic3d_Vertex &Vrp, const Graphic3d_Vector &Axe, const Standard_Real angle, TColStd_Array2OfReal& Matrix ) {
-  Standard_Real Xrp,Yrp,Zrp,Xaxe,Yaxe,Zaxe ;
-  Standard_Real sina,cosa,cos1m,terms1,terms2,terms3 ;
-  Standard_Real termc12,termc13,termc23,vcal ;
-  TColStd_Array2OfReal Tmatrix(0,3,0,3) ;
-  TColStd_Array2OfReal Rmatrix(0,3,0,3) ;
-
-  InitMatrix(Matrix) ;
-  InitMatrix(Tmatrix) ;
-
-  Vrp.Coord(Xrp,Yrp,Zrp) ;
-  Axe.Coord(Xaxe,Yaxe,Zaxe) ;
-  /* translation of x,y,z */
-  Tmatrix(0,3) = Xrp ; Tmatrix(1,3) = Yrp ; Tmatrix(2,3) = Zrp ;
-  /* rotation around an axis */
-  cosa = cos(angle); sina = sin(angle); cos1m = 1. - cosa ;
-  termc12 = Xaxe * Yaxe * cos1m ;
-  termc13 = Xaxe * Zaxe * cos1m ;
-  termc23 = Yaxe * Zaxe * cos1m ;
-  terms1 =  Xaxe * sina ;
-  terms2 =  Yaxe * sina ;
-  terms3 =  Zaxe * sina ;
-
-  vcal =  Xaxe * Xaxe ;
-  Rmatrix(0,0) = vcal + ( 1. - vcal ) * cosa ;
-  Rmatrix(1,0) = termc12 + terms3 ;
-  Rmatrix(2,0) = termc13 - terms2 ;
-  Rmatrix(3,0) = 0. ;
-  Rmatrix(0,1) = termc12 - terms3 ;
-  vcal =  Yaxe * Yaxe ;
-  Rmatrix(1,1) = vcal + ( 1. - vcal ) * cosa ;
-  Rmatrix(2,1) = termc23 + terms1 ;
-  Rmatrix(3,1) = 0. ;
-  Rmatrix(0,2) = termc13 + terms2 ;
-  Rmatrix(1,2) = termc23 - terms1 ;
-  vcal =  Zaxe * Zaxe ;
-  Rmatrix(2,2) = vcal + ( 1. - vcal ) * cosa ;
-  Rmatrix(3,2) = 0. ;
-  Rmatrix(0,3) = 0. ;
-  Rmatrix(1,3) = 0. ;
-  Rmatrix(2,3) = 0. ;
-  Rmatrix(3,3) = 1. ;
-  /* produced by two matrices */
-  Multiply(Tmatrix, Rmatrix, Matrix);
-  /* translation invert */
-  Tmatrix(0,3) = -Xrp;
-  Tmatrix(1,3) = -Yrp;
-  Tmatrix(2,3) = -Zrp;
-  /* product final */
-  Multiply(Matrix, Tmatrix, Matrix);
-}
-
-/*----------------------------------------------------------------------*/
-
-Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix ) {
-  Graphic3d_Vertex PP ;
-  Standard_Real X,Y,Z,XX,YY,ZZ ;
-
+//=============================================================================
+//function : TrsPoint
+//purpose  :
+//=============================================================================
+gp_XYZ V3d_View::TrsPoint (const Graphic3d_Vertex& thePnt, const TColStd_Array2OfReal& theMat)
+{
   // CAL. S3892
-  Standard_Integer lr, ur, lc, uc;
-  lr    = Matrix.LowerRow ();
-  ur    = Matrix.UpperRow ();
-  lc    = Matrix.LowerCol ();
-  uc    = Matrix.UpperCol ();
-  if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
-    P.Coord(X,Y,Z) ;
-    PP.SetCoord(X,Y,Z) ;
-    return PP ;
+  const Standard_Integer lr = theMat.LowerRow();
+  const Standard_Integer ur = theMat.UpperRow();
+  const Standard_Integer lc = theMat.LowerCol();
+  const Standard_Integer uc = theMat.UpperCol();
+  if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4))
+  {
+    return gp_XYZ (thePnt.X(), thePnt.Y(), thePnt.Z());
   }
-  P.Coord(X,Y,Z) ;
-  XX = (Matrix(lr,lc+3) + X*Matrix(lr,lc) + Y*Matrix(lr,lc+1)+
-    Z*Matrix(lr,lc+2))/Matrix(lr+3,lc+3) ;
 
-  YY = (Matrix(lr+1,lc+3) + X*Matrix(lr+1,lc) + Y*Matrix(lr+1,lc+1) +
-    Z*Matrix(lr+1,lc+2))/Matrix(lr+3,lc+3) ;
+  Standard_Real X, Y, Z;
+  thePnt.Coord (X,Y,Z);
+  const Standard_Real XX = (theMat(lr,lc+3)   + X*theMat(lr,lc)   + Y*theMat(lr,lc+1)   + Z*theMat(lr,lc+2)) / theMat(lr+3,lc+3);
+  const Standard_Real YY = (theMat(lr+1,lc+3) + X*theMat(lr+1,lc) + Y*theMat(lr+1,lc+1) + Z*theMat(lr+1,lc+2))/theMat(lr+3,lc+3);
+  const Standard_Real ZZ = (theMat(lr+2,lc+3) + X*theMat(lr+2,lc) + Y*theMat(lr+2,lc+1) + Z*theMat(lr+2,lc+2))/theMat(lr+3,lc+3);
+  return gp_XYZ (XX, YY, ZZ);
+}
 
-  ZZ = (Matrix(lr+2,lc+3) + X*Matrix(lr+2,lc) + Y*Matrix(lr+2,lc+1) +
-    Z*Matrix(lr+2,lc+2))/Matrix(lr+3,lc+3) ;
-  PP.SetCoord(XX,YY,ZZ) ;
-  return PP ;
+//=======================================================================
+//function : Pan
+//purpose  :
+//=======================================================================
+void V3d_View::Pan (const Standard_Integer theDXp,
+                    const Standard_Integer theDYp,
+                    const Standard_Real    theZoomFactor,
+                    const Standard_Boolean theToStart)
+{
+  Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
 }
 
-Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix ) {
-  Graphic3d_Vector VV ;
-  Standard_Real X,Y,Z,XX,YY,ZZ ;
+//=======================================================================
+//function : Panning
+//purpose  :
+//=======================================================================
+void V3d_View::Panning (const Standard_Real theDXv,
+                        const Standard_Real theDYv,
+                        const Standard_Real theZoomFactor,
+                        const Standard_Boolean theToStart)
+{
+  Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
 
-  // CAL. S3892
-  Standard_Integer lr, ur, lc, uc;
-  lr    = Matrix.LowerRow ();
-  ur    = Matrix.UpperRow ();
-  lc    = Matrix.LowerCol ();
-  uc    = Matrix.UpperCol ();
-  if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
-    V.Coord(X,Y,Z) ;
-    VV.SetCoord(X,Y,Z) ;
-    return VV ;
-  }
-  V.Coord(X,Y,Z) ;
-  XX = X*Matrix(lr,lc)+Y*Matrix(lr,lc+1)+Z*Matrix(lr,lc+2) ;
-  YY = X*Matrix(lr+1,lc)+Y*Matrix(lr+1,lc+1)+Z*Matrix(lr+1,lc+2) ;
-  ZZ = X*Matrix(lr+2,lc)+Y*Matrix(lr+2,lc+1)+Z*Matrix(lr+2,lc+2) ;
-  VV.SetCoord(XX,YY,ZZ) ; VV.Normalize() ;
-  return VV ;
-}
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
+  if (theToStart)
+  {
+    myCamStartOpEye    = aCamera->Eye();
+    myCamStartOpCenter = aCamera->Center();
+  }
 
-void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor) {
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-  Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
+  gp_Pnt aViewDims = aCamera->ViewDimensions();
 
-}
+  aCamera->SetEye (myCamStartOpEye);
+  aCamera->SetCenter (myCamStartOpCenter);
+  Translate (aCamera, -theDXv, -theDYv);
+  Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
 
-void V3d_View::Zoom (const Standard_Integer X1,
-                     const Standard_Integer Y1,
-                     const Standard_Integer X2,
-                     const Standard_Integer Y2)
-{
+  SetImmediateUpdate (wasUpdateEnabled);
 
-  Standard_Real dx = Standard_Real (X2-X1);
-  Standard_Real dy = Standard_Real (Y2-Y1);
-  if ( dx != 0. || dy != 0. ) {
-    Standard_Real dzoom = Sqrt(dx*dx + dy*dy) / 100. + 1;
-    dzoom = (dx > 0) ?  dzoom : 1./dzoom;
-    SetZoom(dzoom, Standard_True);
-  }
+  ImmediateUpdate();
 }
 
-void V3d_View::Zoom (const Standard_Integer X1,
-                     const Standard_Integer Y1)
+//=======================================================================
+//function : Zoom
+//purpose  :
+//=======================================================================
+void V3d_View::Zoom (const Standard_Integer theXp1,
+                     const Standard_Integer theYp1,
+                     const Standard_Integer theXp2,
+                     const Standard_Integer theYp2)
 {
-  Standard_Real x,y;
-  Center(x,y);
-  Standard_Integer ix,iy;
-  Convert(x,y,ix,iy);
-  Zoom(ix,iy,X1,Y1);
+  Standard_Integer aDx = theXp2 - theXp1;
+  Standard_Integer aDy = theYp2 - theYp1;
+  if (aDx != 0 || aDy != 0)
+  {
+    Standard_Real aCoeff = Sqrt( (Standard_Real)(aDx * aDx + aDy * aDy) ) / 100.0 + 1.0;
+    aCoeff = (aDx > 0) ? aCoeff : 1.0 / aCoeff;
+    SetZoom (aCoeff, Standard_True);
+  }
 }
 
-// Defines the point (pixel) of zooming (for the method ZoomAtPoint()).
-void V3d_View::StartZoomAtPoint(const Standard_Integer xpix, const Standard_Integer ypix)
+//=======================================================================
+//function : StartZoomAtPoint
+//purpose  :
+//=======================================================================
+void V3d_View::StartZoomAtPoint (const Standard_Integer theXp,
+                                 const Standard_Integer theYp)
 {
-    MyZoomAtPointX = xpix;
-    MyZoomAtPointY = ypix;
-}
-
-// Zooms the model at a pixel defined by the method StartZoomAtPoint().
-void V3d_View::ZoomAtPoint(const Standard_Integer mouseStartX,
-                           const Standard_Integer mouseStartY,
-                           const Standard_Integer mouseEndX,
-                           const Standard_Integer mouseEndY)
+  MyZoomAtPointX = theXp;
+  MyZoomAtPointY = theYp;
+}
+
+//=======================================================================
+//function : ZoomAtPoint
+//purpose  :
+//=======================================================================
+void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX,
+                            const Standard_Integer theMouseStartY,
+                            const Standard_Integer theMouseEndX,
+                            const Standard_Integer theMouseEndY)
 {
-    Standard_Boolean update;
-    V3d_Coordinate X0, Y0, XS, YS;
-
-    // Forbid any update.
-    update = SetImmediateUpdate(Standard_False);
-
-    // Get center point
-    Center(X0, Y0);
-
-    // Pan the point to the center of window.
-    Convert(MyZoomAtPointX, MyZoomAtPointY, XS, YS);
-    Panning(X0-XS, Y0-YS);
-
-    // Zoom
-    Standard_Real d = Standard_Real ((mouseEndX + mouseEndY) - (mouseStartX + mouseStartY));
-
-    Standard_Real dzoom = fabs(d) / 100.0 + 1.0;
-    dzoom = (d > 0) ?  dzoom : 1.0 / dzoom;
-    Viewer_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-    Standard_Real Umin,Vmin,Umax,Vmax;
-    MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
+  // zoom
+  Standard_Real aDxy = Standard_Real ((theMouseEndX + theMouseEndY) - (theMouseStartX + theMouseStartY));
+  Standard_Real aDZoom = Abs (aDxy) / 100.0 + 1.0;
+  aDZoom = (aDxy > 0.0) ?  aDZoom : 1.0 / aDZoom;
 
-    MyXwindowCenter = (Umin + Umax) / 2.0;
-    MyYwindowCenter = (Vmin + Vmax) / 2.0;
-    MyWindowWidth = Abs(Umax - Umin);
-    MyWindowHeight = Abs(Vmax - Vmin);
+  V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
 
-    // Ensure that zoom will not be too small or too big.
-    Standard_Real coef = dzoom;
-    if (MyWindowWidth < coef * Precision::Confusion())
-        coef = MyWindowWidth / Precision::Confusion();
-    else if (MyWindowWidth > coef * 1e12)
-        coef = MyWindowWidth / 1e12;
-    if (MyWindowHeight < coef * Precision::Confusion())
-        coef = MyWindowHeight / Precision::Confusion();
-    else if (MyWindowHeight > coef * 1e12)
-        coef = MyWindowHeight / 1e12;
+  Handle(Graphic3d_Camera) aCamera = Camera();
 
-    Standard_Real Dxv = MyWindowWidth / coef;
-    Standard_Real Dyv = MyWindowHeight / coef;
+  Standard_Real aViewWidth  = aCamera->ViewDimensions().X();
+  Standard_Real aViewHeight = aCamera->ViewDimensions().Y();
 
-    Umin = MyXwindowCenter - Dxv/2.0; Umax = MyXwindowCenter + Dxv/2.0;
-    Vmin = MyYwindowCenter - Dyv/2.0; Vmax = MyYwindowCenter + Dyv/2.0;
-
-    // Pan the point backwards.
-    Dxv = (XS - X0) / coef;
-    Dyv = (YS - Y0) / coef;
+  // ensure that zoom will not be too small or too big.
+  Standard_Real aCoef = aDZoom;
+  if (aViewWidth < aCoef * Precision::Confusion())
+  {
+    aCoef = aViewWidth / Precision::Confusion();
+  }
+  else if (aViewWidth > aCoef * 1e12)
+  {
+    aCoef = aViewWidth / 1e12;
+  }
+  if (aViewHeight < aCoef * Precision::Confusion())
+  {
+    aCoef = aViewHeight / Precision::Confusion();
+  }
+  else if (aViewHeight > aCoef * 1e12)
+  {
+    aCoef = aViewHeight / 1e12;
+  }
 
-    MyXwindowCenter = (Umin + Umax) / 2.0;
-    MyYwindowCenter = (Vmin + Vmax) / 2.0;
-    MyWindowWidth = Abs(Umax - Umin);
-    MyWindowHeight = Abs(Vmax - Vmin);
+  Standard_Real aZoomAtPointXv = 0.0;
+  Standard_Real aZoomAtPointYv = 0.0;
+  Convert (MyZoomAtPointX, MyZoomAtPointY, aZoomAtPointXv, aZoomAtPointYv);
 
-    Standard_Real Xrp,Yrp,Zrp;
-    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-    MyProjReferencePoint.Coord(Xrp,Yrp,Zrp);
+  Standard_Real aDxv = aZoomAtPointXv / aCoef;
+  Standard_Real aDyv = aZoomAtPointYv / aCoef;
 
-    Xrp = MyXwindowCenter - Dxv;
-    Yrp = MyYwindowCenter - Dyv;
+  aCamera->SetScale (aCamera->Scale() / aCoef);
+  Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv);
 
-    Umin = Xrp - MyWindowWidth / 2.0; Umax = Xrp + MyWindowWidth / 2.0;
-    Vmin = Yrp - MyWindowHeight / 2.0; Vmax = Yrp + MyWindowHeight / 2.0;
+  AutoZFit();
 
-    // Set new reference plane coordintes of the window.
-    MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax);
-    if (MyType != V3d_PERSPECTIVE)
-    {
-        MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp);
-        MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
-    }
-    MyView->SetViewMapping(MyViewMapping);
+  SetImmediateUpdate (wasUpdateEnabled);
 
-    // Update the view.
-    SetImmediateUpdate(update);
-    ImmediateUpdate();
+  ImmediateUpdate();
 }
 
+//=============================================================================
+//function : AxialScale
+//purpose  :
+//=============================================================================
 void V3d_View::AxialScale (const Standard_Integer Dx,
                            const Standard_Integer Dy,
                            const V3d_TypeOfAxe Axis)
@@ -3065,59 +2464,46 @@ void V3d_View::AxialScale (const Standard_Integer Dx,
   }
 }
 
-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)
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
+void V3d_View::FitAll(const Standard_Real theXmin,
+                      const Standard_Real theYmin,
+                      const Standard_Real theXmax,
+                      const Standard_Real theYmax)
 {
+  Handle(Graphic3d_Camera) aCamera = Camera();
+  Standard_Real anAspect = aCamera->Aspect();
 
-  Standard_Real Umin,Umax,Vmin,Vmax,Xrp,Yrp,Zrp ;
-  Standard_Real DxvOld,DyvOld,DxvNew,DyvNew,RapOld,RapNew ;
-  Standard_Integer Xpixel,Ypixel;
-  //Standard_Integer Xleft,Yup,Xright,Ylow ;
+  Standard_Real aFitSizeU  = Abs (theXmax - theXmin);
+  Standard_Real aFitSizeV  = Abs (theYmax - theYmin);
+  Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
+  if (aFitAspect >= anAspect)
+  {
+    aFitSizeV = aFitSizeU / anAspect;
+  }
+  else
+  {
+    aFitSizeU = aFitSizeV * anAspect;
+  }
 
-  Viewer_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
-    "V3d_View::FitAll, Window Size is NULL");
+  Translate (aCamera, (theXmin + theXmax) * 0.5, (theYmin + theYmax) * 0.5);
+  Scale (aCamera, aFitSizeU, aFitSizeV);
 
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  aWindow->Size(Xpixel,Ypixel);
-  DxvOld = Xpixel; DyvOld = Ypixel;
+  AutoZFit();
 
-  if( (DxvOld == 0.) || (DyvOld == 0.) ) return ;
-  RapOld = DxvOld/DyvOld ;
-  DxvNew = Abs(Xmax - Xmin) ; DyvNew = Abs(Ymax - Ymin) ;
-  RapNew = DxvNew/DyvNew ;
-  if( RapNew >= RapOld ) {
-    DyvNew = DxvNew/RapOld ;
-  } else {
-    DxvNew = DyvNew*RapOld ;
-  }
-  Xrp = (Xmin + Xmax)/2. ; Yrp = (Ymin + Ymax)/2. ;
-  Umin = Xrp - DxvNew/2. ; Vmin = Yrp - DyvNew/2. ;
-  Umax = Xrp + DxvNew/2. ; Vmax = Yrp + DyvNew/2. ;
-  MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;
-  if( MyType != V3d_PERSPECTIVE ) {
-    MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-    MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
-  }
-  MyView->SetViewMapping(MyViewMapping) ;
-#ifdef IMP020300
-  Update();
-#else
   ImmediateUpdate();
-#endif
 }
 
-#ifdef IMP250900
-static Standard_Boolean zRotation = Standard_False;
-#endif
+//=============================================================================
+//function : StartRotation
+//purpose  :
+//=============================================================================
 void V3d_View::StartRotation(const Standard_Integer X,
                              const Standard_Integer Y,
-                             const Quantity_Ratio zRotationThreshold)
+                             const Standard_Real zRotationThreshold)
 {
-
   sx = X; sy = Y;
   Standard_Real x,y;
   Size(x,y);
@@ -3125,516 +2511,644 @@ 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);
-#ifdef IMP250900
-  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;
   }
-#endif
 
 }
 
+//=============================================================================
+//function : Rotation
+//purpose  :
+//=============================================================================
 void V3d_View::Rotation(const Standard_Integer X,
                         const Standard_Integer Y)
 {
-
-#ifdef IMP210600
   if( rx == 0. || ry == 0. ) {
     StartRotation(X,Y);
     return;
   }
-#endif
-#ifdef IMP250900
   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 {
     dx = (Standard_Real(X) - sx) * M_PI / rx;
     dy = (sy - Standard_Real(Y)) * M_PI / ry;
   }
-  Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
-#else
-  Standard_Real dx = (Standard_Real(X - sx)) * M_PI;
-  Standard_Real dy = (Standard_Real(sy - Y)) * M_PI;
-  Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
-#endif
-#ifdef IMP020300
-  if( !myImmediateUpdate ) Update();
-#else
-  myImmediateUpdate = Standard_False;
-  Rotate(dx/rx, dy/ry, 0., gx, gy, gz, Standard_False);
-  ZFitAll (Zmargin);    //Don't do that, perf improvment
-  myImmediateUpdate = Standard_True;
-  ImmediateUpdate();
-#endif
-}
-
-void V3d_View::SetAnimationModeOn () {
-#ifdef G003
-  if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
-    if( ComputedMode() ) {  // Deactivates computed mode during animation
-      MyAnimationFlags |= V3d_FLAG_COMPUTATION;
-      Standard_Boolean immediatUpdate = myImmediateUpdate;
-      myImmediateUpdate = Standard_False;
-      SetComputedMode(Standard_False);
-      myImmediateUpdate = immediatUpdate;
-    }
-    MyView -> SetAnimationModeOn ( MyAnimationFlags & V3d_FLAG_DEGENERATION );
-  }
-#else
-  MyView->SetAnimationModeOn();
-#endif
-}
-
-void V3d_View::SetAnimationModeOff () {
-#ifdef G003
-  if ( MyAnimationFlags & V3d_FLAG_ANIMATION ) {
-    MyView -> SetAnimationModeOff ();
-    if ( MyAnimationFlags & V3d_FLAG_COMPUTATION ) {
-      // Reactivates computed mode after animation
-      MyAnimationFlags &= ~V3d_FLAG_COMPUTATION;
-      SetComputedMode(Standard_True);
-    } else if( MyAnimationFlags & V3d_FLAG_DEGENERATION ) {
-      Update();
-    }
-  }
-#else
-  MyView->SetAnimationModeOff();
-#endif
-}
 
-Standard_Boolean V3d_View::AnimationModeIsOn () const {
-  return MyView->AnimationModeIsOn();
+  Rotate(dx, dy, dz, gx, gy, gz, Standard_False);
 }
 
-#ifdef G003
-void V3d_View :: SetAnimationMode
-(
- const Standard_Boolean anAnimationFlag,
- const Standard_Boolean aDegenerationFlag
- )
+//=============================================================================
+//function : SetComputedMode
+//purpose  :
+//=============================================================================
+void V3d_View::SetComputedMode (const Standard_Boolean theMode)
 {
-
-  if ( anAnimationFlag )
-    MyAnimationFlags |= V3d_FLAG_ANIMATION;
-  else
-    MyAnimationFlags &= ~V3d_FLAG_ANIMATION;
-
-  if ( aDegenerationFlag )
-    MyAnimationFlags |= V3d_FLAG_DEGENERATION;
+  if (theMode)
+  {
+    if (myComputedMode)
+    {
+      myView->SetComputedMode (Standard_True);
+    }
+  }
   else
-    MyAnimationFlags &= ~V3d_FLAG_DEGENERATION;
-
-}  // end V3d_View :: SetAnimationMode
+  {
+    myView->SetComputedMode (Standard_False);
+  }
+}
 
-Standard_Boolean V3d_View::AnimationMode( Standard_Boolean& isDegenerate ) const
+//=============================================================================
+//function : ComputedMode
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::ComputedMode() const
 {
+  return myView->ComputedMode();
+}
 
-  isDegenerate = MyAnimationFlags & V3d_FLAG_DEGENERATION;
-  return MyAnimationFlags & V3d_FLAG_ANIMATION;
+//=============================================================================
+//function : SetBackFacingModel
+//purpose  :
+//=============================================================================
+void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel theModel)
+{
+  myView->SetBackfacingModel (static_cast<Graphic3d_TypeOfBackfacingModel> (theModel));
+  Redraw();
 }
-#endif
 
-void V3d_View::SetDegenerateModeOn() {
-#ifdef G003
-  SetComputedMode(Standard_False);
-#else
-  MyView->SetDegenerateModeOn();
-  ImmediateUpdate();
-#endif
+//=============================================================================
+//function : BackFacingModel
+//purpose  :
+//=============================================================================
+V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
+{
+  return static_cast<V3d_TypeOfBackfacingModel> (myView->BackfacingModel());
 }
 
-void V3d_View::SetDegenerateModeOff()
+//=============================================================================
+//function : Init
+//purpose  :
+//=============================================================================
+void V3d_View::Init()
 {
-#ifdef G003
-  SetComputedMode(Standard_True);
-#else
-  if(myComputedMode) {
-    MyView->SetDegenerateModeOff();
-    ImmediateUpdate();
+  myComputedMode = MyViewer->ComputedMode();
+  if (!myComputedMode || !MyViewer->DefaultComputedMode())
+  {
+    SetComputedMode (Standard_False);
   }
-#endif
 }
 
-Standard_Boolean V3d_View::DegenerateModeIsOn() const
+//=============================================================================
+//function : Dump
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::Dump (const Standard_CString      theFile,
+                                 const Graphic3d_BufferType& theBufferType)
 {
-#ifdef G003
-  return !ComputedMode();
-#else
-  return MyView->DegenerateModeIsOn();
-#endif
+  Standard_Integer aWinWidth, aWinHeight;
+  MyWindow->Size (aWinWidth, aWinHeight);
+  Image_AlienPixMap anImage;
+
+  return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
 }
 
-#ifdef G003
-void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
+//=============================================================================
+//function : ToPixMap
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
+                                     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()))
+    {
+      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( aMode ) {
-    if( myComputedMode ) {
-      MyView -> SetComputedMode ( Standard_True );
-      Update ();
+      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;
+      }
     }
-  } else {
-    MyView -> SetComputedMode ( Standard_False );
-    Update ();
   }
+  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();
 
-}  // end V3d_View :: SetComputedMode
-
-Standard_Boolean V3d_View :: ComputedMode () const
-{
-
-  return MyView -> ComputedMode ();
+  Handle(Standard_Transient) aFBOPtr;
+  Handle(Standard_Transient) aPrevFBOPtr = myView->FBO();
+  Graphic3d_Vec2i aFBOVPSize = aTargetSize;
 
-}  // end V3d_View :: ComputedMode
+  bool isTiling = false;
+  if (theParams.TileSize > 0)
+  {
+    if (aFBOVPSize.x() > theParams.TileSize
+     || aFBOVPSize.y() > theParams.TileSize)
+    {
+      aFBOVPSize.x() = Min (aFBOVPSize.x(), theParams.TileSize);
+      aFBOVPSize.y() = Min (aFBOVPSize.y(), theParams.TileSize);
+      isTiling = true;
+    }
+  }
 
-void V3d_View :: SetBackFacingModel (
-                                     const V3d_TypeOfBackfacingModel aModel)
-{
+  Graphic3d_Vec2i aPrevFBOVPSize;
+  if (!aPrevFBOPtr.IsNull())
+  {
+    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;
+    }
+  }
 
-  MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
-  Redraw();
-}  // end V3d_View :: SetBackFacingModel
+  if (aFBOPtr.IsNull())
+  {
+    Standard_Integer aMaxTexSizeX = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeX);
+    Standard_Integer aMaxTexSizeY = MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_MaxViewDumpSizeY);
+    if (theParams.TileSize > aMaxTexSizeX
+     || theParams.TileSize > aMaxTexSizeY)
+    {
+      Message::DefaultMessenger()->Send (TCollection_AsciiString ("Image dump can not be performed - specified tile size (")
+                                                                 + theParams.TileSize + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")", Message_Fail);
+      return Standard_False;
+    }
 
-V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const {
+    if (aFBOVPSize.x() > aMaxTexSizeX
+     || aFBOVPSize.y() > aMaxTexSizeY)
+    {
+      if (MyViewer->Driver()->InquireLimit (Graphic3d_TypeOfLimit_IsWorkaroundFBO))
+      {
+        Message::DefaultMessenger ()->Send (TCollection_AsciiString ("Warning, workaround for Intel driver problem with empty FBO for images with big width is applyed."), Message_Warning);
+      }
+      Message::DefaultMessenger()->Send (TCollection_AsciiString ("Info, tiling image dump is used, image size (")
+                                                                 + aFBOVPSize.x() + "x" + aFBOVPSize.y() + ") exceeds hardware limits (" + aMaxTexSizeX + "x" + aMaxTexSizeY + ")", Message_Info);
+      aFBOVPSize.x() = Min (aFBOVPSize.x(), aMaxTexSizeX);
+      aFBOVPSize.y() = Min (aFBOVPSize.y(), aMaxTexSizeY);
+      isTiling = true;
+    }
 
-  return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
+    // Try to create hardware accelerated buffer
+    aFBOPtr = myView->FBOCreate (aFBOVPSize.x(), aFBOVPSize.y());
+  }
+  myView->SetFBO (aFBOPtr);
 
-}  // end V3d_View :: BackFacingModel
-#endif
+  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;
 
-Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const {
-  return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
-}
+    Message::DefaultMessenger()->Send (TCollection_AsciiString ("Warning, on screen buffer is used for image dump - content might be invalid"), Message_Warning);
+  }
 
-void V3d_View::TransientManagerClearDraw() const {
-  Visual3d_TransientManager::ClearDraw(MyView);
-}
+  // backup camera parameters
+  Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
+  Handle(Graphic3d_Camera) aCamera = Camera();
+  aStoreMapping->Copy (aCamera);
+  if (aCamera->IsStereo())
+  {
+    switch (theParams.StereoOptions)
+    {
+      case V3d_SDO_MONO:
+      {
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+        break;
+      }
+      case V3d_SDO_LEFT_EYE:
+      {
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
+        break;
+      }
+      case V3d_SDO_RIGHT_EYE:
+      {
+        aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
+        break;
+      }
+      case V3d_SDO_BLENDED:
+      {
+        break; // dump as is
+      }
+    }
+  }
+  if (theParams.ToAdjustAspect)
+  {
+    aCamera->SetAspect (Standard_Real(aTargetSize.x()) / Standard_Real(aTargetSize.y()));
+  }
+  AutoZFit();
 
-Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const {
-  return Visual3d_TransientManager::BeginAddDraw(MyView);
-}
+  // render immediate structures into back buffer rather than front
+  const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False);
 
-void V3d_View::Init() {
-  myComputedMode = MyViewer->ComputedMode();
-#ifdef G003
-  if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
-    SetComputedMode(Standard_False);
+  Standard_Boolean isSuccess = Standard_True;
+  if (!isTiling)
+  {
+    if (!aFBOPtr.IsNull())
+    {
+      myView->FBOChangeViewport (aFBOPtr, aTargetSize.x(), aTargetSize.y());
+    }
+    Redraw();
+    isSuccess = isSuccess && myView->BufferDump (theImage, theParams.BufferType);
   }
-#else
-  if(!myComputedMode)
-    MyView->SetDegenerateModeOn();
   else
-    if(!MyViewer->DefaultComputedMode()) MyView->SetDegenerateModeOn();
-#endif
+  {
+    Image_PixMap aTilePixMap;
+    aTilePixMap.SetTopDown (theImage.IsTopDown());
 
-#ifdef IMP240100
-  OSD_Environment env_walkthrow("CSF_WALKTHROUGH");
-  env_walkthrow.SetName( "CSF_WALKTHROUGH" );
-  if ( env_walkthrow.Value () != "" ) MyProjModel = V3d_TPM_WALKTHROUGH;
-  else MyProjModel = V3d_TPM_SCREEN;
-#endif
+    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 aTileUncropped;
+        aTileUncropped.Offset    = anOffset;
+        aTileUncropped.TotalSize = aTargetSize;
+        aTileUncropped.TileSize  = aFBOVPSize;
+        const Graphic3d_CameraTile aTile = aTileUncropped.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());
+
+        if (!aFBOPtr.IsNull())
+        {
+          aCamera->SetTile (aTile);
+          myView->FBOChangeViewport (aFBOPtr, aTile.TileSize.x(), aTile.TileSize.y());
+        }
+        else
+        {
+          // no API to resize viewport of on-screen buffer - render uncropped
+          aCamera->SetTile (aTileUncropped);
+        }
+        Redraw();
+        isSuccess = isSuccess && myView->BufferDump (aTilePixMap, theParams.BufferType);
+        if (!isSuccess)
+        {
+          break;
+        }
+      }
+      if (!isSuccess)
+      {
+        break;
+      }
+    }
+  }
 
-void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter) {
-  MyPlotter = aPlotter;
+  // restore state
+  myView->SetImmediateModeDrawToFront (aPrevImmediateMode);
+  aCamera->Copy (aStoreMapping);
+  if (aFBOPtr != aPrevFBOPtr)
+  {
+    myView->FBORelease (aFBOPtr);
+  }
+  else if (!aPrevFBOPtr.IsNull())
+  {
+    myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSize.x(), aPrevFBOVPSize.y());
+  }
+  myView->SetFBO (aPrevFBOPtr);
+  return isSuccess;
 }
 
-void V3d_View::Plot()
+//=============================================================================
+//function : ImmediateUpdate
+//purpose  :
+//=============================================================================
+void V3d_View::ImmediateUpdate() const
 {
-
-  Viewer_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
-
-  MyView->Plot(MyPlotter);
+  if (myImmediateUpdate)
+  {
+    Update();
+  }
 }
 
-Standard_Real V3d_View::Tumble (const Standard_Integer NbImages, const Standard_Boolean AnimationMode)
+//=============================================================================
+//function : SetImmediateUpdate
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate)
 {
-
-  FullTimer.Reset ();
-  FullTimer.Start ();
-
-  if (AnimationMode) MyView->SetAnimationModeOn();
-  Standard_Integer i;
-  Standard_Real delta = 0.01;
-  Standard_Real xangle, yangle;
-  xangle = yangle = delta*int(NbImages/3);
-
-  Rotate (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_True);
-  for (i=1; i<=int(NbImages/3); i++)
-    Rotate (delta*i, 0.0, 0.0, 0.0, 0.0, 0.0, Standard_False);
-  for (i=1; i<=int(NbImages/3); i++)
-    Rotate (xangle, delta*i, 0.0, 0.0, 0.0, 0.0, Standard_False);
-  for (i=1; i<=int(NbImages/3); i++)
-    Rotate (xangle, yangle, delta*i, 0.0, 0.0, 0.0, Standard_False);
-  if (AnimationMode) MyView->SetAnimationModeOff();
-
-  FullTimer.Stop ();
-  cout << "For " << NbImages << " Images : " << endl;
-  FullTimer.Show (cout);
-  cout << flush;
-
-  Standard_Real Seconds, CPUtime;
-  Standard_Integer Minutes, Hours;
-
-  FullTimer.Show (Seconds, Minutes, Hours, CPUtime);
-  cout << "Result " << (AnimationMode ? "with " : "without ")
-    << "display list : " << NbImages/CPUtime << " images/Second."
-    << endl;
-
-  return NbImages/CPUtime;
-
+  Standard_Boolean aPreviousMode = myImmediateUpdate;
+  myImmediateUpdate = theImmediateUpdate;
+  return aPreviousMode;
 }
 
-#define SCREENCOPY_FILENAME "screencopy3d.gif"
-void V3d_View::ScreenCopy (const Handle(PlotMgt_PlotterDriver)& aPlotterDriver,
-                           const Standard_Boolean fWhiteBackground,
-                           const Quantity_Factor aPlotScale)
+// =======================================================================
+// function : SetCamera
+// purpose  :
+// =======================================================================
+void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
 {
-  TCollection_AsciiString aFileToDump;
-  Handle(Aspect_WindowDriver) aWindowDriver =
-#ifdef WNT
-    new WNT_WDriver (Handle(WNT_Window)::DownCast(MyWindow));
-#else
-    new Xw_Driver (Handle(Xw_Window)::DownCast(MyWindow));
-#endif // WNT
-  Quantity_Factor    aScale;
-  Quantity_Length    thePixel;
-  Quantity_Parameter theWWidth, theWHeight;
-  Quantity_Parameter thePWidth, thePHeight;
-  aPlotterDriver -> WorkSpace (thePWidth, thePHeight);
-  aWindowDriver  -> WorkSpace (theWWidth, theWHeight);
-  thePixel = aWindowDriver -> Convert (1);
+  myView->SetCamera (theCamera);
 
-  if (theWWidth * theWHeight != 0.) {
-    if (aPlotScale == 0.) {
-      aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
-    } else {
-      // To be changed !!!!!!!!!!!!!!!
-      aScale = Min (thePWidth / theWWidth, thePHeight / theWHeight);
-    }
-
-    // Set default maps (color, type, etc) for plotter driver
-    aPlotterDriver -> SetColorMap ( new Aspect_GenericColorMap () );
-    aPlotterDriver -> SetTypeMap  ( new Aspect_TypeMap         () );
-    aPlotterDriver -> SetWidthMap ( new Aspect_WidthMap        () );
-    aPlotterDriver -> SetFontMap  ( new Aspect_FontMap         () );
-    aPlotterDriver -> SetMarkMap  ( new Aspect_MarkMap         () );
-
-    // Set backgroung to white, unihiglight if any
-    Quantity_Parameter theRed, theGreen, theBlue;
-    Handle(TColStd_HSequenceOfInteger) theFlags;
-    Graphic3d_MapOfStructure  theStructures;
-    BackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
-    if (fWhiteBackground)
-      SetBackgroundColor (Quantity_NOC_WHITE);
-    MyView -> DisplayedStructures (theStructures);
-    theFlags      = new TColStd_HSequenceOfInteger ();
-    Graphic3d_MapIteratorOfMapOfStructure Iterator (theStructures);
-    while (Iterator.More ()) {
-      Handle(Graphic3d_Structure) aStructure = Iterator.Key();
-      if (aStructure -> IsHighlighted()) {
-        theFlags -> Append (1);
-        aStructure -> UnHighlight ();
-      } else {
-        theFlags -> Append (0);
-      }
-      Iterator.Next ();
-    }
-    Redraw ();
-
-    // Dump the view
-    if (aPlotterDriver->IsKind(STANDARD_TYPE(PlotMgt_ImageDriver))) {
-      aFileToDump  = aPlotterDriver->PlotFileName();
-    } else {
-      aFileToDump  = aPlotterDriver->SpoolDirectory();
-      aFileToDump += SCREENCOPY_FILENAME;
-    }
-    MyWindow -> Dump (aFileToDump.ToCString());
-
-    Standard_Integer theCurStruct = 1;
-    Iterator = Graphic3d_MapIteratorOfMapOfStructure (theStructures);
-    while (Iterator.More ()) {
-      if (theFlags -> Value(theCurStruct))
-        Iterator.Key() -> Highlight (Aspect_TOHM_COLOR);
-      Iterator.Next ();
-      theCurStruct++;
-    }
-    if (fWhiteBackground)
-      SetBackgroundColor (Quantity_TOC_RGB, theRed, theGreen, theBlue);
-    Redraw ();
-
-    // Draw imagefile by plotter driver
-    aPlotterDriver -> SetPixelSize (thePixel);
-    aPlotterDriver -> BeginDraw ();
-    aPlotterDriver -> DrawImageFile (
-      aFileToDump.ToCString(), (float)(thePWidth / 2.), (float)(thePHeight / 2.), aScale);
-    aPlotterDriver -> EndDraw ();
-  }
+  ImmediateUpdate();
 }
-#undef SCREENCOPY_FILENAME
-
-#include <Aspect.hxx>
-#include <Visual3d_Layer.hxx>
 
-////////////////////////////////////////////////////////////////
-Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
-                                 const Image_TypeOfImage theBufferType)
+// =======================================================================
+// function : GetCamera
+// purpose  :
+// =======================================================================
+const Handle(Graphic3d_Camera)& V3d_View::Camera() const
 {
-  Standard_Integer aWinWidth, aWinHeight;
-  MyWindow->Size (aWinWidth, aWinHeight);
-
-  Handle(Aspect_PixMap) aPixMap = ToPixMap (aWinWidth, aWinHeight, theBufferType);
-  return !aPixMap.IsNull() && aPixMap->Dump (theFile);
-}
-
-////////////////////////////////////////////////////////////////
-Standard_Boolean V3d_View::Dump (const Standard_CString theFile,
-                                 const Aspect_FormatOfSheetPaper theFormat,
-                                 const Image_TypeOfImage theBufferType)
-{
-  Standard_Boolean isDone = Standard_False;
-  // convert Aspect_FormatOfSheetPaper size to pixel ...
-  Quantity_Length anSPWidth, anSPHeight;
-  Aspect::ValuesOfFOSP (theFormat, anSPWidth, anSPHeight);
-
-  // adjusting to the ratio width/height ...
-  Quantity_Length aWinWidth, aWinHeight;
-  MyWindow->MMSize (aWinWidth, aWinHeight);
-  Standard_Integer aPixelWidth, aPixelHeight;
-  MyWindow->Size (aPixelWidth, aPixelHeight);
-
-  Quantity_Factor aScale = Min (anSPWidth / aWinWidth, anSPHeight / aWinHeight);
-  aPixelWidth  = Standard_Integer (aPixelWidth  * aScale);
-  aPixelHeight = Standard_Integer (aPixelHeight * aScale);
-  {
-    Handle(Aspect_PixMap) aBitmap = ToPixMap (aPixelWidth, aPixelHeight, theBufferType);
-    Standard_Real aGammaValue = 1.0;
-    OSD_Environment anEnvGamma ("CSF_GAMMA_CORRECTION");
-    TCollection_AsciiString strGamma (anEnvGamma.Value());
-    if (!strGamma.IsEmpty()) aGammaValue = strGamma.RealValue();
-    isDone = !aBitmap.IsNull() && aBitmap->Dump (theFile, aGammaValue);
-  }
-  return isDone;
-}
-
-////////////////////////////////////////////////////////////////
-Handle(Image_PixMap) V3d_View::ToPixMap (const Standard_Integer  theWidth,
-                                         const Standard_Integer  theHeight,
-                                         const Image_TypeOfImage theBufferType,
-                                         const Standard_Boolean  theIsForceCentred)
-{
-  // always prefer hardware accelerated offscreen buffer
-  Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
-  Graphic3d_PtrFrameBuffer aFBOPtr = NULL;
-  Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO;
-  Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0);
-  if (aPrevFBOPtr != NULL)
-  {
-    MyView->FBOGetDimensions (aPrevFBOPtr,
-                              aPrevFBOVPSizeX, aPrevFBOVPSizeY,
-                              aPrevFBOSizeXMax, aPrevFBOSizeYMax);
-    if (theWidth <= aPrevFBOSizeXMax && theHeight <= aPrevFBOSizeYMax)
-    {
-      MyView->FBOChangeViewport (aPrevFBOPtr, theWidth, theHeight);
-      aFBOPtr = aPrevFBOPtr;
-    }
-  }
-
-  if (aFBOPtr == NULL)
+  return myView->Camera();
+}
+
+// =======================================================================
+// function : FitMinMax
+// purpose  : Internal
+// =======================================================================
+Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
+                                      const Bnd_Box& theBox,
+                                      const Standard_Real theMargin,
+                                      const Standard_Real theResolution,
+                                      const Standard_Boolean theToEnlargeIfLine) const
+{
+  // Check bounding box for validness
+  if (theBox.IsVoid())
   {
-    // Try to create hardware accelerated buffer
-    aFBOPtr = MyView->FBOCreate (theWidth, theHeight);
+    return Standard_False; // bounding box is out of bounds...
   }
-  cView->ptrFBO = aFBOPtr;
 
-  // If hardware accelerated buffer - try to use onscreen buffer
-  // Results may be bad!
-  if (aFBOPtr == NULL)
+  // Apply "axial scaling" to the bounding points.
+  // It is not the best approach to make this scaling as a part of fit all operation,
+  // but the axial scale is integrated into camera orientation matrix and the other
+  // option is to perform frustum plane adjustment algorithm in view camera space,
+  // which will lead to a number of additional world-view space conversions and
+  // loosing precision as well.
+  gp_Pnt aBndMin = theBox.CornerMin().XYZ().Multiplied (theCamera->AxialScale());
+  gp_Pnt aBndMax = theBox.CornerMax().XYZ().Multiplied (theCamera->AxialScale());
+
+  if (aBndMax.IsEqual (aBndMin, RealEpsilon()))
   {
-    // retrieve window sizes
-    Standard_Integer aWinWidth, aWinHeight;
-    MyWindow->Size (aWinWidth, aWinHeight);
+    return Standard_False; // nothing to fit all
+  }
+
+  // Prepare camera frustum planes.
+  NCollection_Array1<gp_Pln> aFrustumPlane (1, 6);
+  theCamera->Frustum (aFrustumPlane.ChangeValue (1),
+                      aFrustumPlane.ChangeValue (2),
+                      aFrustumPlane.ChangeValue (3),
+                      aFrustumPlane.ChangeValue (4),
+                      aFrustumPlane.ChangeValue (5),
+                      aFrustumPlane.ChangeValue (6));
+
+  // Prepare camera up, side, direction vectors.
+  gp_Dir aCamUp  = theCamera->OrthogonalizedUp();
+  gp_Dir aCamDir = theCamera->Direction();
+  gp_Dir aCamSide = aCamDir ^ aCamUp;
+
+  // Prepare scene bounding box parameters.
+  gp_Pnt aBndCenter = (aBndMin.XYZ() + aBndMax.XYZ()) / 2.0;
+
+  NCollection_Array1<gp_Pnt> aBndCorner (1, 8);
+  aBndCorner.ChangeValue (1) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMin.Z());
+  aBndCorner.ChangeValue (2) = gp_Pnt (aBndMin.X(), aBndMin.Y(), aBndMax.Z());
+  aBndCorner.ChangeValue (3) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMin.Z());
+  aBndCorner.ChangeValue (4) = gp_Pnt (aBndMin.X(), aBndMax.Y(), aBndMax.Z());
+  aBndCorner.ChangeValue (5) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMin.Z());
+  aBndCorner.ChangeValue (6) = gp_Pnt (aBndMax.X(), aBndMin.Y(), aBndMax.Z());
+  aBndCorner.ChangeValue (7) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMin.Z());
+  aBndCorner.ChangeValue (8) = gp_Pnt (aBndMax.X(), aBndMax.Y(), aBndMax.Z());
+
+  // Perspective-correct camera projection vector, matching the bounding box is determined geometrically.
+  // Knowing the initial shape of a frustum it is possible to match it to a bounding box.
+  // Then, knowing the relation of camera projection vector to the frustum shape it is possible to
+  // set up perspective-correct camera projection matching the bounding box.
+  // These steps support non-asymmetric transformations of view-projection space provided by camera.
+  // The zooming can be done by calculating view plane size matching the bounding box at center of
+  // the bounding box. The only limitation here is that the scale of camera should define size of
+  // its view plane passing through the camera center, and the center of camera should be on the
+  // same line with the center of bounding box.
+
+  // The following method is applied:
+  // 1) Determine normalized asymmetry of camera projection vector by frustum planes.
+  // 2) Determine new location of frustum planes, "matching" the bounding box.
+  // 3) Determine new camera projection vector using the normalized asymmetry.
+  // 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()));
+
+  // 2. Determine how far should be the frustum planes placed from center
+  //    of bounding box, in order to match the bounding box closely.
+  NCollection_Array1<Standard_Real> aFitDistance (1, 6);
+  aFitDistance.ChangeValue (1) = 0.0;
+  aFitDistance.ChangeValue (2) = 0.0;
+  aFitDistance.ChangeValue (3) = 0.0;
+  aFitDistance.ChangeValue (4) = 0.0;
+  aFitDistance.ChangeValue (5) = 0.0;
+  aFitDistance.ChangeValue (6) = 0.0;
+
+  for (Standard_Integer anI = aFrustumPlane.Lower(); anI <= aFrustumPlane.Upper(); ++anI)
+  {
+    // Measure distances from center of bounding box to its corners towards the frustum plane.
+    const gp_Dir& aPlaneN = aFrustumPlane.ChangeValue (anI).Axis().Direction();
+
+    Standard_Real& aFitDist = aFitDistance.ChangeValue (anI);
 
-    // technically we can reduce existing viewport...
-    // but currently allow only dumping the window itself
-    if (theWidth != aWinWidth || theHeight != aWinHeight)
+    for (Standard_Integer aJ = aBndCorner.Lower(); aJ <= aBndCorner.Upper(); ++aJ)
     {
-      return Handle(Image_PixMap)();
+      aFitDist = Max (aFitDist, gp_Vec (aBndCenter, aBndCorner (aJ)).Dot (aPlaneN));
     }
   }
-
-  //szv: save mapping
-  Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
-  Standard_Real Umin, Vmin, Umax, Vmax;
-
-  if (theIsForceCentred)
+  // The center of camera is placed on the same line with center of bounding box.
+  // The view plane section crosses the bounding box at its center.
+  // To compute view plane size, evaluate coefficients converting "point -> plane distance"
+  // into view section size between the point and the frustum plane.
+  //       proj
+  //       /|\   right half of frame     //
+  //        |                           //
+  //  point o<--  distance * coeff  -->//---- (view plane section)
+  //         \                        //
+  //      (distance)                 // 
+  //                ~               //
+  //                 (distance)    //
+  //                           \/\//
+  //                            \//
+  //                            //
+  //                      (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));
+
+  Standard_Real aViewSizeXv = aFitDistance (1) + aFitDistance (2);
+  Standard_Real aViewSizeYv = aFitDistance (3) + aFitDistance (4);
+  Standard_Real aViewSizeZv = aFitDistance (5) + aFitDistance (6);
+
+  // 3. Place center of camera on the same line with center of bounding
+  //    box applying corresponding projection asymmetry (if any).
+  Standard_Real anAssymXv = anAssymX * aViewSizeXv * 0.5;
+  Standard_Real anAssymYv = anAssymY * aViewSizeYv * 0.5;
+  Standard_Real anOffsetXv = (aFitDistance (2) - aFitDistance (1)) * 0.5 + anAssymXv;
+  Standard_Real anOffsetYv = (aFitDistance (4) - aFitDistance (3)) * 0.5 + anAssymYv;
+  gp_Vec aTranslateSide = gp_Vec (aCamSide) * anOffsetXv;
+  gp_Vec aTranslateUp   = gp_Vec (aCamUp)   * anOffsetYv;
+  gp_Pnt aCamNewCenter  = aBndCenter.Translated (aTranslateSide).Translated (aTranslateUp);
+
+  gp_Trsf aCenterTrsf;
+  aCenterTrsf.SetTranslation (theCamera->Center(), aCamNewCenter);
+  theCamera->Transform (aCenterTrsf);
+  theCamera->SetDistance (aFitDistance (6) + aFitDistance (5));
+
+  // Bounding box collapses to a point or thin line going in depth of the screen
+  if (aViewSizeXv < theResolution && aViewSizeYv < theResolution)
   {
-    //szv: get mapping frame
-    Standard_Real PUmin, PVmin, PUmax, PVmax;
-    prevMapping.WindowLimit (PUmin, PVmin, PUmax, PVmax);
-
-    //szv: calculate expansion
-    Umin = PUmin; Vmin = PVmin; Umax = PUmax; Vmax = PVmax;
-    Standard_Real oldWidth = (PUmax - PUmin), oldHeight = (PVmax - PVmin);
-    Standard_Real newWidth = (oldHeight * theWidth) / theHeight;
-    if (newWidth < oldWidth)
-    {
-      Standard_Real newHeight = (oldWidth * theHeight) / theWidth;
-      // Expand height
-      Standard_Real delta = 0.5 * (newHeight - oldHeight);
-      Vmin = PVmin - delta;
-      Vmax = PVmax + delta;
-    }
-    else
+    if (aViewSizeXv < theResolution || !theToEnlargeIfLine)
     {
-      // Expand width
-      Standard_Real delta = 0.5 * (newWidth - oldWidth);
-      Umin = PUmin - delta;
-      Umax = PUmax + delta;
+      return Standard_True; // This is just one point or line and zooming has no effect.
     }
 
-    //szv: apply expanded mapping
-    MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
-    MyView->SetViewMapping (MyViewMapping);
+    // Looking along line and "theToEnlargeIfLine" is requested.
+    // Fit view to see whole scene on rotation.
+    aViewSizeXv = aViewSizeZv;
+    aViewSizeYv = aViewSizeZv;
   }
 
-  //workround for rendering list of Over and Under Layers
-  if (!MyLayerMgr.IsNull())
-  {
-    MyLayerMgr->Compute();
-  }
-  Redraw();
+  Scale (theCamera, aViewSizeXv, aViewSizeYv);
 
-  //szv: restore mapping
-  MyViewMapping = prevMapping;
-  MyView->SetViewMapping (prevMapping);
+  const Standard_Real aZoomCoef = myView->ConsiderZoomPersistenceObjects();
 
-  // allocate image buffer for dumping
-  Image_CRawBufferData aRawBuffer;
-  Handle(Image_PixMap) anImageBitmap = new Image_PixMap (theWidth, theHeight, theBufferType);
-  anImageBitmap->AccessBuffer (aRawBuffer);
-  if (!MyView->BufferDump (aRawBuffer))
-  {
-    // dump is failed!
-    anImageBitmap = Handle(Image_PixMap)();
-  }
+  Scale (theCamera, theCamera->ViewDimensions().X() * (aZoomCoef + theMargin), theCamera->ViewDimensions().Y() * (aZoomCoef + theMargin));
 
-  // FBO now useless, free resources
-  if (aFBOPtr != aPrevFBOPtr)
+  return Standard_True;
+}
+
+// =======================================================================
+// function : Scale
+// purpose  : Internal
+// =======================================================================
+void V3d_View::Scale (const Handle(Graphic3d_Camera)& theCamera,
+                      const Standard_Real theSizeXv,
+                      const Standard_Real theSizeYv) const
+{
+  Standard_Real anAspect = theCamera->Aspect();
+  if (anAspect > 1.0)
   {
-    MyView->FBORelease (aFBOPtr);
+    theCamera->SetScale (Max (theSizeXv / anAspect, theSizeYv));
   }
-  else if (aPrevFBOPtr != NULL)
+  else
   {
-    MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY);
+    theCamera->SetScale (Max (theSizeXv, theSizeYv * anAspect));
   }
-  cView->ptrFBO = aPrevFBOPtr;
-  return anImageBitmap;
+}
+
+// =======================================================================
+// function : Translate
+// purpose  : Internal
+// =======================================================================
+void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera,
+                          const Standard_Real theDXv,
+                          const Standard_Real theDYv) const
+{
+  const gp_Pnt& aCenter = theCamera->Center();
+  const gp_Dir& aDir = theCamera->Direction();
+  const gp_Dir& anUp = theCamera->Up();
+  gp_Ax3 aCameraCS (aCenter, aDir.Reversed(), aDir ^ anUp);
+
+  gp_Vec aCameraPanXv = gp_Vec (aCameraCS.XDirection()) * theDXv;
+  gp_Vec aCameraPanYv = gp_Vec (aCameraCS.YDirection()) * theDYv;
+  gp_Vec aCameraPan = aCameraPanXv + aCameraPanYv;
+  gp_Trsf aPanTrsf;
+  aPanTrsf.SetTranslation (aCameraPan);
+
+  theCamera->Transform (aPanTrsf);
+}
+
+// =======================================================================
+// function : DiagnosticInformation
+// purpose  :
+// =======================================================================
+void V3d_View::DiagnosticInformation (TColStd_IndexedDataMapOfStringString& theDict,
+                                      Graphic3d_DiagnosticInfo theFlags) const
+{
+  myView->DiagnosticInformation (theDict, theFlags);
+}
+
+//=======================================================================
+//function : StatisticInformation
+//purpose  :
+//=======================================================================
+void V3d_View::StatisticInformation (TColStd_IndexedDataMapOfStringString& theDict) const
+{
+  myView->StatisticInformation (theDict);
+}
+
+// =======================================================================
+// function : StatisticInformation
+// purpose  :
+// =======================================================================
+TCollection_AsciiString V3d_View::StatisticInformation() const
+{
+  return myView->StatisticInformation();
+}
+
+//=============================================================================
+//function : RenderingParams
+//purpose  :
+//=============================================================================
+const Graphic3d_RenderingParams& V3d_View::RenderingParams() const
+{
+  return myView->RenderingParams();
+}
+
+//=============================================================================
+//function : ChangeRenderingParams
+//purpose  :
+//=============================================================================
+Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams()
+{
+  return myView->ChangeRenderingParams();
 }