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