0024276: Memory leak due to a static variable
[occt.git] / src / Visual3d / Visual3d_ViewManager.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 /***********************************************************************
21
22      FONCTION :
23      ----------
24         Classe Visual3d_ViewManager.cxx :
25
26         Declaration of variables specific to visualisers
27
28      HISTORIQUE DES MODIFICATIONS   :
29      --------------------------------
30       Mars 1992 : NW,JPB,CAL ; Creation.
31       19-06-96  : FMN ; Suppression variables inutiles
32       04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
33       06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
34       19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
35       24-10-97  : CAL ; Retrait de DownCast.
36       20-11-97  : CAL ; Disparition de la dependance avec math
37       01-12-97  : CAL ; Retrait du test IsActive sur l'Update et le Redraw
38       31-12-97  : CAL ; Disparition de MathGra
39       16-01-98  : CAL ; Ajout du SetTransform sur une TOS_COMPUTED
40       11-03-98  : CAL ; Visual3d_ViewManager::Remove ()
41       20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
42       10-06-98  : CAL ; Modification des signatures de xxProjectRaster.
43       10-06-98  : CAL ; Modification de la signature de ViewExists.
44       01-12-98  : CAL ; S4062. Ajout des layers.
45       02-12-98  : CAL ; Remove () ne detruit plus les vues.
46
47 ************************************************************************/
48
49 /*----------------------------------------------------------------------*/
50 /*
51  * Constants
52  */
53
54 #define NO_DOWNCAST
55 #define NO_DESTROY
56
57 /*----------------------------------------------------------------------*/
58 /*
59  * Includes
60  */
61
62 // for the class
63 #include <Visual3d_ViewManager.ixx>
64 #include <Visual3d_ViewManager.pxx>
65
66 #include <Standard_ErrorHandler.hxx>
67
68 #include <Aspect.hxx>
69 #include <Aspect_IdentDefinitionError.hxx>
70
71 #include <Graphic3d_GraphicDriver.hxx>
72 #include <Graphic3d_MapOfStructure.hxx>
73 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
74
75 #include <Visual3d_PickPath.hxx>
76 #include <Visual3d_SetIteratorOfSetOfView.hxx>
77
78 #if defined (_WIN32) || defined(__WIN32__)
79 # include <WNT_Window.hxx>
80 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
81 # include <Cocoa_Window.hxx>
82 #else
83 # include <Xw_Window.hxx>
84 #endif
85
86 //-Aliases
87
88 //-Global data definitions
89
90 //      -- les vues definies
91 //      MyDefinedView           :       SetOfView;
92
93 //      -- le generateur d'identificateurs de vues
94 //      MyViewGenId             :       GenId;
95
96 //-Constructors
97
98 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
99 Graphic3d_StructureManager (theDriver),
100 MyDefinedView (),
101 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),
102 MyZBufferAuto (Standard_False),
103 MyTransparency (Standard_False)
104 {
105   // default layer is always presented in display layer sequence
106   // it can not be removed
107   myLayerIds.Add (0);
108   myLayerSeq.Append (0);
109
110   MyGraphicDriver = theDriver;
111 }
112
113 //-Destructors
114
115 void Visual3d_ViewManager::Destroy () {
116
117 #ifdef DESTROY
118         cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
119 #endif
120
121         Remove ();
122 }
123
124 //-Methods, in order
125
126 void Visual3d_ViewManager::Remove () {
127
128 #ifdef DESTROY
129         cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
130 #endif
131
132         //
133         // Destroy all defined views
134         //
135
136 #ifdef DESTROY
137         cout << "The Manager " << MyId << " have " << Length << " defined views\n";
138         cout << flush;
139 #endif
140
141   // clear all structures whilst views are alive for correct GPU memory management
142   MyDisplayedStructure.Clear();
143   MyHighlightedStructure.Clear();
144   MyPickStructure.Clear();
145
146   // clear list of managed views
147   MyDefinedView.Clear();
148 }
149
150 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {
151
152 #ifdef TRACE
153         cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
154              << AStructure->Identification ()
155              << ", " << OldPriority << ", " << NewPriority << ")\n";
156         cout << flush;
157 #endif
158
159         //
160         // Change structure priority in all defined views
161         //
162         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
163
164         while (MyIterator.More ()) {
165                 (MyIterator.Value ())->ChangeDisplayPriority
166                         (AStructure, OldPriority, NewPriority);
167
168                 // MyIterator.Next () is located on the next view
169                 MyIterator.Next ();
170         }
171
172 }
173
174 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
175
176   //Standard_Integer LengthD    = MyDisplayedStructure.Extent() ();
177
178   // Even if physically the structure cannot
179   // be displayed (pb of visualisation type)
180   // it has status Displayed.
181
182   if (!MyDisplayedStructure.Contains(AStructure))
183     return;
184
185   //
186   // Recompute structure in all activated views
187   //
188   Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
189
190   while (MyIterator.More ()) {
191     (MyIterator.Value ())->ReCompute (AStructure);
192
193     // MyIterator.Next () is located on the next view
194     MyIterator.Next ();
195   }
196
197 }
198
199 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
200                                       const Handle(Graphic3d_DataStructureManager)& AProjector)
201 {
202
203   if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
204
205 #ifdef DOWNCAST
206   Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
207 #else
208   Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
209 #endif
210   Standard_Integer ViewId = theView->Identification ();
211
212   // Even if physically the structure cannot
213   // be displayed (pb of visualisation type)
214   // it has status Displayed.
215   if (!MyDisplayedStructure.Contains(AStructure))
216     return;
217
218   //
219   // Recompute structure in all activated views
220   //
221   Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
222
223   while (MyIterator.More ()) {
224     if ((MyIterator.Value ())->Identification () == ViewId)
225       theView->ReCompute (AStructure);
226
227     // MyIterator.Next () is located on the next view
228     MyIterator.Next ();
229   }
230
231 }
232
233 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {
234
235         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
236
237         while (MyIterator.More ()) {
238                 (MyIterator.Value ())->Clear (AStructure, WithDestruction);
239
240                 // MyIterator.Next ()  is located on the next view
241                 MyIterator.Next ();
242         }
243
244 }
245
246 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
247
248         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
249
250         while (MyIterator.More ()) {
251                 (MyIterator.Value ())->Connect (AMother, ADaughter);
252
253                 // MyIterator.Next ()  is located on the next view
254                 MyIterator.Next ();
255         }
256
257 }
258
259 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {
260
261         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
262
263         while (MyIterator.More ()) {
264                 (MyIterator.Value ())->Disconnect (AMother, ADaughter);
265
266                 // MyIterator.Next ()  is located on the next view
267                 MyIterator.Next ();
268         }
269
270 }
271
272 void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) {
273
274
275  // Even if physically the structure cannot
276   // be displayed (pb of visualisation type)
277   // it has status Displayed.
278
279   MyDisplayedStructure.Add(AStructure);
280
281         //
282         // Display structure in all activated views
283         //
284         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
285
286         while (MyIterator.More ()) {
287                 (MyIterator.Value ())->Display (AStructure);
288
289                 // MyIterator.Next () is located on the next view
290                 MyIterator.Next ();
291         }
292
293 }
294
295 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {
296
297
298 // Even if physically the structure cannot
299   // be displayed (pb of visualisation type)
300   // it has status Displayed.
301
302  MyDisplayedStructure.Remove(AStructure);
303
304
305
306         //
307         // Erase structure in all defined views
308         //
309         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
310
311         while (MyIterator.More ()) {
312                 (MyIterator.Value ())->Erase (AStructure);
313
314                 // MyIterator.Next () is located on the next view
315                 MyIterator.Next ();
316         }
317
318         MyHighlightedStructure.Remove (AStructure);
319         MyPickStructure.Remove (AStructure);
320
321 }
322
323 void Visual3d_ViewManager::Erase () {
324
325  Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
326
327  for (; it.More(); it.Next()) {
328    Handle(Graphic3d_Structure) SG = it.Key();
329    SG->Erase();
330  }
331
332 }
333
334 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {
335
336   MyHighlightedStructure.Add(AStructure);
337
338         //
339         // Highlight in all activated views
340         //
341         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
342
343         while (MyIterator.More ()) {
344                 (MyIterator.Value ())->Highlight (AStructure, AMethod);
345
346                 // MyIterator.Next () is located on the next view
347                 MyIterator.Next ();
348         }
349
350 }
351
352 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {
353
354         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
355
356         while (MyIterator.More ()) {
357                 (MyIterator.Value ())->SetTransform (AStructure, ATrsf);
358
359                 // MyIterator.Next () is located on the next view
360                 MyIterator.Next ();
361         }
362
363 }
364
365 void Visual3d_ViewManager::UnHighlight () {
366
367   Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
368
369   for (; it.More(); it.Next()) {
370     Handle(Graphic3d_Structure) SG = it.Key();
371     SG->UnHighlight ();
372   }
373
374
375 }
376
377 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {
378
379   MyHighlightedStructure.Remove(AStructure);
380
381
382         //
383         // UnHighlight in all activated views
384         //
385         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
386
387         while (MyIterator.More ()) {
388                 (MyIterator.Value ())->UnHighlight (AStructure);
389
390                 // MyIterator.Next () is located on the next view
391                 MyIterator.Next ();
392         }
393
394 }
395
396 void Visual3d_ViewManager::Redraw () const {
397
398 Standard_Integer MaxDx, MaxDy;
399 Standard_Integer Dx, Dy;
400         MaxDx = MaxDy = IntegerFirst ();
401
402         //
403         // Redraw all activated views
404         //
405         Standard_Integer j = MyDefinedView.Extent ();
406         if (j == 0) return;
407         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
408
409         if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
410             while (MyIterator.More ()) {
411                 (MyIterator.Value ())->Window ()->Size (Dx, Dy);
412                 if (Dx > MaxDx) MaxDx = Dx;
413                 if (Dy > MaxDy) MaxDy = Dy;
414
415                 // MyIterator.Next () is located on the next view
416                 MyIterator.Next ();
417             }
418             if (! MyUnderLayer.IsNull ())
419                 MyUnderLayer->SetViewport (MaxDx, MaxDy);
420             if (! MyOverLayer.IsNull ())
421                 MyOverLayer->SetViewport (MaxDx, MaxDy);
422         }
423
424         if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
425             MyIterator.Initialize (MyDefinedView);
426         while (MyIterator.More ()) {
427             (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);
428
429             // MyIterator.Next () is located on the next view
430             MyIterator.Next ();
431         }
432
433 }
434
435 void Visual3d_ViewManager::Update () const {
436
437         //
438         // Update all activated views
439         //
440         Standard_Integer j = MyDefinedView.Extent ();
441         if (j == 0) return;
442         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
443
444         while (MyIterator.More ()) {
445                 (MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);
446
447                 // MyIterator.Next () is located on the next view
448                 MyIterator.Next ();
449         }
450
451 }
452
453 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {
454
455 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
456
457 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
458
459         while (MyIterator.More ()) {
460                 if ((MyIterator.Value ())->IsActive ())
461                         SG->Add (MyIterator.Value ());
462
463                 // MyIterator.Next () is located on the next view
464                 MyIterator.Next ();
465         }
466
467         return (SG);
468
469 }
470
471 #ifdef IMPLEMENTED
472 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {
473
474 Standard_Boolean Result = Standard_False;
475
476         //
477         // Check all activated views
478         //
479         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
480
481         Standard_Integer i      = MyDefinedView.Extent ();
482
483         while ((! Result) && (MyIterator.More ())) {
484                 if ((MyIterator.Value ())->IsActive ())
485                         Result  =
486                         (MyIterator.Value ())->ContainsComputedStructure ();
487
488                 // MyIterator.Next () is located on the next view
489                 MyIterator.Next ();
490         }
491
492         return Result;
493 }
494 #endif
495
496 Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {
497
498 Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();
499
500 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
501
502         while (MyIterator.More ()) {
503                 SG->Add (MyIterator.Value ());
504
505                 // MyIterator.Next () is located on the next view
506                 MyIterator.Next ();
507         }
508
509         return (SG);
510
511 }
512
513 void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {
514
515 // Convert only if the data is correct
516 Standard_Boolean Exist;
517 Graphic3d_CView  TheCView;
518 //Graphic3d_Vertex Point;
519
520 TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
521 TColStd_Array2OfReal Map_Matrix (0,3,0,3);
522
523 Standard_Integer Width, Height;
524 Standard_Real AX, AY, AZ;
525 Standard_Real Dx, Dy, Ratio;
526
527         Exist   = ViewExists (AWindow, TheCView);
528
529         if (! Exist) {
530                 AU = AV = IntegerLast ();
531         }
532         else {
533     // NKV - 11.02.08 - Use graphic driver functions
534     Standard_Boolean Result;
535
536     AVertex.Coord (AX, AY, AZ);
537
538     Result = MyGraphicDriver->ProjectRaster (TheCView,
539       Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
540       AU, AV);
541
542     // the old code
543     if (!Result) {
544
545       Standard_Real PtX, PtY, PtZ, PtT;
546       Standard_Real APX, APY, APZ;
547       Standard_Real APT;
548
549       Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
550
551       Standard_Integer stop = 0;
552
553       while ((! stop) && (MyIterator.More ())) {
554         if (TheCView.ViewId ==
555             (MyIterator.Value ())->Identification ()) {
556           Ori_Matrix    =
557             (MyIterator.Value ())->MatrixOfOrientation ();
558           Map_Matrix    =
559             (MyIterator.Value ())->MatrixOfMapping ();
560           stop  = 1;
561         }
562
563         // MyIterator.Next () is located on the next view
564         MyIterator.Next ();
565       }
566
567
568       // WCS -> View Reference Coordinate Space
569       PtX       = Ori_Matrix (0, 0) * AX
570                 + Ori_Matrix (0, 1) * AY
571                 + Ori_Matrix (0, 2) * AZ
572                 + Ori_Matrix (0, 3);
573       PtY       = Ori_Matrix (1, 0) * AX
574                 + Ori_Matrix (1, 1) * AY
575                 + Ori_Matrix (1, 2) * AZ
576                 + Ori_Matrix (1, 3);
577       PtZ       = Ori_Matrix (2, 0) * AX
578                 + Ori_Matrix (2, 1) * AY
579                 + Ori_Matrix (2, 2) * AZ
580                 + Ori_Matrix (2, 3);
581       PtT       = Ori_Matrix (3, 0) * AX
582                 + Ori_Matrix (3, 1) * AY
583                 + Ori_Matrix (3, 2) * AZ
584                 + Ori_Matrix (3, 3);
585
586       // VRCS -> Normalized Projection Coordinate Space
587       APX       = Map_Matrix (0, 0) * PtX
588                 + Map_Matrix (0, 1) * PtY
589                 + Map_Matrix (0, 2) * PtZ
590                 + Map_Matrix (0, 3) * PtT;
591       APY       = Map_Matrix (1, 0) * PtX
592                 + Map_Matrix (1, 1) * PtY
593                 + Map_Matrix (1, 2) * PtZ
594                 + Map_Matrix (1, 3) * PtT;
595       APZ       = Map_Matrix (2, 0) * PtX
596                 + Map_Matrix (2, 1) * PtY
597                 + Map_Matrix (2, 2) * PtZ
598                 + Map_Matrix (2, 3) * PtT;
599       APT       = Map_Matrix (3, 0) * PtX
600                 + Map_Matrix (3, 1) * PtY
601                 + Map_Matrix (3, 2) * PtZ
602                 + Map_Matrix (3, 3) * PtT;
603
604       if (APT == 0. || stop == 0) {
605         AU = AV = IntegerLast ();
606       }
607       else {
608         APX /= APT;
609         APY /= APT;
610         APZ /= APT;
611
612         // NPCS -> Device Coordinate Space
613         AWindow->Size (Width, Height);
614         Dx      = Standard_Real (Width);
615         Dy      = Standard_Real (Height);
616         Ratio   = Dx / Dy;
617         if (Ratio >= 1.) {
618           AU = Standard_Integer (APX * Dx);
619           AV = Standard_Integer (Dy - APY * Dy * Ratio);
620         }
621         else {
622           AU = Standard_Integer (APX * Dx / Ratio);
623           AV = Standard_Integer (Dy - APY * Dy);
624         }
625       }
626     }
627   }
628
629 }
630
631 Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {
632
633 // Convert only if the data is correct
634 Graphic3d_CView TheCView;
635 Graphic3d_Vertex Point;
636
637         if (ViewExists (AWindow, TheCView))
638         {
639 Standard_Integer Width, Height;
640 Standard_ShortReal x, y, z;
641 Standard_Boolean Result;
642
643             AWindow->Size (Width, Height);
644
645             Result      = MyGraphicDriver->UnProjectRaster (TheCView,
646                                 0, 0, Width, Height,
647                                 AU, AV, x, y, z);
648
649             // unproject is done by UnProjectRaster
650             if (Result) {
651                 Point.SetCoord
652                     (Standard_Real (x), Standard_Real (y), Standard_Real (z));
653             }
654             // unproject cannot be done by UnProjectRaster
655             // Code suspended since drivers Phigs and Pex are abandoned.
656             else {
657
658 Standard_Real NPCX, NPCY, NPCZ;
659 Standard_Real VRCX, VRCY, VRCZ, VRCT;
660 Standard_Real WCX, WCY, WCZ, WCT;
661
662 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
663 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
664 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
665 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
666
667 Standard_Real Dx, Dy, Ratio;
668 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
669 Standard_Integer j;
670
671 Standard_Integer stop = 0;
672
673 Standard_Boolean BResult;
674
675                 j = MyDefinedView.Extent ();
676
677                 while ((! stop) && (MyIterator.More ())) {
678                     if (TheCView.ViewId ==
679                         (MyIterator.Value ())->Identification ()) {
680                         TOri_Matrix     =
681                                 (MyIterator.Value ())->MatrixOfOrientation ();
682                         TMap_Matrix     =
683                                 (MyIterator.Value ())->MatrixOfMapping ();
684                         stop    = 1;
685                     }
686
687                     // MyIterator.Next () is located on the next view
688                     MyIterator.Next ();
689                 }
690
691                 // View Mapping Transformation and View Clip, inversion
692                 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
693
694                 // View Orientation Transformation, inversion
695                 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
696
697                 // (AU, AV) : Device Coordinate Space
698                 // DCS -> NPCS Normalized Projection Coordinate Space
699                 Dx      = Standard_Real (Width);
700                 Dy      = Standard_Real (Height);
701                 Ratio   = Dx / Dy;
702
703                 if (Ratio >= 1.) {
704                         NPCX    = Standard_Real (AU) / Dx;
705                         NPCY    = (Dy - Standard_Real (AV)) / Dx;
706                 }
707                 else {
708                         NPCX    = Standard_Real (AU) / Dy;
709                         NPCY    = (Dy - Standard_Real (AV)) / Dy;
710                 }
711                 NPCZ    = 0.0;
712
713                 // NPCS -> VRCS View Reference Coordinate Space
714                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
715
716                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
717                         + TMap_Matrix_Inv (0, 1) * NPCY
718                         + TMap_Matrix_Inv (0, 2) * NPCZ
719                         + TMap_Matrix_Inv (0, 3);
720                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
721                         + TMap_Matrix_Inv (1, 1) * NPCY
722                         + TMap_Matrix_Inv (1, 2) * NPCZ
723                         + TMap_Matrix_Inv (1, 3);
724                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
725                         + TMap_Matrix_Inv (2, 1) * NPCY
726                         + TMap_Matrix_Inv (2, 2) * NPCZ
727                         + TMap_Matrix_Inv (2, 3);
728                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
729                         + TMap_Matrix_Inv (3, 1) * NPCY
730                         + TMap_Matrix_Inv (3, 2) * NPCZ
731                         + TMap_Matrix_Inv (3, 3);
732
733                 // VRCS -> WCS World Coordinate Space
734                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
735
736                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
737                         + TOri_Matrix_Inv (0, 1) * VRCY
738                         + TOri_Matrix_Inv (0, 2) * VRCZ
739                         + TOri_Matrix_Inv (0, 3) * VRCT;
740                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
741                         + TOri_Matrix_Inv (1, 1) * VRCY
742                         + TOri_Matrix_Inv (1, 2) * VRCZ
743                         + TOri_Matrix_Inv (1, 3) * VRCT;
744                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
745                         + TOri_Matrix_Inv (2, 1) * VRCY
746                         + TOri_Matrix_Inv (2, 2) * VRCZ
747                         + TOri_Matrix_Inv (2, 3) * VRCT;
748                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
749                         + TOri_Matrix_Inv (3, 1) * VRCY
750                         + TOri_Matrix_Inv (3, 2) * VRCZ
751                         + TOri_Matrix_Inv (3, 3) * VRCT;
752
753                 if (WCT != 0.)
754                     Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
755             }
756         }
757
758         return (Point);
759
760 }
761
762 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
763
764 // Conversion only if the data is correct
765 Graphic3d_CView TheCView;
766
767         if (! ViewExists (AWindow, TheCView)) {
768             Point.SetCoord (0., 0., 0.);
769             Proj.SetCoord (0., 0., 0.);
770         }
771         else {
772 Standard_Integer Width, Height;
773 Standard_ShortReal x, y, z;
774 Standard_ShortReal dx, dy, dz;
775 Standard_Boolean Result;
776
777             AWindow->Size (Width, Height);
778
779             Result      = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
780                                 0, 0, Width, Height,
781                                 AU, AV, x, y, z, dx, dy, dz);
782
783             // unproject is done by UnProjectRaster
784             if (Result) {
785                 Point.SetCoord
786                     (Standard_Real (x), Standard_Real (y), Standard_Real (z));
787                 Proj.SetCoord
788                     (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
789                 Proj.Normalize();
790             }
791             // unproject cannot be done by UnProjectRaster
792             // Code is suspended since drivers Phigs are Pex abandoned.
793             else {
794
795 Standard_Real NPCX, NPCY, NPCZ;
796 Standard_Real VRCX, VRCY, VRCZ, VRCT;
797 Standard_Real WCX, WCY, WCZ, WCT;
798
799 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
800 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
801 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
802 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
803
804 Standard_Real Dx, Dy, Ratio;
805 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
806 Standard_Integer j;
807
808 Standard_Integer stop = 0;
809
810 Standard_Boolean BResult;
811
812                 j = MyDefinedView.Extent ();
813
814                 while ((! stop) && (MyIterator.More ())) {
815                     if (TheCView.ViewId ==
816                         (MyIterator.Value ())->Identification ()) {
817                         TOri_Matrix     =
818                                 (MyIterator.Value ())->MatrixOfOrientation ();
819                         TMap_Matrix     =
820                                 (MyIterator.Value ())->MatrixOfMapping ();
821                         stop    = 1;
822                     }
823
824                     // MyIterator.Next () is located on the next view
825                     MyIterator.Next ();
826                 }
827
828                 // View Mapping Transformation and View Clip, inversion
829                 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
830
831                 // View Orientation Transformation, inversion
832                 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
833
834                 // (AU, AV) : Device Coordinate Space
835                 // DCS -> NPCS Normalized Projection Coordinate Space
836                 Dx      = Standard_Real (Width);
837                 Dy      = Standard_Real (Height);
838                 Ratio   = Dx / Dy;
839
840                 if (Ratio >= 1.) {
841                         NPCX    = Standard_Real (AU) / Dx;
842                         NPCY    = (Dy - Standard_Real (AV)) / Dx;
843                 }
844                 else {
845                         NPCX    = Standard_Real (AU) / Dy;
846                         NPCY    = (Dy - Standard_Real (AV)) / Dy;
847                 }
848                 NPCZ    = 0.0;
849
850                 // NPCS -> VRCS View Reference Coordinate Space
851                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
852
853                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
854                         + TMap_Matrix_Inv (0, 1) * NPCY
855                         + TMap_Matrix_Inv (0, 2) * NPCZ
856                         + TMap_Matrix_Inv (0, 3);
857                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
858                         + TMap_Matrix_Inv (1, 1) * NPCY
859                         + TMap_Matrix_Inv (1, 2) * NPCZ
860                         + TMap_Matrix_Inv (1, 3);
861                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
862                         + TMap_Matrix_Inv (2, 1) * NPCY
863                         + TMap_Matrix_Inv (2, 2) * NPCZ
864                         + TMap_Matrix_Inv (2, 3);
865                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
866                         + TMap_Matrix_Inv (3, 1) * NPCY
867                         + TMap_Matrix_Inv (3, 2) * NPCZ
868                         + TMap_Matrix_Inv (3, 3);
869
870                 // VRCS -> WCS World Coordinate Space
871                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
872
873                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
874                         + TOri_Matrix_Inv (0, 1) * VRCY
875                         + TOri_Matrix_Inv (0, 2) * VRCZ
876                         + TOri_Matrix_Inv (0, 3) * VRCT;
877                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
878                         + TOri_Matrix_Inv (1, 1) * VRCY
879                         + TOri_Matrix_Inv (1, 2) * VRCZ
880                         + TOri_Matrix_Inv (1, 3) * VRCT;
881                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
882                         + TOri_Matrix_Inv (2, 1) * VRCY
883                         + TOri_Matrix_Inv (2, 2) * VRCZ
884                         + TOri_Matrix_Inv (2, 3) * VRCT;
885                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
886                         + TOri_Matrix_Inv (3, 1) * VRCY
887                         + TOri_Matrix_Inv (3, 2) * VRCZ
888                         + TOri_Matrix_Inv (3, 3) * VRCT;
889
890                 if (WCT != 0.)
891                     Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
892                 else
893                     Point.SetCoord (0., 0., 0.);
894
895                 // Define projection ray
896                 NPCZ    = 10.0;
897
898                 // NPCS -> VRCS View Reference Coordinate Space
899                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
900
901                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
902                         + TMap_Matrix_Inv (0, 1) * NPCY
903                         + TMap_Matrix_Inv (0, 2) * NPCZ
904                         + TMap_Matrix_Inv (0, 3);
905                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
906                         + TMap_Matrix_Inv (1, 1) * NPCY
907                         + TMap_Matrix_Inv (1, 2) * NPCZ
908                         + TMap_Matrix_Inv (1, 3);
909                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
910                         + TMap_Matrix_Inv (2, 1) * NPCY
911                         + TMap_Matrix_Inv (2, 2) * NPCZ
912                         + TMap_Matrix_Inv (2, 3);
913                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
914                         + TMap_Matrix_Inv (3, 1) * NPCY
915                         + TMap_Matrix_Inv (3, 2) * NPCZ
916                         + TMap_Matrix_Inv (3, 3);
917
918                 // VRCS -> WCS World Coordinate Space
919                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
920
921                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
922                         + TOri_Matrix_Inv (0, 1) * VRCY
923                         + TOri_Matrix_Inv (0, 2) * VRCZ
924                         + TOri_Matrix_Inv (0, 3) * VRCT;
925                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
926                         + TOri_Matrix_Inv (1, 1) * VRCY
927                         + TOri_Matrix_Inv (1, 2) * VRCZ
928                         + TOri_Matrix_Inv (1, 3) * VRCT;
929                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
930                         + TOri_Matrix_Inv (2, 1) * VRCY
931                         + TOri_Matrix_Inv (2, 2) * VRCZ
932                         + TOri_Matrix_Inv (2, 3) * VRCT;
933                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
934                         + TOri_Matrix_Inv (3, 1) * VRCY
935                         + TOri_Matrix_Inv (3, 2) * VRCZ
936                         + TOri_Matrix_Inv (3, 3) * VRCT;
937
938                 if (WCT != 0.) {
939                     Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
940                     Proj.Normalize();
941                 }
942                 else
943                     Proj.SetCoord (0., 0., 0.);
944             }
945         }
946
947 }
948
949
950 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
951
952 Standard_Boolean Exist = Standard_False;
953
954         // Parse the list of views to find
955         // a view with the specified window
956         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
957
958 #if defined(_WIN32) || defined(__WIN32__)
959   const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
960   int TheSpecifiedWindowId = int (THEWindow->HWindow ());
961 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
962   const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
963   NSView* TheSpecifiedWindowId = THEWindow->HView();
964 #else
965   const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
966   int TheSpecifiedWindowId = int (THEWindow->XWindow ());
967 #endif
968
969         while ((! Exist) && (MyIterator.More ())) {
970
971            if ( ((MyIterator.Value ())->IsDefined ()) &&
972                 ((MyIterator.Value ())->IsActive ()) ) {
973
974 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
975 #if defined(_WIN32) || defined(__WIN32__)
976    const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
977    int TheWindowIdOfView = int (theWindow->HWindow ());
978 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
979    const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
980    NSView* TheWindowIdOfView = theWindow->HView();
981 #else
982    const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
983    int TheWindowIdOfView = int (theWindow->XWindow ());
984 #endif  // WNT
985                 // Comparaison on window IDs
986                 if (TheWindowIdOfView == TheSpecifiedWindowId) {
987                         Exist   = Standard_True;
988                         TheCView        = *(Graphic3d_CView* )(MyIterator.Value())->CView();
989                 }
990            } /* if ((MyIterator.Value ())->IsDefined ()) */
991
992            // MyIterator.Next () is located on the next view
993            MyIterator.Next ();
994         }
995
996         return (Exist);
997
998 }
999
1000 void Visual3d_ViewManager::Activate () {
1001
1002         //
1003         // Activates all deactivated views
1004         //
1005         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1006
1007         while (MyIterator.More ()) {
1008                 if (! (MyIterator.Value ())->IsActive ())
1009                         (MyIterator.Value ())->Activate ();
1010
1011                 // MyIterator.Next () is located on the next view
1012                 MyIterator.Next ();
1013         }
1014
1015 }
1016
1017 void Visual3d_ViewManager::Deactivate () {
1018
1019         //
1020         // Deactivates all activated views
1021         //
1022         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1023
1024         while (MyIterator.More ()) {
1025                 if ((MyIterator.Value ())->IsActive ())
1026                         (MyIterator.Value ())->Deactivate ();
1027
1028                 // MyIterator.Next () is located on the next view
1029                 MyIterator.Next ();
1030         }
1031
1032 }
1033
1034 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
1035
1036         // Retourne the planned of definable views for the current
1037         // Visual3d_ViewManager.
1038         return
1039 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
1040
1041 }
1042
1043 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
1044
1045         return (Graphic3d_StructureManager::Identification (AId));
1046
1047 }
1048
1049 Standard_Integer Visual3d_ViewManager::Identification () const {
1050
1051         return (Graphic3d_StructureManager::Identification ());
1052
1053 }
1054
1055 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
1056
1057         MyDefinedView.Add (AView);
1058         return (MyViewGenId.Next ());
1059
1060 }
1061
1062 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
1063 {
1064   Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1065   while (MyIterator.More()) 
1066   {
1067     if ((MyIterator.Value())->Identification () == aViewId)
1068     {
1069       const Handle(Visual3d_View)& theView = MyIterator.Value();
1070       //remove the view from the list
1071       MyDefinedView.Remove(theView);
1072       break;
1073     }
1074     // go to next
1075     MyIterator.Next ();
1076   }
1077   MyViewGenId.Free(aViewId);
1078 }
1079
1080 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1081
1082         if (MyTransparency && AFlag) return;
1083         if (! MyTransparency && ! AFlag) return;
1084
1085         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1086         while (MyIterator.More ()) {
1087                 (MyIterator.Value ())->SetTransparency (AFlag);
1088                 // MyIterator.Next () is located on the next view
1089                 MyIterator.Next ();
1090         }
1091
1092         MyTransparency  = AFlag;
1093
1094 }
1095
1096 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1097
1098         return (MyTransparency);
1099
1100 }
1101
1102 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1103
1104         if (MyZBufferAuto && AFlag) return;
1105         if (! MyZBufferAuto && ! AFlag) return;
1106
1107         // if pass from False to True :
1108         // no problem, at the next view update, it
1109         // will properly ask questions to answer (SetVisualisation)
1110         // if pass from True to False :
1111         // it is necessary to modify ZBufferActivity at each view so that
1112         // zbuffer could be active only if required by context.
1113         // In this case -1 is passed so that the view ask itself the question
1114         // Note : 0 forces the desactivation, 1 forces the activation
1115         if (! AFlag) {
1116                 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1117                 while (MyIterator.More ()) {
1118                         (MyIterator.Value ())->SetZBufferActivity (-1);
1119                         // MyIterator.Next () is located on the next view
1120                         MyIterator.Next ();
1121                 }
1122         }
1123         MyZBufferAuto   = AFlag;
1124
1125 }
1126
1127 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1128
1129         return (MyZBufferAuto);
1130
1131 }
1132
1133 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1134
1135 #ifdef TRACE_LAYER
1136         cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1137 #endif
1138
1139         if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1140 #ifdef TRACE_LAYER
1141                 if (MyOverLayer.IsNull ())
1142                         cout << "MyOverLayer is defined" << endl;
1143                 else
1144                         cout << "MyOverLayer is redefined" << endl;
1145 #endif
1146                 MyOverLayer = ALayer;
1147         }
1148         else {
1149 #ifdef TRACE_LAYER
1150                 if (MyUnderLayer.IsNull ())
1151                         cout << "MyUnderLayer is defined" << endl;
1152                 else
1153                         cout << "MyUnderLayer is redefined" << endl;
1154 #endif
1155                 MyUnderLayer = ALayer;
1156         }
1157
1158 }
1159
1160 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1161
1162         return (MyUnderLayer);
1163
1164 }
1165
1166 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1167
1168         return (MyOverLayer);
1169
1170 }
1171
1172 //=======================================================================
1173 //function : ChangeZLayer
1174 //purpose  :
1175 //=======================================================================
1176
1177 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1178                                          const Standard_Integer theLayerId)
1179 {
1180   if (!myLayerIds.Contains (theLayerId))
1181     return;
1182
1183   // change display layer for structure in all views
1184   if (MyDisplayedStructure.Contains (theStructure))
1185   {
1186     Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1187     for ( ; aViewIt.More (); aViewIt.Next ())
1188       (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1189   }
1190
1191   // tell graphic driver to update the structure's display layer
1192   MyGraphicDriver->ChangeZLayer (
1193     (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1194 }
1195
1196 //=======================================================================
1197 //function : GetZLayer
1198 //purpose  :
1199 //=======================================================================
1200
1201 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1202 {
1203   Graphic3d_CStructure& aStructure =
1204     (*(Graphic3d_CStructure*)theStructure->CStructure ());
1205
1206   return MyGraphicDriver->GetZLayer (aStructure);
1207 }
1208
1209 //=======================================================================
1210 //function : AddZLayer
1211 //purpose  :
1212 //=======================================================================
1213
1214 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1215 {
1216   try
1217   {
1218     OCC_CATCH_SIGNALS
1219     theLayerId = getZLayerGenId ().Next ();
1220     myLayerIds.Add (theLayerId);
1221     myLayerSeq.Append (theLayerId);
1222   }
1223   catch (Aspect_IdentDefinitionError)
1224   {
1225     // new index can't be generated
1226     return Standard_False;
1227   }
1228
1229   // tell all managed views to remove display layers
1230   Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1231   for ( ; aViewIt.More (); aViewIt.Next ())
1232     (aViewIt.Value ())->AddZLayer (theLayerId);
1233
1234   return Standard_True;
1235 }
1236
1237 //=======================================================================
1238 //function : RemoveZLayer
1239 //purpose  :
1240 //=======================================================================
1241
1242 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1243 {
1244   if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1245     return Standard_False;
1246
1247   // tell all managed views to remove display layers
1248   Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1249   for ( ; aViewIt.More (); aViewIt.Next ())
1250     (aViewIt.Value ())->RemoveZLayer (theLayerId);
1251
1252   MyGraphicDriver->UnsetZLayer (theLayerId);
1253
1254   // remove index
1255   for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1256     if (myLayerSeq(aIdx) == theLayerId)
1257     {
1258       myLayerSeq.Remove (aIdx);
1259       break;
1260     }
1261
1262   myLayerIds.Remove (theLayerId);
1263   getZLayerGenId ().Free (theLayerId);
1264
1265   return Standard_True;
1266 }
1267
1268 //=======================================================================
1269 //function : GetAllZLayers
1270 //purpose  :
1271 //=======================================================================
1272
1273 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1274 {
1275   theLayerSeq.Assign (myLayerSeq);
1276 }
1277
1278 //=======================================================================
1279 //function : getZLayerGenId
1280 //purpose  :
1281 //=======================================================================
1282
1283 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1284 {
1285   static Aspect_GenId aGenId (1, IntegerLast());
1286   return aGenId;
1287 }
1288
1289 //=======================================================================
1290 //function : InstallZLayers
1291 //purpose  :
1292 //=======================================================================
1293
1294 void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
1295 {
1296   if (!MyDefinedView.Contains (theView))
1297     return;
1298
1299   // erase and insert layers iteratively to provide the same layer order as
1300   // in the view manager's sequence. This approach bases on the layer insertion
1301   // order: the new layers are always appended to the end of the list
1302   // inside of view, while layer remove operation doesn't affect the order.
1303   // Starting from second layer : no need to change the default z layer.
1304   for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
1305   {
1306     Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
1307     theView->RemoveZLayer (aLayerID);
1308     theView->AddZLayer (aLayerID);
1309   }
1310 }