]> SALOME platform Git repositories - modules/gui.git/blob - src/GLViewer/GLViewer_ViewPort2d.h
Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort2d.h
1 //  Copyright (C) 2007-2008  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.
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 //  Author : OPEN CASCADE
23 // File:      GLViewer_ViewPort2d.h
24 // Created:   November, 2004
25 //
26 #ifndef GLVIEWER_VIEWPORT2D_H
27 #define GLVIEWER_VIEWPORT2D_H
28
29 #ifdef WIN32
30 #include <windows.h>
31 #endif
32
33 #include <GL/gl.h>
34 #include <GL/glu.h>
35
36 #include "GLViewer_ViewPort.h"
37 #include "GLViewer_Widget.h"
38 #include "GLViewer_Geom.h"
39
40 #include <QtOpenGL>
41 #include <QColor>
42 #include <QPaintDevice>
43
44 #ifdef WIN32
45 #pragma warning( disable:4251 )
46 #endif
47
48 class GLViewer_Compass;
49 class GLViewer_Grid;
50 class GLViewer_Object;
51 class GLViewer_ViewFrame;
52
53 class QtxToolTip;
54
55 class QWidget;
56 class QRubberBand;
57
58 /*! 
59  * Class GLViewer_ViewPort
60  * 2D visualisation canvas of GLViewer
61  */
62 class GLViewer_ViewPort2d: public GLViewer_ViewPort
63 {
64   Q_OBJECT
65
66   //! Dragging states
67   enum vpDragState{ noDrag, initDrag, inDrag };
68
69 public:
70   GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
71   ~GLViewer_ViewPort2d();
72
73   //! On/off rectangular grid
74   void                   turnGrid( GLboolean on );
75   //! Returns rectangular grid
76   GLViewer_Grid*         getGrid() const { return myGrid; }
77   //! Returns grid color
78   void                   setGridColor( const QColor gridColor, const QColor axisColor );
79
80   //! Returns parent window
81   GLViewer_ViewFrame*    getViewFrame() const { return myViewFrame; }
82   //! Returns painted widget
83   GLViewer_Widget*       getGLWidget() const { return myGLWidget; }
84   virtual QPaintDevice*  getPaintDevice() { return myGLWidget; }
85
86   //! Sets background color
87   void                   setBackgroundColor( const QColor& color);
88   //! Returns background color
89   QColor                 backgroundColor() const;
90
91   //! Sets borders of scene
92   void                   setBorder( GLViewer_Rect* border ) { myBorder = border; }
93   //! Get current borders of scene
94   GLViewer_Rect*         getBorder() const { return myBorder; }
95   
96   //! Sets margin of borders
97   void                   setMargin( GLfloat margin ) { myMargin = margin; }
98   //! Returns margin of borders
99   GLfloat                getMargin() const { return myMargin; }
100
101   //! Returns width of view
102   int                    getWidth() const { return myWidth; }
103   //! Returns height of view
104   int                    getHeight() const { return myHeight; }
105
106   
107   //! Returns scale factors
108   void                   getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
109   //! returns offsets
110   void                   getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
111
112   //! Resize view
113   void                   initResize( int width, int height );
114   
115   //! Begins rotation
116   void                   startRotation( int, int );
117   //! Process rotation
118   void                   rotate( int, int );
119   //! Completes rotation
120   void                   endRotation();
121   
122   //! Checks of dragging process state
123   bool                   isDragProcess(){ return myIsDragProcess; }
124   
125   //! On/off compass
126   void                   turnCompass( GLboolean on );
127   //! Draws compass
128   void                   drawCompass();
129   
130   //! Returns unique ID of ViewPort
131   int                    getViewPortId(){ return myViewPortId; }
132   
133   //! Redefined method
134   virtual BlockStatus    currentBlock();
135   
136   //! Initializes before selecting by rect
137   void                   startSelectByRect( int x, int y );
138   //! Draw selecting rectandle
139   void                   drawSelectByRect( int x, int y );
140   //! Pass rect into selector and update
141   void                   finishSelectByRect();
142   
143   //! \warnign It is for ouv
144   bool                   startPulling( GLViewer_Pnt );
145   //! \warnign It is for ouv
146   void                   drawPulling( GLViewer_Pnt );
147   //! \warnign It is for ouv
148   void                   finishPulling();
149   //! \warnign It is for ouv
150   bool                   isPulling() const { return myIsPulling; }
151
152   //! Returns selection by rect
153   QRect                  selectionRect();
154   
155   //! Transforms window rect to global rect 
156   GLViewer_Rect          win2GLV( const QRect& ) const;
157   //! Transforms global rect to window rect
158   QRect                  GLV2win( const GLViewer_Rect& ) const;
159
160 signals:
161   //! Emits after any transformation
162   void                   vpUpdateValues();
163
164   void                   objectMoved();
165
166 protected:
167   void                   onDragObject( QMouseEvent* );
168     
169   virtual void           mouseMoveEvent( QMouseEvent *);
170   virtual void           mousePressEvent( QMouseEvent *);
171   virtual void           mouseReleaseEvent( QMouseEvent *);
172   virtual void           mouseDoubleClickEvent( QMouseEvent *);
173   
174   virtual void           paintEvent( QPaintEvent* );
175   virtual void           resizeEvent( QResizeEvent* );
176
177   //! Returns view to begin state
178   virtual void           reset();
179   //! Sets offset to view
180   virtual void           pan( int dx, int dy );
181   //! Sets view center in global coords
182   virtual void           setCenter( int x, int y );
183   //! Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
184   virtual void           zoom( int x0, int y0, int x1, int y1 );
185   //! Transforms view by rectangle
186   virtual void           fitRect( const QRect& );
187   //! Transforms view by selection
188   virtual void           fitSelect();
189   //! Transform view by view borders ( if \param keepScale = true, zoom does not change )
190   virtual void           fitAll( bool keepScale = false, bool withZ = true );
191
192 protected slots:
193   //! Initializes drag process
194   void                   onStartDragObject();
195   //! Pastes object from clipboard
196   void                   onPasteObject();
197   //! Cuts object to clipboard
198   void                   onCutObject();
199   //! Copies object to clipboard
200   void                   onCopyObject();
201
202   //! Sets tool tip with \param text to \param theTextReg and on \param theViewReg whan mouse is on \param thePoint
203   void                   onMaybeTip( QPoint thePoint, QString& text, QFont& font, QRect& theTextReg, QRect& theViewReg );
204   
205 protected:
206   GLViewer_ViewFrame*    myViewFrame;
207   GLViewer_Widget*       myGLWidget;
208   GLViewer_Rect*         myBorder;
209   QColor                 myBackgroundColor;
210   
211   GLfloat                myMargin;
212   int                    myHeight;
213   int                    myWidth;
214   
215   GLfloat                myXScale;
216   GLfloat                myYScale;
217   GLfloat                myXOldScale;
218   GLfloat                myYOldScale;
219   GLfloat                myXPan;
220   GLfloat                myYPan;
221
222   GLViewer_Grid*         myGrid; 
223   GLViewer_Compass*      myCompass;
224
225   //dragging
226   int                    myIsDragProcess;
227   float*                 myCurDragPosX;
228   float*                 myCurDragPosY;
229   
230   //selection by rect
231   QPoint*                mypFirstPoint;
232   QPoint*                mypLastPoint;
233
234   //pulling
235   bool                   myIsPulling;
236   GLViewer_Object*       myPullingObject;
237     
238   int                    myViewPortId;
239
240   //GLViewer_ObjectTip*    myObjectTip;
241   QtxToolTip*            myObjectTip;
242   //! flag to block mouse release event just after mouse double-click
243   bool                   myIsMouseReleaseBlock;
244
245   QRubberBand*           myRectBand; //!< selection rectangle rubber band
246 };
247
248 #ifdef WIN32
249 #pragma warning ( default:4251 )
250 #endif
251
252 #endif