0025027: Visualization - 2D layer viewport is updated incorrectly on resize
[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
7fd59977 70
872f4e44 71#if defined (_WIN32) || defined(__WIN32__)
7fd59977 72# include <WNT_Window.hxx>
872f4e44 73#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
74# include <Cocoa_Window.hxx>
75#else
76# include <Xw_Window.hxx>
77#endif
7fd59977 78
79//-Aliases
80
81//-Global data definitions
82
83// -- les vues definies
54f7544d 84// MyDefinedView : SequenceOfView;
7fd59977 85
86// -- le generateur d'identificateurs de vues
87// MyViewGenId : GenId;
88
89//-Constructors
90
dc3fe572 91Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver):
92Graphic3d_StructureManager (theDriver),
7fd59977 93MyDefinedView (),
94MyViewGenId (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),
95MyZBufferAuto (Standard_False),
96MyTransparency (Standard_False)
97{
59f45b7c 98 // default layer is always presented in display layer sequence
99 // it can not be removed
100 myLayerIds.Add (0);
101 myLayerSeq.Append (0);
7fd59977 102
dc3fe572 103 MyGraphicDriver = theDriver;
c5751993 104 myMapOfZLayerSettings.Bind (0, Graphic3d_ZLayerSettings());
7fd59977 105}
106
107//-Destructors
108
109void Visual3d_ViewManager::Destroy () {
110
111#ifdef DESTROY
112 cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
113#endif
114
115 Remove ();
116}
117
118//-Methods, in order
119
120void Visual3d_ViewManager::Remove () {
121
122#ifdef DESTROY
123 cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
124#endif
125
126 //
127 // Destroy all defined views
128 //
7fd59977 129
130#ifdef DESTROY
131 cout << "The Manager " << MyId << " have " << Length << " defined views\n";
132 cout << flush;
133#endif
7fd59977 134
5e27df78 135 // clear all structures whilst views are alive for correct GPU memory management
136 MyDisplayedStructure.Clear();
137 MyHighlightedStructure.Clear();
5e27df78 138 MyPickStructure.Clear();
139
140 // clear list of managed views
141 MyDefinedView.Clear();
7fd59977 142}
143
54f7544d 144void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority)
145{
7fd59977 146
147#ifdef TRACE
54f7544d 148 cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
149 << AStructure->Identification ()
150 << ", " << OldPriority << ", " << NewPriority << ")\n";
151 cout << flush;
7fd59977 152#endif
153
54f7544d 154 //
155 // Change structure priority in all defined views
156 //
157 for(int i=1; i<=MyDefinedView.Length(); i++)
158 {
159 (MyDefinedView.Value(i))->ChangeDisplayPriority(AStructure, OldPriority, NewPriority);
160 }
7fd59977 161}
162
bf75be98 163void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
7fd59977 164
165 //Standard_Integer LengthD = MyDisplayedStructure.Extent() ();
166
81bba717 167 // Even if physically the structure cannot
168 // be displayed (pb of visualisation type)
169 // it has status Displayed.
bf75be98 170
7fd59977 171 if (!MyDisplayedStructure.Contains(AStructure))
172 return;
173
174 //
175 // Recompute structure in all activated views
176 //
54f7544d 177 for(int i=1; i<=MyDefinedView.Length(); i++)
178 {
179 (MyDefinedView.Value(i))->ReCompute(AStructure);
7fd59977 180 }
7fd59977 181}
182
bf75be98 183void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure,
184 const Handle(Graphic3d_DataStructureManager)& AProjector)
185{
7fd59977 186
187 if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;
188
189#ifdef DOWNCAST
190 Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
191#else
192 Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
193#endif
194 Standard_Integer ViewId = theView->Identification ();
195
81bba717 196 // Even if physically the structure cannot
197 // be displayed (pb of visualisation type)
198 // it has status Displayed.
7fd59977 199 if (!MyDisplayedStructure.Contains(AStructure))
200 return;
bf75be98 201
7fd59977 202 //
81bba717 203 // Recompute structure in all activated views
7fd59977 204 //
54f7544d 205 for(int i=1; i<=MyDefinedView.Length(); i++)
206 {
207 if ((MyDefinedView.Value(i))->Identification () == ViewId)
208 {
7fd59977 209 theView->ReCompute (AStructure);
54f7544d 210 }
7fd59977 211 }
7fd59977 212}
213
54f7544d 214void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction)
215{
216 for(int i=1; i<=MyDefinedView.Length(); i++)
217 {
218 (MyDefinedView.Value(i))->Clear(AStructure, WithDestruction);
219 }
7fd59977 220}
221
54f7544d 222void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
223{
224 for(int i=1; i<=MyDefinedView.Length(); i++)
225 {
226 (MyDefinedView.Value(i))->Connect (AMother, ADaughter);
227 }
7fd59977 228}
229
54f7544d 230void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter)
231{
232 for(int i=1; i<=MyDefinedView.Length(); i++)
233 {
234 (MyDefinedView.Value(i))->Disconnect (AMother, ADaughter);
235 }
7fd59977 236}
237
54f7544d 238void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure)
239{
240 // Even if physically the structure cannot
81bba717 241 // be displayed (pb of visualisation type)
242 // it has status Displayed.
7fd59977 243
244 MyDisplayedStructure.Add(AStructure);
54f7544d 245
246 for(int i=1; i<=MyDefinedView.Length(); i++)
247 {
248 (MyDefinedView.Value(i))->Display(AStructure);
249 }
7fd59977 250}
251
54f7544d 252void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure)
253{
254 // Even if physically the structure cannot
81bba717 255 // be displayed (pb of visualisation type)
256 // it has status Displayed.
7fd59977 257
54f7544d 258 MyDisplayedStructure.Remove(AStructure);
bf75be98 259
54f7544d 260 //
261 // Erase structure in all defined views
262 //
263 for(int i=1; i<=MyDefinedView.Length(); i++)
264 {
265 (MyDefinedView.Value(i))->Erase (AStructure);
266 }
7fd59977 267
54f7544d 268 MyHighlightedStructure.Remove (AStructure);
269 MyPickStructure.Remove (AStructure);
7fd59977 270}
271
272void Visual3d_ViewManager::Erase () {
273
274 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
bf75be98 275
7fd59977 276 for (; it.More(); it.Next()) {
277 Handle(Graphic3d_Structure) SG = it.Key();
278 SG->Erase();
279 }
280
281}
282
54f7544d 283void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod)
284{
7fd59977 285 MyHighlightedStructure.Add(AStructure);
54f7544d 286
287 //
288 // Highlight in all activated views
289 //
290
291 for(int i=1; i<=MyDefinedView.Length(); i++)
292 {
293 (MyDefinedView.Value(i))->Highlight (AStructure, AMethod);
294 }
7fd59977 295}
296
54f7544d 297void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf)
298{
299 for(int i=1; i<=MyDefinedView.Length(); i++)
300 {
301 (MyDefinedView.Value(i))->SetTransform (AStructure, ATrsf);
302 }
7fd59977 303}
304
305void Visual3d_ViewManager::UnHighlight () {
306
307 Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
bf75be98 308
7fd59977 309 for (; it.More(); it.Next()) {
310 Handle(Graphic3d_Structure) SG = it.Key();
311 SG->UnHighlight ();
312 }
313
314
315}
316
54f7544d 317void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure)
318{
7fd59977 319 MyHighlightedStructure.Remove(AStructure);
320
54f7544d 321 //
322 // UnHighlight in all activated views
323 //
7fd59977 324
54f7544d 325 for(int i=1; i<=MyDefinedView.Length(); i++)
326 {
327 (MyDefinedView.Value(i))->UnHighlight (AStructure);
328 }
7fd59977 329}
330
679ecdee 331void Visual3d_ViewManager::Redraw() const
332{
333 // redraw all activated views
54f7544d 334 if (MyDefinedView.Length() == 0)
679ecdee 335 {
336 return;
337 }
bf75be98 338
679ecdee 339 if (!MyUnderLayer.IsNull() || !MyOverLayer.IsNull())
340 {
341 Standard_Integer aWidth = 0, aHeight = 0;
342 Standard_Integer aWidthMax = 0;
343 Standard_Integer aHeightMax = 0;
54f7544d 344
345 for(int i=1; i<=MyDefinedView.Length(); i++)
679ecdee 346 {
54f7544d 347 MyDefinedView.Value(i)->Window()->Size (aWidth, aHeight);
679ecdee 348 aWidthMax = Max (aWidthMax, aWidth);
c1c1aefa 349 aHeightMax = Max (aHeightMax, aHeight);
679ecdee 350 }
54f7544d 351
679ecdee 352 if (!MyUnderLayer.IsNull())
353 {
354 MyUnderLayer->SetViewport (aWidthMax, aHeightMax);
355 }
356 if (!MyOverLayer.IsNull())
357 {
358 MyOverLayer->SetViewport (aWidthMax, aHeightMax);
359 }
360 }
7fd59977 361
54f7544d 362 for(int i=1; i<=MyDefinedView.Length(); i++)
679ecdee 363 {
54f7544d 364 MyDefinedView.Value(i)->Redraw (MyUnderLayer, MyOverLayer);
365 }
7fd59977 366}
367
679ecdee 368void Visual3d_ViewManager::Update() const
369{
370 Redraw();
371}
7fd59977 372
679ecdee 373void Visual3d_ViewManager::RedrawImmediate() const
374{
54f7544d 375 if (MyDefinedView.Length() == 0)
679ecdee 376 {
377 return;
378 }
bf75be98 379
679ecdee 380 // update all activated views
54f7544d 381 for(int i=1; i<=MyDefinedView.Length(); i++)
679ecdee 382 {
54f7544d 383 MyDefinedView.Value(i)->RedrawImmediate (MyUnderLayer, MyOverLayer);
679ecdee 384 }
385}
7fd59977 386
679ecdee 387void Visual3d_ViewManager::Invalidate() const
388{
54f7544d 389 if (MyDefinedView.Length() == 0)
679ecdee 390 {
391 return;
392 }
7fd59977 393
679ecdee 394 // update all activated views
54f7544d 395 for(int i=1; i<=MyDefinedView.Length(); i++)
679ecdee 396 {
54f7544d 397 MyDefinedView.Value(i)->Invalidate();
679ecdee 398 }
7fd59977 399}
400
54f7544d 401Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::ActivatedView () const
402{
7fd59977 403
54f7544d 404 Handle(Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView();
7fd59977 405
54f7544d 406 for(int i=1; i<=MyDefinedView.Length(); i++)
407 {
408 if ((MyDefinedView.Value(i))->IsActive ())
409 {
410 SG->Append(MyDefinedView.Value(i));
411 }
412 }
7fd59977 413
54f7544d 414 return (SG);
7fd59977 415}
416
417#ifdef IMPLEMENTED
54f7544d 418Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const
419{
420 Standard_Boolean Result = Standard_False;
7fd59977 421
54f7544d 422 //
423 // Check all activated views
424 //
425 for(int i=1; (!Result) && i<=MyDefinedView.Length(); i++)
426 {
427 if ((MyDefinedView.Value(i))->IsActive())
428 {
429 Result = (MyDefinedView.Value(i))->ContainsComputedStructure();
430 }
431 }
7fd59977 432
54f7544d 433 return Result;
7fd59977 434}
435#endif
436
54f7544d 437Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::DefinedView () const
438{
439 Handle (Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView();
7fd59977 440
54f7544d 441 for(int i=1; i<=MyDefinedView.Length(); i++)
442 {
443 SG->Append(MyDefinedView.Value(i));
444 }
7fd59977 445
54f7544d 446 return (SG);
7fd59977 447}
448
54f7544d 449Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const
450{
451 Standard_Boolean Exist = Standard_False;
7fd59977 452
54f7544d 453 // Parse the list of views to find
454 // a view with the specified window
7fd59977 455
872f4e44 456#if defined(_WIN32) || defined(__WIN32__)
457 const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow);
566f8441 458 Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow ();
872f4e44 459#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
460 const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow);
461 NSView* TheSpecifiedWindowId = THEWindow->HView();
7fd59977 462#else
872f4e44 463 const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow);
464 int TheSpecifiedWindowId = int (THEWindow->XWindow ());
465#endif
7fd59977 466
54f7544d 467 for(int i=1; (!Exist) && i<=MyDefinedView.Length(); i++)
468 {
469 if ( ((MyDefinedView.Value(i))->IsDefined ()) && ((MyDefinedView.Value(i))->IsActive ()) )
470 {
471 const Handle(Aspect_Window) AspectWindow = (MyDefinedView.Value(i))->Window();
7fd59977 472
872f4e44 473#if defined(_WIN32) || defined(__WIN32__)
54f7544d 474 const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow);
475 Aspect_Handle TheWindowIdOfView = theWindow->HWindow ();
872f4e44 476#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
54f7544d 477 const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow);
478 NSView* TheWindowIdOfView = theWindow->HView();
7fd59977 479#else
54f7544d 480 const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow);
481 int TheWindowIdOfView = int (theWindow->XWindow ());
7fd59977 482#endif // WNT
54f7544d 483 // Comparaison on window IDs
484 if (TheWindowIdOfView == TheSpecifiedWindowId)
485 {
486 Exist = Standard_True;
487 TheCView = *(Graphic3d_CView* )(MyDefinedView.Value(i))->CView();
488 }
489 }
490 }
7fd59977 491
54f7544d 492 return (Exist);
7fd59977 493}
494
54f7544d 495void Visual3d_ViewManager::Activate ()
496{
497 //
498 // Activates all deactivated views
499 //
500 for(int i=1; i<=MyDefinedView.Length(); i++)
501 {
502 if (! (MyDefinedView.Value(i))->IsActive())
503 {
504 (MyDefinedView.Value(i))->Activate();
505 }
506 }
7fd59977 507}
508
54f7544d 509void Visual3d_ViewManager::Deactivate ()
510{
511 //
512 // Deactivates all activated views
513 //
514 for(int i=1; i<=MyDefinedView.Length(); i++)
515 {
516 if ((MyDefinedView.Value(i))->IsActive())
517 {
518 (MyDefinedView.Value(i))->Deactivate();
519 }
520 }
7fd59977 521
522}
523
524Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {
525
81bba717 526 // Retourne the planned of definable views for the current
527 // Visual3d_ViewManager.
7fd59977 528 return
529(Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));
530
531}
532
533Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {
534
535 return (Graphic3d_StructureManager::Identification (AId));
536
537}
538
539Standard_Integer Visual3d_ViewManager::Identification () const {
bf75be98 540
7fd59977 541 return (Graphic3d_StructureManager::Identification ());
542
543}
544
54f7544d 545Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView)
546{
547 MyDefinedView.Append(AView);
548 return (MyViewGenId.Next ());
7fd59977 549}
550
551void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
552{
54f7544d 553 for(int i=1; i<=MyDefinedView.Length(); i++)
30bf45dc 554 {
54f7544d 555 if ((MyDefinedView.Value(i))->Identification() == aViewId)
30bf45dc 556 {
30bf45dc 557 //remove the view from the list
54f7544d 558 MyDefinedView.Remove(i);
30bf45dc 559 break;
560 }
30bf45dc 561 }
54f7544d 562
7fd59977 563 MyViewGenId.Free(aViewId);
564}
565
54f7544d 566void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag)
567{
568 if (MyTransparency && AFlag) return;
569 if (! MyTransparency && ! AFlag) return;
7fd59977 570
54f7544d 571 for(int i=1; i<=MyDefinedView.Length(); i++)
572 {
573 (MyDefinedView.Value(i))->SetTransparency(AFlag);
574 }
7fd59977 575
54f7544d 576 MyTransparency = AFlag;
7fd59977 577}
578
54f7544d 579Standard_Boolean Visual3d_ViewManager::Transparency () const
580{
581 return (MyTransparency);
7fd59977 582}
583
54f7544d 584void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag)
585{
586 if (MyZBufferAuto && AFlag) return;
587 if (! MyZBufferAuto && ! AFlag) return;
588
589 // if pass from False to True :
590 // no problem, at the next view update, it
591 // will properly ask questions to answer (SetVisualisation)
592 // if pass from True to False :
593 // it is necessary to modify ZBufferActivity at each view so that
594 // zbuffer could be active only if required by context.
595 // In this case -1 is passed so that the view ask itself the question
596 // Note : 0 forces the desactivation, 1 forces the activation
597 if (! AFlag)
598 {
599 for(int i=1; i<=MyDefinedView.Length(); i++)
600 {
601 (MyDefinedView.Value(i))->SetZBufferActivity(-1);
602 }
603 }
604 MyZBufferAuto = AFlag;
7fd59977 605}
606
54f7544d 607Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const
608{
609 return (MyZBufferAuto);
7fd59977 610}
611
612void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {
613
614#ifdef TRACE_LAYER
615 cout << "Visual3d_ViewManager::SetLayer\n" << flush;
616#endif
617
618 if (ALayer->Type () == Aspect_TOL_OVERLAY) {
619#ifdef TRACE_LAYER
620 if (MyOverLayer.IsNull ())
621 cout << "MyOverLayer is defined" << endl;
622 else
623 cout << "MyOverLayer is redefined" << endl;
624#endif
625 MyOverLayer = ALayer;
626 }
627 else {
628#ifdef TRACE_LAYER
629 if (MyUnderLayer.IsNull ())
630 cout << "MyUnderLayer is defined" << endl;
631 else
632 cout << "MyUnderLayer is redefined" << endl;
633#endif
634 MyUnderLayer = ALayer;
635 }
636
637}
638
639const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {
640
641 return (MyUnderLayer);
642
643}
644
645const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {
646
647 return (MyOverLayer);
648
649}
59f45b7c 650
651//=======================================================================
652//function : ChangeZLayer
bf75be98 653//purpose :
59f45b7c 654//=======================================================================
655
656void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
657 const Standard_Integer theLayerId)
658{
659 if (!myLayerIds.Contains (theLayerId))
660 return;
bf75be98 661
59f45b7c 662 // change display layer for structure in all views
663 if (MyDisplayedStructure.Contains (theStructure))
664 {
54f7544d 665 for(int i=1; i<=MyDefinedView.Length(); i++)
666 {
667 (MyDefinedView.Value(i))->ChangeZLayer(theStructure, theLayerId);
668 }
59f45b7c 669 }
bf75be98 670
59f45b7c 671 // tell graphic driver to update the structure's display layer
63bcc448 672 MyGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), theLayerId);
59f45b7c 673}
674
675//=======================================================================
676//function : GetZLayer
677//purpose :
678//=======================================================================
679
680Standard_Integer Visual3d_ViewManager::GetZLayer (const Handle(Graphic3d_Structure)& theStructure) const
681{
63bcc448 682 return MyGraphicDriver->GetZLayer (*theStructure->CStructure ());
59f45b7c 683}
684
685//=======================================================================
c5751993 686//function : SetZLayerSettings
687//purpose :
688//=======================================================================
689void Visual3d_ViewManager::SetZLayerSettings (const Standard_Integer theLayerId,
690 const Graphic3d_ZLayerSettings& theSettings)
691{
692 // tell all managed views to set zlayer settings
54f7544d 693 for(int i=1; i<=MyDefinedView.Length(); i++)
c5751993 694 {
54f7544d 695 (MyDefinedView.Value(i))->SetZLayerSettings (theLayerId, theSettings);
c5751993 696 }
697
698 if (myMapOfZLayerSettings.IsBound (theLayerId))
699 {
700 myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings;
701 }
702 else
703 {
704 myMapOfZLayerSettings.Bind (theLayerId, theSettings);
705 }
706
707}
708
709//=======================================================================
710//function : ZLayerSettings
711//purpose :
712//=======================================================================
713Graphic3d_ZLayerSettings Visual3d_ViewManager::ZLayerSettings (const Standard_Integer theLayerId)
714{
715 if (!myLayerIds.Contains (theLayerId))
716 {
717 return Graphic3d_ZLayerSettings();
718 }
719
720 return myMapOfZLayerSettings.Find (theLayerId);
721}
722
723//=======================================================================
59f45b7c 724//function : AddZLayer
725//purpose :
726//=======================================================================
727
728Standard_Boolean Visual3d_ViewManager::AddZLayer (Standard_Integer& theLayerId)
729{
730 try
731 {
732 OCC_CATCH_SIGNALS
733 theLayerId = getZLayerGenId ().Next ();
734 myLayerIds.Add (theLayerId);
735 myLayerSeq.Append (theLayerId);
736 }
737 catch (Aspect_IdentDefinitionError)
738 {
739 // new index can't be generated
740 return Standard_False;
741 }
742
c5751993 743 // default z-layer settings
744 myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings());
745
59f45b7c 746 // tell all managed views to remove display layers
54f7544d 747 for(int i=1; i<=MyDefinedView.Length(); i++)
748 {
749 (MyDefinedView.Value(i))->AddZLayer(theLayerId);
750 }
59f45b7c 751
752 return Standard_True;
753}
754
755//=======================================================================
756//function : RemoveZLayer
bf75be98 757//purpose :
59f45b7c 758//=======================================================================
759
760Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Standard_Integer theLayerId)
761{
762 if (!myLayerIds.Contains (theLayerId) || theLayerId == 0)
763 return Standard_False;
764
765 // tell all managed views to remove display layers
54f7544d 766 for(int i=1; i<=MyDefinedView.Length(); i++)
767 {
768 (MyDefinedView.Value(i))->RemoveZLayer (theLayerId);
769 }
59f45b7c 770
771 MyGraphicDriver->UnsetZLayer (theLayerId);
772
773 // remove index
774 for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++)
c5751993 775 {
776 if (myLayerSeq (aIdx) == theLayerId)
59f45b7c 777 {
778 myLayerSeq.Remove (aIdx);
779 break;
780 }
c5751993 781 }
782
783 myMapOfZLayerSettings.UnBind (theLayerId);
59f45b7c 784
785 myLayerIds.Remove (theLayerId);
786 getZLayerGenId ().Free (theLayerId);
787
788 return Standard_True;
789}
790
791//=======================================================================
792//function : GetAllZLayers
793//purpose :
794//=======================================================================
795
796void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const
797{
798 theLayerSeq.Assign (myLayerSeq);
799}
800
801//=======================================================================
802//function : getZLayerGenId
803//purpose :
804//=======================================================================
805
806Aspect_GenId& Visual3d_ViewManager::getZLayerGenId ()
807{
808 static Aspect_GenId aGenId (1, IntegerLast());
809 return aGenId;
810}
71c4f9c6 811
812//=======================================================================
813//function : InstallZLayers
814//purpose :
815//=======================================================================
816
817void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const
818{
54f7544d 819 Standard_Boolean isContainsView = Standard_False;
820 for(int i=1; i<=MyDefinedView.Length(); i++)
821 {
822 if(MyDefinedView.Value(i) == theView)
823 {
824 isContainsView = Standard_True;
825 break;
826 }
827 }
828 if (!isContainsView)
71c4f9c6 829 return;
bf75be98 830
71c4f9c6 831 // erase and insert layers iteratively to provide the same layer order as
832 // in the view manager's sequence. This approach bases on the layer insertion
833 // order: the new layers are always appended to the end of the list
834 // inside of view, while layer remove operation doesn't affect the order.
835 // Starting from second layer : no need to change the default z layer.
836 for (Standard_Integer aSeqIdx = 2; aSeqIdx <= myLayerSeq.Length (); aSeqIdx++)
837 {
838 Standard_Integer aLayerID = myLayerSeq.Value (aSeqIdx);
839 theView->RemoveZLayer (aLayerID);
840 theView->AddZLayer (aLayerID);
841 }
842}