summaryrefslogtreecommitdiff
path: root/src/Visual3d/Visual3d_View.cxx
blob: aad6e2b452d96355fc517480997668ed0dd23d81 (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
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
/***********************************************************************

     FONCTION :
     ----------
        Classe Visual3d_View.cxx :


        Declaration of variables specific to views.

        A view is defined by :
                -  ViewManager
                -  ContextView
                -  ViewMapping
                -  ViewOrientation

     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
      Mars 1992 : NW,JPB,CAL ; Creation.
      04-02-97  : FMN ; Suppression de PSOutput, XWDOutput ...
      22-04-97  : CAL ; Ajout du Plot.
      03-06-97  : FMN ; Correction calcul SetRatio
      06-05-97  : CAL ; Ajout du Clear sur les TOS_COMPUTED.
      28-07-97  : PCT ; Ajout lumiere frontale headlight.
      19-09-97  : CAL ; Remplacement de Window->Position par Window->Size;
      17-10-97  : CAL ; Le Projects nouveau est arrive. (NewProjects)
      24-10-97  : CAL ; Retrait de DownCast.
      24-10-97  : CAL ; Retrait des DataStructure (Vieille maquette inutilisee).
      17-11-97  : FMN ; Ajout DoResize dans Resized()
      20-11-97  : CAL ; Disparition de la dependance avec math
      ??-11-97  : CAL ; Retrait de la dependance avec math. Calcul developpe.
      ??-11-97  : CAL ; Ajout de NumberOfDisplayedStructures
      07-08-97  : PCT ; ajout support texture mapping
      05-01-98  : CAL ; Ajout de AnimationMode
      15-01-98  : FMN ; FRA60019 calcul Ratio pour MyViewMappingReset
      15-01-98  : CAL ; Ajout de la transformation d'une TOS_COMPUTED
      26-01-98  : CAL ; Ajout de la methode HaveTheSameOwner
      06-02-98  : FMN ; CTS19079: TOP TEN: Probleme de highlight dans EDesigner.
      05-03-98  : CAL ; GraphicTransform que si Trsf non invalidante
      27-03-98  : CAL ; Ajout de TheStructure = devant Compute (...) !!!!
      16-04-98  : CAL ; Remise a ID de la Trsf sur la COMPUTED
      20-05-98  : CAL ; Perfs. Connection entre structures COMPUTED.
      24-06-98  : CAL ; PRO14526 SetTransparency sur une vue non active.
      17-07-98  : CAL ; PRO14872 test sur aTrsf dans ::SetTransform.
      16-09-98  : BGN ; Points d'entree du Triedre (S3819, Phase 1)
      22-09-98  : BGN ; S3989 (anciennement S3819)
                        TypeOfTriedron* from Aspect (pas Visual3d)
      06-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
      16-10-98  : CAL ; Ajout d'un TIMER si CSF_GraphicTimer est definie.
      02-11-98  : CAL ; Retrait de OSD::SetSignal.
      18-11-98  : FMN ; Correction sur la gestion de la perspective
      02-12-98  : CAL ; S4062. Ajout des layers.
      13-09-99  : GG  ; GER61454 Adds LightLimit() and PlaneLimit() methods
      10-11-99  : GG  ; PRO19603 Add Redraw( area ) method
      14-01-00  : GG  ; IMP140100 Add ViewManager( ) method
      22-10-01  : SAV ; Added EnableDepthTest() method.
      30-04-02  : JMB ; MyDisplayStructure : use a Map instead of a Set (very bad performance
                        in data access when a lot of objects are used)
                        Will improve performance of selection mechanisms

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

#define BUC60572        //GG_03-08-99    Add protection on Zclipping & Zcueing planes
//              positions.

#define BUC60570        //GG 14-09-99 Don't activates lighting
//                      when the view shading model is NONE.

#define GER61454        //GG 14-09-99 Activates model clipping planes

#define IMP140100       //GG14-01-00 Add ViewManager( ) method

#define G003            //EUG 30-09-00 Degeneration management
//                                     Backfacing management

#define RIC120302       //GG Add a NEW SetWindow method which enable
//                      to connect a graphic widget and context to OGL.

#define  BUC61044    /* 25/10/01 SAV ; added functionality to control gl depth testing
                        from higher API */
#define  BUC61045    /* 25/10/01 SAV ; added functionality to control gl lighting
                        from higher API */

#define OCC1188         //SAV Added methods to set background image

/*----------------------------------------------------------------------*/
/*
 * Constantes
 */

#define NO_DEBUG
#define NO_DESTROY
#define NO_TRACE
#define NO_TRACE_ACCEPT
#define NO_TRACE_CLEAR
#define NO_TRACE_CONNECT
#define NO_TRACE_HIGH
#define NO_TRACE_COMP
#define NO_TRACE_TRSF
#define NO_TRACE_DISPLAY
#define NO_TRACE_ISCOMP
#define NO_TRACE_LENGTH
#define NO_TRACE_LAYER

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

#ifdef WNT
#include <windows.h>
#endif

// for the class
#include <Visual3d_View.ixx>
#include <Visual3d_View.pxx>
#include <Visual3d_DepthCueingDefinitionError.hxx>
#include <Visual3d_ZClippingDefinitionError.hxx>

#ifdef OLD_METHOD
#include <math_Vector.hxx>
#endif /* OLD_METHOD */

#include <OSD.hxx>

#include <Graphic3d_Structure.hxx>
#include <Graphic3d_MapOfStructure.hxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
#include <Graphic3d_DataStructureManager.hxx>

#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_GraphicDevice.hxx>

#include <Graphic3d_Vector.hxx>
#include <Graphic3d_Vertex.hxx>

#include <Visual3d_Light.hxx>
#include <Visual3d_SetOfLight.hxx>
#include <Visual3d_HSetOfLight.hxx>
#include <Visual3d_SetIteratorOfSetOfLight.hxx>

#include <Visual3d_ClipPlane.hxx>
#include <Visual3d_SetOfClipPlane.hxx>
#include <Visual3d_HSetOfClipPlane.hxx>
#include <Visual3d_SetIteratorOfSetOfClipPlane.hxx>

#include <Visual3d_SetIteratorOfSetOfView.hxx>

#include <Graphic3d_TextureEnv.hxx>

#include <TColStd_HArray2OfReal.hxx>

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

#include <float.h>

//-Aliases

//-Global data definitions

//-Constructors

Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager):
MyContext (),
MyViewMapping (),
MyViewMappingReset (),
MyViewOrientation (),
MyViewOrientationReset (),
MyTransformation (0, 3, 0, 3),
MyMatrixOfMapping (0, 3, 0, 3),
MyMatrixOfOrientation (0, 3, 0, 3),
MyTOCOMPUTESequence (),
MyCOMPUTEDSequence (),
MyDisplayedStructure ()
{
Standard_Integer i, j;

#ifdef IMP140100
        MyPtrViewManager        = AManager.operator->();
#else
        MyPtrViewManager        = (void *) AManager.operator->();
#endif

        memset (&MyCView, 0, sizeof(MyCView));
        MyCView.ViewId          = int (AManager->Identification (this));
        MyCView.Active          = 0;
        MyCView.IsDeleted       = 0;

        MyCView.WsId    = -1;
        MyCView.DefWindow.IsDefined     = 0;

        MyCView.Context.NbActiveLight   = 0;
        MyCView.Context.NbActivePlane   = 0;
#ifdef GER61454
        MyCView.Context.ActivePlane = NULL;
#endif

        for (i=0; i<=3; i++)
                for (j=0; j<=3; j++)
                        if (i == j)     MyTransformation (i, j) = 1.0;
                        else            MyTransformation (i, j) = 0.0;

Standard_Real X, Y, Z;

        (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferencePoint.x        = float (X);
        MyCView.Orientation.ViewReferencePoint.y        = float (Y);
        MyCView.Orientation.ViewReferencePoint.z        = float (Z);
        (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferencePlane.x        = float (X);
        MyCView.Orientation.ViewReferencePlane.y        = float (Y);
        MyCView.Orientation.ViewReferencePlane.z        = float (Z);
        (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferenceUp.x           = float (X);
        MyCView.Orientation.ViewReferenceUp.y           = float (Y);
        MyCView.Orientation.ViewReferenceUp.z           = float (Z);

Standard_Real Sx, Sy, Sz;

        MyViewOrientation.AxialScale(Sx, Sy, Sz);
        MyCView.Orientation.ViewScaleX                  = float (Sx);
        MyCView.Orientation.ViewScaleY                  = float (Sy);
        MyCView.Orientation.ViewScaleZ                  = float (Sz);

        // NKV : 23/07/07 - Define custom MODELVIEW matrix
        MyCView.Orientation.IsCustomMatrix = 0;
        memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
        MyCView.Orientation.ModelViewMatrix[0][0] =
        MyCView.Orientation.ModelViewMatrix[1][1] =
        MyCView.Orientation.ModelViewMatrix[2][2] =
        MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
        //

Standard_Real um, vm, uM, vM;

        MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
        (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
        MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
        MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
        MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
        MyCView.Mapping.ViewPlaneDistance       =
                        float (MyViewMapping.ViewPlaneDistance ());
        MyCView.Mapping.BackPlaneDistance       =
                        float (MyViewMapping.BackPlaneDistance ());
        MyCView.Mapping.FrontPlaneDistance      =
                        float (MyViewMapping.FrontPlaneDistance ());
        MyViewMapping.WindowLimit (um, vm, uM, vM);
        MyCView.Mapping.WindowLimit.um  = float (um);
        MyCView.Mapping.WindowLimit.vm  = float (vm);
        MyCView.Mapping.WindowLimit.uM  = float (uM);
        MyCView.Mapping.WindowLimit.vM  = float (vM);

        // NKV : 23/07/07 - Define custom MODELVIEW matrix
        MyCView.Mapping.IsCustomMatrix = 0;
        memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
        MyCView.Mapping.ProjectionMatrix[0][0] =
        MyCView.Mapping.ProjectionMatrix[1][1] =
        MyCView.Mapping.ProjectionMatrix[2][2] =
        MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
        //

        MyCView.Context.ZBufferActivity = -1;

        MyMatOfMapIsModified    = Standard_True;
        MyMatOfOriIsModified    = Standard_True;
        MyMatOfMapIsEvaluated   = Standard_False;
        MyMatOfOriIsEvaluated   = Standard_False;

        DegenerateModeIsActive  = Standard_False;
        AnimationModeIsActive   = Standard_False;
#ifdef G003
        MyCView.IsDegenerates     = 0;
        MyCView.IsDegeneratesPrev = 0;
        ComputedModeIsActive      = Standard_False;
        MyCView.Backfacing        = 0;
#endif  // G003

        MyCView.DefBitmap.bitmap = 0;
        MyCView.ptrUnderLayer = 0;
        MyCView.ptrOverLayer = 0;
        MyCView.GContext = 0;
        MyCView.GDisplayCB = 0;
        MyCView.GClientData = 0;

Handle(Aspect_GraphicDriver) agd =
        (MyViewManager->GraphicDevice ())->GraphicDriver ();

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

}

Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& AManager, const Visual3d_ViewOrientation& VO, const Visual3d_ViewMapping& VM, const Visual3d_ContextView& CTX):
MyTransformation (0, 3, 0, 3),
MyMatrixOfMapping (0, 3, 0, 3),
MyMatrixOfOrientation (0, 3, 0, 3),
MyTOCOMPUTESequence (),
MyCOMPUTEDSequence (),
MyDisplayedStructure ()
{
Standard_Integer i, j;

#ifdef IMP140100
        MyPtrViewManager        = AManager.operator->();
#else
        MyPtrViewManager        = (void *) AManager.operator->();
#endif

        MyViewOrientation       = VO;
        MyViewMapping           = VM;
        MyContext               = CTX;
        MyViewOrientationReset  = VO;
        MyViewMappingReset      = VM;

        memset (&MyCView, 0, sizeof(MyCView));
        MyCView.ViewId          = int (AManager->Identification (this));
        MyCView.Active          = 0;
        MyCView.IsDeleted       = 0;

        MyCView.WsId    = -1;
        MyCView.DefWindow.IsDefined     = 0;

        MyCView.Context.NbActiveLight   = 0;
        MyCView.Context.NbActivePlane   = 0;
#ifdef GER61454
        MyCView.Context.ActivePlane = NULL;
#endif

        for (i=0; i<=3; i++)
                for (j=0; j<=3; j++)
                        if (i == j)     MyTransformation (i, j) = 1.0;
                        else            MyTransformation (i, j) = 0.0;

Standard_Real X, Y, Z;

        (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferencePoint.x        = float (X);
        MyCView.Orientation.ViewReferencePoint.y        = float (Y);
        MyCView.Orientation.ViewReferencePoint.z        = float (Z);
        (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferencePlane.x        = float (X);
        MyCView.Orientation.ViewReferencePlane.y        = float (Y);
        MyCView.Orientation.ViewReferencePlane.z        = float (Z);
        (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
        MyCView.Orientation.ViewReferenceUp.x           = float (X);
        MyCView.Orientation.ViewReferenceUp.y           = float (Y);
        MyCView.Orientation.ViewReferenceUp.z           = float (Z);

Standard_Real Sx, Sy, Sz;

        MyViewOrientation.AxialScale(Sx, Sy, Sz);
        MyCView.Orientation.ViewScaleX                  = float (Sx);
        MyCView.Orientation.ViewScaleY                  = float (Sy);
        MyCView.Orientation.ViewScaleZ                  = float (Sz);

        // NKV : 23/07/07 - Define custom MODELVIEW matrix
        if (MyViewOrientation.IsCustomMatrix()) {
          MyCView.Orientation.IsCustomMatrix = 1;
          for ( i = 0; i < 4; i++)
            for ( j = 0; j < 4; j++)
              MyCView.Orientation.ModelViewMatrix[i][j] = (float) MyViewOrientation.MyModelViewMatrix->Value(i,j);
        }
        else {
          MyCView.Orientation.IsCustomMatrix = 0;
          memset( (float*)MyCView.Orientation.ModelViewMatrix, 0, 16*sizeof( float ) );
          MyCView.Orientation.ModelViewMatrix[0][0] =
          MyCView.Orientation.ModelViewMatrix[1][1] =
          MyCView.Orientation.ModelViewMatrix[2][2] =
          MyCView.Orientation.ModelViewMatrix[3][3] = 1.;
        }
        //

Standard_Real um, vm, uM, vM;

        MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
        (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
        MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
        MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
        MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
        MyCView.Mapping.ViewPlaneDistance       =
                        float (MyViewMapping.ViewPlaneDistance ());
        MyCView.Mapping.BackPlaneDistance       =
                        float (MyViewMapping.BackPlaneDistance ());
        MyCView.Mapping.FrontPlaneDistance      =
                        float (MyViewMapping.FrontPlaneDistance ());
        MyViewMapping.WindowLimit (um, vm, uM, vM);
        MyCView.Mapping.WindowLimit.um  = float (um);
        MyCView.Mapping.WindowLimit.vm  = float (vm);
        MyCView.Mapping.WindowLimit.uM  = float (uM);
        MyCView.Mapping.WindowLimit.vM  = float (vM);

        // NKV : 23/07/07 - Define custom MODELVIEW matrix
        if (MyViewMapping.IsCustomMatrix()) {
          MyCView.Mapping.IsCustomMatrix = 1;
          for ( i = 0; i < 4; i++)
            for ( j = 0; j < 4; j++)
              MyCView.Mapping.ProjectionMatrix[i][j] = (float) MyViewMapping.MyProjectionMatrix->Value(i,j);
        }
        else {
          MyCView.Mapping.IsCustomMatrix = 0;
          memset( (float*)MyCView.Mapping.ProjectionMatrix, 0, 16*sizeof( float ) );
          MyCView.Mapping.ProjectionMatrix[0][0] =
          MyCView.Mapping.ProjectionMatrix[1][1] =
          MyCView.Mapping.ProjectionMatrix[2][2] =
          MyCView.Mapping.ProjectionMatrix[3][3] = 1.;
        }
        //

        MyCView.Context.ZBufferActivity = -1;

        MyMatOfMapIsModified    = Standard_True;
        MyMatOfOriIsModified    = Standard_True;
        MyMatOfMapIsEvaluated   = Standard_False;
        MyMatOfOriIsEvaluated   = Standard_False;
#ifdef G003
        AnimationModeIsActive     = Standard_False;
        MyCView.IsDegenerates     = 0;
        MyCView.IsDegeneratesPrev = 0;
        ComputedModeIsActive      = Standard_False;
#endif  // G003

        MyCView.DefBitmap.bitmap = 0;
        MyCView.ptrUnderLayer = 0;
        MyCView.ptrOverLayer = 0;
        MyCView.GContext = 0;
        MyCView.GDisplayCB = 0;
        MyCView.GClientData = 0;

Handle(Aspect_GraphicDriver) agd =
        (MyViewManager->GraphicDevice ())->GraphicDriver ();

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

}

//-Destructors

//-Methods, in order
// RIC120302
void Visual3d_View::SetWindow (const Handle(Aspect_Window)&      AWindow,
                               const Aspect_RenderingContext     AContext,
                               const Aspect_GraphicCallbackProc& ADisplayCB,
                               const Standard_Address            AClientData)
{
  if (IsDeleted ()) return;

  if (IsDefined ())
    Visual3d_ViewDefinitionError::Raise ("Window already defined");

  MyCView.GContext        = AContext;
  MyCView.GDisplayCB      = ADisplayCB;
  MyCView.GClientData     = AClientData;
  SetWindow(AWindow);
}
// RIC120302

void Visual3d_View::SetWindow (const Handle(Aspect_Window)& AWindow) {

        if (IsDeleted ()) return;

        if (IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window already defined");

        MyWindow        = AWindow;
        MyCView.WsId                    = MyCView.ViewId;
        MyCView.DefWindow.IsDefined     = 1;
#ifndef WNT
const Handle(Xw_Window) theWindow = *(Handle(Xw_Window) *) &AWindow;
        MyCView.DefWindow.XWindow       = theWindow->XWindow ();
#ifdef RIC120302
        MyCView.DefWindow.XParentWindow = theWindow->XParentWindow ();
#endif
#else
WNT_WindowData* wd;
const Handle(WNT_Window) theWindow = *(Handle(WNT_Window) *) &AWindow;
        MyCView.DefWindow.XWindow       = ( HWND )(theWindow->HWindow());
#ifdef RIC120302
        MyCView.DefWindow.XParentWindow = ( HWND )(theWindow->HParentWindow());
#endif
        wd = ( WNT_WindowData* )GetWindowLongPtr (( HWND )(theWindow->HWindow()), GWLP_USERDATA);
        wd -> WNT_WDriver_Ptr = ( void* )this;
        wd -> WNT_VMgr        = ( void* )MyPtrViewManager;
#endif  /* WNT */

        Standard_Integer Width, Height;
        AWindow->Size (Width, Height);

        MyCView.DefWindow.dx    = float( Width );
        MyCView.DefWindow.dy    = float( Height );

        Standard_Real R, G, B;
        MyBackground    = MyWindow->Background ();
        (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
        MyCView.DefWindow.Background.r  = float (R);
        MyCView.DefWindow.Background.g  = float (G);
        MyCView.DefWindow.Background.b  = float (B);

        UpdateView ();
        if (! MyGraphicDriver->View (MyCView))
                Visual3d_ViewDefinitionError::Raise ("Association failed");

        MyGradientBackground = MyWindow->GradientBackground();
        SetGradientBackground(MyGradientBackground,1);

        Standard_Boolean AWait = Standard_False;        // => immediate update
        MyGraphicDriver->SetVisualisation (MyCView);
        MyGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn ());
        MyGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn ());
        MyGraphicDriver->ClipLimit (MyCView, AWait);
        MyGraphicDriver->Environment(MyCView);

        // Update planses of model clipping
        UpdatePlanes ();

        // Update light sources 
        UpdateLights ();

        /*
         * Association view-window does not cause the display
         * of structures that can be displayed in the new view.
         * In fact, association view-window is done, but the
         * display is produced only if the view is activated (Activate).
         */

        SetRatio ();

}

Handle(Aspect_Window) Visual3d_View::Window () const {

        if (! IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window not defined");

        return (MyWindow);

}

Standard_Boolean Visual3d_View::IsDefined () const {

        if (MyCView.DefWindow.IsDefined)
                return (Standard_True);
        else
                return (Standard_False);

}

Standard_Boolean Visual3d_View::IsDeleted () const {

        if (MyCView.IsDeleted)
                return (Standard_True);
        else
                return (Standard_False);

}

void Visual3d_View::Destroy () {

#ifdef DESTROY
        cout << "Visual3d_View::Destroy (" << Identification () << ")\n";
#endif

        // Since MyPtrViewManager can be already distroyed,
        // avoid attempts to access it in SetBackground()
        MyPtrViewManager = 0;
        Remove ();

}

void Visual3d_View::Remove () {

#ifdef DESTROY
        cout << "Visual3d_View::Remove (" << Identification () << ")" << endl;
#endif

        if (IsDeleted ()) return;
        if (! IsDefined ()) return;

        MyTOCOMPUTESequence.Clear ();
        MyCOMPUTEDSequence.Clear ();
        MyDisplayedStructure.Clear ();

        Quantity_Color BlackColor (0.0, 0.0, 0.0, Quantity_TOC_RGB);
        Aspect_Background BlackBackground (BlackColor);
        SetBackground (BlackBackground);

        Aspect_GradientBackground BlackGradBackground;
        SetGradientBackground (BlackGradBackground,0);

	if (MyPtrViewManager)
	  MyPtrViewManager->UnIdentification( MyCView.ViewId );

        MyGraphicDriver->RemoveView (MyCView);

        MyCView.WsId            = -1;
        MyCView.IsDeleted       = 1;
        MyCView.DefWindow.IsDefined     = 0;

        MyMatOfMapIsModified    = Standard_True;
        MyMatOfOriIsModified    = Standard_True;
        MyMatOfMapIsEvaluated   = Standard_False;
        MyMatOfOriIsEvaluated   = Standard_False;

        MyWindow.Nullify ();

}

void Visual3d_View::Resized () {

        if (IsDeleted ()) return;

        if (! IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window not defined");
        MyWindow->DoResize() ;
        SetRatio ();

}

void Visual3d_View::SetRatio () {

        if (IsDeleted ()) return;

Aspect_TypeOfUpdate UpdateMode = MyViewManager->UpdateMode ();
        MyViewManager->SetUpdateMode (Aspect_TOU_WAIT);

Standard_Real Umin, Vmin, Umax, Vmax;
Standard_Integer Dxw, Dyw;
Standard_Real Dxv, Dyv;
Standard_Real Xc, Yc;
Standard_Real Rap;

        Rap     = 0. ;
        MyWindow->Size (Dxw, Dyw);
        MyViewMapping.WindowLimit(Umin,Vmin,Umax,Vmax) ;
        Xc      = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
        Dxv     = Umax - Umin ; Dyv     = Vmax - Vmin ;
        if( Dxw > 0 && Dyw > 0 ) Rap = (Standard_Real)Dyw/(Standard_Real)Dxw ;
        if( Rap > 0.0 ) {

            if( Dxv <= Dyv )
            {
                if (Rap <= 1.0)
                {
                    Dyv = Dxv;
                    Dxv = Dxv/Rap;
                }
                else
                {
                    Dxv = Dxv;
                    Dyv = Dxv*Rap;
                }
            }
            else
            {
                if (Rap <= 1.0)
                {
                    Dxv = Dyv/Rap;
                    Dyv = Dyv;
                }
                else
                {
                    Dxv = Dyv;
                    Dyv = Dyv*Rap;
                }
            }

            Umin        = Xc - Dxv/2. ; Vmin    = Yc - Dyv/2. ;
            Umax        = Xc + Dxv/2. ; Vmax    = Yc + Dyv/2. ;

            MyViewMapping.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;

            // Update before SetViewMapping.

            MyCView.DefWindow.dx        = float( Dxw );
            MyCView.DefWindow.dy        = float( Dyw );

            SetViewMapping (MyViewMapping);
//          SetViewMappingDefault ();
            // FMN+ Update Ratio for MyViewMappingReset

            MyViewMappingReset.WindowLimit(Umin,Vmin,Umax,Vmax) ;
            Xc  = (Umin + Umax)/2. ; Yc = (Vmin + Vmax)/2. ;
            Dxv = Umax - Umin ; Dyv     = Vmax - Vmin ;

            if( Dxv <= Dyv )
            {
                if (Rap <= 1.0)
                {
                    Dyv = Dxv;
                    Dxv = Dxv/Rap;
                }
                else
                {
                    Dxv = Dxv;
                    Dyv = Dxv*Rap;
                }
            }
            else
            {
                if (Rap <= 1.0)
                {
                    Dxv = Dyv/Rap;
                    Dyv = Dyv;
                }
                else
                {
                    Dxv = Dyv;
                    Dyv = Dyv*Rap;
                }
            }

            Umin        = Xc - Dxv/2. ; Vmin    = Yc - Dyv/2. ;
            Umax        = Xc + Dxv/2. ; Vmax    = Yc + Dyv/2. ;

            MyViewMappingReset.SetWindowLimit(Umin,Vmin,Umax,Vmax) ;

            // FMN- Update Ratio for MyViewMappingReset

            MyGraphicDriver->RatioWindow (MyCView);
        }

        // Force recalculation of 2 matrices.
        //
        // The current view can help to reconstruct a copied view
        // that is itself. Owing to SetWindow and SetRatio the
        // recalculation of matrices of this new view is imposed.
        MyMatOfMapIsEvaluated   = Standard_False;
        MyMatOfOriIsEvaluated   = Standard_False;

        MyViewManager->SetUpdateMode (UpdateMode);
        if (UpdateMode == Aspect_TOU_ASAP) Update ();

}

void Visual3d_View::UpdateLights () {

Standard_Integer i, j;
CALL_DEF_LIGHT *lights=NULL;

#ifdef BUC60570
  if( MyContext.Model() == Visual3d_TOM_NONE ) {
// Activates only a white ambient light
    MyCView.Context.NbActiveLight = 1;
    lights      = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];
    MyCView.Context.ActiveLight = lights;

    lights[0].WsId              = MyCView.ViewId;
    lights[0].ViewId    = MyCView.ViewId;
    lights[0].LightType = int (Visual3d_TOLS_AMBIENT);
    lights[0].Active    = 1;
    lights[0].LightId   = 0;
    lights[0].Headlight = 0;
    lights[0].Color.r   = lights[0].Color.g = lights[0].Color.b = 1.;
  } else {
#endif
        i       = MyContext.NumberOfActivatedLights ();
        j       = MyGraphicDriver->InquireLightLimit ();
        MyCView.Context.NbActiveLight   = (i > j ? j : i);

        if (MyCView.Context.NbActiveLight > 0) {

                // Dynamic Allocation
                lights  = new CALL_DEF_LIGHT [MyCView.Context.NbActiveLight];

                MyCView.Context.ActiveLight     = lights;

Standard_Real X, Y, Z;

Standard_Real LightConcentration = 0.0;
Standard_Real LightAttenuation1 = 0.0;
Standard_Real LightAttenuation2 = 0.0;
Standard_Real LightAngle = 0.0;
Quantity_Color LightColor;
Graphic3d_Vertex LightPosition;
Graphic3d_Vector LightDirection;
Visual3d_TypeOfLightSource LightType=Visual3d_TOLS_AMBIENT;

                // Parcing of light sources
                for (j=0; j<MyCView.Context.NbActiveLight; j++) {
                        LightType       = (MyContext.ActivatedLight (j+1))->LightType ();

                        lights[j].WsId          = MyCView.ViewId;
                        lights[j].ViewId        = MyCView.ViewId;

                        lights[j].LightType     = int (LightType);
                        lights[j].Active        = 1;
                        lights[j].LightId       =
                                int ((MyContext.ActivatedLight (j+1))->Identification ());
                        lights[j].Headlight = (MyContext.ActivatedLight (j+1))->Headlight ()? 1:0;

                        switch (LightType) {

                        case Visual3d_TOLS_AMBIENT :
                                (MyContext.ActivatedLight (j+1))->Values (
                                                        LightColor
                                                                );
                        break;

                        case Visual3d_TOLS_POSITIONAL :
                                (MyContext.ActivatedLight (j+1))->Values (
                                                        LightColor,
                                                        LightPosition,
                                                        LightAttenuation1,
                                                        LightAttenuation2
                                                                );
                        break;

                        case Visual3d_TOLS_DIRECTIONAL :
                                (MyContext.ActivatedLight (j+1))->Values (
                                                        LightColor,
                                                        LightDirection
                                                                );
                        break;

                        case Visual3d_TOLS_SPOT :
                                (MyContext.ActivatedLight (j+1))->Values (
                                                        LightColor,
                                                        LightPosition,
                                                        LightDirection,
                                                        LightConcentration,
                                                        LightAttenuation1,
                                                        LightAttenuation2,
                                                        LightAngle
                                                                );
                        break;

                        }

                        lights[j].Color.r       = float (LightColor.Red ());
                        lights[j].Color.g       = float (LightColor.Green ());
                        lights[j].Color.b       = float (LightColor.Blue ());

                        if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
                             (LightType == Visual3d_TOLS_SPOT) ) {
                                LightPosition.Coord (X, Y, Z);
                                lights[j].Position.x    = float (X);
                                lights[j].Position.y    = float (Y);
                                lights[j].Position.z    = float (Z);
                        }

                        if ( (LightType == Visual3d_TOLS_DIRECTIONAL) ||
                             (LightType == Visual3d_TOLS_SPOT) ) {
                                LightDirection.Coord (X, Y, Z);
                                lights[j].Direction.x   = float (X);
                                lights[j].Direction.y   = float (Y);
                                lights[j].Direction.z   = float (Z);
                        }

                        if ( (LightType == Visual3d_TOLS_POSITIONAL) ||
                             (LightType == Visual3d_TOLS_SPOT) ) {
                                lights[j].Attenuation[0] =
                                        float (LightAttenuation1);
                                lights[j].Attenuation[1] =
                                        float (LightAttenuation2);
                        }

                        if (LightType == Visual3d_TOLS_SPOT) {
                                lights[j].Concentration =
                                        float (LightConcentration);
                                lights[j].Angle         =
                                        float (LightAngle);
                        }
                }

        }
#ifdef BUC60570
  }
#endif
        // management of light sources
        if (! IsDeleted ())
                if (IsDefined ())
                        MyGraphicDriver->SetLight (MyCView);

        // Dynamic allocation
        if (MyCView.Context.NbActiveLight > 0) delete [] lights;

}

void Visual3d_View::UpdatePlanes () {

Standard_Integer i, j;
CALL_DEF_PLANE *planes=NULL;

        i       = MyContext.NumberOfActivatedClipPlanes ();
        j       = MyGraphicDriver->InquirePlaneLimit ();
        MyCView.Context.NbActivePlane   = (i > j ? j : i);

        if (MyCView.Context.NbActivePlane > 0) {

                // Dynamic Allocation 
#ifdef GER61454 //Keep the plane address for the next Update !
                if( !MyCView.Context.ActivePlane )
                   MyCView.Context.ActivePlane = new CALL_DEF_PLANE [j];
                planes = MyCView.Context.ActivePlane;
#else
                planes  = new CALL_DEF_PLANE [MyCView.Context.NbActivePlane];

                MyCView.Context.ActivePlane     = planes;
#endif
Standard_Real A, B, C, D;

                // Parcing of clipping planes
                for (j=0; j<MyCView.Context.NbActivePlane; j++) {

                        planes[j].WsId          = MyCView.ViewId;
                        planes[j].ViewId        = MyCView.ViewId;

                        planes[j].Active        = 1;
                        planes[j].PlaneId       =
                                int ((MyContext.ActivatedClipPlane (j+1))->Identification ());

                        (MyContext.ActivatedClipPlane (j+1))->Plane (A, B, C, D);
                        planes[j].CoefA         = float (A);
                        planes[j].CoefB         = float (B);
                        planes[j].CoefC         = float (C);
                        planes[j].CoefD         = float (D);
                }

        }

        // Management of planes of clipping model
        if (! IsDeleted ())
                if (IsDefined ())
                        MyGraphicDriver->SetPlane (MyCView);

        // Dynamic allocation
#ifdef GER61454
        if ( MyCView.Context.ActivePlane && (MyCView.Context.NbActivePlane == 0)
 ) {
          delete [] MyCView.Context.ActivePlane;
          MyCView.Context.ActivePlane = NULL;
        }
#else
        if (MyCView.Context.NbActivePlane > 0) delete [] planes;
#endif

}

void Visual3d_View::SetBackground (const Aspect_Background& ABack) {

        if (IsDeleted ()) return;

        if (! IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window not defined");

        // At this level, only GL can update the background.
        // It is not necessary to call MyWindow->SetBackground (ABack); as
        // this method starts update of window background by X
        // (if the windowing is X)

        Standard_Real R, G, B;
        MyBackground    = ABack;
        (MyBackground.Color ()).Values (R, G, B, Quantity_TOC_RGB);
        MyCView.DefWindow.Background.r  = float (R);
        MyCView.DefWindow.Background.g  = float (G);
        MyCView.DefWindow.Background.b  = float (B);

        MyGraphicDriver->Background (MyCView);

        if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
          Update ();

}

void Visual3d_View::SetGradientBackground(const Aspect_GradientBackground& ABack, const Standard_Boolean update)
{

  if (IsDeleted ()) return;

  if (! IsDefined ())
    Visual3d_ViewDefinitionError::Raise ("Window not defined");

  MyGradientBackground = ABack;
  Quantity_Color aCol1,aCol2;
  MyGradientBackground.Colors(aCol1,aCol2);
  MyGraphicDriver->GradientBackground(MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());

  if ( update )
     Update ();
  else if (MyPtrViewManager && MyViewManager->UpdateMode () == Aspect_TOU_ASAP)
    Update();
}

void Visual3d_View::SetBackgroundImage( const Standard_CString FileName,
                                        const Aspect_FillMethod FillStyle,
                                        const Standard_Boolean update )
{
#ifdef OCC1188
  if ( IsDeleted() )
    return;
  if ( !IsDefined() )
    Visual3d_ViewDefinitionError::Raise ("Window not defined");

  MyGraphicDriver->BackgroundImage( FileName, MyCView, FillStyle );

  if ( update )
    Update();
  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
    Update();
#endif
}

void Visual3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle,
                                     const Standard_Boolean update )
{
#ifdef OCC1188
  if ( IsDeleted() )
    return;
  if ( !IsDefined() )
    Visual3d_ViewDefinitionError::Raise ("Window not defined");

  MyGraphicDriver->SetBgImageStyle( MyCView, FillStyle );

  if ( update )
    Update();
  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
    Update();
#endif
}

Aspect_Background Visual3d_View::Background () const {

        return (MyBackground);

}

void Visual3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle,
                                        const Standard_Boolean update )
{
  if ( IsDeleted() )
    return;
  if ( !IsDefined() )
    Visual3d_ViewDefinitionError::Raise ("Window not defined");

  MyGraphicDriver->SetBgGradientStyle( MyCView, FillStyle );

  if ( update )
    Update();
  else if ( MyViewManager->UpdateMode() == Aspect_TOU_ASAP )
    Update();

}

Aspect_GradientBackground Visual3d_View::GradientBackground () const {

        return MyGradientBackground;

}

void Visual3d_View::SetTransform (const TColStd_Array2OfReal& AMatrix) {

        if (IsDeleted ()) return;

Standard_Integer lr, ur, lc, uc;
Standard_Integer i, j;

        // Assign the new transformation in an array [0..3][0..3]
        // Avoid problems if the has defined a matrice [1..4][1..4]
        //                                                 ou [3..6][-1..2] !!
        lr      = AMatrix.LowerRow ();
        ur      = AMatrix.UpperRow ();
        lc      = AMatrix.LowerCol ();
        uc      = AMatrix.UpperCol ();

        if ( (ur - lr + 1 != 4) || (uc - lc + 1 != 4) )
                Visual3d_TransformError::Raise ("Transform : not a 4x4 matrix");

        for (i=0; i<=3; i++)
        for (j=0; j<=3; j++)
                MyTransformation (i, j) = AMatrix (lr + i, lc + j);

Graphic3d_Vector VPN;
Graphic3d_Vertex VRP;
Graphic3d_Vector VUP;
Standard_Real Sx, Sy, Sz;

Visual3d_ViewOrientation NewViewOrientation;

        VPN     = MyViewOrientation.ViewReferencePlane ();
        VRP     = MyViewOrientation.ViewReferencePoint ();
        VUP     = MyViewOrientation.ViewReferenceUp ();
	MyViewOrientation.AxialScale(Sx, Sy, Sz);

        NewViewOrientation.SetViewReferencePlane
                (Graphic3d_Structure::Transforms (Transform (), VPN));

        NewViewOrientation.SetViewReferencePoint
                (Graphic3d_Structure::Transforms (Transform (), VRP));

        NewViewOrientation.SetViewReferenceUp
                (Graphic3d_Structure::Transforms (Transform (), VUP));
	NewViewOrientation.SetAxialScale(Sx, Sy, Sz);

        SetViewOrientation (NewViewOrientation);

        MyMatOfOriIsModified    = Standard_True;
        MyMatOfOriIsEvaluated   = Standard_False;

}

const TColStd_Array2OfReal& Visual3d_View::Transform () const {

        return (MyTransformation);

}

void Visual3d_View::SetViewOrientation (const Visual3d_ViewOrientation& VO) {

        if (IsDeleted ()) return;

        MyViewOrientation       = VO;

Standard_Real X, Y, Z;

        // Tests on modification of parameters.
Standard_Boolean VUPIsModified  = Standard_False;
Standard_Boolean VRPIsModified  = Standard_False;
Standard_Boolean VRUIsModified  = Standard_False;
Standard_Boolean ScaleIsModified  = Standard_False;
Standard_Boolean CustomIsModified = Standard_False;

        (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
        VUPIsModified =
            MyCView.Orientation.ViewReferencePoint.x != float (X)
         || MyCView.Orientation.ViewReferencePoint.y != float (Y)
         || MyCView.Orientation.ViewReferencePoint.z != float (Z);
        MyCView.Orientation.ViewReferencePoint.x        = float (X);
        MyCView.Orientation.ViewReferencePoint.y        = float (Y);
        MyCView.Orientation.ViewReferencePoint.z        = float (Z);

        (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
        VRPIsModified =
            MyCView.Orientation.ViewReferencePlane.x != float (X)
         || MyCView.Orientation.ViewReferencePlane.y != float (Y)
         || MyCView.Orientation.ViewReferencePlane.z != float (Z);
        MyCView.Orientation.ViewReferencePlane.x        = float (X);
        MyCView.Orientation.ViewReferencePlane.y        = float (Y);
        MyCView.Orientation.ViewReferencePlane.z        = float (Z);

        (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
        VRUIsModified =
            MyCView.Orientation.ViewReferenceUp.x != float (X)
         || MyCView.Orientation.ViewReferenceUp.y != float (Y)
         || MyCView.Orientation.ViewReferenceUp.z != float (Z);
        MyCView.Orientation.ViewReferenceUp.x           = float (X);
        MyCView.Orientation.ViewReferenceUp.y           = float (Y);
        MyCView.Orientation.ViewReferenceUp.z           = float (Z);

Standard_Real Sx, Sy, Sz;

        MyViewOrientation.AxialScale(Sx, Sy, Sz);
	ScaleIsModified =
            MyCView.Orientation.ViewScaleX != float (X)
         || MyCView.Orientation.ViewScaleY != float (Y)
         || MyCView.Orientation.ViewScaleZ != float (Z);
        MyCView.Orientation.ViewScaleX                  = float (Sx);
        MyCView.Orientation.ViewScaleY                  = float (Sy);
        MyCView.Orientation.ViewScaleZ                  = float (Sz);

        CustomIsModified =
          Standard_Boolean(MyCView.Orientation.IsCustomMatrix != 0) != MyViewOrientation.IsCustomMatrix();  // note: warning should be removed by changing .IsCustomMatrix type
        MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
        if ( MyViewOrientation.IsCustomMatrix() ) {
          Standard_Integer i, j;
          for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++) {
              if (!CustomIsModified) CustomIsModified =
                MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
              MyCView.Orientation.ModelViewMatrix[i][j] = (float) MyViewOrientation.MyModelViewMatrix->Value(i,j);
            }
        }

#ifdef TRACE_TRSF
cout << "Visual3d_View::SetViewOrientation\n";
        if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
                cout <<   "VUPIsModified : " << VUPIsModified
                     << ", VRPIsModified : " << VRPIsModified
                     << ", VRUIsModified : " << VRUIsModified
                     << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
        else
                cout << "no modification\n" << flush;
#endif

        // restart if one of parameters is modified
        if (VUPIsModified || VRPIsModified || VRUIsModified || ScaleIsModified || CustomIsModified) {

	  if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
                MyMatOfOriIsModified    = Standard_True;
                MyMatOfOriIsEvaluated   = Standard_False;
	      }

                if (! IsDefined ()) return;

Standard_Boolean AWait = Standard_False;        // => immediate update
                MyGraphicDriver->ViewOrientation (MyCView, AWait);

                Compute ();

                if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
        }

}

Visual3d_ViewOrientation Visual3d_View::ViewOrientation () const {

        return (MyViewOrientation);

}

Visual3d_ViewOrientation Visual3d_View::ViewOrientationDefault () const {

        return (MyViewOrientationReset);

}

void Visual3d_View::SetViewOrientationDefault () {

        MyViewOrientationReset.Assign (MyViewOrientation);

}

void Visual3d_View::ViewOrientationReset () {

        if (IsDeleted ()) return;

        MyViewOrientation       = MyViewOrientationReset;

Standard_Real X, Y, Z;

        // Tests on modification of parameters.
Standard_Boolean VUPIsModified  = Standard_False;
Standard_Boolean VRPIsModified  = Standard_False;
Standard_Boolean VRUIsModified  = Standard_False;
Standard_Boolean CustomIsModified = Standard_False;

        (MyViewOrientation.ViewReferencePoint ()).Coord (X, Y, Z);
        VUPIsModified =
            MyCView.Orientation.ViewReferencePoint.x != float (X)
         || MyCView.Orientation.ViewReferencePoint.y != float (Y)
         || MyCView.Orientation.ViewReferencePoint.y != float (Y);
        MyCView.Orientation.ViewReferencePoint.x        = float (X);
        MyCView.Orientation.ViewReferencePoint.y        = float (Y);
        MyCView.Orientation.ViewReferencePoint.z        = float (Z);

        (MyViewOrientation.ViewReferencePlane ()).Coord (X, Y, Z);
        VRPIsModified =
            MyCView.Orientation.ViewReferencePlane.x != float (X)
         || MyCView.Orientation.ViewReferencePlane.y != float (Y)
         || MyCView.Orientation.ViewReferencePlane.y != float (Y);
        MyCView.Orientation.ViewReferencePlane.x        = float (X);
        MyCView.Orientation.ViewReferencePlane.y        = float (Y);
        MyCView.Orientation.ViewReferencePlane.z        = float (Z);

        (MyViewOrientation.ViewReferenceUp ()).Coord (X, Y, Z);
        VRUIsModified =
            MyCView.Orientation.ViewReferenceUp.x != float (X)
         || MyCView.Orientation.ViewReferenceUp.y != float (Y)
         || MyCView.Orientation.ViewReferenceUp.y != float (Y);
        MyCView.Orientation.ViewReferenceUp.x           = float (X);
        MyCView.Orientation.ViewReferenceUp.y           = float (Y);
        MyCView.Orientation.ViewReferenceUp.z           = float (Z);

Standard_Real Sx, Sy, Sz;

        MyViewOrientation.AxialScale(Sx, Sy, Sz);
        MyCView.Orientation.ViewScaleX                  = float (Sx);
        MyCView.Orientation.ViewScaleY                  = float (Sy);
        MyCView.Orientation.ViewScaleZ                  = float (Sz);

        CustomIsModified =
          Standard_Boolean(MyCView.Orientation.IsCustomMatrix != 0) != MyViewOrientation.IsCustomMatrix(); // note: warning should be removed by changing .IsCustomMatrix type
        MyCView.Orientation.IsCustomMatrix = MyViewOrientation.IsCustomMatrix();
        if ( MyViewOrientation.IsCustomMatrix() ) {
          Standard_Integer i, j;
          for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++) {
              if (!CustomIsModified) CustomIsModified =
                MyCView.Orientation.ModelViewMatrix[i][j] != MyViewOrientation.MyModelViewMatrix->Value(i,j);
              MyCView.Orientation.ModelViewMatrix[i][j] = (float)MyViewOrientation.MyModelViewMatrix->Value(i,j);
            }
        }

#ifdef TRACE_TRSF
cout << "Visual3d_View::ViewOrientationReset\n";
if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified)
cout <<   "VUPIsModified : " << VUPIsModified
     << ", VRPIsModified : " << VRPIsModified
     << ", VRUIsModified : " << VRUIsModified
     << ", CustomIsModified : " << CustomIsModified << "\n" << flush;
else
cout << "no modification\n" << flush;
#endif

        // Restart if one of parameters is modified
        if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {

	  if (VUPIsModified || VRPIsModified || VRUIsModified || CustomIsModified) {
                MyMatOfOriIsModified    = Standard_True;
                MyMatOfOriIsEvaluated   = Standard_False;
	      }

                if (! IsDefined ()) return;

Standard_Boolean AWait = Standard_False;        // => immediate update
                MyGraphicDriver->ViewOrientation (MyCView, AWait);

                Compute ();

                if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
        }

}

void Visual3d_View::SetViewMapping (const Visual3d_ViewMapping& VM) {

        if (IsDeleted ()) return;

Visual3d_TypeOfProjection OldType = MyViewMapping.Projection ();
Visual3d_TypeOfProjection NewType = VM.Projection ();

        MyViewMapping   = VM;

Standard_Real X, Y, Z;
Standard_Real um, vm, uM, vM;

        MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
        (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
        MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
        MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
        MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
        MyCView.Mapping.ViewPlaneDistance       =
                        float (MyViewMapping.ViewPlaneDistance ());
        MyCView.Mapping.BackPlaneDistance       =
                        float (MyViewMapping.BackPlaneDistance ());
        MyCView.Mapping.FrontPlaneDistance      =
                        float (MyViewMapping.FrontPlaneDistance ());
        MyViewMapping.WindowLimit (um, vm, uM, vM);
        MyCView.Mapping.WindowLimit.um  = float (um);
        MyCView.Mapping.WindowLimit.vm  = float (vm);
        MyCView.Mapping.WindowLimit.uM  = float (uM);
        MyCView.Mapping.WindowLimit.vM  = float (vM);

        MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
        if (MyViewMapping.IsCustomMatrix()) {
          Standard_Integer i, j;
          for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++)
              MyCView.Mapping.ProjectionMatrix[i][j] = (float)
                MyViewMapping.MyProjectionMatrix->Value(i,j);
        }

        MyMatOfMapIsModified    = Standard_True;
        MyMatOfMapIsEvaluated   = Standard_False;

        if (! IsDefined ()) return;

Standard_Boolean AWait = Standard_False;        // => immediate update
        MyGraphicDriver->ViewMapping (MyCView, AWait);

        // Passage Parallele/Perspective
        if (OldType != NewType)
                Compute ();

        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();

}

Visual3d_ViewMapping Visual3d_View::ViewMapping () const {

        return (MyViewMapping);

}

Visual3d_ViewMapping Visual3d_View::ViewMappingDefault () const {

        return (MyViewMappingReset);

}

void Visual3d_View::SetViewMappingDefault () {

        MyViewMappingReset.Assign (MyViewMapping);

}

void Visual3d_View::ViewMappingReset () {

        if (IsDeleted ()) return;

        MyViewMapping   = MyViewMappingReset;

Standard_Real X, Y, Z;
Standard_Real um, vm, uM, vM;

        MyCView.Mapping.Projection      = int (MyViewMapping.Projection ());
        (MyViewMapping.ProjectionReferencePoint ()).Coord (X, Y, Z);
        MyCView.Mapping.ProjectionReferencePoint.x      = float (X);
        MyCView.Mapping.ProjectionReferencePoint.y      = float (Y);
        MyCView.Mapping.ProjectionReferencePoint.z      = float (Z);
        MyCView.Mapping.ViewPlaneDistance       =
                        float (MyViewMapping.ViewPlaneDistance ());
        MyCView.Mapping.BackPlaneDistance       =
                        float (MyViewMapping.BackPlaneDistance ());
        MyCView.Mapping.FrontPlaneDistance      =
                        float (MyViewMapping.FrontPlaneDistance ());
        MyViewMapping.WindowLimit (um, vm, uM, vM);
        MyCView.Mapping.WindowLimit.um  = float (um);
        MyCView.Mapping.WindowLimit.vm  = float (vm);
        MyCView.Mapping.WindowLimit.uM  = float (uM);
        MyCView.Mapping.WindowLimit.vM  = float (vM);

        MyCView.Mapping.IsCustomMatrix = MyViewMapping.IsCustomMatrix();
        if (MyViewMapping.IsCustomMatrix()) {
          Standard_Integer i, j;
          for (i = 0; i < 4; i++)
            for (j = 0; j < 4; j++)
              MyCView.Mapping.ProjectionMatrix[i][j] = (float)
                MyViewMapping.MyProjectionMatrix->Value(i,j);
        }

        MyMatOfMapIsModified    = Standard_True;
        MyMatOfMapIsEvaluated   = Standard_False;

        if (! IsDefined ()) return;

Standard_Boolean AWait = Standard_False;        // => immediate update
        MyGraphicDriver->ViewMapping (MyCView, AWait);

        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();

}

void Visual3d_View::SetContext (const Visual3d_ContextView& CTX) {

        if (IsDeleted ()) return;

Visual3d_TypeOfVisualization OldVisualMode;
Visual3d_TypeOfVisualization NewVisualMode;

        // To manage display only in case of 
        // change of visualisation mode.
        OldVisualMode   = MyContext.Visualization ();
        NewVisualMode   = CTX.Visualization ();

Visual3d_TypeOfModel OldModel;
Visual3d_TypeOfModel NewModel;

        // To manage change of visualisation only in case 
        // of change of mode of visualisation or of type of shading.
        OldModel        = MyContext.Model ();
        NewModel        = CTX.Model ();

Standard_Boolean OldAliasingMode;
Standard_Boolean NewAliasingMode;

        // To manage antialiasing only in case of change.
        OldAliasingMode = MyContext.AliasingIsOn ();
        NewAliasingMode = CTX.AliasingIsOn ();

Standard_Boolean OldDepthCueingMode;
Standard_Boolean NewDepthCueingMode;

Standard_Real OldDepthCueingFrontPlane;
Standard_Real NewDepthCueingFrontPlane;
Standard_Real OldDepthCueingBackPlane;
Standard_Real NewDepthCueingBackPlane;

        // To manage the depth cueing only in case of change.
        OldDepthCueingMode              = MyContext.DepthCueingIsOn ();
        NewDepthCueingMode              = CTX.DepthCueingIsOn ();

        OldDepthCueingFrontPlane        = MyContext.DepthCueingFrontPlane ();
        NewDepthCueingFrontPlane        = CTX.DepthCueingFrontPlane ();
        OldDepthCueingBackPlane         = MyContext.DepthCueingBackPlane ();
        NewDepthCueingBackPlane         = CTX.DepthCueingBackPlane ();

Standard_Boolean OldFrontZClippingMode;
Standard_Boolean NewFrontZClippingMode;
Standard_Boolean OldBackZClippingMode;
Standard_Boolean NewBackZClippingMode;

Standard_Real OldZClippingFrontPlane;
Standard_Real NewZClippingFrontPlane;
Standard_Real OldZClippingBackPlane;
Standard_Real NewZClippingBackPlane;

        // To manage the Zclipping only in case of change.
        OldFrontZClippingMode   = MyContext.FrontZClippingIsOn ();
        NewFrontZClippingMode   = CTX.FrontZClippingIsOn ();
        OldBackZClippingMode    = MyContext.BackZClippingIsOn ();
        NewBackZClippingMode    = CTX.BackZClippingIsOn ();

        OldZClippingFrontPlane  = MyContext.ZClippingFrontPlane ();
        NewZClippingFrontPlane  = CTX.ZClippingFrontPlane ();
        OldZClippingBackPlane   = MyContext.ZClippingBackPlane ();
        NewZClippingBackPlane   = CTX.ZClippingBackPlane ();

Standard_Integer OldTexEnvId;
Standard_Integer NewTexEnvId;
Visual3d_TypeOfSurfaceDetail OldSurfaceDetail;
Visual3d_TypeOfSurfaceDetail NewSurfaceDetail;

        Handle(Graphic3d_TextureEnv)    TempTextureEnv1 = MyContext.TextureEnv();
        if (! TempTextureEnv1.IsNull()) OldTexEnvId = TempTextureEnv1->TextureId();
        else                            OldTexEnvId = -1;

        Handle(Graphic3d_TextureEnv)    TempTextureEnv2 = CTX.TextureEnv();

        if (! TempTextureEnv2.IsNull()) NewTexEnvId = TempTextureEnv2->TextureId();
        else                            NewTexEnvId = -1;

        OldSurfaceDetail = MyContext.SurfaceDetail();
        NewSurfaceDetail = CTX.SurfaceDetail();

        MyContext       = CTX;

        UpdateView ();

Standard_Boolean AWait = Standard_False;        // => immediate update
        if (IsDefined ()) {
                // management of visualization modes and types of shading.
                if ((OldVisualMode != NewVisualMode) || (OldModel != NewModel))
                        MyGraphicDriver->SetVisualisation (MyCView);

                // management of antialiasing.
                if (OldAliasingMode != NewAliasingMode)
                MyGraphicDriver->AntiAliasing (MyCView, NewAliasingMode);

                // management of depth_cueing.
                if ((OldDepthCueingMode != NewDepthCueingMode) ||
                    (OldDepthCueingFrontPlane != NewDepthCueingFrontPlane) ||
                    (OldDepthCueingBackPlane != NewDepthCueingBackPlane)) {
#ifdef BUC60572
                    if( NewDepthCueingMode &&
                        (NewDepthCueingBackPlane >= NewDepthCueingFrontPlane) )
                        Visual3d_DepthCueingDefinitionError::Raise
                        ("Bad value for DepthCueingPlanes position");
#endif
                        MyGraphicDriver->DepthCueing
                                (MyCView, NewDepthCueingMode);
                }

                // management of Zclipping
                if ((OldFrontZClippingMode != NewFrontZClippingMode) ||
                    (OldBackZClippingMode != NewBackZClippingMode) ||
                    (OldZClippingFrontPlane != NewZClippingFrontPlane) ||
                    (OldZClippingBackPlane != NewZClippingBackPlane)) {
#ifdef BUC60572
                    if( NewBackZClippingMode && NewFrontZClippingMode &&
                        (NewZClippingBackPlane >= NewZClippingFrontPlane) )
                        Visual3d_ZClippingDefinitionError::Raise
                        ("Bad value for ZClippingPlanes position");
#endif
                        MyGraphicDriver->ClipLimit (MyCView, AWait);
                }

                // management of textures
                if ( (OldTexEnvId != NewTexEnvId) ||
                     (OldSurfaceDetail != NewSurfaceDetail) )
                  MyGraphicDriver->Environment(MyCView);

                // Update of planes of model clipping
                UpdatePlanes ();

                // Update of light sources 
                UpdateLights ();
        }

        if (OldVisualMode != NewVisualMode) {

                /*
                 * Change of context =>
                 * Remove structures that cannot be displayed
                 * in the new visualisation mode.
                 * It is not necessary to warn ViewManager as
                 * this structure should not disappear from
                 * the list of structures displayed in it.
                 */
Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
Visual3d_TypeOfAnswer Answer;

                Standard_Integer i      = MyDisplayedStructure.Extent ();

Graphic3d_SequenceOfStructure FooSequence;

                while (S1Iterator.More ()) {
                        Answer  = AcceptDisplay (S1Iterator.Key ());
                        // If the structure can't be displayed in the 
                        // new context of the view, it is removed.
                        if ((Answer == Visual3d_TOA_NO) ||
                            (Answer == Visual3d_TOA_COMPUTE))
                                //Erase (S1Iterator.Key (), Aspect_TOU_WAIT);
                                FooSequence.Append (S1Iterator.Key ());

                        // S1Iterator.Next () is located on the next structure
                        S1Iterator.Next ();
                }

Standard_Integer Length = FooSequence.Length ();
                // The stored structures are removed
                for (i=1; i<=Length; i++)
                        Erase (FooSequence.Value (i), Aspect_TOU_WAIT);
                if (Length != 0) FooSequence.Clear ();

                /*
                 * Change of context =>
                 * Display structures that can be displayed 
                 * with the new visualisation mode.
                 * All structures with status Displayed are removed from the ViewManager 
                 * and displayed in the view directly, if the structure is not already 
                 * displayed and if the view accepts it in its context.
                 */

                i       = MyViewManager->NumberOfDisplayedStructures ();
                Graphic3d_MapOfStructure Map;
                MyViewManager->DisplayedStructures(Map);
                Graphic3d_MapIteratorOfMapOfStructure it(Map);

                for (; it.More(); it.Next()) {
                  Handle(Graphic3d_Structure) SG = it.Key();
                    if (! IsDisplayed (SG)) {
                      Answer = AcceptDisplay(SG);
                        // If the structure can be displayed in the 
                        // new context of the view, it is displayed.
                        if ((Answer == Visual3d_TOA_YES) ||
                            (Answer == Visual3d_TOA_COMPUTE))
                            //Display (MyViewManager->DisplayedStructure (j),
                                //Aspect_TOU_WAIT);
                        FooSequence.Append (SG);
                    }
                }

                Length  = FooSequence.Length ();
                // The stored structures are displayed
                for (i=1; i<=Length; i++)
                        Display (FooSequence.Value (i), Aspect_TOU_WAIT);
                if (Length != 0) FooSequence.Clear ();
        }

        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();

}

const Visual3d_ContextView& Visual3d_View::Context () const {

        return (MyContext);

}

void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& SG) const
{

  if (IsDeleted ()) return;

  Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);

  while (Iterator.More ()) {
    SG.Add (Iterator.Key ());

    // Iterator.Next () is located on the next structure
    Iterator.Next ();
  }

}

void Visual3d_View::Activate () {

        if (IsDeleted ()) return;

        if (! IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window not defined");

        if (! IsActive ()) {

                MyGraphicDriver->ActivateView (MyCView);
                MyGraphicDriver->Background (MyCView);
                MyGraphicDriver->Transparency
                        (MyCView, MyViewManager->Transparency ());

                MyCView.Active  = 1;

                /*
                 * Activation of a new view =>
                 * Display structures that can be displayed in this new view.
                 * All structures with status
                 * Displayed in ViewManager are returned and displayed in 
                 * the view directly, if the structure is not already 
                 * displayed and if the view accepts it in its context.
                 */

		Visual3d_TypeOfAnswer Answer;
                Graphic3d_MapOfStructure Map;
                MyViewManager->DisplayedStructures(Map);
                Graphic3d_MapIteratorOfMapOfStructure it(Map);

                for (; it.More(); it.Next()) {
                  Handle(Graphic3d_Structure) SG = it.Key();
                    if (! IsDisplayed (SG)) {
                      Answer    = AcceptDisplay(SG);
                        // If the structure can be displayed in the
                        // new context of the view, it is displayed.
                        if ((Answer == Visual3d_TOA_YES) ||
                            (Answer == Visual3d_TOA_COMPUTE))
                        Display (SG,Aspect_TOU_WAIT);
                    }
                }

        }

        // If the activation/desactivation of ZBuffer should be automatic
        // depending on the presence or absence of facets.
        if (MyViewManager->ZBufferAuto ()) {
Standard_Boolean BContainsFacet = ContainsFacet ();
Standard_Boolean BZBuffer       = ZBufferIsActivated ();
                // If the view contains facets
                // and if ZBuffer is not active
                if (BContainsFacet && ! BZBuffer)
                        SetZBufferActivity (1);
                // If the view does not contain facets
                // and if ZBuffer is active
                if (! BContainsFacet && BZBuffer)
                        SetZBufferActivity (0);
        }

        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();

}

Standard_Boolean Visual3d_View::IsActive () const {

        if (IsDeleted ()) return (Standard_False);

        if (MyCView.Active)
                return (Standard_True);
        else
                return (Standard_False);

}

void Visual3d_View::Deactivate () {

        if (IsDeleted ()) return;

        if (! IsDefined ())
                Visual3d_ViewDefinitionError::Raise ("Window not defined");

        if (IsActive ()) {

                MyGraphicDriver->DeactivateView (MyCView);

                /*
                 * Deactivation of a view =>
                 * Removal of structures displayed in this view.
                 * All structures with status
                 * Displayed in ViewManager are returned and removed from 
                 * the view directly, if the structure is not already 
                 * displayed and if the view accepts it in its context.
                */

		Visual3d_TypeOfAnswer Answer;
                Graphic3d_MapOfStructure Map;
                MyViewManager->DisplayedStructures(Map);
                Graphic3d_MapIteratorOfMapOfStructure it(Map);

                for (; it.More(); it.Next()) {
                  Handle(Graphic3d_Structure) SG = it.Key();
                    if (! IsDisplayed (SG)) {
                        Answer  = AcceptDisplay(SG);
                        // If the structure was displayed it is removed.
                        if ((Answer == Visual3d_TOA_YES) ||
                            (Answer == Visual3d_TOA_COMPUTE))
                                Erase (SG,Aspect_TOU_WAIT);
                    }
                }

                if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();

                // No action currently possible in the view
                MyCView.Active  = 0;
        }

}

void Visual3d_View::Redraw () {

        Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());

}

void Visual3d_View::Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {

        Redraw (MyViewManager->UnderLayer (), MyViewManager->OverLayer (), x, y, width, height);
}

void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        if (! MyWindow->IsMapped ()) return;

        // san - 14/04/2004 - set up Z buffer state before redrawing
       // If the activation/desactivation of ZBuffer should be automatic
        // depending on the presence or absence of facets.
        if (MyViewManager->ZBufferAuto ()) {
                Standard_Boolean BContainsFacet = ContainsFacet ();
                Standard_Boolean BZBuffer       = ZBufferIsActivated ();
                // If the view contains facets
                // and if ZBuffer is not active
                if (BContainsFacet && ! BZBuffer)
                        SetZBufferActivity (1);
                // If the view contains only facets
                // and if ZBuffer is active
                if (! BContainsFacet && BZBuffer)
                        SetZBufferActivity (0);
        }

        Aspect_CLayer2d OverCLayer;
        Aspect_CLayer2d UnderCLayer;
        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
        MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer);

}

void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) {

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        if (! MyWindow->IsMapped ()) return;

        // san - 14/04/2004 - set up Z buffer state before redrawing
          // If activation/desactivation of ZBuffer should be automatic
        // depending on the presence or absence of facets.
        if (MyViewManager->ZBufferAuto ()) {
        Standard_Boolean BContainsFacet = ContainsFacet ();
        Standard_Boolean BZBuffer       = ZBufferIsActivated ();
                // If the view contains facets
                // and if ZBuffer is not active
                if (BContainsFacet && ! BZBuffer)
                        SetZBufferActivity (1);
                // If the view contains only facets
                // and if ZBuffer is active
                if (! BContainsFacet && BZBuffer)
                        SetZBufferActivity (0);
        }

        Aspect_CLayer2d OverCLayer;
        Aspect_CLayer2d UnderCLayer;
        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
        MyGraphicDriver->Redraw (MyCView, UnderCLayer, OverCLayer, x, y, width, height);

}

void Visual3d_View::Update () {

        Update (MyViewManager->UnderLayer (), MyViewManager->OverLayer ());

}

void Visual3d_View::Update (const Handle(Visual3d_Layer)& AnUnderLayer, const Handle(Visual3d_Layer)& AnOverLayer) {

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        if (! MyWindow->IsMapped ()) return;

        // If activation/desactivation of ZBuffer should be automatic
        // depending on the presence or absence of facets.
        if (MyViewManager->ZBufferAuto ()) {
Standard_Boolean BContainsFacet = ContainsFacet ();
Standard_Boolean BZBuffer       = ZBufferIsActivated ();
                // If the view contains facets
                // and if ZBuffer is not active
                        if (BContainsFacet && ! BZBuffer)
                        SetZBufferActivity (1);
                   // If the view does not contain facets
                // and if ZBuffer is active
                if (! BContainsFacet && BZBuffer)
                        SetZBufferActivity (0);
        }

Aspect_CLayer2d OverCLayer;
Aspect_CLayer2d UnderCLayer;
        OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;
        if (! AnUnderLayer.IsNull ()) UnderCLayer = AnUnderLayer->CLayer ();
        if (! AnOverLayer.IsNull ()) OverCLayer = AnOverLayer->CLayer ();
        //OSD::SetSignal (Standard_False);
        MyGraphicDriver->Update (MyCView, UnderCLayer, OverCLayer);
        //OSD::SetSignal (Standard_True);

        MyMatOfMapIsModified    = Standard_False;
        MyMatOfOriIsModified    = Standard_False;

}

Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& AStructure) const {

// Return type of visualization of the view
Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();

// Return type of visualization of the structure
Graphic3d_TypeOfStructure StructType = AStructure->Visual ();

Visual3d_TypeOfAnswer Result = Visual3d_TOA_NO;

        if (StructType == Graphic3d_TOS_ALL)
                // The structure accepts any type of view
                Result  = Visual3d_TOA_YES;
        else {
                if ((StructType == Graphic3d_TOS_SHADING)
                        && (ViewType == Visual3d_TOV_SHADING))
                        Result  = Visual3d_TOA_YES;
                if ((StructType == Graphic3d_TOS_WIREFRAME)
                        && (ViewType == Visual3d_TOV_WIREFRAME))
                        Result  = Visual3d_TOA_YES;
                if ((StructType == Graphic3d_TOS_COMPUTED)
                        && (ViewType == Visual3d_TOV_WIREFRAME))
                        Result  = Visual3d_TOA_COMPUTE;
                if ((StructType == Graphic3d_TOS_COMPUTED)
                        && (ViewType == Visual3d_TOV_SHADING))
                        Result  = Visual3d_TOA_COMPUTE;
        }

#ifdef TRACE_ACCEPT
        if (Result == Visual3d_TOA_YES)
        cout << "YES = Visual3d_View" << MyCView.ViewId
             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
        if (Result == Visual3d_TOA_NO)
        cout << "NO = Visual3d_View" << MyCView.ViewId
             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
        if (Result == Visual3d_TOA_COMPUTE)
        cout << "COMPUTE = Visual3d_View" << MyCView.ViewId
             << "::AcceptDisplay (" << AStructure->Identification () << ")\n";
        cout << flush;
#endif

        return (Result);

}

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

        if (IsDeleted ()) return;
        if (! IsDefined ()) return;
        if (! IsActive ()) return;
        if (! IsDisplayed (AStructure)) return;

Standard_Integer Index = IsComputed (AStructure);
#ifdef G003
        if (  Index != 0 && ComputedMode () && !DegenerateModeIsOn ()  )
#else
        if ((Index != 0) && (! DegenerateModeIsOn ()))
#endif  // G003
        {
#ifdef TRACE
	Standard_Integer StructId = MyCOMPUTEDSequence.Value (Index)->Identification ();
        cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
             << AStructure->Identification () << "/" << StructId
             << ", " << OldPriority << ", " << NewPriority << ")\n";
        cout << flush;
#endif
                MyGraphicDriver->EraseStructure
                        (MyCView,
                         *(Graphic3d_CStructure *)
                            MyCOMPUTEDSequence.Value (Index)->CStructure ());
                MyGraphicDriver->DisplayStructure
                        (MyCView,
                         *(Graphic3d_CStructure *)
                            MyCOMPUTEDSequence.Value (Index)->CStructure (),
                         int (NewPriority));
        }
        else {
#ifdef TRACE
        Standard_Integer StructId = AStructure->Identification ();
        cout << "Visual3d_View" << MyCView.ViewId << "::ChangeDisplayPriority ("
             << AStructure->Identification () << "/" << StructId
             << ", " << OldPriority << ", " << NewPriority << ")\n";
        cout << flush;
#endif
                MyGraphicDriver->EraseStructure
                        (MyCView,
                         *(Graphic3d_CStructure *)AStructure->CStructure ());
                MyGraphicDriver->DisplayStructure
                        (MyCView,
                         *(Graphic3d_CStructure *)AStructure->CStructure (),
                         int (NewPriority));
        }

}

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

#ifdef TRACE_CLEAR
        cout << "Visual3d_View" << MyCView.ViewId << "::Clear ("
             << AStructure->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer Index = IsComputed (AStructure);
        if (Index != 0) {
#ifdef TRACE_CLEAR
        cout << "Structure " << AStructure->Identification ()
             << " calculated in the view "
             << Identification () << ", by structure "
             << MyCOMPUTEDSequence.Value (Index)->Identification ()
             << " is emptied.\n";
        cout << flush;
#endif
                MyCOMPUTEDSequence.Value (Index)->GraphicClear (WithDestruction);
                MyCOMPUTEDSequence.Value (Index)->SetHLRValidation (Standard_False);
        }

}

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

#ifdef TRACE_CONNECT
        cout << "Visual3d_View" << MyCView.ViewId << "::Connect ("
             << AMother->Identification ()
             << ADaughter->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer IndexM = IsComputed (AMother);
Standard_Integer IndexD = IsComputed (ADaughter);

        if (IndexM != 0 && IndexD != 0) {
#ifdef TRACE_CONNECT
        cout << "Structure " << AMother->Identification ()
             << " is connected to structure "
             << ADaughter->Identification () << endl;
        cout << "These structures are calculated.\n";
        cout << "In the view " << Identification ()
             << "Structure "
             << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
             << " is connected to the structure "
             << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
             << endl;
#endif
                MyCOMPUTEDSequence.Value (IndexM)->GraphicConnect (MyCOMPUTEDSequence.Value (IndexD));
        }

}

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

#ifdef TRACE_CONNECT
        cout << "Visual3d_View" << MyCView.ViewId << "::Disconnect ("
             << AMother->Identification ()
             << ADaughter->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer IndexM = IsComputed (AMother);
Standard_Integer IndexD = IsComputed (ADaughter);

        if (IndexM != 0 && IndexD != 0) {
#ifdef TRACE_CONNECT
        cout << "Structure " << AMother->Identification ()
             << " is disconnected from the structure "
             << ADaughter->Identification () << endl;
        cout << "These structures are calculated.\n";
        cout << "In the view " << Identification ()
             << "Structure "
             << MyCOMPUTEDSequence.Value (IndexM)->Identification ()
             << " is disconnected from the structure "
             << MyCOMPUTEDSequence.Value (IndexD)->Identification ()
             << endl;
#endif
                MyCOMPUTEDSequence.Value (IndexM)->GraphicDisconnect (MyCOMPUTEDSequence.Value (IndexD));
        }

}

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

        Display (AStructure, MyViewManager->UpdateMode ());

}

void Visual3d_View::Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {

        if (IsDeleted ()) return;
        if (! IsDefined ()) return;
        if (! IsActive ()) return;

        // If Display on a structure present in the list
        // of calculated structures while it is not 
        // or more, of calculated type =>
        // - removes it as well as the associated old computed
        // THis happens when hlhsr becomes again of type e
        // non computed after SetVisual.
Standard_Integer Index = IsComputed (AStructure);

        if ((Index != 0) && (AStructure->Visual () != Graphic3d_TOS_COMPUTED)) {

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
                cout << "In Visual3d_View::Display, ";
                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
        }
#endif
                MyTOCOMPUTESequence.Remove (Index);
                MyCOMPUTEDSequence.Remove (Index);

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif
                Index = 0;
        }

	Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);

#ifdef TRACE_DISPLAY
	Standard_Integer StructId = AStructure->Identification ();
        cout << "Visual3d_View" << MyCView.ViewId << "::Display ("
             << StructId << ");\n";
        cout << flush;
#endif

        if (Answer == Visual3d_TOA_NO) {
#ifdef TRACE_DISPLAY
                cout << "Answer : Visual3d_TOA_NO\n";
                cout << flush;
#endif
                return;
        }

        // Mode degenerated active
#ifdef G003
        if (  !ComputedMode () || DegenerateModeIsOn ()  )
                                        Answer = Visual3d_TOA_YES;
#else
        if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
;
#endif  // G003

        if (Answer == Visual3d_TOA_YES ) {
#ifdef TRACE_DISPLAY
                cout << "Answer : Visual3d_TOA_YES\n";
                cout << flush;
#endif
                if (IsDisplayed (AStructure)) return;
                MyGraphicDriver->DisplayStructure (
                        MyCView,
                        *(Graphic3d_CStructure *)AStructure->CStructure (),
                        int (AStructure->DisplayPriority ())
                );
                MyDisplayedStructure.Add (AStructure);
                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
        }

        if (Answer == Visual3d_TOA_COMPUTE) {
#ifdef TRACE_DISPLAY
            cout << "Answer : Visual3d_TOA_COMPUTE\n";
            cout << "Index : " << Index << "\n" << flush;
#endif
            if (Index != 0) {
                // Already computed, is COMPUTED still valid?
#ifdef TRACE_DISPLAY
                if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
                  cout << "Structure "
                     << MyTOCOMPUTESequence.Value (Index)->Identification ()
                     << "already calculated, in the view "
                     << Identification () << ", par la structure "
                     << MyCOMPUTEDSequence.Value (Index)->Identification ()
                     << "\n was not recalculated as HLR is valid\n";
                  cout << flush;
                }
                else {
                  cout << "Structure "
                     << MyTOCOMPUTESequence.Value (Index)->Identification ()
                     << " already calculated, in the view "
                     << Identification () << ", by the structure "
                     << MyCOMPUTEDSequence.Value (Index)->Identification ()
                     << "\n should be recalculated as HLR is invalid\n";
                  cout << flush;
                }
#endif

                // Case COMPUTED valide
                if (MyCOMPUTEDSequence.Value (Index)->HLRValidation ()) {
                    // to be displayed
                    if (! IsDisplayed (AStructure)) {
                        MyDisplayedStructure.Add (AStructure);
                        MyGraphicDriver->DisplayStructure (
                            MyCView,
                            *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
                            int (AStructure->DisplayPriority ())
                        );
                        if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
                    }
                    return;
                }

                // Case COMPUTED invalid
                else {
                    // Is there another valid representation ?
                    // Find in the sequence of already calculated structures
                    // 1/ Structure having the same Owner as <AStructure>
                    // 2/ That is not <AStructure>
                    // 3/ The COMPUTED which of is valid
                    Standard_Integer NewIndex = HaveTheSameOwner (AStructure);

                    // Case of COMPUTED invalid, WITH a valid of replacement
                    if (NewIndex != 0) {
                        // to be displayed
                        if (! IsDisplayed (AStructure)) {
                            MyCOMPUTEDSequence.SetValue
                                (Index, MyCOMPUTEDSequence.Value (NewIndex));
                            MyDisplayedStructure.Add (AStructure);
                            MyGraphicDriver->DisplayStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (NewIndex)->CStructure (),
                                int (AStructure->DisplayPriority ())
                            );
                            if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
                        }
                        return;
                    }

                    // Cas COMPUTED invalid, WITHOUT a valid of replacement
                    else {
                        // COMPUTED is removed if displayed 
                        if (IsDisplayed (AStructure))
                            MyGraphicDriver->EraseStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ()
                            );
                    }
                }
            } // if (Index != 0)

            // Compute + Validation
#ifdef OLD
Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
#else
Handle(Graphic3d_Structure) TheStructure;
TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
            AStructure->Transform (ATrsf);
            if (Index != 0) {
TColStd_Array2OfReal Ident (0, 3, 0, 3);
Standard_Integer ii, jj;
        for (ii=0; ii<=3; ii++)
            for (jj=0; jj<=3; jj++)
                Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
                TheStructure = MyCOMPUTEDSequence.Value (Index);
                TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
                if (AStructure->IsTransformed ()) {
                    AStructure->Compute (this, ATrsf, TheStructure);
                }
                else {
                    AStructure->Compute (this, TheStructure);
                }
            }
            else {
                if (AStructure->IsTransformed ()) {
                    TheStructure = AStructure->Compute (this, ATrsf);
                }
                else {
                    TheStructure = AStructure->Compute (this);
                }
            }
#endif
            TheStructure->SetHLRValidation (Standard_True);

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif

            // TOCOMPUTE and COMPUTED associated to sequences are added
            MyTOCOMPUTESequence.Append (AStructure);
            MyCOMPUTEDSequence.Append (TheStructure);

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif

            // The previous are removed if necessary
            if (Index != 0) {
                MyTOCOMPUTESequence.Remove (Index);
                MyCOMPUTEDSequence.Remove (Index);
            }

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif

// Return type of visualisation of the view
Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();

// Of which type will be the computed ?
Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
                (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));

Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
                (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));

            if (ComputeWireframe)
                TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
            if (ComputeShading)
                TheStructure->SetVisual (Graphic3d_TOS_SHADING);

            if (! ComputeShading && ! ComputeWireframe)
                Answer = Visual3d_TOA_NO;
            else
                Answer = AcceptDisplay (TheStructure);

            if (AStructure->IsHighlighted()) {
                TheStructure->SetHighlightColor (AStructure->HighlightColor ());
                TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
            }

#ifdef TRACE_DISPLAY
            cout << "Structure " << StructId
                 << " in the view " << Identification ()
                 << " is calculated by the structure "
                 << TheStructure->Identification ();
            if (Answer == Visual3d_TOA_YES)
                cout << " and displayed\n";
            else
                cout << " but not displayed\n";
            cout << flush;
#endif

            // It is displayed only if the calculated structure 
            // has a proper type corresponding to the one of the view.
            if (Answer != Visual3d_TOA_NO) {
                if (! IsDisplayed (AStructure))
                        MyDisplayedStructure.Add (AStructure);
                MyGraphicDriver->DisplayStructure (
                        MyCView,
                        *(Graphic3d_CStructure *)TheStructure->CStructure (),
                        int (AStructure->DisplayPriority ())
                );
                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
            }
        } // Visual3d_TOA_COMPUTE
}

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

        if (IsDeleted ()) return;

        Erase (AStructure, MyViewManager->UpdateMode ());

}

void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode) {

        if (IsDeleted ()) return;

        // No test on window as the structure is displayed only if 
        // the window exists, so only one test is enough.
        if (IsDisplayed (AStructure)) {
Visual3d_TypeOfAnswer Answer = AcceptDisplay (AStructure);

                // Degenerated mode is active
#ifdef G003
                if (  !ComputedMode () || DegenerateModeIsOn ()  )
                                        Answer = Visual3d_TOA_YES;
#else
                if (DegenerateModeIsOn ()) Answer = Visual3d_TOA_YES;
#endif  // G003

                if (Answer != Visual3d_TOA_COMPUTE) {
                        MyGraphicDriver->EraseStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)AStructure->CStructure ()
                        );
                }

                if (Answer == Visual3d_TOA_COMPUTE) {
Standard_Integer Index = IsComputed (AStructure);
#ifdef TRACE_COMP
        cout << "Visual3d_View" << MyCView.ViewId << "::Erase ("
             << AStructure->Identification () << ");\n";
        cout << "Index : " << Index << "\n";
        cout << flush;
#endif
#ifdef G003
                    if (  Index != 0 && ComputedMode () &&
                                                !DegenerateModeIsOn ()  )
#else
                    if ((Index != 0) && (! DegenerateModeIsOn ()))
#endif  // G003
                    {
#ifdef TRACE_COMP
                        Standard_Integer StructId =
                        MyCOMPUTEDSequence.Value (Index)->Identification ();
        cout << "Structure " << AStructure->Identification ()
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << StructId << " is removed. \n";
        cout << flush;
#endif
                        MyGraphicDriver->EraseStructure
                                (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
                    }
                    // else is impossible
                }
                MyDisplayedStructure.Remove (AStructure);
                if (AnUpdateMode == Aspect_TOU_ASAP) Update ();
        }

}

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

#ifdef TRACE_HIGH
        cout << "Visual3d_View" << MyCView.ViewId << "::Highlight ("
             << AStructure->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer Index = IsComputed (AStructure);
        if (Index != 0) {
#ifdef TRACE_HIGH
        cout << "Structure " << AStructure->Identification ()
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << MyCOMPUTEDSequence.Value (Index)->Identification ()
             << " passes in highlight mode.\n";
        cout << flush;
#endif
                (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
                        (AStructure->HighlightColor ());
                (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (AMethod);
        }

}

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

#ifdef TRACE_TRSF
        cout << "Visual3d_View" << MyCView.ViewId << "::Transform ("
             << AStructure->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer Index = IsComputed (AStructure);
        if (Index != 0) {
#ifdef TRACE_TRSF
        cout << "The structure " << AStructure->Identification ()
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << MyCOMPUTEDSequence.Value (Index)->Identification ()
             << " is transformed.\n";
        cout << flush;
#endif
                // Test is somewhat light !
                // trsf is transferred only if it is :
                // a translation
                // a scale
                if (ATrsf (0, 1) != 0. || ATrsf (0, 2) != 0.
                 || ATrsf (1, 0) != 0. || ATrsf (1, 2) != 0.
                 || ATrsf (2, 0) != 0. || ATrsf (2, 1) != 0.)
                    ReCompute (AStructure);
                else
                    MyCOMPUTEDSequence.Value (Index)->GraphicTransform (ATrsf);
        }

}

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

#ifdef TRACE_HIGH
        cout << "Visual3d_View" << MyCView.ViewId << "::UnHighlight ("
             << AStructure->Identification () << ")\n";
        cout << flush;
#endif

Standard_Integer Index = IsComputed (AStructure);
        if (Index != 0) {
#ifdef TRACE_HIGH
        cout << "Structure " << AStructure->Identification ()
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << MyCOMPUTEDSequence.Value (Index)->Identification ()
             << " passes in unhighlight mode.\n";
        cout << flush;
#endif
                MyCOMPUTEDSequence.Value (Index)->GraphicUnHighlight ();
        }


}

Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& AStructure) const {

Standard_Integer StrId = AStructure->Identification ();

Standard_Integer Result = 0;
Standard_Integer Length = MyTOCOMPUTESequence.Length ();

        // Recherche de la structure <AStructure> dans la
        // sequence des structures deja calculees
        for (Standard_Integer i=1; i<=Length && Result==0; i++)
                if ((MyTOCOMPUTESequence.Value (i))->Identification ()
                        == StrId) Result        = i;
#ifdef TRACE_ISCOMP
        cout << "\n In the view " << Identification () << " the structure ";
        if (Result != 0)
                cout << StrId << " is calculated by "
                     << MyCOMPUTEDSequence.Value (Result)->Identification ()
                     << "\n" << flush;
        else
                cout << StrId << " is not calculated\n" << flush;
#endif

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
                cout << "In Visual3d_View::IsComputed, ";
                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
        }
#endif

        return (Result);

}

Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const {

Standard_Boolean Result = Standard_False;

        if (IsDeleted ()) return Result;

        Result  = MyDisplayedStructure.Contains (AStructure);

        return Result;

}

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

Standard_Boolean Result = Standard_False;

        if (MyDisplayedStructure.IsEmpty ()) return Result;

Graphic3d_MapIteratorOfMapOfStructure Iterator (MyDisplayedStructure);

        Standard_Integer i      = MyDisplayedStructure.Extent ();

        // Stop at the first structure of type TOS_COMPUTED
        while (! Result && Iterator.More ()) {
                Result  =
                (((Iterator.Key ())->Visual ()) == Graphic3d_TOS_COMPUTED);

                // Iterator.Next () is located on the 
                // next structure
                Iterator.Next ();
        }

        return Result;

}
#endif

Standard_Boolean Visual3d_View::ContainsFacet () const {

        return ContainsFacet (MyDisplayedStructure);

}

Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& ASet) const {

Standard_Boolean Result = Standard_False;

        if (ASet.IsEmpty ()) return Result;

Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);

        // Stop at the first structure containing a facet
        for ( Iterator.Initialize (ASet);
              Iterator.More () && ! Result;
              Iterator.Next ())
                Result  = (Iterator.Key ())->ContainsFacet ();

        return Result;

}

void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {

        MinMaxValues
        (MyDisplayedStructure, XMin, YMin, ZMin, XMax, YMax, ZMax);

}

void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& ZMin, Standard_Real& XMax, Standard_Real& YMax, Standard_Real& ZMax) const {

  if (ASet.IsEmpty ()) {
    XMin = RealFirst ();
    YMin = RealFirst ();
    ZMin = RealFirst ();

    XMax = RealLast ();
    YMax = RealLast ();
    ZMax = RealLast ();
  }
  else {

  Standard_Real Xm, Ym, Zm, XM, YM, ZM;
  Graphic3d_MapIteratorOfMapOfStructure Iterator (ASet);

  XMin = RealLast ();
  YMin = RealLast ();
  ZMin = RealLast ();

  XMax = RealFirst ();
  YMax = RealFirst ();
  ZMax = RealFirst ();

  for ( Iterator.Initialize (ASet);
        Iterator.More ();
        Iterator.Next ()) {

      if ( (Iterator.Key ())->IsInfinite ()){
        //XMin, YMin .... ZMax are initialized by means of infinite line data
        (Iterator.Key ())->MinMaxValues (Xm, Ym, Zm, XM, YM, ZM);
        if ( Xm != RealFirst() && Xm < XMin )
          XMin = Xm ;
        if ( Ym != RealFirst() && Ym < YMin )
          YMin = Ym ;
        if ( Zm != RealFirst() && Zm < ZMin )
          ZMin = Zm ;
        if ( XM != RealLast()  && XM > XMax )
          XMax = XM ;
        if ( YM != RealLast()  && YM > YMax )
          YMax = YM ;
        if ( ZM != RealLast()  && ZM > ZMax )
          ZMax = ZM ;
      }
      // Only non-empty and non-infinite structures 
      // are taken into account for calculation of MinMax
      if (! (Iterator.Key ())->IsInfinite () &&
          ! (Iterator.Key ())->IsEmpty ()) {
            (Iterator.Key ())->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);
          /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
          //"FitAll" operation ignores object with transform persitence parameter
          if( (Iterator.Key ())->TransformPersistenceMode() == Graphic3d_TMF_None )
          {
            if (Xm < XMin) XMin = Xm;
            if (Ym < YMin) YMin = Ym;
            if (Zm < ZMin) ZMin = Zm;
            if (XM > XMax) XMax = XM;
            if (YM > YMax) YMax = YM;
            if (ZM > ZMax) ZMax = ZM;
          }
        }
    }

    // The following cases are relevant
    // For exemple if all structures are empty or infinite
    if (XMax < XMin) { Xm = XMin; XMin = XMax; XMax = Xm; }
    if (YMax < YMin) { Ym = YMin; YMin = YMax; YMax = Ym; }
    if (ZMax < ZMin) { Zm = ZMin; ZMin = ZMax; ZMax = Zm; }
  }
  Standard_Real Sx, Sy, Sz;
  MyViewOrientation.AxialScale(Sx, Sy, Sz);
  XMin = (Sx > 1. && XMin < RealFirst ()/Sx)?RealFirst (): XMin*Sx;
  XMax = (Sx > 1. && XMax > RealLast  ()/Sx)?RealLast  (): XMax*Sx;
  YMin = (Sy > 1. && YMin < RealFirst ()/Sy)?RealFirst (): YMin*Sy;
  YMax = (Sy > 1. && YMax > RealLast  ()/Sy)?RealLast  (): YMax*Sy;
  ZMin = (Sz > 1. && ZMin < RealFirst ()/Sz)?RealFirst (): ZMin*Sz;
  ZMax = (Sz > 1. && ZMax > RealLast  ()/Sz)?RealLast  (): ZMax*Sz;
}

void Visual3d_View::MinMaxValues (Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {

        MinMaxValues (MyDisplayedStructure, XMin, YMin, XMax, YMax);

}

void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& ASet, Standard_Real& XMin, Standard_Real& YMin, Standard_Real& XMax, Standard_Real& YMax) {

Standard_Real Xm, Ym, Zm, XM, YM, ZM;
Standard_Real Xp, Yp, Zp;

        MinMaxValues (ASet, Xm, Ym, Zm, XM, YM, ZM);

        Projects (Xm, Ym, Zm, Xp, Yp, Zp);
        XMin    = Xp;
        YMin    = Yp;

        Projects (XM, YM, ZM, Xp, Yp, Zp);
        XMax    = Xp;
        YMax    = Yp;

        if (XMax < XMin) { Xp = XMax; XMax = XMin; XMin = Xp; }
        if (YMax < YMin) { Yp = YMax; YMax = YMin; YMin = Yp; }
}

const TColStd_Array2OfReal& Visual3d_View::MatrixOfOrientation () {

        if (! MyMatOfOriIsEvaluated) {
                MyGraphicDriver->InquireMat
                    (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
                MyMatOfMapIsEvaluated   = Standard_True;
                MyMatOfOriIsEvaluated   = Standard_True;
        }

        return (MyMatrixOfOrientation);

}

const TColStd_Array2OfReal& Visual3d_View::MatrixOfMapping () {

        if (! MyMatOfMapIsEvaluated) {
                MyGraphicDriver->InquireMat
                    (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
                MyMatOfMapIsEvaluated   = Standard_True;
                MyMatOfOriIsEvaluated   = Standard_True;
        }

        return (MyMatrixOfMapping);

}

Standard_Integer Visual3d_View::NumberOfDisplayedStructures () const {

Standard_Integer Result = MyDisplayedStructure.Extent ();

        return (Result);

}

#ifdef OLD_METHOD
void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) const {

math_Vector PtDC (0,3), PtWC (0,3);

// RLE method:
// Otherwise use new on Visual3d_View (constructor+destructor)
// as Projects is a const method or MatrixOfOrientation and
// MatrixOfMapping is not.
Visual3d_View * const newthis = (Visual3d_View * const) this;
        newthis->MatrixOfOrientation ();
        newthis->MatrixOfMapping ();

// World Coordinate Space
        PtWC (0) = AX;
        PtWC (1) = AY;
        PtWC (2) = AZ;
        PtWC (3) = 1.0;

        // WCS -> View Reference Coordinate Space
        math_Vector PtVRC(0,3);
        PtVRC = MyMatrixOfOrientation.Multiplied (PtWC);

        // VRCS -> Normalized Projection Coordinate Space
        math_Vector PtNPC(0,3);
        PtNPC = MyMatrixOfMapping.Multiplied (PtVRC);
        for (Standard_Integer i=0; i<3; i++) PtNPC (i) = PtNPC (i) / PtNPC (3);

#ifdef DEBUG
        printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
                        PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
#endif // DEBUG

        Standard_Real Ratio;
#ifdef DEBUG
        // NPCS -> Device Coordinate Space
        Standard_Real Dx        = Standard_Real (MyCView.DefWindow.dx);
        Standard_Real Dy        = Standard_Real (MyCView.DefWindow.dy);

        Ratio           = Dx / Dy;
        PtDC (0)        = PtNPC (0) * Dx;
        PtDC (1)        = Dy - PtNPC (1) * Dy * Ratio;

        printf("Display coordinates : %f,%f,%f,%f\n",
                        PtDC(0),PtDC(1),PtDC(2),PtDC(3));
#endif // DEBUG

        // NPCS -> Window Space
Standard_Real um, vm, uM, vM;
        MyViewMapping.WindowLimit (um, vm, uM, vM);

        Ratio   = (uM - um) / (vM - vm);
        if (Ratio >= 1.0)
            PtNPC (1)   = PtNPC (1) * Ratio;
        else
            PtNPC (0)   = PtNPC (0) / Ratio;

#ifdef DEBUG
        printf("Display coordinates PtNPC: %f,%f,%f,%f\n",
                        PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
#endif // DEBUG

        Standard_Real fpd       = MyViewMapping.FrontPlaneDistance ();
        Standard_Real bpd       = MyViewMapping.BackPlaneDistance ();

        /*
         * Coordinates of PtNPC are described in the space
         * [0-1]x[0-1]x[0-1].
         * It is necessary to transform x and y in the window space.
         * It is necessary to transform z in the space of back and front
         * plane, taking into account clipping planes.
         * Z clipping planes are defined between 0 and 1.
        */

        APX     = PtNPC (0) * (uM - um) + um;
        APY     = PtNPC (1) * (vM - vm) + vm;
        APZ     = PtNPC (2) * (fpd - bpd) + bpd;

#ifdef DEBUG
        Standard_Integer l,c;
        printf("OrientationMatrix :");
        for( l=0 ; l<4 ; l++ ) {
          printf("\n    %d->",l);
          for( c=0 ; c<4 ; c++ ) {
            printf(" %f ,",MyMatrixOfOrientation(c,l));
          }
        }
        printf("\n\n");
        printf("MappingMatrix :");
        for( l=0 ; l<4 ; l++ ) {
          printf("\n    %d->",l);
          for( c=0 ; c<4 ; c++ ) {
            printf(" %f ,",MyMatrixOfMapping(c,l));
          }
        }
        printf("\n\n");
        printf("World coordinates : %f,%f,%f,%f\n",
                        PtWC(0),PtWC(1),PtWC(2),PtWC(3));
        printf("View coordinates : %f,%f,%f,%f\n",
                        PtVRC(0),PtVRC(1),PtVRC(2),PtVRC(3));
        printf("Display coordinates : %f,%f,%f,%f\n",
                        PtNPC(0),PtNPC(1),PtNPC(2),PtNPC(3));
        printf("Window limit : %f,%f,%f,%f\n",um,vm,uM,vM);
        printf("Ratio : %f\n",Ratio);
        printf("Front-plane : %f back-plane : %f\n",fpd,bpd);
        printf("Projection : %f,%f,%f\n \n",APX,APY,APZ);
#endif

}
#endif /* OLD_METHOD */

// OCC18942: This method is likely to duplicate Visual3d_ViewManager::ConvertCoord() one,
// therefore it is necessary to consider merging the two methods or making them call the same
// graphic driver's method after OCCT 6.3.
void Visual3d_View::Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) {

Standard_Real PtX, PtY, PtZ, PtT;
Standard_Real APT;
static Standard_Real Ratio, um, vm, uM, vM;
static Standard_Real fpd, bpd;

        if (! MyMatOfOriIsEvaluated || ! MyMatOfMapIsEvaluated) {
                MyGraphicDriver->InquireMat
                    (MyCView, MyMatrixOfOrientation, MyMatrixOfMapping);
                MyMatOfOriIsEvaluated = MyMatOfMapIsEvaluated = Standard_True;
        }

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

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

        APX /= APT;
        APY /= APT;
        APZ /= APT;

        // NPCS -> Window Space
        MyViewMapping.WindowLimit (um, vm, uM, vM);
        fpd     = MyViewMapping.FrontPlaneDistance ();
        bpd     = MyViewMapping.BackPlaneDistance ();

        if(MyCView.Mapping.IsCustomMatrix) {
        	// OCC18942: SAN - If orientation and mapping matrices are those used by OpenGL
        	// visualization, then X, Y and Z coordinates normally vary between -1 and 1
        	APX     = ( APX + 1 ) * 0.5 * (uM - um) + um;
        	APY     = ( APY + 1 ) * 0.5 * (vM - vm) + vm;
        } else {
        	Ratio   = (uM - um) / (vM - vm);
        	if (Ratio >= 1.0)
        		APY *= Ratio;
        	else
        		APX /= Ratio;

        	/*
         * Coordinates of APX, APY, APZ are described in the space
         * [0-1]x[0-1]x[0-1].
         * It is necessary to transform x and y in the window space.
         * It is necessary to transform z in the space of back and front
         * plane, taking into account clipping planes.
         * Z clipping planes are defined between 0 and 1.
         	*/
            APX     = APX * (uM - um) + um;
            APY     = APY * (vM - vm) + vm;
        }
        APZ     = APZ * (fpd - bpd) + bpd;
}

Standard_Integer Visual3d_View::Identification () const {

        return (Standard_Integer (MyCView.ViewId));

}

void Visual3d_View::Exploration () const {

        if (IsDeleted ()) return;

        MyGraphicDriver->DumpView (MyCView);

}

Standard_Boolean Visual3d_View::ZBufferIsActivated () const {

        if (IsDeleted ()) return (Standard_False);

        if ((! IsDefined ()) || (! IsActive ())) return (Standard_False);

// -1 => not forced by the programmer => depends on the type of visualisation
//  0 ou 1 => forced by the programmer

        if (MyCView.Context.ZBufferActivity == -1)
                if (MyContext.Visualization () == Visual3d_TOV_SHADING)
                        return (Standard_True);
                else
                        return (Standard_False);
        else
                if (MyCView.Context.ZBufferActivity)
                        return (Standard_True);
                else
                        return (Standard_False);

}

void Visual3d_View::SetTransparency (const Standard_Boolean AnActivity) {

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        MyGraphicDriver->Transparency (MyCView, AnActivity);

}

void Visual3d_View::SetZBufferActivity (const Standard_Integer AnActivity) {

        if (MyCView.Context.ZBufferActivity == AnActivity) return;

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        MyCView.Context.ZBufferActivity = AnActivity;
        MyGraphicDriver->SetVisualisation (MyCView);

}

void Visual3d_View::UpdateView () {

        MyCView.Context.Aliasing        = (MyContext.AliasingIsOn () ? 1:0);
        MyCView.Context.BackZClipping   =
                (MyContext.BackZClippingIsOn () ? 1:0);
        MyCView.Context.FrontZClipping  =
                (MyContext.FrontZClippingIsOn() ? 1:0);
        MyCView.Context.DepthCueing     =
                (MyContext.DepthCueingIsOn () ? 1:0);

        MyCView.Context.ZClipFrontPlane =
                                float (MyContext.ZClippingFrontPlane ());
        MyCView.Context.ZClipBackPlane          =
                                float (MyContext.ZClippingBackPlane ());
        MyCView.Context.DepthFrontPlane =
                                float (MyContext.DepthCueingFrontPlane ());
        MyCView.Context.DepthBackPlane          =
                                float (MyContext.DepthCueingBackPlane ());

        MyCView.Context.Model           = int (MyContext.Model ());
        MyCView.Context.Visualization   = int (MyContext.Visualization ());

        Handle(Graphic3d_TextureEnv)   TempTextureEnv = MyContext.TextureEnv();
        if (! TempTextureEnv.IsNull()) MyCView.Context.TexEnvId = TempTextureEnv->TextureId();
        else                           MyCView.Context.TexEnvId = -1;
        MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();

}

void Visual3d_View::Compute () {

Standard_Integer i;
Standard_Integer Length = MyCOMPUTEDSequence.Length ();
        for (i=1; i<=Length; i++)
            (MyCOMPUTEDSequence.Value (i))->SetHLRValidation (Standard_False);

        // if the degenerated node is active, nothing is recomputed
#ifdef G003
        if (  DegenerateModeIsOn () || !ComputedMode ()  ) return;
#else
        if (DegenerateModeIsOn ()) return;
#endif  // G003

        /*
         * Force HLRValidation to False on all structures
         * calculated in the view.
         */
#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
                cout << "In Visual3d_View::Compute, ";
                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
        }
#endif

        /*
         * Change of orientation or of projection type =>
         * Remove structures that were calculated for the
         * previous orientation.
         * Recalculation of new structures.
         * Passage of the degenerated mode ON to OFF =>
         * Remove structures that were calculated before 
         * the degenerated mode passed to ON.
         * Recalculate new structures.
         */
Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
Visual3d_TypeOfAnswer Answer;

        i       = MyDisplayedStructure.Extent ();

Graphic3d_SequenceOfStructure FooSequence;

        while (S1Iterator.More ()) {
                Answer  = AcceptDisplay (S1Iterator.Key ());
                // If the structure was calculated, it is recalculated.
                if (Answer == Visual3d_TOA_COMPUTE) {
#ifdef TRACE
                        cout << "AcceptDisplay ("
                             << (S1Iterator.Key ())->Identification ()
                             << ") == Visual3d_TOA_COMPUTE;\n";
                        cout << flush;
#endif
                        //Display (S1Iterator.Key (), Aspect_TOU_WAIT);
                        FooSequence.Append (S1Iterator.Key ());
                }

                // S1Iterator.Next () is located on the next structure
                S1Iterator.Next ();
        }

        Length  = FooSequence.Length ();
        // All stored structures are displayed
        for (i=1; i<=Length; i++)
                Display (FooSequence.Value (i), Aspect_TOU_WAIT);
        if (Length != 0) FooSequence.Clear ();

}

void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& AStructure) {
#ifdef G003
        if ( DegenerateModeIsOn () || !ComputedMode () ) return;
#else
        if (DegenerateModeIsOn()) return;
#endif  // G003

        if (IsDeleted ()) return;

        if ((! IsDefined ()) || (! IsActive ())) return;

        if (! MyWindow->IsMapped ()) return;

        if (! AStructure->IsDisplayed ()) return;

Visual3d_TypeOfAnswer Answer;

        Answer  = AcceptDisplay (AStructure);

        if (Answer == Visual3d_TOA_COMPUTE) {
Standard_Integer Index = IsComputed (AStructure);
                if (Index == 0) {
#ifdef TRACE_COMP
        cout << "Structure " << AStructure->Identification ()
             << " is not calculated in the view "
             << Identification () << "\n";
        cout << flush;
#endif
                }
                else {
#ifdef TRACE_COMP
		  Standard_Integer OldStructId;
                        OldStructId =
                        MyCOMPUTEDSequence.Value (Index)->Identification ();
	Standard_Integer StructId = AStructure->Identification ();
        cout << "Structure " << StructId
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << OldStructId << " is recalculated.\n";
        cout << flush;
#endif

        // Compute + Validation
#ifdef OLD
Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
#else
Handle(Graphic3d_Structure) TheStructure;
TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
        AStructure->Transform (ATrsf);
        if (Index != 0) {
TColStd_Array2OfReal Ident (0, 3, 0, 3);
Standard_Integer ii, jj;
        for (ii=0; ii<=3; ii++)
            for (jj=0; jj<=3; jj++)
                Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
            TheStructure = MyCOMPUTEDSequence.Value (Index);
            TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
            if (AStructure->IsTransformed ()) {
                AStructure->Compute (this, ATrsf, TheStructure);
            }
            else {
                AStructure->Compute (this, TheStructure);
            }
        }
        else {
            if (AStructure->IsTransformed ()) {
                TheStructure = AStructure->Compute (this, ATrsf);
            }
            else {
                TheStructure = AStructure->Compute (this);
            }
        }
#endif
        TheStructure->SetHLRValidation (Standard_True);

// Return type of visualisation of the view
Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();

// Of which type will be the computed ?
Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
        (AStructure->ComputeVisual () != Graphic3d_TOS_SHADING));

Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
        (AStructure->ComputeVisual () != Graphic3d_TOS_WIREFRAME));

                        if (ComputeWireframe)
                            TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
                        if (ComputeShading)
                            TheStructure->SetVisual (Graphic3d_TOS_SHADING);

                        if (AStructure->IsHighlighted ()) {
                            TheStructure->SetHighlightColor
                                (AStructure->HighlightColor ());
                            TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
                        }

                        // Ot is ranged
                        // Find structure <AStructure>
                        // in the sequence of structures to be calculated.

                        // The previous calculation is removed and the new one is dislayed
                        MyGraphicDriver->EraseStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
                        MyGraphicDriver->DisplayStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)TheStructure->CStructure (),
                                int (AStructure->DisplayPriority ())
                        );

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
                cout << "In Visual3d_View::ReCompute, ";
                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
        }
#endif

                          // hlhsr and the new associated compute are added
                          MyTOCOMPUTESequence.Append (AStructure);
                          MyCOMPUTEDSequence.Append (TheStructure);

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif

                          // hlhsr and the new associated compute are removed 

                          MyTOCOMPUTESequence.Remove (Index);
                          MyCOMPUTEDSequence.Remove (Index);

#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif
                }
        }

}

void
#ifdef G003
Visual3d_View::SetAnimationModeOn ( const Standard_Boolean degenerate ) {
#else
Visual3d_View::SetAnimationModeOn () {
#endif

        if (AnimationModeIsOn ()) return;

        AnimationModeIsActive   = Standard_True;
#ifdef G003
        if ( degenerate )
          SetDegenerateModeOn ();
        else
          SetDegenerateModeOff ();
#endif  // G003
        MyGraphicDriver->BeginAnimation (MyCView);

}

void Visual3d_View::SetAnimationModeOff () {

        if (! AnimationModeIsOn ()) return;

        AnimationModeIsActive   = Standard_False;
#ifdef G003
        SetDegenerateModeOff ();
#endif  // G003
        MyGraphicDriver->EndAnimation (MyCView);

}

Standard_Boolean Visual3d_View::AnimationModeIsOn () const {

        return AnimationModeIsActive;

}

void Visual3d_View::SetDegenerateModeOn () {

#ifdef TRACE
        cout << "Visual3d_View" << MyCView.ViewId
             << "::SetDegenerateModeOn ();\n";
        cout << flush;
#endif

        // If the degenerated mode is already active, nothing is recalculated
        if (DegenerateModeIsOn ()) return;
        DegenerateModeIsActive = Standard_True;

#ifdef G003
        MyCView.IsDegenerates  = 1;
#else
        /*
         * Change of activity of the degenerated mode
         * Remove structures that were calculated
         * and displayed when the mode was off.
         * Display of non-calculated structures.
         */
Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
Visual3d_TypeOfAnswer Answer;
Standard_Integer StructId;

        while (S1Iterator.More ()) {

                Answer  = AcceptDisplay (S1Iterator.Key ());
                // If the structure was calculated, the previous one is 
                // removed and the new one is displayed
                // (This is the role of passage into degenerated mode)

                if (Answer == Visual3d_TOA_COMPUTE) {
Standard_Integer Index = IsComputed (S1Iterator.Key ());
                    if (Index != 0) {
                        StructId =
                        MyCOMPUTEDSequence.Value (Index)->Identification ();
#ifdef TRACE_COMP
        cout << "Structure " << S1Iterator.Key ()->Identification ()
             << " calculated, in the view "
             << Identification () << ", by structure "
             << StructId << " passes in degenerated mode.\n";
        cout << "Remove" << StructId << " then display "
             << S1Iterator.Key ()->Identification () << "\n";
        cout << flush;
#endif
                        MyGraphicDriver->EraseStructure
                                (MyCView, *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure ());
                        MyGraphicDriver->DisplayStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure (),
                                int (S1Iterator.Key ()->DisplayPriority ())
                        );
                    }
                    else {
                        // Else is impossible)
                        // If the mode was not degenerated previously, the
                        // calculated structure associated to S1Iterator.Key ()
                        // really exists and Index != 0
                    }
                }

                // S1Iterator.Next () is located on the next structure
                S1Iterator.Next ();
        }
#endif  //G003
}

void Visual3d_View::SetDegenerateModeOff () {

#ifdef TRACE
        cout << "Visual3d_View" << MyCView.ViewId
             << "::SetDegenerateModeOff ();\n";
        cout << flush;
#endif

        // If the degenerated mode is already inactive, nothing is recalculated
        if (! DegenerateModeIsOn ()) return;

        DegenerateModeIsActive  = Standard_False;

#ifdef G003
        MyCView.IsDegenerates  = 0;
#else
        /*
         * Change of activity of degenerated mode
         * Remove structures that were displayed
         * when the mode was on.
         * Calculation of structures.
         */
Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);
Visual3d_TypeOfAnswer Answer;
Standard_Integer StructId;

        Standard_Integer i      = MyDisplayedStructure.Extent ();

        while (S1Iterator.More ()) {

                Answer  = AcceptDisplay (S1Iterator.Key ());
                // If the structure was calculated, the previous one is 
                // removed and the new one is displayed
                // (This is the role of passage into degenerated mode)
           
                if (Answer == Visual3d_TOA_COMPUTE) {
Standard_Integer Index = IsComputed (S1Iterator.Key ());
                    if (Index != 0) {
                        StructId =
                        MyCOMPUTEDSequence.Value (Index)->Identification ();
#ifdef TRACE_COMP
        cout << "Structure " << S1Iterator.Key ()->Identification ()
             << " calculated, in the view "
             << Identification () << ", by the structure "
             << StructId << " passes into normal mode.\n";
        cout << "Remove " << S1Iterator.Key ()->Identification ()
             << " then display " << StructId << "\n";
        cout << flush;
#endif
                        MyGraphicDriver->EraseStructure
                                (MyCView,
                                *(Graphic3d_CStructure *)S1Iterator.Key ()->CStructure ());
                        MyGraphicDriver->DisplayStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)MyCOMPUTEDSequence.Value (Index)->CStructure (),
                                int (S1Iterator.Key ()->DisplayPriority ())
                        );

                        Display (S1Iterator.Key (), Aspect_TOU_WAIT);

                        if ((S1Iterator.Key ())->IsHighlighted()) {
                           if (! (MyCOMPUTEDSequence.Value (Index))->IsHighlighted()) {
                                (MyCOMPUTEDSequence.Value (Index))->SetHighlightColor
                                        ((S1Iterator.Key ())->HighlightColor ());
                                (MyCOMPUTEDSequence.Value (Index))->GraphicHighlight (Aspect_TOHM_COLOR);
                            }
                        }
                    }
                    else {
                        // Else is impossible 
                        // Degenerated mode was activated before display of the
                        // structure. So the structure was displayed in the
                        // degenerated mode, but the calculated structure didn't exist.
                        // It is calculated.

        // Compute + Validation
Handle(Graphic3d_Structure) AStructure = (S1Iterator.Key ());
#ifdef OLD
Handle(Graphic3d_Structure) TheStructure = AStructure->Compute (this);
#else
Handle(Graphic3d_Structure) TheStructure;
TColStd_Array2OfReal ATrsf (0, 3, 0, 3);
        AStructure->Transform (ATrsf);
        if (Index != 0) {
TColStd_Array2OfReal Ident (0, 3, 0, 3);
Standard_Integer ii, jj;
        for (ii=0; ii<=3; ii++)
            for (jj=0; jj<=3; jj++)
                Ident (ii, jj) = (ii == jj ? 1.0 : 0.0);
            TheStructure = MyCOMPUTEDSequence.Value (Index);
            TheStructure->SetTransform (Ident, Graphic3d_TOC_REPLACE);
            if (AStructure->IsTransformed ()) {
                AStructure->Compute (this, ATrsf, TheStructure);
            }
            else {
                AStructure->Compute (this, TheStructure);
            }
        }
        else {
            if (AStructure->IsTransformed ()) {
                TheStructure = AStructure->Compute (this, ATrsf);
            }
            else {
                TheStructure = AStructure->Compute (this);
            }
        }
#endif
        TheStructure->SetHLRValidation (Standard_True);

// Return type of visualisation of the view
Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();

// Of which type will be the computed ?
Standard_Boolean ComputeWireframe = ((ViewType == Visual3d_TOV_WIREFRAME) &&
        ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_SHADING));

Standard_Boolean ComputeShading = ((ViewType == Visual3d_TOV_SHADING) &&
        ((S1Iterator.Key ())->ComputeVisual () != Graphic3d_TOS_WIREFRAME));

                        if (ComputeWireframe)
                            TheStructure->SetVisual (Graphic3d_TOS_WIREFRAME);
                        if (ComputeShading)
                            TheStructure->SetVisual (Graphic3d_TOS_SHADING);

                        if ((S1Iterator.Key ())->IsHighlighted()) {
                            TheStructure->SetHighlightColor
                                ((S1Iterator.Key ())->HighlightColor ());
                            TheStructure->GraphicHighlight (Aspect_TOHM_COLOR);
                        }

                        // Make range
Standard_Integer Result = 0;
Standard_Integer Length = MyTOCOMPUTESequence.Length ();
                        // Find structure <S1Iterator.Key ()>
                        // in the sequence of structures to be calculated
                        StructId = (S1Iterator.Key ())->Identification ();
                        for (i=1; i<=Length && Result==0; i++)
                          if ((MyTOCOMPUTESequence.Value (i))->Identification () ==
                            StructId) Result    = i;
                        if (Result != 0)
                          MyCOMPUTEDSequence.ChangeValue (Result) = TheStructure;
                        else {
                          // hlhsr and the associated new compute are added
#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ()) {
                cout << "In Visual3d_View::SetDegenerateModeOff, ";
                cout << "TOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
        }
#endif
                          MyTOCOMPUTESequence.Append (S1Iterator.Key ());
                          MyCOMPUTEDSequence.Append (TheStructure);
#ifdef TRACE_LENGTH
        if (MyTOCOMPUTESequence.Length () != MyCOMPUTEDSequence.Length ())
                cout << "\tTOCOMPUTE " << MyTOCOMPUTESequence.Length ()
                     << " != COMPUTED " << MyCOMPUTEDSequence.Length ()
                     << "\n" << flush;
#endif
                        }

                        // The degenerated is removed and the calculated is displayed
                        MyGraphicDriver->EraseStructure
                                (MyCView,
                                *(Graphic3d_CStructure *)(S1Iterator.Key ()->CStructure ()));
                        MyGraphicDriver->DisplayStructure (
                                MyCView,
                                *(Graphic3d_CStructure *)TheStructure->CStructure (),
                                int (S1Iterator.Key ()->DisplayPriority ())
                        );
                    }
                }

                // S1Iterator.Next () is located on the next structure
                S1Iterator.Next ();
        }

        if (MyViewManager->UpdateMode () == Aspect_TOU_ASAP) Update ();
#endif  //G003
}

Standard_Boolean Visual3d_View::DegenerateModeIsOn () const {

        return DegenerateModeIsActive;

}

Handle(Aspect_GraphicDriver) Visual3d_View::GraphicDriver () const {

        return MyGraphicDriver;

}

void Visual3d_View::Plot (const Handle(Graphic3d_Plotter)& APlotter) const {

Graphic3d_MapIteratorOfMapOfStructure S1Iterator (MyDisplayedStructure);

        while (S1Iterator.More ()) {

                if (DegenerateModeIsOn ())
                        // As the  mode is degenerated the displayed structure
                        // is plotted without taking into account if it is calculated or not
                        (S1Iterator.Key ())->Plot (APlotter);
                else {
Standard_Integer Index = IsComputed (S1Iterator.Key ());
                        // As the  mode is not degenerated the displayed structure
                        // is plotted as if it was not calculated, otherwise the 
                        // associated calculated structure is plotted.
                        if (Index == 0)
                            (S1Iterator.Key ())->Plot (APlotter);
                        else
                            (MyCOMPUTEDSequence.Value (Index))->Plot (APlotter);
                }

                // S1Iterator.Next () is located on the next structure
                S1Iterator.Next ();
        }

}

Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const {

Standard_Integer Result = 0;
Standard_Integer Length = MyTOCOMPUTESequence.Length ();

        // Find in the sequence of already calculated structures 
        // 1/ Structure with the same Owner as <AStructure>
        // 2/ Which is not <AStructure>
        // 3/ COMPUTED which of is valid
        for (Standard_Integer i=1; i<=Length && Result==0; i++)
           if ((MyTOCOMPUTESequence.Value (i)->Owner () == AStructure->Owner ())
            && (MyTOCOMPUTESequence.Value (i)->Identification () !=
                                                AStructure->Identification ())
            && (MyCOMPUTEDSequence.Value (i)->HLRValidation ())) Result   = i;

        return (Result);

}

Standard_Address Visual3d_View::CView () const {

        return Standard_Address (&MyCView);

}


// Triedron methods : the Triedron is a non-zoomable object.

void Visual3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor,
                                    const Quantity_NameOfColor YColor,
                                    const Quantity_NameOfColor ZColor,
                                    const Standard_Real        SizeRatio,
                                    const Standard_Real        AxisDiametr,
                                    const Standard_Integer     NbFacettes) {
  MyGraphicDriver->ZBufferTriedronSetup(XColor, YColor, ZColor,
                                        SizeRatio, AxisDiametr, NbFacettes);
}



void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition,
 const Quantity_NameOfColor AColor, const Standard_Real AScale, const Standard_Boolean AsWireframe ) {

        MyGraphicDriver->TriedronDisplay (MyCView,APosition, AColor, AScale, AsWireframe);

}

void Visual3d_View::TriedronErase () {

        MyGraphicDriver->TriedronErase (MyCView);


}

void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) {

        MyGraphicDriver->TriedronEcho (MyCView,AType);

}

Standard_Boolean checkFloat(const Standard_Real value)
{
    return value > -FLT_MAX && value < FLT_MAX;
}

void SetMinMaxValuesCallback(void* Visual3dView)
{
    Standard_Real xmin, ymin, zmin, xmax, ymax, zmax;

    Handle(Visual3d_View) view = (Handle(Visual3d_View)&) Visual3dView;
    view->MinMaxValues(xmin, ymin, zmin, xmax, ymax, zmax);

    if (checkFloat(xmin) && checkFloat(ymin) && checkFloat(zmin) &&
        checkFloat(xmax) && checkFloat(ymax) && checkFloat(zmax))
    {
        Handle(Graphic3d_GraphicDriver) driver = Handle(Graphic3d_GraphicDriver)::DownCast(view->GraphicDriver());
        driver->GraduatedTrihedronMinMaxValues((Standard_ShortReal)xmin, (Standard_ShortReal)ymin, (Standard_ShortReal)zmin,
                                               (Standard_ShortReal)xmax, (Standard_ShortReal)ymax, (Standard_ShortReal)zmax);
    }
}

Standard_Boolean Visual3d_View::GetGraduatedTrihedron
    (/* Names of axes */
     TCollection_ExtendedString& xname,
     TCollection_ExtendedString& yname,
     TCollection_ExtendedString& zname,
     /* Draw names */
     Standard_Boolean& xdrawname,
     Standard_Boolean& ydrawname,
     Standard_Boolean& zdrawname,
     /* Draw values */
     Standard_Boolean& xdrawvalues,
     Standard_Boolean& ydrawvalues,
     Standard_Boolean& zdrawvalues,
     /* Draw grid */
     Standard_Boolean& drawgrid,
     /* Draw axes */
     Standard_Boolean& drawaxes,
     /* Number of splits along axes */
     Standard_Integer& nbx,
     Standard_Integer& nby,
     Standard_Integer& nbz,
     /* Offset for drawing values */
     Standard_Integer& xoffset,
     Standard_Integer& yoffset,
     Standard_Integer& zoffset,
     /* Offset for drawing names of axes */
     Standard_Integer& xaxisoffset,
     Standard_Integer& yaxisoffset,
     Standard_Integer& zaxisoffset,
     /* Draw tickmarks */
     Standard_Boolean& xdrawtickmarks,
     Standard_Boolean& ydrawtickmarks,
     Standard_Boolean& zdrawtickmarks,
     /* Length of tickmarks */
     Standard_Integer& xtickmarklength,
     Standard_Integer& ytickmarklength,
     Standard_Integer& ztickmarklength,
     /* Grid color */
     Quantity_Color& gridcolor,
     /* Colors of axis names */
     Quantity_Color& xnamecolor,
     Quantity_Color& ynamecolor,
     Quantity_Color& znamecolor,
     /* Colors of axis and values */
     Quantity_Color& xcolor,
     Quantity_Color& ycolor,
     Quantity_Color& zcolor,
     /* Name of font for names of axes */
     TCollection_AsciiString& fontOfNames,
     /* Style of names of axes */
     OSD_FontAspect& styleOfNames,
     /* Size of names of axes */
     Standard_Integer& sizeOfNames,
     /* Name of font for values */
     TCollection_AsciiString& fontOfValues,
     /* Style of values */
     OSD_FontAspect& styleOfValues,
     /* Size of values */
     Standard_Integer& sizeOfValues) const
{
    if (!MyGTrihedron.ptrVisual3dView)
        return Standard_False;

    /* Names of axes */
    xname = MyGTrihedron.xname;
    yname = MyGTrihedron.yname; 
    zname = MyGTrihedron.zname;
    /* Draw names */
    xdrawname = MyGTrihedron.xdrawname; 
    ydrawname = MyGTrihedron.ydrawname; 
    zdrawname = MyGTrihedron.zdrawname;
    /* Draw values */
    xdrawvalues = MyGTrihedron.xdrawvalues; 
    ydrawvalues = MyGTrihedron.ydrawvalues; 
    zdrawvalues = MyGTrihedron.zdrawvalues;
    /* Draw grid */
    drawgrid = MyGTrihedron.drawgrid;
    /* Draw axes */
    drawaxes = MyGTrihedron.drawaxes;
    /* Number of splits along axes */
    nbx = MyGTrihedron.nbx;
    nby = MyGTrihedron.nby;
    nbz = MyGTrihedron.nbz;
    /* Offset for drawing values */
    xoffset = MyGTrihedron.xoffset;
    yoffset = MyGTrihedron.yoffset;
    zoffset = MyGTrihedron.zoffset;
    /* Offset for drawing names of axes */
    xaxisoffset = MyGTrihedron.xaxisoffset;
    yaxisoffset = MyGTrihedron.yaxisoffset;
    zaxisoffset = MyGTrihedron.zaxisoffset;
    /* Draw tickmarks */
    xdrawtickmarks = MyGTrihedron.xdrawtickmarks;
    ydrawtickmarks = MyGTrihedron.ydrawtickmarks;
    zdrawtickmarks = MyGTrihedron.zdrawtickmarks;
    /* Length of tickmarks */
    xtickmarklength = MyGTrihedron.xtickmarklength;
    ytickmarklength = MyGTrihedron.ytickmarklength;
    ztickmarklength = MyGTrihedron.ztickmarklength;
    /* Grid color */
    gridcolor = MyGTrihedron.gridcolor;
    /* Colors of axis names */
    xnamecolor = MyGTrihedron.xnamecolor;
    ynamecolor = MyGTrihedron.ynamecolor;
    znamecolor = MyGTrihedron.znamecolor;
    /* Colors of axis and values */
    xcolor = MyGTrihedron.xcolor;
    ycolor = MyGTrihedron.ycolor;
    zcolor = MyGTrihedron.zcolor;
    /* Name of font for names of axes */
    fontOfNames = MyGTrihedron.fontOfNames;
    /* Style of names of axes */
    styleOfNames = MyGTrihedron.styleOfNames;
    /* Size of names of axes */
    sizeOfNames = MyGTrihedron.sizeOfNames;
    /* Name of font for values */
    fontOfValues = MyGTrihedron.fontOfValues;
    /* Style of values */
    styleOfValues = MyGTrihedron.styleOfValues;
    /* Size of values */
    sizeOfValues = MyGTrihedron.sizeOfValues;

    return Standard_True;
}

void Visual3d_View::GraduatedTrihedronDisplay
    (/* Names of axes */
     const TCollection_ExtendedString &xname,
     const TCollection_ExtendedString &yname,
     const TCollection_ExtendedString &zname,
     /* Draw names */
     const Standard_Boolean xdrawname,
     const Standard_Boolean ydrawname,
     const Standard_Boolean zdrawname,
     /* Draw values */
     const Standard_Boolean xdrawvalues,
     const Standard_Boolean ydrawvalues,
     const Standard_Boolean zdrawvalues,
     /* Draw grid */
     const Standard_Boolean drawgrid,
     /* Draw axes */
     const Standard_Boolean drawaxes,
     /* Number of splits along axes */
     const Standard_Integer nbx,
     const Standard_Integer nby,
     const Standard_Integer nbz,
     /* Offset for drawing values */
     const Standard_Integer xoffset,
     const Standard_Integer yoffset,
     const Standard_Integer zoffset,
     /* Offset for drawing names of axes */
     const Standard_Integer xaxisoffset,
     const Standard_Integer yaxisoffset,
     const Standard_Integer zaxisoffset,
     /* Draw tickmarks */
     const Standard_Boolean xdrawtickmarks,
     const Standard_Boolean ydrawtickmarks,
     const Standard_Boolean zdrawtickmarks,
     /* Length of tickmarks */
     const Standard_Integer xtickmarklength,
     const Standard_Integer ytickmarklength,
     const Standard_Integer ztickmarklength,
     /* Grid color */
     const Quantity_Color& gridcolor,
     /* Colors of axis names */
     const Quantity_Color& xnamecolor,
     const Quantity_Color& ynamecolor,
     const Quantity_Color& znamecolor,
     /* Colors of axis and values */
     const Quantity_Color& xcolor,
     const Quantity_Color& ycolor,
     const Quantity_Color& zcolor,
     /* Name of font for names of axes */
     const TCollection_AsciiString &fontOfNames,
     /* Style of names of axes */
     const OSD_FontAspect styleOfNames,
     /* Size of names of axes */
     const Standard_Integer sizeOfNames,
     /* Name of font for values */
     const TCollection_AsciiString &fontOfValues,
     /* Style of values */
     const OSD_FontAspect styleOfValues,
     /* Size of values */
     const Standard_Integer sizeOfValues)
{
    /* Names of axes */
    MyGTrihedron.xname = xname;
    MyGTrihedron.yname = yname;
    MyGTrihedron.zname = zname;
    /* Draw names */
    MyGTrihedron.xdrawname = xdrawname;
    MyGTrihedron.ydrawname = ydrawname;
    MyGTrihedron.zdrawname = zdrawname;
    /* Draw values */
    MyGTrihedron.xdrawvalues = xdrawvalues;
    MyGTrihedron.ydrawvalues = ydrawvalues;
    MyGTrihedron.zdrawvalues = zdrawvalues;
    /* Draw grid */
    MyGTrihedron.drawgrid = drawgrid;
    /* Draw axes */
    MyGTrihedron.drawaxes = drawaxes;
    /* Number of splits along axes */
    MyGTrihedron.nbx = nbx;
    MyGTrihedron.nby = nby;
    MyGTrihedron.nbz = nbz;
    /* Offset for drawing values */
    MyGTrihedron.xoffset = xoffset;
    MyGTrihedron.yoffset = yoffset;
    MyGTrihedron.zoffset = zoffset;
    /* Offset for drawing names of axes */
    MyGTrihedron.xaxisoffset = xaxisoffset;
    MyGTrihedron.yaxisoffset = yaxisoffset;
    MyGTrihedron.zaxisoffset = zaxisoffset;
    /* Draw tickmarks */
    MyGTrihedron.xdrawtickmarks = xdrawtickmarks;
    MyGTrihedron.ydrawtickmarks = ydrawtickmarks;
    MyGTrihedron.zdrawtickmarks = zdrawtickmarks;
    /* Length of tickmarks */
    MyGTrihedron.xtickmarklength = xtickmarklength;
    MyGTrihedron.ytickmarklength = ytickmarklength;
    MyGTrihedron.ztickmarklength = ztickmarklength;
    /* Grid color */
    MyGTrihedron.gridcolor = gridcolor;
    /* Colors of axis names */
    MyGTrihedron.xnamecolor = xnamecolor;
    MyGTrihedron.ynamecolor = ynamecolor;
    MyGTrihedron.znamecolor = znamecolor;
    /* Colors of axis and values */
    MyGTrihedron.xcolor = xcolor;
    MyGTrihedron.ycolor = ycolor;
    MyGTrihedron.zcolor = zcolor;
    /* Name of font for names of axes */
    MyGTrihedron.fontOfNames = fontOfNames;
    /* Style of names of axes */
    MyGTrihedron.styleOfNames = styleOfNames;
    /* Size of names of axes */
    MyGTrihedron.sizeOfNames = sizeOfNames;
    /* Name of font for values */
    MyGTrihedron.fontOfValues = fontOfValues;
    /* Style of values */
    MyGTrihedron.styleOfValues = styleOfValues;
    /* Size of values */
    MyGTrihedron.sizeOfValues = sizeOfValues;

    MyGTrihedron.ptrVisual3dView = this;
    MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
    MyGraphicDriver->GraduatedTrihedronDisplay(MyCView,MyGTrihedron);
}

void Visual3d_View::GraduatedTrihedronErase()
{
    MyGTrihedron.ptrVisual3dView = NULL;
    MyGraphicDriver->GraduatedTrihedronErase(MyCView);
}

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

        return (MyViewManager->UnderLayer ());

}

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

        return (MyViewManager->OverLayer ());

}

Standard_Integer Visual3d_View::LightLimit() const {

        Standard_Integer maxlight = MyGraphicDriver->InquireLightLimit ();
//      printf(" $$$ Visual3d_View::LightLimit() is %d\n",maxlight);
        return maxlight;
}

Standard_Integer Visual3d_View::PlaneLimit() const {

        Standard_Integer maxplane = MyGraphicDriver->InquirePlaneLimit ();
//      printf(" $$$ Visual3d_View::PlaneLimit() is %d\n",maxplane);
        return maxplane;
}

#ifdef IMP140100
Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const {

        return MyPtrViewManager;
}
#endif

#ifdef G003
void Visual3d_View :: SetComputedMode ( const Standard_Boolean aMode ) {

 if (  (  (aMode &&  ComputedModeIsActive) ||
         (!aMode && !ComputedModeIsActive)
       ) || DegenerateModeIsOn ()
 ) return;

 Graphic3d_MapIteratorOfMapOfStructure S1Iterator ( MyDisplayedStructure );
 Visual3d_TypeOfAnswer                 Answer;
 Standard_Integer                      StructId;
 Standard_Integer                      i = MyDisplayedStructure.Extent ();

 if (  !( (ComputedModeIsActive = aMode) != 0 )   ) {

  while (  S1Iterator.More ()  ) {

   Answer = AcceptDisplay (  S1Iterator.Key ()  );

   if ( Answer == Visual3d_TOA_COMPUTE ) {

    Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );

    if ( Index != 0 ) {

     StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();

     MyGraphicDriver -> EraseStructure (
                         MyCView,
                         *( Graphic3d_CStructure* )
                          MyCOMPUTEDSequence.Value ( Index ) -> CStructure ()
                        );
     MyGraphicDriver -> DisplayStructure (
                         MyCView,
                                         *( Graphic3d_CStructure* )
                          S1Iterator.Key () -> CStructure (),
                         int (  S1Iterator.Key () -> DisplayPriority ()  )
                                    );
    }  // end if ( Index != 0 ) . . .

   }  // end if ( Answer . . . )

   S1Iterator.Next ();

  }  // end while

 } else {

  while (  S1Iterator.More ()  ) {

   Answer = AcceptDisplay (  S1Iterator.Key ()  );

   if ( Answer == Visual3d_TOA_COMPUTE ) {

    Standard_Integer Index = IsComputed (  S1Iterator.Key ()  );

    if ( Index != 0 ) {

     StructId = MyCOMPUTEDSequence.Value ( Index ) -> Identification ();

     MyGraphicDriver -> EraseStructure (
                         MyCView,
                         *( Graphic3d_CStructure* )
                          S1Iterator.Key () -> CStructure ()
                        );
     MyGraphicDriver -> DisplayStructure (
                         MyCView,
                                         *( Graphic3d_CStructure* )
                          MyCOMPUTEDSequence.Value ( Index ) -> CStructure (),
                                         int (  S1Iterator.Key () -> DisplayPriority ()  )
                        );

     Display (  S1Iterator.Key (), Aspect_TOU_WAIT  );

     if (  S1Iterator.Key () -> IsHighlighted ()  ) {

      if (  !MyCOMPUTEDSequence.Value ( Index ) -> IsHighlighted ()  ) {

       MyCOMPUTEDSequence.Value ( Index ) -> SetHighlightColor (
                                              S1Iterator.Key () ->
                                               HighlightColor ()
                                             );
       MyCOMPUTEDSequence.Value ( Index ) -> GraphicHighlight (
                                              Aspect_TOHM_COLOR
                                             );
      }  // end if

     }  // end if

    } else {

     Handle( Graphic3d_Structure ) AStructure = S1Iterator.Key ();
#ifdef OLD
     Handle( Graphic3d_Structure ) TheStructure = AStructure -> Compute ( this );
#else
     Handle( Graphic3d_Structure ) TheStructure;
     TColStd_Array2OfReal          ATrsf ( 0, 3, 0, 3 );

     AStructure -> Transform ( ATrsf );

     if ( Index != 0 ) {

      TColStd_Array2OfReal Ident ( 0, 3, 0, 3 );
      Standard_Integer     ii, jj;

      for ( ii = 0; ii <= 3; ++ii )

       for ( jj = 0; jj <= 3; ++jj  )

        Ident ( ii, jj ) = ( ii == jj ? 1.0 : 0.0 );

      TheStructure = MyCOMPUTEDSequence.Value ( Index );

      TheStructure -> SetTransform ( Ident, Graphic3d_TOC_REPLACE );

      if (  AStructure->IsTransformed ()  )

       AStructure -> Compute ( this, ATrsf, TheStructure );

      else

       AStructure -> Compute ( this, TheStructure );

     } else {

      if ( AStructure -> IsTransformed ()  )

       TheStructure = AStructure -> Compute ( this, ATrsf );

      else

       TheStructure = AStructure -> Compute ( this );

     }  // end else
#endif  // OLD
     TheStructure -> SetHLRValidation ( Standard_True );

     Visual3d_TypeOfVisualization ViewType = MyContext.Visualization ();

     Standard_Boolean ComputeWireframe =
      (  ( ViewType == Visual3d_TOV_WIREFRAME ) &&
             (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_SHADING  )
      );

     Standard_Boolean ComputeShading =
      (  ( ViewType == Visual3d_TOV_SHADING ) &&
             (  S1Iterator.Key () -> ComputeVisual () != Graphic3d_TOS_WIREFRAME  )
      );

     if ( ComputeWireframe ) TheStructure -> SetVisual ( Graphic3d_TOS_WIREFRAME );
     if ( ComputeShading   ) TheStructure -> SetVisual ( Graphic3d_TOS_SHADING   );

     if (  S1Iterator.Key () -> IsHighlighted ()  ) {

      TheStructure -> SetHighlightColor (
                       S1Iterator.Key () -> HighlightColor ()
                      );
      TheStructure -> GraphicHighlight ( Aspect_TOHM_COLOR );

     }  // end if

     Standard_Integer Result = 0;
     Standard_Integer Length = MyTOCOMPUTESequence.Length ();
     StructId = S1Iterator.Key () -> Identification ();

     for ( i = 1; i <= Length && Result == 0; ++i )

      if (  MyTOCOMPUTESequence.Value ( i ) -> Identification () == StructId  )

       Result = i;

     if ( Result )

      MyCOMPUTEDSequence.ChangeValue ( Result ) = TheStructure;

     else {

      MyTOCOMPUTESequence.Append (  S1Iterator.Key ()  );
      MyCOMPUTEDSequence.Append  ( TheStructure );

     }  // end else

     MyGraphicDriver -> EraseStructure (
                         MyCView,
                         *( Graphic3d_CStructure* )
                          S1Iterator.Key () -> CStructure ()
                        );
     MyGraphicDriver -> DisplayStructure (
                         MyCView,
                         *( Graphic3d_CStructure* )TheStructure -> CStructure (),
                         int (  S1Iterator.Key () -> DisplayPriority ()  )
                        );
    }  // end else

   }  // end if

   S1Iterator.Next ();

  }  // end while

  if (  MyViewManager -> UpdateMode () == Aspect_TOU_ASAP  ) Update ();

 }  // end else

}  // end Visual3d_View :: SetComputedMode

Standard_Boolean Visual3d_View :: ComputedMode () const {

 return ComputedModeIsActive;

}  // end Visual3d_View :: ComputedMode

void Visual3d_View :: SetBackFacingModel (
                       const Visual3d_TypeOfBackfacingModel aModel
                      ) {
 switch ( aModel ) {

  default:
  case Visual3d_TOBM_AUTOMATIC:
   MyCView.Backfacing = 0;
   break;

  case Visual3d_TOBM_FORCE:
   MyCView.Backfacing = 1;
   break;

  case Visual3d_TOBM_DISABLE:
   MyCView.Backfacing = -1;
   break;

 }  // end switch

 MyGraphicDriver -> SetBackFacingModel ( MyCView );

}  // end Visual3d_View :: SetBackFacingModel

Visual3d_TypeOfBackfacingModel Visual3d_View :: BackFacingModel () const {

 switch ( MyCView.Backfacing ) {

  case 0:
   return Visual3d_TOBM_AUTOMATIC;

  case 1:
   return Visual3d_TOBM_FORCE;

 }  // end switch

 return Visual3d_TOBM_DISABLE;

}  // end Visual3d_View :: BackFacingModel
#endif  // G003

void Visual3d_View::EnableDepthTest( const Standard_Boolean enable ) const
{
#ifdef BUC61044
  MyGraphicDriver->SetDepthTestEnabled( MyCView, enable );
#endif
}

Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
{
#ifdef BUC61044
  return MyGraphicDriver->IsDepthTestEnabled( MyCView );
#else
  return Standard_True;
#endif
}

void Visual3d_View::ReadDepths(const Standard_Integer x,
                               const Standard_Integer y,
                               const Standard_Integer width,
                               const Standard_Integer height,
                               const Standard_Address buffer) const
{
  MyGraphicDriver->ReadDepths( MyCView, x, y, width, height, buffer );
}

Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
                                                  const Standard_Integer theHeight)
{
  return MyGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
}

void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
{
  MyGraphicDriver->FBORelease( MyCView, theFBOPtr );
}

void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
                                     Standard_Integer& theWidth,    Standard_Integer& theHeight,
                                     Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
{
  MyGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
                                     theWidth, theHeight,
                                     theWidthMax, theHeightMax );
}

void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
                                      const Standard_Integer theWidth, const Standard_Integer theHeight)
{
  MyGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
                                     theWidth, theHeight );
}

Standard_Boolean Visual3d_View::BufferDump (Image_CRawBufferData& theBuffer)
{
  return MyGraphicDriver->BufferDump( MyCView, theBuffer);
}

void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
{
#ifdef BUC61045
  MyGraphicDriver->SetGLLightEnabled( MyCView, enable );
#endif
}


Standard_Boolean Visual3d_View::IsGLLightEnabled() const
{
#ifdef BUC61045
  return MyGraphicDriver->IsGLLightEnabled( MyCView );
#else
  return Standard_True;
#endif
}

void Visual3d_View::Export( const Standard_CString FileName,
                            const Graphic3d_ExportFormat Format,
                            const Graphic3d_SortType aSortType,
                            const Standard_Real Precision,
                            const Standard_Address ProgressBarFunc,
                            const Standard_Address ProgressObject ) const
{
    Handle( Visual3d_Layer ) AnUnderLayer = MyViewManager->UnderLayer(),
                             AnOverLayer  = MyViewManager->OverLayer();

    Aspect_CLayer2d OverCLayer;
    Aspect_CLayer2d UnderCLayer;
    OverCLayer.ptrLayer = UnderCLayer.ptrLayer = NULL;

    if( !AnOverLayer.IsNull() )
        OverCLayer = AnOverLayer->CLayer();
    if( !AnUnderLayer.IsNull() )
        UnderCLayer = AnUnderLayer->CLayer();

    Standard_Integer W, H;
    Window()->Size( W, H );

    MyGraphicDriver->Export( FileName, Format, aSortType, W, H, MyCView, UnderCLayer, OverCLayer,
                             Precision, ProgressBarFunc, ProgressObject );
}