0024704: Visualization - inherit OpenGl_Structure from Graphic3d_CStructure
[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//
d5f74e42 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
973c2be1 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
7fd59977 508Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {
509
510Standard_Boolean Exist = Standard_False;
511
81bba717 512 // Parse the list of views to find
513 // a view with the specified window
7fd59977 514 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
7fd59977 515
872f4e44 516#if defined(_WIN32) || defined(__WIN32__)
517 const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
566f8441 518 Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow ();
872f4e44 519#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
520 const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
521 NSView* TheSpecifiedWindowId = THEWindow->HView();
7fd59977 522#else
872f4e44 523 const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
524 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
525#endif
7fd59977 526
527 while ((! Exist) && (MyIterator.More ())) {
528
529 if ( ((MyIterator.Value ())->IsDefined ()) &&
530 ((MyIterator.Value ())->IsActive ()) ) {
531
532const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
872f4e44 533#if defined(_WIN32) || defined(__WIN32__)
534 const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
566f8441 535 Aspect_Handle TheWindowIdOfView = theWindow->HWindow ();
872f4e44 536#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
537 const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
538 NSView* TheWindowIdOfView = theWindow->HView();
7fd59977 539#else
872f4e44 540 const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
541 int TheWindowIdOfView = int (theWindow->XWindow ());
7fd59977 542#endif // WNT
81bba717 543 // Comparaison on window IDs
7fd59977 544 if (TheWindowIdOfView == TheSpecifiedWindowId) {
545 Exist = Standard_True;
bf75be98 546 TheCView = *(Graphic3d_CView* )(MyIterator.Value())->CView();
7fd59977 547 }
548 } /* if ((MyIterator.Value ())->IsDefined ()) */
549
81bba717 550 // MyIterator.Next () is located on the next view
7fd59977 551 MyIterator.Next ();
552 }
553
554 return (Exist);
555
556}
557
558void Visual3d_ViewManager::Activate () {
559
560 //
561 // Activates all deactivated views
562 //
563 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
bf75be98 564
7fd59977 565 while (MyIterator.More ()) {
566 if (! (MyIterator.Value ())->IsActive ())
567 (MyIterator.Value ())->Activate ();
568
81bba717 569 // MyIterator.Next () is located on the next view
7fd59977 570 MyIterator.Next ();
571 }
572
573}
574
575void Visual3d_ViewManager::Deactivate () {
576
577 //
578 // Deactivates all activated views
579 //
7fd59977 580 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
bf75be98 581
7fd59977 582 while (MyIterator.More ()) {
583 if ((MyIterator.Value ())->IsActive ())
584 (MyIterator.Value ())->Deactivate ();
585
81bba717 586 // MyIterator.Next () is located on the next view
7fd59977 587 MyIterator.Next ();
588 }
589
590}
591
592Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
593
81bba717 594 // Retourne the planned of definable views for the current
595 // Visual3d_ViewManager.
7fd59977 596 return
597(Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
598
599}
600
601Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
602
603 return (Graphic3d_StructureManager::Identification (AId));
604
605}
606
607Standard_Integer Visual3d_ViewManager::Identification () const {
bf75be98 608
7fd59977 609 return (Graphic3d_StructureManager::Identification ());
610
611}
612
613Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {
614
615 MyDefinedView.Add (AView);
616 return (MyViewGenId.Next ());
617
618}
619
620void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
621{
30bf45dc 622 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
623 while (MyIterator.More())
624 {
625 if ((MyIterator.Value())->Identification () == aViewId)
626 {
627 const Handle(Visual3d_View)& theView = MyIterator.Value();
628 //remove the view from the list
629 MyDefinedView.Remove(theView);
630 break;
631 }
632 // go to next
633 MyIterator.Next ();
634 }
7fd59977 635 MyViewGenId.Free(aViewId);
636}
637
638void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {
639
640 if (MyTransparency && AFlag) return;
641 if (! MyTransparency && ! AFlag) return;
642
643 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
644 while (MyIterator.More ()) {
645 (MyIterator.Value ())->SetTransparency (AFlag);
81bba717 646 // MyIterator.Next () is located on the next view
7fd59977 647 MyIterator.Next ();
648 }
649
650 MyTransparency = AFlag;
651
652}
653
654Standard_Boolean Visual3d_ViewManager::Transparency () const {
655
656 return (MyTransparency);
657
658}
659
660void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {
661
662 if (MyZBufferAuto && AFlag) return;
663 if (! MyZBufferAuto && ! AFlag) return;
664
81bba717 665 // if pass from False to True :
bf75be98 666 // no problem, at the next view update, it
81bba717 667 // will properly ask questions to answer (SetVisualisation)
668 // if pass from True to False :
669 // it is necessary to modify ZBufferActivity at each view so that
670 // zbuffer could be active only if required by context.
671 // In this case -1 is passed so that the view ask itself the question
672 // Note : 0 forces the desactivation, 1 forces the activation
7fd59977 673 if (! AFlag) {
674 Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
675 while (MyIterator.More ()) {
676 (MyIterator.Value ())->SetZBufferActivity (-1);
81bba717 677 // MyIterator.Next () is located on the next view
7fd59977 678 MyIterator.Next ();
679 }
680 }
681 MyZBufferAuto = AFlag;
682
683}
684
685Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {
686
687 return (MyZBufferAuto);
688
689}
690
691void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
692
693#ifdef TRACE_LAYER
694 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
695#endif
696
697 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
698#ifdef TRACE_LAYER
699 if (MyOverLayer.IsNull ())
700 cout << "MyOverLayer is defined" << endl;
701 else
702 cout << "MyOverLayer is redefined" << endl;
703#endif
704 MyOverLayer = ALayer;
705 }
706 else {
707#ifdef TRACE_LAYER
708 if (MyUnderLayer.IsNull ())
709 cout << "MyUnderLayer is defined" << endl;
710 else
711 cout << "MyUnderLayer is redefined" << endl;
712#endif
713 MyUnderLayer = ALayer;
714 }
715
716}
717
718const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
719
720 return (MyUnderLayer);
721
722}
723
724const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
725
726 return (MyOverLayer);
727
728}
59f45b7c 729
730//=======================================================================
731//function : ChangeZLayer
bf75be98 732//purpose :
59f45b7c 733//=======================================================================
734
735void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
736 const Standard_Integer theLayerId)
737{
738 if (!myLayerIds.Contains (theLayerId))
739 return;
bf75be98 740
59f45b7c 741 // change display layer for structure in all views
742 if (MyDisplayedStructure.Contains (theStructure))
743 {
744 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
745 for ( ; aViewIt.More (); aViewIt.Next ())
746 (aViewIt.Value ())->ChangeZLayer (theStructure, theLayerId);
747 }
bf75be98 748
59f45b7c 749 // tell graphic driver to update the structure's display layer
63bcc448 750 MyGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), theLayerId);
59f45b7c 751}
752
753//=======================================================================
754//function : GetZLayer
755//purpose :
756//=======================================================================
757
758Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
759{
63bcc448 760 return MyGraphicDriver->GetZLayer (*theStructure->CStructure ());
59f45b7c 761}
762
763//=======================================================================
764//function : AddZLayer
765//purpose :
766//=======================================================================
767
768Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
769{
770 try
771 {
772 OCC_CATCH_SIGNALS
773 theLayerId = getZLayerGenId ().Next ();
774 myLayerIds.Add (theLayerId);
775 myLayerSeq.Append (theLayerId);
776 }
777 catch (Aspect_IdentDefinitionError)
778 {
779 // new index can't be generated
780 return Standard_False;
781 }
782
783 // tell all managed views to remove display layers
784 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
785 for ( ; aViewIt.More (); aViewIt.Next ())
786 (aViewIt.Value ())->AddZLayer (theLayerId);
787
788 return Standard_True;
789}
790
791//=======================================================================
792//function : RemoveZLayer
bf75be98 793//purpose :
59f45b7c 794//=======================================================================
795
796Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
797{
798 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
799 return Standard_False;
800
801 // tell all managed views to remove display layers
802 Visual3d_SetIteratorOfSetOfView aViewIt(MyDefinedView);
803 for ( ; aViewIt.More (); aViewIt.Next ())
804 (aViewIt.Value ())->RemoveZLayer (theLayerId);
805
806 MyGraphicDriver->UnsetZLayer (theLayerId);
807
808 // remove index
809 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
810 if (myLayerSeq(aIdx) == theLayerId)
811 {
812 myLayerSeq.Remove (aIdx);
813 break;
814 }
815
816 myLayerIds.Remove (theLayerId);
817 getZLayerGenId ().Free (theLayerId);
818
819 return Standard_True;
820}
821
822//=======================================================================
823//function : GetAllZLayers
824//purpose :
825//=======================================================================
826
827void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
828{
829 theLayerSeq.Assign (myLayerSeq);
830}
831
832//=======================================================================
833//function : getZLayerGenId
834//purpose :
835//=======================================================================
836
837Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
838{
839 static Aspect_GenId aGenId (1, IntegerLast());
840 return aGenId;
841}
71c4f9c6 842
843//=======================================================================
844//function : InstallZLayers
845//purpose :
846//=======================================================================
847
848void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
849{
850 if (!MyDefinedView.Contains (theView))
851 return;
bf75be98 852
71c4f9c6 853 // erase and insert layers iteratively to provide the same layer order as
854 // in the view manager's sequence. This approach bases on the layer insertion
855 // order: the new layers are always appended to the end of the list
856 // inside of view, while layer remove operation doesn't affect the order.
857 // Starting from second layer : no need to change the default z layer.
858 for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
859 {
860 Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
861 theView->RemoveZLayer (aLayerID);
862 theView->AddZLayer (aLayerID);
863 }
864}