Salome HOME
Merge modifications for HYDRO project (origin/hydro/imps_2017 branch)
[modules/gui.git] / src / GLViewer / GLViewer_Drawer.cxx
index 9a0f3ef6b02ed5faaaf168498f4ac26717b3a9ec..13d5e8acbef14f0b6bbaffb3abc2e4e93ceba5ec 100644 (file)
@@ -1,43 +1,49 @@
-//  Copyright (C) 2005 OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  Author : OPEN CASCADE
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+//  Author : OPEN CASCADE
 // File:      GLViewer_Drawer.cxx
 // Created:   November, 2004
-
 //#include <GLViewerAfx.h>
+//
 #include "GLViewer_Drawer.h"
 #include "GLViewer_Object.h"
 #include "GLViewer_Text.h"
 #include "GLViewer_ViewFrame.h"
 #include "GLViewer_ViewPort2d.h"
 
-#ifndef WIN32
+#include <QApplication>
+#include <QImage>
+#include <QPainter>
+#include <QFile>
+
+#if defined(__APPLE__)
+#include <OpenGL/CGLCurrent.h>
+#elif !defined(WIN32)
 #include <GL/glx.h>
 #endif
 
 #include <gp_Pnt2d.hxx>
 
-#include <qimage.h>
-#include <qpainter.h>
-
 #define TEXT_GAP    5
 // Two texture components for texmapped fonts: luminance and alpha
 #define NB_TEX_COMP 2
 
 GLfloat modelMatrix[16];
 
-//================================================================
-// Class       : GLViewer_TexFont
-// Description : 
-//================================================================
+
 //! code of first font symbol
 static int FirstSymbolNumber = 32;
 //! code of last font symbol
@@ -60,10 +63,9 @@ static int LastSymbolNumber = 127;
 QMap<GLViewer_TexFindId,GLViewer_TexIdStored> GLViewer_TexFont::TexFontBase;
 QMap<GLViewer_TexFindId,GLuint>               GLViewer_TexFont::BitmapFontCache; 
 
-//=======================================================================
-// Function: clearTextBases
-// Purpose :
-//=======================================================================
+/*!
+  Clears all generated fonts
+*/
 void GLViewer_TexFont::clearTextBases()
 {
   //cout << "Clear font map" << endl;
@@ -71,14 +73,13 @@ void GLViewer_TexFont::clearTextBases()
   BitmapFontCache.clear();
 }
 
-//======================================================================
-// Function: GLViewer_TexFont
-// Purpose :
-//=======================================================================
+/*!
+  Default constructor
+*/
 GLViewer_TexFont::GLViewer_TexFont()
 : myMaxRowWidth( 0 ), myFontHeight( 0 )
 {
-    myQFont = QFont::defaultFont();
+    myQFont = QApplication::font();//QFont::defaultFont();
     mySeparator = 2;
     myIsResizeable = false;
     myMinMagFilter = GL_LINEAR;
@@ -86,10 +87,13 @@ GLViewer_TexFont::GLViewer_TexFont()
     init();
 }
 
-//======================================================================
-// Function: GLViewer_TexFont
-// Purpose :
-//=======================================================================
+/*!
+  Constructor
+  \param theFont         - a base font
+  \param theSeparator    - separator between letters
+  \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
+  \param theMinMagFilter - min/mag filter, affects text sharpness
+*/
 GLViewer_TexFont::GLViewer_TexFont( QFont* theFont, int theSeparator, bool theIsResizeable, GLuint theMinMagFilter )
 : myMaxRowWidth( 0 ), myFontHeight( 0 )
 {
@@ -101,20 +105,18 @@ GLViewer_TexFont::GLViewer_TexFont( QFont* theFont, int theSeparator, bool theIs
     init();
 }
 
-//======================================================================
-// Function: ~GLViewer_TexFont
-// Purpose :
-//=======================================================================
+/*!
+  Destructor
+*/
 GLViewer_TexFont::~GLViewer_TexFont()
 {
     delete[] myWidths;
     delete[] myPositions;
 } 
 
-//======================================================================
-// Function: init
-// Purpose :
-//=======================================================================
+/*!
+  Initializes font parameters
+*/
 void GLViewer_TexFont::init()
 {
     myNbSymbols = LastSymbolNumber - FirstSymbolNumber + 1;
@@ -148,10 +150,9 @@ void GLViewer_TexFont::init()
     myTexFontHeight = 0;
 }
   
-//======================================================================
-// Function: generateTexture
-// Purpose :
-//=======================================================================
+/*!
+  Generating font texture
+*/
 bool GLViewer_TexFont::generateTexture()
 {
     GLViewer_TexFindId aFindFont;
@@ -160,7 +161,7 @@ bool GLViewer_TexFont::generateTexture()
     aFindFont.myIsItal = myQFont.italic();
     aFindFont.myIsUndl = myQFont.underline();
     aFindFont.myPointSize = myQFont.pointSize();
-    aFindFont.myViewPortId = (int)QGLContext::currentContext();
+    aFindFont.myViewPortId = size_t(QGLContext::currentContext());
         
     if( TexFontBase.contains( aFindFont ) )
     {
@@ -209,7 +210,7 @@ bool GLViewer_TexFont::generateTexture()
             aPainter.drawText( myPositions[l], ( row + 1 ) * aRowPixelHeight - aDescent, aLetter );
         }
     
-        QImage aImage = aPixmap.convertToImage();
+        QImage aImage = aPixmap.toImage();
 
         //int qqq = 0;
         //if (qqq)
@@ -265,10 +266,13 @@ bool GLViewer_TexFont::generateTexture()
     return true;
 }
 
-//======================================================================
-// Function: drawString
-// Purpose :
-//=======================================================================
+/*!
+  Drawing string in viewer
+  \param theStr - string to be drawn
+  \param theX - X position
+  \param theY - Y position
+  \param theScale - scale coefficient
+*/
 void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY, GLfloat theScale )
 {
     // Adding some pixels to have a gap between rows
@@ -308,9 +312,9 @@ void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY
     float aDY = ( aRowPixelHeight - 1 ) / aYScale, aDX;
     char aLetter;
     int aLettIndex, row;
-    for( int i = 0; i < theStr.length(); i++ )
+    for ( int i = 0; i < (int)theStr.length(); i++ )
     {
-        aLetter    = theStr.data()[i];
+        aLetter    = theStr.data()[i].toLatin1();
         aLettIndex = (int)aLetter - FirstSymbolNumber;
         row        = aLettIndex / TEX_ROW_LEN;
 
@@ -334,16 +338,15 @@ void GLViewer_TexFont::drawString( QString theStr, GLdouble theX , GLdouble theY
     glPopAttrib();
 }
 
-//======================================================================
-// Function: getStringWidth
-// Purpose :
-//=======================================================================
+/*!
+  \return width of string in pixels
+*/
 int GLViewer_TexFont::getStringWidth( QString theStr )
 {
     int aWidth = 0;
-    for( int i = 0; i < theStr.length(); i ++ )
+    for ( int i = 0; i < (int)theStr.length(); i ++ )
     {
-        char aLetter = theStr.data()[i];
+        char aLetter = theStr.data()[i].toLatin1();
         int aLettIndex = (int)aLetter - FirstSymbolNumber;
         aWidth += myWidths[aLettIndex] + mySeparator;
     }
@@ -351,17 +354,18 @@ int GLViewer_TexFont::getStringWidth( QString theStr )
     return aWidth;
 }
 
-//======================================================================
-// Function: getStringHeight
-// Purpose :
-//=======================================================================
+/*!
+  \return height of string in pixels
+*/
 int GLViewer_TexFont::getStringHeight()
 {
     QFontMetrics aFM( myQFont );
     return aFM.height();
 }
 
-//! function for generation list base for bitmap fonts
+/*!
+  Generates list base for bitmap fonts
+*/
 static GLuint displayListBase( QFont* theFont )
 {
   if ( !theFont )
@@ -375,7 +379,7 @@ static GLuint displayListBase( QFont* theFont )
   aFindFont.myIsUndl = theFont->underline();
   aFindFont.myPointSize = theFont->pointSize();
 
-#ifdef WIN32
+#if defined(WIN32)
   HGLRC ctx = ::wglGetCurrentContext();
   if ( !ctx )
     return aList;  
@@ -390,18 +394,47 @@ static GLuint displayListBase( QFont* theFont )
     QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
     for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
     {
-      if ( it.key().myViewPortId == (int)ctx && it.data() > listBase )
-        listBase = it.data();
+      if ( it.key().myViewPortId == (int)ctx && it.value() > listBase )
+        listBase = it.value();
     }
     listBase += 256;
 
     HDC glHdc = ::wglGetCurrentDC();
+ #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     ::SelectObject( glHdc, theFont->handle() );
+ #endif
     if ( !::wglUseFontBitmaps( glHdc, 0, 256, listBase ) )
       listBase = 0;
     aList = listBase;
     GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
   }
+#elif defined(__APPLE__)
+  CGLContextObj ctx = ::CGLGetCurrentContext();
+  if ( !ctx )
+    return aList;
+
+  aFindFont.myViewPortId = (long)ctx;
+
+  if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
+    aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
+  else
+  {
+    GLuint listBase = 0;
+    QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
+    for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
+    {
+      if ( it.key().myViewPortId == (long)ctx && it.value() > listBase )
+        listBase = it.value();
+    }
+    listBase += 256;
+
+    //HDC glHdc = ::wglGetCurrentDC();
+    //::SelectObject( glHdc, theFont->handle() );
+    //if ( !::wglUseFontBitmaps( glHdc, 0, 256, listBase ) )
+    //  listBase = 0;
+    aList = listBase;
+    GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
+  }
 #else //X Window
   Display* aDisp = glXGetCurrentDisplay();
   if( !aDisp )
@@ -421,7 +454,7 @@ static GLuint displayListBase( QFont* theFont )
     return aList;
   }
 
-  aFindFont.myViewPortId = (int)aCont;
+  aFindFont.myViewPortId = size_t(aCont);
 
   if ( GLViewer_TexFont::BitmapFontCache.contains( aFindFont ) )
     aList = GLViewer_TexFont::BitmapFontCache[aFindFont];
@@ -431,19 +464,22 @@ static GLuint displayListBase( QFont* theFont )
     QMap<GLViewer_TexFindId, GLuint>::iterator it = GLViewer_TexFont::BitmapFontCache.begin();
     for ( ; it != GLViewer_TexFont::BitmapFontCache.end(); ++it )
     {
-      if ( it.key().myViewPortId == (int)aCont && it.data() > listBase )
-        listBase = it.data();
+      if ( it.key().myViewPortId == size_t(aCont) && it.value() > listBase )
+        listBase = it.value();
     }
     listBase += 256;
     
     //glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase );
     int aFontCont = 0;
     QString aFontDef = theFont->toString();
-    char** xFontList = XListFonts( aDisp, aFontDef.latin1()/*aFindFont.myFontString.data()*/, 1, &aFontCont  );
+    char** xFontList = XListFonts( aDisp, aFontDef.toLatin1()/*aFindFont.myFontString.data()*/, 1, &aFontCont  );
+// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     if( !theFont->handle() )
-    {       
+    {
+#endif
 #ifdef _DEBUG_
-      printf( "Can't load font %s. loading default font....\n", aFontDef.latin1()/*aFindFont.myFontString.data()*/ );
+      printf( "Can't load font %s. loading default font....\n", aFontDef.toLatin1().data()/*aFindFont.myFontString.data()*/ );
 #endif
       QString aFontMask ("-*-*-*-r-*-*-");
       aFontMask += aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 );
@@ -451,19 +487,20 @@ static GLuint displayListBase( QFont* theFont )
       printf( "Height of Default font: %s\n", aFontDef/*aFindFont.myFontString*/.section( ',', 1, 1 ).data() );
 #endif
       aFontMask += "-*-*-*-m-*-*-*";
-      xFontList = XListFonts( aDisp, aFontMask.data()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont  );
+      xFontList = XListFonts( aDisp, aFontMask.toLatin1().constData()/*"-*-*-*-r-*-*-12-*-*-*-m-*-*-*"*/, 1, &aFontCont  );
       if( aFontCont == 0 )
-      {      
+      {
 #ifdef _DEBUG_
         printf( "Can't load default font\n" );
 #endif
         return 0;
       }
       glXUseXFont( (Font)(XLoadFont( aDisp,xFontList[0] )), 0, 256, listBase );
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     }
     else
       glXUseXFont( (Font)(theFont->handle()), 0, 256, listBase );
-    
+#endif
     aList = listBase;
     GLViewer_TexFont::BitmapFontCache[aFindFont] = aList;
   }
@@ -473,16 +510,9 @@ static GLuint displayListBase( QFont* theFont )
   return aList;
 }
 
-/***************************************************************************
-**  Class:   GLViewer_Drawer
-**  Descr:   Drawer for GLViewer_Object
-**  Module:  GLViewer
-**  Created: UI team, 01.10.01
-****************************************************************************/
-//======================================================================
-// Function: GLViewer_Drawer
-// Purpose :
-//=======================================================================
+/*!
+  Default constructor
+*/
 GLViewer_Drawer::GLViewer_Drawer()
 : myFont( "Helvetica", 10, QFont::Bold )
 {
@@ -495,60 +525,60 @@ GLViewer_Drawer::GLViewer_Drawer()
   myTextScale = 0.125;
 }
 
-//======================================================================
-// Function: ~GLViewer_Drawer
-// Purpose :
-//=======================================================================
+/*!
+  Destructor
+*/
 GLViewer_Drawer::~GLViewer_Drawer()
 {
   myObjects.clear();
   glDeleteLists( myTextList, 1 );
 }
 
-//======================================================================
-// Function: destroyAllTextures
-// Purpose :
-//=======================================================================
+/*!
+  Clears all generated textures
+*/
 void GLViewer_Drawer::destroyAllTextures()
 {
     QMap<GLViewer_TexFindId,GLViewer_TexIdStored>::Iterator anIt= GLViewer_TexFont::TexFontBase.begin();
     QMap<GLViewer_TexFindId,GLViewer_TexIdStored>::Iterator anEndIt= GLViewer_TexFont::TexFontBase.end();
 
     for( ; anIt != anEndIt; anIt++ )
-        glDeleteTextures( 1, &(anIt.data().myTexFontId) );
+        glDeleteTextures( 1, &(anIt.value().myTexFontId) );
 }
 
-//=======================================================================
-// Function: setAntialiasing
-// Purpose : The function enables and disables antialiasing in Open GL (for points, lines and polygons).
-//=======================================================================
+/*!
+  Enables and disables antialiasing in Open GL (for points, lines and polygons).
+  \param on - if it is true, antialiasing is enabled
+*/
 void GLViewer_Drawer::setAntialiasing(const bool on)
 {
-       if (on)
-       {
+        if (on)
+        {
     glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
     glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
 
-               glEnable(GL_POINT_SMOOTH);
-               glEnable(GL_LINE_SMOOTH);
-               glEnable(GL_POLYGON_SMOOTH);
-               glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
-               glEnable (GL_BLEND);
-       }
-       else
-       {
-               glDisable(GL_POINT_SMOOTH);
-               glDisable(GL_LINE_SMOOTH);
-               glDisable(GL_POLYGON_SMOOTH);
-               glBlendFunc (GL_ONE, GL_ZERO);
-               glDisable (GL_BLEND);
-       }
+                glEnable(GL_POINT_SMOOTH);
+                glEnable(GL_LINE_SMOOTH);
+                glEnable(GL_POLYGON_SMOOTH);
+                glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
+                glEnable (GL_BLEND);
+        }
+        else
+        {
+                glDisable(GL_POINT_SMOOTH);
+                glDisable(GL_LINE_SMOOTH);
+                glDisable(GL_POLYGON_SMOOTH);
+                glBlendFunc (GL_ONE, GL_ZERO);
+                glDisable (GL_BLEND);
+        }
 }
 
-//======================================================================
-// Function: loadTexture
-// Purpose :
-//=======================================================================
+/*! Loads texture from file
+  \param fileName - the name of texture file
+  \param x_size   - the horizontal size of picture ( less or equal texture horizontal size )
+  \param y_size   - the vertical size of picture ( less or equal texture vertical size )
+  \param t_size   - the size of texture ( texture vertical size equals texture horizontal size )
+*/
 GLuint GLViewer_Drawer::loadTexture( const QString& fileName,
                                      GLint* x_size,
                                      GLint* y_size,
@@ -620,10 +650,12 @@ GLuint GLViewer_Drawer::loadTexture( const QString& fileName,
     return texture;
 }
 
-//======================================================================
-// Function: drawTexture
-// Purpose :
-//=======================================================================
+/*! Draw square texture
+   \param texture - the texture ID
+   \param size    - the size of square texture
+   \param x       - x coord
+   \param y       - y coord
+*/
 void GLViewer_Drawer::drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y )
 {
     /*float xScale = myXScale;
@@ -660,10 +692,13 @@ void GLViewer_Drawer::drawTexture( GLuint texture, GLint size, GLfloat x, GLfloa
   drawTexture( texture, size, size, x, y );
 }
 
-//======================================================================
-// Function: drawTexture
-// Purpose :
-//=======================================================================
+/*! Draw texture
+   \param texture - the texture ID
+   \param x_size  - the horizontal size of texture
+   \param y_size  - the vertical size of texture
+   \param x       - x coord
+   \param y       - y coord
+*/
 void GLViewer_Drawer::drawTexture( GLuint texture, GLint x_size, GLint y_size, GLfloat x, GLfloat y )
 {
     /*float xScale = myXScale;
@@ -699,10 +734,16 @@ void GLViewer_Drawer::drawTexture( GLuint texture, GLint x_size, GLint y_size, G
   drawTexturePart( texture, 1.0, 1.0, x_size, y_size, x, y );
 }
 
-//======================================================================
-// Function: drawTexture
-// Purpose :
-//=======================================================================
+/*! Draw texture part
+   \param texture - the texture ID
+   \param x_ratio - the horizontal ratio of texture part
+   \param y_ratio - the vertical ratio of texture part
+   \param x_size  - the horizontal size of texture
+   \param y_size  - the vertical size of texture
+   \param x       - x coord
+   \param y       - y coord
+   \param scale   - common scale factor ( if = 0, use drawer scales )
+*/
 void GLViewer_Drawer::drawTexturePart( GLuint texture,
                                        GLfloat x_ratio,
                                        GLfloat y_ratio,
@@ -750,10 +791,16 @@ void GLViewer_Drawer::drawTexturePart( GLuint texture,
   glDisable( GL_TEXTURE_2D );
 }
 
-//======================================================================
-// Function: drawText
-// Purpose :
-//=======================================================================
+/*!
+  Draw text
+  \param text - text to be drawn
+  \param xPos - x position
+  \param yPos - y position
+  \param color - color of text
+  \param theFont - font of text
+  \param theSeparator - letter separator
+  \param theFormat - text format (by default DTF_BITMAP)
+*/
 void GLViewer_Drawer::drawText( const QString& text, GLfloat xPos, GLfloat yPos,
                                 const QColor& color, QFont* theFont, int theSeparator, DisplayTextFormat theFormat )
 {
@@ -777,14 +824,13 @@ void GLViewer_Drawer::drawText( const QString& text, GLfloat xPos, GLfloat yPos,
   {
     glRasterPos2f( xPos, yPos );
     glListBase( displayListBase( theFont ) );
-    glCallLists( text.length(), GL_UNSIGNED_BYTE, text.local8Bit().data() );
+    glCallLists( text.length(), GL_UNSIGNED_BYTE, text.toLocal8Bit().data() );
   }
 }
 
-//======================================================================
-// Function: drawText
-// Purpose :
-//=======================================================================
+/*!
+  Draws object-text
+*/
 void GLViewer_Drawer::drawText( GLViewer_Object* theObject )
 {
   if( !theObject )
@@ -801,16 +847,21 @@ void GLViewer_Drawer::drawText( GLViewer_Object* theObject )
   drawText( aText->getText(), aPosX, aPosY, aText->getColor(), &aTmpVarFont, aText->getSeparator(), aText->getDisplayTextFormat() );
 }
 
-//======================================================================
-// Function: drawGLText
-// Purpose :
-//=======================================================================
+/*! Draw text
+   \param text      - the text string
+   \param x         - x coord
+   \param y         - y coord
+   \param hPosition - horizontal alignment
+   \param vPosition - vertical alignment
+   \param color     - text color
+   \param smallFont - font format
+*/
 void GLViewer_Drawer::drawGLText( QString text, float x, float y,
                                   int hPosition, int vPosition, QColor color, bool smallFont )
 {
   QFont aFont( myFont );
   if( smallFont )
-    aFont.setPointSize( aFont.pointSize() * 0.8 );
+    aFont.setPointSize( int(aFont.pointSize() * 0.8) );
 
   GLfloat scale = textScale() > 0. ? textScale() : 1.;
 
@@ -838,10 +889,9 @@ void GLViewer_Drawer::drawGLText( QString text, float x, float y,
   drawText( text, x, y, color, &aFont, 2, myTextFormat );
 }
 
-//======================================================================
-// Function: textRect
-// Purpose :
-//=======================================================================
+/*!
+  \return a rectangle of text (without viewer scale)
+*/
 GLViewer_Rect GLViewer_Drawer::textRect( const QString& text ) const
 {
   GLfloat scale = textScale() > 0. ? textScale() : 1.;
@@ -853,10 +903,11 @@ GLViewer_Rect GLViewer_Drawer::textRect( const QString& text ) const
   return GLViewer_Rect( 0, width, height, 0 );
 }
 
-//======================================================================
-// Function: drawRectangle
-// Purpose :
-//=======================================================================
+/*!
+  Draws rectangle
+  \param rect - instance of primitive
+  \param color - color of primitive
+*/
 void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, QColor color )
 {
   if( !rect )
@@ -880,10 +931,12 @@ void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, QColor color )
   glEnd();
 }
 
-//======================================================================
-// Function: translateToHPGL
-// Purpose :
-//=======================================================================
+/*!
+  Saves object to file with format of HPGL
+  \param hFile - file
+  \param aViewerCS - viewer co-ordinate system
+  \param aHPGLCS - paper co-ordinate system
+*/
 bool GLViewer_Drawer::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS )
 {
     bool result = true;
@@ -892,10 +945,12 @@ bool GLViewer_Drawer::translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aView
     return result;
 }
 
-//======================================================================
-// Function: translateToPS
-// Purpose :
-//=======================================================================
+/*!
+  Saves object to file with format of PostScript
+  \param hFile - file
+  \param aViewerCS - viewer co-ordinate system
+  \param aPSCS - paper co-ordinate system
+*/
 bool GLViewer_Drawer::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
 {
     bool result = true;
@@ -905,10 +960,12 @@ bool GLViewer_Drawer::translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewer
 }
 
 #ifdef WIN32
-//======================================================================
-// Function: translateToEMF
-// Purpose :
-//=======================================================================
+/*!
+  Saves object to file with format of EMF
+  \param hFile - file
+  \param aViewerCS - viewer co-ordinate system
+  \param aEMFCS - paper co-ordinate system
+*/
 bool GLViewer_Drawer::translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
 {
     bool result = true;
@@ -918,12 +975,17 @@ bool GLViewer_Drawer::translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS,
 }
 #endif
 
-//======================================================================
-// Function: drawRectangle
-// Purpose :
-//=======================================================================
+/*!
+  Draws rectangle
+  \param rect - instance of primitive
+  \param lineWidth - width of line
+  \param gap - gap of rectangle
+  \param color - color of primitive
+  \param filled - if it is true, then rectangle will be drawn filled with color "fillingColor"
+  \param fillingColor - color of filling
+*/
 void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, GLfloat lineWidth, GLfloat gap,
-                                    QColor color, bool filled, QColor fillingColor )
+                                     QColor color, bool filled, QColor fillingColor )
 {
   if( !rect )
     return;
@@ -959,10 +1021,12 @@ void GLViewer_Drawer::drawRectangle( GLViewer_Rect* rect, GLfloat lineWidth, GLf
   glEnd();
 }
 
-//======================================================================
-// Function: drawContour
-// Purpose :
-//=======================================================================
+/*!
+  Draws contour
+  \param pntList - list of points
+  \param color - color of contour
+  \param lineWidth - width of line
+*/
 void GLViewer_Drawer::drawContour( const GLViewer_PntList& pntList, QColor color, GLfloat lineWidth )
 {
   glColor3f( ( GLfloat )color.red() / 255,
@@ -971,18 +1035,22 @@ void GLViewer_Drawer::drawContour( const GLViewer_PntList& pntList, QColor color
   glLineWidth( lineWidth );
   
   glBegin( GL_LINES );
-  QValueList<GLViewer_Pnt>::const_iterator it = pntList.begin();
+  QList<GLViewer_Pnt>::const_iterator it = pntList.begin();
   for( ; it != pntList.end(); ++it )
     glVertex2f( (*it).x(), (*it).y() );
   glEnd();
 }
 
-//======================================================================
-// Function: drawContour
-// Purpose :
-//=======================================================================
+/*!
+  Draws rectangular contour
+  \param rect - instance of rectangle
+  \param color - color of primitive
+  \param lineWidth - width of line
+  \param pattern - pattern of line
+  \param isStripe - enables line stipple
+*/
 void GLViewer_Drawer::drawContour( GLViewer_Rect* rect, QColor color, GLfloat lineWidth,
-                                  GLushort pattern, bool isStripe )
+                                   GLushort pattern, bool isStripe )
 {
   float x1 = rect->left();
   float x2 = rect->right();
@@ -1011,26 +1079,30 @@ void GLViewer_Drawer::drawContour( GLViewer_Rect* rect, QColor color, GLfloat li
   glDisable( GL_LINE_STIPPLE );
 }
 
-//======================================================================
-// Function: drawPolygon
-// Purpose :
-//=======================================================================
+/*!
+  Draws polygon
+  \param pntList - list of points
+  \param color - color of polygon
+*/
 void GLViewer_Drawer::drawPolygon( const GLViewer_PntList& pntList, QColor color )
 {
   glColor3f( ( GLfloat )color.red() / 255,
     ( GLfloat )color.green() / 255,
     ( GLfloat )color.blue() / 255 );
   glBegin( GL_POLYGON );
-  QValueList<GLViewer_Pnt>::const_iterator it = pntList.begin();
+  QList<GLViewer_Pnt>::const_iterator it = pntList.begin();
   for( ; it != pntList.end(); ++it )
     glVertex2f( (*it).x(), (*it).y() );
   glEnd();
 }
 
-//======================================================================
-// Function: drawPolygon
-// Purpose :
-//=======================================================================
+/*!
+  Draws rectangle
+  \param rect - instance of rectangle
+  \param color - color of polygon
+  \param pattern - pattern of line
+  \param isStripe - enables line stipple
+*/
 void GLViewer_Drawer::drawPolygon( GLViewer_Rect* rect, QColor color,
                                       GLushort pattern, bool isStripe )
 {
@@ -1058,11 +1130,14 @@ void GLViewer_Drawer::drawPolygon( GLViewer_Rect* rect, QColor color,
   glDisable( GL_LINE_STIPPLE );
 }
 
-//======================================================================
-// Function: drawVertex
-// Purpose :
-//=======================================================================
 GLubyte rasterVertex[5] = { 0x70, 0xf8, 0xf8, 0xf8, 0x70 };
+
+/*!
+  Draws vertex
+  \param x - x position
+  \param y - y position
+  \param color - color of vertex
+*/
 void GLViewer_Drawer::drawVertex( GLfloat x, GLfloat y, QColor color )
 {
   glColor3f( ( GLfloat )color.red() / 255, ( GLfloat )color.green() / 255, ( GLfloat )color.blue() / 255 );
@@ -1070,11 +1145,14 @@ void GLViewer_Drawer::drawVertex( GLfloat x, GLfloat y, QColor color )
   glBitmap( 5, 5, 2, 2, 0, 0, rasterVertex );
 }
 
-//======================================================================
-// Function: drawCross
-// Purpose :
-//=======================================================================
 GLubyte rasterCross[7] =  { 0x82, 0x44, 0x28, 0x10, 0x28, 0x44, 0x82 };
+
+/*!
+  Draws cross
+  \param x - x position
+  \param y - y position
+  \param color - color of cross
+*/
 void GLViewer_Drawer::drawCross( GLfloat x, GLfloat y, QColor color )
 {
   glColor3f( ( GLfloat )color.red() / 255, ( GLfloat )color.green() / 255, ( GLfloat )color.blue() / 255 );
@@ -1082,14 +1160,22 @@ void GLViewer_Drawer::drawCross( GLfloat x, GLfloat y, QColor color )
   glBitmap( 7, 7, 3, 3, 0, 0, rasterCross );
 }
 
-//======================================================================
-// Function: drawArrow
-// Purpose :
-//=======================================================================
+/*!
+  Draws arrow
+  \param red, green, blue - components of color
+  \param lineWidth - width of line
+  \param staff - 
+  \param length - length of arrow
+  \param width - width of arrow
+  \param x - x position
+  \param y - y position
+  \param angle - angle of arrow
+  \param filled - drawn as filled
+*/
 void GLViewer_Drawer::drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
-                                GLfloat lineWidth,
-                                GLfloat staff, GLfloat length, GLfloat width,
-                                GLfloat x, GLfloat y, GLfloat angle, GLboolean filled )
+                                 GLfloat lineWidth,
+                                 GLfloat staff, GLfloat length, GLfloat width,
+                                 GLfloat x, GLfloat y, GLfloat angle, GLboolean filled )
 {
   GLfloat vx1 = x;
   GLfloat vy1 = y + staff + length;