Salome HOME
917391c24511090b81edb1f20a8d9c03b79eb506
[modules/gui.git] / src / GLViewer / GLViewer_Widget.h
1 // File:      GLViewer_Widget.h
2 // Created:   November, 2004
3 // Author:    OCC team
4 // Copyright (C) CEA 2004
5
6 /*! Class GLViewer_Widget
7  *  Class for visualization OpenGL scene (widget) for GLViewer
8  */
9 #ifndef GLVIEWER_WIDGET_H
10 #define GLVIEWER_WIDGET_H
11
12 #include "GLViewer.h"
13
14 #include <qgl.h>
15 #include <qfile.h>
16
17 class GLViewer_ViewPort2d;
18 class GLViewer_CoordSystem;
19
20 class GLVIEWER_API GLViewer_Widget : public QGLWidget
21 {
22   Q_OBJECT
23
24 public:
25   //! A constructor
26   /*! Parameters using for QOGLWidget as is 
27   */
28   GLViewer_Widget( QWidget* theParent, const char* theName = 0 );
29  
30   //! A destructor
31   ~GLViewer_Widget();
32
33   //! Returns parent GLViewer_ViewPort2d
34   /*! ViewPort2d because this class is not use for 3D Viewer */
35   GLViewer_ViewPort2d*   getViewPort() const { return myViewPort; }
36   //! Returns width of OpenGl Window
37   GLint                  getWidth() const { return myWidth; }
38   //! Returns height of OpenGl Window
39   GLint                  getHeight() const { return myHeight; }
40   
41   //! Returns scales on OpenGL scene along 3 directions
42   /*! in 2d scene zScale = 1.0 */
43   void                   getScale( GLfloat& xScale,
44                                    GLfloat& yScale,
45                                    GLfloat& zScale );
46   //! A function for installing the scales of OpenGL scene
47   void                   setScale( GLfloat xScale,
48                                    GLfloat yScale,
49                                    GLfloat zScaleGLfloat );
50   
51   //! Returns offset parameters of Window in OpenGL global scene
52   void                   getPan( GLfloat& xPan, GLfloat& yPan, GLfloat& zPan );
53   //! A function for installing the  offset parameters of Window in OpenGL global scene
54   void                   setPan( GLfloat xPan, GLfloat yPan, GLfloat zPan );
55   
56   //! Returns rotation angle of Window in OpenGL global scene in degree
57   /*! Only in 2D */
58   GLfloat                getRotationAngle() const { return myRotationAnglePrev; }
59   //! A function for installing the rotation angle of Window in OpenGL global scene in degree
60   /*! Only in 2D */
61   void                   setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
62
63   //! Returns start point of curren rotation of Window in OpenGL global scene
64   void                   getRotationStart( GLfloat& rotationStartX,
65                                            GLfloat& rotationStartY,
66                                            GLfloat& rotationStartZ );
67   //! A function for installing the start point of curren rotation of Window in OpenGL global scene
68   void                   setRotationStart( GLfloat rotationStartX,
69                                            GLfloat rotationStartY,
70                                            GLfloat rotationStartZ );
71   //! Returns parameters of current rotation
72   void                   getRotation( GLfloat& rotationAngle,
73                                       GLfloat& rotationCenterX,
74                                       GLfloat& rotationCenterY,
75                                       GLfloat& rotationCenterZ );
76   //! A function for installing the parameters of current rotation
77   void                   setRotation( GLfloat, GLfloat, GLfloat, GLfloat );
78
79   //! A function load picture from file with name theFileName and post it in center of global OpenGL scene
80   void                   setBackground( QString theFileName );
81   
82   //! A function add the tool tip with text theTTText on theTTRect rect to the widget window
83   void                   addToolTip( QString theTTText, QRect theTTRect );
84   //! A function remove tool tip form widget window
85   void                   removeToolTip();
86   
87   //! A function translate background of window in to PostScript file on disk
88   /*!
89    *\param hFile     the name of PostScript file chosen by user
90    *\param aViewerCS the GLViewer_CoordSystem of window
91    *\param aPSCS     the GLViewer_CoordSystem of PostScript page
92   */
93   virtual void           translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
94   
95   //! A function repaints OpenGL scene in export mode
96   /* Repaints all objects in only current view */
97   void                   exportRepaint();
98
99 #ifdef WIN32
100   //! A function translate background of window in to EMF file on disk
101   //! 
102   /*!
103    *\warning WIN32 only
104    *
105    *\param dc        the name of HDC associated with file chosen by user
106    *\param aViewerCS the GLViewer_CoordSystem of window
107    *\param aEMFCS    the GLViewer_CoordSystem of EMF page
108   */
109   virtual void           translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
110 #endif
111
112 private:
113   //! Auxiliary function. Returns rect of window background in viewer coordinate system
114   void                   getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
115   
116 protected:
117   /* Redefined QT methods */
118   //! A function is called before first display of window (create OpenGL scene)
119   virtual void           initializeGL();
120   //! A function is called in earch paint event of window
121   /* Calling by public method repaint() */
122   virtual void           paintGL();
123   //! A function is called in earch resize event of window
124   virtual void           resizeGL( int, int );
125   
126   
127   virtual void           paintEvent( QPaintEvent* );
128   virtual void           mouseMoveEvent( QMouseEvent* );
129   virtual void           mousePressEvent( QMouseEvent* );
130   virtual void           mouseReleaseEvent( QMouseEvent* );
131
132   /* Needs to redefine because Window must be updated highlight presentation when mouse enter window */
133   virtual void           enterEvent( QEvent* );
134   /* Needs to redefine because Window must be updated highlight presentation when mouse leave window */
135   virtual void           leaveEvent( QEvent* );
136   
137 private:
138   //! width of window
139   GLint                  myWidth;
140   //! height of window
141   GLint                  myHeight;
142   
143   //! Scale along X direction
144   GLfloat                myXScale;
145   //! Scale along Y direction
146   GLfloat                myYScale;
147   //! Scale along Z direction
148   /* equals 1 in 2D */
149   GLfloat                myZScale;
150
151   //! Window offset along X direction
152   GLfloat                myXPan;
153   //! Window offset along Y direction
154   GLfloat                myYPan;
155   //! Window offset along Z direction
156   /* equals 0 in 2D */
157   GLfloat                myZPan;
158
159   GLfloat                myRotationStartX;
160   GLfloat                myRotationStartY;
161   GLfloat                myRotationStartZ;
162   GLfloat                myRotationAngle;
163   GLfloat                myRotationCenterX;
164   GLfloat                myRotationCenterY;
165   GLfloat                myRotationCenterZ;
166   GLfloat                myRotationAnglePrev;
167   
168   GLboolean              myStart;
169   GLViewer_ViewPort2d*   myViewPort;
170   
171   //! True if background is loaded
172   bool                   isLoadBackground;
173   //! File name of background image
174   QString                myBackgroundFile;
175   //! Texture id of loaded background image
176   GLuint                 texName;
177   //! Width of background image
178   int                    myIW;
179   //! Height of background image
180   int                    myIH;
181   //! Size of background image
182   int                    myBackgroundSize;
183
184   QRect                  myToolTipRect;
185
186   //! Needs for export repaint
187   bool                   isExportMode;
188 };
189
190 #endif // GLVIEWER_WIDGET_H