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