0029419: Make V3d_Viewer::PrivilegedPlane() return const reference rather than a...
[occt.git] / src / V3d / V3d_Viewer.cxx
old mode 100755 (executable)
new mode 100644 (file)
index a444346..a8747f7
-// Copyright (c) 1999-2012 OPEN CASCADE SAS
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
 //
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
 //
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
 //
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
-
-/***********************************************************************
-     FONCTION :
-     ----------
-        Classe V3d_Viewer :
-     HISTORIQUE DES MODIFICATIONS   :
-     --------------------------------
-      00-09-92 : GG  ; Creation.
-      15-11-97 : FMN ; Ajout texture mapping
-      02-02-98 : FMN ; Mise a niveau WNT
-      23-02-98 : FMN ; Remplacement PI par Standard_PI
-      16-07-98 : CAL ; S3892. Ajout grilles 3d.
-
-************************************************************************/
-
-//GER61351     //GG_15/12/99 Adds SetDefaultBackgroundColor() and DefaultBackgroundColor() methods
-
-#define IMP240100      //GG 
-//                     Initalize grid echo fields
-
-/*----------------------------------------------------------------------*/
-/*
- * Includes
- */
-
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <V3d_Viewer.hxx>
+
+#include <Aspect_Grid.hxx>
+#include <Aspect_IdentDefinitionError.hxx>
+#include <Graphic3d_ArrayOfSegments.hxx>
+#include <Graphic3d_AspectLine3d.hxx>
+#include <Graphic3d_AspectMarker3d.hxx>
+#include <Graphic3d_AspectText3d.hxx>
+#include <Graphic3d_GraphicDriver.hxx>
+#include <Graphic3d_Group.hxx>
+#include <Graphic3d_Structure.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_Type.hxx>
 #include <V3d.hxx>
-#include <Visual3d_View.hxx>
-#include <Visual3d_Light.hxx>
-#include <V3d_Viewer.ixx>
+#include <V3d_BadValue.hxx>
+#include <V3d_CircularGrid.hxx>
+#include <V3d_AmbientLight.hxx>
+#include <V3d_DirectionalLight.hxx>
+#include <V3d_RectangularGrid.hxx>
 #include <V3d_View.hxx>
-#include <Viewer_BadValue.hxx>
-#include <V3d_OrthographicView.hxx>
-#include <V3d_PerspectiveView.hxx>
-
-/*----------------------------------------------------------------------*/
-
-//-Constructor:
-V3d_Viewer::V3d_Viewer(const Handle(Graphic3d_GraphicDriver)& theDriver , const Standard_ExtString aName, const Standard_CString aDomain,const Standard_Real ViewSize , const V3d_TypeOfOrientation ViewProj , const Quantity_NameOfColor ViewBackground , const V3d_TypeOfVisualization Visualization , const V3d_TypeOfShadingModel ShadingModel , const V3d_TypeOfUpdate UpdateMode, const Standard_Boolean ComputedMode , const Standard_Boolean DefaultComputedMode , const V3d_TypeOfSurfaceDetail SurfaceDetail )  
-:Viewer_Viewer(theDriver,aName,aDomain,-1),
-MyDefinedViews(),
-MyActiveViews(),
-MyDefinedLights(),
-MyActiveLights(),
-MyDefinedPlanes(),
-myActiveViewsIterator(),
-myDefinedViewsIterator(),
-myActiveLightsIterator(),
-myDefinedLightsIterator(),
-myDefinedPlanesIterator(),
-myComputedMode(ComputedMode),
-myDefaultComputedMode(DefaultComputedMode),
-myPrivilegedPlane(gp_Ax3(gp_Pnt(0.,0.,0),gp_Dir(0.,0.,1.),gp_Dir(1.,0.,0.))),
-myDisplayPlane(Standard_False),
-myDisplayPlaneLength(ViewSize)
-#ifdef IMP240100
-,myGridEcho(Standard_True),myGridEchoStructure(),myGridEchoGroup()
-#endif 
-{
-
-  MyViewer = new Visual3d_ViewManager(theDriver) ;
-  // san (16/09/2010): It has been decided to turn depth test ON
-  // by default, as this is important for new font rendering
-  // (without it, there are numerous texture rendering artefacts)
-  MyViewer->SetZBufferAuto (Standard_False);
-  SetUpdateMode( UpdateMode ) ;
-  SetDefaultViewSize(ViewSize) ;
-  SetDefaultViewProj(ViewProj) ;
-  SetDefaultBackgroundColor(ViewBackground) ;
-  SetDefaultVisualization(Visualization) ;
-  SetDefaultShadingModel(ShadingModel) ;
-  SetDefaultSurfaceDetail(SurfaceDetail) ; 
-  SetDefaultAngle(M_PI / 2.);
-  SetDefaultTypeOfView(V3d_ORTHOGRAPHIC);
-
-  Quantity_Color Color1 (Quantity_NOC_GRAY50);
-  Quantity_Color Color2 (Quantity_NOC_GRAY70);
-//  Quantity_Color White (Quantity_NOC_WHITE);
-  myRGrid = new V3d_RectangularGrid(this,Color1,Color2);
-  myCGrid = new V3d_CircularGrid(this,Color1,Color2);
-  myGridType = Aspect_GT_Rectangular;
-}
-
-//-Methods, in order
-
-
-Handle(V3d_View) V3d_Viewer::CreateView () {
-  if (MyDefaultTypeOfView == V3d_ORTHOGRAPHIC) 
-    return new V3d_OrthographicView(this);
-  else
-    return new V3d_PerspectiveView(this);
-}
-
-void V3d_Viewer::SetViewOn( ) {
-
-  for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
-    SetViewOn(ActiveView());};
-}
 
-Handle(V3d_OrthographicView) V3d_Viewer::DefaultOrthographicView() {
-
-  return MyDefaultOrthographicView;
+IMPLEMENT_STANDARD_RTTIEXT(V3d_Viewer, Standard_Transient)
+
+// ========================================================================
+// function : V3d_Viewer
+// purpose  :
+// ========================================================================
+V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver)
+: myDriver (theDriver),
+  myStructureManager (new Graphic3d_StructureManager (theDriver)),
+  myZLayerGenId (1, IntegerLast()),
+  myBackground (Quantity_NOC_GRAY30),
+  myViewSize (1000.0),
+  myViewProj (V3d_XposYnegZpos),
+  myVisualization (V3d_ZBUFFER),
+  myShadingModel (V3d_GOURAUD),
+  myDefaultTypeOfView (V3d_ORTHOGRAPHIC),
+  myComputedMode (Standard_True),
+  myDefaultComputedMode (Standard_False),
+  myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
+  myDisplayPlane (Standard_False),
+  myDisplayPlaneLength (1000.0),
+  myGridType (Aspect_GT_Rectangular),
+  myGridEcho (Standard_True),
+  myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
+{
+  myRGrid = new V3d_RectangularGrid (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
+  myCGrid = new V3d_CircularGrid    (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
+}
+
+// ========================================================================
+// function : V3d_Viewer
+// purpose  :
+// ========================================================================
+V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver,
+                        const Standard_ExtString ,
+                        const Standard_CString ,
+                        const Standard_Real           theViewSize,
+                        const V3d_TypeOfOrientation   theViewProj,
+                        const Quantity_Color&         theViewBackground,
+                        const V3d_TypeOfVisualization theVisualization,
+                        const V3d_TypeOfShadingModel  theShadingModel,
+                        const Standard_Boolean        theComputedMode,
+                        const Standard_Boolean        theDefaultComputedMode)
+: myDriver (theDriver),
+  myStructureManager (new Graphic3d_StructureManager (theDriver)),
+  myZLayerGenId (1, IntegerLast()),
+  myBackground (theViewBackground),
+  myViewSize (theViewSize),
+  myViewProj (theViewProj),
+  myVisualization (theVisualization),
+  myShadingModel (theShadingModel),
+  myDefaultTypeOfView (V3d_ORTHOGRAPHIC),
+  myComputedMode (theComputedMode),
+  myDefaultComputedMode (theDefaultComputedMode),
+  myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0.))),
+  myDisplayPlane (Standard_False),
+  myDisplayPlaneLength (theViewSize),
+  myGridType (Aspect_GT_Rectangular),
+  myGridEcho (Standard_True),
+  myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast())
+{
+  myRGrid = new V3d_RectangularGrid (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
+  myCGrid = new V3d_CircularGrid    (this, Quantity_Color (Quantity_NOC_GRAY50), Quantity_Color (Quantity_NOC_GRAY70));
+  SetDefaultViewSize (theViewSize);
 }
 
-Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
-
-  return MyDefaultPerspectiveView;
+// ========================================================================
+// function : CreateView
+// purpose  :
+// ========================================================================
+Handle(V3d_View) V3d_Viewer::CreateView ()
+{
+  return new V3d_View(this, myDefaultTypeOfView);
 }
 
-void V3d_Viewer::SetViewOff( ) {
-
-  for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
-    SetViewOff(ActiveView());};
+// ========================================================================
+// function : SetViewOn
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOn()
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    SetViewOn (aDefViewIter.Value());
+  }
 }
 
-void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) {
-
-  Handle(Visual3d_View) MyView = TheView->View() ;
-  if( MyView->IsDefined() && !IsActive(TheView)) {
-    MyActiveViews.Append(TheView) ;
-    MyView->Activate();
-    for (InitActiveLights();MoreActiveLights();NextActiveLights()){
-      TheView->SetLightOn(ActiveLight());}
-    // Grid
-    TheView->SetGrid (myPrivilegedPlane, Grid ());
-    TheView->SetGridActivity (Grid ()->IsActive ());
-    // Update
-    MyView->Redraw() ;
+// ========================================================================
+// function : SetViewOff
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOff()
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    SetViewOff (aDefViewIter.Value());
   }
 }
 
-void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
+// ========================================================================
+// function : SetViewOn
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView)
+{
+  Handle(Graphic3d_CView) aViewImpl = theView->View();
+  if (!aViewImpl->IsDefined() || myActiveViews.Contains (theView))
+  {
+    return;
+  }
 
-  Handle(Visual3d_View) MyView =TheView->View(); 
-  if( MyView->IsDefined() && IsActive(TheView) ) {
-    MyActiveViews.Remove(TheView);
-    MyView->Deactivate() ;
+  myActiveViews.Append (theView);
+  aViewImpl->Activate();
+  for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
+  {
+    theView->SetLightOn (anActiveLightIter.Value());
   }
-}
 
-Standard_Boolean V3d_Viewer::ComputedMode() const {
-  return myComputedMode;
+  theView->SetGrid (myPrivilegedPlane, Grid ());
+  theView->SetGridActivity (Grid ()->IsActive ());
+  theView->Redraw();
 }
 
-Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
-  return myDefaultComputedMode;
+// ========================================================================
+// function : SetViewOff
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView)
+{
+  Handle(Graphic3d_CView) aViewImpl = theView->View();
+  if (aViewImpl->IsDefined() && myActiveViews.Contains (theView))
+  {
+    myActiveViews.Remove (theView);
+    aViewImpl->Deactivate() ;
+  }
 }
 
-void V3d_Viewer::Update() {
-
-  MyViewer->Update();
+// ========================================================================
+// function : Redraw
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Redraw() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->Redraw();
+  }
 }
 
-void V3d_Viewer::Redraw()const  {
-
-  MyViewer->Redraw();
+// ========================================================================
+// function : RedrawImmediate
+// purpose  :
+// ========================================================================
+void V3d_Viewer::RedrawImmediate() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->RedrawImmediate();
+  }
 }
 
-void V3d_Viewer::Remove() {
-
-  MyViewer->Remove();
+// ========================================================================
+// function : Invalidate
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Invalidate() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->Invalidate();
+  }
 }
 
-void V3d_Viewer::Erase() const {
-  
-  MyViewer->Erase();
+// ========================================================================
+// function : Remove
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Remove()
+{
+  myStructureManager->Remove();
 }
 
-void V3d_Viewer::UnHighlight() const {
-
-  //FMN MyViewer->UnHighlight();
+// ========================================================================
+// function : Erase
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Erase() const
+{
+  myStructureManager->Erase();
 }
 
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) {
-  Standard_Real V1 = v1 ;
-  Standard_Real V2 = v2 ;
-  Standard_Real V3 = v3 ;
-
-  if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ;
-  if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ;
-  if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ;
-
-  Quantity_Color C(V1,V2,V3,Type) ;
-  SetDefaultBackgroundColor(C);
+// ========================================================================
+// function : UnHighlight
+// purpose  :
+// ========================================================================
+void V3d_Viewer::UnHighlight() const
+{
+  myStructureManager->UnHighlight();
 }
 
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name)
+void V3d_Viewer::SetDefaultViewSize (const Standard_Real theSize)
 {
-  Quantity_Color C(Name) ;
-  SetDefaultBackgroundColor(C);
+  if (theSize <= 0.0)
+    throw V3d_BadValue("V3d_Viewer::SetDefaultViewSize, bad size");
+  myViewSize = theSize;
 }
 
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color)
+// ========================================================================
+// function : IfMoreViews
+// purpose  :
+// ========================================================================
+Standard_Boolean V3d_Viewer::IfMoreViews() const
 {
-  MyBackground.SetColor(Color) ;
+  return myDefinedViews.Size() < myStructureManager->MaxNumOfViews();
 }
 
-void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_NameOfColor Name1,
-                                             const Quantity_NameOfColor Name2,
-                                             const Aspect_GradientFillMethod FillStyle){
-
-  Quantity_Color C1(Name1) ;
-  Quantity_Color C2(Name2) ;
-  MyGradientBackground.SetColors(C1, C2, FillStyle);
-
-} 
-
-void V3d_Viewer::SetDefaultBgGradientColors( const Quantity_Color& Color1,
-                                             const Quantity_Color& Color2,
-                                             const Aspect_GradientFillMethod FillStyle ){
-
-  MyGradientBackground.SetColors(Color1, Color2, FillStyle);
-
-}  
-
-
-void V3d_Viewer::SetDefaultViewSize(const Standard_Real Size) {
-
-  Viewer_BadValue_Raise_if( Size <= 0. ,"V3d_Viewer::SetDefaultViewSize, bad size");
-  MyViewSize = Size ;
+// ========================================================================
+// function : AddView
+// purpose  :
+// ========================================================================
+void V3d_Viewer::AddView (const Handle(V3d_View)& theView)
+{
+  if (!myDefinedViews.Contains (theView))
+  {
+    myDefinedViews.Append (theView);
+  }
 }
 
-void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
-
-  MyViewProj = Orientation ;
+// ========================================================================
+// function : DelView
+// purpose  :
+// ========================================================================
+void V3d_Viewer::DelView (const Handle(V3d_View)& theView)
+{
+  myActiveViews.Remove (theView);
+  myDefinedViews.Remove (theView);
 }
 
-void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) {
-
-  MyVisualization = Type ;
-}
-void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) {
-  MyViewer->SetZBufferAuto (Automatic);
-}
-Standard_Boolean V3d_Viewer::ZBufferManagment() const {
-  return MyViewer->ZBufferAuto();
-}
+//=======================================================================
+//function : AddZLayer
+//purpose  :
+//=======================================================================
+Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
+{
+  try
+  {
+    OCC_CATCH_SIGNALS
+    theLayerId = myZLayerGenId.Next();
+  }
+  catch (Aspect_IdentDefinitionError)
+  {
+    // new index can't be generated
+    return Standard_False;
+  }
 
-void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
+  myLayerIds.Add (theLayerId);
+  myDriver->AddZLayer (theLayerId);
 
-  MyShadingModel = Type ;
+  return Standard_True;
 }
 
-void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
+//=======================================================================
+//function : RemoveZLayer
+//purpose  : 
+//=======================================================================
+Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
+{
+  if (!myLayerIds.Contains (theLayerId)
+    || theLayerId < myZLayerGenId.Lower()
+    || theLayerId > myZLayerGenId.Upper())
+  {
+    return Standard_False;
+  }
 
-  MySurfaceDetail = Type ;
-}
+  myDriver->RemoveZLayer (theLayerId);
+  myLayerIds.Remove  (theLayerId);
+  myZLayerGenId.Free (theLayerId);
 
-void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
-  MyDefaultAngle = Angle;
+  return Standard_True;
 }
 
-void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
-  MyDefaultTypeOfView = Type;}
-
-
-void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
-  
-  MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
+//=======================================================================
+//function : GetAllZLayers
+//purpose  :
+//=======================================================================
+void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+{
+  myDriver->ZLayers (theLayerSeq);
 }
 
-void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const
+//=======================================================================
+//function : SetZLayerSettings
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings)
 {
-  Quantity_Color C = DefaultBackgroundColor();
-  C.Values(V1,V2,V3,Type) ;
+  myDriver->SetZLayerSettings (theLayerId, theSettings);
 }
 
-Quantity_Color V3d_Viewer::DefaultBackgroundColor() const
+//=======================================================================
+//function : ZLayerSettings
+//purpose  :
+//=======================================================================
+Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId)
 {
-  return MyBackground.Color() ;
+  return myDriver->ZLayerSettings (theLayerId);
 }
 
-void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const
+//=======================================================================
+//function : UpdateLights
+//purpose  :
+//=======================================================================
+void V3d_Viewer::UpdateLights()
 {
-  MyGradientBackground.Colors(Color1,Color2);     
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->UpdateLights();
+  }
 }
 
-Standard_Real V3d_Viewer::DefaultViewSize() const {
-  return MyViewSize ;
-}
+//=======================================================================
+//function : SetLightOn
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetLightOn (const Handle(V3d_Light)& theLight)
+{
+  if (!myActiveLights.Contains (theLight))
+  {
+    myActiveLights.Append (theLight);
+  }
 
-V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
-  return MyViewProj ;
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->SetLightOn (theLight);
+  }
 }
 
-V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
-  return MyVisualization ;
+//=======================================================================
+//function : SetLightOff
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetLightOff (const Handle(V3d_Light)& theLight)
+{
+  myActiveLights.Remove (theLight);
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->SetLightOff (theLight);
+  }
 }
 
-V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
-  return MyShadingModel ;
+//=======================================================================
+//function : SetLightOn
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetLightOn()
+{
+  for (V3d_ListOfLight::Iterator aDefLightIter (myDefinedLights); aDefLightIter.More(); aDefLightIter.Next())
+  {
+    if (!myActiveLights.Contains (aDefLightIter.Value()))
+    {
+      myActiveLights.Append (aDefLightIter.Value());
+      for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+      {
+        anActiveViewIter.Value()->SetLightOn (aDefLightIter.Value());
+      }
+    }
+  }
 }
 
-V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
-  return MySurfaceDetail ;
+//=======================================================================
+//function : SetLightOff
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetLightOff()
+{
+  for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
+  {
+    for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+    {
+      anActiveViewIter.Value()->SetLightOff (anActiveLightIter.Value());
+    }
+  }
+  myActiveLights.Clear();
 }
 
-Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
-  return MyDefaultAngle;
+//=======================================================================
+//function : IsGlobalLight
+//purpose  :
+//=======================================================================
+Standard_Boolean V3d_Viewer::IsGlobalLight (const Handle(V3d_Light)& theLight) const
+{
+  return myActiveLights.Contains (theLight);
 }
 
-V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
-
-  V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
-  return Mode ;
+//=======================================================================
+//function : AddLight
+//purpose  :
+//=======================================================================
+void V3d_Viewer::AddLight (const Handle(V3d_Light)& theLight)
+{
+  if (!myDefinedLights.Contains (theLight))
+  {
+    myDefinedLights.Append (theLight);
+  }
 }
 
-Standard_Boolean V3d_Viewer::IfMoreViews() const {
-  Standard_Boolean TheStatus = Standard_False ;
-
-#ifdef NEW
-  if( MyActiveViews->Length() < Visual3d_View::Limit() )
-#endif /*NEW*/
-    TheStatus = Standard_True ;
-  return TheStatus ;
+//=======================================================================
+//function : DelLight
+//purpose  :
+//=======================================================================
+void V3d_Viewer::DelLight (const Handle(V3d_Light)& theLight)
+{
+  SetLightOff (theLight);
+  myDefinedLights.Remove (theLight);
 }
 
-Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
-  return MyViewer ;
-}
+//=======================================================================
+//function : SetDefaultLights
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetDefaultLights()
+{
+  while (!myDefinedLights.IsEmpty())
+  {
+    Handle(V3d_Light) aLight = myDefinedLights.First();
+    DelLight (aLight);
+  }
 
-Aspect_Background V3d_Viewer::GetBackgroundColor() const {
-  return MyBackground ;
+  Handle(V3d_DirectionalLight) aDirLight  = new V3d_DirectionalLight (V3d_Zneg, Quantity_NOC_WHITE, Standard_True);
+  Handle(V3d_AmbientLight)     anAmbLight = new V3d_AmbientLight (Quantity_NOC_WHITE);
+  AddLight (aDirLight);
+  AddLight (anAmbLight);
+  SetLightOn (aDirLight);
+  SetLightOn (anAmbLight);
 }
 
-Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
-  return MyGradientBackground;
-}   
-
-void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
+//=======================================================================
+//function : SetPrivilegedPlane
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetPrivilegedPlane (const gp_Ax3& thePlane)
+{
+  myPrivilegedPlane = thePlane;
+  Grid()->SetDrawMode(Grid()->DrawMode());
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->SetGrid (myPrivilegedPlane, Grid());
+  }
 
-  MyDefinedViews.Append(TheView);
-  IncrCount();
+  if (myDisplayPlane)
+  {
+    DisplayPrivilegedPlane (Standard_True, myDisplayPlaneLength);
+  }
 }
 
-void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
+//=======================================================================
+//function : DisplayPrivilegedPlane
+//purpose  :
+//=======================================================================
+void V3d_Viewer::DisplayPrivilegedPlane (const Standard_Boolean theOnOff, const Standard_Real theSize)
+{
+  myDisplayPlane = theOnOff;
+  myDisplayPlaneLength = theSize;
+
+  if (!myDisplayPlane)
+  {
+    if (!myPlaneStructure.IsNull())
+       {
+      myPlaneStructure->Erase();
+    }
+    return;
+  }
 
-  MyActiveViews.Remove(TheView);
-  MyDefinedViews.Remove(TheView);
-}
+  if (myPlaneStructure.IsNull())
+  {
+    myPlaneStructure = new Graphic3d_Structure (StructureManager());
+    myPlaneStructure->SetInfiniteState (Standard_True);
+    myPlaneStructure->Display();
+  }
+  else
+  {
+    myPlaneStructure->Clear();
+  }
 
-void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {
+  Handle(Graphic3d_Group) aGroup = myPlaneStructure->NewGroup();
 
-  MyDefinedPlanes.Append(ThePlane) ;
-}
+  Handle(Graphic3d_AspectLine3d) aLineAttrib = new Graphic3d_AspectLine3d (Quantity_NOC_GRAY60, Aspect_TOL_SOLID, 1.0);
+  aGroup->SetGroupPrimitivesAspect (aLineAttrib);
 
-void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
-  
-  MyDefinedPlanes.Remove(ThePlane);
-}
+  Handle(Graphic3d_AspectText3d) aTextAttrib = new Graphic3d_AspectText3d();
+  aTextAttrib->SetColor (Quantity_Color (Quantity_NOC_ROYALBLUE1));
+  aGroup->SetGroupPrimitivesAspect (aTextAttrib);
 
-//=======================================================================
-//function : AddZLayer
-//purpose  :
-//=======================================================================
+  Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments (6);
 
-Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId)
-{
-  return MyViewer->AddZLayer (theLayerId);
-}
+  const gp_Pnt& p0 = myPrivilegedPlane.Location();
 
-//=======================================================================
-//function : RemoveZLayer
-//purpose  : 
-//=======================================================================
+  const gp_Pnt pX (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.XDirection().XYZ());
+  aPrims->AddVertex (p0);
+  aPrims->AddVertex (pX);
+  aGroup->Text ("X", Graphic3d_Vertex (pX.X(), pX.Y(), pX.Z()), 1.0 / 81.0);
 
-Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId)
-{
-  return MyViewer->RemoveZLayer (theLayerId);
-}
+  const gp_Pnt pY (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.YDirection().XYZ());
+  aPrims->AddVertex (p0);
+  aPrims->AddVertex (pY);
+  aGroup->Text ("Y", Graphic3d_Vertex (pY.X(), pY.Y(), pY.Z()), 1.0 / 81.0);
 
-//=======================================================================
-//function : GetAllZLayers
-//purpose  :
-//=======================================================================
+  const gp_Pnt pZ (p0.XYZ() + myDisplayPlaneLength * myPrivilegedPlane.Direction().XYZ());
+  aPrims->AddVertex (p0);
+  aPrims->AddVertex (pZ);
+  aGroup->Text ("Z", Graphic3d_Vertex (pZ.X(), pZ.Y(), pZ.Z()), 1.0 / 81.0);
 
-void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
-{
-  MyViewer->GetAllZLayers (theLayerSeq);
+  aGroup->AddPrimitiveArray (aPrims);
+
+  myPlaneStructure->Display();
 }