Salome HOME
Initial version
[modules/gui.git] / src / GLViewer / GLViewer_Drawer.h
1 // File:      GLViewer_Drawer.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 /***************************************************************************
7 **  Class:   GLViewer_Drawer
8 **  Descr:   Drawer for GLViewer_Object
9 **  Module:  GLViewer
10 **  Created: UI team, 01.10.01
11 ****************************************************************************/
12 #ifndef GLVIEWER_DRAWER_H
13 #define GLVIEWER_DRAWER_H
14
15 #ifdef WNT
16 #include "windows.h"
17 #endif
18
19 #include <qcolor.h>
20 #include <qobject.h>
21 #include <qfile.h>
22 #include <qfont.h>
23 #include <qgl.h>
24
25 #include <GL/gl.h>
26
27 #include "GLViewer.h"
28 #include "GLViewer_Defs.h"
29
30 class GLViewer_Object;
31 class GLViewer_Text;
32 class GLViewer_AspectLine;
33 class GLViewer_CoordSystem;
34
35 #ifdef WNT
36 #pragma warning( disable:4251 )
37 #endif
38
39 struct GLVIEWER_EXPORT GLViewer_TexIdStored
40 {
41     GLuint      myTexFontId;
42     int         myTexFontWidth;
43     int         myTexFontHeight;
44 };
45
46 struct GLVIEWER_EXPORT GLViewer_TexFindId
47 {
48     QString     myFontString;
49     int         myViewPortId;
50     bool operator < (const GLViewer_TexFindId theStruct) const 
51     { 
52       if ( myViewPortId != theStruct.myViewPortId ) return myViewPortId < theStruct.myViewPortId; 
53       else return myFontString < theStruct.myFontString;
54     }
55 };
56
57 class GLVIEWER_EXPORT GLViewer_TexFont
58 {
59 public:
60     GLViewer_TexFont();
61     GLViewer_TexFont( QFont* theFont, int theSeparator = 2 );
62     ~GLViewer_TexFont();
63     
64     void            generateTexture();
65     void            drawString( QString theStr, GLdouble theX = 0.0, GLdouble theY = 0.0 );
66     
67     int             getSeparator(){ return mySeparator; }
68     void            setSeparator( int theSeparator ){ mySeparator = theSeparator; }
69     
70     int             getStringWidth( QString );
71     int             getStringHeight();
72     
73     static  QMap<GLViewer_TexFindId,GLViewer_TexIdStored> TexFontBase;
74     static  int         LastmyTexStoredId;
75     
76 protected:
77     int*            myWidths;
78     int*            myPositions;
79     QFont           myQFont;
80     GLuint          myTexFont;
81     int             myTexFontWidth;
82     int             myTexFontHeight;
83     int             mySeparator;
84 };
85
86 /***************************************************************************
87 **  Class:   GLViewer_Drawer
88 **  Descr:   Drawer for GLObject
89 **  Module:  GLViewer
90 **  Created: UI team, 03.10.01
91 ****************************************************************************/
92 class GLVIEWER_EXPORT GLViewer_Drawer: public QObject
93 {
94     Q_OBJECT
95     
96 public:
97     GLViewer_Drawer();
98     virtual ~GLViewer_Drawer();
99   
100     enum ObjectStatus { OS_Normal = 0, OS_Highlighted = 1, OS_Selected = 2 };
101     enum ClosedStatus { CS_CLOSED = 0, CS_OPEN = 1 };  
102     
103     virtual void                    create( float, float, bool ) = 0;  
104     
105     virtual void                    addObject( GLViewer_Object* theObject ){ myObjects.append( theObject ); }
106     virtual void                    clear(){ myObjects.clear(); }
107     
108     QString                         getObjectType(){ return myObjectType; }
109     
110     static void                     destroyAllTextures();
111     
112     virtual bool                    translateToHPGL( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aHPGLCS );
113     virtual bool                    translateToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ); 
114   
115 #ifdef WIN32
116     virtual bool                    translateToEMF( HDC hDC, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
117 #endif
118     
119     void                            drawText( const QString& text,
120                                               GLfloat xPos, GLfloat yPos,
121                                               const QColor& color,
122                                               QFont* aFont, int,
123                                               DisplayTextFormat = DTF_BITMAP );
124  protected:
125     virtual void                    drawText( GLViewer_Object* );
126     
127     float                           myXScale;
128     float                           myYScale;
129     
130     QValueList<GLViewer_Object*>    myObjects;
131     GLuint                          myTextList;
132     
133     QString                         myObjectType;
134 };
135
136 /***************************************************************************
137 **  Class:   GLViewer_MarkerDrawer
138 **  Descr:   Drawer for GLViewer_MarkerSet
139 **  Module:  GLViewer
140 **  Created: UI team, 03.10.01
141 ****************************************************************************/
142 #ifndef GLVIEWER_MARKERDRAWER_H
143 #define GLVIEWER_MARKERDRAWER_H
144
145 class GLVIEWER_EXPORT GLViewer_MarkerDrawer : public GLViewer_Drawer  
146 {
147 public:
148     GLViewer_MarkerDrawer();
149     ~GLViewer_MarkerDrawer();
150     
151     virtual void       create( float, float, bool );
152     
153 private:
154     void               drawMarker( float&, float&, float&, QColor&, GLViewer_AspectLine* );
155 };
156
157 #endif // GLVIEWER_MARKERDRAWER_H
158
159 /***************************************************************************
160 **  Class:   GLViewer_PolylineDrawer
161 **  Descr:   Drawer for GLViewer_Polyline
162 **  Module:  GLViewer
163 **  Created: UI team, 03.10.01
164 ****************************************************************************/
165 #ifndef GLVIEWER_POLYLINEDRAWER_H
166 #define GLVIEWER_POLYLINEDRAWER_H
167
168 class GLVIEWER_EXPORT GLViewer_PolylineDrawer : public GLViewer_Drawer  
169 {
170 public:
171     GLViewer_PolylineDrawer();
172     ~GLViewer_PolylineDrawer();
173     
174     virtual void       create( float, float, bool );    
175 };
176
177 #endif // GLVIEWER_POLYLINEDRAWER_H
178
179 /***************************************************************************
180 **  Class:   GLViewer_TextDrawer
181 **  Descr:   
182 **  Module:  GLViewer
183 **  Created: UI team, 27.02.04
184 ****************************************************************************/
185 #ifndef GLVIEWER_TEXTDRAWER
186 #define GLVIEWER_TEXTDRAWER
187
188 class GLVIEWER_EXPORT GLViewer_TextDrawer: public GLViewer_Drawer
189 {
190   
191 public:
192     GLViewer_TextDrawer();
193     ~GLViewer_TextDrawer();
194     
195     virtual void              create( float, float, bool );
196     void                      updateObjects(); //after update font
197 };
198
199 #endif // GLVIEWER_TEXTDRAWER
200
201 #ifdef WNT
202 #pragma warning ( default:4251 )
203 #endif
204
205 #endif // GLVIEWER_DRAWER_H