1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Widget.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_WIDGET_H
28 #define GLVIEWER_WIDGET_H
36 class GLViewer_ViewPort2d;
37 class GLViewer_CoordSystem;
40 \class GLViewer_Widget
41 Widget for visualization of OpenGL scene
43 class GLVIEWER_API GLViewer_Widget : public QGLWidget
49 /*! Parameters using for QOGLWidget as is
51 GLViewer_Widget( QWidget* theParent, const char* theName = 0 );
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; }
64 //! Returns scales on OpenGL scene along 3 directions
65 /*! in 2d scene zScale = 1.0 */
66 void getScale( GLfloat& xScale,
69 //! A function for installing the scales of OpenGL scene
70 void setScale( GLfloat xScale,
72 GLfloat zScaleGLfloat );
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 );
79 //! Returns rotation angle of Window in OpenGL global scene in degree
81 GLfloat getRotationAngle() const { return myRotationAnglePrev; }
82 //! A function for installing the rotation angle of Window in OpenGL global scene in degree
84 void setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
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 );
102 //! A function load picture from file with name theFileName and post it in center of global OpenGL scene
103 void setBackground( QString theFileName );
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();
110 //! A function translate background of window in to PostScript file on disk
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
116 virtual void translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
118 //! A function repaints OpenGL scene in export mode
119 /* Repaints all objects in only current view */
120 void exportRepaint();
123 //! A function translate background of window in to EMF file on disk
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
132 virtual void translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
136 //! Auxiliary function. Returns rect of window background in viewer coordinate system
137 void getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
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 );
150 virtual void paintEvent( QPaintEvent* );
151 virtual void mouseMoveEvent( QMouseEvent* );
152 virtual void mousePressEvent( QMouseEvent* );
153 virtual void mouseReleaseEvent( QMouseEvent* );
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* );
160 virtual bool event ( QEvent* );
168 //! Scale along X direction
170 //! Scale along Y direction
172 //! Scale along Z direction
176 //! Window offset along X direction
178 //! Window offset along Y direction
180 //! Window offset along Z direction
184 GLfloat myRotationStartX;
185 GLfloat myRotationStartY;
186 GLfloat myRotationStartZ;
187 GLfloat myRotationAngle;
188 GLfloat myRotationCenterX;
189 GLfloat myRotationCenterY;
190 GLfloat myRotationCenterZ;
191 GLfloat myRotationAnglePrev;
194 GLViewer_ViewPort2d* myViewPort;
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
202 //! Width of background image
204 //! Height of background image
206 //! Size of background image
207 int myBackgroundSize;
211 //! Needs for export repaint
215 #endif // GLVIEWER_WIDGET_H