0022149: Strings with Japanese characters can not be displayed in 3D viewer
[occt.git] / src / OpenGl / OpenGl_triedron.cxx
1 /***********************************************************************
2
3 FONCTION :
4 ----------
5 File OpenGl_triedron : gestion du triedre non zoomable.
6
7 REMARQUES:
8 ---------- 
9
10 Algorithme :
11 o dimensions et origine du triedre sont recalcules a chaque fois, en
12 fonction de la taille (u,v = largeur-hauteur) de la fenetre =>
13 il est inutile ici de jouer sur le facteur d'echelle.
14 o on n'inhibe que les translations, car on veut conserver les
15 transformations d'orientations.
16
17
18 HISTORIQUE DES MODIFICATIONS   :
19 --------------------------------
20 08-12-98 : BGN ; Creation.
21
22
23 ************************************************************************/
24
25 #define BUC60851  /* GG 15/03/01 Avoid to raise after the second creation
26 of the trihedron
27 */
28
29 #define BUC61045        /* 25/10/01 SAV ; added functionality to control gl lighting 
30 from higher API */
31
32
33 #define QTOCC_PATCH   /* Active QtOPENCASCADE patches */
34
35 /*----------------------------------------------------------------------*/
36 /*
37 * Includes
38 */ 
39
40 #include <OpenGl_tgl_all.hxx>
41 #include <OpenGl_tgl_tox.hxx>
42
43
44 #include <stddef.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <math.h> /* pour M_PI */
48
49 #include <OpenGl_LightBox.hxx>
50 #include <OpenGl_TextureBox.hxx>
51 #include <OpenGl_tgl_tox.hxx>
52
53 #include <OpenGl_tsm_ws.hxx>  /* pour TsmGetWSAttri */
54 #include <OpenGl_telem_view.hxx>  /* pour tel_view_data */
55 #include <InterfaceGraphic_Graphic3d.hxx>  /* pour CALL_DEF_STRUCTURE */
56 #include <InterfaceGraphic_Aspect.hxx>  /* pour CALL_DEF_VIEW  */
57 #include <InterfaceGraphic_Visual3d.hxx>
58
59 #include <OpenGl_transform_persistence.hxx>
60
61 #ifdef HAVE_GL2PS
62 #include <gl2ps.h>
63 #endif
64
65 #ifdef HAVE_CONFIG_H
66 #include <config.h>
67 #endif
68 #ifdef HAVE_STRING_H
69 #include <string.h>
70 #endif
71
72 #include <OpenGl_TextRender.hxx>
73 /*----------------------------------------------------------------------*/
74 /*
75 * Constantes
76 */ 
77
78 #define NO_DEBUG
79 #define NO_PRINT
80 #define NO_PRINT_MATRIX
81
82 #ifndef M_PI
83 # define M_PI          3.14159265358979323846
84 #endif
85
86 /* on trouve que 10 vues sera suffisant */
87 #define GROW_SIZE_NZ_WKS   10
88
89 /* pour l'instant on ne travaille que sur le triedre */
90 /* on augmentera le define quand on developpera les struc. non zoomables*/
91 #define GROW_SIZE_NZ_STRUC  1 
92
93 /* Identificateur du Triedre Non Zommable dans la liste des structures */
94 # define TRIEDRON_ID -100
95
96 /*----------------------------------------------------------------------*/
97 /*
98 * Definition de types
99 */ 
100 typedef struct
101 {
102   float aXColor[3];
103   float aYColor[3];
104   float aZColor[3];
105   float aRatio;
106   float aDiametr;
107   int   aNbFacettes;
108 } ZBUF_STRUCT;
109
110
111 /* donnees des structures non zoomables liees a une wks (=une vue) */
112 typedef struct
113 {
114   int   NZStrucID; /* = TRIEDRON_ID ou astructure->Id de Graphic3d sinon.*/
115   int   aPos;
116   float aColor[3];
117   float aScale;
118   int   isWireframe;
119   CALL_DEF_STRUCTURE * astructure;
120   ZBUF_STRUCT* aZBufParam;
121 } NZ_STRUC_DATA;
122
123
124
125 /* liste des wks (=vues) concernees par les structures non zoomables */
126 typedef struct
127 {
128   int   nz_wks; /* = id de la wks  */
129   int   triedron_on; /* =0 si le triedre non zoomable n'est pas defini */
130   int   nz_struc_count; /* nb de structures non zoomables de la vue */
131   int   nz_struc_size;
132   NZ_STRUC_DATA *nz_struc;
133 } NZ_WKS;
134
135
136 typedef  struct
137 {
138   TEL_VIEW_REP    vrep;
139 } TEL_VIEW_DATA, *tel_view_data; /* Internal data stored for every view rep */
140
141 /*----------------------------------------------------------------------*/
142 /*
143 * Variables statiques
144 */
145
146 static NZ_WKS *nz_wks = NULL;
147 static int     nz_wks_count = 0;
148 static int     nz_wks_size = 0;
149
150 /* Default parameters for ZBUFFER triheron */
151 static float theXColor[] = { 1.0, 0.0, 0.0 };
152 static float theYColor[] = { 0.0, 1.0, 0.0 };
153 static float theZColor[] = { 0.0, 0.0, 1.0 };
154 static float theRatio = 0.8f;
155 static float theDiametr = 0.05f;
156 static int   theNBFacettes = 12;
157
158 /*----------------------------------------------------------------------*/
159 /*----------------------------------------------------------------------*/
160 /*
161 * Fonctions privees
162 */
163
164
165
166 /*----------------------------------------------------------------------*/
167 /*
168 * recherche de la wks NZWksID concernee par les structures non zoomables;
169 * creation de l'element wks s'il n'existe pas.
170 */
171 static int find_nz_wks(int NZWksID, int alloc)
172 {
173   int i;
174
175   /* recherche la wks dans la liste si elle existe */
176   for (i=0; i<nz_wks_count; i++)
177     if (nz_wks[i].nz_wks == NZWksID)
178       return i;
179
180   if (!alloc) return -1;
181
182   /* la wks n'existe pas => on fait de la place si il n'y en a plus */
183   if (nz_wks_count == nz_wks_size) {      
184 #ifdef BUC60851
185     if( nz_wks_size > 0 ) {
186       nz_wks_size += GROW_SIZE_NZ_WKS;
187       nz_wks =  (NZ_WKS *) realloc(nz_wks, nz_wks_size * sizeof(NZ_WKS)); 
188     } else {
189       nz_wks_size = GROW_SIZE_NZ_WKS;
190       nz_wks = (NZ_WKS *) malloc(nz_wks_size * sizeof(NZ_WKS));
191     }
192 #else
193     nz_wks_size += GROW_SIZE_NZ_WKS;
194     nz_wks =  (NZ_WKS *) realloc(nz_wks, nz_wks_size * sizeof(NZ_WKS));
195 #endif
196     if (nz_wks == NULL) return -1;
197   }
198
199   nz_wks[nz_wks_count].nz_wks = NZWksID;
200   nz_wks[nz_wks_count].triedron_on = 0;
201   nz_wks[nz_wks_count].nz_struc = NULL;
202   nz_wks[nz_wks_count].nz_struc_size = 0;
203   nz_wks[nz_wks_count].nz_struc_count = 0;
204
205   return nz_wks_count++;
206 }
207
208 /*-----------------------------------------------------------------*/
209 /*
210 * recherche de la structure non zoomable NZStrucID dans la liste
211 * de la wks NZWksIdx ;
212 * creation de l'element structure non zoomable s'il n'existe pas.
213 */
214 static int find_nz_struc(int NZWksIdx, int NZStrucID, int alloc)
215 {
216   int i;
217   NZ_STRUC_DATA *nz_struc;
218
219
220   /* recherche la structure non zoomable dans la liste de la wks */
221   nz_struc = nz_wks[NZWksIdx].nz_struc;
222   for (i=0; i<nz_wks[NZWksIdx].nz_struc_count; i++)
223     if (nz_struc[i].NZStrucID == NZStrucID)
224       return i;
225
226   if (!alloc) return -1;
227
228   /* la structure non zoomable n'existe pas => on la cree */
229   if (nz_wks[NZWksIdx].nz_struc_count == nz_wks[NZWksIdx].nz_struc_size) {
230 #ifdef BUC60851
231     if( nz_wks[NZWksIdx].nz_struc_size > 0 ) {
232       nz_wks[NZWksIdx].nz_struc_size += GROW_SIZE_NZ_STRUC;
233       nz_wks[NZWksIdx].nz_struc = 
234         (NZ_STRUC_DATA *)  realloc(nz_wks[NZWksIdx].nz_struc, 
235         nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
236     } else {
237       nz_wks[NZWksIdx].nz_struc_size = GROW_SIZE_NZ_STRUC;
238       nz_wks[NZWksIdx].nz_struc = 
239         (NZ_STRUC_DATA *)  malloc( nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
240     }
241 #else
242     nz_wks[NZWksIdx].nz_struc_size += GROW_SIZE_NZ_STRUC;
243     nz_wks[NZWksIdx].nz_struc = (NZ_STRUC_DATA *)  realloc(nz_wks[NZWksIdx].nz_struc, nz_wks[NZWksIdx].nz_struc_size * sizeof(NZ_STRUC_DATA));
244 #endif
245     if (nz_wks[NZWksIdx].nz_struc == NULL) return -1;
246
247     nz_wks[NZWksIdx].nz_struc[nz_wks[NZWksIdx].nz_struc_count].aZBufParam = NULL;
248   }
249
250   return nz_wks[NZWksIdx].nz_struc_count++;
251 }
252
253
254 /*----------------------------------------------------------------------*/
255
256 /*
257 * affichage d'un triedre non zoomable a partir des index dans les tables
258 * des structures non zoomables.
259 *
260 * Triedre = Objet non Zoomable :
261 * on recalcule ses dimensions et son origine en fonction de la taille
262 * de la fenetre; on positionne selon le choix de l'init;
263 * et on inhibe seulement les translations.
264 *
265 */
266
267
268
269
270 TStatus call_triedron_redraw (
271                               int      nz_wks_entry,
272                               int      nz_struc_entry,
273                               GLdouble U,
274                               GLdouble V
275                               )
276 {
277   GLdouble modelMatrix[4][4];
278   GLdouble projMatrix[4][4];
279
280   GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
281   GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
282   GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
283   GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
284   GLfloat TriedronColor[3] = { 1.0, 1.0, 1.0 }; /* def = blanc */
285
286   GLfloat TriedronWidth = 1.0;
287   GLfloat TriedronScale = (float)0.1 ;
288   GLint   TriedronPosition = 0; /* def = Aspect_TOTP_CENTER */
289
290   GLdouble L, l, rayon ;
291   GLdouble minUV;
292   int      ii;
293 #ifdef PRINT_MATRIX 
294   int      jj;
295 #endif
296   int      NbFacettes;
297   double   Angle;
298   GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
299
300   GLuint fontBase = 0;
301   GLint mode;
302
303 #ifdef QTOCC_PATCH /* PCD 10/02/08 */
304   /* Fix to problem with clipping planes chopping off pieces of the triedron */
305   GLint max_plane=0;
306   GLboolean* isPlaneActive;
307   glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
308   isPlaneActive= new GLboolean[max_plane];
309   /* Backup the clip planes.         */
310   for (ii = 0; ii < max_plane ; ii++) {
311     isPlaneActive[ii] = glIsEnabled(GL_CLIP_PLANE0 + ii);
312     glDisable(GL_CLIP_PLANE0 + ii);
313   }
314 #endif
315
316   /* 
317   * Lecture des Init. du Triedre 
318   */
319
320   TriedronColor[0] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0];
321   TriedronColor[1] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1];
322   TriedronColor[2] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2];
323   TriedronScale = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale;
324   TriedronPosition = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos;
325
326
327   /* 
328   * Calcul des axes => on inhibe le zoom.
329   */
330
331   /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
332   /* de la dimension la plus petite de la window.                    */ 
333   if ( U < V )  minUV = U;
334   else minUV = V;
335   L = minUV * (double) TriedronScale ;
336
337   /* Position de l'origine */
338   TriedronOrigin[0]= 0.0; 
339   TriedronOrigin[1]= 0.0;
340   TriedronOrigin[2]= 0.0; 
341
342   /* Position des Axes */
343   TriedronAxeX[0] = TriedronOrigin[0] + L ;
344   TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
345   TriedronAxeX[2] = TriedronOrigin[2] + 0.0;
346
347   TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
348   TriedronAxeY[1] = TriedronOrigin[1] + L ;
349   TriedronAxeY[2] = TriedronOrigin[2] + 0.0;
350
351   TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
352   TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
353   TriedronAxeZ[2] = TriedronOrigin[2] + L ;
354
355   /*
356   * On inhibe les translations; on conserve les autres transformations.
357   */
358
359   /* on lit les matrices de transformation et de projection de la vue */
360   /* pour annuler les translations (dernieres colonnes des matrices). */
361   glGetDoublev( GL_MODELVIEW_MATRIX,  (GLdouble *) modelMatrix );
362   glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
363
364 #ifdef PRINT_MATRIX 
365   printf ("\n--- call_triedron_redraw : avant transfo projMatrix= ");
366   for (ii = 0; ii<4 ; ii++) {
367     printf ("\n ");
368     for (jj = 0; jj<4 ; jj++) {
369       printf ("  %f  ", projMatrix[ii][jj] );
370     }
371   }
372   printf ("\n--- call_triedron_redraw : avant transfo  modelMatrix= ");
373   for (ii = 0; ii<4 ; ii++) {
374     printf ("\n ");
375     for (jj = 0; jj<4 ; jj++) {
376       printf ("  %f  ", modelMatrix[ii][jj] );
377     }
378   }
379 #endif
380
381
382   /* on annule la translation qui peut etre affectee a la vue */
383   modelMatrix[3][0] = 0. ;
384   modelMatrix[3][1] = 0. ;
385   modelMatrix[3][2] = 0. ; 
386   projMatrix[3][0] = 0. ;
387   projMatrix[3][1] = 0. ;
388   projMatrix[3][2] = 0. ; 
389
390
391   /* sauvegarde du contexte des matrices avant chargement */
392   glMatrixMode (GL_MODELVIEW);
393   glPushMatrix ();
394   glLoadIdentity ();
395   glLoadMatrixd( (GLdouble *) modelMatrix);
396   glMatrixMode ( GL_PROJECTION );
397   glPushMatrix ();
398   glLoadIdentity();
399   glLoadMatrixd( (GLdouble *) projMatrix);
400
401
402 #ifdef PRINT_MATRIX 
403   printf ("\n\n\n--- call_triedron_redraw :  APRES transfo projMatrix= ");
404   for (ii = 0; ii<4 ; ii++) {
405     printf ("\n ");
406     for (jj = 0; jj<4 ; jj++) {
407       printf ("  %f  ", projMatrix[ii][jj] );
408     }
409   }
410   printf ("\n--- call_triedron_redraw : APRES transfo  modelMatrix= ");
411   for (ii = 0; ii<4 ; ii++) {
412     printf ("\n ");
413     for (jj = 0; jj<4 ; jj++) {
414       printf ("  %f  ", modelMatrix[ii][jj] );
415     }
416   }
417 #endif
418
419
420   /*
421   * Positionnement de l'origine du triedre selon le choix de l'init
422   */
423
424   /* on fait uniquement une translation de l'origine du Triedre */
425
426   switch (TriedronPosition) {
427
428        case 0 : /* Aspect_TOTP_CENTER */
429          break;
430
431        case 1 : /* Aspect_TOTP_LEFT_LOWER */
432          glTranslated( -U/2. + L , -V/2. + L , 0. );
433          break;
434
435        case 2  : /*Aspect_TOTP_LEFT_UPPER */
436          glTranslated( -U/2. + L , +V/2. - L -L/3. , 0. );
437          break;
438
439        case 3 : /* Aspect_TOTP_RIGHT_LOWER */
440          glTranslated( U/2. - L -L/3. , -V/2. + L , 0. );
441          break;
442
443        case 4  : /* Aspect_TOTP_RIGHT_UPPER */
444          glTranslated( U/2. - L -L/3. , +V/2. - L -L/3. , 0. );
445          break;
446
447        default :
448          break;
449
450   }
451
452 #ifdef PRINT 
453   printf ("\n--- call_triedron_redraw :  TriedronOrigin= %f %f %f\n",
454     TriedronOrigin[0], TriedronOrigin[1], TriedronOrigin[2]);
455   printf ("\n---                      :  TriedronAxeX= %f %f %f \n",
456     TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
457   printf ("\n---                      :  TriedronAxeY= %f %f %f \n",
458     TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2] );
459   printf ("\n---                      :  TriedronAxeZ= %f %f %f \n",
460     TriedronAxeZ[0], TriedronAxeZ[1], TriedronAxeZ[2]);
461   printf ("\n---                      : TriedronScale= %f \n",TriedronScale);
462   printf ("\n---                      : 1/echelle = ( %f %f %f %f ) \n",
463     modelMatrix[0][0],modelMatrix[1][1],modelMatrix[2][2],modelMatrix[3][3]);
464 #endif
465
466
467   /* 
468   * Creation du triedre 
469   */
470   glColor3fv (TriedronColor);
471
472   glGetIntegerv( GL_RENDER_MODE, &mode );
473
474 #ifdef HAVE_GL2PS
475   if( mode==GL_RENDER )
476     glLineWidth( TriedronWidth );
477   else if( mode==GL_FEEDBACK )
478     gl2psLineWidth( TriedronWidth );
479 #else
480         glLineWidth( TriedronWidth );
481 #endif 
482
483 #ifdef QTOCC_PATCH /* Fotis Sioutis 2007-11-14 15:06 
484   I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode 
485   changes colors depending on the state of the view. This behaviour can be easily 
486   corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl.
487   The only change needed is to erase the LightOff() function that is called before the 
488   Axis name drawing and move this function call just before the initial axis drawing.
489   Below is the code portion with the modification.I don't know if this is considered to 
490   be a bug but anyway i believe it might help some of you out there.*/
491   LightOff();
492 #endif
493
494   /* dessin des axes */
495   glBegin(GL_LINES);
496   glVertex3dv( TriedronOrigin );
497   glVertex3dv( TriedronAxeX );
498
499   glVertex3dv( TriedronOrigin );
500   glVertex3dv( TriedronAxeY );
501
502   glVertex3dv( TriedronOrigin );
503   glVertex3dv( TriedronAxeZ );
504   glEnd();
505
506
507   /* fleches au bout des axes (= cones de la couleur demandee) */
508   l = L - L/4. ; /* distance a l'origine */
509   rayon = L/30. ; /* rayon de la base du cone */
510   NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */
511   Angle = 2. * M_PI/ NbFacettes;
512
513   /* solution FILAIRE des cones au bout des axes : une seule ligne */
514   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
515   /* (la couleur est deja initialisee dans TriedronColor) */
516   /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */
517
518   /* fleche en X */
519   glBegin(GL_TRIANGLE_FAN);
520   glVertex3dv( TriedronAxeX );
521   TriedronCoord[0] = TriedronOrigin[0] + l ;
522   ii = NbFacettes;
523   while (ii >= 0 ) {
524     TriedronCoord[1] = TriedronOrigin[1] + ( rayon * sin(ii * Angle) );
525     TriedronCoord[2] = TriedronOrigin[2] + ( rayon * cos(ii * Angle) );
526     glVertex3dv( TriedronCoord );
527     ii--;
528   }
529   glEnd();
530
531   /* fleche en Y */
532   glBegin(GL_TRIANGLE_FAN);
533   glVertex3dv( TriedronAxeY );
534   TriedronCoord[1] = TriedronOrigin[1] + l ;
535   ii = NbFacettes;
536   while (ii >= 0 ) {
537     TriedronCoord[0] = TriedronOrigin[0] + (rayon * cos(ii * Angle) );
538     TriedronCoord[2] = TriedronOrigin[2] + (rayon * sin(ii * Angle) );
539     glVertex3dv( TriedronCoord );
540     ii--;
541   }
542   glEnd();
543
544   /* fleche en Z */
545   glBegin(GL_TRIANGLE_FAN);
546   glVertex3dv( TriedronAxeZ );
547   TriedronCoord[2] = TriedronOrigin[2] + l ;
548   ii = NbFacettes;
549   while (ii >= 0 ) {
550     TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
551     TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
552     glVertex3dv( TriedronCoord );
553     ii--;
554   }
555   glEnd();
556
557   /* dessin de l'origine */
558   TriedronCoord[0] = TriedronOrigin[0] + rayon ;
559   TriedronCoord[1] = TriedronOrigin[1] + 0.0 ;
560   TriedronCoord[2] = TriedronOrigin[2] + 0.0 ;
561   ii = 24 ;
562   Angle = 2. * M_PI/ii ;
563   glBegin(GL_LINE_LOOP);
564   while (ii >= 0 ) {
565     TriedronCoord[0] = TriedronOrigin[0] + ( rayon * sin(ii * Angle) );
566     TriedronCoord[1] = TriedronOrigin[1] + ( rayon * cos(ii * Angle) );
567     glVertex3dv( TriedronCoord );
568     ii--;
569   }  
570   glEnd();
571
572   LightOff();
573
574   /* 
575   * Noms des axes et de l'origine
576   */
577
578   /* init de la fonte */
579
580   OpenGl_TextRender* textRender=OpenGl_TextRender::instance();
581
582   /* Axe X */
583   TriedronCoord[0] = TriedronOrigin[0] + ( L + rayon ) ;
584   TriedronCoord[1] = TriedronOrigin[1] + 0.0;
585   TriedronCoord[2] = TriedronOrigin[2] - rayon ;
586   textRender->RenderText(L"X", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2] );
587
588   /* Axe Y */
589   TriedronCoord[0] = TriedronOrigin[0] + rayon ;
590   TriedronCoord[1] = TriedronOrigin[1] + ( L + 3.0 * rayon ) ;
591   TriedronCoord[2] = TriedronOrigin[2] + ( 2.0 * rayon );
592   textRender->RenderText(L"Y", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);
593
594   /* Axe Z */
595   TriedronCoord[0] = TriedronOrigin[0] + ( - 2.0 * rayon ) ;
596   TriedronCoord[1] = TriedronOrigin[1] +  rayon/2. ;
597   TriedronCoord[2] = TriedronOrigin[2] + ( L + 3.0 * rayon ) ;
598   textRender->RenderText(L"Z", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);
599
600 #ifdef QTOCC_PATCH /* PCD 10/02/08 */
601   /* Recover the clip planes */
602   glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
603   for (ii = 0; ii <max_plane ; ii++) {
604     if (isPlaneActive[ii]) { 
605       glEnable(GL_CLIP_PLANE0 + ii);
606     }
607   } 
608   free(isPlaneActive);
609
610 #endif
611
612   /* 
613   * restauration du contexte des matrices
614   */
615   glMatrixMode (GL_PROJECTION);
616   glPopMatrix ();
617   glMatrixMode (GL_MODELVIEW);
618   glPopMatrix ();
619
620
621   return (TSuccess);
622
623 }
624
625
626
627
628 /*******************************************************
629 *  Draws ZBUFFER trihedron mode
630 *******************************************************/
631 TStatus call_zbuffer_triedron_redraw (
632                                       int      nz_wks_entry,
633                                       int      nz_struc_entry,
634                                       GLdouble U,
635                                       GLdouble V
636                                       )
637 {
638   GLdouble modelMatrix[4][4];
639   GLdouble projMatrix[4][4];
640
641   GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
642   GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
643   GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
644   GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
645   GLfloat TriedronColor[3] = { 1.0, 1.0, 1.0 }; /* def = blanc */
646
647   GLfloat TriedronScale = (float)0.1 ;
648   GLint   TriedronPosition = 0; /* def = Aspect_TOTP_CENTER */
649
650   GLdouble L, l, rayon ;
651   GLdouble minUV;
652   int      NbFacettes = 12;
653   double   Angle;
654   GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
655
656   GLuint fontBase = 0;
657
658   GLuint startList;
659   GLUquadricObj* aQuadric;
660   GLfloat aXColor[] = { 1.0, 0.0, 0.0, 0.6f };
661   GLfloat aYColor[] = { 0.0, 1.0, 0.0, 0.6f };
662   GLfloat aZColor[] = { 0.0, 0.0, 1.0, 0.6f };
663   GLdouble aConeDiametr;
664   GLdouble aConeLength;
665   GLdouble aCylinderDiametr;
666   GLdouble aCylinderLength;
667   GLboolean aIsDepthEnabled;
668 #ifndef BUG
669   GLboolean aIsDepthMaskEnabled;
670 #endif
671   GLint   aViewPort[4];  /* to store view port coordinates */
672   GLdouble aWinCoord[3];
673   GLboolean isWithinView;
674   GLdouble aLengthReduce = 0.8;
675   GLdouble aAxisDiametr = 0.05;
676   ZBUF_STRUCT* aParam;
677
678 #ifdef QTOCC_PATCH 
679   GLint df;                                       /* PCD 17/06/07 */      
680   GLfloat aNULLColor[] = { 0.0, 0.0, 0.0, 0.0f }; /* FS 21/01/08 */
681   /* Fix to problem with clipping planes chopping off pieces of the triedron   */
682   int i;
683   GLint max_plane=0;
684   GLboolean* isPlaneActive;
685   glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
686   isPlaneActive = new GLboolean[max_plane];
687   /* Backup the clip planes. */
688   for (i = 0; i < max_plane ; i++) {
689     isPlaneActive[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
690     glDisable(GL_CLIP_PLANE0 + i);
691   }
692 #endif
693
694   /* 
695   * Lecture des Init. du Triedre 
696   */
697
698   TriedronColor[0] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0];
699   TriedronColor[1] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1];
700   TriedronColor[2] = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2];
701   TriedronScale = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale;
702   TriedronPosition = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos;
703
704   if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam != NULL) {
705     aParam = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam;
706     aXColor[0] = aParam->aXColor[0];
707     aXColor[1] = aParam->aXColor[1];
708     aXColor[2] = aParam->aXColor[2];
709
710     aYColor[0] = aParam->aYColor[0];
711     aYColor[1] = aParam->aYColor[1];
712     aYColor[2] = aParam->aYColor[2];
713
714     aZColor[0] = aParam->aZColor[0];
715     aZColor[1] = aParam->aZColor[1];
716     aZColor[2] = aParam->aZColor[2];
717
718     aLengthReduce = aParam->aRatio;
719     aAxisDiametr = aParam->aDiametr;
720     NbFacettes = aParam->aNbFacettes;
721   }
722
723   /* 
724   * Calcul des axes => on inhibe le zoom.
725   */
726
727   /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
728   /* de la dimension la plus petite de la window.                    */ 
729   if ( U < V )  minUV = U;
730   else minUV = V;
731   L = minUV * (double) TriedronScale ;
732
733   /* Position de l'origine */
734   TriedronOrigin[0]= 0.0; 
735   TriedronOrigin[1]= 0.0;
736   TriedronOrigin[2]= 0.0; 
737
738   /* Position des Axes */
739   TriedronAxeX[0] = TriedronOrigin[0] + L ;
740   TriedronAxeX[1] = TriedronOrigin[1] + 0.0;
741   TriedronAxeX[2] = TriedronOrigin[2] + 0.0;
742
743   TriedronAxeY[0] = TriedronOrigin[0] + 0.0;
744   TriedronAxeY[1] = TriedronOrigin[1] + L ;
745   TriedronAxeY[2] = TriedronOrigin[2] + 0.0;
746
747   TriedronAxeZ[0] = TriedronOrigin[0] + 0.0;
748   TriedronAxeZ[1] = TriedronOrigin[1] + 0.0;
749   TriedronAxeZ[2] = TriedronOrigin[2] + L ;
750
751   /* Check position in the ViewPort */
752   glGetDoublev( GL_MODELVIEW_MATRIX,  (GLdouble *) modelMatrix );
753   glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
754
755   glGetIntegerv(GL_VIEWPORT, aViewPort);
756   gluProject(TriedronOrigin[0], TriedronOrigin[1], TriedronOrigin[2],
757     (GLdouble *)modelMatrix, (GLdouble *)projMatrix, aViewPort,
758     &aWinCoord[0], &aWinCoord[1], &aWinCoord[2]);
759
760 #ifdef QTOCC_PATCH /* PCD 29/09/2008 */
761   /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey  */
762   /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER   */
763   /* which causes the glyph to jump around the screen when the origin moves offscreen. */
764   isWithinView = GL_FALSE;
765 #else
766   /* Original code */
767   isWithinView = !((aWinCoord[0]<aViewPort[0]) || (aWinCoord[0]>aViewPort[2]) ||
768     (aWinCoord[1]<aViewPort[1]) || (aWinCoord[1]>aViewPort[3]));
769 #endif
770
771   if (!isWithinView) {
772     /* Annulate translation matrix */
773     modelMatrix[3][0] = 0. ;
774     modelMatrix[3][1] = 0. ;
775     modelMatrix[3][2] = 0. ; 
776     projMatrix[3][0] = 0. ;
777     projMatrix[3][1] = 0. ;
778     projMatrix[3][2] = 0. ; 
779
780     /* save matrix */
781     glMatrixMode (GL_MODELVIEW);
782     glPushMatrix ();
783     glLoadIdentity ();
784     glLoadMatrixd( (GLdouble *) modelMatrix);
785     glMatrixMode ( GL_PROJECTION );
786     glPushMatrix ();
787     glLoadIdentity();
788     glLoadMatrixd( (GLdouble *) projMatrix);
789
790
791     /*
792     * Define position in the view
793     */
794     switch (TriedronPosition) {
795       case 0 :  /* Aspect_TOTP_CENTER */
796         break;
797
798       case 1 :  /* Aspect_TOTP_LEFT_LOWER */
799         glTranslated( -U/2. + L , -V/2. + L , 0. );
800         break;
801
802       case 2  : /* Aspect_TOTP_LEFT_UPPER */
803         glTranslated( -U/2. + L , +V/2. - L -L/3. , 0. );
804         break;
805
806       case 3 :  /* Aspect_TOTP_RIGHT_LOWER */
807         glTranslated( U/2. - L -L/3. , -V/2. + L , 0. );
808         break;
809
810       case 4  :  /* Aspect_TOTP_RIGHT_UPPER */
811         glTranslated( U/2. - L -L/3. , +V/2. - L -L/3. , 0. );
812         break;
813
814       default :
815         break;
816
817     }
818     L *= aLengthReduce;
819   }
820
821
822   /* 
823   * Creation the trihedron
824   */
825
826 #define COLOR_REDUCE      0.3f
827 #define CYLINDER_LENGTH   0.75f
828 #ifdef BUG
829 #define ALPHA_REDUCE      0.4f
830 #else
831 #define ALPHA_REDUCE      1.0f
832 #endif
833
834   startList = glGenLists(4);
835   aQuadric = gluNewQuadric();
836
837   aCylinderLength = L * CYLINDER_LENGTH;
838   aCylinderDiametr = L * aAxisDiametr;
839   aConeDiametr = aCylinderDiametr * 2;
840   aConeLength = L * (1 - CYLINDER_LENGTH);
841   /* Correct for owerlapping */
842   /*    aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/
843
844   aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST);
845 #ifndef BUG
846
847 #ifdef QTOCC_PATCH  /*PCD 02/07/07   */
848   /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the  */
849   /* original code is shown to be broken when run under an OpenGL debugger  */
850   /* like GLIntercept. This is the correct way to retrieve the mask value.  */
851   glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled); 
852 #else
853   aIsDepthMaskEnabled = glIsEnabled(GL_DEPTH_WRITEMASK);
854 #endif
855
856 #endif 
857
858   /* Create cylinder for axis */
859   gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */
860   gluQuadricNormals(aQuadric, GLU_FLAT);
861   /* Axis */
862   glNewList(startList, GL_COMPILE);
863   gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, NbFacettes, 1);
864   glEndList();
865   /* Cone */
866   glNewList(startList + 1, GL_COMPILE);
867   gluCylinder(aQuadric, aConeDiametr, 0, aConeLength, NbFacettes, 1);
868   glEndList();
869   /* Central sphere */
870   glNewList(startList + 2, GL_COMPILE);
871 #ifdef QTOCC_PATCH
872   gluSphere(aQuadric, aCylinderDiametr * 2, NbFacettes, NbFacettes);
873 #else
874   gluSphere(aQuadric, aCylinderDiametr, NbFacettes, NbFacettes);
875 #endif
876   glEndList();
877   /* End disk */
878   gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/
879   glNewList(startList + 3, GL_COMPILE);
880   gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, NbFacettes, 1/*szv:2*/);
881   glEndList();
882
883 #ifdef QTOCC_PATCH
884   /* Store previous attributes */
885   glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
886   LightOn();
887 #else
888   LightOn();
889
890   /* Store previous attributes */
891   glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
892 #endif
893
894   glCullFace(GL_BACK);
895   glEnable(GL_CULL_FACE);
896
897 #ifdef QTOCC_PATCH /*Fotis Sioutis | 2008-01-21 10:55 
898   In the function call_zbuffer_triedron_redraw of TKOpengl, 
899   the z buffered trihedron changes colors in case there 
900   is an object in the scene that has an explicit material 
901   attached to it.In the trihedron display loop, 
902   GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE 
903   parameter is utilized in glColorMaterial(...).
904   This causes the last ambient,specular and emission values 
905   used, to stay at the stack and applied to the trihedron
906   (which causes the color change).
907   A fix is proposed , to change GL_DIFFUSE to 
908   GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in 
909   line 946.The above of course will leave unchanged 
910   the SPECULAR and EMISSION values.
911   Another proposal which would fix 100% the problem 
912   is to use glMaterial instead of glColor on the trihedron 
913   drawing loop.               */
914   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor);
915   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor);
916   glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor);
917
918   glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.);
919 #endif
920
921   glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
922   glEnable(GL_COLOR_MATERIAL);
923
924   if (!aIsDepthEnabled)  {
925     glEnable(GL_DEPTH_TEST);
926 #ifndef BUG
927     glClear(GL_DEPTH_BUFFER_BIT);
928 #endif
929   }
930 #ifdef BUG
931   if (!(aIsDepthEnabled && isWithinView))
932     glClear(GL_DEPTH_BUFFER_BIT);
933 #endif
934 #ifndef BUG
935   if (!aIsDepthMaskEnabled)  {
936     /* This is how the depthmask needs to be re-enabled...*/
937     glDepthMask(GL_TRUE);
938     /* ...and not this stuff below */
939   }
940 #endif
941
942   glMatrixMode(GL_MODELVIEW);
943 #ifdef QTOCC_PATCH /* PCD 17/06/07  */
944   glGetIntegerv (GL_DEPTH_FUNC, &df); 
945 #else
946   /*szv:if (isWithinView) {*/
947   glDepthFunc(GL_GREATER);
948   glPushMatrix();
949   glPushMatrix();
950   glPushMatrix();
951
952   glColor4f(TriedronColor[0]*COLOR_REDUCE, 
953     TriedronColor[1]*COLOR_REDUCE, 
954     TriedronColor[2]*COLOR_REDUCE,
955     ALPHA_REDUCE);
956   glCallList(startList+2);
957
958   /* Z axis */
959   glColor4f(aZColor[0]*COLOR_REDUCE, 
960     aZColor[1]*COLOR_REDUCE, 
961     aZColor[2]*COLOR_REDUCE,
962     ALPHA_REDUCE);
963   glCallList(startList);
964   glTranslated(0, 0, L * CYLINDER_LENGTH);
965   glCallList(startList + 3);
966   glCallList(startList + 1);
967   glPopMatrix();    
968
969   /* X axis */
970   glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
971   glColor4f(aXColor[0]*COLOR_REDUCE, 
972     aXColor[1]*COLOR_REDUCE, 
973     aXColor[2]*COLOR_REDUCE,
974     ALPHA_REDUCE);
975   glCallList(startList);
976   glTranslated(0, 0, L * CYLINDER_LENGTH);
977   glCallList(startList + 3);
978   glCallList(startList + 1);
979   glPopMatrix();    
980
981   /* Y axis */
982   glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
983   glColor4f(aYColor[0]*COLOR_REDUCE, 
984     aYColor[1]*COLOR_REDUCE, 
985     aYColor[2]*COLOR_REDUCE,
986     ALPHA_REDUCE);
987   glCallList(startList);
988   glTranslated(0, 0, L * CYLINDER_LENGTH);
989   glCallList(startList + 3);
990   glCallList(startList + 1);
991   glPopMatrix();
992
993   glDepthFunc(GL_LESS);
994   /*szv:}*/
995 #endif
996
997 #ifdef QTOCC_PATCH
998   for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */
999   {
1000     if (i == 0) /*  First pass  */
1001     {                          
1002       glDepthFunc(GL_ALWAYS); 
1003     }
1004     else
1005     {
1006       glDepthFunc(GL_LEQUAL); 
1007     }
1008 #endif
1009
1010     glPushMatrix();
1011     glPushMatrix();
1012     glPushMatrix();
1013
1014     glColor3fv(TriedronColor);
1015     glCallList(startList+2);
1016
1017     /* Z axis */
1018     glColor4fv(aZColor);
1019     glCallList(startList);
1020     glTranslated(0, 0, L * CYLINDER_LENGTH);
1021     glCallList(startList + 3);
1022     glCallList(startList + 1);
1023     glPopMatrix();    
1024
1025     /* X axis */
1026     glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
1027     glColor4fv(aXColor);
1028     glCallList(startList);
1029     glTranslated(0, 0, L * CYLINDER_LENGTH);
1030     glCallList(startList + 3);
1031     glCallList(startList + 1);
1032     glPopMatrix();    
1033
1034     /* Y axis */
1035     glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
1036     glColor4fv(aYColor);
1037     glCallList(startList);
1038     glTranslated(0, 0, L * CYLINDER_LENGTH);
1039     glCallList(startList + 3);
1040     glCallList(startList + 1);
1041     glPopMatrix();
1042
1043 #ifdef QTOCC_PATCH
1044   }
1045 #endif
1046
1047   if (!aIsDepthEnabled) 
1048     glDisable(GL_DEPTH_TEST);
1049 #ifndef BUG
1050   if (!aIsDepthMaskEnabled)
1051
1052 #ifdef QTOCC_PATCH /*PCD 02/07/07   */
1053     glDepthMask(GL_FALSE);
1054 #else
1055     glDisable(GL_DEPTH_WRITEMASK);
1056 #endif
1057
1058 #endif
1059   glDisable(GL_CULL_FACE);
1060   glDisable(GL_COLOR_MATERIAL);
1061
1062   gluDeleteQuadric(aQuadric);
1063   glColor3fv (TriedronColor);
1064
1065 #ifdef QTOCC_PATCH /* PCD 11/02/08 */
1066   /* Always write the text */
1067   glDepthFunc(GL_ALWAYS); 
1068 #endif
1069
1070   glPopAttrib();
1071
1072   /* fleches au bout des axes (= cones de la couleur demandee) */
1073   l = L - L/4. ; /* distance a l'origine */
1074   rayon = L/30. ; /* rayon de la base du cone */
1075   Angle = 2. * M_PI/ NbFacettes;
1076
1077   glDeleteLists(startList, 4); 
1078
1079   LightOff();
1080
1081   /* 
1082   * origine names
1083   */
1084
1085   /* init font */
1086
1087   OpenGl_TextRender* textRender=OpenGl_TextRender::instance();
1088
1089   /* Axe X */
1090   TriedronCoord[0] = TriedronOrigin[0] + ( L + rayon ) ;
1091   TriedronCoord[1] = TriedronOrigin[1] + 0.0;
1092   TriedronCoord[2] = TriedronOrigin[2] - rayon ;
1093   textRender->RenderText(L"X", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);
1094
1095   /* Axe Y */
1096   TriedronCoord[0] = TriedronOrigin[0] + rayon ;
1097   TriedronCoord[1] = TriedronOrigin[1] + ( L + 3.0 * rayon ) ;
1098   TriedronCoord[2] = TriedronOrigin[2] + ( 2.0 * rayon );
1099   textRender->RenderText(L"Y", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);
1100
1101   /* Axe Z */
1102   TriedronCoord[0] = TriedronOrigin[0] + ( - 2.0 * rayon ) ;
1103   TriedronCoord[1] = TriedronOrigin[1] +  rayon/2. ;
1104   TriedronCoord[2] = TriedronOrigin[2] + ( L + 3.0 * rayon ) ;
1105   textRender->RenderText(L"Z", fontBase, 0, (float)TriedronCoord[0], (float)TriedronCoord[1], (float)TriedronCoord[2]);
1106
1107 #ifdef QTOCC_PATCH 
1108   /*PCD 17/06/07    */
1109   glDepthFunc(df);
1110
1111   /* PCD 10/02/08  */
1112   /* Recover the clip planes */ 
1113   glGetIntegerv( GL_MAX_CLIP_PLANES, &max_plane);
1114   for (i = 0; i < max_plane ; i++) {
1115     if (isPlaneActive[i]) { 
1116       glEnable(GL_CLIP_PLANE0 + i);
1117     }
1118   }
1119   free(isPlaneActive);
1120 #endif
1121
1122   if (!isWithinView) { /* restore matrix */
1123     glMatrixMode (GL_PROJECTION);
1124     glPopMatrix ();
1125     glMatrixMode (GL_MODELVIEW);
1126     glPopMatrix ();
1127   }
1128
1129   return (TSuccess);
1130
1131 }
1132
1133
1134 /*----------------------------------------------------------------------*/
1135
1136 /*----------------------------------------------------------------------*/
1137 /*
1138 * Fonctions publiques 
1139 */
1140
1141
1142 /*
1143 * initialisation d'un triedre non zoomable dans une vue.
1144 * ou modification des valeurs deja initialisees.
1145 */
1146
1147 TStatus call_triedron_init (
1148                             CALL_DEF_VIEW * aview, 
1149                             int aPosition, 
1150                             float r,
1151                             float g,
1152                             float b, 
1153                             float aScale,
1154                             int asWireframe 
1155                             )
1156
1157 {
1158
1159   int nz_wks_entry;
1160   int nz_struc_entry;
1161   ZBUF_STRUCT* aParam;
1162
1163
1164 #ifdef PRINT
1165   printf("\n----------- call_triedron_init  r = %f, g = %f, b = %f",
1166     r, g, b);
1167   printf(", aScale = %f, aPosition = %d \n", aScale, aPosition );
1168 #endif
1169
1170   if (aview->WsId == -1) return(TFailure);
1171   if (aview->ViewId == -1) return(TFailure);
1172 #ifdef PRINT
1173   printf(", aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
1174 #endif
1175
1176
1177
1178   /* recherche du num de la liste de structures non zoomables de la wks */
1179   /* creation sinon */
1180   nz_wks_entry = find_nz_wks(aview->WsId, 1);
1181   if (nz_wks_entry == -1) return TFailure;
1182
1183   /* recherche du Triedre s'il existe; creation sinon */
1184   nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 1);
1185   if (nz_struc_entry == -1) return TFailure;
1186
1187   /* mise a jour du Triedre */
1188   nz_wks[nz_wks_entry].triedron_on = 1;
1189   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].NZStrucID = TRIEDRON_ID;
1190   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].astructure = NULL;
1191   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aPos = aPosition;
1192   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[0] = r;
1193   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[1] = g;
1194   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aColor[2] = b;
1195   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aScale = aScale;
1196   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].isWireframe = asWireframe;
1197
1198   nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam = new ZBUF_STRUCT();
1199   if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam == NULL) return TFailure;
1200
1201   aParam = nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].aZBufParam;
1202   aParam->aXColor[0] = theXColor[0];
1203   aParam->aXColor[1] = theXColor[1];
1204   aParam->aXColor[2] = theXColor[2];
1205
1206   aParam->aYColor[0] = theYColor[0];
1207   aParam->aYColor[1] = theYColor[1];
1208   aParam->aYColor[2] = theYColor[2];
1209
1210   aParam->aZColor[0] = theZColor[0];
1211   aParam->aZColor[1] = theZColor[1];
1212   aParam->aZColor[2] = theZColor[2];
1213
1214   aParam->aRatio = theRatio;
1215   aParam->aDiametr = theDiametr;
1216   aParam->aNbFacettes = theNBFacettes;
1217
1218
1219 #ifdef DEBUG
1220   printf("nz_wks_entry=%d nz_struc_entry=%d \n",nz_wks_entry,nz_struc_entry);
1221   printf("ajout ok\n");
1222 #endif
1223   return (TSuccess);
1224
1225 }
1226
1227 /*----------------------------------------------------------------------*/
1228
1229 /*
1230 * affichage d'un triedre non zoomable dans la wks  awsid 
1231 *
1232 * Triedre = Objet non Zoomable;
1233 * on cree cette fonction pour pouvoir travailler par les structures 
1234 * utilisees par les fonctions Tsm* et TEL_VIEW_REP
1235 *
1236 */
1237
1238 TStatus call_triedron_redraw_from_wsid (
1239                                         Tint awsid
1240                                         )
1241
1242 {
1243
1244   TStatus   status = TSuccess;
1245   int       nz_wks_entry;
1246   int       nz_struc_entry;
1247   int    save_texture_state;
1248   GLdouble  U, V ; /* largeur,hauteur de la fenetre */
1249
1250   CMN_KEY_DATA    key;
1251   tel_view_data   vptr;
1252
1253   if ( awsid == -1) return (TFailure );
1254
1255 #ifdef BUC61045
1256   /* check if GL_LIGHTING should be disabled
1257   no enabling 'cause it will be done (if necessary: kinda Polygon types ) 
1258   during redrawing structures 
1259   */
1260   TsmGetWSAttri (awsid, WSGLLight, &key );
1261   if ( key.ldata == TOff )
1262     glDisable( GL_LIGHTING );
1263 #endif
1264
1265   /* recherche du numero de la liste de structures non zoomables de la wks */
1266 #ifdef PRINT
1267   printf("\n----------- call_triedron_redraw_from_WSID : appel find_nz_wks \n");
1268 #endif
1269   nz_wks_entry = find_nz_wks(awsid, 0);
1270   /* si on ne l'a pas trouve, il n'y a rien a faire */
1271   if (nz_wks_entry == -1) return (TSuccess);
1272
1273   /* recherche du Triedre */
1274 #ifdef PRINT
1275   printf("\n----------- call_triedron_redraw_from_WSID : appel find_nz_struc \n");
1276 #endif
1277   nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 0);
1278   /* si on ne l'a pas trouve, il n'y a rien a faire */
1279   if (nz_struc_entry == -1) return (TSuccess);
1280   /* si il est "off" il n'y a rien a faire */
1281   if (nz_wks[nz_wks_entry].triedron_on == 0) return (TSuccess);
1282
1283
1284   /* recherche de la dimension de la fenetre                   */
1285   /* (car la taille des axes du treiedre en sera 1 proportion) */
1286   TsmGetWSAttri (awsid, WSViews, &key );
1287   vptr = (tel_view_data)key.pdata ; /* Obtain defined view data*/
1288   if ( !vptr ) return TFailure; /* no view defined yet */
1289   U = vptr->vrep.extra.map.window.xmax - vptr->vrep.extra.map.window.xmin;
1290   V = vptr->vrep.extra.map.window.ymax - vptr->vrep.extra.map.window.ymin;
1291
1292   /* sauvegarde du contexte (on reste dans le buffer courant) */
1293   save_texture_state = IsTextureEnabled();
1294   DisableTexture();
1295
1296   /* affichage du Triedre Non Zoomable */
1297   transform_persistence_end();
1298   if (nz_wks[nz_wks_entry].nz_struc[nz_struc_entry].isWireframe)
1299     status = call_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);
1300   else
1301     status = call_zbuffer_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);
1302
1303   /* restauration du contexte */
1304   if (save_texture_state) EnableTexture();
1305
1306   return status;
1307
1308 }
1309
1310 /*----------------------------------------------------------------------*/
1311
1312 /*
1313 * affichage d'un triedre non zoomable dans la vue aview 
1314 *
1315 * Triedre = Objet non Zoomable;
1316 * on cree cette fonction pour pouvoir utiliser CALL_DEF_VIEW
1317 *
1318 */
1319
1320 TStatus call_triedron_redraw_from_view (
1321                                         CALL_DEF_VIEW * aview
1322                                         )
1323 {
1324
1325   TStatus   status = TSuccess;
1326   int       nz_wks_entry;
1327   int       nz_struc_entry;
1328   int    save_texture_state;
1329   GLdouble  U, V ; /* largeur,hauteur de la fenetre */
1330
1331
1332
1333   if (aview->WsId == -1) return (TFailure );
1334   if (aview->ViewId == -1) return (TFailure);
1335 #ifdef PRINT
1336   printf("\n call_triedron_redraw_from_VIEW aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
1337 #endif
1338
1339
1340   /* recherche du numero de la liste de structures non zoomables de la wks */
1341 #ifdef PRINT
1342   printf("\n----------- call_triedron_redraw_from_VIEW : appel find_nz_wks \n");
1343 #endif
1344   nz_wks_entry = find_nz_wks(aview->WsId, 0);
1345   /* si on ne l'a pas trouve, il n'y a rien a faire */
1346   if (nz_wks_entry == -1) return (TSuccess);
1347
1348   /* recherche du Triedre */
1349 #ifdef PRINT
1350   printf("\n----------- call_triedron_redraw_from_VIEW : appel find_nz_struc \n");
1351 #endif
1352   nz_struc_entry = find_nz_struc(nz_wks_entry, TRIEDRON_ID, 0);
1353   /* si on ne l'a pas trouve, il n'y a rien a faire */
1354   if (nz_struc_entry == -1) return (TSuccess);
1355   /* si il est "off" il n'y a rien a faire */
1356   if (nz_wks[nz_wks_entry].triedron_on == 0) return (TSuccess);
1357
1358
1359   /* recherche de la dimension de la fenetre                   */
1360   /* (car la taille des axes du treiedre en sera 1 proportion) */
1361   U = aview->Mapping.WindowLimit.uM - aview->Mapping.WindowLimit.um ;
1362   V = aview->Mapping.WindowLimit.vM - aview->Mapping.WindowLimit.vm ;
1363
1364   /* sauvegarde du contexte et ecriture en front buffer */
1365   save_texture_state = IsTextureEnabled();
1366   DisableTexture();
1367   glDrawBuffer (GL_FRONT);
1368
1369   /* affichage du Triedre Non Zoomable */
1370   transform_persistence_end();
1371   status = call_triedron_redraw (nz_wks_entry, nz_struc_entry, U, V);
1372
1373   /* necessaire pour WNT */
1374   glFlush();
1375
1376   /* restauration du contexte */
1377   if (save_texture_state) EnableTexture();
1378   glDrawBuffer (GL_BACK); 
1379
1380   return status;
1381
1382 }
1383
1384 /*----------------------------------------------------------------------*/
1385
1386 /*
1387 * destruction du triedre non zoomable d'une vue.
1388 */
1389
1390 TStatus call_triedron_erase (
1391                              CALL_DEF_VIEW * aview
1392                              )
1393
1394 {
1395   int   nz_wks_entry;
1396   int i;
1397
1398
1399 #ifdef PRINT
1400   printf("\n----------- call_triedron_erase  " );
1401 #endif
1402
1403   if (aview->WsId == -1) return(TFailure);
1404   if (aview->ViewId == -1) return(TFailure);
1405 #ifdef PRINT
1406   printf(", aview->WsId=%d  aview->ViewId=%d \n",aview->WsId,aview->ViewId);
1407 #endif
1408
1409
1410   /* recherche du num de la liste de structures non zoomables de la wks */
1411   /* si on ne l'a pas trouve, il n'y a rien a faire                     */
1412   nz_wks_entry = find_nz_wks(aview->WsId, 0);
1413   if (nz_wks_entry == -1) return TSuccess;
1414
1415
1416   /* 
1417   * destruction du Triedre puis de toute la wks
1418   */
1419   /* (aujourd'hui il n'y a pas d'autre structure graphique dans la table */
1420   /* de la wks => on detruit tout ;                                      */
1421   /* si on ajoutait d'autres structures non zoomables, il faudrait       */
1422   /* selectionner et detruire uniquement l'element Triedre en cherchant  */
1423   /* s'il existe via une variable nz_struc_entry ).                      */
1424   for (i = 0; i < nz_wks[nz_wks_entry].nz_struc_count; i++) {
1425     if (nz_wks[nz_wks_entry].nz_struc[i].aZBufParam != NULL) 
1426       free(nz_wks[nz_wks_entry].nz_struc[i].aZBufParam);
1427   }
1428
1429   if (nz_wks[nz_wks_entry].nz_struc != NULL) {
1430     free(nz_wks[nz_wks_entry].nz_struc);
1431   }
1432
1433   if (nz_wks_count == 1) {
1434     free(nz_wks);
1435     nz_wks_count = 0;
1436     nz_wks_size = 0;
1437   }
1438   else { /* il y a au moins 2 wks definies */
1439     memcpy(&nz_wks[nz_wks_entry],
1440       &nz_wks[nz_wks_entry+1],
1441       (nz_wks_count - nz_wks_entry - 1)*sizeof(NZ_WKS));
1442     nz_wks_count--;
1443   }
1444
1445
1446 #ifdef DEBUG
1447   printf("nz_wks_entry=%d   nz_wks_count=%d   nz_wks_size=%d\n",
1448     nz_wks_entry,  nz_wks_count, nz_wks_size );
1449   printf("erase ok\n");
1450 #endif
1451
1452   return (TSuccess);
1453 }
1454
1455 /*----------------------------------------------------------------------*/
1456
1457
1458 /*
1459 * gestion d'un echo de designation du triedre non zoomable d' une vue.
1460 */
1461 TStatus call_triedron_echo (
1462                             CALL_DEF_VIEW * aview,
1463                             int aType
1464                             )
1465
1466 {
1467   return (TSuccess);
1468 }
1469
1470
1471 /*----------------------------------------------------------------------*/
1472
1473 /*
1474 * initialisation of zbuffer trihedron
1475 */
1476 extern TStatus  call_ztriedron_setup (
1477                                       float* xcolor,
1478                                       float* ycolor,
1479                                       float* zcolor,
1480                                       float  sizeratio,
1481                                       float  axisdiameter,
1482                                       int    nbfacettes)
1483 {
1484   theXColor[0] = xcolor[0];
1485   theXColor[1] = xcolor[1];
1486   theXColor[2] = xcolor[2];
1487
1488   theYColor[0] = ycolor[0];
1489   theYColor[1] = ycolor[1];
1490   theYColor[2] = ycolor[2];
1491
1492   theZColor[0] = zcolor[0];
1493   theZColor[1] = zcolor[1];
1494   theZColor[2] = zcolor[2];
1495
1496   theRatio = sizeratio;
1497   theDiametr = axisdiameter;
1498   theNBFacettes = nbfacettes;
1499
1500   return (TSuccess);
1501 }
1502