1 // Copyright (C) 2007-2023 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
40 #include <OpenGL/gl.h>
46 #include "GLViewer_Defs.h"
47 #include "GLViewer_Geom.h"
49 class GLViewer_Object;
51 class GLViewer_CoordSystem;
54 #pragma warning( disable:4251 )
57 * Struct GLViewer_TexIdStored
58 * Structure for store information about texture
60 struct GLVIEWER_API GLViewer_TexIdStored
71 * Struct GLViewer_TexFindId
72 * Structure for srorage information about texture font
74 struct GLVIEWER_API GLViewer_TexFindId
76 //! Font family description
82 //! Underline parameter
88 //! Overloaded operator for using struct as MAP key
89 bool operator < (const GLViewer_TexFindId theStruct) const
91 if ( myViewPortId != theStruct.myViewPortId )
92 return myViewPortId < theStruct.myViewPortId;
93 else if ( myPointSize != theStruct.myPointSize )
94 return myPointSize < theStruct.myPointSize;
95 else if ( myIsBold != theStruct.myIsBold )
96 return myIsBold < theStruct.myIsBold;
97 else if ( myIsItal != theStruct.myIsItal )
98 return myIsItal < theStruct.myIsItal;
99 else if ( myIsUndl != theStruct.myIsUndl )
100 return myIsUndl < theStruct.myIsUndl;
102 return myFontFamily < theStruct.myFontFamily;
107 \class GLViewer_TexFont
108 Font for GLViewer_Drawer, Drawing bitmap and texture fonts in GLViewer
111 class GLVIEWER_API GLViewer_TexFont
114 //! A default constructor
118 * \param theFont - a base font
119 * \param theSeparator - separator between letters
120 * \param theIsResizeable - specifies whether text drawn by this object can be scaled along with the scene
121 * \param theMinMagFilter - min/mag filter, affects text sharpness
123 GLViewer_TexFont( QFont* theFont,
124 int theSeparator = 2,
125 bool theIsResizeable = false,
126 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
130 //! Generating font texture
131 bool generateTexture();
132 //! Drawing string theStr in point with coords theX and theY
133 void drawString( QString theStr,
136 GLfloat theScale = 1.0 );
138 //! Returns separator between letters
139 int getSeparator(){ return mySeparator; }
140 //! Installing separator between letters
141 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
143 //! Returns width of string in pixels
144 int getStringWidth( QString theString );
145 //! Returns height of string in pixels
146 int getStringHeight();
148 //! Clears all generated fonts
149 static void clearTextBases();
151 //! Map for strorage generated texture fonts
152 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
153 //! Map for strorage generated bitmaps fonts
154 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
157 //! Initializes font parameters
161 //! Number of characters in the font texture
163 //! Array of letter width
165 //! Array of letter positions in texture
167 //! Pointer to base font
171 //! Font texture width
173 //! Font texture height
175 //! Separator between letters
177 //! Flag controlling scalability of this texmapped font
180 GLuint myMinMagFilter;
183 //! Diagnostic information
188 \class GLViewer_Drawer
189 Drawer for GLViewer_Objects.
190 Drawer creates only one times per one type of object
192 class GLVIEWER_API GLViewer_Drawer
195 //! Text position relatively object
205 // Objects status ( needs for change colors )
223 virtual ~GLViewer_Drawer();
225 //! Main method which drawing object in GLViewer
227 *\param xScale - current scale along X-direction
228 *\param yScale - current scale along Y-direction
229 *\param onlyUpdate - = true if only update highlight-select information
231 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
233 //! Adds object to drawer display list
234 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
235 //! Clears drawer display list
236 virtual void clear(){ myObjects.clear(); }
238 //! Returns object type (needs for dynamic search of right drawer )
239 QString getObjectType() const { return myObjectType; }
241 //! Returns object priority
242 int getPriority() const { return myPriority; }
244 //! The function enables and disables antialiasing in Open GL (for points, lines and polygons).
245 void setAntialiasing(const bool on);
247 //! Clears all generated textures
248 static void destroyAllTextures();
250 //! A function translate object in to HPGL file on disk
252 *\param hFile the name of PostScript file chosen by user
253 *\param aViewerCS the GLViewer_CoordSystem of window
254 *\param aHPGLCS the GLViewer_CoordSystem of PostScript page
256 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
258 //! A function translate object in to PostScript file on disk
260 *\param hFile the name of PostScript file chosen by user
261 *\param aViewerCS the GLViewer_CoordSystem of window
262 *\param aPSCS the GLViewer_CoordSystem of PostScript page
264 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
267 //! A function translate object in to EMF file on disk
271 *\param dc the name of HDC associated with file chosen by user
272 *\param aViewerCS the GLViewer_CoordSystem of window
273 *\param aEMFCS the GLViewer_CoordSystem of EMF page
275 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
278 //! Loads texture from file
280 *\param fileName - the name of texture file
281 *\param x_size - the horizontal size of picture ( less or equal texture horizontal size )
282 *\param y_size - the vertical size of picture ( less or equal texture vertical size )
283 *\param t_size - the size of texture ( texture vertical size equals texture horizontal size )
285 static GLuint loadTexture( const QString& fileName,
290 //! Draw square texture
292 *\param texture - the texture ID
293 *\param size - the size of square texture
297 void drawTexture( GLuint texture,
304 *\param texture - the texture ID
305 *\param x_size - the horizontal size of texture
306 *\param y_size - the vertical size of texture
310 void drawTexture( GLuint texture,
316 //! Draw texture part
318 *\param texture - the texture ID
319 *\param x_ratio - the horizontal ratio of texture part
320 *\param y_ratio - the vertical ratio of texture part
321 *\param x_size - the horizontal size of texture
322 *\param y_size - the vertical size of texture
325 *\param scale - common scale factor ( if = 0, use drawer scales )
327 void drawTexturePart( GLuint texture,
340 *\param text - the text string
341 *\param xPos - x coord
342 *\param yPos - y coord
343 *\param color - text color
344 *\param aFont - base font of text
345 *\param theSeparator - letter separator
346 *\param DisplayTextFormat - text format
348 void drawText( const QString& text,
354 DisplayTextFormat = DTF_BITMAP );
358 *\param text - the text string
361 *\param hPosition - horizontal alignment
362 *\param vPosition - vertical alignment
363 *\param color - text color
364 *\param smallFont - font format
366 void drawGLText( QString text,
369 int hPosition = GLText_Center,
370 int vPosition = GLText_Center,
371 QColor color = Qt::black,
372 bool smallFont = false );
374 //! Sets a default font to be used by drawGLText method
376 *\param font - the default font
378 inline void setFont( const QFont& font ) { myFont = font; }
380 //! Returns a default font used by drawGLText method
381 inline QFont font() const { return myFont; }
383 //! Sets a default text displaying format to be used by drawGLText method
385 *\param format - the default text displaying format
387 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
389 //! Returns a default text displaying format used by drawGLText method
390 inline DisplayTextFormat textFormat() const { return myTextFormat; }
392 //! Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE)
394 *\param factor - scale factor
396 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
398 //! Returns a text string displaying scale factor
399 inline GLfloat textScale() const { return myTextScale; }
401 //! Returns a rectangle of text (without viewer scale)
402 GLViewer_Rect textRect( const QString& ) const;
405 //! Draw rectangle with predefined color
406 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
409 //! Draw basic primitives: rectangle, contour, polygon, vertex, cross, arrow
410 //* with predefined color
411 static void drawRectangle( GLViewer_Rect*, GLfloat, GLfloat = 0, QColor = Qt::black,
412 bool = false, QColor = Qt::white );
413 static void drawContour( GLViewer_Rect*, QColor, GLfloat, GLushort, bool );
414 static void drawContour( const GLViewer_PntList&, QColor, GLfloat );
415 static void drawPolygon( GLViewer_Rect*, QColor, GLushort, bool );
416 static void drawPolygon( const GLViewer_PntList&, QColor );
417 static void drawVertex( GLfloat, GLfloat, QColor );
418 static void drawCross( GLfloat, GLfloat, QColor );
419 static void drawArrow( const GLfloat red, const GLfloat green, const GLfloat blue,
420 GLfloat, GLfloat, GLfloat, GLfloat,
421 GLfloat, GLfloat, GLfloat, GLboolean = GL_FALSE );
424 virtual void drawText( GLViewer_Object* theObject );
432 QList<GLViewer_Object*> myObjects;
433 //! List generated textures
436 //! Type of supporting object
437 QString myObjectType;
441 //! Default font for drawGLText() method
443 //! Default text displaying format for drawGLText() method
444 DisplayTextFormat myTextFormat;
446 //! Scale factor for text string draw, by default 0.125
447 //! (used only with text format DTF_TEXTURE_SCALABLE)
452 #pragma warning ( default:4251 )
455 #endif // GLVIEWER_DRAWER_H