Salome HOME
5d3f15e1d23579926e693ad56a8c73723f481f50
[modules/gui.git] / src / GLViewer / GLViewer_Grid.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  Author : OPEN CASCADE
23 // File:      GLViewer_Grid.h
24 // Created:   November, 2004
25 //
26 #ifndef GLVIEWER_GRID_H
27 #define GLVIEWER_GRID_H
28
29 #ifdef WIN32
30 #include "windows.h"
31 #endif
32
33 #include "GLViewer.h"
34
35 #include <GL/gl.h>
36 #include <GL/glu.h>
37
38 #ifdef WIN32
39 #pragma warning( disable:4251 )
40 #endif
41
42 /*! Class GLViewer_Grid
43   2D rectangular grid for GLViewer
44   Grid is adapt cells for current view
45 */
46
47 class GLVIEWER_API GLViewer_Grid 
48 {
49 public:
50   //! A default constructor
51   GLViewer_Grid();
52   //! A constructor
53   /*
54   * \param  width and \param height - width and height of grid 
55   * \param winW and \param winH     - width and height of window 
56   * \param xSize and \param ySize   - steps along x and y direction
57   * \param xPan and \param yPan     - offsets along x and y direction
58   * \param xScale and \param yScal  - scale factors along x and y direction
59   */
60   GLViewer_Grid( GLfloat width, GLfloat height,
61                  GLfloat winW, GLfloat winH,
62                  GLfloat xSize, GLfloat ySize,
63                  GLfloat xPan, GLfloat yPan,
64                  GLfloat xScale, GLfloat yScale );
65   ~GLViewer_Grid();
66
67   //! Draws grid
68   void                   draw();
69
70   //! Sets color of grid in RGB format
71   void                   setGridColor( GLfloat r, GLfloat g, GLfloat b );
72   //! Sets color of grid axes in RGB format
73   void                   setAxisColor( GLfloat r, GLfloat g, GLfloat b );
74   void                   setGridWidth( float );
75   //! Sets Radius of center point( begin coords )
76   void                   setCenterRadius( int );
77
78   //! Sets steps along x and y directions
79   void                   setSize( float xs, float ys );
80   //! Sets offset along x and y direction
81   void                   setPan( float xp, float yp );
82   //! Sets common scale factor along x and y direction
83   bool                   setZoom( float zoom );
84   //! Recomputes grid in new size and scale of view
85   void                   setResize( float winW, float winH, float Zoom );
86
87   void                   getSize( float&, float& ) const;
88   void                   getPan( float&, float& ) const;
89   void                   getScale( float&, float& ) const;
90
91   //! Sets step of scale
92   void                   setScaleFactor( int );
93   int                    getScaleFactor();
94
95 protected:
96   //! Initialize grid display list
97   bool                   initList();
98
99   GLuint                 myGridList;
100   GLfloat                myGridColor[3];
101   GLfloat                myAxisColor[3];
102   GLfloat                myGridHeight;
103   GLfloat                myGridWidth;
104   GLfloat                myWinW;
105   GLfloat                myWinH;
106   GLfloat                myXSize;
107   GLfloat                myYSize;
108   GLfloat                myXPan;
109   GLfloat                myYPan;
110   GLfloat                myXScale;
111   GLfloat                myYScale;
112   GLfloat                myLineWidth;
113   GLfloat                myCenterWidth;
114   GLint                  myCenterRadius;
115   GLint                  myScaleFactor;
116   GLboolean              myIsUpdate;
117 };
118
119 #ifdef WIN32
120 #pragma warning ( default:4251 )
121 #endif
122
123 #endif