1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Drawer.h
23 // Created: November, 2004
25 #ifndef GLVIEWER_DRAWER_H
26 #define GLVIEWER_DRAWER_H
41 #include "GLViewer_Defs.h"
42 #include "GLViewer_Geom.h"
44 class GLViewer_Object;
46 class GLViewer_CoordSystem;
49 #pragma warning( disable:4251 )
52 * Struct GLViewer_TexIdStored
53 * Structure for store information about texture
55 struct GLVIEWER_API GLViewer_TexIdStored
66 * Struct GLViewer_TexFindId
67 * Structure for srorage information about texture font
69 struct GLVIEWER_API GLViewer_TexFindId
71 //! Font family description
77 //! Underline parameter
83 //! Overloaded operator for using struct as MAP key
84 bool operator < (const GLViewer_TexFindId theStruct) const
86 if ( myViewPortId != theStruct.myViewPortId )
87 return myViewPortId < theStruct.myViewPortId;
88 else if ( myPointSize != theStruct.myPointSize )
89 return myPointSize < theStruct.myPointSize;
90 else if ( myIsBold != theStruct.myIsBold )
91 return myIsBold < theStruct.myIsBold;
92 else if ( myIsItal != theStruct.myIsItal )
93 return myIsItal < theStruct.myIsItal;
94 else if ( myIsUndl != theStruct.myIsUndl )
95 return myIsUndl < theStruct.myIsUndl;
97 return myFontFamily < theStruct.myFontFamily;
101 /***************************************************************************
102 ** Class: GLViewer_TexFont
103 ** Descr: Font for GLViewer_Drawer
105 ** Created: UI team, 03.10.01
106 ****************************************************************************/
109 * Class GLViewer_TexFont
110 * Drawing bitmap and texture fonts in GLViewer
112 class GLVIEWER_API GLViewer_TexFont
115 //! A default constructor
119 * \param theFont - a base font
120 * \param theSeparator - separator between letters
121 * \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
122 * \param theMinMagFilter - min/mag filter, affects text sharpness
124 GLViewer_TexFont( QFont* theFont,
125 int theSeparator = 2,
126 bool theIsResizeable = false,
127 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
131 //! Generating font texture
132 bool generateTexture();
133 //! Drawing string theStr in point with coords theX and theY
134 void drawString( QString theStr,
137 GLfloat theScale = 1.0 );
139 //! Returns separator between letters
140 int getSeparator(){ return mySeparator; }
141 //! Installing separator between letters
142 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
144 //! Returns width of string in pixels
145 int getStringWidth( QString theString );
146 //! Returns height of string in pixels
147 int getStringHeight();
149 //! Clears all generated fonts
150 static void clearTextBases();
152 //! Map for strorage generated texture fonts
153 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
154 //! Map for strorage generated bitmaps fonts
155 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
158 //! Initializes font parameters
162 //! Number of characters in the font texture
164 //! Array of letter width
166 //! Array of letter positions in texture
168 //! Pointer to base font
172 //! Font texture width
174 //! Font texture height
176 //! Separator between letters
178 //! Flag controlling scalability of this texmapped font
181 GLuint myMinMagFilter;
184 //! Diagnostic information
188 /***************************************************************************
189 ** Class: GLViewer_Drawer
190 ** Descr: Drawer for GLObject
192 ** Created: UI team, 03.10.01
193 ****************************************************************************/
195 * Class GLViewer_Drawer
196 * Drawer for GLViewer_Objects.
197 * Drawer creates only one times per one type of object
199 class GLVIEWER_API GLViewer_Drawer
202 //! Text position relatively object
212 // Objects status ( needs for change colors )
230 virtual ~GLViewer_Drawer();
232 //! Main method which drawing object in GLViewer
234 *\param xScale - current scale along X-direction
235 *\param yScale - current scale along Y-direction
236 *\param onlyUpdate - = true if only update highlight-select information
238 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
240 //! Adds object to drawer display list
241 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
242 //! Clears drawer display list
243 virtual void clear(){ myObjects.clear(); }
245 //! Returns object type (needs for dynamic search of right drawer )
246 QString getObjectType() const { return myObjectType; }
248 //! Returns object priority
249 int getPriority() const { return myPriority; }
251 //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
252 void setAntialiasing(const bool on);
254 //! Clears all generated textures
255 static void destroyAllTextures();
257 //! A function translate object in to HPGL file on disk
259 *\param hFile the name of PostScript file chosen by user
260 *\param aViewerCS the GLViewer_CoordSystem of window
261 *\param aHPGLCS the GLViewer_CoordSystem of PostScript page
263 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
265 //! A function translate object in to PostScript file on disk
267 *\param hFile the name of PostScript file chosen by user
268 *\param aViewerCS the GLViewer_CoordSystem of window
269 *\param aPSCS the GLViewer_CoordSystem of PostScript page
271 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
274 //! A function translate object in to EMF file on disk
278 *\param dc the name of HDC associated with file chosen by user
279 *\param aViewerCS the GLViewer_CoordSystem of window
280 *\param aEMFCS the GLViewer_CoordSystem of EMF page
282 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
285 //! Loads texture from file
287 *\param fileName - the name of texture file
288 *\param x_size - the horizontal size of picture ( less or equal texture horizontal size )
289 *\param y_size - the vertical size of picture ( less or equal texture vertical size )
290 *\param t_size - the size of texture ( texture vertical size equals texture horizontal size )
292 static GLuint loadTexture( const QString& fileName,
297 //! Draw square texture
299 *\param texture - the texture ID
300 *\param size - the size of square texture
304 void drawTexture( GLuint texture,
311 *\param texture - the texture ID
312 *\param x_size - the horizontal size of texture
313 *\param y_size - the vertical size of texture
317 void drawTexture( GLuint texture,
323 //! Draw texture part
325 *\param texture - the texture ID
326 *\param x_ratio - the horizontal ratio of texture part
327 *\param y_ratio - the vertical ratio of texture part
328 *\param x_size - the horizontal size of texture
329 *\param y_size - the vertical size of texture
332 *\param scale - common scale factor ( if = 0, use drawer scales )
334 void drawTexturePart( GLuint texture,
347 *\param text - the text string
348 *\param xPos - x coord
349 *\param yPos - y coord
350 *\param color - text color
351 *\param aFont - base font of text
352 *\param theSeparator - letter separator
353 *\param DisplayTextFormat - text format
355 void drawText( const QString& text,
361 DisplayTextFormat = DTF_BITMAP );
365 *\param text - the text string
368 *\param hPosition - horizontal alignment
369 *\param vPosition - vertical alignment
370 *\param color - text color
371 *\param smallFont - font format
373 void drawGLText( QString text,
376 int hPosition = GLText_Center,
377 int vPosition = GLText_Center,
378 QColor color = Qt::black,
379 bool smallFont = false );
381 //! Sets a default font to be used by drawGLText method
383 *\param font - the default font
385 inline void setFont( const QFont& font ) { myFont = font; }
387 //! Returns a default font used by drawGLText method
388 inline QFont font() const { return myFont; }
390 //! Sets a default text displaying format to be used by drawGLText method
392 *\param format - the default text displaying format
394 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
396 //! Returns a default text displaying format used by drawGLText method
397 inline DisplayTextFormat textFormat() const { return myTextFormat; }
399 //! Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE)
401 *\param factor - scale factor
403 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
405 //! Returns a text string displaying scale factor
406 inline GLfloat textScale() const { return myTextScale; }
408 //! Returns a rectangle of text (without viewer scale)
409 GLViewer_Rect textRect( const QString& ) const;
412 //! Draw rectangle with predefined color
413 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
416 //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow
417 //* with predefined color
418 static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black,
419 bool = false, QColor = Qt::white );
420 static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
421 static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
422 static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool );
423 static void drawPolygon( const GLViewer_PntList&, QColor );
424 static void drawVertex( GLfloat, GLfloat, QColor );
425 static void drawCross( GLfloat, GLfloat, QColor );
426 static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
427 GLfloat, GLfloat, GLfloat, GLfloat,
428 GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE );
431 virtual void drawText( GLViewer_Object* theObject );
439 QValueList<GLViewer_Object*> myObjects;
440 //! List generated textures
443 //! Type of supporting object
444 QString myObjectType;
448 //! Default font for drawGLText() method
450 //! Default text displaying format for drawGLText() method
451 DisplayTextFormat myTextFormat;
453 //! Scale factor for text string draw, by default 0.125
454 //! (used only with text format DTF_TEXTURE_SCALABLE)
459 #pragma warning ( default:4251 )
462 #endif // GLVIEWER_DRAWER_H