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