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;
102 \class GLViewer_TexFont
103 Font for GLViewer_Drawer, Drawing bitmap and texture fonts in GLViewer
106 class GLVIEWER_API GLViewer_TexFont
109 //! A default constructor
113 * \param theFont - a base font
114 * \param theSeparator - separator between letters
115 * \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
116 * \param theMinMagFilter - min/mag filter, affects text sharpness
118 GLViewer_TexFont( QFont* theFont,
119 int theSeparator = 2,
120 bool theIsResizeable = false,
121 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
125 //! Generating font texture
126 bool generateTexture();
127 //! Drawing string theStr in point with coords theX and theY
128 void drawString( QString theStr,
131 GLfloat theScale = 1.0 );
133 //! Returns separator between letters
134 int getSeparator(){ return mySeparator; }
135 //! Installing separator between letters
136 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
138 //! Returns width of string in pixels
139 int getStringWidth( QString theString );
140 //! Returns height of string in pixels
141 int getStringHeight();
143 //! Clears all generated fonts
144 static void clearTextBases();
146 //! Map for strorage generated texture fonts
147 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
148 //! Map for strorage generated bitmaps fonts
149 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
152 //! Initializes font parameters
156 //! Number of characters in the font texture
158 //! Array of letter width
160 //! Array of letter positions in texture
162 //! Pointer to base font
166 //! Font texture width
168 //! Font texture height
170 //! Separator between letters
172 //! Flag controlling scalability of this texmapped font
175 GLuint myMinMagFilter;
178 //! Diagnostic information
183 \class GLViewer_Drawer
184 Drawer for GLViewer_Objects.
185 Drawer creates only one times per one type of object
187 class GLVIEWER_API GLViewer_Drawer
190 //! Text position relatively object
200 // Objects status ( needs for change colors )
218 virtual ~GLViewer_Drawer();
220 //! Main method which drawing object in GLViewer
222 *\param xScale - current scale along X-direction
223 *\param yScale - current scale along Y-direction
224 *\param onlyUpdate - = true if only update highlight-select information
226 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
228 //! Adds object to drawer display list
229 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
230 //! Clears drawer display list
231 virtual void clear(){ myObjects.clear(); }
233 //! Returns object type (needs for dynamic search of right drawer )
234 QString getObjectType() const { return myObjectType; }
236 //! Returns object priority
237 int getPriority() const { return myPriority; }
239 //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
240 void setAntialiasing(const bool on);
242 //! Clears all generated textures
243 static void destroyAllTextures();
245 //! A function translate object in to HPGL file on disk
247 *\param hFile the name of PostScript file chosen by user
248 *\param aViewerCS the GLViewer_CoordSystem of window
249 *\param aHPGLCS the GLViewer_CoordSystem of PostScript page
251 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
253 //! A function translate object in to PostScript file on disk
255 *\param hFile the name of PostScript file chosen by user
256 *\param aViewerCS the GLViewer_CoordSystem of window
257 *\param aPSCS the GLViewer_CoordSystem of PostScript page
259 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
262 //! A function translate object in to EMF file on disk
266 *\param dc the name of HDC associated with file chosen by user
267 *\param aViewerCS the GLViewer_CoordSystem of window
268 *\param aEMFCS the GLViewer_CoordSystem of EMF page
270 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
273 //! Loads texture from file
275 *\param fileName - the name of texture file
276 *\param x_size - the horizontal size of picture ( less or equal texture horizontal size )
277 *\param y_size - the vertical size of picture ( less or equal texture vertical size )
278 *\param t_size - the size of texture ( texture vertical size equals texture horizontal size )
280 static GLuint loadTexture( const QString& fileName,
285 //! Draw square texture
287 *\param texture - the texture ID
288 *\param size - the size of square texture
292 void drawTexture( GLuint texture,
299 *\param texture - the texture ID
300 *\param x_size - the horizontal size of texture
301 *\param y_size - the vertical size of texture
305 void drawTexture( GLuint texture,
311 //! Draw texture part
313 *\param texture - the texture ID
314 *\param x_ratio - the horizontal ratio of texture part
315 *\param y_ratio - the vertical ratio of texture part
316 *\param x_size - the horizontal size of texture
317 *\param y_size - the vertical size of texture
320 *\param scale - common scale factor ( if = 0, use drawer scales )
322 void drawTexturePart( GLuint texture,
335 *\param text - the text string
336 *\param xPos - x coord
337 *\param yPos - y coord
338 *\param color - text color
339 *\param aFont - base font of text
340 *\param theSeparator - letter separator
341 *\param DisplayTextFormat - text format
343 void drawText( const QString& text,
349 DisplayTextFormat = DTF_BITMAP );
353 *\param text - the text string
356 *\param hPosition - horizontal alignment
357 *\param vPosition - vertical alignment
358 *\param color - text color
359 *\param smallFont - font format
361 void drawGLText( QString text,
364 int hPosition = GLText_Center,
365 int vPosition = GLText_Center,
366 QColor color = Qt::black,
367 bool smallFont = false );
369 //! Sets a default font to be used by drawGLText method
371 *\param font - the default font
373 inline void setFont( const QFont& font ) { myFont = font; }
375 //! Returns a default font used by drawGLText method
376 inline QFont font() const { return myFont; }
378 //! Sets a default text displaying format to be used by drawGLText method
380 *\param format - the default text displaying format
382 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
384 //! Returns a default text displaying format used by drawGLText method
385 inline DisplayTextFormat textFormat() const { return myTextFormat; }
387 //! Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE)
389 *\param factor - scale factor
391 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
393 //! Returns a text string displaying scale factor
394 inline GLfloat textScale() const { return myTextScale; }
396 //! Returns a rectangle of text (without viewer scale)
397 GLViewer_Rect textRect( const QString& ) const;
400 //! Draw rectangle with predefined color
401 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
404 //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow
405 //* with predefined color
406 static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black,
407 bool = false, QColor = Qt::white );
408 static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
409 static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
410 static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool );
411 static void drawPolygon( const GLViewer_PntList&, QColor );
412 static void drawVertex( GLfloat, GLfloat, QColor );
413 static void drawCross( GLfloat, GLfloat, QColor );
414 static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
415 GLfloat, GLfloat, GLfloat, GLfloat,
416 GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE );
419 virtual void drawText( GLViewer_Object* theObject );
427 QValueList<GLViewer_Object*> myObjects;
428 //! List generated textures
431 //! Type of supporting object
432 QString myObjectType;
436 //! Default font for drawGLText() method
438 //! Default text displaying format for drawGLText() method
439 DisplayTextFormat myTextFormat;
441 //! Scale factor for text string draw, by default 0.125
442 //! (used only with text format DTF_TEXTURE_SCALABLE)
447 #pragma warning ( default:4251 )
450 #endif // GLVIEWER_DRAWER_H