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