Version: 9.16.0
GLViewer_Drawer.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
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.
10//
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.
15//
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
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23// Author : OPEN CASCADE
24// File: GLViewer_Drawer.h
25// Created: November, 2004
26//
27#ifndef GLVIEWER_DRAWER_H
28#define GLVIEWER_DRAWER_H
29
30#ifdef WIN32
31#include "windows.h"
32#endif
33
34#include <QColor>
35#include <QFont>
36
37class QFile;
38
39#ifdef __APPLE__
40#include <OpenGL/gl.h>
41#else
42#include <GL/gl.h>
43#endif
44
45#include "GLViewer.h"
46#include "GLViewer_Defs.h"
47#include "GLViewer_Geom.h"
48
49class GLViewer_Object;
50class GLViewer_Rect;
52
53#ifdef WIN32
54#pragma warning( disable:4251 )
55#endif
61{
68};
69
75{
77 QString myFontFamily;
89 bool operator < (const GLViewer_TexFindId theStruct) const
90 {
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;
101 else
102 return myFontFamily < theStruct.myFontFamily;
103 }
104};
105
112{
113public:
117 /*
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
122 */
123 GLViewer_TexFont( QFont* theFont,
124 int theSeparator = 2,
125 bool theIsResizeable = false,
126 GLuint theMinMagFilter = GL_LINEAR/*_ATTENUATION*/ );
129
131 bool generateTexture();
133 void drawString( QString theStr,
134 GLdouble theX = 0.0,
135 GLdouble theY = 0.0,
136 GLfloat theScale = 1.0 );
137
139 int getSeparator(){ return mySeparator; }
141 void setSeparator( int theSeparator ){ mySeparator = theSeparator; }
142
144 int getStringWidth( QString theString );
146 int getStringHeight();
147
149 static void clearTextBases();
150
152 static QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
154 static QMap<GLViewer_TexFindId,GLuint> BitmapFontCache;
155
156private:
158 void init();
159
160private:
168 QFont myQFont;
170 GLuint myTexFont;
185};
186
193{
194public:
196 enum
197 {
198 GLText_Center = 0,
202 GLText_Bottom
203 };
204
205 // Objects status ( needs for change colors )
206 //enum ObjectStatus
207 //{
208 // OS_Normal = 0,
209 // OS_Highlighted,
210 // OS_Selected
211 //};
212
213 //
214 //enum ClosedStatus
215 //{
216 // CS_CLOSED = 0,
217 // CS_OPEN = 1
218 //};
219
223 virtual ~GLViewer_Drawer();
224
226 /*
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
230 */
231 virtual void create( float xScale, float yScale, bool onlyUpdate ) = 0;
232
234 virtual void addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
236 virtual void clear(){ myObjects.clear(); }
237
239 QString getObjectType() const { return myObjectType; }
240
242 int getPriority() const { return myPriority; }
243
245 void setAntialiasing(const bool on);
246
248 static void destroyAllTextures();
249
251
256 virtual bool translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
257
259
264 virtual bool translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
265
266#ifdef WIN32
268
275 virtual bool translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
276#endif
277
279
285 static GLuint loadTexture( const QString& fileName,
286 GLint* x_size = 0,
287 GLint* y_size = 0,
288 GLint* t_size = 0);
289
291
297 void drawTexture( GLuint texture,
298 GLint size,
299 GLfloat x,
300 GLfloat y );
301
303
310 void drawTexture( GLuint texture,
311 GLint x_size,
312 GLint y_size,
313 GLfloat x,
314 GLfloat y );
315
317
327 void drawTexturePart( GLuint texture,
328 GLfloat x_ratio,
329 GLfloat y_ratio,
330 GLfloat x_size,
331 GLfloat y_size,
332 GLfloat x,
333 GLfloat y,
334 GLfloat scale = 0 );
335
336
337
339
348 void drawText( const QString& text,
349 GLfloat xPos,
350 GLfloat yPos,
351 const QColor& color,
352 QFont* aFont,
353 int theSeparator,
355
357
366 void drawGLText( QString text,
367 float x,
368 float y,
369 int hPosition = GLText_Center,
370 int vPosition = GLText_Center,
371 QColor color = Qt::black,
372 bool smallFont = false );
373
375
378 inline void setFont( const QFont& font ) { myFont = font; }
379
381 inline QFont font() const { return myFont; }
382
384
387 inline void setTextFormat( const DisplayTextFormat format ) { myTextFormat = format; }
388
390 inline DisplayTextFormat textFormat() const { return myTextFormat; }
391
393
396 inline void setTextScale( const GLfloat factor ) { myTextScale = factor; }
397
399 inline GLfloat textScale() const { return myTextScale; }
400
402 GLViewer_Rect textRect( const QString& ) const;
403
404
406 static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black );
407
408protected:
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 );
422
424 virtual void drawText( GLViewer_Object* theObject );
425
427 float myXScale;
429 float myYScale;
430
435
440
442 QFont myFont;
445
448 GLfloat myTextScale;
449};
450
451#ifdef WIN32
452#pragma warning ( default:4251 )
453#endif
454
455#endif // GLVIEWER_DRAWER_H
#define GLVIEWER_API
Macro for exports.
Definition: GLViewer.h:37
DisplayTextFormat
Display Text Format of Objects.
Definition: GLViewer_Defs.h:47
@ DTF_BITMAP
Definition: GLViewer_Defs.h:50
void drawText(GLuint theTextList, const char *theText, GLdouble thePosition[3], GLfloat theColor[3])
Definition: OCCViewer_Trihedron.cxx:161
const QString const bool const double theScale
Definition: OCCViewer_ViewModel.cxx:975
bool operator<(const QList< QVariant > &v1, const QList< QVariant > &v2)
Definition: QtxPopupMgr.cxx:33
Class implementing mathematical model of 2D coordinate system.
Definition: GLViewer_CoordSystem.h:45
Definition: GLViewer_Drawer.h:193
int getPriority() const
Returns object priority.
Definition: GLViewer_Drawer.h:242
virtual void clear()
Clears drawer display list.
Definition: GLViewer_Drawer.h:236
QString getObjectType() const
Returns object type (needs for dynamic search of right drawer )
Definition: GLViewer_Drawer.h:239
GLuint myTextList
List generated textures.
Definition: GLViewer_Drawer.h:434
@ GLText_Left
Definition: GLViewer_Drawer.h:199
@ GLText_Top
Definition: GLViewer_Drawer.h:201
@ GLText_Right
Definition: GLViewer_Drawer.h:200
virtual void addObject(GLViewer_Object *theObject)
Adds object to drawer display list.
Definition: GLViewer_Drawer.h:234
GLfloat textScale() const
Returns a text string displaying scale factor.
Definition: GLViewer_Drawer.h:399
virtual void create(float xScale, float yScale, bool onlyUpdate)=0
Main method which drawing object in GLViewer.
void setFont(const QFont &font)
Sets a default font to be used by drawGLText method.
Definition: GLViewer_Drawer.h:378
QList< GLViewer_Object * > myObjects
List of objects.
Definition: GLViewer_Drawer.h:432
GLfloat myTextScale
Scale factor for text string draw, by default 0.125 (used only with text format DTF_TEXTURE_SCALABLE)
Definition: GLViewer_Drawer.h:448
QFont font() const
Returns a default font used by drawGLText method.
Definition: GLViewer_Drawer.h:381
DisplayTextFormat myTextFormat
Default text displaying format for drawGLText() method.
Definition: GLViewer_Drawer.h:444
void setTextScale(const GLfloat factor)
Sets a text string displaying scale factor (used only with text format DTF_TEXTURE_SCALABLE)
Definition: GLViewer_Drawer.h:396
QFont myFont
Default font for drawGLText() method.
Definition: GLViewer_Drawer.h:442
int myPriority
Dislay priority.
Definition: GLViewer_Drawer.h:439
QString myObjectType
Type of supporting object.
Definition: GLViewer_Drawer.h:437
float myYScale
Y scale factor.
Definition: GLViewer_Drawer.h:429
void setTextFormat(const DisplayTextFormat format)
Sets a default text displaying format to be used by drawGLText method.
Definition: GLViewer_Drawer.h:387
float myXScale
X Scale factor.
Definition: GLViewer_Drawer.h:427
DisplayTextFormat textFormat() const
Returns a default text displaying format used by drawGLText method.
Definition: GLViewer_Drawer.h:390
Definition: GLViewer_Object.h:65
Definition: GLViewer_Geom.h:69
Definition: GLViewer_Drawer.h:112
int * myWidths
Array of letter width.
Definition: GLViewer_Drawer.h:164
QFont myQFont
Pointer to base font.
Definition: GLViewer_Drawer.h:168
GLuint myMinMagFilter
Min/mag filter.
Definition: GLViewer_Drawer.h:180
int myFontHeight
Font height.
Definition: GLViewer_Drawer.h:182
static QMap< GLViewer_TexFindId, GLuint > BitmapFontCache
Map for strorage generated bitmaps fonts.
Definition: GLViewer_Drawer.h:154
int myMaxRowWidth
Diagnostic information.
Definition: GLViewer_Drawer.h:184
static QMap< GLViewer_TexFindId, GLViewer_TexIdStored > TexFontBase
Map for strorage generated texture fonts.
Definition: GLViewer_Drawer.h:152
int getSeparator()
Returns separator between letters.
Definition: GLViewer_Drawer.h:139
bool myIsResizeable
Flag controlling scalability of this texmapped font.
Definition: GLViewer_Drawer.h:178
int myTexFontWidth
Font texture width.
Definition: GLViewer_Drawer.h:172
int * myPositions
Array of letter positions in texture.
Definition: GLViewer_Drawer.h:166
GLuint myTexFont
Font texture ID.
Definition: GLViewer_Drawer.h:170
void setSeparator(int theSeparator)
Installing separator between letters.
Definition: GLViewer_Drawer.h:141
int myTexFontHeight
Font texture height.
Definition: GLViewer_Drawer.h:174
int myNbSymbols
Number of characters in the font texture.
Definition: GLViewer_Drawer.h:162
int mySeparator
Separator between letters.
Definition: GLViewer_Drawer.h:176
Quantity_Color color(const QColor &)
Convert QColor object to Quantity_Color object.
Definition: OCCViewer.cxx:28
Definition: GLViewer_Drawer.h:75
bool myIsBold
Bold parameter.
Definition: GLViewer_Drawer.h:79
long myViewPortId
View Port ID.
Definition: GLViewer_Drawer.h:87
bool myIsItal
Italic parameter.
Definition: GLViewer_Drawer.h:81
bool myIsUndl
Underline parameter.
Definition: GLViewer_Drawer.h:83
int myPointSize
Font Size.
Definition: GLViewer_Drawer.h:85
QString myFontFamily
Font family description.
Definition: GLViewer_Drawer.h:77
Definition: GLViewer_Drawer.h:61
int myTexFontHeight
texture height
Definition: GLViewer_Drawer.h:67
GLuint myTexFontId
Texture ID.
Definition: GLViewer_Drawer.h:63
int myTexFontWidth
Texture width.
Definition: GLViewer_Drawer.h:65