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