0025133: TKOpenGl - Crash on closing a view containing presentations with capping
[occt.git] / src / OpenGl / OpenGl_GraduatedTrihedron.cxx
old mode 100644 (file)
new mode 100755 (executable)
index 120e6ba..a0a3af9
@@ -1,7 +1,17 @@
-// File:      OpenGl_GraduatedTrihedron.cxx
-// Created:   20 September 2011
-// Author:    Sergey ZERCHANINOV
-// Copyright: OPEN CASCADE 2011
+// Created on: 2011-09-20
+// Created by: Sergey ZERCHANINOV
+// Copyright (c) 2011-2013 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
 
 #include <OpenGl_GlCore11.hxx>
 
 #include <InterfaceGraphic_Aspect.hxx>
 #include <InterfaceGraphic_Visual3d.hxx>
 
-#include <GL/glu.h> // gluUnProject()
-
 #ifdef HAVE_CONFIG_H
-#include <config.h>
+  #include <config.h>
 #endif
 #ifdef HAVE_STRING_H
-#include <string.h>
+  #include <string.h>
 #endif
 
 #include <OpenGl_Workspace.hxx>
 #include <OpenGl_GraduatedTrihedron.hxx>
 #include <OpenGl_AspectLine.hxx>
 
-IMPLEMENT_STANDARD_HANDLE(OpenGl_GraduatedTrihedron,MMgt_TShared)
-IMPLEMENT_STANDARD_RTTIEXT(OpenGl_GraduatedTrihedron,MMgt_TShared)
-
 const OpenGl_AspectLine myDefaultAspectLine;
 
+static const OpenGl_TextParam THE_LABEL_PARAMS =
+{
+  16, Graphic3d_HTA_LEFT, Graphic3d_VTA_BOTTOM
+};
+
 /* Bounding box */
 float xmin = 0.0f, ymin = 0.0f, zmin = 0.0f, xmax = 100.0f, ymax = 100.0f, zmax = 100.0f;
 
 /* Normal of the view (not normalized!) */
-static float getNormal(float* normal) 
+static float getNormal(float* normal)
 {
   GLint viewport[4];
   GLdouble model_matrix[16], proj_matrix[16];
@@ -72,47 +82,47 @@ static float getDistance2Corner(float* normal, float* center, float x, float y,
     return normal[0] * (x - center[0]) + normal[1] * (y - center[1]) + normal[2] * (z - center[2]);
 }
 
-static char getFarestCorner(float d000, float d100, float d010, float d001, 
+static char getFarestCorner(float d000, float d100, float d010, float d001,
                             float d110, float d101, float d011, float d111)
 {
-    if (d000 > 0.0f && 
-        d000 > d100 && d000 > d010 && d000 > d001 && d000 > d110 && 
+    if (d000 > 0.0f &&
+        d000 > d100 && d000 > d010 && d000 > d001 && d000 > d110 &&
         d000 > d101 && d000 > d011 && d000 > d111)
     {
         return 1;
     }
     else if (d100 > 0.0f &&
-             d100 > d000 && d100 > d010 && d100 > d001 && d100 > d110 && 
+             d100 > d000 && d100 > d010 && d100 > d001 && d100 > d110 &&
              d100 > d101 && d100 > d011 && d100 > d111)
     {
         return 2;
     }
     else if (d010 > 0.0f &&
-             d010 > d000 && d010 > d100 && d010 > d001 && d010 > d110 && 
+             d010 > d000 && d010 > d100 && d010 > d001 && d010 > d110 &&
              d010 > d101 && d010 > d011 && d010 > d111)
     {
         return 3;
     }
     else if (d001 > 0.0f &&
-             d001 > d000 && d001 > d100 && d001 > d010 && d001 > d110 && 
+             d001 > d000 && d001 > d100 && d001 > d010 && d001 > d110 &&
              d001 > d101 && d001 > d011 && d001 > d111)
     {
         return 4;
     }
     else if (d110 > 0.0f &&
-             d110 > d000 && d110 > d100 && d110 > d010 && d110 > d001 && 
+             d110 > d000 && d110 > d100 && d110 > d010 && d110 > d001 &&
              d110 > d101 && d110 > d011 && d110 > d111)
     {
         return 5;
     }
     else if (d101 > 0.0f &&
-             d101 > d000 && d101 > d100 && d101 > d010 && d101 > d001 && 
+             d101 > d000 && d101 > d100 && d101 > d010 && d101 > d001 &&
              d101 > d110 && d101 > d011 && d101 > d111)
     {
         return 6;
     }
     else if (d011 > 0.0f &&
-             d011 > d000 && d011 > d100 && d011 > d010 && d011 > d001 && 
+             d011 > d000 && d011 > d100 && d011 > d010 && d011 > d001 &&
              d011 > d110 && d011 > d101 && d011 > d111)
     {
         return 7;
@@ -120,29 +130,7 @@ static char getFarestCorner(float d000, float d100, float d010, float d001,
     return 8; /* d111 */
 }
 
-static void drawText(const Handle(OpenGl_Workspace) &AWorkspace, const wchar_t* text, const char* font, OSD_FontAspect style, int size, float x, float y, float z)
-{
-  AWorkspace->FindFont(font, style, size);
-  AWorkspace->RenderText(text, 0, x, y, z);
-
-/* 4 OCC 6.3.1 and older:
-    GLuint fontBase;
-
-#ifndef WNT
-     fontBase = tXfmsetfont (1.0F, 1.0F);
-#else
-     fontBase = WNTSetFont (1.0F, 1.0F);
-#endif
-
-#ifndef WNT
-     tXfmprstr(text, fontBase, x, y, z);
-#else
-     WNTPuts(text, fontBase, 0, x, y, z);
-#endif
-*/
-}
-
-static void drawArrow(float x1, float y1, float z1, 
+static void drawArrow(float x1, float y1, float z1,
                       float x2, float y2, float z2,
                       float xn, float yn, float zn)
 {
@@ -197,121 +185,103 @@ static void drawArrow(float x1, float y1, float z1,
     glEnd();
 }
 
-OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_CGraduatedTrihedron &AData)
-: myXName(NULL), myYName(NULL), myZName(NULL),
-  myDrawXName(AData.xdrawname), myDrawYName(AData.ydrawname), myDrawZName(AData.zdrawname),
-  myDrawXValues(AData.xdrawvalues), myDrawYValues(AData.ydrawvalues), myDrawZValues(AData.zdrawvalues),
-  myDrawGrid(AData.drawgrid), myDrawAxes(AData.drawaxes),
-  myNbX(AData.nbx), myNbY(AData.nby), myNbZ(AData.nbz),
-  myXOffset(AData.xoffset), myYOffset(AData.yoffset), myZOffset(AData.zoffset),
-  myXAxisOffset(AData.xaxisoffset), myYAxisOffset(AData.yaxisoffset), myZAxisOffset(AData.zaxisoffset),
-  myDrawXTickmarks(AData.xdrawtickmarks), myDrawYTickmarks(AData.ydrawtickmarks), myDrawZTickmarks(AData.zdrawtickmarks),
-  myXTickmarkLength(AData.xtickmarklength), myYTickmarkLength(AData.ytickmarklength), myZTickmarkLength(AData.ztickmarklength),
-  myFontOfNames(NULL),
-  myStyleOfNames(AData.styleOfNames),
-  mySizeOfNames(AData.sizeOfNames),
-  myFontOfValues(NULL),
-  myStyleOfValues(AData.styleOfValues),
-  mySizeOfValues(AData.sizeOfValues),
-  myCbCubicAxes(AData.cbCubicAxes),
-  myPtrVisual3dView(AData.ptrVisual3dView)
+// =======================================================================
+// function : Release
+// purpose  :
+// =======================================================================
+void OpenGl_GraduatedTrihedron::Release (OpenGl_Context* theCtx)
 {
-  /* Names of axes */
-  /* X-name */
-  int len = AData.xname.Length();
-  if (len)
-  {
-    Standard_ExtString iname = AData.xname.ToExtString();
-    wchar_t *xname = new wchar_t[len+1];
-    len = 0; while (xname[len] = (wchar_t)(iname[len])) len++;
-    myXName = xname;
-  }
-  /* Y-name */
-  len = AData.yname.Length();
-  if (len)
-  {
-    Standard_ExtString iname = AData.yname.ToExtString();
-    wchar_t *yname = new wchar_t[len+1];
-    len = 0; while (yname[len] = (wchar_t)(iname[len])) len++;
-    myYName = yname;
-  }
-  /* Z-name */
-  len = AData.zname.Length();
-  if (len)
-  {
-    Standard_ExtString iname = AData.zname.ToExtString();
-    wchar_t *zname = new wchar_t[len+1];
-    len = 0; while (zname[len] = (wchar_t)(iname[len])) len++;
-    myZName = zname;
-  }
-  /* Grid color */
-  myGridColor[0] = (float) AData.gridcolor.Red();
-  myGridColor[1] = (float) AData.gridcolor.Green();
-  myGridColor[2] = (float) AData.gridcolor.Blue();
-  /* X name color */
-  myXNameColor[0] = (float) AData.xnamecolor.Red();
-  myXNameColor[1] = (float) AData.xnamecolor.Green();
-  myXNameColor[2] = (float) AData.xnamecolor.Blue();
-  /* Y name color */
-  myYNameColor[0] = (float) AData.ynamecolor.Red();
-  myYNameColor[1] = (float) AData.ynamecolor.Green();
-  myYNameColor[2] = (float) AData.ynamecolor.Blue();
-  /* Z name color */
-  myZNameColor[0] = (float) AData.znamecolor.Red();
-  myZNameColor[1] = (float) AData.znamecolor.Green();
-  myZNameColor[2] = (float) AData.znamecolor.Blue();
-  /* X color of axis and values */
-  myXColor[0] = (float) AData.xcolor.Red();
-  myXColor[1] = (float) AData.xcolor.Green();
-  myXColor[2] = (float) AData.xcolor.Blue();
-  /* Y color of axis and values */
-  myYColor[0] = (float) AData.ycolor.Red();
-  myYColor[1] = (float) AData.ycolor.Green();
-  myYColor[2] = (float) AData.ycolor.Blue();
-  /* Z color of axis and values */
-  myZColor[0] = (float) AData.zcolor.Red();
-  myZColor[1] = (float) AData.zcolor.Green();
-  myZColor[2] = (float) AData.zcolor.Blue();
-  /* Font name of names of axes: Courier, Arial, ... */
-  len = AData.fontOfNames.Length();
-  char *fontOfNames = new char[len+1];
-  if (len)
-    strcpy(fontOfNames, AData.fontOfNames.ToCString());
-  else
-    fontOfNames[0] = '\0';
-  myFontOfNames = fontOfNames;
-  /* Font name of values: Courier, Arial, ... */
-  len = AData.fontOfValues.Length();
-  char *fontOfValues = new char[len+1];
-  if (len)
-    strcpy(fontOfValues, AData.fontOfValues.ToCString());
-  else
-    fontOfValues[0] = '\0';
-  myFontOfValues = fontOfValues;
+  myLabelX.Release (theCtx);
+  myLabelY.Release (theCtx);
+  myLabelZ.Release (theCtx);
+  myLabelValues.Release (theCtx);
 }
 
-OpenGl_GraduatedTrihedron::~OpenGl_GraduatedTrihedron ()
+OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron (const Graphic3d_CGraduatedTrihedron& theData)
+: myLabelX (NCollection_String ((Standard_Utf16Char* )theData.xname.ToExtString()).ToCString(), OpenGl_Vec3(1.0f, 0.0f, 0.0f), THE_LABEL_PARAMS),
+  myLabelY (NCollection_String ((Standard_Utf16Char* )theData.yname.ToExtString()).ToCString(), OpenGl_Vec3(0.0f, 1.0f, 0.0f), THE_LABEL_PARAMS),
+  myLabelZ (NCollection_String ((Standard_Utf16Char* )theData.zname.ToExtString()).ToCString(), OpenGl_Vec3(0.0f, 0.0f, 1.0f), THE_LABEL_PARAMS),
+  myToDrawXName (theData.xdrawname == Standard_True),
+  myToDrawYName (theData.ydrawname == Standard_True),
+  myToDrawZName (theData.zdrawname == Standard_True),
+  myToDrawXValues (theData.xdrawvalues == Standard_True),
+  myToDrawYValues (theData.ydrawvalues == Standard_True),
+  myToDrawZValues (theData.zdrawvalues == Standard_True),
+  myToDrawGrid (theData.drawgrid == Standard_True),
+  myToDrawAxes (theData.drawaxes == Standard_True),
+  myNbX (theData.nbx),
+  myNbY (theData.nby),
+  myNbZ (theData.nbz),
+  myXOffset (theData.xoffset),
+  myYOffset (theData.yoffset),
+  myZOffset (theData.zoffset),
+  myXAxisOffset (theData.xaxisoffset),
+  myYAxisOffset (theData.yaxisoffset),
+  myZAxisOffset (theData.zaxisoffset),
+  myDrawXTickmarks (theData.xdrawtickmarks),
+  myDrawYTickmarks (theData.ydrawtickmarks),
+  myDrawZTickmarks (theData.zdrawtickmarks),
+  myXTickmarkLength (theData.xtickmarklength),
+  myYTickmarkLength (theData.ytickmarklength),
+  myZTickmarkLength (theData.ztickmarklength),
+  myCbCubicAxes (theData.cbCubicAxes),
+  myPtrVisual3dView (theData.ptrVisual3dView)
 {
-  // Names of axes
-  if (myXName)
-    delete[] myXName;
-  if (myYName)
-    delete[] myYName;
-  if (myZName)
-    delete[] myZName;
-
-  // Fonts
-  if (myFontOfNames)
-    delete[] myFontOfNames;
-  if (myFontOfValues)
-    delete[] myFontOfValues;
+  myAspectLabels.ChangeFontName() = theData.fontOfNames;
+  myAspectValues.ChangeFontName() = theData.fontOfValues;
+  myAspectLabels.SetFontAspect (theData.styleOfNames);
+  myAspectValues.SetFontAspect (theData.styleOfValues);
+  myLabelX.SetFontSize (NULL, theData.sizeOfNames);
+  myLabelY.SetFontSize (NULL, theData.sizeOfNames);
+  myLabelZ.SetFontSize (NULL, theData.sizeOfNames);
+  myLabelValues.SetFontSize (NULL, theData.sizeOfValues);
+
+  // Grid color
+  myGridColor[0] = (float) theData.gridcolor.Red();
+  myGridColor[1] = (float) theData.gridcolor.Green();
+  myGridColor[2] = (float) theData.gridcolor.Blue();
+  // X name color
+  myXNameColor.rgb[0] = (float )theData.xnamecolor.Red();
+  myXNameColor.rgb[1] = (float )theData.xnamecolor.Green();
+  myXNameColor.rgb[2] = (float )theData.xnamecolor.Blue();
+  myXNameColor.rgb[3] = 1.0f;
+  // Y name color
+  myYNameColor.rgb[0] = (float )theData.ynamecolor.Red();
+  myYNameColor.rgb[1] = (float )theData.ynamecolor.Green();
+  myYNameColor.rgb[2] = (float )theData.ynamecolor.Blue();
+  myYNameColor.rgb[3] = 1.0f;
+  // Z name color
+  myZNameColor.rgb[0] = (float )theData.znamecolor.Red();
+  myZNameColor.rgb[1] = (float )theData.znamecolor.Green();
+  myZNameColor.rgb[2] = (float )theData.znamecolor.Blue();
+  myZNameColor.rgb[3] = 1.0f;
+  // X color of axis and values
+  myXColor.rgb[0] = (float )theData.xcolor.Red();
+  myXColor.rgb[1] = (float )theData.xcolor.Green();
+  myXColor.rgb[2] = (float )theData.xcolor.Blue();
+  myXColor.rgb[3] = 1.0f;
+  // Y color of axis and values
+  myYColor.rgb[0] = (float )theData.ycolor.Red();
+  myYColor.rgb[1] = (float )theData.ycolor.Green();
+  myYColor.rgb[2] = (float )theData.ycolor.Blue();
+  myYColor.rgb[3] = 1.0f;
+  // Z color of axis and values
+  myZColor.rgb[0] = (float )theData.zcolor.Red();
+  myZColor.rgb[1] = (float )theData.zcolor.Green();
+  myZColor.rgb[2] = (float )theData.zcolor.Blue();
+  myZColor.rgb[3] = 1.0f;
+}
+
+OpenGl_GraduatedTrihedron::~OpenGl_GraduatedTrihedron()
+{
+  //
 }
 
 //call_graduatedtrihedron_redraw
-void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspace) const
+void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const
 {
-  const OpenGl_AspectLine *oldAspectLine = AWorkspace->SetAspectLine(&myDefaultAspectLine);
-  AWorkspace->AspectLine(Standard_True);
+  const OpenGl_AspectLine *oldAspectLine = theWorkspace->SetAspectLine(&myDefaultAspectLine);
+  theWorkspace->AspectLine(Standard_True);
 
   /* Update boundary box */
   if (myCbCubicAxes)
@@ -356,9 +326,9 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
   float LX1[6], LX2[6], LX3[6]; /* Lines along X direction */
   float LY1[6], LY2[6], LY3[6]; /* Lines along Y direction */
   float LZ1[6], LZ2[6], LZ3[6]; /* Lines along Z direction */
-  unsigned char LX1draw, LX2draw, LX3draw; /* Allows drawing of X-line (000 - 100 is forbidden) */
-  unsigned char LY1draw, LY2draw, LY3draw; /* Allows drawing of Y-line (000 - 010 is forbidden) */
-  unsigned char LZ1draw, LZ2draw, LZ3draw; /* Allows drawing of Z-line (000 - 001 is forbidden) */
+  unsigned char LX1draw = 0, LX2draw = 0, LX3draw = 0; /* Allows drawing of X-line (000 - 100 is forbidden) */
+  unsigned char LY1draw = 0, LY2draw = 0, LY3draw = 0; /* Allows drawing of Y-line (000 - 010 is forbidden) */
+  unsigned char LZ1draw = 0, LZ2draw = 0, LZ3draw = 0; /* Allows drawing of Z-line (000 - 001 is forbidden) */
 
   /* The first axis will be used for drawing the text and the values. */
   switch (farestCorner)
@@ -637,17 +607,17 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     }
   }
 
-  /* Draw the graduated trihedron */
-  unsigned int i, j, offset;
+  // Draw the graduated trihedron
+  unsigned int i, offset;
   float m1[3], m2[3];
   float step, dx, dy, dz;
 
-  /* Grid */
-  if (myDrawGrid)
+  // Grid
+  if (myToDrawGrid)
   {
     glColor3fv(myGridColor);
     glBegin(GL_LINES);
-    /* Boundary grid-lines */
+    // Boundary grid-lines
     if (LX1draw == 1)
     {
       glVertex3fv(&(LX1[0]));
@@ -699,7 +669,7 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     /* X-Grid lines */
     if (myNbX > 0)
     {
-      i = myDrawAxes ? 1 : 0;
+      i = myToDrawAxes ? 1 : 0;
       step = fabsf(LX1[3] - LX1[0]) / (float) myNbX;
       while (i < myNbX)
       {
@@ -714,7 +684,7 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     /* Y-Grid lines */
     if (myNbY > 0)
     {
-      i = myDrawAxes ? 1 : 0;
+      i = myToDrawAxes ? 1 : 0;
       step = fabsf(LY1[4] - LY1[1]) / (float) myNbY;
       while (i < myNbY)
       {
@@ -729,8 +699,9 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     /* Z-Grid lines */
     if (myNbZ > 0)
     {
-      i = myDrawAxes ? 1 : 0;
+      i = myToDrawAxes ? 1 : 0;
       step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ;
+
       while (i < myNbZ)
       {
         glBegin(GL_LINE_STRIP);
@@ -743,39 +714,38 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     }
   }
 
-  /* Axes (arrows) */
-  if (myDrawAxes)
+  // Axes (arrows)
+  if (myToDrawAxes)
   {
-    /* X-axis */
-    glColor3fv(myXColor);
+    // X-axis
+    glColor3fv(myXColor.rgb);
     drawArrow(xmin, ymin, zmin, xmax, ymin, zmin, normal[0], normal[1], normal[2]);
 
-    /* Y-axis */
-    glColor3fv(myYColor);
+    // Y-axis
+    glColor3fv(myYColor.rgb);
     drawArrow(xmin, ymin, zmin, xmin, ymax, zmin, normal[0], normal[1], normal[2]);
 
-    /* Z-axis */
-    glColor3fv(myZColor);
+    // Z-axis
+    glColor3fv(myZColor.rgb);
     drawArrow(xmin, ymin, zmin, xmin, ymin, zmax, normal[0], normal[1], normal[2]);
   }
 
-  /* Names of axes & values */
+  // Names of axes & values
   char textValue[128];
-  wchar_t wtextValue[128];
 
-  if (myDrawXName || myDrawXValues)
+  if (myToDrawXName || myToDrawXValues)
   {
-    /* Middle point of the first X-axis */
+    // Middle point of the first X-axis
     m1[0] = 0.5f * (LX1[0] + LX1[3]);
     m1[1] = 0.5f * (LX1[1] + LX1[4]);
     m1[2] = 0.5f * (LX1[2] + LX1[5]);
 
-    /* Middle point of the second X-axis */
+    // Middle point of the second X-axis
     m2[0] = 0.5f * (LX2[0] + LX2[3]);
     m2[1] = 0.5f * (LX2[1] + LX2[4]);
     m2[2] = 0.5f * (LX2[2] + LX2[5]);
 
-    /* Apply offset to m1 */
+    // Apply offset to m1
     dy = m1[1] - m2[1];
     if (fabsf(dy) > 1.e-7f)
     {
@@ -789,64 +759,66 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     m2[1] = dpix * dy;
     m2[2] = dpix * dz;
 
-    /* Name of X-axis */
-    if (myDrawXName)
+    // Name of X-axis
+    if (myToDrawXName)
     {
-      glColor3fv(myXNameColor);
       offset = myXAxisOffset + myXTickmarkLength;
-      drawText(AWorkspace, myXName, myFontOfNames, myStyleOfNames, mySizeOfNames, 
-               m1[0], m1[1] + offset * m2[1], m1[2] + offset * m2[2]);
+
+      // draw axes labels
+      myAspectLabels.ChangeColor() = myXNameColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels);
+      myLabelX.SetPosition (OpenGl_Vec3(m1[0], m1[1] + offset * m2[1], m1[2] + offset * m2[2]));
+      myLabelX.Render (theWorkspace);
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* X-values */
-    if (myDrawXValues && myNbX > 0)
+    // X-values
+    if (myToDrawXValues && myNbX > 0)
     {
-      glColor3fv(myXColor);
+      myAspectValues.ChangeColor() = myXColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues);
 
-      i = 0;
       step = fabsf(LX1[3] - LX1[0]) / (float) myNbX;
       offset = myXOffset + myXTickmarkLength;
-      while (i <= myNbX)
+      for (unsigned int anIter = 0; anIter <= myNbX; ++anIter)
       {
-        sprintf(textValue, "%g", LX1[0] + i * step);
-        j = 0; while (wtextValue[j] = textValue[j]) j++;
-        drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, 
-                 LX1[0] + i * step, m1[1] + offset * m2[1], m1[2] + offset * m2[2]);
-        i++;
+        sprintf (textValue, "%g", LX1[0] + anIter * step);
+        myLabelValues.Init (theWorkspace->GetGlContext(), textValue,
+                            OpenGl_Vec3(LX1[0] + anIter * step, m1[1] + offset * m2[1], m1[2] + offset * m2[2]));
+        myLabelValues.Render (theWorkspace);
       }
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* X-tickmark */
+    // X-tickmark
     if (myDrawXTickmarks && myNbX > 0)
     {
       glColor3fv(myGridColor);
 
-      i = 0;
       step = fabsf(LX1[3] - LX1[0]) / (float) myNbX;
-      while (i <= myNbX)
+      for (unsigned int anIter = 0; anIter <= myNbX; ++anIter)
       {
         glBegin(GL_LINES);
-        glVertex3f(LX1[0] + i * step, m1[1],                             m1[2]);
-        glVertex3f(LX1[0] + i * step, m1[1] + myXTickmarkLength * m2[1], m1[2] + myXTickmarkLength * m2[2]);
+        glVertex3f(LX1[0] + anIter * step, m1[1],                             m1[2]);
+        glVertex3f(LX1[0] + anIter * step, m1[1] + myXTickmarkLength * m2[1], m1[2] + myXTickmarkLength * m2[2]);
         glEnd();
-        i++;
       }
     }
   }
 
-  if (myDrawYName || myDrawYValues)
+  if (myToDrawYName || myToDrawYValues)
   {
-    /* Middle point of the first Y-axis */
+    // Middle point of the first Y-axis
     m1[0] = 0.5f * (LY1[0] + LY1[3]);
     m1[1] = 0.5f * (LY1[1] + LY1[4]);
     m1[2] = 0.5f * (LY1[2] + LY1[5]);
 
-    /* Middle point of the second Y-axis */
+    // Middle point of the second Y-axis
     m2[0] = 0.5f * (LY2[0] + LY2[3]);
     m2[1] = 0.5f * (LY2[1] + LY2[4]);
     m2[2] = 0.5f * (LY2[2] + LY2[5]);
 
-    /* Apply offset to m1 */
+    // Apply offset to m1
     dx = m1[0] - m2[0];
     if (fabsf(dx) > 1.e-7f)
     {
@@ -861,34 +833,37 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     m2[0] = dpix * dx;
     m2[2] = dpix * dz;
 
-    /* Name of Y-axis */
-    if (myDrawYName)
+    // Name of Y-axis
+    if (myToDrawYName)
     {
-      glColor3fv(myYNameColor);
       offset = myYAxisOffset + myYTickmarkLength;
-      drawText(AWorkspace, myYName, myFontOfNames, myStyleOfNames, mySizeOfNames, 
-               m1[0] + offset * m2[0], m1[1], m1[2] + offset * m2[2]);
+
+      myAspectLabels.ChangeColor() = myYNameColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels);
+      myLabelY.SetPosition (OpenGl_Vec3(m1[0] + offset * m2[0], m1[1], m1[2] + offset * m2[2]));
+      myLabelY.Render (theWorkspace);
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* Y-values */
-    if (myDrawYValues && myNbY > 0)
+    // Y-values
+    if (myToDrawYValues && myNbY > 0)
     {
-      glColor3fv(myYColor);
+      myAspectValues.ChangeColor() = myYColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues);
 
-      i = 0;
       step = fabsf(LY1[4] - LY1[1]) / (float) myNbY;
       offset = myYOffset + myYTickmarkLength;
-      while (i <= myNbY)
+      for (unsigned int anIter = 0; anIter <= myNbY; ++anIter)
       {
-        sprintf(textValue, "%g", LY1[1] + i * step);
-        j = 0; while (wtextValue[j] = textValue[j]) j++;
-        drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, 
-                 m1[0] + offset * m2[0], LY1[1] + i * step, m1[2] + offset * m2[2]);
-        i++;
+        sprintf (textValue, "%g", LY1[1] + anIter * step);
+        myLabelValues.Init (theWorkspace->GetGlContext(), textValue,
+                            OpenGl_Vec3(m1[0] + offset * m2[0], LY1[1] + anIter * step, m1[2] + offset * m2[2]));
+        myLabelValues.Render (theWorkspace);
       }
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* Y-tickmark */
+    // Y-tickmark
     if (myDrawYTickmarks && myNbY > 0)
     {
       glColor3fv(myGridColor);
@@ -906,19 +881,19 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     }
   }
 
-  if (myDrawZName || myDrawZValues)
+  if (myToDrawZName || myToDrawZValues)
   {
-    /* Middle point of the first Z-axis */
+    // Middle point of the first Z-axis
     m1[0] = 0.5f * (LZ1[0] + LZ1[3]);
     m1[1] = 0.5f * (LZ1[1] + LZ1[4]);
     m1[2] = 0.5f * (LZ1[2] + LZ1[5]);
 
-    /* Middle point of the second Z-axis */
+    // Middle point of the second Z-axis
     m2[0] = 0.5f * (LZ2[0] + LZ2[3]);
     m2[1] = 0.5f * (LZ2[1] + LZ2[4]);
     m2[2] = 0.5f * (LZ2[2] + LZ2[5]);
 
-    /* Apply offset to m1 */
+    // Apply offset to m1
     dx = m1[0] - m2[0];
     if (fabsf(dx) > 1.e-7f)
     {
@@ -933,34 +908,37 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     m2[0] = dpix * dx;
     m2[1] = dpix * dy;
 
-    /* Name of Z-axis */
-    if (myDrawZName)
+    // Name of Z-axis
+    if (myToDrawZName)
     {
-      glColor3fv(myZNameColor);
       offset = myZAxisOffset + myZTickmarkLength;
-      drawText(AWorkspace, myZName, myFontOfNames, myStyleOfNames, mySizeOfNames, 
-               m1[0] + offset * m2[0], m1[1] + offset * m2[1], m1[2]);
+
+      myAspectLabels.ChangeColor() = myZNameColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectLabels);
+      myLabelZ.SetPosition (OpenGl_Vec3(m1[0] + offset * m2[0], m1[1] + offset * m2[1], m1[2]));
+      myLabelZ.Render (theWorkspace);
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* Z-values */
-    if (myDrawZValues && myNbZ > 0)
+    // Z-values
+    if (myToDrawZValues && myNbZ > 0)
     {
-      glColor3fv(myZColor);
+      myAspectValues.ChangeColor() = myZColor;
+      const OpenGl_AspectText* aPrevAspectText = theWorkspace->SetAspectText (&myAspectValues);
 
-      i = 0;
       step = fabsf(LZ1[5] - LZ1[2]) / (float) myNbZ;
       offset = myZOffset + myZTickmarkLength;
-      while (i <= myNbZ)
+      for (unsigned int anIter = 0; anIter <= myNbZ; ++anIter)
       {
-        sprintf(textValue, "%g", LZ1[2] + i * step);
-        j = 0; while (wtextValue[j] = textValue[j]) j++;
-        drawText(AWorkspace, wtextValue, myFontOfValues, myStyleOfValues, mySizeOfValues, 
-                 m1[0] + offset * m2[0], m1[1] + offset * m2[1], LZ1[2] + i * step);
-        i++;
+        sprintf (textValue, "%g", LZ1[2] + anIter * step);
+        myLabelValues.Init (theWorkspace->GetGlContext(), textValue,
+                            OpenGl_Vec3(m1[0] + offset * m2[0], m1[1] + offset * m2[1], LZ1[2] + anIter * step));
+        myLabelValues.Render (theWorkspace);
       }
+      theWorkspace->SetAspectText (aPrevAspectText);
     }
 
-    /* Z-tickmark */
+    // Z-tickmark
     if (myDrawZTickmarks && myNbZ > 0)
     {
       glColor3fv(myGridColor);
@@ -978,11 +956,11 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace) &AWorkspa
     }
   }
 
-  /* Activate the lighting if it was turned off by this method call */
+  // Activate the lighting if it was turned off by this method call
   if (light)
     glEnable(GL_LIGHTING);
 
-  AWorkspace->SetAspectLine(oldAspectLine);
+  theWorkspace->SetAspectLine(oldAspectLine);
 }
 
 //call_graduatedtrihedron_minmaxvalues