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