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