0024882: Visualization - default orientation is ignored
[occt.git] / src / V3d / V3d_View.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 1703c7f..1c6af3f
@@ -1,19 +1,15 @@
-// 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.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 /***********************************************************************
 
@@ -60,7 +56,6 @@ ne marche pas. Contournement en appelant WNT_Window::Size(Int,Int).
 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.
@@ -82,32 +77,6 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 //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 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
 
@@ -142,23 +111,35 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 */
 
 #include <Standard_TypeMismatch.hxx>
+#include <Standard_ShortReal.hxx>
+#include <Standard_Assert.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_DivideByZero.hxx>
+
 #include <Visual3d_ViewManager.hxx>
 #include <Visual3d_Light.hxx>
-#include <Graphic3d_Structure.hxx>
-#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
-#include <Graphic3d_MapOfStructure.hxx>
-#include <Graphic3d_TextureEnv.hxx>
-#include <Image_AlienPixMap.hxx>
+#include <Visual3d_Layer.hxx>
+
 #include <V3d.hxx>
 #include <V3d_View.ixx>
 #include <V3d_BadValue.hxx>
-#include <Standard_ShortReal.hxx>
+#include <V3d_StereoDumpOptions.hxx>
+
+#include <Image_AlienPixMap.hxx>
+
 #include <gp_Dir.hxx>
+#include <gp_Pln.hxx>
 #include <TColStd_Array2OfReal.hxx>
-#include <Visual3d_TransientManager.hxx>
+#include <TColStd_HSequenceOfInteger.hxx>
+
+#include <Bnd_Box.hxx>
+
 #include <Precision.hxx>
 
-// S3892
+#include <Graphic3d_Structure.hxx>
+#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
+#include <Graphic3d_MapOfStructure.hxx>
+#include <Graphic3d_TextureEnv.hxx>
 #include <Graphic3d_AspectMarker3d.hxx>
 #include <Graphic3d_GraphicDriver.hxx>
 
@@ -168,7 +149,7 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 #include <Aspect_WidthMap.hxx>
 #include <Aspect_MarkMap.hxx>
 #include <Aspect_FontMap.hxx>
-#include <TColStd_HSequenceOfInteger.hxx>
+#include <Aspect.hxx>
 
 #define V3d_FLAG_COMPUTATION   0x00000004
 
@@ -180,99 +161,22 @@ To solve the problem (for lack of a better solution) I make 2 passes.
 * Constant
 */
 
-#define Zmargin 1.
 #define DEUXPI (2. * M_PI)
 
-/*----------------------------------------------------------------------*/
-/*
-* Local data definitions
-*/
-
-
-static Standard_Real MyXwindowCenter ;
-static Standard_Real MyYwindowCenter ;
-static Standard_Real MyWindowWidth ;
-static Standard_Real MyWindowHeight ;
-
-#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()
-
-static Graphic3d_Vector& _MyYscreenAxis() {
-  static Graphic3d_Vector MyYscreenAxis;
-  return MyYscreenAxis;
-}
-#define MyYscreenAxis _MyYscreenAxis()
-
-static Graphic3d_Vector& _MyZscreenAxis() {
-  static Graphic3d_Vector MyZscreenAxis;
-  return MyZscreenAxis;
-}
-#define MyZscreenAxis _MyZscreenAxis()
-
-static Graphic3d_Vector& _MyViewReferencePlane() {
-  static Graphic3d_Vector MyViewReferencePlane;
-  return MyViewReferencePlane;
-}
-#define MyViewReferencePlane _MyViewReferencePlane()
-
-static Graphic3d_Vector& _MyViewReferenceUp() {
-  static Graphic3d_Vector MyViewReferenceUp;
-  return MyViewReferenceUp;
-}
-#define MyViewReferenceUp _MyViewReferenceUp()
-
-static Graphic3d_Vector& _MyViewAxis() {
-  static Graphic3d_Vector MyViewAxis;
-  return MyViewAxis;
-}
-#define MyViewAxis _MyViewAxis()
-
-static Graphic3d_Vertex& _MyViewReferencePoint() {
-  static Graphic3d_Vertex MyViewReferencePoint;
-  return MyViewReferencePoint;
-}
-#define MyViewReferencePoint _MyViewReferencePoint()
-
-static Graphic3d_Vertex& _MyGravityReferencePoint() {
-  static Graphic3d_Vertex MyGravityReferencePoint;
-  return MyGravityReferencePoint;
-}
-#define MyGravityReferencePoint _MyGravityReferencePoint()
-
-static Graphic3d_Vertex& _MyProjReferencePoint() {
-  static Graphic3d_Vertex MyProjReferencePoint;
-  return MyProjReferencePoint;
-}
-#define MyProjReferencePoint _MyProjReferencePoint()
-#endif // LOPTIM
-
-/*----------------------------------------------------------------------*/
-//-Constructors
-
+//=============================================================================
+//function : Constructor
+//purpose  :
+//=============================================================================
 V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) :
-MyType ( Type ),
-MyProjModel(V3d_TPM_SCREEN),
-MyViewer(VM.operator->()),
-MyActiveLights(),
-MyViewContext (),
-myActiveLightsIterator(),
-SwitchSetFront(Standard_False),
-MyTrsf (1, 4, 1, 4)         // S3892
+  MyProjModel(V3d_TPM_SCREEN),
+  MyViewer(VM.operator->()),
+  MyActiveLights(),
+  MyViewContext (),
+  myActiveLightsIterator(),
+  SwitchSetFront(Standard_False),
+  MyTrsf (1, 4, 1, 4),
+  myAutoZFitIsOn (Standard_True),
+  myAutoZFitScaleFactor (1.0)
 {
   myImmediateUpdate = Standard_False;
   MyView = new Visual3d_View(MyViewer->Viewer());
@@ -319,7 +223,7 @@ MyTrsf (1, 4, 1, 4)         // S3892
   else
     MyViewContext.SetBackZClippingOff ();
 
-  // Visualisation and Shading Model
+  // Visualization and Shading Model
   MyViewContext.SetModel ((MyView->Context ()).Model ());
   MyViewContext.SetVisualization ((MyView->Context ()).Visualization ());
 
@@ -328,80 +232,93 @@ MyTrsf (1, 4, 1, 4)         // S3892
   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()) ;
+  // camera init
+  Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera();
+  aCamera->SetFOVy (45.0);
+  aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05);
+  aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0);
+  SetCamera (aCamera);
+
+  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.) ;
+  SetZSize (2.*zsize);
+  SetZClippingDepth (0.);
+  SetZClippingWidth (zsize);
+  SetZCueingDepth (0.);
+  SetZCueingWidth (zsize);
+  SetDepth (VM->DefaultViewSize()/2.0);
   SetViewMappingDefault();
-  VM->AddView(this) ;
+  SetViewOrientationDefault();
+  VM->AddView (this);
   Init();
   myImmediateUpdate = Standard_True;
 
-  // S3892
-#ifndef IMP240100
-#endif  //IMP240100
+  aCamera->SetProjectionType ((Type == V3d_ORTHOGRAPHIC)
+    ? Graphic3d_Camera::Projection_Orthographic
+    : Graphic3d_Camera::Projection_Perspective);
 
-#ifdef IMP210200
   MyTransparencyFlag = Standard_False;
-#endif
 }
 
-/*----------------------------------------------------------------------*/
-
-V3d_View::V3d_View(const Handle(V3d_Viewer)& VM,const Handle(V3d_View)& V, const V3d_TypeOfView Type ) :
-MyType ( Type ),
-MyProjModel(V3d_TPM_SCREEN),
-MyViewer(VM.operator->()),
-MyActiveLights(),
-MyViewContext (),
-myActiveLightsIterator(),
-SwitchSetFront(Standard_False),
-MyTrsf (1, 4, 1, 4)                                    // S3892
+//=============================================================================
+//function : Constructor
+//purpose  :
+//=============================================================================
+V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) :
+  MyProjModel(V3d_TPM_SCREEN),
+  MyViewer(theVM.operator->()),
+  MyActiveLights(),
+  MyViewContext (),
+  myActiveLightsIterator(),
+  SwitchSetFront(Standard_False),
+  MyTrsf (1, 4, 1, 4)
 {
-  Handle(Visual3d_View) FromView = V->View() ;
+  Handle(Visual3d_View) aFromView = theView->View();
 
   myImmediateUpdate = Standard_False;
-  MyView = new Visual3d_View(MyViewer->Viewer());
+  MyView = new Visual3d_View (MyViewer->Viewer());
 
-  for (V->InitActiveLights();V->MoreActiveLights();V->NextActiveLights()){
-    MyActiveLights.Append(V->ActiveLight());}
+  for (theView->InitActiveLights(); theView->MoreActiveLights(); theView->NextActiveLights())
+  {
+    MyActiveLights.Append (theView->ActiveLight());
+  }
 
-  MyViewContext = FromView->Context() ;
+  MyViewContext = aFromView->Context() ;
 
-  MyViewMapping = FromView->ViewMapping() ;
-  MyViewOrientation = FromView->ViewOrientation() ;
-  MyBackground = FromView->Background() ;
-  MyGradientBackground = FromView->GradientBackground();
+  SetCamera (new Graphic3d_Camera (theView->Camera()));
+  myAutoZFitIsOn        = theView->AutoZFitMode();
+  myAutoZFitScaleFactor = theView->AutoZFitScaleFactor();
 
-  MyView->SetContext(MyViewContext) ;
+  MyBackground = aFromView->Background() ;
+  MyGradientBackground = aFromView->GradientBackground();
+
+  MyView->SetContext (MyViewContext) ;
+
+  SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
+
+  SetViewMappingDefault();
+  SetViewOrientationDefault();
+  theVM->AddView (this);
 
-  SetAxis(0.,0.,0.,1.,1.,1.) ;
-  VM->AddView(this) ;
   Init();
+
   myImmediateUpdate = Standard_True;
 }
 
-/*----------------------------------------------------------------------*/
-
-//-Methods, in order
-
+//=============================================================================
+//function : SetMagnify
+//purpose  :
+//=============================================================================
 void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
                           const Handle(V3d_View)& aPreviousView,
                           const Standard_Integer x1,
@@ -416,7 +333,6 @@ void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
     MyView->SetWindow(TheWindow) ;
     FitAll(TheWindow,a,b,c,d);
     MyView->SetContext(MyViewContext) ;
-    MyView->SetViewOrientation(MyViewOrientation) ;
     MyView->SetBackground(MyBackground) ;
     MyViewer->SetViewOn(this) ;
     MyWindow = TheWindow;
@@ -425,8 +341,10 @@ void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow,
   }
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetWindow
+//purpose  :
+//=============================================================================
 void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
 {
   Standard_MultiplyDefined_Raise_if( MyView->IsDefined(),
@@ -439,19 +357,16 @@ void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow)
   // 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) ;
   MyView->Redraw() ;
 }
 
-// RIC120302
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetWindow
+//purpose  :
+//=============================================================================
 void V3d_View::SetWindow(const Handle(Aspect_Window)&      aWindow,
                          const Aspect_RenderingContext     aContext,
                          const Aspect_GraphicCallbackProc& aDisplayCB,
@@ -466,18 +381,16 @@ void V3d_View::SetWindow(const Handle(Aspect_Window)&      aWindow,
   // 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() ;
 }
-// RIC120302
-
-/*----------------------------------------------------------------------*/
 
+//=============================================================================
+//function : Remove
+//purpose  :
+//=============================================================================
 void V3d_View::Remove() const
 {
   MyViewer->DelView (this);
@@ -486,30 +399,62 @@ void V3d_View::Remove() const
   aWin.Nullify();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Update
+//purpose  :
+//=============================================================================
 void V3d_View::Update() const
 {
   if( MyView->IsDefined() )  MyView->Update() ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Redraw
+//purpose  :
+//=============================================================================
 void V3d_View::Redraw() const
 {
   if( MyView->IsDefined() ) MyView->Redraw() ;
 }
 
-/*----------------------------------------------------------------------*/
+//=============================================================================
+//function : RedrawImmediate
+//purpose  :
+//=============================================================================
+void V3d_View::RedrawImmediate() const
+{
+  if (MyView->IsDefined())
+  {
+    MyView->RedrawImmediate();
+  }
+}
 
+//=============================================================================
+//function : Invalidate
+//purpose  :
+//=============================================================================
+void V3d_View::Invalidate() const
+{
+  if (MyView->IsDefined())
+  {
+    MyView->Invalidate();
+  }
+}
+
+//=============================================================================
+//function : Redraw
+//purpose  :
+//=============================================================================
 void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc,
                       const Standard_Integer width,const Standard_Integer height) const
 {
   if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : IsEmpty
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::IsEmpty() const
 {
   Standard_Boolean TheStatus = Standard_True ;
@@ -520,16 +465,20 @@ Standard_Boolean V3d_View::IsEmpty() const
   return (TheStatus) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : UpdateLights
+//purpose  :
+//=============================================================================
 void V3d_View::UpdateLights() const
 {
   MyView->SetContext(MyViewContext);
   Update();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : DoMapping
+//purpose  :
+//=============================================================================
 void V3d_View::DoMapping()
 {
   if( MyView->IsDefined() ) {
@@ -537,8 +486,10 @@ void V3d_View::DoMapping()
   }
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : MustBeResized
+//purpose  :
+//=============================================================================
 void V3d_View::MustBeResized()
 {
   if ( !MyLayerMgr.IsNull() )
@@ -546,13 +497,14 @@ void V3d_View::MustBeResized()
 
   if( MyView->IsDefined() ) {
     MyView->Resized() ;
-    MyViewMapping = MyView->ViewMapping();
     MyView->Redraw();
   }
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBackgroundColor
+//purpose  :
+//=============================================================================
 void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3)
 {
   Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 );
@@ -563,8 +515,10 @@ void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standar
   SetBackgroundColor( C );
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBackgroundColor
+//purpose  :
+//=============================================================================
 void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
 {
   MyBackground.SetColor( Color );
@@ -575,16 +529,20 @@ void V3d_View::SetBackgroundColor(const Quantity_Color &Color)
     MyLayerMgr->Resized();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBackgroundColor
+//purpose  :
+//=============================================================================
 void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name)
 {
   Quantity_Color C( Name );
   SetBackgroundColor( C );
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBgGradientColors
+//purpose  :
+//=============================================================================
 void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
                                     const Quantity_Color& Color2,
                                     const Aspect_GradientFillMethod FillStyle,
@@ -595,8 +553,10 @@ void V3d_View::SetBgGradientColors( const Quantity_Color& Color1,
     MyView->SetGradientBackground( MyGradientBackground, status );
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBgGradientColors
+//purpose  :
+//=============================================================================
 void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
                                     const Quantity_NameOfColor Color2,
                                     const Aspect_GradientFillMethod FillStyle,
@@ -609,8 +569,10 @@ void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1,
     MyView->SetGradientBackground( MyGradientBackground, status );
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBgGradientStyle
+//purpose  :
+//=============================================================================
 void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
                                    const Standard_Boolean update)
 {
@@ -621,8 +583,10 @@ void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
     MyView->SetBgGradientStyle( FillStyle, update ) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBackgroundImage
+//purpose  :
+//=============================================================================
 void V3d_View::SetBackgroundImage( const Standard_CString FileName,
                                    const Aspect_FillMethod FillStyle,
                                    const Standard_Boolean update )
@@ -633,8 +597,10 @@ void V3d_View::SetBackgroundImage( const Standard_CString FileName,
 #endif
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetBgImageStyle
+//purpose  :
+//=============================================================================
 void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
                                 const Standard_Boolean update )
 {
@@ -644,8 +610,10 @@ void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
 #endif
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetAxis
+//purpose  :
+//=============================================================================
 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 ;
@@ -655,128 +623,138 @@ void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Stand
   Nx /= D ; Ny /= D ; Nz /= D ;
   MyDefaultViewPoint.SetCoord(X,Y,Z) ;
   MyDefaultViewAxis.SetCoord(Nx,Ny,Nz) ;
-  MyDefaultViewAxis.Normalize() ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetShadingModel
+//purpose  :
+//=============================================================================
 void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model)
 {
   MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ;
   MyView->SetContext(MyViewContext) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetSurfaceDetail
+//purpose  :
+//=============================================================================
 void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model)
 {
   MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ;
   MyView->SetContext(MyViewContext) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetTextureEnv
+//purpose  :
+//=============================================================================
 void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture)
 {
   MyViewContext.SetTextureEnv(ATexture) ;
   MyView->SetContext(MyViewContext) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : SetVisualization
+//purpose  :
+//=============================================================================
 void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode)
 {
   MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode);
   MyView->SetContext(MyViewContext) ;
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//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);
 
+  myCamera->SetCenter (gp_Pnt (xo, yo, zo));
   if(SwitchSetFront)
-    MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(-vx,-vy,-vz));
+    myCamera->SetDirection (gp_Dir (vx, vy, vz));
   else
-    MyViewOrientation.SetViewReferencePlane(Graphic3d_Vector(vx,vy,vz));
-
-  SwitchSetFront = !SwitchSetFront;
+    myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed());
+  myCamera->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();
 }
 
-/*----------------------------------------------------------------------*/
-
-void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Standard_Real az, const Standard_Boolean Start)
+//=============================================================================
+//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 ;
-  Graphic3d_Vector Vpn,Vup ;
-  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 ;
-  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( 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 = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
+  }
+
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->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]);
+
+  myCamera->Transform (aTrsf);
+
+  AutoZFit();
 
-  if( Start ) {
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
-      V3d_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();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//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)
 {
+
   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 ;
@@ -785,42 +763,46 @@ 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))
-      V3d_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
+  if (Start)
+  {
+    myGravityReferencePoint.SetCoord (X, Y, Z);
+    myCamStartOpUp = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
+  }
+
+  const Graphic3d_Vertex& aVref = myGravityReferencePoint;
+
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+
+  // rotate camera around 3 initial axes
+  gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
+
+  gp_Dir aZAxis (myCamera->Direction().Reversed());
+  gp_Dir aYAxis (myCamera->Up());
+  gp_Dir 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]);
+
+  myCamera->Transform (aTrsf);
+
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
 void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const Standard_Boolean Start)
 {
   switch (Axe) {
@@ -836,97 +818,107 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, const
   }
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
 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)
 {
   Standard_Real Angle = angle ;
-  Graphic3d_Vector Vpn,Vup ;
-  Graphic3d_Vertex Vrp ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
 
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
-  if( Start ) {
-    MyGravityReferencePoint.SetCoord(X,Y,Z) ;
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
+  if (Start)
+  {
+    myGravityReferencePoint.SetCoord (X, Y, Z);
+    myCamStartOpUp = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
+
     switch (Axe) {
     case V3d_X :
-      MyViewAxis.SetCoord(1.,0.,0.) ;
+      myViewAxis.SetCoord(1.,0.,0.) ;
       break ;
     case V3d_Y :
-      MyViewAxis.SetCoord(0.,1.,0.) ;
+      myViewAxis.SetCoord(0.,1.,0.) ;
       break ;
     case V3d_Z :
-      MyViewAxis.SetCoord(0.,0.,1.) ;
+      myViewAxis.SetCoord(0.,0.,1.) ;
       break ;
     }
+
+    myCamStartOpUp = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->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
+  const Graphic3d_Vertex& aVref = myGravityReferencePoint;
+
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+
+  // rotate camera around passed axis
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z());
+  gp_Dir aRAxis ((Axe == V3d_X) ? 1.0 : 0.0,
+                  (Axe == V3d_Y) ? 1.0 : 0.0,
+                  (Axe == V3d_Z) ? 1.0 : 0.0);
+
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
+  myCamera->Transform (aRotation);
+
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : Rotate
+//purpose  :
+//=============================================================================
 void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start)
 {
-  Standard_Real Angle = angle ;
-  Graphic3d_Vector Vpn,Vup ;
-  TColStd_Array2OfReal Matrix(0,3,0,3) ;
+  Standard_Real Angle = angle;
 
   if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ;
   else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ;
 
   if( Start ) {
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
+    myCamStartOpUp = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
   }
 
-  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
+  const Graphic3d_Vertex& aPnt = MyDefaultViewPoint;
+  const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
+
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter (aPnt.X(), aPnt.Y(), aPnt.Z());
+  gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
+  myCamera->Transform (aRotation);
+
+  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 ;
@@ -936,54 +928,40 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa
   else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ;
 
   if( Start ) {
-    MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-    MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-    MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-    MyViewReferenceUp = MyViewOrientation.ViewReferenceUp() ;
-    if (!ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis))
-      V3d_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 = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
+  }
 
-/*----------------------------------------------------------------------*/
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+
+  // rotate camera around 3 initial axes
+  gp_Pnt aRCenter = myCamera->Eye();
+  gp_Dir aZAxis (myCamera->Direction().Reversed());
+  gp_Dir aYAxis (myCamera->Up());
+  gp_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]);
+
+  myCamera->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) {
@@ -999,887 +977,769 @@ void V3d_View::Turn(const V3d_TypeOfAxe Axe, const Standard_Real angle, const St
   }
 }
 
+//=============================================================================
+//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 ;
 
   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 = myCamera->Up();
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
+  }
+
+  myCamera->SetUp (myCamStartOpUp);
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+
+  const Graphic3d_Vector& anAxis = MyDefaultViewAxis;
+
+  gp_Trsf aRotation;
+  gp_Pnt aRCenter = myCamera->Eye();
+  gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z());
+  aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle);
+  myCamera->Transform (aRotation);
+
+  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 ;
+  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) ;
+  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  gp_Dir anUp;
+
+  anUp = gp_Dir (0.0, 0.0, 1.0);
+
+  TheStatus = ScreenAxis(aReferencePlane, anUp,
+    myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (0.0, 1.0, 0.0);
+    TheStatus = ScreenAxis(aReferencePlane, anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (1.0, 0.0, 0.0);
+    TheStatus = ScreenAxis(aReferencePlane, anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
 
   V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,");
+  
+  gp_Pnt aRCenter = myCamera->Center();
+  gp_Dir aZAxis (myCamera->Direction().Reversed());
+
+  gp_Trsf aTrsf;
+  aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle);
+
+  Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
+  myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
+
+  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+  myCamera->Transform (aTrsf);
+
+  AutoZFit();
 
-  MyViewReferencePoint = MyViewOrientation.ViewReferencePoint() ;
-  RotAxis(MyViewReferencePoint,MyZscreenAxis,Angle,Matrix) ;
-  MyViewReferenceUp = TrsPoint(MyYscreenAxis,Matrix) ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
   ImmediateUpdate();
 }
 
-#ifdef IMP240100
-void V3d_View::SetProjModel( const V3d_TypeOfProjectionModel aModel )
+//=============================================================================
+//function : SetAutoZFitMode
+//purpose  :
+//=============================================================================
+void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn, const Standard_Real theScaleFactor)
 {
-  MyProjModel = aModel;
+  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+  myAutoZFitScaleFactor = theScaleFactor;
+  myAutoZFitIsOn = theIsOn;
 }
 
-V3d_TypeOfProjectionModel V3d_View::ProjModel() const
+//=============================================================================
+//function : AutoZFitMode
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::AutoZFitMode() const
 {
-  return MyProjModel;
+  return myAutoZFitIsOn;
 }
-#endif
 
+//=============================================================================
+//function : AutoZFitScaleFactor
+//purpose  :
+//=============================================================================
+Standard_Real V3d_View::AutoZFitScaleFactor () const
+{
+  return myAutoZFitScaleFactor;
+}
+
+//=============================================================================
+//function : SetEye
+//purpose  :
+//=============================================================================
 void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard_Real 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) ;
-  V3d_BadValue_Raise_if( Zrp <= 0. , "V3d_View::SetEye:: Eye,At are Confused");
-
-  Xpn /= Zrp ; Ypn /= Zrp ; Zpn /= Zrp ;
-  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
-  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();
+  Standard_Real aTwistBefore = Twist();
+
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+  myCamera->SetEye (gp_Pnt (X, Y, Z));
+  SetTwist (aTwistBefore);
+
+  AutoZFit();
+
+  SetImmediateUpdate (wasUpdateEnabled);
+
+  ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetDepth
+//purpose  :
+//=============================================================================
 void V3d_View::SetDepth(const Standard_Real Depth)
 {
-  Standard_Real Xrp,Yrp,Zrp ;
-#ifdef IMP250200
-  V3d_BadValue_Raise_if( Depth == 0. ,"V3d_View::SetDepth, bad depth");
-#else
-  V3d_BadValue_Raise_if( Depth <= 0. ,"V3d_View::SetDepth, bad depth");
-#endif
+  V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth");
 
-  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);
+    // Move eye using center (target) as anchor.
+    myCamera->SetDistance (Depth);
   }
-#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
+  else
+  {
+    // Move the view ref point instead of the eye.
+    gp_Vec aDir (myCamera->Direction());
+    gp_Pnt aCameraEye = myCamera->Eye();
+    gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth)));
 
-    ImmediateUpdate();
-}
+    myCamera->SetCenter (aCameraCenter);
+  }
 
+  AutoZFit();
 
+  ImmediateUpdate();
+}
+
+//=============================================================================
+//function : SetProj
+//purpose  :
+//=============================================================================
 void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Standard_Real Vz )
 {
-  Standard_Real Angle ;
-
   V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0.,
     "V3d_View::SetProj, null projection vector");
 
-  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;
+  Standard_Real aTwistBefore = Twist();
+
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+  myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed());
+
+  if (MyProjModel == V3d_TPM_SCREEN)
+  {
+    SetTwist(aTwistBefore);
+  }
+
+  AutoZFit();
+
+  SetImmediateUpdate (wasUpdateEnabled);
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetProj
+//purpose  :
+//=============================================================================
 void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation )
 {
-  MyViewReferencePlane = V3d::GetProjAxis(Orientation) ;
-  MyViewOrientation.SetViewReferencePlane(MyViewReferencePlane) ;
-  // MSV 14.03.2007: reset ViewReferencePoint to debug LH3D14955
-  MyViewOrientation.SetViewReferencePoint(Graphic3d_Vertex (0.0f, 0.0f, 0.0f));
   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
+
+  const Graphic3d_Vector& aBck = V3d::GetProjAxis (Orientation);
+
+  // retain camera panning from origin when switching projection
+  gp_Pnt anOriginVCS = myCamera->ConvertWorld2View (gp::Origin());
+  Standard_Real aPanX = anOriginVCS.X();
+  Standard_Real aPanY = anOriginVCS.Y();
+
+  myCamera->SetCenter (gp_Pnt (0, 0, 0));
+  myCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed());
+  myCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn));
+  myCamera->OrthogonalizeUp();
+
+  Panning (aPanX, aPanY);
+
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetAt
+//purpose  :
+//=============================================================================
 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) ;
-  V3d_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
+  Standard_Real aTwistBefore = Twist();
+
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+  myCamera->SetCenter (gp_Pnt (X, Y, Z));
+
+  SetTwist (aTwistBefore);
+
+  AutoZFit();
+
+  SetImmediateUpdate (wasUpdateEnabled);
+
   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();
 }
 
+//=============================================================================
+//function : SetUp
+//purpose  :
+//=============================================================================
 void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standard_Real Vz)
 {
   Standard_Boolean TheStatus ;
   V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. ,
     "V3d_View::SetUp, nullUp vector");
 
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  MyViewReferenceUp.SetCoord(Vx,Vy,Vz) ;
-  MyViewReferenceUp.Normalize() ;
-  TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-    MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  gp_Dir anUp (Vx, Vy, Vz);
+
+  TheStatus = ScreenAxis(aReferencePlane,anUp,
+    myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,0.,1.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (0.0, 0.0, 1.0);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (0.0, 1.0, 0.0);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (1.0, 0.0, 0.0);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   V3d_BadValue_Raise_if( !TheStatus,"V3d_View::Setup, alignment of Eye,At,Up");
 
-  MyViewReferenceUp = MyYscreenAxis ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
+  Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
+  myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
+
+  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetUp
+//purpose  :
+//=============================================================================
 void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation )
 {
   Standard_Boolean TheStatus ;
 
-  MyViewReferenceUp = V3d::GetProjAxis(Orientation) ;
-  MyViewReferencePlane = MyViewOrientation.ViewReferencePlane() ;
-  TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-    MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  gp_Dir anUp;
+
+  const Graphic3d_Vector& aViewReferenceUp = V3d::GetProjAxis(Orientation) ;
+  anUp = gp_Dir (aViewReferenceUp.X(), aViewReferenceUp.Y(), aViewReferenceUp.Z());
+
+  TheStatus = ScreenAxis(aReferencePlane,anUp,
+    myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,0.,1.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (0.,0.,1.);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (0.,1.,0.);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   if( !TheStatus ) {
-    MyViewReferenceUp.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(MyViewReferencePlane,MyViewReferenceUp,
-      MyXscreenAxis,MyYscreenAxis,MyZscreenAxis) ;
+    anUp = gp_Dir (1.,0.,0.);
+    TheStatus = ScreenAxis(aReferencePlane,anUp,
+      myXscreenAxis,myYscreenAxis,myZscreenAxis) ;
   }
   V3d_BadValue_Raise_if( !TheStatus, "V3d_View::SetUp, alignment of Eye,At,Up");
 
-  MyViewReferenceUp = MyYscreenAxis ;
-  MyViewOrientation.SetViewReferenceUp(MyViewReferenceUp) ;
-  MyView->SetViewOrientation(MyViewOrientation) ;
-  ImmediateUpdate();
-}
+  Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ;
+  myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ);
+
+  myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ));
+
+  AutoZFit();
 
-void V3d_View::SetViewOrientation(const Visual3d_ViewOrientation& VO)
-{
-  MyViewOrientation = VO;
-  MyView->SetViewOrientation(MyViewOrientation) ;
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetViewOrientationDefault
+//purpose  :
+//=============================================================================
 void V3d_View::SetViewOrientationDefault()
 {
-  MyView->SetViewOrientation(MyViewOrientation) ;
   MyView->SetViewOrientationDefault() ;
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : ResetViewOrientation
+//purpose  :
+//=============================================================================
 void V3d_View::ResetViewOrientation()
 {
   MyView->ViewOrientationReset() ;
-  MyViewOrientation = MyView->ViewOrientation() ;
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : Reset
+//purpose  :
+//=============================================================================
 void V3d_View::Reset( const Standard_Boolean update )
 {
-  MyView->ViewOrientationReset() ;
-  MyViewOrientation = MyView->ViewOrientation() ;
-  MyView->ViewMappingReset();
-  MyViewMapping = MyView->ViewMapping() ;
+  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
 
-  ZFitAll (Zmargin);
-  SwitchSetFront = Standard_False;
-#ifdef IMP020300
-  if( !myImmediateUpdate && update ) Update();
-#else
-  ImmediateUpdate();
-#endif
-}
+  if (!aDefaultCamera.IsNull())
+  {
+    myCamera->CopyMappingData (aDefaultCamera);
+    myCamera->CopyOrientationData (aDefaultCamera);
 
-void V3d_View::Panning(const Standard_Real Dx, const Standard_Real Dy, const Quantity_Factor aZoomFactor, const Standard_Boolean Start)
-{
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp,Dxv,Dyv ;
-  V3d_BadValue_Raise_if( aZoomFactor <= 0.,"V3d_View::Panning, bad zoom factor");
+    AutoZFit();
+  }
 
-  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) ;
-    V3d_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();
-}
+  SwitchSetFront = Standard_False;
 
-void V3d_View::SetCenter(const Standard_Integer X, const Standard_Integer Y)
-{
-  Standard_Real x,y;
-  Convert(X,Y,x,y);
-  SetCenter(x,y);
+  if( !myImmediateUpdate && update ) Update();
 }
 
-void V3d_View::SetCenter(const Standard_Real Xc, const Standard_Real Yc)
+//=======================================================================
+//function : SetCenter
+//purpose  :
+//=======================================================================
+void V3d_View::SetCenter (const Standard_Integer theXp,
+                          const Standard_Integer theYp)
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp ;
+  Standard_Real aXv, aYv;
+  Convert (theXp, theYp, aXv, aYv);
+  Translate (myCamera, aXv, aYv);
 
-  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) ;
-  V3d_BadValue_Raise_if( MyWindowWidth <= 0. || MyWindowHeight <= 0. ,
-    "V3d_View::SetCenter, Window Size is NULL");
-
-  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 : SetSize
+//purpose  :
+//=============================================================================
+void V3d_View::SetSize (const Standard_Real theSize)
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Rap ;
+  V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL");
 
-  V3d_BadValue_Raise_if(  Size  <= 0.,
-    "V3d_View::SetSize, Window Size is NULL");
+  myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize);
 
+  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();
 }
 
+//=============================================================================
+//function : SetZSize
+//purpose  :
+//=============================================================================
 void V3d_View::SetZSize(const Standard_Real Size)
 {
   Standard_Real Zmax = Size/2.;
 
-#ifdef IMP020300
+  Standard_Real aDistance = myCamera->Distance();
+
   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;
+    Zmax = aDistance;
   }
-#else
-  V3d_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 Front = MyViewContext.ZClippingFrontPlane();
+  Standard_Real Back  = MyViewContext.ZClippingBackPlane();
 
-  MyViewMapping.SetFrontPlaneDistance(Zmax) ;
-  MyViewMapping.SetBackPlaneDistance(-Zmax) ;
+  // 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);
 
-  // OCC18942
-  if( MyProjModel != V3d_TPM_WALKTHROUGH ) {
-    MyViewMapping.SetViewPlaneDistance(MyType == V3d_PERSPECTIVE ? 0. : Zmax) ;
+  Standard_Real aZFar  =  Zmax  + aDistance * 2.0;
+  Standard_Real aZNear = -Zmax  + aDistance;
+  aZNear              -= Abs (aZNear) * aPrecision;
+  aZFar               += Abs (aZFar)  * aPrecision;
+
+  if (!myCamera->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->SetViewMapping(MyViewMapping) ;
-  if( MyViewContext.FrontZClippingIsOn()  ||
-      MyViewContext.BackZClippingIsOn() )
+  // If range is too small
+  if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
   {
-    MyViewContext.SetZClippingFrontPlane(Front) ;
-    MyViewContext.SetZClippingBackPlane(Back) ;
-    MyView->SetContext(MyViewContext) ;
+    aZFar = aZNear + Abs (aZFar) * aPrecision;
+  }
+
+  myCamera->SetZRange (aZNear, aZFar);
+
+  if (MyViewContext.FrontZClippingIsOn()  ||
+      MyViewContext.BackZClippingIsOn())
+  {
+    MyViewContext.SetZClippingFrontPlane (Front);
+    MyViewContext.SetZClippingBackPlane (Back);
+    MyView->SetContext (MyViewContext);
   }
 }
 
+//=============================================================================
+//function : SetZoom
+//purpose  :
+//=============================================================================
 void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start)
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Dxv,Dyv ;
   V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient");
 
-  if( Start ) {
-    MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-    MyXwindowCenter = (Umin + Umax)/2. ;
-    MyYwindowCenter = (Vmin + Vmax)/2. ;
-    MyWindowWidth = Abs(Umax - Umin) ;
-    MyWindowHeight = Abs(Vmax - Vmin) ;
+  if (Start)
+  {
+    myCamStartOpEye    = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
   }
 
+  Standard_Real aViewWidth  = myCamera->ViewDimensions().X();
+  Standard_Real aViewHeight = myCamera->ViewDimensions().Y();
+
   // 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) ;
+  if (aViewWidth < coef * Precision::Confusion())
+  {
+    coef = aViewWidth / Precision::Confusion();
+  }
+  else if (aViewWidth > coef * 1e12)
+  {
+    coef = aViewWidth / 1e12;
+  }
+  if (aViewHeight < coef * Precision::Confusion())
+  {
+    coef = aViewHeight / Precision::Confusion();
+  }
+  else if (aViewHeight > coef * 1e12)
+  {
+    coef = aViewHeight / 1e12;
+  }
+
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+  myCamera->SetScale (myCamera->Scale() / Coef);
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetScale
+//purpose  :
+//=============================================================================
 void V3d_View::SetScale( const Standard_Real Coef )
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Dxv,Dyv ;
-  Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
-
   V3d_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) ;
+  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
+
+  // Strange behavior for the sake of compatibility.
+  if (!aDefaultCamera.IsNull())
+  {
+    myCamera->SetAspect (aDefaultCamera->Aspect());
+    Standard_Real aDefaultScale = aDefaultCamera->Scale();
+    myCamera->SetScale (aDefaultScale / Coef);
+  } 
+  else
+  {
+    myCamera->SetScale (myCamera->Scale() / Coef);
+  }
+
+  AutoZFit();
+
   ImmediateUpdate();
 }
 
+//=============================================================================
+//function : SetAxialScale
+//purpose  :
+//=============================================================================
 void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz )
 {
-  Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax,U,V,W ;
-  Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ;
   V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient");
 
-  MyViewOrientation.SetAxialScale( Sx, Sy, Sz );
-  Aspect_TypeOfUpdate updateMode = MyView->ViewManager()->UpdateMode();
-  MyView->ViewManager()->SetUpdateMode(Aspect_TOU_ASAP);
-  MyView->SetViewOrientation(MyViewOrientation);
-  MyView->ViewManager()->SetUpdateMode(updateMode);
-
-  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 ) {
-      return;
-    }
-
-    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( Wmax > 0. ) {
-      SetZSize(2.*Wmax + Wmax) ;
-    }
+  myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz));
+  AutoZFit();
 }
 
-void V3d_View::FitAll(const Standard_Real Coef, const Standard_Boolean FitZ,
-                      const Standard_Boolean update)
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
+void V3d_View::FitAll (const Standard_Real theMargin, const Standard_Boolean theToUpdate)
 {
-  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();
+  Standard_ASSERT_RAISE (theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient");
 
-  if ((Nstruct <= 0) || (Coef < 0.0) || (Coef > 1.0))
+  if (MyView->NumberOfDisplayedStructures() == 0)
   {
-#ifndef IMP020300
-    ImmediateUpdate();
-#endif
     return;
   }
 
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint();
-  MyProjReferencePoint.Coord (Xrp, Yrp, Zrp);
-  if (MyView->IsDefined())
+  Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
+  MyView->MinMaxValues (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+  gp_XYZ aMin (aXmin, aYmin, aZmin);
+  gp_XYZ aMax (aXmax, aYmax, aZmax);
+
+  if (!FitMinMax (myCamera, aMin, aMax, theMargin, 10.0 * Precision::Confusion()))
   {
-    Standard_Integer Xpixel, Ypixel;
-    MyWindow->Size (Xpixel, Ypixel);
-    DxvOld = Xpixel;
-    DyvOld = Ypixel;
+    return;
   }
-  else
+
+  AutoZFit();
+
+  if (myImmediateUpdate || theToUpdate)
   {
-    MyViewMapping.WindowLimit (Umin, Vmin, Umax, Vmax);
-    DxvOld = Abs (Umax - Umin);
-    DyvOld = Abs (Vmax - Vmin);
+    Update();
   }
-  if ((DxvOld == 0.0) || (DyvOld == 0.0))
+}
+
+//=============================================================================
+//function : AutoZFit
+//purpose  :
+//=============================================================================
+void V3d_View::AutoZFit()
+{
+  if (!AutoZFitMode())
   {
     return;
   }
 
-  Standard_Real aWinRatio = DxvOld / DyvOld;
+  ZFitAll (myAutoZFitScaleFactor);
+}
+
+//=============================================================================
+//function : ZFitAll
+//purpose  :
+//=============================================================================
+void V3d_View::ZFitAll (const Standard_Real theScaleFactor)
+{
+  Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
+
+  // Method changes ZNear and ZFar planes of camera so as to fit the graphical structures
+  // by their real boundaries (computed ignoring infinite flag) into the viewing volume.
+  // In addition to the graphical boundaries, the usual min max used for fitting perspective
+  // camera. To avoid numeric errors for perspective camera the negative ZNear values are
+  // fixed using tolerance distance, relative to boundaries size. The tolerance distance
+  // should be computed using information on boundaries of primary application actors,
+  // (e.g. representing the displayed model) - to ensure that they are not unreasonably clipped.
+
+  Standard_Real aMinMax[6];    // applicative min max boundaries
+  View()->MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
+                        aMinMax[3], aMinMax[4], aMinMax[5],
+                        Standard_False);
 
-  // retrieve min / max values for current displayed objects
-  MyView->MinMaxValues (Xmin, Ymin, Zmin,
-                        Xmax, Ymax, Zmax);
+  Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
+  View()->MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
+                        aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
+                        Standard_True);
 
-  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)
+  // Check if anything can be adjusted
+  Standard_Real aLim = (ShortRealLast() - 1.0);
+  if (Abs (aGraphicBB[0]) > aLim || Abs (aGraphicBB[1]) > aLim || Abs (aGraphicBB[2]) > aLim ||
+      Abs (aGraphicBB[3]) > aLim || Abs (aGraphicBB[4]) > aLim || Abs (aGraphicBB[5]) > aLim)
   {
-#ifndef IMP020300
+    SetZSize (0.0);
     ImmediateUpdate();
-#endif
     return;
   }
 
-  // eliminate fluctuations between sequential FitAll() calls
-  MyViewMapping.SetWindowLimit (-1.0 * aWinRatio, -1.0, 1.0 * aWinRatio, 1.0);
-  if (MyType != V3d_PERSPECTIVE)
+  // Measure depth of boundary points from camera eye
+  gp_Pnt aPntsToMeasure[16] =
   {
-    MyProjReferencePoint.SetCoord (0.0, 0.0, Zrp);
-    MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
-  }
-  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)
+    gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[2]),
+    gp_Pnt (aMinMax[0], aMinMax[1], aMinMax[5]),
+    gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[2]),
+    gp_Pnt (aMinMax[0], aMinMax[4], aMinMax[5]),
+    gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[2]),
+    gp_Pnt (aMinMax[3], aMinMax[1], aMinMax[5]),
+    gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[2]),
+    gp_Pnt (aMinMax[3], aMinMax[4], aMinMax[5]),
+
+    gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2]),
+    gp_Pnt (aGraphicBB[0], aGraphicBB[1], aGraphicBB[5]),
+    gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[2]),
+    gp_Pnt (aGraphicBB[0], aGraphicBB[4], aGraphicBB[5]),
+    gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[2]),
+    gp_Pnt (aGraphicBB[3], aGraphicBB[1], aGraphicBB[5]),
+    gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[2]),
+    gp_Pnt (aGraphicBB[3], aGraphicBB[4], aGraphicBB[5])
+  };
+
+  // Camera eye plane
+  gp_Dir aCamDir = myCamera->Direction();
+  gp_Pnt aCamEye = myCamera->Eye();
+  gp_Pln aCamPln (aCamEye, aCamDir);
+
+  Standard_Real aModelMinDist   = RealLast();
+  Standard_Real aModelMaxDist   = RealFirst();
+  Standard_Real aGraphicMinDist = RealLast();
+  Standard_Real aGraphicMaxDist = RealFirst();
+
+  const gp_XYZ& anAxialScale = myCamera->AxialScale();
+
+  // Get minimum and maximum distances to the eye plane
+  for (Standard_Integer aPntIt = 0; aPntIt < 16; ++aPntIt)
   {
-    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);
+    gp_Pnt aMeasurePnt = aPntsToMeasure[aPntIt];
 
-    MyView->Projects (Xmin, Ymin, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+    if (Abs (aMeasurePnt.X()) > aLim || Abs (aMeasurePnt.Y()) > aLim || Abs (aMeasurePnt.Z()) > aLim)
+    {
+      continue;
+    }
 
-    MyView->Projects (Xmax, Ymin, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+    aMeasurePnt = gp_Pnt (aMeasurePnt.X() * anAxialScale.X(),
+                          aMeasurePnt.Y() * anAxialScale.Y(),
+                          aMeasurePnt.Z() * anAxialScale.Z());
 
-    MyView->Projects (Xmax, Ymin, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+    Standard_Real aDistance = aCamPln.Distance (aMeasurePnt);
 
-    MyView->Projects (Xmax, Ymax, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+    // Check if the camera is intruded into the scene
+    if (aCamDir.IsOpposite (gp_Vec (aCamEye, aMeasurePnt), M_PI * 0.5))
+    {
+      aDistance *= -1;
+    }
 
-    MyView->Projects (Xmin, Ymax, Zmax, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+    Standard_Real& aChangeMinDist = aPntIt >= 8 ? aGraphicMinDist : aModelMinDist;
+    Standard_Real& aChangeMaxDist = aPntIt >= 8 ? aGraphicMaxDist : aModelMaxDist;
+    aChangeMinDist = Min (aDistance, aChangeMinDist);
+    aChangeMaxDist = Max (aDistance, aChangeMaxDist);
+  }
 
-    MyView->Projects (Xmin, Ymax, Zmin, U, V, W);
-    Umin = Min (U, Umin); Umax = Max (U, Umax);
-    Vmin = Min (V, Vmin); Vmax = Max (V, Vmax);
+  // Compute depth of bounding box center
+  Standard_Real aMidDepth  = (aGraphicMinDist + aGraphicMaxDist) * 0.5;
+  Standard_Real aHalfDepth = (aGraphicMaxDist - aGraphicMinDist) * 0.5;
 
-    DxvNew = Abs (Umax - Umin);
-    DyvNew = Abs (Vmax - Vmin);
+  // 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);
 
-    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
+  // Compute enlarged or shrank near and far z ranges
+  Standard_Real aZNear = aMidDepth - aHalfDepth * theScaleFactor;
+  Standard_Real aZFar  = aMidDepth + aHalfDepth * theScaleFactor;
+  aZNear              -= Abs (aZNear) * aPrecision;
+  aZFar               += Abs (aZFar)  * aPrecision;
+
+  if (!myCamera->IsOrthographic())
+  {
+    if (aZFar >= aPrecision)
     {
-      // 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;
-      }
-    }
+      // To avoid numeric errors... (See comments in the beginning of the method).
+      // Choose between model distance and graphical distance, as the model boundaries
+      // might be infinite if all structures have infinite flag.
+      const Standard_Real aGraphicDepth = aGraphicMaxDist >= aGraphicMinDist
+        ? aGraphicMaxDist - aGraphicMinDist : RealLast();
 
-    // new scene center
-    Xrp = 0.5 * (Umin + Umax);
-    Yrp = 0.5 * (Vmin + Vmax);
+      const Standard_Real aModelDepth = aModelMaxDist >= aModelMinDist
+        ? aModelMaxDist - aModelMinDist : RealLast();
 
-    // 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);
+      const Standard_Real aMinDepth = Min (aModelDepth, aGraphicDepth);
+      const Standard_Real aZTolerance =
+        Max (Abs (aMinDepth) * aPrecision, aPrecision);
 
-    if (MyType != V3d_PERSPECTIVE)
+      if (aZNear < aZTolerance)
+      {
+        aZNear = aZTolerance;
+      }
+    }
+    else // aZFar < aPrecision - Invalid case when both ZNear and ZFar are negative
     {
-      // center the view
-      MyProjReferencePoint.SetCoord (Xrp, Yrp, Zrp);
-      MyViewMapping.SetProjectionReferencePoint (MyProjReferencePoint);
+      aZNear = aPrecision;
+      aZFar  = aPrecision * 2.0;
     }
-    MyView->SetViewMapping (MyViewMapping);
   }
 
-  if (FitZ)
-  {
-    ZFitAll (Zmargin);
-#ifdef IMP020300
-  }
-  else
-  {
-    ImmediateUpdate();
-#endif
-  }
-#ifdef IMP020300
-  if (!myImmediateUpdate && update)
+  // If range is too small
+  if (aZFar < (aZNear + Abs (aZFar) * aPrecision))
   {
-    Update();
-  }
-#endif
-}
-
-void V3d_View::ZFitAll(const Standard_Real Coef)
-{
-  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() ;
-
-  if( MyType == V3d_PERSPECTIVE ) {
-    ImmediateUpdate();
-    return ;
-  }
-
-  if( (Nstruct <= 0) || (Coef < 0.) ) {
-    ImmediateUpdate();
-    return ;
+    aZFar = aZNear + Abs (aZFar) * aPrecision;
   }
 
-  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 ;
-    }
+  myCamera->SetZRange (aZNear, aZFar);
 
-    // 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();
+  ImmediateUpdate();
 }
 
+//=============================================================================
+//function : DepthFitAll
+//purpose  :
+//=============================================================================
 void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect,
                            const Quantity_Coefficient 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() ;
 
-  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.;
@@ -1939,280 +1799,449 @@ 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)
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
+void V3d_View::FitAll(const Standard_Real theMinXv,
+                      const Standard_Real theMinYv,
+                      const Standard_Real theMaxXv,
+                      const Standard_Real theMaxYv)
 {
-  FitAll(MyWindow,Xmin,Ymin,Xmax,Ymax);
-#ifndef IMP020300
-  ImmediateUpdate();
-#endif
+  FitAll (MyWindow, theMinXv, theMinYv, theMaxXv, theMaxYv);
 }
 
-void V3d_View::WindowFitAll(const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax)
+//=============================================================================
+//function : WindowFitAll
+//purpose  :
+//=============================================================================
+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)
+//=======================================================================
+//function : WindowFit
+//purpose  :
+//=======================================================================
+void V3d_View::WindowFit (const Standard_Integer theMinXp,
+                          const Standard_Integer theMinYp,
+                          const Standard_Integer theMaxXp,
+                          const Standard_Integer theMaxYp)
 {
-  Standard_Real x1,y1,x2,y2;
-  Convert(Xmin,Ymin,x1,y1);
-  Convert(Xmax,Ymax,x2,y2);
-  FitAll(x1,y1,x2,y2);
-}
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-void V3d_View::SetViewMapping(const Visual3d_ViewMapping& VM)
-{
-  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;
+  if (!myCamera->IsOrthographic())
+  {
+    // normalize view coordiantes
+    Standard_Integer aWinWidth, aWinHeight;
+    MyWindow->Size (aWinWidth, aWinHeight);
+
+    // z coordinate of camera center
+    Standard_Real aDepth = myCamera->Project (myCamera->Center()).Z();
+
+    // 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;
+
+    // compute camera panning
+    gp_Pnt aScreenCenter (0.0, 0.0, aDepth);
+    gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth);
+    gp_Pnt aPanTo = myCamera->ConvertProj2View (aFitCenter);
+    gp_Pnt aPanFrom = myCamera->ConvertProj2View (aScreenCenter);
+    gp_Vec aPanVec (aPanFrom, aPanTo);
+
+    // compute section size
+    gp_Pnt aFitTopRight (aUMax, aVMax, aDepth);
+    gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth);
+    gp_Pnt aViewBotLeft = myCamera->ConvertProj2View (aFitBotLeft);
+    gp_Pnt aViewTopRight = myCamera->ConvertProj2View (aFitTopRight);
+
+    Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X();
+    Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y();
+
+    Translate (myCamera, aPanVec.X(), -aPanVec.Y());
+    Scale (myCamera, 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);
+  }
+
+  SetImmediateUpdate (wasUpdateEnabled);
 
-  MyView->SetViewMapping(MyViewMapping) ;
   ImmediateUpdate();
 }
 
+//=======================================================================
+//function : SetViewMappingDefault
+//purpose  :
+//=======================================================================
 void V3d_View::SetViewMappingDefault()
 {
-  MyView->SetViewMapping(MyViewMapping) ;
   MyView->SetViewMappingDefault();
+
   ImmediateUpdate();
 }
 
+//=======================================================================
+//function : ResetViewMapping
+//purpose  :
+//=======================================================================
 void V3d_View::ResetViewMapping()
 {
   MyView->ViewMappingReset();
-  MyViewMapping = MyView->ViewMapping() ;
-#ifdef IMP020300
-  ZFitAll (Zmargin);
+
   Update();
-#else
-  ImmediateUpdate();
-#endif
 }
 
+//=======================================================================
+//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
+{
+  Graphic3d_Vertex aVrp;
+  Standard_Real anX, anY, aZ;
+  Convert (Xp, Yp, anX, anY, aZ);
+  aVrp.SetCoord (anX, anY, aZ);
+
+  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;
+  }
+}
+
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
 Standard_Real V3d_View::Convert(const Standard_Integer Vp) const
 {
-  Standard_Real Umin,Umax,Vmin,Vmax,Dxv,Vv ;
-  Standard_Integer Dxw,Dyw ;
+  Standard_Integer aDxw, aDyw ;
 
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+
+  MyWindow->Size (aDxw, aDyw);
+  Standard_Real aValue;
 
-  MyWindow->Size(Dxw,Dyw);
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Dxv = Umax - Umin ;
-  Vv = Dxv*(Standard_Real)Vp/(Standard_Real)Dxw ;
+  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw;
 
-  return Vv ;
+  return aValue;
 }
 
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xv, Standard_Real& Yv) const
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+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 ;
+  Standard_Integer aDxw, aDyw;
 
-  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+
+  MyWindow->Size (aDxw, aDyw);
 
-  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 ;
+  gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0);
+  aPoint = myCamera->ConvertProj2View (aPoint);
+
+  Xv = aPoint.X();
+  Yv = aPoint.Y();
 }
 
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
 Standard_Integer V3d_View::Convert(const Standard_Real Vv) const
 {
-  V3d_UnMapped_Raise_if!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
 
-  Standard_Integer Dxw, Dyw;
-  MyWindow->Size(Dxw,Dyw);
+  Standard_Integer aDxw, aDyw;
+  MyWindow->Size (aDxw, aDyw);
 
-  Standard_Real Umin,Umax,Vmin,Vmax;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Standard_Real Dxv = Umax - Umin;
-  return RealToInt ( Dxw * Vv / Dxv );
+  gp_Pnt aViewDims = myCamera->ViewDimensions();
+  Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X()));
+
+  return aValue;
 }
 
-void V3d_View::Convert(const Standard_Real Xv, const Standard_Real Yv, Standard_Integer& Xp, Standard_Integer& Yp) const
+//=======================================================================
+//function : Convert
+//purpose  :
+//=======================================================================
+void V3d_View::Convert(const Standard_Real Xv,
+                       const Standard_Real Yv,
+                       Standard_Integer& Xp,
+                       Standard_Integer& Yp) const
 {
-  V3d_UnMapped_Raise_if!MyView->IsDefined(), "view has no window");
+  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
 
-  Standard_Integer Dxw, Dyw;
-  MyWindow->Size(Dxw,Dyw);
+  Standard_Integer aDxw, aDyw;
+  MyWindow->Size (aDxw, aDyw);
 
-  Standard_Real Umin,Umax,Vmin,Vmax;
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Standard_Real Dxv = Umax - Umin;
-  Standard_Real Dyv = Vmax - Vmin;
+  gp_Pnt aPoint (Xv, Yv, 0.0);
+  aPoint = myCamera->ConvertView2Proj (aPoint);
+  aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0);
 
-  // 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);
+  Xp = RealToInt (aPoint.X());
+  Yp = RealToInt (aPoint.Y());
 }
 
-void V3d_View::Convert(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& X, Standard_Real& Y, Standard_Real& Z) 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
 {
-  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
-}
+  V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window");
+  Standard_Integer aHeight, aWidth;
+  MyWindow->Size (aWidth, aHeight);
 
-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
-{
-  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_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;
 
-#ifdef IMP240100
-void V3d_View::ConvertToGrid(const Standard_Integer Xp, const Standard_Integer Yp, Standard_Real& Xg, Standard_Real& Yg, Standard_Real& Zg) const
-{
-  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) ;
-}
+  gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+
+  X = aResult.X();
+  Y = aResult.Y();
+  Z = aResult.Z();
+
+  Graphic3d_Vertex aVrp;
+  aVrp.SetCoord (X, Y, Z);
 
-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 Vrp(X,Y,Z) ;
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(Xg,Yg,Zg) ;
-  } else {
-    Xg = X; Yg = Y; Zg = Z;
+    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
+    aNewVrp.Coord (X, Y, Z) ;
   }
 }
-#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 : ConvertWithProj
+//purpose  :
+//=======================================================================
+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
 {
-  Graphic3d_Vertex Vrp ;
-  Vrp = (MyViewer->Viewer())->ConvertCoord(MyWindow,Xp,Yp) ;
-  Vrp.Coord(X,Y,Z) ;
+  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 = myCamera->UnProject (gp_Pnt (anX, anY, aZ));
+
+  X = aResult.X();
+  Y = aResult.Y();
+  Z = aResult.Z();
+
+  Graphic3d_Vertex aVrp;
+  aVrp.SetCoord (X, Y, Z);
+
+  aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0));
+
+  Dx = X - aResult.X();
+  Dy = Y - aResult.Y();
+  Dz = Z - aResult.Z();
+
   if( MyViewer->Grid()->IsActive() ) {
-    Graphic3d_Vertex NewVrp = Compute(Vrp) ;
-    NewVrp.Coord(X,Y,Z) ;
+    Graphic3d_Vertex aNewVrp = Compute (aVrp) ;
+    aNewVrp.Coord (X, Y, Z) ;
   }
 }
-#endif
 
-#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
+//=======================================================================
+//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
 {
-  Graphic3d_Vertex Vrp(X,Y,Z) ;
-  (MyViewer->Viewer())->ConvertCoord(MyWindow,Vrp,Xp,Yp) ;
+  V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window");
+  Standard_Integer aHeight, aWidth;
+  MyWindow->Size (aWidth, aHeight);
+
+  gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z));
+
+  Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth);
+  Yp = RealToInt ((aPoint.Y() + 1) * 0.5 * aHeight);
 }
 
-void V3d_View::Project(const Standard_Real X, const Standard_Real Y, const Standard_Real Z, Standard_Real &Xp, Standard_Real &Yp) const
+//=======================================================================
+//function : Project
+//purpose  :
+//=======================================================================
+void V3d_View::Project(const Standard_Real X,
+                       const Standard_Real Y,
+                       const Standard_Real Z,
+                       Standard_Real &Xp,
+                       Standard_Real &Yp) const
 {
-  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);
-  }
+  Standard_Real Zp;
+  MyView->Projects (X, Y, Z, Xp, Yp, Zp);
 }
 
-void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type,Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const
+//=======================================================================
+//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) ;
 }
 
+//=======================================================================
+//function : BackgroundColor
+//purpose  :
+//=======================================================================
 Quantity_Color V3d_View::BackgroundColor() const
 {
   return MyBackground.Color() ;
 }
 
+//=======================================================================
+//function : GradientBackgroundColors
+//purpose  :
+//=======================================================================
 void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const
 {
   MyGradientBackground.Colors(Color1, Color2);
 }
 
+//=======================================================================
+//function : GradientBackground
+//purpose  :
+//=======================================================================
 Aspect_GradientBackground V3d_View::GradientBackground() const
 {
    return MyGradientBackground;
 }
 
+//=======================================================================
+//function : Scale
+//purpose  :
+//=======================================================================
 Standard_Real V3d_View::Scale() const
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Dxv ;
-  Visual3d_ViewMapping VMD = MyView->ViewMappingDefault() ;
-  Standard_Real S = 0. ;
+  Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera();
 
-  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 ;
-}
+  Standard_Real aCameraScale;
 
-void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
-{
-  MyViewOrientation.AxialScale( Sx, Sy, Sz );
+  // Strange behavior for the sake of compatibility.
+  if (!aDefaultCamera.IsNull())
+  {
+    Standard_Real aDefaultScale = aDefaultCamera->Scale();
+    aCameraScale = aDefaultScale / myCamera->Scale();
+  } 
+  else
+  {
+    aCameraScale = myCamera->Scale();
+  }
+
+  return aCameraScale;
 }
 
-void V3d_View::Center(Standard_Real& Xc, Standard_Real& Yc) const
+//=======================================================================
+//function : AxialScale
+//purpose  :
+//=======================================================================
+void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const
 {
-  Standard_Real Umin,Vmin,Umax,Vmax ;
-
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Xc = (Umin + Umax)/2. ;
-  Yc = (Vmin + Vmax)/2. ;
+  gp_Pnt anAxialScale = myCamera->AxialScale();
+  Sx = anAxialScale.X();
+  Sy = anAxialScale.Y();
+  Sz = anAxialScale.Z();
 }
 
+//=======================================================================
+//function : Size
+//purpose  :
+//=======================================================================
 void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const
 {
-  Standard_Real Umin,Vmin,Umax,Vmax ;
+  gp_Pnt aViewDims = myCamera->ViewDimensions();
 
-  MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
-  Width = Umax - Umin ;
-  Height = Vmax - Vmin ;
+  Width = aViewDims.X();
+  Height = aViewDims.Y();
 }
 
+//=======================================================================
+//function : ZSize
+//purpose  :
+//=======================================================================
 Standard_Real V3d_View::ZSize() const
 {
-  Standard_Real Wmin,Wmax,Depth ;
+  gp_Pnt aViewDims = myCamera->ViewDimensions();
 
-  Wmax = MyViewMapping.FrontPlaneDistance() ;
-  Wmin = MyViewMapping.BackPlaneDistance() ;
-  Depth = 2. * Max(Wmin,Wmax) ;
-  return (Depth) ;
+  return aViewDims.Z();
 }
 
-Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real& Vmin, Standard_Real& Umax, Standard_Real& Vmax) const
+//=======================================================================
+//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 ;
@@ -2251,7 +2280,16 @@ 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() ;
@@ -2263,10 +2301,13 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, Standard_Real& Ymin, Stan
   return Nstruct ;
 }
 
+//=======================================================================
+//function : Gravity
+//purpose  :
+//=======================================================================
 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_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax;
   Standard_Integer Nstruct,Npoint ;
   Graphic3d_MapOfStructure MySetOfStructures;
 
@@ -2275,50 +2316,44 @@ Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_
 
   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 ;
-          }
+  for (; MyIterator.More(); MyIterator.Next())
+  {
+    const Handle(Graphic3d_Structure)& aStruct = MyIterator.Key();
+    if (!aStruct->IsEmpty())
+    {
+      aStruct->MinMaxValues (Xmin, Ymin, Zmin, Xmax, Ymax, Zmax);
+
+      // Check bounding box for validness
+      Standard_Real aLim = (ShortRealLast() - 1.0);
+      if (Abs (Xmin) > aLim || Abs (Ymin) > aLim || Abs (Zmin) > aLim ||
+          Abs (Xmax) > aLim || Abs (Ymax) > aLim || Abs (Zmax) > aLim)
+      {
+        continue;
+      }
+
+      // use camera projection to find gravity point
+      gp_Pnt aPnts[8] = { 
+        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 < 8; ++aPntIt)
+      {
+        const gp_Pnt& aBndPnt = aPnts[aPntIt];
+
+        gp_Pnt aProjected = myCamera->Project (aBndPnt);
+        const Standard_Real& U = aProjected.X();
+        const Standard_Real& V = aProjected.Y();
+        if (Abs(U) <= 1.0 && Abs(V) <= 1.0)
+        {
+          Npoint++;
+          X += aBndPnt.X();
+          Y += aBndPnt.Y();
+          Z += aBndPnt.Z();
         }
+      }
     }
   }
   if( Npoint > 0 ) {
@@ -2328,115 +2363,129 @@ Standard_Integer V3d_View::Gravity(Standard_Real& X, Standard_Real& Y, Standard_
   return Nstruct ;
 }
 
+//=======================================================================
+//function : Eye
+//purpose  :
+//=======================================================================
 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 ;
-
-  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;
+  gp_Pnt aCameraEye = myCamera->Eye();
+  X = aCameraEye.X();
+  Y = aCameraEye.Y();
+  Z = aCameraEye.Z();
 }
 
+//=============================================================================
+//function : FocalReferencePoint
+//purpose  :
+//=============================================================================
 void V3d_View::FocalReferencePoint(Standard_Real& X, Standard_Real& Y,Standard_Real& Z) const
 {
-  Graphic3d_Vertex PRP,VRPoint;
-  Graphic3d_Vector VRPlane;
-  Standard_Real FPD,Xprp,Yprp,Zprp;
-  Standard_Real Xvrp,Yvrp,Zvrp,DXvrp,DYvrp,DZvrp;
-
-  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;
-  }
-  else Eye(X,Y,Z);
+  Eye (X,Y,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 : 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);
   }
 }
 
+//=============================================================================
+//function : Depth
+//purpose  :
+//=============================================================================
 Standard_Real V3d_View::Depth() const
 {
-  Graphic3d_Vertex Prp ;
-  Standard_Real Xrp,Yrp,Zrp ;
-
-  Prp = MyViewMapping.ProjectionReferencePoint() ;
-  Prp.Coord(Xrp,Yrp,Zrp) ;
-  return Zrp ;
+  return myCamera->Distance();
 }
 
+//=============================================================================
+//function : Proj
+//purpose  :
+//=============================================================================
 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) ;
+  gp_Dir aCameraDir = myCamera->Direction().Reversed();
+  Dx = aCameraDir.X();
+  Dy = aCameraDir.Y();
+  Dz = aCameraDir.Z();
 }
 
+//=============================================================================
+//function : At
+//purpose  :
+//=============================================================================
 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) ;
+  gp_Pnt aCameraCenter = myCamera->Center();
+  X = aCameraCenter.X();
+  Y = aCameraCenter.Y();
+  Z = aCameraCenter.Z();
 }
 
+//=============================================================================
+//function : Up
+//purpose  :
+//=============================================================================
 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) ;
+  gp_Dir aCameraUp = myCamera->Up();
+  Vx = aCameraUp.X();
+  Vy = aCameraUp.Y();
+  Vz = aCameraUp.Z();
 }
 
+//=============================================================================
+//function : Twist
+//purpose  :
+//=============================================================================
 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 ;
+  Graphic3d_Vector 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) ;
+  gp_Dir aReferencePlane (myCamera->Direction().Reversed());
+  gp_Dir anUp;
+
+  Proj(Xpn,Ypn,Zpn);
+  anUp = gp_Dir (0.,0.,1.) ;
+  TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ;
   if( !TheStatus ) {
-    Vup.SetCoord(0.,1.,0.) ;
-    TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
+    anUp = gp_Dir (0.,1.,0.) ;
+    TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ;
   }
   if( !TheStatus ) {
-    Vup.SetCoord(1.,0.,0.) ;
-    TheStatus = ScreenAxis(Vpn,Vup,Xaxis,Yaxis,Zaxis) ;
+    anUp = gp_Dir (1.,0.,0.) ;
+    TheStatus = ScreenAxis (aReferencePlane, anUp,Xaxis,Yaxis,Zaxis) ;
   }
   Yaxis.Coord(X0,Y0,Z0) ;
-  Vup = MyViewOrientation.ViewReferenceUp() ;
-  Vup.Coord(Xup,Yup,Zup) ;
+
+  Up(Xup,Yup,Zup) ;
   /* Compute Cross Vector From Up & Origin */
   pvx = Y0*Zup - Z0*Yup ;
   pvy = Z0*Xup - X0*Zup ;
@@ -2456,24 +2505,40 @@ Standard_Real V3d_View::Twist() const
   return angle ;
 }
 
+//=============================================================================
+//function : ShadingModel
+//purpose  :
+//=============================================================================
 V3d_TypeOfShadingModel V3d_View::ShadingModel() const
 {
   V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ;
   return SM ;
 }
 
+//=============================================================================
+//function : SurfaceDetail
+//purpose  :
+//=============================================================================
 V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const
 {
   V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ;
   return SM ;
 }
 
-Handle_Graphic3d_TextureEnv V3d_View::TextureEnv() const
+//=============================================================================
+//function : TextureEnv
+//purpose  :
+//=============================================================================
+Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const
 {
   Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ;
   return SM ;
 }
 
+//=============================================================================
+//function : Visualization
+//purpose  :
+//=============================================================================
 V3d_TypeOfVisualization V3d_View::Visualization() const
 {
   V3d_TypeOfVisualization V =
@@ -2481,279 +2546,128 @@ V3d_TypeOfVisualization V3d_View::Visualization() const
   return V ;
 }
 
+//=============================================================================
+//function : Antialiasing
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::Antialiasing() const
 {
   Standard_Boolean A = MyViewContext.AliasingIsOn() ;
   return A ;
 }
 
+//=============================================================================
+//function : Viewer
+//purpose  :
+//=============================================================================
 Handle(V3d_Viewer) V3d_View::Viewer() const
 {
   return MyViewer ;
 }
 
+//=============================================================================
+//function : IfWindow
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::IfWindow() const
 {
   Standard_Boolean TheStatus = MyView->IsDefined() ;
   return TheStatus ;
 }
 
+//=============================================================================
+//function : Window
+//purpose  :
+//=============================================================================
 Handle(Aspect_Window) V3d_View::Window() const
 {
   return MyWindow;
 }
 
+//=============================================================================
+//function : Type
+//purpose  :
+//=============================================================================
 V3d_TypeOfView V3d_View::Type() const
 {
-  return (MyType) ;
+  return myCamera->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE;
 }
 
+//=============================================================================
+//function : SetFocale
+//purpose  :
+//=============================================================================
 void V3d_View::SetFocale( const Standard_Real focale )
 {
-  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 ;
+  if (myCamera->IsOrthographic())
+  {
+    return;
   }
-  MyViewMapping.SetViewPlaneDistance(ViewPlane) ;
-  MyView->SetViewMapping(MyViewMapping) ;
 
-  ImmediateUpdate();
-}
+  Standard_Real aFOVyRad = ATan (focale / (myCamera->Distance() * 2.0));
 
-Standard_Real V3d_View::Focale( ) const
-{
-  Standard_Real Xrp,Yrp,Zrp,ViewPlane,FrontPlane ;
-  Standard_Real focale = 0.0 ;
-  Graphic3d_Vertex Prp ;
+  myCamera->SetFOVy (aFOVyRad * (360 / M_PI));
 
-  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 ;
-    }
-  }
-  return (focale) ;
+  ImmediateUpdate();
 }
 
-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 : Focale
+//purpose  :
+//=============================================================================
+Standard_Real V3d_View::Focale() const
 {
-  Standard_Real Umin,Vmin,Umax,Vmax,Xrp,Yrp,Zrp;
-
-  V3d_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. ;
+  if (myCamera->IsOrthographic())
+  {
+    return 0.0;
   }
-  MyProjReferencePoint.SetCoord(Xrp,Yrp,Zrp) ;
-  MyViewMapping.SetProjectionReferencePoint(MyProjReferencePoint);
 
-  MyView->SetViewMapping(MyViewMapping) ;
-  //  SetZSize(0.);
-  ImmediateUpdate();
+  return myCamera->Distance() * 2.0 * Tan(myCamera->FOVy() * M_PI / 360.0);
 }
 
+//=============================================================================
+//function : View
+//purpose  :
+//=============================================================================
 Handle(Visual3d_View) V3d_View::View() const
 {
   return MyView ;
 }
 
-Visual3d_ViewMapping V3d_View::ViewMapping() const
-{
-  return MyViewMapping;
-}
-
-Visual3d_ViewOrientation V3d_View::ViewOrientation() const
-{
-  return MyViewOrientation;
-}
-
-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 ;
-}
-
-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 ;
-
-  for( I=LR ; I<=UR ; I++ ) {
-    for( J=LC ; J<=UC ; J++ ) Matrix(I,J) = 0. ;
-  }
-  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_Integer llr = Left.LowerRow ();
-  Standard_Integer llc = Left.LowerCol ();
-  Standard_Integer luc = Left.UpperCol ();
-
-  Standard_Integer rlr = Right.LowerRow ();
-  Standard_Integer rur = Right.UpperRow ();
-  Standard_Integer rlc = Right.LowerCol ();
-
-  Standard_Integer mlr = Matrix.LowerRow ();
-  Standard_Integer mur = Matrix.UpperRow ();
-  Standard_Integer mlc = Matrix.LowerCol ();
-  Standard_Integer muc = Matrix.UpperCol ();
-
-  TColStd_Array2OfReal Result (mlr, mur, mlc, muc);
-
-  InitMatrix (Result);
-
-  // Left et Right incompatibles
-  if (luc - llc + 1 != rur - rlr + 1)
-    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++;
-  }
-
-  for (i=mlr; i<=mur; i++)
-    for (j=mlc; j<=muc; j++)
-      Matrix (i, j) = Result (i, j);
-
+//=============================================================================
+//function : ScreenAxis
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::ScreenAxis( const gp_Dir &Vpn, const gp_Dir &Vup, Graphic3d_Vector &Xaxe, Graphic3d_Vector &Yaxe, Graphic3d_Vector &Zaxe)
+{
+  Standard_Real Xpn, Ypn, Zpn, Xup, Yup, Zup;
+  Standard_Real dx1, dy1, dz1, xx, yy, zz;
+
+  Xpn = Vpn.X(); Ypn = Vpn.Y(); Zpn = Vpn.Z();
+  Xup = Vup.X(); Yup = Vup.Y(); Zup = Vup.Z();
+  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(); 
+
+  Zaxe.SetCoord (Xpn, Ypn, Zpn);
+  Zaxe.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);
-}
-
-/*----------------------------------------------------------------------*/
-
+//=============================================================================
+//function : TrsPoint
+//purpose  :
+//=============================================================================
 Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Array2OfReal &Matrix )
 {
   Graphic3d_Vertex PP ;
@@ -2765,7 +2679,7 @@ Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Ar
   ur    = Matrix.UpperRow ();
   lc    = Matrix.LowerCol ();
   uc    = Matrix.UpperCol ();
-  if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
+  if ((ur - lr + 1 != 4) || (uc - lc + 1 != 4) ) {
     P.Coord(X,Y,Z) ;
     PP.SetCoord(X,Y,Z) ;
     return PP ;
@@ -2783,151 +2697,140 @@ Graphic3d_Vertex V3d_View::TrsPoint( const Graphic3d_Vertex &P, const TColStd_Ar
   return PP ;
 }
 
-Graphic3d_Vector V3d_View::TrsPoint( const Graphic3d_Vector& V, const TColStd_Array2OfReal& Matrix )
-{
-  Graphic3d_Vector VV ;
-  Standard_Real X,Y,Z,XX,YY,ZZ ;
-
-  // 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 ;
-}
-
-void V3d_View::Pan(const Standard_Integer Dx, const Standard_Integer Dy,const Quantity_Factor aZoomFactor)
+//=======================================================================
+//function : Pan
+//purpose  :
+//=======================================================================
+void V3d_View::Pan (const Standard_Integer theDXp,
+                    const Standard_Integer theDYp,
+                    const Quantity_Factor  theZoomFactor,
+                    const Standard_Boolean theToStart)
 {
-  Panning(Convert(Dx),Convert(Dy),aZoomFactor,Standard_True);
+  Panning (Convert (theDXp), Convert (theDYp), theZoomFactor, theToStart);
 }
 
-void V3d_View::Zoom (const Standard_Integer X1,
-                     const Standard_Integer Y1,
-                     const Standard_Integer X2,
-                     const Standard_Integer Y2)
+//=======================================================================
+//function : Panning
+//purpose  :
+//=======================================================================
+void V3d_View::Panning (const Standard_Real theDXv,
+                        const Standard_Real theDYv,
+                        const Quantity_Factor theZoomFactor,
+                        const Standard_Boolean theToStart)
 {
+  Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor");
 
-  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);
+  if (theToStart)
+  {
+    myCamStartOpEye = myCamera->Eye();
+    myCamStartOpCenter = myCamera->Center();
   }
+
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
+
+  gp_Pnt aViewDims = myCamera->ViewDimensions();
+
+  myCamera->SetEye (myCamStartOpEye);
+  myCamera->SetCenter (myCamStartOpCenter);
+  Translate (myCamera, -theDXv, -theDYv);
+  Scale (myCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor);
+
+  SetImmediateUpdate (wasUpdateEnabled);
+
+  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;
+  MyZoomAtPointX = theXp;
+  MyZoomAtPointY = theYp;
 }
 
-// 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)
+//=======================================================================
+//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;
-    V3d_BadValue_Raise_if( dzoom <= 0.,"V3d_View::ZoomAtPoint, bad coefficient");
-
-    Standard_Real Umin,Vmin,Umax,Vmax;
-    MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax);
+  Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False);
 
-    MyXwindowCenter = (Umin + Umax) / 2.0;
-    MyYwindowCenter = (Vmin + Vmax) / 2.0;
-    MyWindowWidth = Abs(Umax - Umin);
-    MyWindowHeight = Abs(Vmax - Vmin);
+  // 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;
 
-    // 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;
+  V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient");
 
-    Standard_Real Dxv = MyWindowWidth / coef;
-    Standard_Real Dyv = MyWindowHeight / coef;
+  Standard_Real aViewWidth  = myCamera->ViewDimensions().X();
+  Standard_Real aViewHeight = myCamera->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);
+  V3d_Coordinate aDxv = aZoomAtPointXv / aCoef;
+  V3d_Coordinate aDyv = aZoomAtPointYv / aCoef;
 
-    Xrp = MyXwindowCenter - Dxv;
-    Yrp = MyYwindowCenter - Dyv;
+  myCamera->SetScale (myCamera->Scale() / aCoef);
+  Translate (myCamera, 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)
@@ -2944,51 +2847,44 @@ void V3d_View::AxialScale (const Standard_Integer Dx,
   }
 }
 
+//=============================================================================
+//function : FitAll
+//purpose  :
+//=============================================================================
 void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow,
                       const Standard_Real Xmin,
                       const Standard_Real Ymin,
                       const Standard_Real Xmax,
                       const Standard_Real Ymax)
 {
+  Standard_Integer aWinWidth, aWinHeight;
+  aWindow->Size (aWinWidth, aWinHeight);
 
-  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 ;
-
-  V3d_BadValue_Raise_if( (Xmin == Xmax) || (Ymin == Ymax) ,
-    "V3d_View::FitAll, Window Size is NULL");
-
-  MyProjReferencePoint = MyViewMapping.ProjectionReferencePoint() ;
-  MyProjReferencePoint.Coord(Xrp,Yrp,Zrp) ;
-  aWindow->Size(Xpixel,Ypixel);
-  DxvOld = Xpixel; DyvOld = Ypixel;
-
-  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 ;
+  Standard_Real aWinAspect = (Standard_Real)aWinWidth / aWinHeight;
+  Standard_Real aFitSizeU  = Abs (Xmax - Xmin);
+  Standard_Real aFitSizeV  = Abs (Ymax - Ymin);
+  Standard_Real aFitAspect = aFitSizeU / aFitSizeV;
+  if (aFitAspect >= aWinAspect)
+  {
+    aFitSizeV = aFitSizeU / aWinAspect;
   }
-  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);
+  else
+  {
+    aFitSizeU = aFitSizeV * aWinAspect;
   }
-  MyView->SetViewMapping(MyViewMapping) ;
-#ifdef IMP020300
-  Update();
-#else
+
+  myCamera->SetAspect (aWinAspect);
+  Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5);
+  Scale (myCamera, aFitSizeU, aFitSizeV);
+  AutoZFit();
+
   ImmediateUpdate();
-#endif
 }
 
+//=============================================================================
+//function : StartRotation
+//purpose  :
+//=============================================================================
 #ifdef IMP250900
 static Standard_Boolean zRotation = Standard_False;
 #endif
@@ -2996,7 +2892,6 @@ void V3d_View::StartRotation(const Standard_Integer X,
                              const Standard_Integer Y,
                              const Quantity_Ratio zRotationThreshold)
 {
-
   sx = X; sy = Y;
   Standard_Real x,y;
   Size(x,y);
@@ -3017,10 +2912,13 @@ void V3d_View::StartRotation(const Standard_Integer X,
 
 }
 
+//=============================================================================
+//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);
@@ -3053,95 +2951,106 @@ void V3d_View::Rotation(const Standard_Integer X,
 #endif
 }
 
-void V3d_View :: SetComputedMode ( const Standard_Boolean aMode )
+//=============================================================================
+//function : SetComputedMode
+//purpose  :
+//=============================================================================
+void V3d_View::SetComputedMode (const Standard_Boolean aMode)
 {
-  if( aMode ) {
-    if( myComputedMode ) {
-      MyView -> SetComputedMode ( Standard_True );
-      Update ();
+  if (aMode)
+  {
+    if (myComputedMode)
+    {
+      MyView->SetComputedMode (Standard_True);
+      Update();
     }
-  } else {
-    MyView -> SetComputedMode ( Standard_False );
-    Update ();
+  } 
+  else 
+  {
+    MyView->SetComputedMode (Standard_False);
+    Update();
   }
 }
 
-Standard_Boolean V3d_View :: ComputedMode () const
+//=============================================================================
+//function : ComputedMode
+//purpose  :
+//=============================================================================
+Standard_Boolean V3d_View::ComputedMode() const
 {
-  return MyView -> ComputedMode ();
+  return MyView->ComputedMode();
 }
 
-void V3d_View :: SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
+//=============================================================================
+//function : SetBackFacingModel
+//purpose  :
+//=============================================================================
+void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel)
 {
-  MyView -> SetBackFacingModel ( Visual3d_TypeOfBackfacingModel(aModel) );
+  MyView->SetBackFacingModel (Visual3d_TypeOfBackfacingModel(aModel));
   Redraw();
 }
 
-V3d_TypeOfBackfacingModel V3d_View :: BackFacingModel () const
+//=============================================================================
+//function : BackFacingModel
+//purpose  :
+//=============================================================================
+V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const
 {
   return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ());
 }
 
-Standard_Boolean V3d_View::TransientManagerBeginDraw(const Standard_Boolean DoubleBuffer,const Standard_Boolean RetainMode) const
-{
-  return Visual3d_TransientManager::BeginDraw(MyView,DoubleBuffer,RetainMode);
-}
-
-void V3d_View::TransientManagerClearDraw() const
-{
-  Visual3d_TransientManager::ClearDraw(MyView);
-}
-
-Standard_Boolean V3d_View::TransientManagerBeginAddDraw() const
-{
-  return Visual3d_TransientManager::BeginAddDraw(MyView);
-}
-
 void V3d_View::Init()
 {
   myComputedMode = MyViewer->ComputedMode();
   if( !myComputedMode || !MyViewer->DefaultComputedMode() ) {
     SetComputedMode(Standard_False);
   }
-
-#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
 }
 
+//=============================================================================
+//function : SetPlotter
+//purpose  :
+//=============================================================================
 void V3d_View::SetPlotter(const Handle(Graphic3d_Plotter)& aPlotter)
 {
   MyPlotter = aPlotter;
 }
 
+//=============================================================================
+//function : Plot
+//purpose  :
+//=============================================================================
 void V3d_View::Plot()
 {
   V3d_BadValue_Raise_if( !MyPlotter.IsNull(), "view has no plotter");
   MyView->Plot(MyPlotter);
 }
 
-#include <Aspect.hxx>
-#include <Visual3d_Layer.hxx>
-
-////////////////////////////////////////////////////////////////
+//=============================================================================
+//function : Dump
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::Dump (const Standard_CString      theFile,
                                  const Graphic3d_BufferType& theBufferType)
 {
   Standard_Integer aWinWidth, aWinHeight;
   MyWindow->Size (aWinWidth, aWinHeight);
   Image_AlienPixMap anImage;
+
   return ToPixMap (anImage, aWinWidth, aWinHeight, theBufferType) && anImage.Save (theFile);
 }
 
-////////////////////////////////////////////////////////////////
+//=============================================================================
+//function : ToPixMap
+//purpose  :
+//=============================================================================
 Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
                                      const Standard_Integer      theWidth,
                                      const Standard_Integer      theHeight,
                                      const Graphic3d_BufferType& theBufferType,
-                                     const Standard_Boolean      theIsForceCentred)
+                                     const Standard_Boolean      theToKeepAspect,
+                                     const V3d_StereoDumpOptions theStereoOptions)
 {
   Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView();
 
@@ -3195,51 +3104,48 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
     }
   }
 
-  //szv: save mapping
-  Visual3d_ViewMapping prevMapping = MyView->ViewMapping();
-  Standard_Real Umin, Vmin, Umax, Vmax;
+  Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera();
+
+  aStoreMapping->Copy (myCamera);
 
-  if (theIsForceCentred)
+  if (myCamera->IsStereo())
   {
-    //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 * aFBOVPSizeX) / aFBOVPSizeY;
-    if (newWidth < oldWidth)
-    {
-      Standard_Real newHeight = (oldWidth * aFBOVPSizeY) / aFBOVPSizeX;
-      // Expand height
-      Standard_Real delta = 0.5 * (newHeight - oldHeight);
-      Vmin = PVmin - delta;
-      Vmax = PVmax + delta;
-    }
-    else
+    switch (theStereoOptions)
     {
-      // Expand width
-      Standard_Real delta = 0.5 * (newWidth - oldWidth);
-      Umin = PUmin - delta;
-      Umax = PUmax + delta;
+      case V3d_SDO_MONO :
+        myCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective);
+        break;
+
+      case V3d_SDO_LEFT_EYE :
+        myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye);
+        break;
+
+      case V3d_SDO_RIGHT_EYE :
+        myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye);
+        break;
     }
+  }
+
+  // render immediate structures into back buffer rather than front
+  Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver());
+  const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False);
+
+  const Standard_Boolean toAutoUpdate = myImmediateUpdate;
+  myImmediateUpdate = Standard_False;
+  AutoZFit();
+  myImmediateUpdate = toAutoUpdate;
 
-    //szv: apply expanded mapping
-    MyViewMapping.SetWindowLimit (Umin, Vmin, Umax, Vmax);
-    MyView->SetViewMapping (MyViewMapping);
+  if (theToKeepAspect)
+  {
+    myCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY);
   }
 
-  //workround for rendering list of Over and Under Layers
+  //workaround for rendering list of Over and Under Layers
   if (!MyLayerMgr.IsNull())
   {
     MyLayerMgr->Compute();
   }
 
-  // render immediate structures into back buffer rather than front
-  Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver());
-  const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False);
-
   Redraw();
 
   if (!aDriver.IsNull())
@@ -3247,9 +3153,7 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
     aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode);
   }
 
-  //szv: restore mapping
-  MyViewMapping = prevMapping;
-  MyView->SetViewMapping (prevMapping);
+  myCamera->Copy (aStoreMapping);
 
   Standard_Boolean isSuccess = Standard_True;
 
@@ -3295,3 +3199,216 @@ Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmedia
   myImmediateUpdate = theImmediateUpdate;
   return aPreviousMode;
 }
+
+// =======================================================================
+// function : SetCamera
+// purpose  :
+// =======================================================================
+void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
+{
+  Standard_ASSERT_RAISE (!theCamera.IsNull(), "Void camera is not allowed");
+
+  myCamera = theCamera;
+
+  MyView->SetCamera (theCamera);
+}
+
+// =======================================================================
+// function : GetCamera
+// purpose  :
+// =======================================================================
+const Handle(Graphic3d_Camera)& V3d_View::Camera() const
+{
+  return myCamera;
+}
+
+// =======================================================================
+// function : FitMinMax
+// purpose  : Internal
+// =======================================================================
+Standard_Boolean V3d_View::FitMinMax (const Handle(Graphic3d_Camera)& theCamera,
+                                      const gp_XYZ& theMinCorner,
+                                      const gp_XYZ& theMaxCorner,
+                                      const Standard_Real theMargin,
+                                      const Standard_Real theResolution,
+                                      const Standard_Boolean theToEnlargeIfLine) const
+{
+  // Check bounding box for validness
+  Standard_Real aLim = (ShortRealLast() - 1.0);
+  if (Abs (theMinCorner.X()) > aLim || Abs (theMinCorner.Y()) > aLim || Abs (theMinCorner.Z()) > aLim ||
+      Abs (theMaxCorner.X()) > aLim || Abs (theMaxCorner.Y()) > aLim || Abs (theMaxCorner.Z()) > aLim)
+  {
+    return Standard_False; // bounding box is out of bounds...
+  }
+
+  // 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.
+  Standard_Real aXmin = theMinCorner.X() * theCamera->AxialScale().X();
+  Standard_Real aXmax = theMaxCorner.X() * theCamera->AxialScale().X();
+  Standard_Real aYmin = theMinCorner.Y() * theCamera->AxialScale().Y();
+  Standard_Real aYmax = theMaxCorner.Y() * theCamera->AxialScale().Y();
+  Standard_Real aZmin = theMinCorner.Z() * theCamera->AxialScale().Z();
+  Standard_Real aZmax = theMaxCorner.Z() * theCamera->AxialScale().Z();
+
+  Bnd_Box aBBox;
+  aBBox.Update (aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
+  if (aBBox.IsThin (RealEpsilon()))
+  {
+    return Standard_False; // nothing to fit all
+  }
+
+  gp_Pnt aBBCenter ((aXmin + aXmax) * 0.5, (aYmin + aYmax) * 0.5, (aZmin + aZmax) * 0.5);
+
+  gp_Pln aFrustumLeft;
+  gp_Pln aFrustumRight;
+  gp_Pln aFrustumBottom;
+  gp_Pln aFrustumTop;
+  gp_Pln aFrustumNear;
+  gp_Pln aFrustumFar;
+  theCamera->Frustum (aFrustumLeft, aFrustumRight, aFrustumBottom, aFrustumTop, aFrustumNear, aFrustumFar);
+
+  gp_Dir aCamUp  = theCamera->OrthogonalizedUp();
+  gp_Dir aCamDir = theCamera->Direction();
+  gp_Dir aCamSide = aCamDir ^ aCamUp;
+
+  // 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.
+
+  // Determine normalized projection asymmetry (if any).
+
+  Standard_Real anAssymX = Tan ( aCamSide.Angle (aFrustumLeft.Axis().Direction()))
+                         - Tan (-aCamSide.Angle (aFrustumRight.Axis().Direction()));
+  Standard_Real anAssymY = Tan ( aCamUp.Angle   (aFrustumBottom.Axis().Direction()))
+                         - Tan (-aCamUp.Angle   (aFrustumTop.Axis().Direction()));
+
+  // Determine how far should be the frustum planes placed from center
+  // of bounding box, in order to match the bounding box closely.
+  gp_Pln aMatchSide[6] = {aFrustumLeft, aFrustumRight, aFrustumBottom, aFrustumTop, aFrustumNear, aFrustumFar};
+  Standard_Real aMatchDistance[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
+  for (Standard_Integer anIt = 0; anIt < 6; ++anIt)
+  {
+    const gp_Dir& aPlaneN = aMatchSide[anIt].Axis().Direction();
+
+    gp_Trsf aPlaneTrsf;
+    aPlaneTrsf.SetTransformation (gp_Ax3(), gp_Ax3 (aBBCenter, aPlaneN));
+    Bnd_Box aRelativeBBox = aBBox.Transformed (aPlaneTrsf);
+
+    Standard_Real aDummy = 0.0;
+    Standard_Real aZmin  = 0.0;
+    Standard_Real aZmax  = 0.0;
+    aRelativeBBox.Get (aDummy, aDummy, aZmin, aDummy, aDummy, aZmax);
+    aMatchDistance[anIt] = -aZmin;
+  }
+  // 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)
+
+  aMatchDistance[0] *= Sqrt(1 + Pow (Tan ( aCamSide.Angle (aFrustumLeft.Axis().Direction())),   2.0));
+  aMatchDistance[1] *= Sqrt(1 + Pow (Tan (-aCamSide.Angle (aFrustumRight.Axis().Direction())),  2.0));
+  aMatchDistance[2] *= Sqrt(1 + Pow (Tan ( aCamUp.Angle   (aFrustumBottom.Axis().Direction())), 2.0));
+  aMatchDistance[3] *= Sqrt(1 + Pow (Tan (-aCamUp.Angle   (aFrustumTop.Axis().Direction())),    2.0));
+  aMatchDistance[4] *= Sqrt(1 + Pow (Tan ( aCamDir.Angle  (aFrustumNear.Axis().Direction())),   2.0));
+  aMatchDistance[5] *= Sqrt(1 + Pow (Tan (-aCamDir.Angle  (aFrustumFar.Axis().Direction())),    2.0));
+
+  Standard_Real aViewSizeXv = aMatchDistance[0] + aMatchDistance[1];
+  Standard_Real aViewSizeYv = aMatchDistance[2] + aMatchDistance[3];
+  Standard_Real aViewSizeZv = aMatchDistance[4] + aMatchDistance[5];
+
+  // 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 = (aMatchDistance[1] - aMatchDistance[0]) * 0.5 + anAssymXv;
+  Standard_Real anOffsetYv = (aMatchDistance[3] - aMatchDistance[2]) * 0.5 + anAssymYv;
+  gp_Vec aTranslateSide = gp_Vec (aCamSide) * anOffsetXv;
+  gp_Vec aTranslateUp   = gp_Vec (aCamUp)   * anOffsetYv;
+  gp_Pnt aNewCenter     = aBBCenter.Translated (aTranslateSide).Translated (aTranslateUp);
+
+  gp_Trsf aCenterTrsf;
+  aCenterTrsf.SetTranslation (theCamera->Center(), aNewCenter);
+  theCamera->Transform (aCenterTrsf);
+  theCamera->SetDistance (Max (aMatchDistance[5] + aMatchDistance[4], Precision::Confusion()));
+
+  // Bounding box collapses to a point or thin line going in depth of the screen
+  if (aViewSizeXv < theResolution && aViewSizeYv < theResolution)
+  {
+    if (aViewSizeXv < theResolution || !theToEnlargeIfLine)
+    {
+      return Standard_True; // This is just one point or line and zooming has no effect.
+    }
+
+    // Looking along line and "theToEnlargeIfLine" is requested.
+    // Fit view to see whole scene on rotation.
+    aViewSizeXv = aViewSizeZv;
+    aViewSizeYv = aViewSizeZv;
+  }
+
+  Scale (theCamera, aViewSizeXv * (1.0 + theMargin), aViewSizeYv * (1.0 + theMargin));
+
+  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();
+  Standard_Real aMaxSize = Max (theSizeXv / anAspect, theSizeYv);
+  theCamera->SetScale (aMaxSize);
+}
+
+// =======================================================================
+// 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);
+}