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