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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Widget.h
23 // Created: November, 2004
25 /*! Class GLViewer_Widget
26 * Class for visualization OpenGL scene (widget) for GLViewer
28 #ifndef GLVIEWER_WIDGET_H
29 #define GLVIEWER_WIDGET_H
36 class GLViewer_ViewPort2d;
37 class GLViewer_CoordSystem;
39 class GLVIEWER_API GLViewer_Widget : public QGLWidget
45 /*! Parameters using for QOGLWidget as is
47 GLViewer_Widget( QWidget* theParent, const char* theName = 0 );
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; }
60 //! Returns scales on OpenGL scene along 3 directions
61 /*! in 2d scene zScale = 1.0 */
62 void getScale( GLfloat& xScale,
65 //! A function for installing the scales of OpenGL scene
66 void setScale( GLfloat xScale,
68 GLfloat zScaleGLfloat );
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 );
75 //! Returns rotation angle of Window in OpenGL global scene in degree
77 GLfloat getRotationAngle() const { return myRotationAnglePrev; }
78 //! A function for installing the rotation angle of Window in OpenGL global scene in degree
80 void setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
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 );
98 //! A function load picture from file with name theFileName and post it in center of global OpenGL scene
99 void setBackground( QString theFileName );
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();
106 //! A function translate background of window in to PostScript file on disk
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
112 virtual void translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
114 //! A function repaints OpenGL scene in export mode
115 /* Repaints all objects in only current view */
116 void exportRepaint();
119 //! A function translate background of window in to EMF file on disk
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
128 virtual void translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
132 //! Auxiliary function. Returns rect of window background in viewer coordinate system
133 void getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
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 );
146 virtual void paintEvent( QPaintEvent* );
147 virtual void mouseMoveEvent( QMouseEvent* );
148 virtual void mousePressEvent( QMouseEvent* );
149 virtual void mouseReleaseEvent( QMouseEvent* );
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* );
162 //! Scale along X direction
164 //! Scale along Y direction
166 //! Scale along Z direction
170 //! Window offset along X direction
172 //! Window offset along Y direction
174 //! Window offset along Z direction
178 GLfloat myRotationStartX;
179 GLfloat myRotationStartY;
180 GLfloat myRotationStartZ;
181 GLfloat myRotationAngle;
182 GLfloat myRotationCenterX;
183 GLfloat myRotationCenterY;
184 GLfloat myRotationCenterZ;
185 GLfloat myRotationAnglePrev;
188 GLViewer_ViewPort2d* myViewPort;
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
196 //! Width of background image
198 //! Height of background image
200 //! Size of background image
201 int myBackgroundSize;
205 //! Needs for export repaint
209 #endif // GLVIEWER_WIDGET_H