90ccd311e37acb452d372e5b4bfa93dce128bcf0
[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 #ifndef WNT
79 # include <Xw_Window.hxx>
80 #else
81 # include <WNT_Window.hxx>
82 #endif  // WNT
83
84 //-Aliases
85
86 //-Global data definitions
87
88 //      -- les vues definies
89 //      MyDefinedView           :       SetOfView;
90
91 //      -- le generateur d'identificateurs de vues
92 //      MyViewGenId             :       GenId;
93
94 //-Constructors
95
96 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
97 Graphic3d_StructureManager (aDevice),
98 MyDefinedView (),
99 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),
100 MyZBufferAuto (Standard_False),
101 MyTransparency (Standard_False)
102 {
103   // default layer is always presented in display layer sequence
104   // it can not be removed
105   myLayerIds.Add (0);
106   myLayerSeq.Append (0);
107
108   Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();
109
110   MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;
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             Point.SetCoord (RealLast (), RealLast (), RealLast ());
641         else {
642 Standard_Integer Width, Height;
643 Standard_ShortReal x, y, z;
644 Standard_Boolean Result;
645
646             AWindow->Size (Width, Height);
647
648             Result      = MyGraphicDriver->UnProjectRaster (TheCView,
649                                 0, 0, Width, Height,
650                                 AU, AV, x, y, z);
651
652             // unproject is done by UnProjectRaster
653             if (Result) {
654                 Point.SetCoord
655                     (Standard_Real (x), Standard_Real (y), Standard_Real (z));
656             }
657             // unproject cannot be done by UnProjectRaster
658             // Code suspended since drivers Phigs and Pex are abandoned.
659             else {
660
661 Standard_Real NPCX, NPCY, NPCZ;
662 Standard_Real VRCX, VRCY, VRCZ, VRCT;
663 Standard_Real WCX, WCY, WCZ, WCT;
664
665 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
666 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
667 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
668 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
669
670 Standard_Real Dx, Dy, Ratio;
671 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
672 Standard_Integer j;
673
674 Standard_Integer stop = 0;
675
676 Standard_Boolean BResult;
677
678                 j = MyDefinedView.Extent ();
679
680                 while ((! stop) && (MyIterator.More ())) {
681                     if (TheCView.ViewId ==
682                         (MyIterator.Value ())->Identification ()) {
683                         TOri_Matrix     =
684                                 (MyIterator.Value ())->MatrixOfOrientation ();
685                         TMap_Matrix     =
686                                 (MyIterator.Value ())->MatrixOfMapping ();
687                         stop    = 1;
688                     }
689
690                     // MyIterator.Next () is located on the next view
691                     MyIterator.Next ();
692                 }
693
694                 // View Mapping Transformation and View Clip, inversion
695                 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
696
697                 // View Orientation Transformation, inversion
698                 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
699
700                 // (AU, AV) : Device Coordinate Space
701                 // DCS -> NPCS Normalized Projection Coordinate Space
702                 Dx      = Standard_Real (Width);
703                 Dy      = Standard_Real (Height);
704                 Ratio   = Dx / Dy;
705
706                 if (Ratio >= 1.) {
707                         NPCX    = Standard_Real (AU) / Dx;
708                         NPCY    = (Dy - Standard_Real (AV)) / Dx;
709                 }
710                 else {
711                         NPCX    = Standard_Real (AU) / Dy;
712                         NPCY    = (Dy - Standard_Real (AV)) / Dy;
713                 }
714                 NPCZ    = 0.0;
715
716                 // NPCS -> VRCS View Reference Coordinate Space
717                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
718
719                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
720                         + TMap_Matrix_Inv (0, 1) * NPCY
721                         + TMap_Matrix_Inv (0, 2) * NPCZ
722                         + TMap_Matrix_Inv (0, 3);
723                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
724                         + TMap_Matrix_Inv (1, 1) * NPCY
725                         + TMap_Matrix_Inv (1, 2) * NPCZ
726                         + TMap_Matrix_Inv (1, 3);
727                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
728                         + TMap_Matrix_Inv (2, 1) * NPCY
729                         + TMap_Matrix_Inv (2, 2) * NPCZ
730                         + TMap_Matrix_Inv (2, 3);
731                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
732                         + TMap_Matrix_Inv (3, 1) * NPCY
733                         + TMap_Matrix_Inv (3, 2) * NPCZ
734                         + TMap_Matrix_Inv (3, 3);
735
736                 // VRCS -> WCS World Coordinate Space
737                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
738
739                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
740                         + TOri_Matrix_Inv (0, 1) * VRCY
741                         + TOri_Matrix_Inv (0, 2) * VRCZ
742                         + TOri_Matrix_Inv (0, 3) * VRCT;
743                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
744                         + TOri_Matrix_Inv (1, 1) * VRCY
745                         + TOri_Matrix_Inv (1, 2) * VRCZ
746                         + TOri_Matrix_Inv (1, 3) * VRCT;
747                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
748                         + TOri_Matrix_Inv (2, 1) * VRCY
749                         + TOri_Matrix_Inv (2, 2) * VRCZ
750                         + TOri_Matrix_Inv (2, 3) * VRCT;
751                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
752                         + TOri_Matrix_Inv (3, 1) * VRCY
753                         + TOri_Matrix_Inv (3, 2) * VRCZ
754                         + TOri_Matrix_Inv (3, 3) * VRCT;
755
756                 if (WCT != 0.)
757                     Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
758                 else
759                     Point.SetCoord (RealLast (), RealLast (), RealLast ());
760             }
761         }
762
763         return (Point);
764
765 }
766
767 void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {
768
769 // Conversion only if the data is correct
770 Graphic3d_CView TheCView;
771
772         if (! ViewExists (AWindow, TheCView)) {
773             Point.SetCoord (RealLast (), RealLast (), RealLast ());
774             Proj.SetCoord (0., 0., 0.);
775         }
776         else {
777 Standard_Integer Width, Height;
778 Standard_ShortReal x, y, z;
779 Standard_ShortReal dx, dy, dz;
780 Standard_Boolean Result;
781
782             AWindow->Size (Width, Height);
783
784             Result      = MyGraphicDriver->UnProjectRasterWithRay (TheCView,
785                                 0, 0, Width, Height,
786                                 AU, AV, x, y, z, dx, dy, dz);
787
788             // unproject is done by UnProjectRaster
789             if (Result) {
790                 Point.SetCoord
791                     (Standard_Real (x), Standard_Real (y), Standard_Real (z));
792                 Proj.SetCoord
793                     (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
794                 Proj.Normalize();
795             }
796             // unproject cannot be done by UnProjectRaster
797             // Code is suspended since drivers Phigs are Pex abandoned.
798             else {
799
800 Standard_Real NPCX, NPCY, NPCZ;
801 Standard_Real VRCX, VRCY, VRCZ, VRCT;
802 Standard_Real WCX, WCY, WCZ, WCT;
803
804 TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
805 TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
806 TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
807 TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);
808
809 Standard_Real Dx, Dy, Ratio;
810 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
811 Standard_Integer j;
812
813 Standard_Integer stop = 0;
814
815 Standard_Boolean BResult;
816
817                 j = MyDefinedView.Extent ();
818
819                 while ((! stop) && (MyIterator.More ())) {
820                     if (TheCView.ViewId ==
821                         (MyIterator.Value ())->Identification ()) {
822                         TOri_Matrix     =
823                                 (MyIterator.Value ())->MatrixOfOrientation ();
824                         TMap_Matrix     =
825                                 (MyIterator.Value ())->MatrixOfMapping ();
826                         stop    = 1;
827                     }
828
829                     // MyIterator.Next () is located on the next view
830                     MyIterator.Next ();
831                 }
832
833                 // View Mapping Transformation and View Clip, inversion
834                 BResult = Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);
835
836                 // View Orientation Transformation, inversion
837                 BResult = Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);
838
839                 // (AU, AV) : Device Coordinate Space
840                 // DCS -> NPCS Normalized Projection Coordinate Space
841                 Dx      = Standard_Real (Width);
842                 Dy      = Standard_Real (Height);
843                 Ratio   = Dx / Dy;
844
845                 if (Ratio >= 1.) {
846                         NPCX    = Standard_Real (AU) / Dx;
847                         NPCY    = (Dy - Standard_Real (AV)) / Dx;
848                 }
849                 else {
850                         NPCX    = Standard_Real (AU) / Dy;
851                         NPCY    = (Dy - Standard_Real (AV)) / Dy;
852                 }
853                 NPCZ    = 0.0;
854
855                 // NPCS -> VRCS View Reference Coordinate Space
856                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
857
858                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
859                         + TMap_Matrix_Inv (0, 1) * NPCY
860                         + TMap_Matrix_Inv (0, 2) * NPCZ
861                         + TMap_Matrix_Inv (0, 3);
862                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
863                         + TMap_Matrix_Inv (1, 1) * NPCY
864                         + TMap_Matrix_Inv (1, 2) * NPCZ
865                         + TMap_Matrix_Inv (1, 3);
866                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
867                         + TMap_Matrix_Inv (2, 1) * NPCY
868                         + TMap_Matrix_Inv (2, 2) * NPCZ
869                         + TMap_Matrix_Inv (2, 3);
870                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
871                         + TMap_Matrix_Inv (3, 1) * NPCY
872                         + TMap_Matrix_Inv (3, 2) * NPCZ
873                         + TMap_Matrix_Inv (3, 3);
874
875                 // VRCS -> WCS World Coordinate Space
876                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
877
878                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
879                         + TOri_Matrix_Inv (0, 1) * VRCY
880                         + TOri_Matrix_Inv (0, 2) * VRCZ
881                         + TOri_Matrix_Inv (0, 3) * VRCT;
882                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
883                         + TOri_Matrix_Inv (1, 1) * VRCY
884                         + TOri_Matrix_Inv (1, 2) * VRCZ
885                         + TOri_Matrix_Inv (1, 3) * VRCT;
886                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
887                         + TOri_Matrix_Inv (2, 1) * VRCY
888                         + TOri_Matrix_Inv (2, 2) * VRCZ
889                         + TOri_Matrix_Inv (2, 3) * VRCT;
890                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
891                         + TOri_Matrix_Inv (3, 1) * VRCY
892                         + TOri_Matrix_Inv (3, 2) * VRCZ
893                         + TOri_Matrix_Inv (3, 3) * VRCT;
894
895                 if (WCT != 0.)
896                     Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
897                 else
898                     Point.SetCoord (RealLast (), RealLast (), RealLast ());
899
900                 // Define projection ray
901                 NPCZ    = 10.0;
902
903                 // NPCS -> VRCS View Reference Coordinate Space
904                 // PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);
905
906                 VRCX    = TMap_Matrix_Inv (0, 0) * NPCX
907                         + TMap_Matrix_Inv (0, 1) * NPCY
908                         + TMap_Matrix_Inv (0, 2) * NPCZ
909                         + TMap_Matrix_Inv (0, 3);
910                 VRCY    = TMap_Matrix_Inv (1, 0) * NPCX
911                         + TMap_Matrix_Inv (1, 1) * NPCY
912                         + TMap_Matrix_Inv (1, 2) * NPCZ
913                         + TMap_Matrix_Inv (1, 3);
914                 VRCZ    = TMap_Matrix_Inv (2, 0) * NPCX
915                         + TMap_Matrix_Inv (2, 1) * NPCY
916                         + TMap_Matrix_Inv (2, 2) * NPCZ
917                         + TMap_Matrix_Inv (2, 3);
918                 VRCT    = TMap_Matrix_Inv (3, 0) * NPCX
919                         + TMap_Matrix_Inv (3, 1) * NPCY
920                         + TMap_Matrix_Inv (3, 2) * NPCZ
921                         + TMap_Matrix_Inv (3, 3);
922
923                 // VRCS -> WCS World Coordinate Space
924                 // PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);
925
926                 WCX     = TOri_Matrix_Inv (0, 0) * VRCX
927                         + TOri_Matrix_Inv (0, 1) * VRCY
928                         + TOri_Matrix_Inv (0, 2) * VRCZ
929                         + TOri_Matrix_Inv (0, 3) * VRCT;
930                 WCY     = TOri_Matrix_Inv (1, 0) * VRCX
931                         + TOri_Matrix_Inv (1, 1) * VRCY
932                         + TOri_Matrix_Inv (1, 2) * VRCZ
933                         + TOri_Matrix_Inv (1, 3) * VRCT;
934                 WCZ     = TOri_Matrix_Inv (2, 0) * VRCX
935                         + TOri_Matrix_Inv (2, 1) * VRCY
936                         + TOri_Matrix_Inv (2, 2) * VRCZ
937                         + TOri_Matrix_Inv (2, 3) * VRCT;
938                 WCT     = TOri_Matrix_Inv (3, 0) * VRCX
939                         + TOri_Matrix_Inv (3, 1) * VRCY
940                         + TOri_Matrix_Inv (3, 2) * VRCZ
941                         + TOri_Matrix_Inv (3, 3) * VRCT;
942
943                 if (WCT != 0.) {
944                     Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
945                     Proj.Normalize();
946                 }
947                 else
948                     Proj.SetCoord (0., 0., 0.);
949             }
950         }
951
952 }
953
954
955 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
956
957 Standard_Boolean Exist = Standard_False;
958
959         // Parse the list of views to find
960         // a view with the specified window
961         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
962         int TheWindowIdOfView;
963
964 #ifndef WNT
965 const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
966         int TheSpecifiedWindowId = int (THEWindow->XWindow ());
967 #else
968 const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
969         int TheSpecifiedWindowId = int (THEWindow->HWindow ());
970 #endif  // WNT
971
972         while ((! Exist) && (MyIterator.More ())) {
973
974            if ( ((MyIterator.Value ())->IsDefined ()) &&
975                 ((MyIterator.Value ())->IsActive ()) ) {
976
977 const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
978 #ifndef WNT
979 const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
980         TheWindowIdOfView = int (theWindow->XWindow ());
981 #else
982 const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
983         TheWindowIdOfView = int (theWindow->HWindow ());
984 #endif  // WNT
985                 // Comparaison on window IDs
986                 if (TheWindowIdOfView == TheSpecifiedWindowId) {
987                         Exist   = Standard_True;
988                         TheCView        = *(CALL_DEF_VIEW *)(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   MyViewGenId.Free(aViewId);
1065 }
1066
1067 void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
1068
1069         if (MyTransparency && AFlag) return;
1070         if (! MyTransparency && ! AFlag) return;
1071
1072         Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1073         while (MyIterator.More ()) {
1074                 (MyIterator.Value ())->SetTransparency (AFlag);
1075                 // MyIterator.Next () is located on the next view
1076                 MyIterator.Next ();
1077         }
1078
1079         MyTransparency  = AFlag;
1080
1081 }
1082
1083 Standard_Boolean Visual3d_ViewManager::Transparency () const {
1084
1085         return (MyTransparency);
1086
1087 }
1088
1089 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
1090
1091         if (MyZBufferAuto && AFlag) return;
1092         if (! MyZBufferAuto && ! AFlag) return;
1093
1094         // if pass from False to True :
1095         // no problem, at the next view update, it 
1096         // will properly ask questions to answer (SetVisualisation)
1097         // if pass from True to False :
1098         // it is necessary to modify ZBufferActivity at each view so that
1099         // zbuffer could be active only if required by context.
1100         // In this case -1 is passed so that the view ask itself the question
1101         // Note : 0 forces the desactivation, 1 forces the activation
1102         if (! AFlag) {
1103                 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
1104                 while (MyIterator.More ()) {
1105                         (MyIterator.Value ())->SetZBufferActivity (-1);
1106                         // MyIterator.Next () is located on the next view
1107                         MyIterator.Next ();
1108                 }
1109         }
1110         MyZBufferAuto   = AFlag;
1111
1112 }
1113
1114 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
1115
1116         return (MyZBufferAuto);
1117
1118 }
1119
1120 void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
1121
1122 #ifdef TRACE_LAYER
1123         cout << "Visual3d_ViewManager::SetLayer\n" << flush;
1124 #endif
1125
1126         if (ALayer->Type () == Aspect_TOL_OVERLAY) {
1127 #ifdef TRACE_LAYER
1128                 if (MyOverLayer.IsNull ())
1129                         cout << "MyOverLayer is defined" << endl;
1130                 else
1131                         cout << "MyOverLayer is redefined" << endl;
1132 #endif
1133                 MyOverLayer = ALayer;
1134         }
1135         else {
1136 #ifdef TRACE_LAYER
1137                 if (MyUnderLayer.IsNull ())
1138                         cout << "MyUnderLayer is defined" << endl;
1139                 else
1140                         cout << "MyUnderLayer is redefined" << endl;
1141 #endif
1142                 MyUnderLayer = ALayer;
1143         }
1144
1145 }
1146
1147 const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
1148
1149         return (MyUnderLayer);
1150
1151 }
1152
1153 const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
1154
1155         return (MyOverLayer);
1156
1157 }
1158
1159 //=======================================================================
1160 //function : ChangeZLayer
1161 //purpose  : 
1162 //=======================================================================
1163
1164 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
1165                                          const Standard_Integer theLayerId)
1166 {
1167   if (!myLayerIds.Contains (theLayerId))
1168     return;
1169   
1170   // change display layer for structure in all views
1171   if (MyDisplayedStructure.Contains (theStructure))
1172   {
1173     Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1174     for ( ; aViewIt.More (); aViewIt.Next ())
1175       (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
1176   }
1177   
1178   // tell graphic driver to update the structure's display layer
1179   MyGraphicDriver->ChangeZLayer (
1180     (*(Graphic3d_CStructure*)theStructure->CStructure ()), theLayerId);
1181 }
1182
1183 //=======================================================================
1184 //function : GetZLayer
1185 //purpose  :
1186 //=======================================================================
1187
1188 Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
1189 {
1190   Graphic3d_CStructure& aStructure =
1191     (*(Graphic3d_CStructure*)theStructure->CStructure ());
1192
1193   return MyGraphicDriver->GetZLayer (aStructure);
1194 }
1195
1196 //=======================================================================
1197 //function : AddZLayer
1198 //purpose  :
1199 //=======================================================================
1200
1201 Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
1202 {
1203   try
1204   {
1205     OCC_CATCH_SIGNALS
1206     theLayerId = getZLayerGenId ().Next ();
1207     myLayerIds.Add (theLayerId);
1208     myLayerSeq.Append (theLayerId);
1209   }
1210   catch (Aspect_IdentDefinitionError)
1211   {
1212     // new index can't be generated
1213     return Standard_False;
1214   }
1215
1216   // tell all managed views to remove display layers
1217   Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1218   for ( ; aViewIt.More (); aViewIt.Next ())
1219     (aViewIt.Value ())->AddZLayer (theLayerId);
1220
1221   return Standard_True;
1222 }
1223
1224 //=======================================================================
1225 //function : RemoveZLayer
1226 //purpose  : 
1227 //=======================================================================
1228
1229 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
1230 {
1231   if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
1232     return Standard_False;
1233
1234   // tell all managed views to remove display layers
1235   Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
1236   for ( ; aViewIt.More (); aViewIt.Next ())
1237     (aViewIt.Value ())->RemoveZLayer (theLayerId);
1238
1239   MyGraphicDriver->UnsetZLayer (theLayerId);
1240
1241   // remove index
1242   for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
1243     if (myLayerSeq(aIdx) == theLayerId)
1244     {
1245       myLayerSeq.Remove (aIdx);
1246       break;
1247     }
1248
1249   myLayerIds.Remove (theLayerId);
1250   getZLayerGenId ().Free (theLayerId);
1251
1252   return Standard_True;
1253 }
1254
1255 //=======================================================================
1256 //function : GetAllZLayers
1257 //purpose  :
1258 //=======================================================================
1259
1260 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
1261 {
1262   theLayerSeq.Assign (myLayerSeq);
1263 }
1264
1265 //=======================================================================
1266 //function : getZLayerGenId
1267 //purpose  :
1268 //=======================================================================
1269
1270 Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
1271 {
1272   static Aspect_GenId aGenId (1, IntegerLast());
1273   return aGenId;
1274 }
1275
1276 //=======================================================================
1277 //function : InstallZLayers
1278 //purpose  :
1279 //=======================================================================
1280
1281 void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
1282 {
1283   if (!MyDefinedView.Contains (theView))
1284     return;
1285   
1286   // erase and insert layers iteratively to provide the same layer order as
1287   // in the view manager's sequence. This approach bases on the layer insertion
1288   // order: the new layers are always appended to the end of the list
1289   // inside of view, while layer remove operation doesn't affect the order.
1290   // Starting from second layer : no need to change the default z layer.
1291   for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
1292   {
1293     Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
1294     theView->RemoveZLayer (aLayerID);
1295     theView->AddZLayer (aLayerID);
1296   }
1297 }