summaryrefslogtreecommitdiff
path: root/src/Visual3d/Visual3d_ViewManager.cxx
blob: dc9d337148e57f376b28021f568140e8af58ce48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264

/***********************************************************************

     FONCTION :
     ----------
        Classe Visual3d_ViewManager.cxx :

	Declaration of variables specific to visualisers

     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
      Mars 1992 : NW,JPB,CAL ; Creation.
      19-06-96  : FMN ; Suppression variables inutiles
      04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
      06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
      19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
      24-10-97  : CAL ; Retrait de DownCast.
      20-11-97  : CAL ; Disparition de la dependance avec math
      01-12-97  : CAL ; Retrait du test IsActive sur l'Update et le Redraw
      31-12-97  : CAL ; Disparition de MathGra 
      16-01-98  : CAL ; Ajout du SetTransform sur une TOS_COMPUTED
      11-03-98  : CAL ; Visual3d_ViewManager::Remove ()
      20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
      10-06-98  : CAL ; Modification des signatures de xxProjectRaster.
      10-06-98  : CAL ; Modification de la signature de ViewExists.
      01-12-98  : CAL ; S4062. Ajout des layers.
      02-12-98  : CAL ; Remove () ne detruit plus les vues.

************************************************************************/

/*----------------------------------------------------------------------*/
/*
 * Constants
 */

#define NO_DOWNCAST
#define NO_DESTROY

/*----------------------------------------------------------------------*/
/*
 * Includes
 */

// for the class
#include <Visual3d_ViewManager.ixx>
#include <Visual3d_ViewManager.pxx>

#include <Standard_ErrorHandler.hxx>

#include <Aspect.hxx>

#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_MapOfStructure.hxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>

#include <Visual3d_PickPath.hxx>
#include <Visual3d_SetIteratorOfSetOfView.hxx>

#ifndef WNT
# include <Xw_Window.hxx>
#else
# include <WNT_Window.hxx>
#endif  // WNT

//-Aliases

//-Global data definitions

//	-- les vues definies
//	MyDefinedView		:	SetOfView;

//	-- le generateur d'identificateurs de vues
//	MyViewGenId		: 	GenId;

//-Constructors

Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Aspect_GraphicDevice)& aDevice):
Graphic3d_StructureManager (aDevice),
MyDefinedView (),
MyViewGenId (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),
MyZBufferAuto (Standard_False),
MyTransparency (Standard_False)
{

Handle(Aspect_GraphicDriver) agd = aDevice->GraphicDriver ();

	MyGraphicDriver = *(Handle(Graphic3d_GraphicDriver) *) &agd;

}

//-Destructors

void Visual3d_ViewManager::Destroy () {

#ifdef DESTROY
	cout << "Visual3d_ViewManager::Destroy (" << MyId << ")\n" << flush;
#endif

	Remove ();
}

//-Methods, in order

void Visual3d_ViewManager::Remove () {

#ifdef DESTROY
	cout << "Visual3d_ViewManager::Remove (" << MyId << ")\n" << flush;
#endif

	//
	// Destroy all defined views
	//

#ifdef DESTROY
	cout << "The Manager " << MyId << " have " << Length << " defined views\n";
	cout << flush;
#endif
 
	MyDefinedView.Clear ();

}

void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) {

#ifdef TRACE
	cout << "Visual3d_ViewManager::ChangeDisplayPriority ("
	     << AStructure->Identification ()
	     << ", " << OldPriority << ", " << NewPriority << ")\n";
	cout << flush;
#endif

	//
	// Change structure priority in all defined views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->ChangeDisplayPriority
			(AStructure, OldPriority, NewPriority);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { 

  //Standard_Integer LengthD	= MyDisplayedStructure.Extent() ();

  // Even if physically the structure cannot
  // be displayed (pb of visualisation type)
  // it has status Displayed.
 
  if (!MyDisplayedStructure.Contains(AStructure))
    return;

  //
  // Recompute structure in all activated views
  //
  Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
  while (MyIterator.More ()) {
    (MyIterator.Value ())->ReCompute (AStructure);

    // MyIterator.Next () is located on the next view
    MyIterator.Next ();
  }
  
}

void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, 
				      const Handle(Graphic3d_DataStructureManager)& AProjector) 
{ 

  if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return;

#ifdef DOWNCAST
  Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector);
#else
  Handle(Visual3d_View) theView = *(Handle(Visual3d_View) *) &AProjector;
#endif
  Standard_Integer ViewId = theView->Identification ();


  // Even if physically the structure cannot
  // be displayed (pb of visualisation type)
  // it has status Displayed.
  if (!MyDisplayedStructure.Contains(AStructure))
    return;
	
  //
  // Recompute structure in all activated views
  //
  Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
  while (MyIterator.More ()) {
    if ((MyIterator.Value ())->Identification () == ViewId)
      theView->ReCompute (AStructure);

    // MyIterator.Next () is located on the next view
    MyIterator.Next ();
  }

}

void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) {

	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Clear (AStructure, WithDestruction);

		// MyIterator.Next ()  is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {

	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Connect (AMother, ADaughter);

		// MyIterator.Next ()  is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) {

	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Disconnect (AMother, ADaughter);

		// MyIterator.Next ()  is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) { 


 // Even if physically the structure cannot
  // be displayed (pb of visualisation type)
  // it has status Displayed.

  MyDisplayedStructure.Add(AStructure);

	//
	// Display structure in all activated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Display (AStructure);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) {


// Even if physically the structure cannot
  // be displayed (pb of visualisation type)
  // it has status Displayed.

 MyDisplayedStructure.Remove(AStructure);



	//
	// Erase structure in all defined views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Erase (AStructure);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

	MyHighlightedStructure.Remove (AStructure);
	MyVisibleStructure.Remove (AStructure);
	MyPickStructure.Remove (AStructure);

}

void Visual3d_ViewManager::Erase () {

 Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure);
 
 for (; it.More(); it.Next()) {
   Handle(Graphic3d_Structure) SG = it.Key();
   SG->Erase();
 }

}

void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) {

  MyHighlightedStructure.Add(AStructure);

	//
	// Highlight in all activated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Highlight (AStructure, AMethod);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) {

	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->SetTransform (AStructure, ATrsf);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::UnHighlight () {

  Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure);
  
  for (; it.More(); it.Next()) {
    Handle(Graphic3d_Structure) SG = it.Key();
    SG->UnHighlight ();
  }


}

void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) {

  MyHighlightedStructure.Remove(AStructure);


	//
	// UnHighlight in all activated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->UnHighlight (AStructure);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Redraw () const {

Standard_Integer MaxDx, MaxDy;
Standard_Integer Dx, Dy;
	MaxDx = MaxDy = IntegerFirst ();

	//
	// Redraw all activated views
	//
	Standard_Integer j = MyDefinedView.Extent ();
	if (j == 0) return;
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ()) {
	    while (MyIterator.More ()) {
		(MyIterator.Value ())->Window ()->Size (Dx, Dy);
		if (Dx > MaxDx) MaxDx = Dx;
		if (Dy > MaxDy) MaxDy = Dy;

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	    }
	    if (! MyUnderLayer.IsNull ())
		MyUnderLayer->SetViewport (MaxDx, MaxDy);
	    if (! MyOverLayer.IsNull ())
		MyOverLayer->SetViewport (MaxDx, MaxDy);
	}
 
	if (! MyUnderLayer.IsNull () || ! MyOverLayer.IsNull ())
	    MyIterator.Initialize (MyDefinedView);
	while (MyIterator.More ()) {
	    (MyIterator.Value ())->Redraw (MyUnderLayer, MyOverLayer);

	    // MyIterator.Next () is located on the next view
	    MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Update () const {

	//
	// Update all activated views
	//
	Standard_Integer j = MyDefinedView.Extent ();
	if (j == 0) return;
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		(MyIterator.Value ())->Update (MyUnderLayer, MyOverLayer);

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

Handle(Visual3d_HSetOfView) Visual3d_ViewManager::ActivatedView () const {

Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();

Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

	while (MyIterator.More ()) {
		if ((MyIterator.Value ())->IsActive ())
			SG->Add (MyIterator.Value ());

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

	return (SG);

}

#ifdef IMPLEMENTED
Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const {

Standard_Boolean Result = Standard_False;

	//
	// Check all activated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

	Standard_Integer i	= MyDefinedView.Extent ();

	while ((! Result) && (MyIterator.More ())) {
		if ((MyIterator.Value ())->IsActive ())
			Result	=
			(MyIterator.Value ())->ContainsComputedStructure ();

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

	return Result;
}
#endif

Handle(Visual3d_HSetOfView) Visual3d_ViewManager::DefinedView () const {

Handle (Visual3d_HSetOfView) SG = new Visual3d_HSetOfView ();

Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

	while (MyIterator.More ()) {
		SG->Add (MyIterator.Value ());

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

	return (SG);

}

void Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Graphic3d_Vertex& AVertex, Standard_Integer& AU, Standard_Integer& AV) const {

// Convert only if the data is correct
Standard_Boolean Exist;
Graphic3d_CView  TheCView;
//Graphic3d_Vertex Point;

TColStd_Array2OfReal Ori_Matrix (0,3,0,3);
TColStd_Array2OfReal Map_Matrix (0,3,0,3);

Standard_Integer Width, Height;
Standard_Real AX, AY, AZ;
Standard_Real Dx, Dy, Ratio;

	Exist	= ViewExists (AWindow, TheCView);

	if (! Exist) {
		AU = AV = IntegerLast ();
	}
	else {
    // NKV - 11.02.08 - Use graphic driver functions
    Standard_Boolean Result;

    AVertex.Coord (AX, AY, AZ);

    Result = MyGraphicDriver->ProjectRaster (TheCView, 
      Standard_ShortReal (AX), Standard_ShortReal (AY), Standard_ShortReal (AZ),
      AU, AV);

    // the old code
    if (!Result) {

      Standard_Real PtX, PtY, PtZ, PtT;
      Standard_Real APX, APY, APZ;
      Standard_Real APT;

      Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

      Standard_Integer stop = 0;

      while ((! stop) && (MyIterator.More ())) {
	if (TheCView.ViewId ==
	    (MyIterator.Value ())->Identification ()) {
	  Ori_Matrix	=
	    (MyIterator.Value ())->MatrixOfOrientation ();
	  Map_Matrix	=
	    (MyIterator.Value ())->MatrixOfMapping ();
	  stop	= 1;
	}

	// MyIterator.Next () is located on the next view
	MyIterator.Next ();
      }


      // WCS -> View Reference Coordinate Space
      PtX	= Ori_Matrix (0, 0) * AX
	        + Ori_Matrix (0, 1) * AY
	        + Ori_Matrix (0, 2) * AZ
	        + Ori_Matrix (0, 3);
      PtY	= Ori_Matrix (1, 0) * AX
	        + Ori_Matrix (1, 1) * AY
	        + Ori_Matrix (1, 2) * AZ
	        + Ori_Matrix (1, 3);
      PtZ	= Ori_Matrix (2, 0) * AX
	        + Ori_Matrix (2, 1) * AY
	        + Ori_Matrix (2, 2) * AZ
	        + Ori_Matrix (2, 3);
      PtT	= Ori_Matrix (3, 0) * AX
	        + Ori_Matrix (3, 1) * AY
	        + Ori_Matrix (3, 2) * AZ
	        + Ori_Matrix (3, 3);

      // VRCS -> Normalized Projection Coordinate Space
      APX	= Map_Matrix (0, 0) * PtX
	        + Map_Matrix (0, 1) * PtY
	        + Map_Matrix (0, 2) * PtZ
	        + Map_Matrix (0, 3) * PtT;
      APY	= Map_Matrix (1, 0) * PtX
	        + Map_Matrix (1, 1) * PtY
	        + Map_Matrix (1, 2) * PtZ
	        + Map_Matrix (1, 3) * PtT;
      APZ	= Map_Matrix (2, 0) * PtX
	        + Map_Matrix (2, 1) * PtY
	        + Map_Matrix (2, 2) * PtZ
	        + Map_Matrix (2, 3) * PtT;
      APT	= Map_Matrix (3, 0) * PtX
	        + Map_Matrix (3, 1) * PtY
	        + Map_Matrix (3, 2) * PtZ
	        + Map_Matrix (3, 3) * PtT;

      if (APT == 0. || stop == 0) {
	AU = AV = IntegerLast ();
      }
      else {
	APX /= APT;
	APY /= APT;
	APZ /= APT;

	// NPCS -> Device Coordinate Space
	AWindow->Size (Width, Height);
	Dx	= Standard_Real (Width);
	Dy	= Standard_Real (Height);
	Ratio	= Dx / Dy;
	if (Ratio >= 1.) {
	  AU = Standard_Integer (APX * Dx);
	  AV = Standard_Integer (Dy - APY * Dy * Ratio);
	}
	else {
	  AU = Standard_Integer (APX * Dx / Ratio);
	  AV = Standard_Integer (Dy - APY * Dy);
	}
      }
    }
  }

}

Graphic3d_Vertex Visual3d_ViewManager::ConvertCoord (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV) const {

// Convert only if the data is correct
Graphic3d_CView TheCView;
Graphic3d_Vertex Point;

	if (! ViewExists (AWindow, TheCView))
	    Point.SetCoord (RealLast (), RealLast (), RealLast ());
	else {
Standard_Integer Width, Height;
Standard_ShortReal x, y, z;
Standard_Boolean Result;

	    AWindow->Size (Width, Height);

	    Result	= MyGraphicDriver->UnProjectRaster (TheCView,
				0, 0, Width, Height,
				AU, AV, x, y, z);

	    // unproject is done by UnProjectRaster
	    if (Result) {
		Point.SetCoord
		    (Standard_Real (x), Standard_Real (y), Standard_Real (z));
	    }
	    // unproject cannot be done by UnProjectRaster
	    // Code suspended since drivers Phigs and Pex are abandoned.
	    else {

Standard_Real NPCX, NPCY, NPCZ;
Standard_Real VRCX, VRCY, VRCZ, VRCT;
Standard_Real WCX, WCY, WCZ, WCT;

TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);

Standard_Real Dx, Dy, Ratio;
Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

Standard_Integer stop = 0;

		while ((! stop) && (MyIterator.More ())) {
		    if (TheCView.ViewId ==
			(MyIterator.Value ())->Identification ()) {
			TOri_Matrix	=
				(MyIterator.Value ())->MatrixOfOrientation ();
			TMap_Matrix	=
				(MyIterator.Value ())->MatrixOfMapping ();
			stop	= 1;
		    }

		    // MyIterator.Next () is located on the next view
		    MyIterator.Next ();
		}

		// View Mapping Transformation and View Clip, inversion
		Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);

		// View Orientation Transformation, inversion
		Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);

		// (AU, AV) : Device Coordinate Space
		// DCS -> NPCS Normalized Projection Coordinate Space
		Dx	= Standard_Real (Width);
		Dy	= Standard_Real (Height);
		Ratio	= Dx / Dy;

		if (Ratio >= 1.) {
			NPCX	= Standard_Real (AU) / Dx;
			NPCY	= (Dy - Standard_Real (AV)) / Dx;
		}
		else {
			NPCX	= Standard_Real (AU) / Dy;
			NPCY	= (Dy - Standard_Real (AV)) / Dy;
		}
		NPCZ	= 0.0;

		// NPCS -> VRCS View Reference Coordinate Space
		// PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);

		VRCX	= TMap_Matrix_Inv (0, 0) * NPCX
			+ TMap_Matrix_Inv (0, 1) * NPCY
			+ TMap_Matrix_Inv (0, 2) * NPCZ
			+ TMap_Matrix_Inv (0, 3);
		VRCY	= TMap_Matrix_Inv (1, 0) * NPCX
			+ TMap_Matrix_Inv (1, 1) * NPCY
			+ TMap_Matrix_Inv (1, 2) * NPCZ
			+ TMap_Matrix_Inv (1, 3);
		VRCZ	= TMap_Matrix_Inv (2, 0) * NPCX
			+ TMap_Matrix_Inv (2, 1) * NPCY
			+ TMap_Matrix_Inv (2, 2) * NPCZ
			+ TMap_Matrix_Inv (2, 3);
		VRCT	= TMap_Matrix_Inv (3, 0) * NPCX
			+ TMap_Matrix_Inv (3, 1) * NPCY
			+ TMap_Matrix_Inv (3, 2) * NPCZ
			+ TMap_Matrix_Inv (3, 3);

		// VRCS -> WCS World Coordinate Space
		// PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);

		WCX	= TOri_Matrix_Inv (0, 0) * VRCX
			+ TOri_Matrix_Inv (0, 1) * VRCY
			+ TOri_Matrix_Inv (0, 2) * VRCZ
			+ TOri_Matrix_Inv (0, 3) * VRCT;
		WCY	= TOri_Matrix_Inv (1, 0) * VRCX
			+ TOri_Matrix_Inv (1, 1) * VRCY
			+ TOri_Matrix_Inv (1, 2) * VRCZ
			+ TOri_Matrix_Inv (1, 3) * VRCT;
		WCZ	= TOri_Matrix_Inv (2, 0) * VRCX
			+ TOri_Matrix_Inv (2, 1) * VRCY
			+ TOri_Matrix_Inv (2, 2) * VRCZ
			+ TOri_Matrix_Inv (2, 3) * VRCT;
		WCT	= TOri_Matrix_Inv (3, 0) * VRCX
			+ TOri_Matrix_Inv (3, 1) * VRCY
			+ TOri_Matrix_Inv (3, 2) * VRCZ
			+ TOri_Matrix_Inv (3, 3) * VRCT;

		if (WCT != 0.)
		    Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
		else
		    Point.SetCoord (RealLast (), RealLast (), RealLast ());
	    }
	}

	return (Point);

}

void Visual3d_ViewManager::ConvertCoordWithProj (const Handle(Aspect_Window)& AWindow, const Standard_Integer AU, const Standard_Integer AV, Graphic3d_Vertex& Point, Graphic3d_Vector& Proj) const {

// Conversion only if the data is correct
Graphic3d_CView TheCView;

        if (! ViewExists (AWindow, TheCView)) {
	    Point.SetCoord (RealLast (), RealLast (), RealLast ());
	    Proj.SetCoord (0., 0., 0.);
        }
	else {
Standard_Integer Width, Height;
Standard_ShortReal x, y, z;
Standard_ShortReal dx, dy, dz;
Standard_Boolean Result;

	    AWindow->Size (Width, Height);

	    Result	= MyGraphicDriver->UnProjectRasterWithRay (TheCView,
				0, 0, Width, Height,
				AU, AV, x, y, z, dx, dy, dz);

	    // unproject is done by UnProjectRaster
	    if (Result) {
		Point.SetCoord
		    (Standard_Real (x), Standard_Real (y), Standard_Real (z));
		Proj.SetCoord
		    (Standard_Real (dx), Standard_Real (dy), Standard_Real (dz));
                Proj.Normalize();
	    }
	    // unproject cannot be done by UnProjectRaster
	    // Code is suspended since drivers Phigs are Pex abandoned.
	    else {

Standard_Real NPCX, NPCY, NPCZ;
Standard_Real VRCX, VRCY, VRCZ, VRCT;
Standard_Real WCX, WCY, WCZ, WCT;

TColStd_Array2OfReal TOri_Matrix (0,3,0,3);
TColStd_Array2OfReal TMap_Matrix (0,3,0,3);
TColStd_Array2OfReal TOri_Matrix_Inv (0,3,0,3);
TColStd_Array2OfReal TMap_Matrix_Inv (0,3,0,3);

Standard_Real Dx, Dy, Ratio;
Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);

Standard_Integer stop = 0;

		while ((! stop) && (MyIterator.More ())) {
		    if (TheCView.ViewId ==
			(MyIterator.Value ())->Identification ()) {
			TOri_Matrix	=
				(MyIterator.Value ())->MatrixOfOrientation ();
			TMap_Matrix	=
				(MyIterator.Value ())->MatrixOfMapping ();
			stop	= 1;
		    }

		    // MyIterator.Next () is located on the next view
		    MyIterator.Next ();
		}

		// View Mapping Transformation and View Clip, inversion
		Aspect::Inverse (TMap_Matrix, TMap_Matrix_Inv);

		// View Orientation Transformation, inversion
		Aspect::Inverse (TOri_Matrix, TOri_Matrix_Inv);

		// (AU, AV) : Device Coordinate Space
		// DCS -> NPCS Normalized Projection Coordinate Space
		Dx	= Standard_Real (Width);
		Dy	= Standard_Real (Height);
		Ratio	= Dx / Dy;

		if (Ratio >= 1.) {
			NPCX	= Standard_Real (AU) / Dx;
			NPCY	= (Dy - Standard_Real (AV)) / Dx;
		}
		else {
			NPCX	= Standard_Real (AU) / Dy;
			NPCY	= (Dy - Standard_Real (AV)) / Dy;
		}
		NPCZ	= 0.0;

		// NPCS -> VRCS View Reference Coordinate Space
		// PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);

		VRCX	= TMap_Matrix_Inv (0, 0) * NPCX
			+ TMap_Matrix_Inv (0, 1) * NPCY
			+ TMap_Matrix_Inv (0, 2) * NPCZ
			+ TMap_Matrix_Inv (0, 3);
		VRCY	= TMap_Matrix_Inv (1, 0) * NPCX
			+ TMap_Matrix_Inv (1, 1) * NPCY
			+ TMap_Matrix_Inv (1, 2) * NPCZ
			+ TMap_Matrix_Inv (1, 3);
		VRCZ	= TMap_Matrix_Inv (2, 0) * NPCX
			+ TMap_Matrix_Inv (2, 1) * NPCY
			+ TMap_Matrix_Inv (2, 2) * NPCZ
			+ TMap_Matrix_Inv (2, 3);
		VRCT	= TMap_Matrix_Inv (3, 0) * NPCX
			+ TMap_Matrix_Inv (3, 1) * NPCY
			+ TMap_Matrix_Inv (3, 2) * NPCZ
			+ TMap_Matrix_Inv (3, 3);

		// VRCS -> WCS World Coordinate Space
		// PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);

		WCX	= TOri_Matrix_Inv (0, 0) * VRCX
			+ TOri_Matrix_Inv (0, 1) * VRCY
			+ TOri_Matrix_Inv (0, 2) * VRCZ
			+ TOri_Matrix_Inv (0, 3) * VRCT;
		WCY	= TOri_Matrix_Inv (1, 0) * VRCX
			+ TOri_Matrix_Inv (1, 1) * VRCY
			+ TOri_Matrix_Inv (1, 2) * VRCZ
			+ TOri_Matrix_Inv (1, 3) * VRCT;
		WCZ	= TOri_Matrix_Inv (2, 0) * VRCX
			+ TOri_Matrix_Inv (2, 1) * VRCY
			+ TOri_Matrix_Inv (2, 2) * VRCZ
			+ TOri_Matrix_Inv (2, 3) * VRCT;
		WCT	= TOri_Matrix_Inv (3, 0) * VRCX
			+ TOri_Matrix_Inv (3, 1) * VRCY
			+ TOri_Matrix_Inv (3, 2) * VRCZ
			+ TOri_Matrix_Inv (3, 3) * VRCT;

		if (WCT != 0.)
		    Point.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
		else
		    Point.SetCoord (RealLast (), RealLast (), RealLast ());

                // Define projection ray
		NPCZ	= 10.0;

		// NPCS -> VRCS View Reference Coordinate Space
		// PtVRC = Map_Matrix_Inv.Multiplied (PtNPC);

		VRCX	= TMap_Matrix_Inv (0, 0) * NPCX
			+ TMap_Matrix_Inv (0, 1) * NPCY
			+ TMap_Matrix_Inv (0, 2) * NPCZ
			+ TMap_Matrix_Inv (0, 3);
		VRCY	= TMap_Matrix_Inv (1, 0) * NPCX
			+ TMap_Matrix_Inv (1, 1) * NPCY
			+ TMap_Matrix_Inv (1, 2) * NPCZ
			+ TMap_Matrix_Inv (1, 3);
		VRCZ	= TMap_Matrix_Inv (2, 0) * NPCX
			+ TMap_Matrix_Inv (2, 1) * NPCY
			+ TMap_Matrix_Inv (2, 2) * NPCZ
			+ TMap_Matrix_Inv (2, 3);
		VRCT	= TMap_Matrix_Inv (3, 0) * NPCX
			+ TMap_Matrix_Inv (3, 1) * NPCY
			+ TMap_Matrix_Inv (3, 2) * NPCZ
			+ TMap_Matrix_Inv (3, 3);

		// VRCS -> WCS World Coordinate Space
		// PtWC = Ori_Matrix_Inv.Multiplied (PtVRC);

		WCX	= TOri_Matrix_Inv (0, 0) * VRCX
			+ TOri_Matrix_Inv (0, 1) * VRCY
			+ TOri_Matrix_Inv (0, 2) * VRCZ
			+ TOri_Matrix_Inv (0, 3) * VRCT;
		WCY	= TOri_Matrix_Inv (1, 0) * VRCX
			+ TOri_Matrix_Inv (1, 1) * VRCY
			+ TOri_Matrix_Inv (1, 2) * VRCZ
			+ TOri_Matrix_Inv (1, 3) * VRCT;
		WCZ	= TOri_Matrix_Inv (2, 0) * VRCX
			+ TOri_Matrix_Inv (2, 1) * VRCY
			+ TOri_Matrix_Inv (2, 2) * VRCZ
			+ TOri_Matrix_Inv (2, 3) * VRCT;
		WCT	= TOri_Matrix_Inv (3, 0) * VRCX
			+ TOri_Matrix_Inv (3, 1) * VRCY
			+ TOri_Matrix_Inv (3, 2) * VRCZ
			+ TOri_Matrix_Inv (3, 3) * VRCT;

                if (WCT != 0.) {
		    Proj.SetCoord (WCX/WCT, WCY/WCT, WCZ/WCT);
                    Proj.Normalize();
                }
		else
		    Proj.SetCoord (0., 0., 0.);
	    }
	}

}

Visual3d_PickDescriptor Visual3d_ViewManager::Pick (const Visual3d_ContextPick& CTX, const Handle(Aspect_Window)& AWindow, const Standard_Integer AX, const Standard_Integer AY) {

// The marking is activated only if the data is correct
Standard_Boolean DoPick = Standard_False;

CALL_DEF_PICK apick; //@todo CALL_DEF_PICK should have constructor
Standard_Integer Width, Height;

	// Parse the list of views to find a 
	// view having this specified window
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
	int TheWindowIdOfView;

#ifndef WNT
const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
	int TheSpecifiedWindowId = int (THEWindow->XWindow ());
#else
const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
	int TheSpecifiedWindowId = int (THEWindow->HWindow ());
#endif  // WNT

	while ((! DoPick) && (MyIterator.More ())) {

	   if ( ((MyIterator.Value ())->IsDefined ()) &&
		((MyIterator.Value ())->IsActive ()) ) {

const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
#ifndef WNT
const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
	TheWindowIdOfView = int (theWindow->XWindow ());
#else
const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
	TheWindowIdOfView = int (theWindow->HWindow ());
#endif  // WNT
		// Comparision on window IDs
		if (TheWindowIdOfView == TheSpecifiedWindowId) {
			DoPick		= Standard_True;

			// Update
			apick.WsId	=
			int ((MyIterator.Value ())->Identification ());

			apick.ViewId	=
			int ((MyIterator.Value ())->Identification ());
#ifndef WNT
			apick.DefWindow.XWindow	= TheSpecifiedWindowId;
#else
			apick.DefWindow.XWindow	= (HWND) TheSpecifiedWindowId;
#endif

			apick.x			= int (AX);
			apick.y			= int (AY);

			theWindow->Size (Width, Height);
			apick.DefWindow.dx	= float (Width);
			apick.DefWindow.dy	= float (Height);

			apick.Context.aperture	= (float) CTX.Aperture ();
			apick.Context.order	= int (CTX.Order ());
			apick.Context.depth	= int (CTX.Depth ());

		}
	   } /* if ((MyIterator.Value ())->IsDefined ()) { */

	   // MyIterator.Next () is located on the next view
	   MyIterator.Next ();
	}

	if (DoPick)
		MyGraphicDriver->Pick (apick);
	else
		apick.Pick.depth	= 0;

	// Picking : return
Standard_Integer i, j=0;
Standard_Integer NbPick;

Visual3d_PickDescriptor PDes (CTX);
Visual3d_PickPath PPat;

	PDes.Clear ();
	NbPick	= 0;
	// For i=0 it is not a graphic structure it is a view structure
	// For i=1 it is the displayed graphic structure
	// For i=2 to apick.Pick.depth-1 it is the connected graphic structures
	if (apick.Pick.depth != 0) {
	    j = apick.Pick.listid[1];
	    if ((Graphic3d_StructureManager::Identification (j))->
						IsSelectable ()) {
		// Maj element number
		PPat.SetElementNumber (apick.Pick.listelem[1]);
		// Maj pick identifier
		PPat.SetPickIdentifier (apick.Pick.listpickid[1]);
		// Maj structure
		PPat.SetStructIdentifier
			(Graphic3d_StructureManager::Identification (j));
		// Maj PickPath
		PDes.AddPickPath (PPat);
		NbPick++;
	    }
	}

	// Not very efficient, revise (CAL 22/09/95)
	if (apick.Pick.depth > 2) {
Handle(Graphic3d_Structure) StructCur =
	Graphic3d_StructureManager::Identification (j);
Standard_Boolean found;
Graphic3d_MapOfStructure Set;

	    for (i=2; i<apick.Pick.depth; i++) {
		found = Standard_False;
		j = apick.Pick.listid[i-1];
		Set.Clear ();
		StructCur->Descendants (Set);
Graphic3d_MapIteratorOfMapOfStructure IteratorD (Set);

		j = apick.Pick.listid[i];
		while (IteratorD.More () && !found) {
		    StructCur = IteratorD.Key ();
		    if (StructCur->Identification () == j ) {
			found = Standard_True;
			// Maj element number
			PPat.SetElementNumber (apick.Pick.listelem[i]);
			// Maj pick identifier
			PPat.SetPickIdentifier (apick.Pick.listpickid[i]);
			// Maj structure
			PPat.SetStructIdentifier (StructCur);
			// Maj PickPath
			PDes.AddPickPath (PPat);
			NbPick++;
		    }
		    // IteratorD.Next () is located on the next structure
		    IteratorD.Next ();
		}
	    }
	}

	apick.Pick.depth	= int (NbPick);

	MyGraphicDriver->InitPick ();

	return (PDes);

}

Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const {

Standard_Boolean Exist = Standard_False;

	// Parse the list of views to find
	// a view with the specified window
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
	int TheWindowIdOfView;

#ifndef WNT
const Handle(Xw_Window) THEWindow = *(Handle(Xw_Window) *) &AWindow;
	int TheSpecifiedWindowId = int (THEWindow->XWindow ());
#else
const Handle(WNT_Window) THEWindow = *(Handle(WNT_Window) *) &AWindow;
	int TheSpecifiedWindowId = int (THEWindow->HWindow ());
#endif  // WNT

	while ((! Exist) && (MyIterator.More ())) {

	   if ( ((MyIterator.Value ())->IsDefined ()) &&
		((MyIterator.Value ())->IsActive ()) ) {

const Handle(Aspect_Window) AspectWindow = (MyIterator.Value ())->Window ();
#ifndef WNT
const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AspectWindow;
	TheWindowIdOfView = int (theWindow->XWindow ());
#else
const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AspectWindow;
	TheWindowIdOfView = int (theWindow->HWindow ());
#endif  // WNT
		// Comparaison on window IDs
		if (TheWindowIdOfView == TheSpecifiedWindowId) {
			Exist	= Standard_True;
			TheCView	= *(CALL_DEF_VIEW *)(MyIterator.Value ())->CView ();
		}
	   } /* if ((MyIterator.Value ())->IsDefined ()) */

	   // MyIterator.Next () is located on the next view
	   MyIterator.Next ();
	}

	return (Exist);

}

void Visual3d_ViewManager::Activate () {

	//
	// Activates all deactivated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		if (! (MyIterator.Value ())->IsActive ())
			(MyIterator.Value ())->Activate ();

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

void Visual3d_ViewManager::Deactivate () {

	//
	// Deactivates all activated views
	//
	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
 
	while (MyIterator.More ()) {
		if ((MyIterator.Value ())->IsActive ())
			(MyIterator.Value ())->Deactivate ();

		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

}

Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const {

	// Retourne the planned of definable views for the current
	// Visual3d_ViewManager.
	return
(Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ()));

}

Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const {

	return (Graphic3d_StructureManager::Identification (AId));

}

Standard_Integer Visual3d_ViewManager::Identification () const {
 
	return (Graphic3d_StructureManager::Identification ());

}

Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) {

	MyDefinedView.Add (AView);
	return (MyViewGenId.Next ());

}

void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId)
{
  MyViewGenId.Free(aViewId);
}

void Visual3d_ViewManager::SetTransparency (const Standard_Boolean AFlag) {

	if (MyTransparency && AFlag) return;
	if (! MyTransparency && ! AFlag) return;

	Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
	while (MyIterator.More ()) {
		(MyIterator.Value ())->SetTransparency (AFlag);
		// MyIterator.Next () is located on the next view
		MyIterator.Next ();
	}

	MyTransparency	= AFlag;

}

Standard_Boolean Visual3d_ViewManager::Transparency () const {

	return (MyTransparency);

}

void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) {

	if (MyZBufferAuto && AFlag) return;
	if (! MyZBufferAuto && ! AFlag) return;

	// if pass from False to True :
	// no problem, at the next view update, it 
	// will properly ask questions to answer (SetVisualisation)
	// if pass from True to False :
	// it is necessary to modify ZBufferActivity at each view so that
	// zbuffer could be active only if required by context.
	// In this case -1 is passed so that the view ask itself the question
	// Note : 0 forces the desactivation, 1 forces the activation
	if (! AFlag) {
		Visual3d_SetIteratorOfSetOfView MyIterator(MyDefinedView);
		while (MyIterator.More ()) {
			(MyIterator.Value ())->SetZBufferActivity (-1);
			// MyIterator.Next () is located on the next view
			MyIterator.Next ();
		}
	}
	MyZBufferAuto	= AFlag;

}

Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const {

	return (MyZBufferAuto);

}

void Visual3d_ViewManager::SetLayer (const Handle(Visual3d_Layer)& ALayer) {

#ifdef TRACE_LAYER
	cout << "Visual3d_ViewManager::SetLayer\n" << flush;
#endif

	if (ALayer->Type () == Aspect_TOL_OVERLAY) {
#ifdef TRACE_LAYER
		if (MyOverLayer.IsNull ())
			cout << "MyOverLayer is defined" << endl;
		else
			cout << "MyOverLayer is redefined" << endl;
#endif
		MyOverLayer = ALayer;
	}
	else {
#ifdef TRACE_LAYER
		if (MyUnderLayer.IsNull ())
			cout << "MyUnderLayer is defined" << endl;
		else
			cout << "MyUnderLayer is redefined" << endl;
#endif
		MyUnderLayer = ALayer;
	}

}

const Handle(Visual3d_Layer)& Visual3d_ViewManager::UnderLayer () const {

	return (MyUnderLayer);

}

const Handle(Visual3d_Layer)& Visual3d_ViewManager::OverLayer () const {

	return (MyOverLayer);

}