82a8b458cc18b7bfb3e75dd7fa30a2f7cb515212
[occt.git] / src / Visual3d / Visual3d_ViewManager.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 /***********************************************************************
16
17      FONCTION :
18      ----------
19         Classe Visual3d_ViewManager.cxx :
20
21         Declaration of variables specific to visualisers
22
23      HISTORIQUE DES MODIFICATIONS   :
24      --------------------------------
25       Mars 1992 : NW,JPB,CAL ; Creation.
26       19-06-96  : FMN ; Suppression variables inutiles
27       04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
28       06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
29       19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
30       24-10-97  : CAL ; Retrait de DownCast.
31       20-11-97  : CAL ; Disparition de la dependance avec math
32       01-12-97  : CAL ; Retrait du test IsActive sur l'Update et le Redraw
33       31-12-97  : CAL ; Disparition de MathGra
34       16-01-98  : CAL ; Ajout du SetTransform sur une TOS_COMPUTED
35       11-03-98  : CAL ; Visual3d_ViewManager::Remove ()
36       20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
37       10-06-98  : CAL ; Modification des signatures de xxProjectRaster.
38       10-06-98  : CAL ; Modification de la signature de ViewExists.
39       01-12-98  : CAL ; S4062. Ajout des layers.
40       02-12-98  : CAL ; Remove () ne detruit plus les vues.
41
42 ************************************************************************/
43
44 /*----------------------------------------------------------------------*/
45 /*
46  * Constants
47  */
48
49 #define NO_DOWNCAST
50 #define NO_DESTROY
51
52 /*----------------------------------------------------------------------*/
53 /*
54  * Includes
55  */
56 // for the class
57
58 #include <Aspect_IdentDefinitionError.hxx>
59 #include <Aspect_Window.hxx>
60 #include <Graphic3d_DataStructureManager.hxx>
61 #include <Graphic3d_GraphicDriver.hxx>
62 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
63 #include <Graphic3d_MapOfStructure.hxx>
64 #include <Graphic3d_Structure.hxx>
65 #include <Standard_ErrorHandler.hxx>
66 #include <Standard_Type.hxx>
67 #include <Visual3d_View.hxx>
68 #include <Visual3d_ViewManager.hxx>
69
70 #if defined (_WIN32) || defined(__WIN32__)
71 # include <WNT_Window.hxx>
72 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
73 # include <Cocoa_Window.hxx>
74 #else
75 # include <Xw_Window.hxx>
76 #include <Visual3d_View.hxx>
77 #endif
78
79 // views identifiers : possible range
80 #define View_IDMIN      1
81 #define View_IDMAX      10000
82
83 Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
84 Graphic3d_StructureManager (theDriver),
85 MyDefinedView (),
86 MyViewGenId (0, 31),
87 MyZBufferAuto (Standard_False),
88 myZLayerGenId (1, IntegerLast())
89 {
90   MyGraphicDriver = theDriver;
91
92   // default layers are always presented in display layer sequence it can not be removed
93   Graphic3d_ZLayerSettings anUnderlaySettings;
94   anUnderlaySettings.Flags = 0;
95   anUnderlaySettings.IsImmediate = false;
96   myLayerIds.Add             (Graphic3d_ZLayerId_BotOSD);
97   myLayerSeq.Append          (Graphic3d_ZLayerId_BotOSD);
98   myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, anUnderlaySettings);
99
100   Graphic3d_ZLayerSettings aDefSettings;
101   aDefSettings.Flags = Graphic3d_ZLayerDepthTest
102                      | Graphic3d_ZLayerDepthWrite;
103   aDefSettings.IsImmediate = false;
104   myLayerIds.Add             (Graphic3d_ZLayerId_Default);
105   myLayerSeq.Append          (Graphic3d_ZLayerId_Default);
106   myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aDefSettings);
107
108   Graphic3d_ZLayerSettings aTopSettings;
109   aTopSettings.Flags = Graphic3d_ZLayerDepthTest
110                      | Graphic3d_ZLayerDepthWrite;
111   aTopSettings.IsImmediate = true;
112   myLayerIds.Add             (Graphic3d_ZLayerId_Top);
113   myLayerSeq.Append          (Graphic3d_ZLayerId_Top);
114   myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aTopSettings);
115
116   Graphic3d_ZLayerSettings aTopmostSettings;
117   aTopmostSettings.Flags = Graphic3d_ZLayerDepthTest
118                          | Graphic3d_ZLayerDepthWrite
119                          | Graphic3d_ZLayerDepthClear;
120   aTopmostSettings.IsImmediate = true;
121   myLayerIds.Add             (Graphic3d_ZLayerId_Topmost);
122   myLayerSeq.Append          (Graphic3d_ZLayerId_Topmost);
123   myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aTopmostSettings);
124
125   Graphic3d_ZLayerSettings anOsdSettings;
126   anOsdSettings.Flags = 0;
127   anOsdSettings.IsImmediate = true;
128   myLayerIds.Add             (Graphic3d_ZLayerId_TopOSD);
129   myLayerSeq.Append          (Graphic3d_ZLayerId_TopOSD);
130   myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, anOsdSettings);
131 }
132
133 //-Destructors
134
135 void Visual3d_ViewManager::Destroy () {
136
137         Remove ();
138 }
139
140 //-Methods, in order
141
142 void Visual3d_ViewManager::Remove () {
143
144         //
145         // Destroy all defined views
146         //
147
148   // clear all structures whilst views are alive for correct GPU memory management
149   MyDisplayedStructure.Clear();
150   MyHighlightedStructure.Clear();
151
152   // clear list of managed views
153   MyDefinedView.Clear();
154 }
155
156 void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority)
157 {
158   //
159   // Change structure priority in all defined views
160   //
161   for(int i=1; i<=MyDefinedView.Length(); i++)
162   {
163     (MyDefinedView.Value(i))->ChangeDisplayPriority(AStructure, OldPriority, NewPriority);
164   }
165 }
166
167 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
168
169   //Standard_Integer LengthD    = MyDisplayedStructure.Extent() ();
170
171   // Even if physically the structure cannot
172   // be displayed (pb of visualisation type)
173   // it has status Displayed.
174
175   if (!MyDisplayedStructure.Contains(AStructure))
176     return;
177
178   //
179   // Recompute structure in all activated views
180   //
181   for(int i=1; i<=MyDefinedView.Length(); i++)
182   {
183     (MyDefinedView.Value(i))->ReCompute(AStructure);
184   }
185 }
186
187 void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
188                                       const Handle(Graphic3d_DataStructureManager)& AProjector)
189 {
190
191   if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
192
193 #ifdef DOWNCAST
194   Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
195 #else
196   Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
197 #endif
198   Standard_Integer ViewId = theView->Identification ();
199
200   // Even if physically the structure cannot
201   // be displayed (pb of visualisation type)
202   // it has status Displayed.
203   if (!MyDisplayedStructure.Contains(AStructure))
204     return;
205
206   //
207   // Recompute structure in all activated views
208   //
209   for(int i=1; i<=MyDefinedView.Length(); i++)
210   {
211     if ((MyDefinedView.Value(i))->Identification () == ViewId)
212     {
213       theView->ReCompute (AStructure);
214     }
215   }
216 }
217
218 void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction)
219 {
220   for(int i=1; i<=MyDefinedView.Length(); i++)
221   {
222     (MyDefinedView.Value(i))->Clear(AStructure, WithDestruction);
223   }
224 }
225
226 void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
227 {
228   for(int i=1; i<=MyDefinedView.Length(); i++)
229   {
230     (MyDefinedView.Value(i))->Connect (AMother, ADaughter);
231   }
232 }
233
234 void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
235 {
236   for(int i=1; i<=MyDefinedView.Length(); i++)
237   {
238     (MyDefinedView.Value(i))->Disconnect (AMother, ADaughter);
239   }
240 }
241
242 void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure)
243 {
244   // Even if physically the structure cannot
245   // be displayed (pb of visualisation type)
246   // it has status Displayed.
247
248   MyDisplayedStructure.Add(AStructure);
249   
250   for(int i=1; i<=MyDefinedView.Length(); i++)
251   {
252     (MyDefinedView.Value(i))->Display(AStructure);
253   }
254 }
255
256 void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure)
257 {
258   // Even if physically the structure cannot
259   // be displayed (pb of visualisation type)
260   // it has status Displayed.
261
262   MyDisplayedStructure.Remove(AStructure);
263
264   //
265   // Erase structure in all defined views
266   //
267   for(int i=1; i<=MyDefinedView.Length(); i++)
268   {
269     (MyDefinedView.Value(i))->Erase (AStructure);
270   }
271
272   MyHighlightedStructure.Remove (AStructure);
273 }
274
275 void Visual3d_ViewManager::Erase () {
276
277  Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
278
279  for (; it.More(); it.Next()) {
280    Handle(Graphic3d_Structure) SG = it.Key();
281    SG->Erase();
282  }
283
284 }
285
286 void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod)
287 {
288   MyHighlightedStructure.Add(AStructure);
289   
290   //
291   // Highlight in all activated views
292   //
293   
294   for(int i=1; i<=MyDefinedView.Length(); i++)
295   {
296     (MyDefinedView.Value(i))->Highlight (AStructure, AMethod);
297   }
298 }
299
300 void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf)
301 {
302   for(int i=1; i<=MyDefinedView.Length(); i++)
303   {
304     (MyDefinedView.Value(i))->SetTransform (AStructure, ATrsf);
305   }
306 }
307
308 void Visual3d_ViewManager::UnHighlight () {
309
310   Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
311
312   for (; it.More(); it.Next()) {
313     Handle(Graphic3d_Structure) SG = it.Key();
314     SG->UnHighlight ();
315   }
316
317
318 }
319
320 void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure)
321 {
322   MyHighlightedStructure.Remove(AStructure);
323
324   //
325   // UnHighlight in all activated views
326   //
327
328   for(int i=1; i<=MyDefinedView.Length(); i++)
329   {
330     (MyDefinedView.Value(i))->UnHighlight (AStructure);
331   }
332 }
333
334 void Visual3d_ViewManager::Redraw() const
335 {
336   // redraw all activated views
337   if (MyDefinedView.Length() == 0)
338   {
339     return;
340   }
341
342   for(int i=1; i<=MyDefinedView.Length(); i++)
343   {
344     MyDefinedView.Value(i)->Redraw ();
345   }
346 }
347
348 void Visual3d_ViewManager::Update() const
349 {
350   Redraw();
351 }
352
353 void Visual3d_ViewManager::RedrawImmediate() const
354 {
355   if (MyDefinedView.Length() == 0)
356   {
357     return;
358   }
359
360   // update all activated views
361   for(int i=1; i<=MyDefinedView.Length(); i++)
362   {
363     MyDefinedView.Value(i)->RedrawImmediate ();
364   }
365 }
366
367 void Visual3d_ViewManager::Invalidate() const
368 {
369   if (MyDefinedView.Length() == 0)
370   {
371     return;
372   }
373
374   // update all activated views
375   for(int i=1; i<=MyDefinedView.Length(); i++)
376   {
377     MyDefinedView.Value(i)->Invalidate();
378   }
379 }
380
381 Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::ActivatedView () const
382 {
383
384   Handle(Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView();
385
386   for(int i=1; i<=MyDefinedView.Length(); i++)
387   {
388     if ((MyDefinedView.Value(i))->IsActive ())
389     {
390       SG->Append(MyDefinedView.Value(i));
391     }
392   }
393
394   return (SG);
395 }
396
397 #ifdef IMPLEMENTED
398 Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const
399 {
400   Standard_Boolean Result = Standard_False;
401
402   //
403   // Check all activated views
404   //
405   for(int i=1; (!Result) && i<=MyDefinedView.Length(); i++)
406   {
407     if ((MyDefinedView.Value(i))->IsActive())
408     {
409       Result = (MyDefinedView.Value(i))->ContainsComputedStructure();
410     }
411   }
412
413   return Result;
414 }
415 #endif
416
417 const Visual3d_SequenceOfView& Visual3d_ViewManager::DefinedViews() const
418 {
419   return MyDefinedView;
420 }
421
422 Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const
423 {
424   Standard_Boolean Exist = Standard_False;
425
426   // Parse the list of views to find
427   // a view with the specified window
428
429 #if defined(_WIN32)
430   const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
431   Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow ();
432 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
433   const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
434   #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
435     UIView* TheSpecifiedWindowId = THEWindow->HView();
436   #else
437     NSView* TheSpecifiedWindowId = THEWindow->HView();
438   #endif
439 #elif defined(__ANDROID__)
440   int TheSpecifiedWindowId = -1;
441 #else
442   const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
443   int TheSpecifiedWindowId = int (THEWindow->XWindow ());
444 #endif
445
446   for(int i=1; (!Exist) && i<=MyDefinedView.Length(); i++)
447   {
448     if ( ((MyDefinedView.Value(i))->IsDefined ()) && ((MyDefinedView.Value(i))->IsActive ()) )
449     {
450       const Handle(Aspect_Window) AspectWindow = (MyDefinedView.Value(i))->Window();
451
452 #if defined(_WIN32)
453       const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
454       Aspect_Handle TheWindowIdOfView = theWindow->HWindow ();
455 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
456       const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
457       #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
458         UIView* TheWindowIdOfView = theWindow->HView();
459       #else
460         NSView* TheWindowIdOfView = theWindow->HView();
461       #endif
462 #elif defined(__ANDROID__)
463       int TheWindowIdOfView = 0;
464 #else
465       const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
466       int TheWindowIdOfView = int (theWindow->XWindow ());
467 #endif  // WNT
468       // Comparaison on window IDs
469       if (TheWindowIdOfView == TheSpecifiedWindowId)
470       {
471         Exist = Standard_True;
472         TheCView = *(Graphic3d_CView* )(MyDefinedView.Value(i))->CView();
473       }
474     }
475   }
476
477   return (Exist);
478 }
479
480 void Visual3d_ViewManager::Activate ()
481 {
482   //
483   // Activates all deactivated views
484   //
485   for(int i=1; i<=MyDefinedView.Length(); i++)
486   {
487     if (! (MyDefinedView.Value(i))->IsActive())
488     {
489       (MyDefinedView.Value(i))->Activate();
490     }
491   }
492 }
493
494 void Visual3d_ViewManager::Deactivate ()
495 {
496   //
497   // Deactivates all activated views
498   //
499   for(int i=1; i<=MyDefinedView.Length(); i++)
500   {
501     if ((MyDefinedView.Value(i))->IsActive())
502     {
503       (MyDefinedView.Value(i))->Deactivate();
504     }
505   }
506
507 }
508
509 Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
510
511         // Retourne the planned of definable views for the current
512         // Visual3d_ViewManager.
513         return
514 (Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
515
516 }
517
518 Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
519
520         return (Graphic3d_StructureManager::Identification (AId));
521
522 }
523
524 Standard_Integer Visual3d_ViewManager::Identification () const {
525
526         return (Graphic3d_StructureManager::Identification ());
527
528 }
529
530 Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView)
531 {
532   MyDefinedView.Append(AView);
533   return (MyViewGenId.Next ());
534 }
535
536 void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
537 {
538   for(int i=1; i<=MyDefinedView.Length(); i++)
539   {
540     if ((MyDefinedView.Value(i))->Identification() == aViewId)
541     {
542       //remove the view from the list
543       MyDefinedView.Remove(i);
544       break;
545     }
546   }
547
548   MyViewGenId.Free(aViewId);
549 }
550
551 void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag)
552 {
553   MyZBufferAuto = AFlag;
554 }
555
556 Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const
557 {
558   return (MyZBufferAuto);
559 }
560
561 //=======================================================================
562 //function : ChangeZLayer
563 //purpose  :
564 //=======================================================================
565
566 void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
567                                          const Graphic3d_ZLayerId           theLayerId)
568 {
569   if (!myLayerIds.Contains (theLayerId)
570    || !MyDisplayedStructure.Contains (theStructure))
571   {
572     return;
573   }
574
575   // change display layer for structure in all views
576   for (int aViewIter = 1; aViewIter <= MyDefinedView.Length(); ++aViewIter)
577   {
578     MyDefinedView.Value (aViewIter)->ChangeZLayer (theStructure, theLayerId);
579   }
580 }
581
582 //=======================================================================
583 //function : SetZLayerSettings
584 //purpose  :
585 //=======================================================================
586 void Visual3d_ViewManager::SetZLayerSettings (const Graphic3d_ZLayerId        theLayerId,
587                                               const Graphic3d_ZLayerSettings& theSettings)
588 {
589   // tell all managed views to set zlayer settings
590   for(int i=1; i<=MyDefinedView.Length(); i++)
591   {
592     (MyDefinedView.Value(i))->SetZLayerSettings (theLayerId, theSettings);
593   }
594
595   if (myMapOfZLayerSettings.IsBound (theLayerId))
596   {
597     myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings;
598   }
599   else
600   {
601     myMapOfZLayerSettings.Bind (theLayerId, theSettings);
602   }
603   
604 }
605
606 //=======================================================================
607 //function : ZLayerSettings
608 //purpose  :
609 //=======================================================================
610 Graphic3d_ZLayerSettings Visual3d_ViewManager::ZLayerSettings (const Graphic3d_ZLayerId theLayerId)
611 {
612   if (!myLayerIds.Contains (theLayerId))
613   {
614     return Graphic3d_ZLayerSettings();
615   }
616
617   return myMapOfZLayerSettings.Find (theLayerId);
618 }
619
620 //=======================================================================
621 //function : AddZLayer
622 //purpose  :
623 //=======================================================================
624
625 Standard_Boolean Visual3d_ViewManager::AddZLayer (Graphic3d_ZLayerId& theLayerId)
626 {
627   try
628   {
629     OCC_CATCH_SIGNALS
630     theLayerId = myZLayerGenId.Next();
631     myLayerIds.Add    (theLayerId);
632     myLayerSeq.Append (theLayerId);
633   }
634   catch (Aspect_IdentDefinitionError)
635   {
636     // new index can't be generated
637     return Standard_False;
638   }
639
640   // default z-layer settings
641   myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
642
643   // tell all managed views to remove display layers
644   for(int i=1; i<=MyDefinedView.Length(); i++)
645   {
646     (MyDefinedView.Value(i))->AddZLayer(theLayerId);
647   }
648
649   return Standard_True;
650 }
651
652 //=======================================================================
653 //function : RemoveZLayer
654 //purpose  :
655 //=======================================================================
656
657 Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Graphic3d_ZLayerId theLayerId)
658 {
659   if (!myLayerIds.Contains (theLayerId)
660     || theLayerId < myZLayerGenId.Lower()
661     || theLayerId > myZLayerGenId.Upper())
662   {
663     return Standard_False;
664   }
665
666   // tell all managed views to remove display layers
667   for(int i=1; i<=MyDefinedView.Length(); i++)
668   {
669     (MyDefinedView.Value(i))->RemoveZLayer (theLayerId);
670   }
671
672   MyGraphicDriver->UnsetZLayer (theLayerId);
673
674   // remove index
675   for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
676   {
677     if (myLayerSeq (aIdx) == theLayerId)
678     {
679       myLayerSeq.Remove (aIdx);
680       break;
681     }
682   }
683
684   myMapOfZLayerSettings.UnBind (theLayerId);
685
686   myLayerIds.Remove  (theLayerId);
687   myZLayerGenId.Free (theLayerId);
688
689   return Standard_True;
690 }
691
692 //=======================================================================
693 //function : GetAllZLayers
694 //purpose  :
695 //=======================================================================
696
697 void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
698 {
699   theLayerSeq.Assign (myLayerSeq);
700 }
701
702 //=======================================================================
703 //function : InstallZLayers
704 //purpose  :
705 //=======================================================================
706
707 void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
708 {
709   Standard_Boolean isContainsView = Standard_False;
710   for(int i=1; i<=MyDefinedView.Length(); i++)
711   {
712     if(MyDefinedView.Value(i) == theView)
713     {
714       isContainsView = Standard_True;
715       break;
716     }
717   }
718   if (!isContainsView)
719     return;
720
721   // erase and insert layers iteratively to provide the same layer order as
722   // in the view manager's sequence. This approach bases on the layer insertion
723   // order: the new layers are always appended to the end of the list
724   // inside of view, while layer remove operation doesn't affect the order.
725   // Starting from second layer : no need to change the default z layer.
726   for (Standard_Integer aSeqIdx = 1; aSeqIdx <= myLayerSeq.Length(); ++aSeqIdx)
727   {
728     const Graphic3d_ZLayerId        aLayerID  = myLayerSeq.Value (aSeqIdx);
729     const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID);
730     if (aLayerID < myZLayerGenId.Lower()
731      || aLayerID > myZLayerGenId.Upper())
732     {
733       theView->SetZLayerSettings (aLayerID, aSettings);
734       continue;
735     }
736
737     theView->RemoveZLayer      (aLayerID);
738     theView->AddZLayer         (aLayerID);
739     theView->SetZLayerSettings (aLayerID, aSettings);
740   }
741 }