0025027: Visualization - 2D layer viewport is updated incorrectly on resize
[occt.git] / src / Visual3d / Visual3d_ViewManager.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 8330001..e2a0dc7
@@ -1,3 +1,16 @@
+// Copyright (c) 1995-1999 Matra Datavision
+// 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.
 
 /***********************************************************************
 
@@ -17,7 +30,7 @@
       24-10-97  : CAL ; Retrait de DownCast.
       20-11-97  : CAL ; Disparition de la dependance avec math
       01-12-97  : CAL ; Retrait du test IsActive sur l'Update et le Redraw
-      31-12-97  : CAL ; Disparition de MathGra 
+      31-12-97  : CAL ; Disparition de MathGra
       16-01-98  : CAL ; Ajout du SetTransform sur une TOS_COMPUTED
       11-03-98  : CAL ; Visual3d_ViewManager::Remove ()
       20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
 #include <Standard_ErrorHandler.hxx>
 
 #include <Aspect.hxx>
+#include <Aspect_IdentDefinitionError.hxx>
 
 #include <Graphic3d_GraphicDriver.hxx>
 #include <Graphic3d_MapOfStructure.hxx>
 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
 
-#include <Visual3d_PickPath.hxx>
-#include <Visual3d_SetIteratorOfSetOfView.hxx>
 
-#ifndef WNT
-# include <Xw_Window.hxx>
-#else
+#if defined (_WIN32) || defined(__WIN32__)
 # include <WNT_Window.hxx>
-#endif  // WNT
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+# include <Cocoa_Window.hxx>
+#else
+# include <Xw_Window.hxx>
+#endif
 
 //-Aliases
 
 //-Global data definitions
 
 //     -- les vues definies
-//     MyDefinedView           :       SetOfView;
+//     MyDefinedView           :       SequenceOfView;
 
 //     -- le generateur d'identificateurs de vues
 //     MyViewGenId             :       GenId;
 
 //-Constructors
 
-Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
-Graphic3d_StructureManager (aDevice),
+Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
+Graphic3d_StructureManager (theDriver),
 MyDefinedView (),
 MyViewGenId (View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*(Visual3d_ViewManager::CurrentId ()-1),View_IDMIN+((View_IDMIN+View_IDMAX)/(Visual3d_ViewManager::Limit ()))*Visual3d_ViewManager::CurrentId ()-1),
 MyZBufferAuto (Standard_False),
 MyTransparency (Standard_False)
 {
+  // default layer is always presented in display layer sequence
+  // it can not be removed
+  myLayerIds.Add (0);
+  myLayerSeq.Append (0);
 
-Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();
-
-       MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
-
+  MyGraphicDriver = theDriver;
+  myMapOfZLayerSettings.Bind (0, Graphic3d_ZLayerSettings());
 }
 
 //-Destructors
@@ -110,78 +126,63 @@ void Visual3d_ViewManager::Remove () {
        //
        // Destroy all defined views
        //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
 
 #ifdef DESTROY
        cout << "The Manager " << MyId << " have " << Length << " defined views\n";
        cout << flush;
 #endif
-       MyDefinedView.Clear ();
 
+  // clear all structures whilst views are alive for correct GPU memory management
+  MyDisplayedStructure.Clear();
+  MyHighlightedStructure.Clear();
+  MyPickStructure.Clear();
+
+  // clear list of managed views
+  MyDefinedView.Clear();
 }
 
-void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
+void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority)
+{
 
 #ifdef TRACE
-       cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
-            << AStructure->Identification ()
-            << ", " << OldPriority << ", " << NewPriority << ")\n";
-       cout << flush;
-#endif
-
-       //
-       // Change structure priority in all defined views
-       //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
+  cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
+    << AStructure->Identification ()
+    << ", " << OldPriority << ", " << NewPriority << ")\n";
+  cout << flush;
 #endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->ChangeDisplayPriority
-                       (AStructure, OldPriority, NewPriority);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
 
+  //
+  // Change structure priority in all defined views
+  //
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->ChangeDisplayPriority(AStructure, OldPriority, NewPriority);
+  }
 }
 
-void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { 
+void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
 
   //Standard_Integer LengthD   = MyDisplayedStructure.Extent() ();
 
   // Even if physically the structure cannot
   // be displayed (pb of visualisation type)
   // it has status Displayed.
+
   if (!MyDisplayedStructure.Contains(AStructure))
     return;
 
   //
   // Recompute structure in all activated views
   //
-  Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-  while (MyIterator.More ()) {
-    (MyIterator.Value ())->ReCompute (AStructure);
-
-    // MyIterator.Next () is located on the next view
-    MyIterator.Next ();
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->ReCompute(AStructure);
   }
-  
 }
 
-void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, 
-                                     const Handle(Graphic3d_DataStructureManager)& AProjector) 
-{ 
+void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
+                                     const Handle(Graphic3d_DataStructureManager)& AProjector)
+{
 
   if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
 
@@ -192,144 +193,86 @@ void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStruct
 #endif
   Standard_Integer ViewId = theView->Identification ();
 
-  Standard_Integer indexD = 0;
-
   // Even if physically the structure cannot
   // be displayed (pb of visualisation type)
   // it has status Displayed.
   if (!MyDisplayedStructure.Contains(AStructure))
     return;
-       
+
   //
   // Recompute structure in all activated views
   //
-  Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-  while (MyIterator.More ()) {
-    if ((MyIterator.Value ())->Identification () == ViewId)
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if ((MyDefinedView.Value(i))->Identification () == ViewId)
+    {
       theView->ReCompute (AStructure);
-
-    // MyIterator.Next () is located on the next view
-    MyIterator.Next ();
+    }
   }
-
 }
 
-void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
-
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Clear (AStructure, WithDestruction);
-
-               // MyIterator.Next ()  is located on the next view
-               MyIterator.Next ();
-       }
-
+void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction)
+{
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Clear(AStructure, WithDestruction);
+  }
 }
 
-void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
-
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Connect (AMother, ADaughter);
-
-               // MyIterator.Next ()  is located on the next view
-               MyIterator.Next ();
-       }
-
+void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
+{
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Connect (AMother, ADaughter);
+  }
 }
 
-void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
-
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Disconnect (AMother, ADaughter);
-
-               // MyIterator.Next ()  is located on the next view
-               MyIterator.Next ();
-       }
-
+void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
+{
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Disconnect (AMother, ADaughter);
+  }
 }
 
-void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) { 
-
-
- // Even if physically the structure cannot
+void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure)
+{
+  // Even if physically the structure cannot
   // be displayed (pb of visualisation type)
   // it has status Displayed.
 
   MyDisplayedStructure.Add(AStructure);
-
-       //
-       // Display structure in all activated views
-       //
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Display (AStructure);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
+  
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Display(AStructure);
+  }
 }
 
-void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
-
-
-// Even if physically the structure cannot
+void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure)
+{
+  // Even if physically the structure cannot
   // be displayed (pb of visualisation type)
   // it has status Displayed.
 
- MyDisplayedStructure.Remove(AStructure);
-
-
-
-       //
-       // Erase structure in all defined views
-       //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Erase (AStructure);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
+  MyDisplayedStructure.Remove(AStructure);
 
-       MyHighlightedStructure.Remove (AStructure);
-       MyVisibleStructure.Remove (AStructure);
-       MyPickStructure.Remove (AStructure);
+  //
+  // Erase structure in all defined views
+  //
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Erase (AStructure);
+  }
 
+  MyHighlightedStructure.Remove (AStructure);
+  MyPickStructure.Remove (AStructure);
 }
 
 void Visual3d_ViewManager::Erase () {
 
  Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
+
  for (; it.More(); it.Next()) {
    Handle(Graphic3d_Structure) SG = it.Key();
    SG->Erase();
@@ -337,51 +280,32 @@ void Visual3d_ViewManager::Erase () {
 
 }
 
-void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
-
+void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod)
+{
   MyHighlightedStructure.Add(AStructure);
-
-       //
-       // Highlight in all activated views
-       //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Highlight (AStructure, AMethod);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
+  
+  //
+  // Highlight in all activated views
+  //
+  
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->Highlight (AStructure, AMethod);
+  }
 }
 
-void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
-
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
+void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf)
+{
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->SetTransform (AStructure, ATrsf);
+  }
 }
 
 void Visual3d_ViewManager::UnHighlight () {
 
   Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
-  
+
   for (; it.More(); it.Next()) {
     Handle(Graphic3d_Structure) SG = it.Key();
     SG->UnHighlight ();
@@ -390,828 +314,210 @@ void Visual3d_ViewManager::UnHighlight () {
 
 }
 
-void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
-
+void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure)
+{
   MyHighlightedStructure.Remove(AStructure);
 
+  //
+  // UnHighlight in all activated views
+  //
 
-       //
-       // UnHighlight in all activated views
-       //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->UnHighlight (AStructure);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->UnHighlight (AStructure);
+  }
 }
 
-void Visual3d_ViewManager::Redraw () const {
-
-Standard_Integer MaxDx, MaxDy;
-Standard_Integer Dx, Dy;
-       MaxDx = MaxDy = IntegerFirst ();
-
-       //
-       // Redraw all activated views
-       //
-       Standard_Integer j = MyDefinedView.Extent ();
-       if (j == 0) return;
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
-           while (MyIterator.More ()) {
-               (MyIterator.Value ())->Window ()->Size (Dx, Dy);
-               if (Dx > MaxDx) MaxDx = Dx;
-               if (Dy > MaxDy) MaxDy = Dy;
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-           }
-           if (! MyUnderLayer.IsNull ())
-               MyUnderLayer->SetViewport (MaxDx, MaxDy);
-           if (! MyOverLayer.IsNull ())
-               MyOverLayer->SetViewport (MaxDx, MaxDy);
-       }
-       if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
-           MyIterator.Initialize (MyDefinedView);
-       while (MyIterator.More ()) {
-           (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
-
-           // MyIterator.Next () is located on the next view
-           MyIterator.Next ();
-       }
-
-}
+void Visual3d_ViewManager::Redraw() const
+{
+  // redraw all activated views
+  if (MyDefinedView.Length() == 0)
+  {
+    return;
+  }
 
-void Visual3d_ViewManager::Update () const {
+  if (!MyUnderLayer.IsNull() || !MyOverLayer.IsNull())
+  {
+    Standard_Integer aWidth = 0, aHeight = 0;
+    Standard_Integer aWidthMax  = 0;
+    Standard_Integer aHeightMax = 0;
+
+    for(int i=1; i<=MyDefinedView.Length(); i++)
+    {
+      MyDefinedView.Value(i)->Window()->Size (aWidth, aHeight);
+      aWidthMax  = Max (aWidthMax,  aWidth);
+      aHeightMax = Max (aHeightMax, aHeight);
+    }
 
-       //
-       // Update all activated views
-       //
-       Standard_Integer j = MyDefinedView.Extent ();
-       if (j == 0) return;
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
+    if (!MyUnderLayer.IsNull())
+    {
+      MyUnderLayer->SetViewport (aWidthMax, aHeightMax);
+    }
+    if (!MyOverLayer.IsNull())
+    {
+      MyOverLayer->SetViewport (aWidthMax, aHeightMax);
+    }
+  }
 
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    MyDefinedView.Value(i)->Redraw (MyUnderLayer, MyOverLayer);
+  }
 }
 
-Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
-
-Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
-
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-
-       while (MyIterator.More ()) {
-               if ((MyIterator.Value ())->IsActive ())
-                       SG->Add (MyIterator.Value ());
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
-       return (SG);
-
+void Visual3d_ViewManager::Update() const
+{
+  Redraw();
 }
 
-#ifdef IMPLEMENTED
-Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
-
-Standard_Boolean Result = Standard_False;
-
-       //
-       // Check all activated views
-       //
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-
-       Standard_Integer i      = MyDefinedView.Extent ();
-
-       while ((! Result) && (MyIterator.More ())) {
-               if ((MyIterator.Value ())->IsActive ())
-                       Result  =
-                       (MyIterator.Value ())->ContainsComputedStructure ();
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
+void Visual3d_ViewManager::RedrawImmediate() const
+{
+  if (MyDefinedView.Length() == 0)
+  {
+    return;
+  }
 
-       return Result;
+  // update all activated views
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    MyDefinedView.Value(i)->RedrawImmediate (MyUnderLayer, MyOverLayer);
+  }
 }
-#endif
-
-Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
-
-Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
-
-Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-
-       while (MyIterator.More ()) {
-               SG->Add (MyIterator.Value ());
 
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
-       return (SG);
+void Visual3d_ViewManager::Invalidate() const
+{
+  if (MyDefinedView.Length() == 0)
+  {
+    return;
+  }
 
+  // update all activated views
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    MyDefinedView.Value(i)->Invalidate();
+  }
 }
 
-void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
-
-// Convert only if the data is correct
-Standard_Boolean Exist;
-Graphic3d_CView  TheCView;
-//Graphic3d_Vertex Point;
-
-TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
-TColStd_Array2OfReal Map_Matrix (0,3,0,3);
-
-Standard_Integer Width, Height;
-Standard_Real AX, AY, AZ;
-Standard_Real Dx, Dy, Ratio;
-
-       Exist   = ViewExists (AWindow, TheCView);
-
-       if (! Exist) {
-               AU = AV = IntegerLast ();
-       }
-       else {
-    // NKV - 11.02.08 - Use graphic driver functions
-    Standard_Boolean Result;
-
-    AVertex.Coord (AX, AY, AZ);
-
-    Result = MyGraphicDriver->ProjectRaster (TheCView, 
-      Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
-      AU, AV);
-
-    // the old code
-    if (!Result) {
-
-      Standard_Real PtX, PtY, PtZ, PtT;
-      Standard_Real APX, APY, APZ;
-      Standard_Real APT;
-
-      Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-#ifdef DEB
-      Standard_Integer Length = MyDefinedView.Extent ();
-#else
-      MyDefinedView.Extent ();
-#endif
-
-      Standard_Integer stop = 0;
-
-      while ((! stop) && (MyIterator.More ())) {
-       if (TheCView.ViewId ==
-           (MyIterator.Value ())->Identification ()) {
-         Ori_Matrix    =
-           (MyIterator.Value ())->MatrixOfOrientation ();
-         Map_Matrix    =
-           (MyIterator.Value ())->MatrixOfMapping ();
-         stop  = 1;
-       }
-
-       // MyIterator.Next () is located on the next view
-       MyIterator.Next ();
-      }
+Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::ActivatedView () const
+{
 
+  Handle(Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView();
 
-      // WCS -> View Reference Coordinate Space
-      PtX      = Ori_Matrix (0, 0) * AX
-               + Ori_Matrix (0, 1) * AY
-               + Ori_Matrix (0, 2) * AZ
-               + Ori_Matrix (0, 3);
-      PtY      = Ori_Matrix (1, 0) * AX
-               + Ori_Matrix (1, 1) * AY
-               + Ori_Matrix (1, 2) * AZ
-               + Ori_Matrix (1, 3);
-      PtZ      = Ori_Matrix (2, 0) * AX
-               + Ori_Matrix (2, 1) * AY
-               + Ori_Matrix (2, 2) * AZ
-               + Ori_Matrix (2, 3);
-      PtT      = Ori_Matrix (3, 0) * AX
-               + Ori_Matrix (3, 1) * AY
-               + Ori_Matrix (3, 2) * AZ
-               + Ori_Matrix (3, 3);
-
-      // VRCS -> Normalized Projection Coordinate Space
-      APX      = Map_Matrix (0, 0) * PtX
-               + Map_Matrix (0, 1) * PtY
-               + Map_Matrix (0, 2) * PtZ
-               + Map_Matrix (0, 3) * PtT;
-      APY      = Map_Matrix (1, 0) * PtX
-               + Map_Matrix (1, 1) * PtY
-               + Map_Matrix (1, 2) * PtZ
-               + Map_Matrix (1, 3) * PtT;
-      APZ      = Map_Matrix (2, 0) * PtX
-               + Map_Matrix (2, 1) * PtY
-               + Map_Matrix (2, 2) * PtZ
-               + Map_Matrix (2, 3) * PtT;
-      APT      = Map_Matrix (3, 0) * PtX
-               + Map_Matrix (3, 1) * PtY
-               + Map_Matrix (3, 2) * PtZ
-               + Map_Matrix (3, 3) * PtT;
-
-      if (APT == 0. || stop == 0) {
-       AU = AV = IntegerLast ();
-      }
-      else {
-       APX /= APT;
-       APY /= APT;
-       APZ /= APT;
-
-       // NPCS -> Device Coordinate Space
-       AWindow->Size (Width, Height);
-       Dx      = Standard_Real (Width);
-       Dy      = Standard_Real (Height);
-       Ratio   = Dx / Dy;
-       if (Ratio >= 1.) {
-         AU = Standard_Integer (APX * Dx);
-         AV = Standard_Integer (Dy - APY * Dy * Ratio);
-       }
-       else {
-         AU = Standard_Integer (APX * Dx / Ratio);
-         AV = Standard_Integer (Dy - APY * Dy);
-       }
-      }
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if ((MyDefinedView.Value(i))->IsActive ())
+    {
+      SG->Append(MyDefinedView.Value(i));
     }
   }
 
+  return (SG);
 }
 
-Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
-
-// Convert only if the data is correct
-Graphic3d_CView TheCView;
-Graphic3d_Vertex Point;
-
-       if (! ViewExists (AWindow, TheCView))
-           Point.SetCoord (RealLast (), RealLast (), RealLast ());
-       else {
-Standard_Integer Width, Height;
-Standard_ShortReal x, y, z;
-Standard_Boolean Result;
-
-           AWindow->Size (Width, Height);
-
-           Result      = MyGraphicDriver->UnProjectRaster (TheCView,
-                               0, 0, Width, Height,
-                               AU, AV, x, y, z);
-
-           // unproject is done by UnProjectRaster
-           if (Result) {
-               Point.SetCoord
-                   (Standard_Real (x), Standard_Real (y), Standard_Real (z));
-           }
-           // unproject cannot be done by UnProjectRaster
-           // Code suspended since drivers Phigs and Pex are abandoned.
-           else {
-
-Standard_Real NPCX, NPCY, NPCZ;
-Standard_Real VRCX, VRCY, VRCZ, VRCT;
-Standard_Real WCX, WCY, WCZ, WCT;
-
-TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
-TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
-TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
-TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
-
-Standard_Real Dx, Dy, Ratio;
-Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-Standard_Integer j;
-
-Standard_Integer stop = 0;
-
-Standard_Boolean BResult;
-
-               j = MyDefinedView.Extent ();
-
-               while ((! stop) && (MyIterator.More ())) {
-                   if (TheCView.ViewId ==
-                       (MyIterator.Value ())->Identification ()) {
-                       TOri_Matrix     =
-                               (MyIterator.Value ())->MatrixOfOrientation ();
-                       TMap_Matrix     =
-                               (MyIterator.Value ())->MatrixOfMapping ();
-                       stop    = 1;
-                   }
-
-                   // MyIterator.Next () is located on the next view
-                   MyIterator.Next ();
-               }
-
-               // View Mapping Transformation and View Clip, inversion
-               BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
-
-               // View Orientation Transformation, inversion
-               BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
-
-               // (AU, AV) : Device Coordinate Space
-               // DCS -> NPCS Normalized Projection Coordinate Space
-               Dx      = Standard_Real (Width);
-               Dy      = Standard_Real (Height);
-               Ratio   = Dx / Dy;
-
-               if (Ratio >= 1.) {
-                       NPCX    = Standard_Real (AU) / Dx;
-                       NPCY    = (Dy - Standard_Real (AV)) / Dx;
-               }
-               else {
-                       NPCX    = Standard_Real (AU) / Dy;
-                       NPCY    = (Dy - Standard_Real (AV)) / Dy;
-               }
-               NPCZ    = 0.0;
-
-               // NPCS -> VRCS View Reference Coordinate Space
-               // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
-
-               VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
-                       + TMap_Matrix_Inv (0, 1) * NPCY
-                       + TMap_Matrix_Inv (0, 2) * NPCZ
-                       + TMap_Matrix_Inv (0, 3);
-               VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
-                       + TMap_Matrix_Inv (1, 1) * NPCY
-                       + TMap_Matrix_Inv (1, 2) * NPCZ
-                       + TMap_Matrix_Inv (1, 3);
-               VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
-                       + TMap_Matrix_Inv (2, 1) * NPCY
-                       + TMap_Matrix_Inv (2, 2) * NPCZ
-                       + TMap_Matrix_Inv (2, 3);
-               VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
-                       + TMap_Matrix_Inv (3, 1) * NPCY
-                       + TMap_Matrix_Inv (3, 2) * NPCZ
-                       + TMap_Matrix_Inv (3, 3);
-
-               // VRCS -> WCS World Coordinate Space
-               // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
-
-               WCX     = TOri_Matrix_Inv (0, 0) * VRCX
-                       + TOri_Matrix_Inv (0, 1) * VRCY
-                       + TOri_Matrix_Inv (0, 2) * VRCZ
-                       + TOri_Matrix_Inv (0, 3) * VRCT;
-               WCY     = TOri_Matrix_Inv (1, 0) * VRCX
-                       + TOri_Matrix_Inv (1, 1) * VRCY
-                       + TOri_Matrix_Inv (1, 2) * VRCZ
-                       + TOri_Matrix_Inv (1, 3) * VRCT;
-               WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
-                       + TOri_Matrix_Inv (2, 1) * VRCY
-                       + TOri_Matrix_Inv (2, 2) * VRCZ
-                       + TOri_Matrix_Inv (2, 3) * VRCT;
-               WCT     = TOri_Matrix_Inv (3, 0) * VRCX
-                       + TOri_Matrix_Inv (3, 1) * VRCY
-                       + TOri_Matrix_Inv (3, 2) * VRCZ
-                       + TOri_Matrix_Inv (3, 3) * VRCT;
-
-               if (WCT != 0.)
-                   Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
-               else
-                   Point.SetCoord (RealLast (), RealLast (), RealLast ());
-           }
-       }
-
-       return (Point);
-
-}
-
-void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
-
-// Conversion only if the data is correct
-Graphic3d_CView TheCView;
+#ifdef IMPLEMENTED
+Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const
+{
+  Standard_Boolean Result = Standard_False;
 
-        if (! ViewExists (AWindow, TheCView)) {
-           Point.SetCoord (RealLast (), RealLast (), RealLast ());
-           Proj.SetCoord (0., 0., 0.);
-        }
-       else {
-Standard_Integer Width, Height;
-Standard_ShortReal x, y, z;
-Standard_ShortReal dx, dy, dz;
-Standard_Boolean Result;
-
-           AWindow->Size (Width, Height);
-
-           Result      = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
-                               0, 0, Width, Height,
-                               AU, AV, x, y, z, dx, dy, dz);
-
-           // unproject is done by UnProjectRaster
-           if (Result) {
-               Point.SetCoord
-                   (Standard_Real (x), Standard_Real (y), Standard_Real (z));
-               Proj.SetCoord
-                   (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
-                Proj.Normalize();
-           }
-           // unproject cannot be done by UnProjectRaster
-           // Code is suspended since drivers Phigs are Pex abandoned.
-           else {
-
-Standard_Real NPCX, NPCY, NPCZ;
-Standard_Real VRCX, VRCY, VRCZ, VRCT;
-Standard_Real WCX, WCY, WCZ, WCT;
-
-TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
-TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
-TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
-TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
-
-Standard_Real Dx, Dy, Ratio;
-Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-Standard_Integer j;
-
-Standard_Integer stop = 0;
-
-Standard_Boolean BResult;
-
-               j = MyDefinedView.Extent ();
-
-               while ((! stop) && (MyIterator.More ())) {
-                   if (TheCView.ViewId ==
-                       (MyIterator.Value ())->Identification ()) {
-                       TOri_Matrix     =
-                               (MyIterator.Value ())->MatrixOfOrientation ();
-                       TMap_Matrix     =
-                               (MyIterator.Value ())->MatrixOfMapping ();
-                       stop    = 1;
-                   }
-
-                   // MyIterator.Next () is located on the next view
-                   MyIterator.Next ();
-               }
-
-               // View Mapping Transformation and View Clip, inversion
-               BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
-
-               // View Orientation Transformation, inversion
-               BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
-
-               // (AU, AV) : Device Coordinate Space
-               // DCS -> NPCS Normalized Projection Coordinate Space
-               Dx      = Standard_Real (Width);
-               Dy      = Standard_Real (Height);
-               Ratio   = Dx / Dy;
-
-               if (Ratio >= 1.) {
-                       NPCX    = Standard_Real (AU) / Dx;
-                       NPCY    = (Dy - Standard_Real (AV)) / Dx;
-               }
-               else {
-                       NPCX    = Standard_Real (AU) / Dy;
-                       NPCY    = (Dy - Standard_Real (AV)) / Dy;
-               }
-               NPCZ    = 0.0;
-
-               // NPCS -> VRCS View Reference Coordinate Space
-               // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
-
-               VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
-                       + TMap_Matrix_Inv (0, 1) * NPCY
-                       + TMap_Matrix_Inv (0, 2) * NPCZ
-                       + TMap_Matrix_Inv (0, 3);
-               VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
-                       + TMap_Matrix_Inv (1, 1) * NPCY
-                       + TMap_Matrix_Inv (1, 2) * NPCZ
-                       + TMap_Matrix_Inv (1, 3);
-               VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
-                       + TMap_Matrix_Inv (2, 1) * NPCY
-                       + TMap_Matrix_Inv (2, 2) * NPCZ
-                       + TMap_Matrix_Inv (2, 3);
-               VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
-                       + TMap_Matrix_Inv (3, 1) * NPCY
-                       + TMap_Matrix_Inv (3, 2) * NPCZ
-                       + TMap_Matrix_Inv (3, 3);
-
-               // VRCS -> WCS World Coordinate Space
-               // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
-
-               WCX     = TOri_Matrix_Inv (0, 0) * VRCX
-                       + TOri_Matrix_Inv (0, 1) * VRCY
-                       + TOri_Matrix_Inv (0, 2) * VRCZ
-                       + TOri_Matrix_Inv (0, 3) * VRCT;
-               WCY     = TOri_Matrix_Inv (1, 0) * VRCX
-                       + TOri_Matrix_Inv (1, 1) * VRCY
-                       + TOri_Matrix_Inv (1, 2) * VRCZ
-                       + TOri_Matrix_Inv (1, 3) * VRCT;
-               WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
-                       + TOri_Matrix_Inv (2, 1) * VRCY
-                       + TOri_Matrix_Inv (2, 2) * VRCZ
-                       + TOri_Matrix_Inv (2, 3) * VRCT;
-               WCT     = TOri_Matrix_Inv (3, 0) * VRCX
-                       + TOri_Matrix_Inv (3, 1) * VRCY
-                       + TOri_Matrix_Inv (3, 2) * VRCZ
-                       + TOri_Matrix_Inv (3, 3) * VRCT;
-
-               if (WCT != 0.)
-                   Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
-               else
-                   Point.SetCoord (RealLast (), RealLast (), RealLast ());
-
-                // Define projection ray
-               NPCZ    = 10.0;
-
-               // NPCS -> VRCS View Reference Coordinate Space
-               // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
-
-               VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
-                       + TMap_Matrix_Inv (0, 1) * NPCY
-                       + TMap_Matrix_Inv (0, 2) * NPCZ
-                       + TMap_Matrix_Inv (0, 3);
-               VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
-                       + TMap_Matrix_Inv (1, 1) * NPCY
-                       + TMap_Matrix_Inv (1, 2) * NPCZ
-                       + TMap_Matrix_Inv (1, 3);
-               VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
-                       + TMap_Matrix_Inv (2, 1) * NPCY
-                       + TMap_Matrix_Inv (2, 2) * NPCZ
-                       + TMap_Matrix_Inv (2, 3);
-               VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
-                       + TMap_Matrix_Inv (3, 1) * NPCY
-                       + TMap_Matrix_Inv (3, 2) * NPCZ
-                       + TMap_Matrix_Inv (3, 3);
-
-               // VRCS -> WCS World Coordinate Space
-               // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
-
-               WCX     = TOri_Matrix_Inv (0, 0) * VRCX
-                       + TOri_Matrix_Inv (0, 1) * VRCY
-                       + TOri_Matrix_Inv (0, 2) * VRCZ
-                       + TOri_Matrix_Inv (0, 3) * VRCT;
-               WCY     = TOri_Matrix_Inv (1, 0) * VRCX
-                       + TOri_Matrix_Inv (1, 1) * VRCY
-                       + TOri_Matrix_Inv (1, 2) * VRCZ
-                       + TOri_Matrix_Inv (1, 3) * VRCT;
-               WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
-                       + TOri_Matrix_Inv (2, 1) * VRCY
-                       + TOri_Matrix_Inv (2, 2) * VRCZ
-                       + TOri_Matrix_Inv (2, 3) * VRCT;
-               WCT     = TOri_Matrix_Inv (3, 0) * VRCX
-                       + TOri_Matrix_Inv (3, 1) * VRCY
-                       + TOri_Matrix_Inv (3, 2) * VRCZ
-                       + TOri_Matrix_Inv (3, 3) * VRCT;
-
-                if (WCT != 0.) {
-                   Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
-                    Proj.Normalize();
-                }
-               else
-                   Proj.SetCoord (0., 0., 0.);
-           }
-       }
+  //
+  // Check all activated views
+  //
+  for(int i=1; (!Result) && i<=MyDefinedView.Length(); i++)
+  {
+    if ((MyDefinedView.Value(i))->IsActive())
+    {
+      Result = (MyDefinedView.Value(i))->ContainsComputedStructure();
+    }
+  }
 
+  return Result;
 }
-
-Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) {
-
-// The marking is activated only if the data is correct
-Standard_Boolean DoPick = Standard_False;
-
-CALL_DEF_PICK apick;
-Standard_Integer Width, Height;
-
-       // Parse the list of views to find a 
-       // view having this specified window
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       int TheWindowIdOfView;
-
-#ifndef WNT
-const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
-       int TheSpecifiedWindowId = int (THEWindow->XWindow ());
-#else
-const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
-       int TheSpecifiedWindowId = int (THEWindow->HWindow ());
-#endif  // WNT
-
-       while ((! DoPick) && (MyIterator.More ())) {
-
-          if ( ((MyIterator.Value ())->IsDefined ()) &&
-               ((MyIterator.Value ())->IsActive ()) ) {
-
-const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
-#ifndef WNT
-const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
-       TheWindowIdOfView = int (theWindow->XWindow ());
-#else
-const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
-       TheWindowIdOfView = int (theWindow->HWindow ());
-#endif  // WNT
-               // Comparision on window IDs
-               if (TheWindowIdOfView == TheSpecifiedWindowId) {
-                       DoPick          = Standard_True;
-
-                       // Update
-                       apick.WsId      =
-                       int ((MyIterator.Value ())->Identification ());
-
-                       apick.ViewId    =
-                       int ((MyIterator.Value ())->Identification ());
-#ifndef WNT
-                       apick.DefWindow.XWindow = TheSpecifiedWindowId;
-#else
-                       apick.DefWindow.XWindow = (HWND) TheSpecifiedWindowId;
 #endif
 
-                       apick.x                 = int (AX);
-                       apick.y                 = int (AY);
-
-                       theWindow->Size (Width, Height);
-                       apick.DefWindow.dx      = float (Width);
-                       apick.DefWindow.dy      = float (Height);
-
-                       apick.Context.aperture  = (float) CTX.Aperture ();
-                       apick.Context.order     = int (CTX.Order ());
-                       apick.Context.depth     = int (CTX.Depth ());
-
-               }
-          } /* if ((MyIterator.Value ())->IsDefined ()) { */
-
-          // MyIterator.Next () is located on the next view
-          MyIterator.Next ();
-       }
-
-       if (DoPick)
-               MyGraphicDriver->Pick (apick);
-       else
-               apick.Pick.depth        = 0;
-
-       // Picking : return
-Standard_Integer i, j=0;
-Standard_Integer NbPick;
-
-Visual3d_PickDescriptor PDes (CTX);
-Visual3d_PickPath PPat;
-
-       PDes.Clear ();
-       NbPick  = 0;
-       // For i=0 it is not a graphic structure it is a view structure
-       // For i=1 it is the displayed graphic structure
-       // For i=2 to apick.Pick.depth-1 it is the connected graphic structures
-       if (apick.Pick.depth != 0) {
-           j = apick.Pick.listid[1];
-           if ((Graphic3d_StructureManager::Identification (j))->
-                                               IsSelectable ()) {
-               // Maj element number
-               PPat.SetElementNumber (apick.Pick.listelem[1]);
-               // Maj pick identifier
-               PPat.SetPickIdentifier (apick.Pick.listpickid[1]);
-               // Maj structure
-               PPat.SetStructIdentifier
-                       (Graphic3d_StructureManager::Identification (j));
-               // Maj PickPath
-               PDes.AddPickPath (PPat);
-               NbPick++;
-           }
-       }
-
-       // Not very efficient, revise (CAL 22/09/95)
-       if (apick.Pick.depth > 2) {
-Handle(Graphic3d_Structure) StructCur =
-       Graphic3d_StructureManager::Identification (j);
-Standard_Boolean found;
-Graphic3d_MapOfStructure Set;
-
-           for (i=2; i<apick.Pick.depth; i++) {
-               found = Standard_False;
-               j = apick.Pick.listid[i-1];
-               Set.Clear ();
-               StructCur->Descendants (Set);
-Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set);
-
-               j = apick.Pick.listid[i];
-               while (IteratorD.More () && !found) {
-                   StructCur = IteratorD.Key ();
-                   if (StructCur->Identification () == j ) {
-                       found = Standard_True;
-                       // Maj element number
-                       PPat.SetElementNumber (apick.Pick.listelem[i]);
-                       // Maj pick identifier
-                       PPat.SetPickIdentifier (apick.Pick.listpickid[i]);
-                       // Maj structure
-                       PPat.SetStructIdentifier (StructCur);
-                       // Maj PickPath
-                       PDes.AddPickPath (PPat);
-                       NbPick++;
-                   }
-                   // IteratorD.Next () is located on the next structure
-                   IteratorD.Next ();
-               }
-           }
-       }
-
-       apick.Pick.depth        = int (NbPick);
-
-       MyGraphicDriver->InitPick ();
+Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::DefinedView () const
+{
+  Handle (Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView();
 
-       return (PDes);
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    SG->Append(MyDefinedView.Value(i));
+  }
 
+  return (SG);
 }
 
-Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
-
-Standard_Boolean Exist = Standard_False;
+Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const
+{
+  Standard_Boolean Exist = Standard_False;
 
-       // Parse the list of views to find
-       // a view with the specified window
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       int TheWindowIdOfView;
+  // Parse the list of views to find
+  // a view with the specified window
 
-#ifndef WNT
-const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
-       int TheSpecifiedWindowId = int (THEWindow->XWindow ());
+#if defined(_WIN32) || defined(__WIN32__)
+  const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
+  Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow ();
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+  const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
+  NSView* TheSpecifiedWindowId = THEWindow->HView();
 #else
-const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
-       int TheSpecifiedWindowId = int (THEWindow->HWindow ());
-#endif  // WNT
-
-       while ((! Exist) && (MyIterator.More ())) {
-
-          if ( ((MyIterator.Value ())->IsDefined ()) &&
-               ((MyIterator.Value ())->IsActive ()) ) {
+  const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
+  int TheSpecifiedWindowId = int (THEWindow->XWindow ());
+#endif
 
-const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
-#ifndef WNT
-const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
-       TheWindowIdOfView = int (theWindow->XWindow ());
+  for(int i=1; (!Exist) && i<=MyDefinedView.Length(); i++)
+  {
+    if ( ((MyDefinedView.Value(i))->IsDefined ()) && ((MyDefinedView.Value(i))->IsActive ()) )
+    {
+      const Handle(Aspect_Window) AspectWindow = (MyDefinedView.Value(i))->Window();
+
+#if defined(_WIN32) || defined(__WIN32__)
+      const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
+      Aspect_Handle TheWindowIdOfView = theWindow->HWindow ();
+#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
+      const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
+      NSView* TheWindowIdOfView = theWindow->HView();
 #else
-const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
-       TheWindowIdOfView = int (theWindow->HWindow ());
+      const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
+      int TheWindowIdOfView = int (theWindow->XWindow ());
 #endif  // WNT
-               // Comparaison on window IDs
-               if (TheWindowIdOfView == TheSpecifiedWindowId) {
-                       Exist   = Standard_True;
-                       TheCView        = *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
-               }
-          } /* if ((MyIterator.Value ())->IsDefined ()) */
-
-          // MyIterator.Next () is located on the next view
-          MyIterator.Next ();
-       }
-
-       return (Exist);
+      // Comparaison on window IDs
+      if (TheWindowIdOfView == TheSpecifiedWindowId)
+      {
+        Exist = Standard_True;
+        TheCView = *(Graphic3d_CView* )(MyDefinedView.Value(i))->CView();
+      }
+    }
+  }
 
+  return (Exist);
 }
 
-void Visual3d_ViewManager::Activate () {
-
-       //
-       // Activates all deactivated views
-       //
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-
-       while (MyIterator.More ()) {
-               if (! (MyIterator.Value ())->IsActive ())
-                       (MyIterator.Value ())->Activate ();
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
-
+void Visual3d_ViewManager::Activate ()
+{
+  //
+  // Activates all deactivated views
+  //
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if (! (MyDefinedView.Value(i))->IsActive())
+    {
+      (MyDefinedView.Value(i))->Activate();
+    }
+  }
 }
 
-void Visual3d_ViewManager::Deactivate () {
-
-       //
-       // Deactivates all activated views
-       //
-#ifdef DEB
-       Standard_Integer Length = MyDefinedView.Extent ();
-#else
-        MyDefinedView.Extent ();
-#endif
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               if ((MyIterator.Value ())->IsActive ())
-                       (MyIterator.Value ())->Deactivate ();
-
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
+void Visual3d_ViewManager::Deactivate ()
+{
+  //
+  // Deactivates all activated views
+  //
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if ((MyDefinedView.Value(i))->IsActive())
+    {
+      (MyDefinedView.Value(i))->Deactivate();
+    }
+  }
 
 }
 
@@ -1231,74 +537,76 @@ Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard
 }
 
 Standard_Integer Visual3d_ViewManager::Identification () const {
+
        return (Graphic3d_StructureManager::Identification ());
 
 }
 
-Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
-
-       MyDefinedView.Add (AView);
-       return (MyViewGenId.Next ());
-
+Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView)
+{
+  MyDefinedView.Append(AView);
+  return (MyViewGenId.Next ());
 }
 
 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
 {
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if ((MyDefinedView.Value(i))->Identification() == aViewId)
+    {
+      //remove the view from the list
+      MyDefinedView.Remove(i);
+      break;
+    }
+  }
+
   MyViewGenId.Free(aViewId);
 }
 
-void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
-
-       if (MyTransparency && AFlag) return;
-       if (! MyTransparency && ! AFlag) return;
-
-       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-       while (MyIterator.More ()) {
-               (MyIterator.Value ())->SetTransparency (AFlag);
-               // MyIterator.Next () is located on the next view
-               MyIterator.Next ();
-       }
+void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag)
+{
+  if (MyTransparency && AFlag) return;
+  if (! MyTransparency && ! AFlag) return;
 
-       MyTransparency  = AFlag;
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->SetTransparency(AFlag);
+  }
 
+  MyTransparency = AFlag;
 }
 
-Standard_Boolean Visual3d_ViewManager::Transparency () const {
-
-       return (MyTransparency);
-
+Standard_Boolean Visual3d_ViewManager::Transparency () const
+{
+  return (MyTransparency);
 }
 
-void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
-
-       if (MyZBufferAuto && AFlag) return;
-       if (! MyZBufferAuto && ! AFlag) return;
-
-       // if pass from False to True :
-       // no problem, at the next view update, it 
-       // will properly ask questions to answer (SetVisualisation)
-       // if pass from True to False :
-       // it is necessary to modify ZBufferActivity at each view so that
-       // zbuffer could be active only if required by context.
-       // In this case -1 is passed so that the view ask itself the question
-       // Note : 0 forces the desactivation, 1 forces the activation
-       if (! AFlag) {
-               Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
-               while (MyIterator.More ()) {
-                       (MyIterator.Value ())->SetZBufferActivity (-1);
-                       // MyIterator.Next () is located on the next view
-                       MyIterator.Next ();
-               }
-       }
-       MyZBufferAuto   = AFlag;
-
+void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag)
+{
+  if (MyZBufferAuto && AFlag) return;
+  if (! MyZBufferAuto && ! AFlag) return;
+
+  // if pass from False to True :
+  // no problem, at the next view update, it
+  // will properly ask questions to answer (SetVisualisation)
+  // if pass from True to False :
+  // it is necessary to modify ZBufferActivity at each view so that
+  // zbuffer could be active only if required by context.
+  // In this case -1 is passed so that the view ask itself the question
+  // Note : 0 forces the desactivation, 1 forces the activation
+  if (! AFlag)
+  {
+    for(int i=1; i<=MyDefinedView.Length(); i++)
+    {
+      (MyDefinedView.Value(i))->SetZBufferActivity(-1);
+    }
+  }
+  MyZBufferAuto = AFlag;
 }
 
-Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
-
-       return (MyZBufferAuto);
-
+Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const
+{
+  return (MyZBufferAuto);
 }
 
 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
@@ -1339,3 +647,196 @@ const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
        return (MyOverLayer);
 
 }
+
+//=======================================================================
+//function : ChangeZLayer
+//purpose  :
+//=======================================================================
+
+void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
+                                         const Standard_Integer theLayerId)
+{
+  if (!myLayerIds.Contains (theLayerId))
+    return;
+
+  // change display layer for structure in all views
+  if (MyDisplayedStructure.Contains (theStructure))
+  {
+    for(int i=1; i<=MyDefinedView.Length(); i++)
+    {
+      (MyDefinedView.Value(i))->ChangeZLayer(theStructure, theLayerId);
+    }
+  }
+
+  // tell graphic driver to update the structure's display layer
+  MyGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), theLayerId);
+}
+
+//=======================================================================
+//function : GetZLayer
+//purpose  :
+//=======================================================================
+
+Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
+{
+  return MyGraphicDriver->GetZLayer (*theStructure->CStructure ());
+}
+
+//=======================================================================
+//function : SetZLayerSettings
+//purpose  :
+//=======================================================================
+void Visual3d_ViewManager::SetZLayerSettings (const Standard_Integer theLayerId,
+                                              const Graphic3d_ZLayerSettings& theSettings)
+{
+  // tell all managed views to set zlayer settings
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->SetZLayerSettings (theLayerId, theSettings);
+  }
+
+  if (myMapOfZLayerSettings.IsBound (theLayerId))
+  {
+    myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings;
+  }
+  else
+  {
+    myMapOfZLayerSettings.Bind (theLayerId, theSettings);
+  }
+  
+}
+
+//=======================================================================
+//function : ZLayerSettings
+//purpose  :
+//=======================================================================
+Graphic3d_ZLayerSettings Visual3d_ViewManager::ZLayerSettings (const Standard_Integer theLayerId)
+{
+  if (!myLayerIds.Contains (theLayerId))
+  {
+    return Graphic3d_ZLayerSettings();
+  }
+
+  return myMapOfZLayerSettings.Find (theLayerId);
+}
+
+//=======================================================================
+//function : AddZLayer
+//purpose  :
+//=======================================================================
+
+Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
+{
+  try
+  {
+    OCC_CATCH_SIGNALS
+    theLayerId = getZLayerGenId ().Next ();
+    myLayerIds.Add (theLayerId);
+    myLayerSeq.Append (theLayerId);
+  }
+  catch (Aspect_IdentDefinitionError)
+  {
+    // new index can't be generated
+    return Standard_False;
+  }
+
+  // default z-layer settings
+  myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
+
+  // tell all managed views to remove display layers
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->AddZLayer(theLayerId);
+  }
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : RemoveZLayer
+//purpose  :
+//=======================================================================
+
+Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
+{
+  if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
+    return Standard_False;
+
+  // tell all managed views to remove display layers
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    (MyDefinedView.Value(i))->RemoveZLayer (theLayerId);
+  }
+
+  MyGraphicDriver->UnsetZLayer (theLayerId);
+
+  // remove index
+  for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
+  {
+    if (myLayerSeq (aIdx) == theLayerId)
+    {
+      myLayerSeq.Remove (aIdx);
+      break;
+    }
+  }
+
+  myMapOfZLayerSettings.UnBind (theLayerId);
+
+  myLayerIds.Remove (theLayerId);
+  getZLayerGenId ().Free (theLayerId);
+
+  return Standard_True;
+}
+
+//=======================================================================
+//function : GetAllZLayers
+//purpose  :
+//=======================================================================
+
+void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
+{
+  theLayerSeq.Assign (myLayerSeq);
+}
+
+//=======================================================================
+//function : getZLayerGenId
+//purpose  :
+//=======================================================================
+
+Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
+{
+  static Aspect_GenId aGenId (1, IntegerLast());
+  return aGenId;
+}
+
+//=======================================================================
+//function : InstallZLayers
+//purpose  :
+//=======================================================================
+
+void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
+{
+  Standard_Boolean isContainsView = Standard_False;
+  for(int i=1; i<=MyDefinedView.Length(); i++)
+  {
+    if(MyDefinedView.Value(i) == theView)
+    {
+      isContainsView = Standard_True;
+      break;
+    }
+  }
+  if (!isContainsView)
+    return;
+
+  // erase and insert layers iteratively to provide the same layer order as
+  // in the view manager's sequence. This approach bases on the layer insertion
+  // order: the new layers are always appended to the end of the list
+  // inside of view, while layer remove operation doesn't affect the order.
+  // Starting from second layer : no need to change the default z layer.
+  for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
+  {
+    Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
+    theView->RemoveZLayer (aLayerID);
+    theView->AddZLayer (aLayerID);
+  }
+}