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