1 // Copyright (C) 2005 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : OPEN CASCADE
22 // File: GLViewer_Widget.h
23 // Created: November, 2004
25 #ifndef GLVIEWER_WIDGET_H
26 #define GLVIEWER_WIDGET_H
33 class GLViewer_ViewPort2d;
34 class GLViewer_CoordSystem;
37 \class GLViewer_Widget
38 Widget for visualization of OpenGL scene
40 class GLVIEWER_API GLViewer_Widget : public QGLWidget
46 /*! Parameters using for QOGLWidget as is
48 GLViewer_Widget( QWidget* theParent, const char* theName = 0 );
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; }
61 //! Returns scales on OpenGL scene along 3 directions
62 /*! in 2d scene zScale = 1.0 */
63 void getScale( GLfloat& xScale,
66 //! A function for installing the scales of OpenGL scene
67 void setScale( GLfloat xScale,
69 GLfloat zScaleGLfloat );
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 );
76 //! Returns rotation angle of Window in OpenGL global scene in degree
78 GLfloat getRotationAngle() const { return myRotationAnglePrev; }
79 //! A function for installing the rotation angle of Window in OpenGL global scene in degree
81 void setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
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 );
99 //! A function load picture from file with name theFileName and post it in center of global OpenGL scene
100 void setBackground( QString theFileName );
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();
107 //! A function translate background of window in to PostScript file on disk
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
113 virtual void translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
115 //! A function repaints OpenGL scene in export mode
116 /* Repaints all objects in only current view */
117 void exportRepaint();
120 //! A function translate background of window in to EMF file on disk
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
129 virtual void translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
133 //! Auxiliary function. Returns rect of window background in viewer coordinate system
134 void getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
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 );
147 virtual void paintEvent( QPaintEvent* );
148 virtual void mouseMoveEvent( QMouseEvent* );
149 virtual void mousePressEvent( QMouseEvent* );
150 virtual void mouseReleaseEvent( QMouseEvent* );
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* );
163 //! Scale along X direction
165 //! Scale along Y direction
167 //! Scale along Z direction
171 //! Window offset along X direction
173 //! Window offset along Y direction
175 //! Window offset along Z direction
179 GLfloat myRotationStartX;
180 GLfloat myRotationStartY;
181 GLfloat myRotationStartZ;
182 GLfloat myRotationAngle;
183 GLfloat myRotationCenterX;
184 GLfloat myRotationCenterY;
185 GLfloat myRotationCenterZ;
186 GLfloat myRotationAnglePrev;
189 GLViewer_ViewPort2d* myViewPort;
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
197 //! Width of background image
199 //! Height of background image
201 //! Size of background image
202 int myBackgroundSize;
206 //! Needs for export repaint
210 #endif // GLVIEWER_WIDGET_H