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