Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GLViewer_Drawer.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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 
37 class 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 
49 class GLViewer_Object;
50 class GLViewer_Rect;
52 
53 #ifdef WIN32
54 #pragma warning( disable:4251 )
55 #endif
56 
61 {
63  GLuint myTexFontId;
68 };
69 
75 {
77  QString myFontFamily;
79  bool myIsBold;
81  bool myIsItal;
83  bool myIsUndl;
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 {
113 public:
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*/ );
128  ~GLViewer_TexFont();
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 
156 private:
158  void init();
159 
160 private:
164  int* myWidths;
168  QFont myQFont;
170  GLuint myTexFont;
185 };
186 
193 {
194 public:
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 
221  GLViewer_Drawer();
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
267 
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 
408 protected:
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 
434  GLuint myTextList;
435 
437  QString myObjectType;
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