0024510: Remove unused local variables
[occt.git] / src / OpenGl / OpenGl_Trihedron.cxx
CommitLineData
b311480e 1// Created on: 2011-09-20
2// Created by: Sergey ZERCHANINOV
973c2be1 3// Copyright (c) 2011-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public version 2.1 as published
9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
b311480e 15
5f8b738e 16#include <OpenGl_GlCore11.hxx>
2166f0fa
SK
17
18#include <stddef.h>
19#include <stdio.h>
20#include <stdlib.h>
2166f0fa 21
2166f0fa
SK
22#include <InterfaceGraphic_Graphic3d.hxx> /* pour CALL_DEF_STRUCTURE */
23#include <InterfaceGraphic_Aspect.hxx> /* pour CALL_DEF_VIEW */
24#include <InterfaceGraphic_Visual3d.hxx>
25
26#include <OpenGl_transform_persistence.hxx>
27
2166f0fa
SK
28#include <OpenGl_Workspace.hxx>
29#include <OpenGl_View.hxx>
30#include <OpenGl_Trihedron.hxx>
31
a174a3c5 32static const OpenGl_TextParam THE_LABEL_PARAMS =
33{
34 16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
35};
2166f0fa 36
2166f0fa
SK
37static const CALL_DEF_CONTEXTLINE myDefaultContextLine =
38{
39 1, //IsDef
40 1, //IsSet
41 { 1.F, 1.F, 1.F }, //Color
42 Aspect_TOL_SOLID, //LineType
43 1.F //Width
44};
45
46static const CALL_DEF_CONTEXTTEXT myDefaultContextText =
47{
48 1, //IsDef
49 1, //IsSet
50 "Courier", //Font
51 0.3F, //Space
52 1.0F, //Expan
53 { 1.F, 1.F, 1.F }, //Color
54 Aspect_TOST_NORMAL, //Style
55 Aspect_TODT_NORMAL, //DisplayType
56 { 1.F, 1.F, 1.F }, //ColorSubTitle
57 0, //TextZoomable
58 0.F, //TextAngle
eeaaaefb 59 Font_FA_Regular //TextFontAspect
2166f0fa
SK
60};
61
62/*----------------------------------------------------------------------*/
63/*
64* Variables statiques
65*/
66
67/* Default parameters for ZBUFFER triheron */
68static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }};
69static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }};
70static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }};
71static float theRatio = 0.8f;
72static float theDiameter = 0.05f;
73static int theNbFacettes = 12;
74
75/*----------------------------------------------------------------------*/
76
77/*
78* affichage d'un triedre non zoomable a partir des index dans les tables
79* des structures non zoomables.
80*
81* Triedre = Objet non Zoomable :
82* on recalcule ses dimensions et son origine en fonction de la taille
83* de la fenetre; on positionne selon le choix de l'init;
84* et on inhibe seulement les translations.
85*
86*/
87
88//call_triedron_redraw
a174a3c5 89void OpenGl_Trihedron::redraw (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 90{
a174a3c5 91 const Standard_Real U = theWorkspace->ActiveView()->Height();
92 const Standard_Real V = theWorkspace->ActiveView()->Width();
2166f0fa
SK
93
94 /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
bf75be98 95 /* de la dimension la plus petite de la window. */
2166f0fa
SK
96 const GLdouble L = ( U < V ? U : V ) * myScale;
97
98 /*
99 * On inhibe les translations; on conserve les autres transformations.
100 */
101
102 /* on lit les matrices de transformation et de projection de la vue */
103 /* pour annuler les translations (dernieres colonnes des matrices). */
104 GLdouble modelMatrix[4][4];
105 glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
106 GLdouble projMatrix[4][4];
107 glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
108
109 /* on annule la translation qui peut etre affectee a la vue */
110 modelMatrix[3][0] = 0.;
111 modelMatrix[3][1] = 0.;
112 modelMatrix[3][2] = 0.;
113 projMatrix[3][0] = 0.;
114 projMatrix[3][1] = 0.;
115 projMatrix[3][2] = 0.;
116
117 /* sauvegarde du contexte des matrices avant chargement */
118 glMatrixMode (GL_MODELVIEW);
119 glPushMatrix ();
120 glLoadMatrixd( (GLdouble *) modelMatrix );
121 glMatrixMode ( GL_PROJECTION );
122 glPushMatrix ();
123 glLoadMatrixd( (GLdouble *) projMatrix );
124
125 /*
126 * Positionnement de l'origine du triedre selon le choix de l'init
127 */
128
129 /* on fait uniquement une translation de l'origine du Triedre */
130
131 switch (myPos)
132 {
133 case Aspect_TOTP_LEFT_LOWER :
134 glTranslated( -0.5*U + L , -0.5*V + L , 0. );
135 break;
136
137 case Aspect_TOTP_LEFT_UPPER :
138 glTranslated( -0.5*U + L , +0.5*V - L -L/3., 0. );
139 break;
140
141 case Aspect_TOTP_RIGHT_LOWER :
142 glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. );
143 break;
144
145 case Aspect_TOTP_RIGHT_UPPER :
146 glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. );
147 break;
148
149 //case Aspect_TOTP_CENTER :
150 default :
151 break;
152 }
153
bf75be98 154 /*
155 * Creation du triedre
2166f0fa 156 */
2166f0fa 157
bf75be98 158 /* Fotis Sioutis 2007-11-14 15:06
159 I have also seen in previous posts that the view trihedron in V3d_WIREFRAME mode
160 changes colors depending on the state of the view. This behaviour can be easily
2166f0fa 161 corrected by altering call_triedron_redraw function in OpenGl_triedron.c of TKOpengl.
bf75be98 162 The only change needed is to erase glDisable(GL_LIGHTING) that is called before the
2166f0fa 163 Axis name drawing and move this function call just before the initial axis drawing.
bf75be98 164 Below is the code portion with the modification.I don't know if this is considered to
2166f0fa
SK
165 be a bug but anyway i believe it might help some of you out there.*/
166 glDisable(GL_LIGHTING);
2166f0fa
SK
167
168 /* Position de l'origine */
169 const GLdouble TriedronOrigin[3] = { 0.0, 0.0, 0.0 };
170
171 /* Position des Axes */
172 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
173 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
174 GLdouble TriedronAxeZ[3] = { 0.0, 0.0, 1.0 };
175 TriedronAxeX[0] = L ;
176 TriedronAxeY[1] = L ;
177 TriedronAxeZ[2] = L ;
178
179 /* dessin des axes */
180 glBegin(GL_LINES);
181 glVertex3dv( TriedronOrigin );
182 glVertex3dv( TriedronAxeX );
183
184 glVertex3dv( TriedronOrigin );
185 glVertex3dv( TriedronAxeY );
186
187 glVertex3dv( TriedronOrigin );
188 glVertex3dv( TriedronAxeZ );
189 glEnd();
190
191 /* fleches au bout des axes (= cones de la couleur demandee) */
192 const GLdouble l = 0.75*L; /* distance a l'origine */
193 const GLdouble rayon = L/30. ; /* rayon de la base du cone */
194 const int NbFacettes = 12; /* le cone sera compose de 12 facettes triangulaires */
195 const double Angle = 2. * M_PI/ NbFacettes;
196
197 int ii;
198 GLdouble TriedronCoord[3] = { 1.0, 0.0, 0.0 };
199
200 /* solution FILAIRE des cones au bout des axes : une seule ligne */
201 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
202 /* (la couleur est deja initialisee dans AspectLine) */
203 /* FIN de la solution FILAIRE CHOISIE pour les cones des axes */
204
205 /* fleche en X */
206 glBegin(GL_TRIANGLE_FAN);
207 glVertex3dv( TriedronAxeX );
208 TriedronCoord[0] = l;
209 ii = NbFacettes;
210 while (ii >= 0 ) {
211 TriedronCoord[1] = rayon * sin(ii * Angle);
212 TriedronCoord[2] = rayon * cos(ii * Angle);
213 glVertex3dv( TriedronCoord );
214 ii--;
215 }
216 glEnd();
217
218 /* fleche en Y */
219 glBegin(GL_TRIANGLE_FAN);
220 glVertex3dv( TriedronAxeY );
221 TriedronCoord[1] = l;
222 ii = NbFacettes;
223 while (ii >= 0 ) {
224 TriedronCoord[0] = rayon * cos(ii * Angle);
225 TriedronCoord[2] = rayon * sin(ii * Angle);
226 glVertex3dv( TriedronCoord );
227 ii--;
228 }
229 glEnd();
230
231 /* fleche en Z */
232 glBegin(GL_TRIANGLE_FAN);
233 glVertex3dv( TriedronAxeZ );
234 TriedronCoord[2] = l;
235 ii = NbFacettes;
236 while (ii >= 0 ) {
237 TriedronCoord[0] = rayon * sin(ii * Angle);
238 TriedronCoord[1] = rayon * cos(ii * Angle);
239 glVertex3dv( TriedronCoord );
240 ii--;
241 }
242 glEnd();
243
244 /* dessin de l'origine */
245 TriedronCoord[2] = 0.0 ;
246 ii = 24 ;
247 const double Angle1 = 2. * M_PI/ ii;
248 glBegin(GL_LINE_LOOP);
249 while (ii >= 0 ) {
250 TriedronCoord[0] = rayon * sin(ii * Angle1);
251 TriedronCoord[1] = rayon * cos(ii * Angle1);
252 glVertex3dv( TriedronCoord );
253 ii--;
bf75be98 254 }
2166f0fa
SK
255 glEnd();
256
a174a3c5 257 // draw axes labels
258 myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon)));
259 myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon)));
260 myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon)));
261 myLabelX.Render (theWorkspace);
262 myLabelY.Render (theWorkspace);
263 myLabelZ.Render (theWorkspace);
2166f0fa 264
bf75be98 265 /*
2166f0fa
SK
266 * restauration du contexte des matrices
267 */
268 glMatrixMode (GL_PROJECTION);
269 glPopMatrix ();
270 glMatrixMode (GL_MODELVIEW);
271 glPopMatrix ();
272}
273
274
275/*******************************************************
276* Draws ZBUFFER trihedron mode
277*******************************************************/
278//call_zbuffer_triedron_redraw
a174a3c5 279void OpenGl_Trihedron::redrawZBuffer (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 280{
a174a3c5 281 const Standard_Real U = theWorkspace->ActiveView()->Height();
282 const Standard_Real V = theWorkspace->ActiveView()->Width();
2166f0fa
SK
283
284 GLdouble modelMatrix[4][4];
285 glGetDoublev( GL_MODELVIEW_MATRIX, (GLdouble *) modelMatrix );
286 GLdouble projMatrix[4][4];
287 glGetDoublev( GL_PROJECTION_MATRIX, (GLdouble *) projMatrix );
288
289 /* Check position in the ViewPort */
5f8b738e 290 /* PCD 29/09/2008 */
2166f0fa
SK
291 /* Simple code modification recommended by Fotis Sioutis and Peter Dolbey */
292 /* to remove the irritating default behaviour of triedrons using V3d_ZBUFFER */
293 /* which causes the glyph to jump around the screen when the origin moves offscreen. */
294 GLboolean isWithinView = GL_FALSE;
2166f0fa
SK
295
296 /* la taille des axes est 1 proportion (fixee a l'init du triedre) */
bf75be98 297 /* de la dimension la plus petite de la window. */
2166f0fa
SK
298 GLdouble L = ( U < V ? U : V ) * myScale;
299
300 if (!isWithinView)
301 {
302 /* Annulate translation matrix */
303 modelMatrix[3][0] = 0.;
304 modelMatrix[3][1] = 0.;
305 modelMatrix[3][2] = 0.;
306 projMatrix[3][0] = 0.;
307 projMatrix[3][1] = 0.;
308 projMatrix[3][2] = 0.;
309
310 /* save matrix */
311 glMatrixMode (GL_MODELVIEW);
312 glPushMatrix ();
313 //glLoadIdentity ();
314 glLoadMatrixd( (GLdouble *) modelMatrix);
315 glMatrixMode ( GL_PROJECTION );
316 glPushMatrix ();
317 //glLoadIdentity();
318 glLoadMatrixd( (GLdouble *) projMatrix);
319
320 /*
321 * Define position in the view
322 */
323 switch (myPos)
324 {
bf75be98 325 case Aspect_TOTP_LEFT_LOWER :
2166f0fa
SK
326 glTranslated( -0.5*U + L , -0.5*V + L , 0. );
327 break;
328
329 case Aspect_TOTP_LEFT_UPPER :
330 glTranslated( -0.5*U + L , +0.5*V - L -L/3. , 0. );
331 break;
332
333 case Aspect_TOTP_RIGHT_LOWER :
334 glTranslated( 0.5*U - L -L/3. , -0.5*V + L , 0. );
335 break;
336
337 case Aspect_TOTP_RIGHT_UPPER :
338 glTranslated( 0.5*U - L -L/3. , +0.5*V - L -L/3. , 0. );
339 break;
340
341 //case Aspect_TOTP_CENTER :
342 default :
343 break;
344 }
345 L *= myRatio;
346 }
347
a174a3c5 348 const OpenGl_AspectLine *AspectLine = theWorkspace->AspectLine( Standard_True );
2166f0fa
SK
349 const TEL_COLOUR &aLineColor = AspectLine->Color();
350
bf75be98 351 /*
2166f0fa
SK
352 * Creation the trihedron
353 */
354#define CYLINDER_LENGTH 0.75f
355
356 const GLuint startList = glGenLists(4);
357 GLUquadricObj* aQuadric = gluNewQuadric();
358
359 const GLboolean aIsDepthEnabled = glIsEnabled(GL_DEPTH_TEST);
360
2166f0fa 361 GLboolean aIsDepthMaskEnabled;
5f8b738e 362 /*PCD 02/07/07 */
2166f0fa
SK
363 /* GL_DEPTH_WRITEMASK is not a valid argument to glIsEnabled, the */
364 /* original code is shown to be broken when run under an OpenGL debugger */
365 /* like GLIntercept. This is the correct way to retrieve the mask value. */
bf75be98 366 glGetBooleanv(GL_DEPTH_WRITEMASK, &aIsDepthMaskEnabled);
2166f0fa
SK
367
368 const GLdouble aCylinderLength = L * CYLINDER_LENGTH;
369 const GLdouble aCylinderDiametr = L * myDiameter;
370 const GLdouble aConeDiametr = aCylinderDiametr * 2.;
371 const GLdouble aConeLength = L * (1 - CYLINDER_LENGTH);
372 /* Correct for owerlapping */
373 /* aCylinderLength += aConeLength - 1.2*aCylinderDiametr*aConeLength/aConeDiametr;*/
374
375 /* Create cylinder for axis */
376 gluQuadricDrawStyle(aQuadric, GLU_FILL); /* smooth shaded */
377 gluQuadricNormals(aQuadric, GLU_FLAT);
378 /* Axis */
379 glNewList(startList, GL_COMPILE);
380 gluCylinder(aQuadric, aCylinderDiametr, aCylinderDiametr, aCylinderLength, myNbFacettes, 1);
381 glEndList();
382 /* Cone */
383 glNewList(startList + 1, GL_COMPILE);
384 gluCylinder(aQuadric, aConeDiametr, 0., aConeLength, myNbFacettes, 1);
385 glEndList();
386 /* Central sphere */
387 glNewList(startList + 2, GL_COMPILE);
388 gluSphere(aQuadric, aCylinderDiametr * 2., myNbFacettes, myNbFacettes);
389 glEndList();
390 /* End disk */
391 gluQuadricOrientation(aQuadric,GLU_INSIDE); /*szv*/
392 glNewList(startList + 3, GL_COMPILE);
393 gluDisk(aQuadric, aCylinderDiametr, aConeDiametr, myNbFacettes, 1/*szv:2*/);
394 glEndList();
395
396 /* Store previous attributes */
397 glPushAttrib(GL_LIGHTING_BIT | GL_POLYGON_BIT);
398 glEnable(GL_LIGHTING);
399
400 glCullFace(GL_BACK);
401 glEnable(GL_CULL_FACE);
402
5f8b738e 403 /*Fotis Sioutis | 2008-01-21 10:55
bf75be98 404 In the function call_zbuffer_triedron_redraw of TKOpengl,
405 the z buffered trihedron changes colors in case there
406 is an object in the scene that has an explicit material
407 attached to it.In the trihedron display loop,
408 GL_COLOR_MATERIAL is enabled, but only the GL_DIFFUSE
2166f0fa 409 parameter is utilized in glColorMaterial(...).
bf75be98 410 This causes the last ambient,specular and emission values
2166f0fa
SK
411 used, to stay at the stack and applied to the trihedron
412 (which causes the color change).
bf75be98 413 A fix is proposed , to change GL_DIFFUSE to
414 GL_AMBIENT_AND_DIFFUSE in glColorMaterial call in
415 line 946.The above of course will leave unchanged
2166f0fa 416 the SPECULAR and EMISSION values.
bf75be98 417 Another proposal which would fix 100% the problem
418 is to use glMaterial instead of glColor on the trihedron
2166f0fa
SK
419 drawing loop. */
420 const GLfloat aNULLColor[] = { 0.f, 0.f, 0.f, 0.f }; /* FS 21/01/08 */
421 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, aNULLColor);
422 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, aNULLColor);
423 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, aNULLColor);
424 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 0.f);
2166f0fa
SK
425
426 glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
427 glEnable(GL_COLOR_MATERIAL);
428
429 if (!aIsDepthEnabled) {
430 glEnable(GL_DEPTH_TEST);
2166f0fa 431 glClear(GL_DEPTH_BUFFER_BIT);
2166f0fa 432 }
2166f0fa 433
2166f0fa
SK
434 if (!aIsDepthMaskEnabled) {
435 /* This is how the depthmask needs to be re-enabled...*/
436 glDepthMask(GL_TRUE);
437 /* ...and not this stuff below */
438 }
2166f0fa
SK
439
440 /* Position des Axes */
441 GLdouble TriedronAxeX[3] = { 1.0, 0.0, 0.0 };
442 GLdouble TriedronAxeY[3] = { 0.0, 1.0, 0.0 };
2166f0fa
SK
443 TriedronAxeX[0] = L;
444 TriedronAxeY[1] = L;
2166f0fa
SK
445
446 glMatrixMode(GL_MODELVIEW);
447
5f8b738e 448 /* PCD 17/06/07 */
2166f0fa 449 GLint df;
bf75be98 450 glGetIntegerv (GL_DEPTH_FUNC, &df);
2166f0fa 451
2166f0fa
SK
452 int i;
453 for (i = 0; i < 2; i++) /* PCD 11/02/08 Two pass method */
454 {
455 if (i == 0) /* First pass */
bf75be98 456 {
457 glDepthFunc(GL_ALWAYS);
2166f0fa
SK
458 }
459 else
460 {
bf75be98 461 glDepthFunc(GL_LEQUAL);
2166f0fa 462 }
2166f0fa
SK
463
464 glPushMatrix();
465 glPushMatrix();
466 glPushMatrix();
467
468 glColor3fv(aLineColor.rgb);
469 glCallList(startList+2);
470
471 // Z axis
472 glColor4fv(myZColor.rgb);
473 glCallList(startList);
474 glTranslated(0, 0, L * CYLINDER_LENGTH);
475 glCallList(startList + 3);
476 glCallList(startList + 1);
bf75be98 477 glPopMatrix();
2166f0fa
SK
478
479 // X axis
480 glRotated(90.0, TriedronAxeY[0], TriedronAxeY[1], TriedronAxeY[2]);
481 glColor4fv(myXColor.rgb);
482 glCallList(startList);
483 glTranslated(0, 0, L * CYLINDER_LENGTH);
484 glCallList(startList + 3);
485 glCallList(startList + 1);
bf75be98 486 glPopMatrix();
2166f0fa
SK
487
488 // Y axis
489 glRotated(-90.0, TriedronAxeX[0], TriedronAxeX[1], TriedronAxeX[2]);
490 glColor4fv(myYColor.rgb);
491 glCallList(startList);
492 glTranslated(0, 0, L * CYLINDER_LENGTH);
493 glCallList(startList + 3);
494 glCallList(startList + 1);
495 glPopMatrix();
2166f0fa 496 }
2166f0fa 497
bf75be98 498 if (!aIsDepthEnabled)
2166f0fa 499 glDisable(GL_DEPTH_TEST);
2166f0fa 500
5f8b738e 501 if (!aIsDepthMaskEnabled)
2166f0fa 502 glDepthMask(GL_FALSE);
2166f0fa 503
2166f0fa
SK
504 glDisable(GL_CULL_FACE);
505 glDisable(GL_COLOR_MATERIAL);
506
507 gluDeleteQuadric(aQuadric);
508 glColor3fv (aLineColor.rgb);
509
2166f0fa 510 /* Always write the text */
bf75be98 511 glDepthFunc(GL_ALWAYS);
2166f0fa
SK
512
513 glPopAttrib();
514
515 /* fleches au bout des axes (= cones de la couleur demandee) */
516 //const GLdouble l = 0.75*L; /* distance a l'origine */
517 const GLdouble rayon = L/30. ; /* rayon de la base du cone */
518 //const double Angle = 2. * M_PI/ myNbFacettes;
519
bf75be98 520 glDeleteLists(startList, 4);
2166f0fa
SK
521
522 glDisable(GL_LIGHTING);
523
a174a3c5 524 // draw axes labels
525 myLabelX.SetPosition (OpenGl_Vec3(float(L + rayon), 0.0f, float(-rayon)));
526 myLabelY.SetPosition (OpenGl_Vec3(float(rayon), float(L + 3.0 * rayon), float(2.0 * rayon)));
527 myLabelZ.SetPosition (OpenGl_Vec3(float(-2.0 * rayon), float(0.5 * rayon), float(L + 3.0 * rayon)));
528 myLabelX.Render (theWorkspace);
529 myLabelY.Render (theWorkspace);
530 myLabelZ.Render (theWorkspace);
2166f0fa 531
2166f0fa
SK
532 /*PCD 17/06/07 */
533 glDepthFunc(df);
2166f0fa
SK
534
535 if (!isWithinView) { /* restore matrix */
536 glMatrixMode (GL_PROJECTION);
537 glPopMatrix ();
538 glMatrixMode (GL_MODELVIEW);
539 glPopMatrix ();
540 }
541}
542
543
544/*----------------------------------------------------------------------*/
545
546/*----------------------------------------------------------------------*/
547/*
bf75be98 548* Fonctions publiques
2166f0fa
SK
549*/
550
551
552/*
553* initialisation d'un triedre non zoomable dans une vue.
554* ou modification des valeurs deja initialisees.
555*/
556
557//call_triedron_init
a174a3c5 558OpenGl_Trihedron::OpenGl_Trihedron (const Aspect_TypeOfTriedronPosition thePosition,
559 const Quantity_NameOfColor theColor,
560 const Standard_Real theScale,
561 const Standard_Boolean theAsWireframe)
562: myPos (thePosition),
563 myScale (theScale),
564 myIsWireframe (theAsWireframe),
565 myLabelX (TCollection_ExtendedString ("X"), OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS),
566 myLabelY (TCollection_ExtendedString ("Y"), OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS),
567 myLabelZ (TCollection_ExtendedString ("Z"), OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS)
2166f0fa
SK
568{
569 Standard_Real R,G,B;
a174a3c5 570 Quantity_Color aColor (theColor);
571 aColor.Values (R, G, B, Quantity_TOC_RGB);
2166f0fa 572
fd4a6963 573 CALL_DEF_CONTEXTLINE aLineAspect = myDefaultContextLine;
574 aLineAspect.Color.r = (float)R;
575 aLineAspect.Color.g = (float)G;
576 aLineAspect.Color.b = (float)B;
577 myAspectLine.SetAspect (aLineAspect);
578
579 CALL_DEF_CONTEXTTEXT aTextAspect = myDefaultContextText;
580 aTextAspect.Color.r = (float)R;
581 aTextAspect.Color.g = (float)G;
582 aTextAspect.Color.b = (float)B;
583 myAspectText.SetAspect (aTextAspect);
2166f0fa
SK
584
585 myXColor = theXColor;
586 myYColor = theYColor;
587 myZColor = theZColor;
588
589 myRatio = theRatio;
590 myDiameter = theDiameter;
591 myNbFacettes = theNbFacettes;
592}
593
594/*----------------------------------------------------------------------*/
595
596/*
597* destruction du triedre non zoomable d'une vue.
598*/
599
600//call_triedron_erase
a174a3c5 601OpenGl_Trihedron::~OpenGl_Trihedron()
602{
603}
604
605// =======================================================================
606// function : Release
607// purpose :
608// =======================================================================
609void OpenGl_Trihedron::Release (const Handle(OpenGl_Context)& theCtx)
2166f0fa 610{
a174a3c5 611 myLabelX.Release (theCtx);
612 myLabelY.Release (theCtx);
613 myLabelZ.Release (theCtx);
30f0ad28 614 myAspectLine.Release (theCtx);
615 myAspectText.Release (theCtx);
2166f0fa
SK
616}
617
618/*----------------------------------------------------------------------*/
619
620/*
bf75be98 621* affichage d'un triedre non zoomable dans la wks awsid
2166f0fa
SK
622*
623* Triedre = Objet non Zoomable;
bf75be98 624* on cree cette fonction pour pouvoir travailler par les structures
2166f0fa
SK
625* utilisees par les fonctions Tsm* et TEL_VIEW_REP
626*
627*/
628
629//call_triedron_redraw_from_wsid
bf75be98 630void OpenGl_Trihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
2166f0fa 631{
bf75be98 632 const OpenGl_AspectLine* aPrevAspectLine = theWorkspace->SetAspectLine (&myAspectLine);
633 const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectText);
2166f0fa
SK
634
635 /* check if GL_LIGHTING should be disabled
bf75be98 636 no enabling 'cause it will be done (if necessary: kinda Polygon types )
2166f0fa
SK
637 during redrawing structures
638 */
bf75be98 639 if (!theWorkspace->UseGLLight())
640 {
641 glDisable (GL_LIGHTING);
642 }
2166f0fa 643
bf75be98 644 const Handle(OpenGl_Texture) aPrevTexture = theWorkspace->DisableTexture();
2166f0fa
SK
645
646 /* affichage du Triedre Non Zoomable */
30f0ad28 647 theWorkspace->ActiveView()->EndTransformPersistence (theWorkspace->GetGlContext());
2166f0fa
SK
648
649 if (myIsWireframe)
bf75be98 650 {
a174a3c5 651 redraw (theWorkspace);
bf75be98 652 }
2166f0fa 653 else
bf75be98 654 {
a174a3c5 655 redrawZBuffer (theWorkspace);
bf75be98 656 }
2166f0fa 657
bf75be98 658 // restore aspects
659 if (!aPrevTexture.IsNull())
660 {
661 theWorkspace->EnableTexture (aPrevTexture);
662 }
2166f0fa 663
bf75be98 664 theWorkspace->SetAspectText (aPrevAspectText);
665 theWorkspace->SetAspectLine (aPrevAspectLine);
2166f0fa
SK
666}
667
668/*----------------------------------------------------------------------*/
669//call_ztriedron_setup
670void OpenGl_Trihedron::Setup (const Quantity_NameOfColor XColor, const Quantity_NameOfColor YColor, const Quantity_NameOfColor ZColor,
671 const Standard_Real SizeRatio, const Standard_Real AxisDiametr, const Standard_Integer NbFacettes)
672{
673 Standard_Real R,G,B;
674
675 Quantity_Color(XColor).Values(R, G, B, Quantity_TOC_RGB);
676 theXColor.rgb[0] = float (R);
677 theXColor.rgb[1] = float (G);
678 theXColor.rgb[2] = float (B);
679
680 Quantity_Color(YColor).Values(R, G, B, Quantity_TOC_RGB);
681 theYColor.rgb[0] = float (R);
682 theYColor.rgb[1] = float (G);
683 theYColor.rgb[2] = float (B);
684
685 Quantity_Color(ZColor).Values(R, G, B, Quantity_TOC_RGB);
686 theZColor.rgb[0] = float (R);
687 theZColor.rgb[1] = float (G);
688 theZColor.rgb[2] = float (B);
689
690 theRatio = float (SizeRatio);
691 theDiameter = float (AxisDiametr);
692 theNbFacettes = NbFacettes;
693}