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"
43 class GLViewer_Object;
45 class GLViewer_CoordSystem;
48 #pragma warning( disable:4251 )
51 * Struct GLViewer_TexIdStored
52 * Structure for store information about texture
54 struct GLVIEWER_API GLViewer_TexIdStored
65 * Struct GLViewer_TexFindId
66 * Structure for srorage information about texture font
68 struct GLVIEWER_API GLViewer_TexFindId
74 //! Overloaded operator for using struct as MAP key
75 bool operator < (const GLViewer_TexFindId theStruct) const
77 if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId;
78 else return myFontString < theStruct.myFontString;
82 /***************************************************************************
83 ** Class: GLViewer_TexFont
84 ** Descr: Font for GLViewer_Drawer
86 ** Created: UI team, 03.10.01
87 ****************************************************************************/
90 * Class GLViewer_TexFont
91 * Drawing bitmap and texture fonts in GLViewer
93 class GLVIEWER_API GLViewer_TexFont
96 //! A default constructor
100 * \param theFont - a base font
101 * \param theSeparator - separator between letters
102 * \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
103 * \param theMinMagFilter - min/mag filter, affects text sharpness
105 GLViewer_TexFont( QFont* theFont,
106 int theSeparator = 2,
107 bool theIsResizeable = false,
108 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
112 //! Generating font texture
113 void generateTexture();
114 //! Drawing string theStr in point with coords theX and theY
115 void drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
117 //! Returns separator between letters
118 int getSeparator(){ return mySeparator; }
119 //! Installing separator between letters
120 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
122 //! Returns width of string in pixels
123 int getStringWidth( QString theString );
124 //! Returns height of string in pixels
125 int getStringHeight();
127 //! Clears all generated fonts
128 static void clearTextBases();
130 //! Map for strorage generated texture fonts
131 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
132 //! Map for strorage generated bitmaps fonts
133 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
136 //! Array of letter width
138 //! Array of letter positions in texture
140 //! Pointer to base font
144 //! Font texture width
146 //! Font texture height
148 //! Separator between letters
150 //! Flag controlling scalability of this texmapped font
153 GLuint myMinMagFilter;
156 /***************************************************************************
157 ** Class: GLViewer_Drawer
158 ** Descr: Drawer for GLObject
160 ** Created: UI team, 03.10.01
161 ****************************************************************************/
163 * Class GLViewer_Drawer
164 * Drawer for GLViewer_Objects.
165 * Drawer creates only one times per one type of object
167 class GLVIEWER_API GLViewer_Drawer
170 //! Text position relatively object
180 // Objects status ( needs for change colors )
198 virtual ~GLViewer_Drawer();
200 //! Main method which drawing object in GLViewer
202 *\param xScale - current scale along X-direction
203 *\param yScale - current scale along Y-direction
204 *\param onlyUpdate - = true if only update highlight-select information
206 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
208 //! Adds object to drawer display list
209 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
210 //! Clears drawer display list
211 virtual void clear(){ myObjects.clear(); }
213 //! Returns object type (needs for dynamic search of right drawer )
214 QString getObjectType() const { return myObjectType; }
216 //! Returns object priority
217 int getPriority() const { return myPriority; }
219 //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
220 void setAntialiasing(const bool on);
222 //! Clears all generated textures
223 static void destroyAllTextures();
225 //! A function translate object in to HPGL file on disk
227 *\param hFile the name of PostScript file chosen by user
228 *\param aViewerCS the GLViewer_CoordSystem of window
229 *\param aHPGLCS the GLViewer_CoordSystem of PostScript page
231 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
233 //! A function translate object in to PostScript file on disk
235 *\param hFile the name of PostScript file chosen by user
236 *\param aViewerCS the GLViewer_CoordSystem of window
237 *\param aPSCS the GLViewer_CoordSystem of PostScript page
239 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
242 //! A function translate object in to EMF file on disk
246 *\param dc the name of HDC associated with file chosen by user
247 *\param aViewerCS the GLViewer_CoordSystem of window
248 *\param aEMFCS the GLViewer_CoordSystem of EMF page
250 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
253 //! Loads texture from file
255 *\param fileName - the name of texture file
256 *\param x_size - the horizontal size of picture ( less or equal texture horizontal size )
257 *\param y_size - the vertical size of picture ( less or equal texture vertical size )
258 *\param t_size - the size of texture ( texture vertical size equals texture horizontal size )
260 static GLuint loadTexture( const QString& fileName,
265 //! Draw square texture
267 *\param texture - the texture ID
268 *\param size - the size of square texture
272 void drawTexture( GLuint texture,
279 *\param texture - the texture ID
280 *\param x_size - the horizontal size of texture
281 *\param y_size - the vertical size of texture
285 void drawTexture( GLuint texture,
291 //! Draw texture part
293 *\param texture - the texture ID
294 *\param x_ratio - the horizontal ratio of texture part
295 *\param y_ratio - the vertical ratio of texture part
296 *\param x_size - the horizontal size of texture
297 *\param y_size - the vertical size of texture
300 *\param scale - common scale factor ( if = 0, use drawer scales )
302 void drawTexturePart( GLuint texture,
315 *\param text - the text string
316 *\param xPos - x coord
317 *\param yPos - y coord
318 *\param color - text color
319 *\param aFont - base font of text
320 *\param theSeparator - letter separator
321 *\param DisplayTextFormat - text format
323 void drawText( const QString& text,
329 DisplayTextFormat = DTF_BITMAP );
333 *\param text - the text string
336 *\param hPosition - horizontal alignment
337 *\param vPosition - vertical alignment
338 *\param color - text color
339 *\param smallFont - font format
341 void drawGLText( QString text,
344 int hPosition = GLText_Center,
345 int vPosition = GLText_Center,
346 QColor color = Qt::black,
347 bool smallFont = false );
349 //! Sets a default font to be used by drawGLText method
351 *\param font - the default font
353 inline void setFont( const QFont& font ) { myFont = font; }
355 //! Returns a default font used by drawGLText method
356 inline QFont font() const { return myFont; }
358 //! Sets a default text displaying format to be used by drawGLText method
360 *\param format - the default text displaying format
362 inline void setTextFormat( DisplayTextFormat format ) { myTextFormat = format; }
364 //! Returns a default text displaying format used by drawGLText method
365 inline DisplayTextFormat textFormat() const { return myTextFormat; }
367 //! Draw rectangle with predefined color
368 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
372 virtual void drawText( GLViewer_Object* theObject );
380 QValueList<GLViewer_Object*> myObjects;
381 //! List generated textures
384 //! Type of supporting object
385 QString myObjectType;
389 //! Default font for drawGLText() method
391 //! Default text displaying format for drawGLText() method
392 DisplayTextFormat myTextFormat;
396 #pragma warning ( default:4251 )
399 #endif // GLVIEWER_DRAWER_H