Salome HOME
studyActivated() virtual method has been added
[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 /* GLViewer_ViewPort2d Header File */
7
8 #ifdef WNT
9 #include <windows.h>
10 #endif
11
12 #include <GL/gl.h>
13 #include <GL/glu.h>
14
15 #include "GLViewer_ViewPort.h"
16 #include "GLViewer_Drawer.h"
17
18 #include <qcolor.h>
19
20 class GLViewer_ViewFrame;
21 class GLViewer_Object;
22 class GLViewer_Pnt;
23 class GLViewer_Rect;
24
25 /***************************************************************************
26 **  Class:   GLViewer_RectangularGrid
27 **  Descr:   OpenGL Grid for GLViewer_ViewPort2d
28 **  Module:  QAD
29 **  Created: UI team, 16.09.02
30 ****************************************************************************/
31 #ifndef GLVIEWER_RECTANGULARGRID_H
32 #define GLVIEWER_RECTANGULARGRID_H
33
34 class GLVIEWER_EXPORT GLViewer_RectangularGrid 
35 {
36 public:
37   GLViewer_RectangularGrid();
38   GLViewer_RectangularGrid( float, float, float, float, float, float, float, float, float, float );
39   ~GLViewer_RectangularGrid();
40
41   void                   draw();
42
43   void                   setGridColor( GLfloat, GLfloat, GLfloat );
44   void                   setAxisColor( GLfloat, GLfloat, GLfloat );
45   void                   setGridWidth( float );
46   void                   setCenterRadius( int );
47
48   void                   setSize( float, float );
49   void                   setPan( float, float );
50   bool                   setZoom( float );
51   void                   setResize( float, float, float );
52
53   void                   getSize( float&, float& ) const;
54   void                   getPan( float&, float& ) const;
55   void                   getScale( float&, float& ) const;
56
57   void                   setScaleFactor( int );
58   int                    getScaleFactor();
59
60 protected:
61   bool                   initList();
62
63   GLuint                 myGridList;
64   GLfloat                myGridColor[3];
65   GLfloat                myAxisColor[3];
66   GLfloat                myGridHeight;
67   GLfloat                myGridWidth;
68   GLfloat                myWinW;
69   GLfloat                myWinH;
70   GLfloat                myXSize;
71   GLfloat                myYSize;
72   GLfloat                myXPan;
73   GLfloat                myYPan;
74   GLfloat                myXScale;
75   GLfloat                myYScale;
76   GLfloat                myLineWidth;
77   GLfloat                myCenterWidth;
78   GLint                  myCenterRadius;
79   GLint                  myScaleFactor;
80   GLboolean              myIsUpdate;
81 };
82
83 #endif
84
85 /***************************************************************************
86 **  Class:   GLViewer_ViewPort2d
87 **  Descr:   OpenGL ViewPort 2D
88 **  Module:  QAD
89 **  Created: UI team, 02.09.02
90 ****************************************************************************/
91
92 //********* class compass for viewport******************
93 class GLVIEWER_EXPORT GLViewer_Compass {   
94 public:
95     enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
96
97     GLViewer_Compass( const QColor& color = QColor ( 0, 255, 0 ), 
98                    const int size = 60,
99                    const Position pos = TopRight,
100                    const int WidthTop = 20,
101                    const int WidthBottom = 10,
102                    const int HeightTop = 25,
103                    const int HeightBottom = 7 );
104     ~GLViewer_Compass(){ delete myFont; }
105
106     void        setCompass( const QColor& color, const int size, const Position pos )
107                                                     {myCol=color;mySize=size;myPos=pos;};
108     void        setVisible( const bool vis = true );
109     bool        getVisible(){ return myIsVisible; };
110
111     void        setSize( const int size ){mySize=size;};
112     int         getSize(){ return mySize; };
113
114     void        setPos( const Position pos ){myPos=pos;};
115     int         getPos(){ return myPos; };
116
117     void        setColor( const QColor& color ){myCol=color;};
118     QColor      getColor(){ return myCol; };
119
120     void        setArrowWidthTop( const int WidthTop ){ if( WidthTop<myArrowWidthBottom || 
121                                                             WidthTop>mySize ) return;
122                                                         myArrowWidthTop=WidthTop; };
123     int         getArrowWidthTop(){return myArrowWidthTop;};
124
125     void        setArrowWidthBottom( const int WidthBot ){ if( WidthBot>myArrowWidthTop || WidthBot<1 )return;
126                                                            myArrowWidthBottom=WidthBot; };
127     int         getArrowWidthBottom(){return myArrowWidthBottom;};
128
129     void        setArrowHeightTop( const int HeightTop ){ if( HeightTop>(2*mySize-myArrowHeightBottom ) ||
130                                                               HeightTop<1 )return;
131                                                           myArrowHeightTop=HeightTop;};
132     int         getArrowHeightTop(){return myArrowHeightTop;};
133
134     void        setArrowHeightBottom( const int HeightBot ){ if( HeightBot>( 2*mySize-myArrowHeightTop ) ||
135                                                                  HeightBot<1)return;
136                                                           myArrowHeightBottom=HeightBot;};
137     int         getArrowHeightBottom(){return myArrowHeightBottom;};        
138
139     GLViewer_TexFont* getFont();
140     void           setFont( QFont theFont ){ delete myFont; myFont = new GLViewer_TexFont( &theFont ); } 
141
142 protected:
143     QColor          myCol;
144     int             mySize;
145     int             myPos;
146     bool            myIsVisible;
147     int             myArrowWidthTop;
148     int             myArrowWidthBottom;
149     int             myArrowHeightTop;
150     int             myArrowHeightBottom;
151     GLViewer_TexFont*  myFont;
152     bool            isGenereted;
153 };
154
155
156 #ifndef GLVIEWER_VIEWPORT2D_H
157 #define GLVIEWER_VIEWPORT2D_H
158
159 #include <qwidget.h>
160 #include <qmap.h>
161 #include <qpaintdevice.h>
162 #include <qgl.h>
163
164 #include "GLViewer_Widget.h"
165
166 class QtxToolTip;
167
168 class GLViewer_ViewPort2d: public GLViewer_ViewPort
169 {
170   Q_OBJECT
171
172       enum vpDragState{ noDrag, initDrag, inDrag };
173
174 public:
175     GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
176     ~GLViewer_ViewPort2d();
177
178     void                   turnGrid( GLboolean on );
179     GLViewer_RectangularGrid* getGrid() const { return myGrid; }
180     void                   setGridColor( const QColor gridColor, const QColor axisColor );
181
182     GLViewer_ViewFrame*    getViewFrame() const { return myViewFrame; }
183     GLViewer_Widget*       getGLWidget() const { return myGLWidget; }
184     virtual QPaintDevice*  getPaintDevice() { return myGLWidget; }
185
186     void                   setBackgroundColor( const QColor& color);
187     QColor                 backgroundColor() const;
188
189     void                   setBorder( QRect* border ) { myBorder = border; }
190     QRect*                 getBorder() const { return myBorder; }
191
192     void                   setMargin( GLfloat margin ) { myMargin = margin; }
193     GLfloat                getMargin() const { return myMargin; }
194
195     int                    getHeight() const { return myHeight; }
196     int                    getWidth() const { return myWidth; }
197
198     void                   getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
199     void                   getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
200
201     void                   initResize( int, int );
202
203     void                   startRotation( int, int );
204     void                   rotate( int, int );
205     void                   endRotation();
206
207     bool                   isDragProcess(){ return myIsDragProcess; }
208
209     void                   turnCompass( GLboolean on );
210     void                   drawCompass();
211
212     int                    getViewPortId(){ return myViewPortId; }
213
214     virtual BlockStatus    currentBlock();
215
216     void                   startSelectByRect( int, int );
217     void                   drawSelectByRect( int, int );
218     void                   finishSelectByRect();
219
220     bool                   startPulling( GLViewer_Pnt );
221     void                   drawPulling( GLViewer_Pnt );
222     void                   finishPulling();
223     bool                   isPulling() const { return myIsPulling; }
224
225     //selection by rect
226     QRect                  selectionRect();
227     
228     GLViewer_Rect          win2GLV( const QRect& ) const;
229     QRect                  GLV2win( const GLViewer_Rect& ) const;
230
231 signals:
232     void                   vpUpdateValues();
233     void                   objectMoved();
234
235 protected:
236     void                   onCreatePopup();
237     void                   onCreatePopup( QPopupMenu* );
238     void                   onDestroyPopup( QPopupMenu* );
239
240     void                   onDragObject( QMouseEvent* );
241     
242     virtual void           mouseMoveEvent( QMouseEvent *);
243     virtual void           mousePressEvent( QMouseEvent *);
244     virtual void           mouseReleaseEvent( QMouseEvent *);
245
246     virtual void           paintEvent( QPaintEvent* );
247     virtual void           resizeEvent( QResizeEvent* );
248
249     virtual void           reset();
250     virtual void           pan( int, int );
251     virtual void           setCenter( int, int );    
252     virtual void           zoom( int, int, int, int );
253     virtual void           fitRect( const QRect& );
254     virtual void           fitSelect();
255     virtual void           fitAll( bool keepScale = false, bool withZ = true );
256
257 protected slots:
258     void                   onStartDragObject();
259     void                   onPasteObject();
260     void                   onCutObject();
261     void                   onCopyObject();
262
263     void                   onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& );
264
265 protected:
266     GLViewer_Widget*       myGLWidget;
267     QColor                 myBackgroundColor;
268     QRect*                 myBorder;
269     GLfloat                myMargin;
270     int                    myHeight;
271     int                    myWidth;
272     GLfloat                myXScale;
273     GLfloat                myYScale;
274     GLfloat                myXOldScale;
275     GLfloat                myYOldScale;
276     GLfloat                myXPan;
277     GLfloat                myYPan;
278     GLViewer_RectangularGrid* myGrid; 
279     GLViewer_ViewFrame*    myViewFrame;
280
281     bool                   myDegenerated;
282
283     //dragging
284     int                    myIsDragProcess;
285     float*                 myCurDragPosX;
286     float*                 myCurDragPosY;
287     
288     GLViewer_Compass*      myCompass;
289
290     //selection by rect
291     QPoint*                mypFirstPoint;
292     QPoint*                mypLastPoint;
293
294     //pulling
295     bool                   myIsPulling;
296     GLViewer_Object*       myPullingObject;
297     
298     int                    myViewPortId;
299
300     //GLViewer_ObjectTip*    myObjectTip;
301     QtxToolTip*            myObjectTip;
302 };
303
304 #endif