summaryrefslogtreecommitdiff
path: root/src/OpenGl/OpenGl_triedron.cxx
blob: 3b03570d36a8d08c706daa49d652c4e2f33bea29 (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
/***********************************************************************

FONCTION :
----------
File OpenGl_triedron : gestion du triedre non zoomable.

REMARQUES:
---------- 

Algorithme :
o dimensions et origine du triedre sont recalcules a chaque fois, en
fonction de la taille (u,v = largeur-hauteur) de la fenetre =>
il est inutile ici de jouer sur le facteur d'echelle.
o on n'inhibe que les translations, car on veut conserver les
transformations d'orientations.


HISTORIQUE DES MODIFICATIONS   :
--------------------------------
08-12-98 : BGN ; Creation.


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

#define BUC60851  /* GG 15/03/01 Avoid to raise after the second creation
of the trihedron
*/

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


#define QTOCC_PATCH   /* Active QtOPENCASCADE patches */

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

#include <OpenGl_tgl_all.hxx>
#include <OpenGl_tgl_tox.hxx>


#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h> /* pour M_PI */

#include <OpenGl_LightBox.hxx>
#include <OpenGl_TextureBox.hxx>
#include <OpenGl_tgl_tox.hxx>

#include <OpenGl_tsm_ws.hxx>  /* pour TsmGetWSAttri */
#include <OpenGl_telem_view.hxx>  /* pour tel_view_data */
#include <InterfaceGraphic_Graphic3d.hxx>  /* pour CALL_DEF_STRUCTURE */
#include <InterfaceGraphic_Aspect.hxx>  /* pour CALL_DEF_VIEW  */
#include <InterfaceGraphic_Visual3d.hxx>

#include <OpenGl_transform_persistence.hxx>

#ifdef HAVE_GL2PS
#include <gl2ps.h>
#endif

#ifdef HAVE_CONFIG_H
#include <oce-config.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif

#include <OpenGl_TextRender.hxx>
/*----------------------------------------------------------------------*/
/*
* Constantes
*/ 

#define NO_DEBUG
#define NO_PRINT
#define NO_PRINT_MATRIX

#ifndef M_PI
# define M_PI          3.14159265358979323846
#endif

/* on trouve que 10 vues sera suffisant */
#define GROW_SIZE_NZ_WKS   10

/* pour l'instant on ne travaille que sur le triedre */
/* on augmentera le define quand on developpera les struc. non zoomables*/
#define GROW_SIZE_NZ_STRUC  1 

/* Identificateur du Triedre Non Zommable dans la liste des structures */
# define TRIEDRON_ID -100

/*----------------------------------------------------------------------*/
/*
* Definition de types
*/ 
typedef struct
{
  float aXColor[3];
  float aYColor[3];
  float aZColor[3];
  float aRatio;
  float aDiametr;
  int   aNbFacettes;
} ZBUF_STRUCT;


/* donnees des structures non zoomables liees a une wks (=une vue) */
typedef struct
{
  int   NZStrucID; /* = TRIEDRON_ID ou astructure->Id de Graphic3d sinon.*/
  int   aPos;
  float aColor[3];
  float aScale;
  int   isWireframe;
  CALL_DEF_STRUCTURE * astructure;
  ZBUF_STRUCT* aZBufParam;
} NZ_STRUC_DATA;



/* liste des wks (=vues) concernees par les structures non zoomables */
typedef struct
{
  int   nz_wks; /* = id de la wks  */
  int   triedron_on; /* =0 si le triedre non zoomable n'est pas defini */
  int   nz_struc_count; /* nb de structures non zoomables de la vue */
  int   nz_struc_size;
  NZ_STRUC_DATA *nz_struc;
} NZ_WKS;


typedef  struct
{
  TEL_VIEW_REP    vrep;
} TEL_VIEW_DATA, *tel_view_data; /* Internal data stored for every view rep */

/*----------------------------------------------------------------------*/
/*
* Variables statiques
*/

static NZ_WKS *nz_wks = NULL;
static int     nz_wks_count = 0;
static int     nz_wks_size = 0;

/* Default parameters for ZBUFFER triheron */
static float theXColor[] = { 1.0, 0.0, 0.0 };
static float theYColor[] = { 0.0, 1.0, 0.0 };
static float theZColor[] = { 0.0, 0.0, 1.0 };
static float theRatio = 0.8f;
static float theDiametr = 0.05f;
static int   theNBFacettes = 12;

/*----------------------------------------------------------------------*/
/*----------------------------------------------------------------------*/
/*
* Fonctions privees
*/



/*----------------------------------------------------------------------*/
/*
* recherche de la wks NZWksID concernee par les structures non zoomables;
* creation de l'element wks s'il n'existe pas.
*/
static int find_nz_wks(int NZWksID, int alloc)
{
  int i;

  /* recherche la wks dans la liste si elle existe */
  for (i=0; i<nz_wks_count; i++)
    if (nz_wks[i].nz_wks == NZWksID)
      return i;

  if (!alloc) return -1;

  /* la wks n'existe pas => on fait de la place si il n'y en a plus */
  if (nz_wks_count == nz_wks_size) {      
#ifdef BUC60851
    if( nz_wks_size > 0 ) {
      nz_wks_size += GROW_SIZE_NZ_WKS;
      nz_wks =  (NZ_WKS *) realloc(nz_wks, nz_wks_size * sizeof(NZ_WKS)); 
    } else {
      nz_wks_size = GROW_SIZE_NZ_WKS;
      nz_wks = (NZ_WKS *) malloc(nz_wks_size * sizeof(NZ_WKS));
    }
#else
    nz_wks_size += GROW_SIZE_NZ_WKS;
    nz_wks =  (NZ_WKS *) realloc(nz_wks, nz_wks_size * sizeof(NZ_WKS));
#endif
    if (nz_wks == NULL) return -1;
  }

  nz_wks[nz_wks_count].nz_wks = NZWksID;
  nz_wks[nz_wks_count].triedron_on = 0;
  nz_wks[nz_wks_count].nz_struc = NULL;
  nz_wks[nz_wks_count].nz_struc_size = 0;
  nz_wks[nz_wks_count].nz_struc_count = 0;

  return nz_wks_count++;
}

/*-----------------------------------------------------------------*/
/*
* recherche de la structure non zoomable NZStrucID dans la liste
* de la wks NZWksIdx ;
* creation de l'element structure non zoomable s'il n'existe pas.
*/
static int find_nz_struc(int NZWksIdx, int NZStrucID, int alloc)
{
  int i;
  NZ_STRUC_DATA *nz_struc;


  /* recherche la structure non zoomable dans la liste de la wks */
  nz_struc = nz_wks[NZWksIdx].nz_struc;
  for (i=0; i<nz_wks[NZWksIdx].nz_struc_count; i++)
    if (nz_struc[i].NZStrucID == NZStrucID)
      return i;

  if (!alloc) return -1;

  /* la structure non zoomable n'existe pas => on la cree */
  if (nz_wks[NZWksIdx].nz_struc_count == nz_wks[NZWksIdx].nz_struc_size) {
#ifdef BUC60851
    if( nz_wks[NZWksIdx].nz_struc_size > 0 ) {
      nz_wks[NZWksIdx].nz_struc_size += GROW_SIZE_NZ_STRUC;
      nz_wks[NZWksIdx].nz_struc = 
        (NZ_STRUC_DATA *)  realloc(nz_wks[NZWksIdx].nz_struc, 
        nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
    } else {
      nz_wks[NZWksIdx].nz_struc_size = GROW_SIZE_NZ_STRUC;
      nz_wks[NZWksIdx].nz_struc = 
        (NZ_STRUC_DATA *)  malloc( nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
    }
#else
    nz_wks[NZWksIdx].nz_struc_size += GROW_SIZE_NZ_STRUC;
    nz_wks[NZWksIdx].nz_struc = (NZ_STRUC_DATA *)  realloc(nz_wks[NZWksIdx].nz_struc, nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
#endif
    if (nz_wks[NZWksIdx].nz_struc == NULL) return -1;

    nz_wks[NZWksIdx].nz_struc[nz_wks[NZWksIdx].nz_struc_count].aZBufParam = NULL;
  }

  return nz_wks[NZWksIdx].nz_struc_count++;
}


/*----------------------------------------------------------------------*/

/*
* affichage d'un triedre non zoomable a partir des index dans les tables
* des structures non zoomables.
*
* Triedre = Objet non Zoomable :
* on recalcule ses dimensions et son origine en fonction de la taille
* de la fenetre; on positionne selon le choix de l'init;
* et on inhibe seulement les translations.
*
*/




TStatus call_triedron_redraw (
                              int      nz_wks_entry,
                              int      nz_struc_entry,
                              GLdouble U,
                              GLdouble V
                              )
{
  GLdouble modelMatrix[4][4];
  GLdouble projMatrix[4][4];

  GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
  GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
  GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
  GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
  GLfloat TriedronColor[3] = { 1.0, 1.0, 1.0 }; /* def = blanc */

  GLfloat TriedronWidth = 1.0;
  GLfloat TriedronScale = (float)0.1 ;
  GLint   TriedronPosition = 0; /* def = Aspect_TOTP_CENTER */

  GLdouble L, l, rayon ;
  GLdouble minUV;
  int      ii;
#ifdef PRINT_MATRIX 
  int      jj;
#endif
  int      NbFacettes;
  double   Angle;
  GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };

  GLuint fontBase = 0;
  GLint mode;

#ifdef QTOCC_PATCH /* PCD 10/02/08 */
  /* Fix to problem with clipping planes chopping off pieces of the triedron */
  GLint max_plane=0;
  GLboolean* isPlaneActive;
  glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
  isPlaneActive= new GLboolean[max_plane];
  /* Backup the clip planes.         */
  for (ii = 0; ii < max_plane ; ii++) {
    isPlaneActive[ii] = glIsEnabled(GL_CLIP_PLANE0 + ii);
    glDisable(GL_CLIP_PLANE0 + ii);
  }
#endif

  /* 
  * Lecture des Init. du Triedre 
  */

  TriedronColor[0] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0];
  TriedronColor[1] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1];
  TriedronColor[2] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2];
  TriedronScale = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale;
  TriedronPosition = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos;


  /* 
  * Calcul des axes => on inhibe le zoom.
  */

  /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
  /* de la dimension la plus petite de la window.                    */ 
  if ( U < V )  minUV = U;
  else minUV = V;
  L = minUV * (double) TriedronScale ;

  /* Position de l'origine */
  TriedronOrigin[0]= 0.0; 
  TriedronOrigin[1]= 0.0;
  TriedronOrigin[2]= 0.0; 

  /* Position des Axes */
  TriedronAxeX[0] = TriedronOrigin[0] + L ;
  TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
  TriedronAxeX[2] = TriedronOrigin[2] + 0.0;

  TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
  TriedronAxeY[1] = TriedronOrigin[1] + L ;
  TriedronAxeY[2] = TriedronOrigin[2] + 0.0;

  TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
  TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
  TriedronAxeZ[2] = TriedronOrigin[2] + L ;

  /*
  * On inhibe les translations; on conserve les autres transformations.
  */

  /* on lit les matrices de transformation et de projection de la vue */
  /* pour annuler les translations (dernieres colonnes des matrices). */
  glGetDoublev( GL_MODELVIEW_MATRIX,  (GLdouble *) modelMatrix );
  glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );

#ifdef PRINT_MATRIX 
  printf ("\n--- call_triedron_redraw : avant transfo projMatrix= ");
  for (ii = 0; ii<4 ; ii++) {
    printf ("\n ");
    for (jj = 0; jj<4 ; jj++) {
      printf ("  %f  ", projMatrix[ii][jj] );
    }
  }
  printf ("\n--- call_triedron_redraw : avant transfo  modelMatrix= ");
  for (ii = 0; ii<4 ; ii++) {
    printf ("\n ");
    for (jj = 0; jj<4 ; jj++) {
      printf ("  %f  ", modelMatrix[ii][jj] );
    }
  }
#endif


  /* on annule la translation qui peut etre affectee a la vue */
  modelMatrix[3][0] = 0. ;
  modelMatrix[3][1] = 0. ;
  modelMatrix[3][2] = 0. ; 
  projMatrix[3][0] = 0. ;
  projMatrix[3][1] = 0. ;
  projMatrix[3][2] = 0. ; 


  /* sauvegarde du contexte des matrices avant chargement */
  glMatrixMode (GL_MODELVIEW);
  glPushMatrix ();
  glLoadIdentity ();
  glLoadMatrixd( (GLdouble *) modelMatrix);
  glMatrixMode ( GL_PROJECTION );
  glPushMatrix ();
  glLoadIdentity();
  glLoadMatrixd( (GLdouble *) projMatrix);


#ifdef PRINT_MATRIX 
  printf ("\n\n\n--- call_triedron_redraw :  APRES transfo projMatrix= ");
  for (ii = 0; ii<4 ; ii++) {
    printf ("\n ");
    for (jj = 0; jj<4 ; jj++) {
      printf ("  %f  ", projMatrix[ii][jj] );
    }
  }
  printf ("\n--- call_triedron_redraw : APRES transfo  modelMatrix= ");
  for (ii = 0; ii<4 ; ii++) {
    printf ("\n ");
    for (jj = 0; jj<4 ; jj++) {
      printf ("  %f  ", modelMatrix[ii][jj] );
    }
  }
#endif


  /*
  * Positionnement de l'origine du triedre selon le choix de l'init
  */

  /* on fait uniquement une translation de l'origine du Triedre */

  switch (TriedronPosition) {

       case 0 : /* Aspect_TOTP_CENTER */
         break;

       case 1 : /* Aspect_TOTP_LEFT_LOWER */
         glTranslated( -U/2. + L , -V/2. + L , 0. );
         break;

       case 2  : /*Aspect_TOTP_LEFT_UPPER */
         glTranslated( -U/2. + L , +V/2. - L -L/3. , 0. );
         break;

       case 3 : /* Aspect_TOTP_RIGHT_LOWER */
         glTranslated( U/2. - L -L/3. , -V/2. + L , 0. );
         break;

       case 4  : /* Aspect_TOTP_RIGHT_UPPER */
         glTranslated( U/2. - L -L/3. , +V/2. - L -L/3. , 0. );
         break;

       default :
         break;

  }

#ifdef PRINT 
  printf ("\n--- call_triedron_redraw :  TriedronOrigin= %f %f %f\n",
    TriedronOrigin[0], TriedronOrigin[1], TriedronOrigin[2]);
  printf ("\n---                      :  TriedronAxeX= %f %f %f \n",
    TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
  printf ("\n---                      :  TriedronAxeY= %f %f %f \n",
    TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2] );
  printf ("\n---                      :  TriedronAxeZ= %f %f %f \n",
    TriedronAxeZ[0], TriedronAxeZ[1], TriedronAxeZ[2]);
  printf ("\n---                      : TriedronScale= %f \n",TriedronScale);
  printf ("\n---                      : 1/echelle = ( %f %f %f %f ) \n",
    modelMatrix[0][0],modelMatrix[1][1],modelMatrix[2][2],modelMatrix[3][3]);
#endif


  /* 
  * Creation du triedre 
  */
  glColor3fv (TriedronColor);

  glGetIntegerv( GL_RENDER_MODE, &mode );

#ifdef HAVE_GL2PS
  if( mode==GL_RENDER )
    glLineWidth( TriedronWidth );
  else if( mode==GL_FEEDBACK )
    gl2psLineWidth( TriedronWidth );
#else
	glLineWidth( TriedronWidth );
#endif 

#ifdef QTOCC_PATCH /* Fotis Sioutis 2007-11-14 15:06 
  I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode 
  changes colors depending on the state of the view. This behaviour can be easily 
  corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl.
  The only change needed is to erase the LightOff() function that is called before the 
  Axis name drawing and move this function call just before the initial axis drawing.
  Below is the code portion with the modification.I don't know if this is considered to 
  be a bug but anyway i believe it might help some of you out there.*/
  LightOff();
#endif

  /* dessin des axes */
  glBegin(GL_LINES);
  glVertex3dv( TriedronOrigin );
  glVertex3dv( TriedronAxeX );

  glVertex3dv( TriedronOrigin );
  glVertex3dv( TriedronAxeY );

  glVertex3dv( TriedronOrigin );
  glVertex3dv( TriedronAxeZ );
  glEnd();


  /* fleches au bout des axes (= cones de la couleur demandee) */
  l = L - L/4. ; /* distance a l'origine */
  rayon = L/30. ; /* rayon de la base du cone */
  NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */
  Angle = 2. * M_PI/ NbFacettes;

  /* solution FILAIRE des cones au bout des axes : une seule ligne */
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  /* (la couleur est deja initialisee dans TriedronColor) */
  /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */

  /* fleche en X */
  glBegin(GL_TRIANGLE_FAN);
  glVertex3dv( TriedronAxeX );
  TriedronCoord[0] = TriedronOrigin[0] + l ;
  ii = NbFacettes;
  while (ii >= 0 ) {
    TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) );
    TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) );
    glVertex3dv( TriedronCoord );
    ii--;
  }
  glEnd();

  /* fleche en Y */
  glBegin(GL_TRIANGLE_FAN);
  glVertex3dv( TriedronAxeY );
  TriedronCoord[1] = TriedronOrigin[1] + l ;
  ii = NbFacettes;
  while (ii >= 0 ) {
    TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) );
    TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) );
    glVertex3dv( TriedronCoord );
    ii--;
  }
  glEnd();

  /* fleche en Z */
  glBegin(GL_TRIANGLE_FAN);
  glVertex3dv( TriedronAxeZ );
  TriedronCoord[2] = TriedronOrigin[2] + l ;
  ii = NbFacettes;
  while (ii >= 0 ) {
    TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
    TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
    glVertex3dv( TriedronCoord );
    ii--;
  }
  glEnd();

  /* dessin de l'origine */
  TriedronCoord[0] = TriedronOrigin[0] + rayon ;
  TriedronCoord[1] = TriedronOrigin[1] + 0.0 ;
  TriedronCoord[2] = TriedronOrigin[2] + 0.0 ;
  ii = 24 ;
  Angle = 2. * M_PI/ii ;
  glBegin(GL_LINE_LOOP);
  while (ii >= 0 ) {
    TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
    TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
    glVertex3dv( TriedronCoord );
    ii--;
  }  
  glEnd();

  LightOff();

  /* 
  * Noms des axes et de l'origine
  */

  /* init de la fonte */

  OpenGl_TextRender* textRender=OpenGl_TextRender::instance();

  /* Axe X */
  TriedronCoord[0] = TriedronOrigin[0] + ( L + rayon ) ;
  TriedronCoord[1] = TriedronOrigin[1] + 0.0;
  TriedronCoord[2] = TriedronOrigin[2] - rayon ;
  textRender->RenderText(L"X", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2] );

  /* Axe Y */
  TriedronCoord[0] = TriedronOrigin[0] + rayon ;
  TriedronCoord[1] = TriedronOrigin[1] + ( L + 3.0 * rayon ) ;
  TriedronCoord[2] = TriedronOrigin[2] + ( 2.0 * rayon );
  textRender->RenderText(L"Y", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);

  /* Axe Z */
  TriedronCoord[0] = TriedronOrigin[0] + ( - 2.0 * rayon ) ;
  TriedronCoord[1] = TriedronOrigin[1] +  rayon/2. ;
  TriedronCoord[2] = TriedronOrigin[2] + ( L + 3.0 * rayon ) ;
  textRender->RenderText(L"Z", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);

#ifdef QTOCC_PATCH /* PCD 10/02/08 */
  /* Recover the clip planes */
  glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
  for (ii = 0; ii <max_plane ; ii++) {
    if (isPlaneActive[ii]) { 
      glEnable(GL_CLIP_PLANE0 + ii);
    }
  } 
  delete [] isPlaneActive;

#endif

  /* 
  * restauration du contexte des matrices
  */
  glMatrixMode (GL_PROJECTION);
  glPopMatrix ();
  glMatrixMode (GL_MODELVIEW);
  glPopMatrix ();


  return (TSuccess);

}




/*******************************************************
*  Draws ZBUFFER trihedron mode
*******************************************************/
TStatus call_zbuffer_triedron_redraw (
                                      int      nz_wks_entry,
                                      int      nz_struc_entry,
                                      GLdouble U,
                                      GLdouble V
                                      )
{
  GLdouble modelMatrix[4][4];
  GLdouble projMatrix[4][4];

  GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
  GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
  GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
  GLfloat TriedronColor[3] = { 1.0, 1.0, 1.0 }; /* def = blanc */

  GLfloat TriedronScale = (float)0.1 ;
  GLint   TriedronPosition = 0; /* def = Aspect_TOTP_CENTER */

  GLdouble L, rayon ;
  GLdouble minUV;
  int      NbFacettes = 12;
  GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };

  GLuint fontBase = 0;

  GLuint startList;
  GLUquadricObj* aQuadric;
  GLfloat aXColor[] = { 1.0, 0.0, 0.0, 0.6f };
  GLfloat aYColor[] = { 0.0, 1.0, 0.0, 0.6f };
  GLfloat aZColor[] = { 0.0, 0.0, 1.0, 0.6f };
  GLdouble aConeDiametr;
  GLdouble aConeLength;
  GLdouble aCylinderDiametr;
  GLdouble aCylinderLength;
  GLboolean aIsDepthEnabled;
#ifndef BUG
  GLboolean aIsDepthMaskEnabled;
#endif
  GLint   aViewPort[4];  /* to store view port coordinates */
  GLdouble aWinCoord[3];
  GLboolean isWithinView;
  GLdouble aLengthReduce = 0.8;
  GLdouble aAxisDiametr = 0.05;
  ZBUF_STRUCT* aParam;

#ifdef QTOCC_PATCH 
  GLint df;                                       /* PCD 17/06/07 */      
  GLfloat aNULLColor[] = { 0.0, 0.0, 0.0, 0.0f }; /* FS 21/01/08 */
  /* Fix to problem with clipping planes chopping off pieces of the triedron   */
  int i;
  GLint max_plane=0;
  GLboolean* isPlaneActive;
  glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
  isPlaneActive = new GLboolean[max_plane];
  /* Backup the clip planes. */
  for (i = 0; i < max_plane ; i++) {
    isPlaneActive[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
    glDisable(GL_CLIP_PLANE0 + i);
  }
#endif

  /* 
  * Lecture des Init. du Triedre 
  */

  TriedronColor[0] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0];
  TriedronColor[1] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1];
  TriedronColor[2] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2];
  TriedronScale = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale;
  TriedronPosition = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos;

  if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam != NULL) {
    aParam = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam;
    aXColor[0] = aParam->aXColor[0];
    aXColor[1] = aParam->aXColor[1];
    aXColor[2] = aParam->aXColor[2];

    aYColor[0] = aParam->aYColor[0];
    aYColor[1] = aParam->aYColor[1];
    aYColor[2] = aParam->aYColor[2];

    aZColor[0] = aParam->aZColor[0];
    aZColor[1] = aParam->aZColor[1];
    aZColor[2] = aParam->aZColor[2];

    aLengthReduce = aParam->aRatio;
    aAxisDiametr = aParam->aDiametr;
    NbFacettes = aParam->aNbFacettes;
  }

  /* 
  * Calcul des axes => on inhibe le zoom.
  */

  /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
  /* de la dimension la plus petite de la window.                    */ 
  if ( U < V )  minUV = U;
  else minUV = V;
  L = minUV * (double) TriedronScale ;

  /* Position de l'origine */
  TriedronOrigin[0]= 0.0; 
  TriedronOrigin[1]= 0.0;
  TriedronOrigin[2]= 0.0; 

  /* Position des Axes */
  TriedronAxeX[0] = TriedronOrigin[0] + L ;
  TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
  TriedronAxeX[2] = TriedronOrigin[2] + 0.0;

  TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
  TriedronAxeY[1] = TriedronOrigin[1] + L ;
  TriedronAxeY[2] = TriedronOrigin[2] + 0.0;

  /* Check position in the ViewPort */
  glGetDoublev( GL_MODELVIEW_MATRIX,  (GLdouble *) modelMatrix );
  glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );

  glGetIntegerv(GL_VIEWPORT, aViewPort);
  gluProject(TriedronOrigin[0], TriedronOrigin[1], TriedronOrigin[2],
    (GLdouble *)modelMatrix, (GLdouble *)projMatrix, aViewPort,
    &aWinCoord[0], &aWinCoord[1], &aWinCoord[2]);

#ifdef QTOCC_PATCH /* PCD 29/09/2008 */
  /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey  */
  /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER   */
  /* which causes the glyph to jump around the screen when the origin moves offscreen. */
  isWithinView = GL_FALSE;
#else
  /* Original code */
  isWithinView = !((aWinCoord[0]<aViewPort[0]) || (aWinCoord[0]>aViewPort[2]) ||
    (aWinCoord[1]<aViewPort[1]) || (aWinCoord[1]>aViewPort[3]));
#endif

  if (!isWithinView) {
    /* Annulate translation matrix */
    modelMatrix[3][0] = 0. ;
    modelMatrix[3][1] = 0. ;
    modelMatrix[3][2] = 0. ; 
    projMatrix[3][0] = 0. ;
    projMatrix[3][1] = 0. ;
    projMatrix[3][2] = 0. ; 

    /* save matrix */
    glMatrixMode (GL_MODELVIEW);
    glPushMatrix ();
    glLoadIdentity ();
    glLoadMatrixd( (GLdouble *) modelMatrix);
    glMatrixMode ( GL_PROJECTION );
    glPushMatrix ();
    glLoadIdentity();
    glLoadMatrixd( (GLdouble *) projMatrix);


    /*
    * Define position in the view
    */
    switch (TriedronPosition) {
      case 0 :  /* Aspect_TOTP_CENTER */
        break;

      case 1 :  /* Aspect_TOTP_LEFT_LOWER */
        glTranslated( -U/2. + L , -V/2. + L , 0. );
        break;

      case 2  : /* Aspect_TOTP_LEFT_UPPER */
        glTranslated( -U/2. + L , +V/2. - L -L/3. , 0. );
        break;

      case 3 :  /* Aspect_TOTP_RIGHT_LOWER */
        glTranslated( U/2. - L -L/3. , -V/2. + L , 0. );
        break;

      case 4  :  /* Aspect_TOTP_RIGHT_UPPER */
        glTranslated( U/2. - L -L/3. , +V/2. - L -L/3. , 0. );
        break;

      default :
        break;

    }
    L *= aLengthReduce;
  }


  /* 
  * Creation the trihedron
  */

#define COLOR_REDUCE      0.3f
#define CYLINDER_LENGTH   0.75f
#ifdef BUG
#define ALPHA_REDUCE      0.4f
#else
#define ALPHA_REDUCE      1.0f
#endif

  startList = glGenLists(4);
  aQuadric = gluNewQuadric();

  aCylinderLength = L * CYLINDER_LENGTH;
  aCylinderDiametr = L * aAxisDiametr;
  aConeDiametr = aCylinderDiametr * 2;
  aConeLength = L * (1 - CYLINDER_LENGTH);
  /* Correct for owerlapping */
  /*    aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/

  aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST);
#ifndef BUG

#ifdef QTOCC_PATCH  /*PCD 02/07/07   */
  /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the  */
  /* original code is shown to be broken when run under an OpenGL debugger  */
  /* like GLIntercept. This is the correct way to retrieve the mask value.  */
  glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled); 
#else
  aIsDepthMaskEnabled = glIsEnabled(GL_DEPTH_WRITEMASK);
#endif

#endif 

  /* Create cylinder for axis */
  gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */
  gluQuadricNormals(aQuadric, GLU_FLAT);
  /* Axis */
  glNewList(startList, GL_COMPILE);
  gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, NbFacettes, 1);
  glEndList();
  /* Cone */
  glNewList(startList + 1, GL_COMPILE);
  gluCylinder(aQuadric, aConeDiametr, 0, aConeLength, NbFacettes, 1);
  glEndList();
  /* Central sphere */
  glNewList(startList + 2, GL_COMPILE);
#ifdef QTOCC_PATCH
  gluSphere(aQuadric, aCylinderDiametr * 2, NbFacettes, NbFacettes);
#else
  gluSphere(aQuadric, aCylinderDiametr, NbFacettes, NbFacettes);
#endif
  glEndList();
  /* End disk */
  gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/
  glNewList(startList + 3, GL_COMPILE);
  gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, NbFacettes, 1/*szv:2*/);
  glEndList();

#ifdef QTOCC_PATCH
  /* Store previous attributes */
  glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
  LightOn();
#else
  LightOn();

  /* Store previous attributes */
  glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
#endif

  glCullFace(GL_BACK);
  glEnable(GL_CULL_FACE);

#ifdef QTOCC_PATCH /*Fotis Sioutis | 2008-01-21 10:55 
  In the function call_zbuffer_triedron_redraw of TKOpengl, 
  the z buffered trihedron changes colors in case there 
  is an object in the scene that has an explicit material 
  attached to it.In the trihedron display loop, 
  GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE 
  parameter is utilized in glColorMaterial(...).
  This causes the last ambient,specular and emission values 
  used, to stay at the stack and applied to the trihedron
  (which causes the color change).
  A fix is proposed , to change GL_DIFFUSE to 
  GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in 
  line 946.The above of course will leave unchanged 
  the SPECULAR and EMISSION values.
  Another proposal which would fix 100% the problem 
  is to use glMaterial instead of glColor on the trihedron 
  drawing loop.               */
  glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor);
  glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor);

  glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.);
#endif

  glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  glEnable(GL_COLOR_MATERIAL);

  if (!aIsDepthEnabled)  {
    glEnable(GL_DEPTH_TEST);
#ifndef BUG
    glClear(GL_DEPTH_BUFFER_BIT);
#endif
  }
#ifdef BUG
  if (!(aIsDepthEnabled && isWithinView))
    glClear(GL_DEPTH_BUFFER_BIT);
#endif
#ifndef BUG
  if (!aIsDepthMaskEnabled)  {
    /* This is how the depthmask needs to be re-enabled...*/
    glDepthMask(GL_TRUE);
    /* ...and not this stuff below */
  }
#endif

  glMatrixMode(GL_MODELVIEW);
#ifdef QTOCC_PATCH /* PCD 17/06/07  */
  glGetIntegerv (GL_DEPTH_FUNC, &df); 
#else
  /*szv:if (isWithinView) {*/
  glDepthFunc(GL_GREATER);
  glPushMatrix();
  glPushMatrix();
  glPushMatrix();

  glColor4f(TriedronColor[0]*COLOR_REDUCE, 
    TriedronColor[1]*COLOR_REDUCE, 
    TriedronColor[2]*COLOR_REDUCE,
    ALPHA_REDUCE);
  glCallList(startList+2);

  /* Z axis */
  glColor4f(aZColor[0]*COLOR_REDUCE, 
    aZColor[1]*COLOR_REDUCE, 
    aZColor[2]*COLOR_REDUCE,
    ALPHA_REDUCE);
  glCallList(startList);
  glTranslated(0, 0, L * CYLINDER_LENGTH);
  glCallList(startList + 3);
  glCallList(startList + 1);
  glPopMatrix();    

  /* X axis */
  glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
  glColor4f(aXColor[0]*COLOR_REDUCE, 
    aXColor[1]*COLOR_REDUCE, 
    aXColor[2]*COLOR_REDUCE,
    ALPHA_REDUCE);
  glCallList(startList);
  glTranslated(0, 0, L * CYLINDER_LENGTH);
  glCallList(startList + 3);
  glCallList(startList + 1);
  glPopMatrix();    

  /* Y axis */
  glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
  glColor4f(aYColor[0]*COLOR_REDUCE, 
    aYColor[1]*COLOR_REDUCE, 
    aYColor[2]*COLOR_REDUCE,
    ALPHA_REDUCE);
  glCallList(startList);
  glTranslated(0, 0, L * CYLINDER_LENGTH);
  glCallList(startList + 3);
  glCallList(startList + 1);
  glPopMatrix();

  glDepthFunc(GL_LESS);
  /*szv:}*/
#endif

#ifdef QTOCC_PATCH
  for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */
  {
    if (i == 0) /*  First pass  */
    {                          
      glDepthFunc(GL_ALWAYS); 
    }
    else
    {
      glDepthFunc(GL_LEQUAL); 
    }
#endif

    glPushMatrix();
    glPushMatrix();
    glPushMatrix();

    glColor3fv(TriedronColor);
    glCallList(startList+2);

    /* Z axis */
    glColor4fv(aZColor);
    glCallList(startList);
    glTranslated(0, 0, L * CYLINDER_LENGTH);
    glCallList(startList + 3);
    glCallList(startList + 1);
    glPopMatrix();    

    /* X axis */
    glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
    glColor4fv(aXColor);
    glCallList(startList);
    glTranslated(0, 0, L * CYLINDER_LENGTH);
    glCallList(startList + 3);
    glCallList(startList + 1);
    glPopMatrix();    

    /* Y axis */
    glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
    glColor4fv(aYColor);
    glCallList(startList);
    glTranslated(0, 0, L * CYLINDER_LENGTH);
    glCallList(startList + 3);
    glCallList(startList + 1);
    glPopMatrix();

#ifdef QTOCC_PATCH
  }
#endif

  if (!aIsDepthEnabled) 
    glDisable(GL_DEPTH_TEST);
#ifndef BUG
  if (!aIsDepthMaskEnabled)

#ifdef QTOCC_PATCH /*PCD 02/07/07   */
    glDepthMask(GL_FALSE);
#else
    glDisable(GL_DEPTH_WRITEMASK);
#endif

#endif
  glDisable(GL_CULL_FACE);
  glDisable(GL_COLOR_MATERIAL);

  gluDeleteQuadric(aQuadric);
  glColor3fv (TriedronColor);

#ifdef QTOCC_PATCH /* PCD 11/02/08 */
  /* Always write the text */
  glDepthFunc(GL_ALWAYS); 
#endif

  glPopAttrib();

  /* fleches au bout des axes (= cones de la couleur demandee) */
  rayon = L/30. ; /* rayon de la base du cone */

  glDeleteLists(startList, 4); 

  LightOff();

  /* 
  * origine names
  */

  /* init font */

  OpenGl_TextRender* textRender=OpenGl_TextRender::instance();

  /* Axe X */
  TriedronCoord[0] = TriedronOrigin[0] + ( L + rayon ) ;
  TriedronCoord[1] = TriedronOrigin[1] + 0.0;
  TriedronCoord[2] = TriedronOrigin[2] - rayon ;
  textRender->RenderText(L"X", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);

  /* Axe Y */
  TriedronCoord[0] = TriedronOrigin[0] + rayon ;
  TriedronCoord[1] = TriedronOrigin[1] + ( L + 3.0 * rayon ) ;
  TriedronCoord[2] = TriedronOrigin[2] + ( 2.0 * rayon );
  textRender->RenderText(L"Y", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);

  /* Axe Z */
  TriedronCoord[0] = TriedronOrigin[0] + ( - 2.0 * rayon ) ;
  TriedronCoord[1] = TriedronOrigin[1] +  rayon/2. ;
  TriedronCoord[2] = TriedronOrigin[2] + ( L + 3.0 * rayon ) ;
  textRender->RenderText(L"Z", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);

#ifdef QTOCC_PATCH 
  /*PCD 17/06/07    */
  glDepthFunc(df);

  /* PCD 10/02/08  */
  /* Recover the clip planes */ 
  glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
  for (i = 0; i < max_plane ; i++) {
    if (isPlaneActive[i]) { 
      glEnable(GL_CLIP_PLANE0 + i);
    }
  }
  delete [] isPlaneActive;
#endif

  if (!isWithinView) { /* restore matrix */
    glMatrixMode (GL_PROJECTION);
    glPopMatrix ();
    glMatrixMode (GL_MODELVIEW);
    glPopMatrix ();
  }

  return (TSuccess);

}


/*----------------------------------------------------------------------*/

/*----------------------------------------------------------------------*/
/*
* Fonctions publiques 
*/


/*
* initialisation d'un triedre non zoomable dans une vue.
* ou modification des valeurs deja initialisees.
*/

TStatus call_triedron_init (
                            CALL_DEF_VIEW * aview, 
                            int aPosition, 
                            float r,
                            float g,
                            float b, 
                            float aScale,
                            int asWireframe 
                            )

{

  int nz_wks_entry;
  int nz_struc_entry;
  ZBUF_STRUCT* aParam;


#ifdef PRINT
  printf("\n----------- call_triedron_init  r = %f, g = %f, b = %f",
    r, g, b);
  printf(", aScale = %f, aPosition = %d \n", aScale, aPosition );
#endif

  if (aview->WsId == -1) return(TFailure);
  if (aview->ViewId == -1) return(TFailure);
#ifdef PRINT
  printf(", aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
#endif



  /* recherche du num de la liste de structures non zoomables de la wks */
  /* creation sinon */
  nz_wks_entry = find_nz_wks(aview->WsId, 1);
  if (nz_wks_entry == -1) return TFailure;

  /* recherche du Triedre s'il existe; creation sinon */
  nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 1);
  if (nz_struc_entry == -1) return TFailure;

  /* mise a jour du Triedre */
  nz_wks[nz_wks_entry].triedron_on = 1;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].NZStrucID = TRIEDRON_ID;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].astructure = NULL;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos = aPosition;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0] = r;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1] = g;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2] = b;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale = aScale;
  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].isWireframe = asWireframe;

  nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam = new ZBUF_STRUCT();
  if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam == NULL) return TFailure;

  aParam = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam;
  aParam->aXColor[0] = theXColor[0];
  aParam->aXColor[1] = theXColor[1];
  aParam->aXColor[2] = theXColor[2];

  aParam->aYColor[0] = theYColor[0];
  aParam->aYColor[1] = theYColor[1];
  aParam->aYColor[2] = theYColor[2];

  aParam->aZColor[0] = theZColor[0];
  aParam->aZColor[1] = theZColor[1];
  aParam->aZColor[2] = theZColor[2];

  aParam->aRatio = theRatio;
  aParam->aDiametr = theDiametr;
  aParam->aNbFacettes = theNBFacettes;


#ifdef DEBUG
  printf("nz_wks_entry=%d nz_struc_entry=%d \n",nz_wks_entry,nz_struc_entry);
  printf("ajout ok\n");
#endif
  return (TSuccess);

}

/*----------------------------------------------------------------------*/

/*
* affichage d'un triedre non zoomable dans la wks  awsid 
*
* Triedre = Objet non Zoomable;
* on cree cette fonction pour pouvoir travailler par les structures 
* utilisees par les fonctions Tsm* et TEL_VIEW_REP
*
*/

TStatus call_triedron_redraw_from_wsid (
                                        Tint awsid
                                        )

{

  TStatus   status = TSuccess;
  int       nz_wks_entry;
  int       nz_struc_entry;
  int    save_texture_state;
  GLdouble  U, V ; /* largeur,hauteur de la fenetre */

  CMN_KEY_DATA    key;
  tel_view_data   vptr;

  if ( awsid == -1) return (TFailure );

#ifdef BUC61045
  /* check if GL_LIGHTING should be disabled
  no enabling 'cause it will be done (if necessary: kinda Polygon types ) 
  during redrawing structures 
  */
  TsmGetWSAttri (awsid, WSGLLight, &key );
  if ( key.ldata == TOff )
    glDisable( GL_LIGHTING );
#endif

  /* recherche du numero de la liste de structures non zoomables de la wks */
#ifdef PRINT
  printf("\n----------- call_triedron_redraw_from_WSID : appel find_nz_wks \n");
#endif
  nz_wks_entry = find_nz_wks(awsid, 0);
  /* si on ne l'a pas trouve, il n'y a rien a faire */
  if (nz_wks_entry == -1) return (TSuccess);

  /* recherche du Triedre */
#ifdef PRINT
  printf("\n----------- call_triedron_redraw_from_WSID : appel find_nz_struc \n");
#endif
  nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 0);
  /* si on ne l'a pas trouve, il n'y a rien a faire */
  if (nz_struc_entry == -1) return (TSuccess);
  /* si il est "off" il n'y a rien a faire */
  if (nz_wks[nz_wks_entry].triedron_on == 0) return (TSuccess);


  /* recherche de la dimension de la fenetre                   */
  /* (car la taille des axes du treiedre en sera 1 proportion) */
  TsmGetWSAttri (awsid, WSViews, &key );
  vptr = (tel_view_data)key.pdata ; /* Obtain defined view data*/
  if ( !vptr ) return TFailure; /* no view defined yet */
  U = vptr->vrep.extra.map.window.xmax - vptr->vrep.extra.map.window.xmin;
  V = vptr->vrep.extra.map.window.ymax - vptr->vrep.extra.map.window.ymin;

  /* sauvegarde du contexte (on reste dans le buffer courant) */
  save_texture_state = IsTextureEnabled();
  DisableTexture();

  /* affichage du Triedre Non Zoomable */
  transform_persistence_end();
  if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].isWireframe)
    status = call_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);
  else
    status = call_zbuffer_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);

  /* restauration du contexte */
  if (save_texture_state) EnableTexture();

  return status;

}

/*----------------------------------------------------------------------*/

/*
* affichage d'un triedre non zoomable dans la vue aview 
*
* Triedre = Objet non Zoomable;
* on cree cette fonction pour pouvoir utiliser CALL_DEF_VIEW
*
*/

TStatus call_triedron_redraw_from_view (
                                        CALL_DEF_VIEW * aview
                                        )
{

  TStatus   status = TSuccess;
  int       nz_wks_entry;
  int       nz_struc_entry;
  int    save_texture_state;
  GLdouble  U, V ; /* largeur,hauteur de la fenetre */



  if (aview->WsId == -1) return (TFailure );
  if (aview->ViewId == -1) return (TFailure);
#ifdef PRINT
  printf("\n call_triedron_redraw_from_VIEW aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
#endif


  /* recherche du numero de la liste de structures non zoomables de la wks */
#ifdef PRINT
  printf("\n----------- call_triedron_redraw_from_VIEW : appel find_nz_wks \n");
#endif
  nz_wks_entry = find_nz_wks(aview->WsId, 0);
  /* si on ne l'a pas trouve, il n'y a rien a faire */
  if (nz_wks_entry == -1) return (TSuccess);

  /* recherche du Triedre */
#ifdef PRINT
  printf("\n----------- call_triedron_redraw_from_VIEW : appel find_nz_struc \n");
#endif
  nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 0);
  /* si on ne l'a pas trouve, il n'y a rien a faire */
  if (nz_struc_entry == -1) return (TSuccess);
  /* si il est "off" il n'y a rien a faire */
  if (nz_wks[nz_wks_entry].triedron_on == 0) return (TSuccess);


  /* recherche de la dimension de la fenetre                   */
  /* (car la taille des axes du treiedre en sera 1 proportion) */
  U = aview->Mapping.WindowLimit.uM - aview->Mapping.WindowLimit.um ;
  V = aview->Mapping.WindowLimit.vM - aview->Mapping.WindowLimit.vm ;

  /* sauvegarde du contexte et ecriture en front buffer */
  save_texture_state = IsTextureEnabled();
  DisableTexture();
  glDrawBuffer (GL_FRONT);

  /* affichage du Triedre Non Zoomable */
  transform_persistence_end();
  status = call_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);

  /* necessaire pour WNT */
  glFlush();

  /* restauration du contexte */
  if (save_texture_state) EnableTexture();
  glDrawBuffer (GL_BACK); 

  return status;

}

/*----------------------------------------------------------------------*/

/*
* destruction du triedre non zoomable d'une vue.
*/

TStatus call_triedron_erase (
                             CALL_DEF_VIEW * aview
                             )

{
  int   nz_wks_entry;
  int i;


#ifdef PRINT
  printf("\n----------- call_triedron_erase  " );
#endif

  if (aview->WsId == -1) return(TFailure);
  if (aview->ViewId == -1) return(TFailure);
#ifdef PRINT
  printf(", aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
#endif


  /* recherche du num de la liste de structures non zoomables de la wks */
  /* si on ne l'a pas trouve, il n'y a rien a faire                     */
  nz_wks_entry = find_nz_wks(aview->WsId, 0);
  if (nz_wks_entry == -1) return TSuccess;


  /* 
  * destruction du Triedre puis de toute la wks
  */
  /* (aujourd'hui il n'y a pas d'autre structure graphique dans la table */
  /* de la wks => on detruit tout ;                                      */
  /* si on ajoutait d'autres structures non zoomables, il faudrait       */
  /* selectionner et detruire uniquement l'element Triedre en cherchant  */
  /* s'il existe via une variable nz_struc_entry ).                      */
  for (i = 0; i < nz_wks[nz_wks_entry].nz_struc_count; i++) {
    if (nz_wks[nz_wks_entry].nz_struc[i].aZBufParam != NULL) 
      free(nz_wks[nz_wks_entry].nz_struc[i].aZBufParam);
  }

  if (nz_wks[nz_wks_entry].nz_struc != NULL) {
    free(nz_wks[nz_wks_entry].nz_struc);
  }

  if (nz_wks_count == 1) {
    free(nz_wks);
    nz_wks_count = 0;
    nz_wks_size = 0;
  }
  else { /* il y a au moins 2 wks definies */
    memcpy(&nz_wks[nz_wks_entry],
      &nz_wks[nz_wks_entry+1],
      (nz_wks_count - nz_wks_entry - 1)*sizeof(NZ_WKS));
    nz_wks_count--;
  }


#ifdef DEBUG
  printf("nz_wks_entry=%d   nz_wks_count=%d   nz_wks_size=%d\n",
    nz_wks_entry,  nz_wks_count, nz_wks_size );
  printf("erase ok\n");
#endif

  return (TSuccess);
}

/*----------------------------------------------------------------------*/


/*
* gestion d'un echo de designation du triedre non zoomable d' une vue.
*/
TStatus call_triedron_echo (
                            CALL_DEF_VIEW * aview,
                            int aType
                            )

{
  return (TSuccess);
}


/*----------------------------------------------------------------------*/

/*
* initialisation of zbuffer trihedron
*/
extern TStatus  call_ztriedron_setup (
                                      float* xcolor,
                                      float* ycolor,
                                      float* zcolor,
                                      float  sizeratio,
                                      float  axisdiameter,
                                      int    nbfacettes)
{
  theXColor[0] = xcolor[0];
  theXColor[1] = xcolor[1];
  theXColor[2] = xcolor[2];

  theYColor[0] = ycolor[0];
  theYColor[1] = ycolor[1];
  theYColor[2] = ycolor[2];

  theZColor[0] = zcolor[0];
  theZColor[1] = zcolor[1];
  theZColor[2] = zcolor[2];

  theRatio = sizeratio;
  theDiametr = axisdiameter;
  theNBFacettes = nbfacettes;

  return (TSuccess);
}