Salome HOME
Update comments
[modules/gui.git] / src / GLViewer / GLViewer_Drawer.h
1 // File:      GLViewer_Drawer.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 #ifndef GLVIEWER_DRAWER_H
7 #define GLVIEWER_DRAWER_H
8
9 #ifdef WNT
10 #include "windows.h"
11 #endif
12
13 #include <qcolor.h>
14 #include <qobject.h>
15 #include <qfile.h>
16 #include <qfont.h>
17 #include <qgl.h>
18
19 #include <GL/gl.h>
20
21 #include "GLViewer.h"
22 #include "GLViewer_Defs.h"
23
24 class GLViewer_Object;
25 class GLViewer_Rect;
26 class GLViewer_CoordSystem;
27
28 #ifdef WNT
29 #pragma warning( disable:4251 )
30 #endif
31 /*! 
32  * Struct GLViewer_TexIdStored
33  * Structure for store information about texture
34  */
35 struct GLVIEWER_API GLViewer_TexIdStored
36 {
37   //! Texture ID
38   GLuint      myTexFontId;
39   //! Texture width
40   int         myTexFontWidth;
41   //! texture height
42   int         myTexFontHeight;
43 };
44
45 /*! 
46  * Struct GLViewer_TexFindId
47  * Structure for srorage information about texture font
48  */
49 struct GLVIEWER_API GLViewer_TexFindId
50 {
51   //! Font description
52   QString     myFontString;
53   //! View POrt ID
54   int         myViewPortId;
55   //! Overloaded operator for using struct as MAP key
56   bool operator < (const GLViewer_TexFindId theStruct) const 
57   { 
58     if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId; 
59     else return myFontString < theStruct.myFontString;
60   }
61 };
62
63 /***************************************************************************
64 **  Class:   GLViewer_TexFont
65 **  Descr:   Font for GLViewer_Drawer
66 **  Module:  GLViewer
67 **  Created: UI team, 03.10.01
68 ****************************************************************************/
69
70 /*! 
71  * Class GLViewer_TexFont
72  * Drawing bitmap and texture fonts in GLViewer
73  */
74 class GLVIEWER_API GLViewer_TexFont
75 {
76 public:
77   //! A default constructor
78   GLViewer_TexFont();
79   //! A constructor
80   /*
81   * \param theFont      - a base font
82   * \param theSeparator - separator between letters
83   */
84   GLViewer_TexFont( QFont* theFont, int theSeparator = 2 );
85   //! A destructor
86   ~GLViewer_TexFont();
87   
88   //! Generating font texture
89   void            generateTexture();
90   //! Drawing string theStr in point with coords theX and theY
91   void            drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
92   
93   //! Returns separator between letters
94   int             getSeparator(){ return mySeparator; }
95   //! Installing separator between letters
96   void            setSeparator( int theSeparator ){ mySeparator = theSeparator; }
97   
98   //! Returns width of string in pixels
99   int             getStringWidth( QString theString );
100   //! Returns height of string in pixels
101   int             getStringHeight();
102   
103   //! Clears all generated fonts
104   static void     clearTextBases();
105
106   //! Map for strorage generated texture fonts
107   static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
108   //! Map for strorage generated bitmaps fonts
109   static QMap<GLViewer_TexFindId,GLuint>               BitmapFontCache;
110   
111 protected:
112   //! Array of letter width
113   int*            myWidths;
114   //! Array of letter positions in texture
115   int*            myPositions;
116   //! Pointer to base font
117   QFont           myQFont;
118   //! Font texture ID
119   GLuint          myTexFont;
120   //! Font texture width
121   int             myTexFontWidth;
122   //! Font texture height
123   int             myTexFontHeight;
124   //! Separator between letters
125   int             mySeparator;
126 };
127
128 /***************************************************************************
129 **  Class:   GLViewer_Drawer
130 **  Descr:   Drawer for GLObject
131 **  Module:  GLViewer
132 **  Created: UI team, 03.10.01
133 ****************************************************************************/
134 /*! 
135  * Class GLViewer_Drawer
136  * Drawer for GLViewer_Objects.
137  * Drawer creates only one times per one type of object
138  */
139 class GLVIEWER_API GLViewer_Drawer
140 {
141 public:
142   //! Text position relatively object
143   enum
144   {
145     GLText_Center = 0,
146     GLText_Left,
147     GLText_Right,
148     GLText_Top,
149     GLText_Bottom
150   };
151
152   // Objects status ( needs for change colors )
153   //enum ObjectStatus
154   //{
155   //  OS_Normal = 0,
156   //  OS_Highlighted,
157   //  OS_Selected
158   //};
159   
160   // 
161   //enum ClosedStatus
162   //{
163   //  CS_CLOSED = 0,
164   //  CS_OPEN = 1
165   //};  
166
167   //! A constructor
168   GLViewer_Drawer();
169   //! A destructor
170   virtual ~GLViewer_Drawer();
171   
172   //! Main method which drawing object in GLViewer
173   /*
174   *\param xScale - current scale along X-direction
175   *\param yScale - current scale along Y-direction
176   *\param onlyUpdate - = true if only update highlight-select information
177   */
178   virtual void                    create( float xScale, float yScale, bool onlyUpdate ) = 0;  
179   
180   //! Adds object to drawer display list
181   virtual void                    addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
182   //! Clears drawer display list
183   virtual void                    clear(){ myObjects.clear(); }
184   
185   //! Returns object type (needs for dynamic search of right drawer ) 
186   QString                         getObjectType() const { return myObjectType; }
187
188   //! Returns object priority
189   int                             getPriority() const { return myPriority; }
190   
191   //! Clears all generated textures
192   static void                     destroyAllTextures();
193   
194   //! A function translate object in to HPGL file on disk
195   /*!
196    *\param hFile     the name of PostScript file chosen by user
197    *\param aViewerCS the GLViewer_CoordSystem of window
198    *\param aHPGLCS   the GLViewer_CoordSystem of PostScript page
199   */
200   virtual bool                    translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
201   
202   //! A function translate object in to PostScript file on disk
203   /*!
204    *\param hFile     the name of PostScript file chosen by user
205    *\param aViewerCS the GLViewer_CoordSystem of window
206    *\param aPSCS     the GLViewer_CoordSystem of PostScript page
207   */
208   virtual bool                    translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ); 
209   
210 #ifdef WIN32
211   //! A function translate object in to EMF file on disk
212   /*!
213    *\warning WIN32 only
214    *
215    *\param dc        the name of HDC associated with file chosen by user
216    *\param aViewerCS the GLViewer_CoordSystem of window
217    *\param aEMFCS    the GLViewer_CoordSystem of EMF page
218   */
219   virtual bool                    translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
220 #endif
221   
222   //! Loads texture from file
223   static GLuint                   loadTexture( const QString& fileName );
224
225   //! Draw square texture
226   /*!
227    *\param texture - the texture ID
228    *\param size    - the size of texture
229    *\param x       - x coord
230    *\param y       - y coord
231   */
232   void                            drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y );
233
234   //! Draw text string
235   /*!
236    *\param text              - the text string
237    *\param xPos              - x coord
238    *\param yPos              - y coord
239    *\param color             - text color
240    *\param aFont             - base font of text
241    *\param theSeparator      - letter separator
242    *\param DisplayTextFormat - text format
243   */
244   void                            drawText( const QString& text,
245                                             GLfloat xPos,
246                                             GLfloat yPos,
247                                             const QColor& color,
248                                             QFont* aFont,
249                                             int theSeparator,
250                                             DisplayTextFormat = DTF_BITMAP );
251
252   //! Draw text string
253   /*!
254    *\param text      - the text string
255    *\param x         - x coord
256    *\param y         - y coord
257    *\param hPosition - horizontal alignment
258    *\param vPosition - vertical alignment
259    *\param color     - text color
260    *\param smallFont - font format
261   */
262   void                            drawGLText( QString text,
263                                               float x,
264                                               float y,
265                                               int hPosition = GLText_Center,
266                                               int vPosition = GLText_Center,
267                                               QColor color = Qt::black,
268                                               bool smallFont = false );
269
270   //! Draw rectangle with predefined color
271   static void                     drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
272
273 protected:
274   //! Draw object text
275   virtual void                    drawText( GLViewer_Object* theObject );
276
277   //! X Scale factor
278   float                           myXScale;
279   //! Y scale factor
280   float                           myYScale;
281   
282   //! List of objects
283   QValueList<GLViewer_Object*>    myObjects;
284   //! List generated textures
285   GLuint                          myTextList;
286   
287   //! Type of supporting object
288   QString                         myObjectType;
289   //! Dislay priority
290   int                             myPriority;
291 };
292
293 #ifdef WNT
294 #pragma warning ( default:4251 )
295 #endif
296
297 #endif // GLVIEWER_DRAWER_H