Salome HOME
0a1379cbdf24327dd8569311761bf9f2ce1ba17e
[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   //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
192   void                            setAntialiasing(const bool on);
193   
194   //! Clears all generated textures
195   static void                     destroyAllTextures();
196   
197   //! A function translate object in to HPGL file on disk
198   /*!
199    *\param hFile     the name of PostScript file chosen by user
200    *\param aViewerCS the GLViewer_CoordSystem of window
201    *\param aHPGLCS   the GLViewer_CoordSystem of PostScript page
202   */
203   virtual bool                    translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
204   
205   //! A function translate object in to PostScript file on disk
206   /*!
207    *\param hFile     the name of PostScript file chosen by user
208    *\param aViewerCS the GLViewer_CoordSystem of window
209    *\param aPSCS     the GLViewer_CoordSystem of PostScript page
210   */
211   virtual bool                    translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ); 
212   
213 #ifdef WIN32
214   //! A function translate object in to EMF file on disk
215   /*!
216    *\warning WIN32 only
217    *
218    *\param dc        the name of HDC associated with file chosen by user
219    *\param aViewerCS the GLViewer_CoordSystem of window
220    *\param aEMFCS    the GLViewer_CoordSystem of EMF page
221   */
222   virtual bool                    translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
223 #endif
224   
225   //! Loads texture from file
226   static GLuint                   loadTexture( const QString& fileName );
227
228   //! Draw square texture
229   /*!
230    *\param texture - the texture ID
231    *\param size    - the size of texture
232    *\param x       - x coord
233    *\param y       - y coord
234   */
235   void                            drawTexture( GLuint texture, GLint size, GLfloat x, GLfloat y );
236
237   //! Draw text string
238   /*!
239    *\param text              - the text string
240    *\param xPos              - x coord
241    *\param yPos              - y coord
242    *\param color             - text color
243    *\param aFont             - base font of text
244    *\param theSeparator      - letter separator
245    *\param DisplayTextFormat - text format
246   */
247   void                            drawText( const QString& text,
248                                             GLfloat xPos,
249                                             GLfloat yPos,
250                                             const QColor& color,
251                                             QFont* aFont,
252                                             int theSeparator,
253                                             DisplayTextFormat = DTF_BITMAP );
254
255   //! Draw text string
256   /*!
257    *\param text      - the text string
258    *\param x         - x coord
259    *\param y         - y coord
260    *\param hPosition - horizontal alignment
261    *\param vPosition - vertical alignment
262    *\param color     - text color
263    *\param smallFont - font format
264   */
265   void                            drawGLText( QString text,
266                                               float x,
267                                               float y,
268                                               int hPosition = GLText_Center,
269                                               int vPosition = GLText_Center,
270                                               QColor color = Qt::black,
271                                               bool smallFont = false );
272
273   //! Draw rectangle with predefined color
274   static void                     drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
275
276 protected:
277   //! Draw object text
278   virtual void                    drawText( GLViewer_Object* theObject );
279
280   //! X Scale factor
281   float                           myXScale;
282   //! Y scale factor
283   float                           myYScale;
284   
285   //! List of objects
286   QValueList<GLViewer_Object*>    myObjects;
287   //! List generated textures
288   GLuint                          myTextList;
289   
290   //! Type of supporting object
291   QString                         myObjectType;
292   //! Dislay priority
293   int                             myPriority;
294 };
295
296 #ifdef WNT
297 #pragma warning ( default:4251 )
298 #endif
299
300 #endif // GLVIEWER_DRAWER_H