0028726: Quantity_NameOfColor should be replaced by Quantity_Color in function input...
[occt.git] / src / V3d / V3d_Viewer.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 42318ed..d2c5798
-/***********************************************************************
-     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.
-
-************************************************************************/
-
-#define GER61351       //GG_15/12/99 Adds SetDefaultBackgroundColor()
-//                                   and DefaultBackgroundColor() methods
-
-#define IMP240100      //GG 
-//                     Initalize grid echo fields
-
-/*----------------------------------------------------------------------*/
-/*
- * Includes
- */
-
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// 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.
+//
+// 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_AspectMarker3d.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>
-#ifdef WNT
-#include <WNT_GraphicDevice.hxx>
-#endif
-
-/*----------------------------------------------------------------------*/
-
-//-Constructor:
-V3d_Viewer::V3d_Viewer(const Handle(Aspect_GraphicDevice)& Device , 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(Device,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(Device) ;
-  // 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(Standard_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;
-}
-
-Handle(V3d_PerspectiveView) V3d_Viewer::DefaultPerspectiveView () {
 
-  return MyDefaultPerspectiveView;
+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);
 }
 
-void V3d_Viewer::SetViewOff( ) {
-
-  for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){
-    SetViewOff(ActiveView());};
+// ========================================================================
+// function : CreateView
+// purpose  :
+// ========================================================================
+Handle(V3d_View) V3d_Viewer::CreateView ()
+{
+  return new V3d_View(this, myDefaultTypeOfView);
 }
 
-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 : SetViewOn
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOn()
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    SetViewOn (aDefViewIter.Value());
   }
 }
 
-void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) {
-
-  Handle(Visual3d_View) MyView =TheView->View(); 
-  if( MyView->IsDefined() && IsActive(TheView) ) {
-    MyActiveViews.Remove(TheView);
-    MyView->Deactivate() ;
+// ========================================================================
+// function : SetViewOff
+// purpose  :
+// ========================================================================
+void V3d_Viewer::SetViewOff()
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    SetViewOff (aDefViewIter.Value());
   }
 }
 
-Standard_Boolean V3d_Viewer::ComputedMode() const {
-  return myComputedMode;
-}
-
-Standard_Boolean V3d_Viewer::DefaultComputedMode() const {
-  return myDefaultComputedMode;
-}
-
-void V3d_Viewer::Update() {
-
-  MyViewer->Update();
-}
-
-void V3d_Viewer::Redraw()const  {
-
-  MyViewer->Redraw();
-}
+// ========================================================================
+// 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;
+  }
 
-void V3d_Viewer::Remove() {
+  myActiveViews.Append (theView);
+  aViewImpl->Activate();
+  for (V3d_ListOfLight::Iterator anActiveLightIter (myActiveLights); anActiveLightIter.More(); anActiveLightIter.Next())
+  {
+    theView->SetLightOn (anActiveLightIter.Value());
+  }
 
-  MyViewer->Remove();
+  theView->SetGrid (myPrivilegedPlane, Grid ());
+  theView->SetGridActivity (Grid ()->IsActive ());
+  theView->Redraw();
 }
 
-void V3d_Viewer::Erase() const {
-  
-  MyViewer->Erase();
+// ========================================================================
+// 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::UnHighlight() const {
-
-  //FMN MyViewer->UnHighlight();
+// ========================================================================
+// function : Redraw
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Redraw() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->Redraw();
+  }
 }
 
-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) ;
-#ifdef GER61351
-  SetDefaultBackgroundColor(C);
-#else
-  MyBackground.SetColor(C) ;
-#endif
+// ========================================================================
+// function : RedrawImmediate
+// purpose  :
+// ========================================================================
+void V3d_Viewer::RedrawImmediate() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->RedrawImmediate();
+  }
 }
 
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_NameOfColor Name) {
-
-  Quantity_Color C(Name) ;
-#ifdef GER61351
-  SetDefaultBackgroundColor(C);
-#else
-  MyBackground.SetColor(C) ;
-#endif
+// ========================================================================
+// function : Invalidate
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Invalidate() const
+{
+  for (V3d_ListOfView::Iterator aDefViewIter (myDefinedViews); aDefViewIter.More(); aDefViewIter.Next())
+  {
+    aDefViewIter.Value()->Invalidate();
+  }
 }
 
-#ifdef GER61351
-void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_Color &Color) {
-
-  MyBackground.SetColor(Color) ;
+// ========================================================================
+// function : Remove
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Remove()
+{
+  myStructureManager->Remove();
 }
-#endif
-
-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 : Erase
+// purpose  :
+// ========================================================================
+void V3d_Viewer::Erase() const
+{
+  myStructureManager->Erase();
 }
 
-void V3d_Viewer::SetDefaultViewProj(const V3d_TypeOfOrientation Orientation) {
-
-  MyViewProj = Orientation ;
+// ========================================================================
+// function : UnHighlight
+// purpose  :
+// ========================================================================
+void V3d_Viewer::UnHighlight() const
+{
+  myStructureManager->UnHighlight();
 }
 
-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();
+void V3d_Viewer::SetDefaultViewSize (const Standard_Real theSize)
+{
+  if (theSize <= 0.0)
+    throw V3d_BadValue("V3d_Viewer::SetDefaultViewSize, bad size");
+  myViewSize = theSize;
 }
 
-void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) {
-
-  MyShadingModel = Type ;
+// ========================================================================
+// function : IfMoreViews
+// purpose  :
+// ========================================================================
+Standard_Boolean V3d_Viewer::IfMoreViews() const
+{
+  return myDefinedViews.Size() < myStructureManager->MaxNumOfViews();
 }
 
-void V3d_Viewer::SetDefaultSurfaceDetail(const V3d_TypeOfSurfaceDetail Type) {
-
-  MySurfaceDetail = Type ;
+// ========================================================================
+// function : AddView
+// purpose  :
+// ========================================================================
+void V3d_Viewer::AddView (const Handle(V3d_View)& theView)
+{
+  if (!myDefinedViews.Contains (theView))
+  {
+    myDefinedViews.Append (theView);
+  }
 }
 
-void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) {
-  MyDefaultAngle = Angle;
+// ========================================================================
+// function : DelView
+// purpose  :
+// ========================================================================
+void V3d_Viewer::DelView (const Handle(V3d_View)& theView)
+{
+  myActiveViews.Remove (theView);
+  myDefinedViews.Remove (theView);
 }
 
-void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) {
-  MyDefaultTypeOfView = Type;}
+//=======================================================================
+//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;
+  }
 
+  myLayerIds.Add (theLayerId);
+  myDriver->AddZLayer (theLayerId);
 
-void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) {
-  
-  MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ;
+  return Standard_True;
 }
 
-void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const {
-
-#ifdef GER61351
-  Quantity_Color C = DefaultBackgroundColor();
-#else
-  Quantity_Color C = MyBackground.Color() ;
-#endif
-  C.Values(V1,V2,V3,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;
+  }
 
-#ifdef GER61351
-Quantity_Color V3d_Viewer::DefaultBackgroundColor() const {
-  return MyBackground.Color() ;
-}
-#endif
+  myDriver->RemoveZLayer (theLayerId);
+  myLayerIds.Remove  (theLayerId);
+  myZLayerGenId.Free (theLayerId);
 
-void V3d_Viewer::DefaultBgGradientColors(Quantity_Color& Color1,Quantity_Color& Color2) const{   
-  MyGradientBackground.Colors(Color1,Color2);     
+  return Standard_True;
 }
 
-Standard_Real V3d_Viewer::DefaultViewSize() const {
-  return MyViewSize ;
+//=======================================================================
+//function : GetAllZLayers
+//purpose  :
+//=======================================================================
+void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+{
+  myDriver->ZLayers (theLayerSeq);
 }
 
-V3d_TypeOfOrientation V3d_Viewer::DefaultViewProj() const {
-  return MyViewProj ;
+//=======================================================================
+//function : SetZLayerSettings
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings)
+{
+  myDriver->SetZLayerSettings (theLayerId, theSettings);
 }
 
-V3d_TypeOfVisualization V3d_Viewer::DefaultVisualization() const {
-  return MyVisualization ;
+//=======================================================================
+//function : ZLayerSettings
+//purpose  :
+//=======================================================================
+Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId)
+{
+  return myDriver->ZLayerSettings (theLayerId);
 }
 
-V3d_TypeOfShadingModel V3d_Viewer::DefaultShadingModel() const {
-  return MyShadingModel ;
+//=======================================================================
+//function : UpdateLights
+//purpose  :
+//=======================================================================
+void V3d_Viewer::UpdateLights()
+{
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->UpdateLights();
+  }
 }
 
-V3d_TypeOfSurfaceDetail V3d_Viewer::DefaultSurfaceDetail() const {
-  return MySurfaceDetail ;
-}
+//=======================================================================
+//function : SetLightOn
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetLightOn (const Handle(V3d_Light)& theLight)
+{
+  if (!myActiveLights.Contains (theLight))
+  {
+    myActiveLights.Append (theLight);
+  }
 
-Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const {
-  return MyDefaultAngle;
+  for (V3d_ListOfView::Iterator anActiveViewIter (myActiveViews); anActiveViewIter.More(); anActiveViewIter.Next())
+  {
+    anActiveViewIter.Value()->SetLightOn (theLight);
+  }
 }
 
-V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const {
-
-  V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ;
-  return Mode ;
+//=======================================================================
+//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);
+  }
 }
 
-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 : 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());
+      }
+    }
+  }
 }
 
-Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const {
-  return MyViewer ;
+//=======================================================================
+//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();
 }
 
-Aspect_Background V3d_Viewer::GetBackgroundColor() const {
-  return MyBackground ;
+//=======================================================================
+//function : IsGlobalLight
+//purpose  :
+//=======================================================================
+Standard_Boolean V3d_Viewer::IsGlobalLight (const Handle(V3d_Light)& theLight) const
+{
+  return myActiveLights.Contains (theLight);
 }
 
-Aspect_GradientBackground V3d_Viewer::GetGradientBackground() const {
-  return MyGradientBackground;
-}   
-
-void V3d_Viewer::AddView( const Handle(V3d_View)& TheView ) {
-
-  MyDefinedViews.Append(TheView);
-  IncrCount();
+//=======================================================================
+//function : AddLight
+//purpose  :
+//=======================================================================
+void V3d_Viewer::AddLight (const Handle(V3d_Light)& theLight)
+{
+  if (!myDefinedLights.Contains (theLight))
+  {
+    myDefinedLights.Append (theLight);
+  }
 }
 
-void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) {
-
-  MyActiveViews.Remove(TheView);
-  MyDefinedViews.Remove(TheView);
+//=======================================================================
+//function : DelLight
+//purpose  :
+//=======================================================================
+void V3d_Viewer::DelLight (const Handle(V3d_Light)& theLight)
+{
+  SetLightOff (theLight);
+  myDefinedLights.Remove (theLight);
 }
 
-void V3d_Viewer::AddPlane( const Handle(V3d_Plane)& ThePlane ) {
-
-  MyDefinedPlanes.Append(ThePlane) ;
-}
+//=======================================================================
+//function : SetDefaultLights
+//purpose  :
+//=======================================================================
+void V3d_Viewer::SetDefaultLights()
+{
+  while (!myDefinedLights.IsEmpty())
+  {
+    Handle(V3d_Light) aLight = myDefinedLights.First();
+    DelLight (aLight);
+  }
 
-void V3d_Viewer::DelPlane( const Handle(V3d_Plane)& ThePlane ) {
-  
-  MyDefinedPlanes.Remove(ThePlane);
+  SetLightOn (new V3d_DirectionalLight (this, V3d_Zneg, Quantity_NOC_WHITE, Standard_True));
+  SetLightOn (new V3d_AmbientLight (this));
 }