1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Drawer.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_DRAWER_H
28 #define GLVIEWER_DRAWER_H
42 #include "GLViewer_Defs.h"
43 #include "GLViewer_Geom.h"
45 class GLViewer_Object;
47 class GLViewer_CoordSystem;
50 #pragma warning( disable:4251 )
53 * Struct GLViewer_TexIdStored
54 * Structure for store information about texture
56 struct GLVIEWER_API GLViewer_TexIdStored
67 * Struct GLViewer_TexFindId
68 * Structure for srorage information about texture font
70 struct GLVIEWER_API GLViewer_TexFindId
72 //! Font family description
78 //! Underline parameter
84 //! Overloaded operator for using struct as MAP key
85 bool operator < (const GLViewer_TexFindId theStruct) const
87 if ( myViewPortId != theStruct.myViewPortId )
88 return myViewPortId < theStruct.myViewPortId;
89 else if ( myPointSize != theStruct.myPointSize )
90 return myPointSize < theStruct.myPointSize;
91 else if ( myIsBold != theStruct.myIsBold )
92 return myIsBold < theStruct.myIsBold;
93 else if ( myIsItal != theStruct.myIsItal )
94 return myIsItal < theStruct.myIsItal;
95 else if ( myIsUndl != theStruct.myIsUndl )
96 return myIsUndl < theStruct.myIsUndl;
98 return myFontFamily < theStruct.myFontFamily;
103 \class GLViewer_TexFont
104 Font for GLViewer_Drawer, Drawing bitmap and texture fonts in GLViewer
107 class GLVIEWER_API GLViewer_TexFont
110 //! A default constructor
114 * \param theFont - a base font
115 * \param theSeparator - separator between letters
116 * \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
117 * \param theMinMagFilter - min/mag filter, affects text sharpness
119 GLViewer_TexFont( QFont* theFont,
120 int theSeparator = 2,
121 bool theIsResizeable = false,
122 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
126 //! Generating font texture
127 bool generateTexture();
128 //! Drawing string theStr in point with coords theX and theY
129 void drawString( QString theStr,
132 GLfloat theScale = 1.0 );
134 //! Returns separator between letters
135 int getSeparator(){ return mySeparator; }
136 //! Installing separator between letters
137 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
139 //! Returns width of string in pixels
140 int getStringWidth( QString theString );
141 //! Returns height of string in pixels
142 int getStringHeight();
144 //! Clears all generated fonts
145 static void clearTextBases();
147 //! Map for strorage generated texture fonts
148 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
149 //! Map for strorage generated bitmaps fonts
150 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
153 //! Initializes font parameters
157 //! Number of characters in the font texture
159 //! Array of letter width
161 //! Array of letter positions in texture
163 //! Pointer to base font
167 //! Font texture width
169 //! Font texture height
171 //! Separator between letters
173 //! Flag controlling scalability of this texmapped font
176 GLuint myMinMagFilter;
179 //! Diagnostic information
184 \class GLViewer_Drawer
185 Drawer for GLViewer_Objects.
186 Drawer creates only one times per one type of object
188 class GLVIEWER_API GLViewer_Drawer
191 //! Text position relatively object
201 // Objects status ( needs for change colors )
219 virtual ~GLViewer_Drawer();
221 //! Main method which drawing object in GLViewer
223 *\param xScale - current scale along X-direction
224 *\param yScale - current scale along Y-direction
225 *\param onlyUpdate - = true if only update highlight-select information
227 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
229 //! Adds object to drawer display list
230 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
231 //! Clears drawer display list
232 virtual void clear(){ myObjects.clear(); }
234 //! Returns object type (needs for dynamic search of right drawer )
235 QString getObjectType() const { return myObjectType; }
237 //! Returns object priority
238 int getPriority() const { return myPriority; }
240 //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
241 void setAntialiasing(const bool on);
243 //! Clears all generated textures
244 static void destroyAllTextures();
246 //! A function translate object in to HPGL file on disk
248 *\param hFile the name of PostScript file chosen by user
249 *\param aViewerCS the GLViewer_CoordSystem of window
250 *\param aHPGLCS the GLViewer_CoordSystem of PostScript page
252 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
254 //! A function translate object in to PostScript file on disk
256 *\param hFile the name of PostScript file chosen by user
257 *\param aViewerCS the GLViewer_CoordSystem of window
258 *\param aPSCS the GLViewer_CoordSystem of PostScript page
260 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
263 //! A function translate object in to EMF file on disk
267 *\param dc the name of HDC associated with file chosen by user
268 *\param aViewerCS the GLViewer_CoordSystem of window
269 *\param aEMFCS the GLViewer_CoordSystem of EMF page
271 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
274 //! Loads texture from file
276 *\param fileName - the name of texture file
277 *\param x_size - the horizontal size of picture ( less or equal texture horizontal size )
278 *\param y_size - the vertical size of picture ( less or equal texture vertical size )
279 *\param t_size - the size of texture ( texture vertical size equals texture horizontal size )
281 static GLuint loadTexture( const QString& fileName,
286 //! Draw square texture
288 *\param texture - the texture ID
289 *\param size - the size of square texture
293 void drawTexture( GLuint texture,
300 *\param texture - the texture ID
301 *\param x_size - the horizontal size of texture
302 *\param y_size - the vertical size of texture
306 void drawTexture( GLuint texture,
312 //! Draw texture part
314 *\param texture - the texture ID
315 *\param x_ratio - the horizontal ratio of texture part
316 *\param y_ratio - the vertical ratio of texture part
317 *\param x_size - the horizontal size of texture
318 *\param y_size - the vertical size of texture
321 *\param scale - common scale factor ( if = 0, use drawer scales )
323 void drawTexturePart( GLuint texture,
336 *\param text - the text string
337 *\param xPos - x coord
338 *\param yPos - y coord
339 *\param color - text color
340 *\param aFont - base font of text
341 *\param theSeparator - letter separator
342 *\param DisplayTextFormat - text format
344 void drawText( const QString& text,
350 DisplayTextFormat = DTF_BITMAP );
354 *\param text - the text string
357 *\param hPosition - horizontal alignment
358 *\param vPosition - vertical alignment
359 *\param color - text color
360 *\param smallFont - font format
362 void drawGLText( QString text,
365 int hPosition = GLText_Center,
366 int vPosition = GLText_Center,
367 QColor color = Qt::black,
368 bool smallFont = false );
370 //! Sets a default font to be used by drawGLText method
372 *\param font - the default font
374 inline void setFont( const QFont& font ) { myFont = font; }
376 //! Returns a default font used by drawGLText method
377 inline QFont font() const { return myFont; }
379 //! Sets a default text displaying format to be used by drawGLText method
381 *\param format - the default text displaying format
383 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
385 //! Returns a default text displaying format used by drawGLText method
386 inline DisplayTextFormat textFormat() const { return myTextFormat; }
388 //! Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE)
390 *\param factor - scale factor
392 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
394 //! Returns a text string displaying scale factor
395 inline GLfloat textScale() const { return myTextScale; }
397 //! Returns a rectangle of text (without viewer scale)
398 GLViewer_Rect textRect( const QString& ) const;
401 //! Draw rectangle with predefined color
402 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
405 //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow
406 //* with predefined color
407 static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black,
408 bool = false, QColor = Qt::white );
409 static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
410 static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
411 static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool );
412 static void drawPolygon( const GLViewer_PntList&, QColor );
413 static void drawVertex( GLfloat, GLfloat, QColor );
414 static void drawCross( GLfloat, GLfloat, QColor );
415 static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
416 GLfloat, GLfloat, GLfloat, GLfloat,
417 GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE );
420 virtual void drawText( GLViewer_Object* theObject );
428 QList<GLViewer_Object*> myObjects;
429 //! List generated textures
432 //! Type of supporting object
433 QString myObjectType;
437 //! Default font for drawGLText() method
439 //! Default text displaying format for drawGLText() method
440 DisplayTextFormat myTextFormat;
442 //! Scale factor for text string draw, by default 0.125
443 //! (used only with text format DTF_TEXTURE_SCALABLE)
448 #pragma warning ( default:4251 )
451 #endif // GLVIEWER_DRAWER_H