1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_ViewPort2d.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_VIEWPORT2D_H
28 #define GLVIEWER_VIEWPORT2D_H
35 #include <OpenGL/gl.h>
36 #include <OpenGL/glu.h>
42 #include "GLViewer_ViewPort.h"
43 #include "GLViewer_Widget.h"
44 #include "GLViewer_Geom.h"
48 #include <QPaintDevice>
51 #pragma warning( disable:4251 )
54 class GLViewer_Compass;
56 class GLViewer_Object;
57 class GLViewer_ViewFrame;
65 * Class GLViewer_ViewPort
66 * 2D visualisation canvas of GLViewer
68 class GLViewer_ViewPort2d: public GLViewer_ViewPort
73 enum vpDragState{ noDrag, initDrag, inDrag };
76 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
77 ~GLViewer_ViewPort2d();
79 //! On/off rectangular grid
80 void turnGrid( GLboolean on );
81 //! Returns rectangular grid
82 GLViewer_Grid* getGrid() const { return myGrid; }
83 //! Returns grid color
84 void setGridColor( const QColor gridColor, const QColor axisColor );
86 //! Returns parent window
87 GLViewer_ViewFrame* getViewFrame() const { return myViewFrame; }
88 //! Returns painted widget
89 GLViewer_Widget* getGLWidget() const { return myGLWidget; }
90 virtual QPaintDevice* getPaintDevice() { return myGLWidget; }
92 //! Sets background color
93 void setBackgroundColor( const QColor& color);
94 //! Returns background color
95 QColor backgroundColor() const;
97 //! Sets borders of scene
98 void setBorder( GLViewer_Rect* border ) { myBorder = border; }
99 //! Get current borders of scene
100 GLViewer_Rect* getBorder() const { return myBorder; }
102 //! Sets margin of borders
103 void setMargin( GLfloat margin ) { myMargin = margin; }
104 //! Returns margin of borders
105 GLfloat getMargin() const { return myMargin; }
107 //! Returns width of view
108 int getWidth() const { return myWidth; }
109 //! Returns height of view
110 int getHeight() const { return myHeight; }
113 //! Returns scale factors
114 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
116 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
119 void initResize( int width, int height );
122 void startRotation( int, int );
124 void rotate( int, int );
125 //! Completes rotation
128 //! Checks of dragging process state
129 bool isDragProcess(){ return myIsDragProcess; }
132 void turnCompass( GLboolean on );
136 //! Returns unique ID of ViewPort
137 int getViewPortId(){ return myViewPortId; }
140 virtual BlockStatus currentBlock();
142 //! Initializes before selecting by rect
143 void startSelectByRect( int x, int y );
144 //! Draw selecting rectandle
145 void drawSelectByRect( int x, int y );
146 //! Pass rect into selector and update
147 void finishSelectByRect();
149 //! \warnign It is for ouv
150 bool startPulling( GLViewer_Pnt );
151 //! \warnign It is for ouv
152 void drawPulling( GLViewer_Pnt );
153 //! \warnign It is for ouv
154 void finishPulling();
155 //! \warnign It is for ouv
156 bool isPulling() const { return myIsPulling; }
158 //! Returns selection by rect
159 QRect selectionRect();
161 //! Transforms window rect to global rect
162 GLViewer_Rect win2GLV( const QRect& ) const;
163 //! Transforms global rect to window rect
164 QRect GLV2win( const GLViewer_Rect& ) const;
167 //! Emits after any transformation
168 void vpUpdateValues();
173 void onDragObject( QMouseEvent* );
175 virtual void mouseMoveEvent( QMouseEvent *);
176 virtual void mousePressEvent( QMouseEvent *);
177 virtual void mouseReleaseEvent( QMouseEvent *);
178 virtual void mouseDoubleClickEvent( QMouseEvent *);
180 virtual void paintEvent( QPaintEvent* );
181 virtual void resizeEvent( QResizeEvent* );
183 //! Returns view to begin state
184 virtual void reset();
185 //! Sets offset to view
186 virtual void pan( int dx, int dy );
187 //! Sets view center in global coords
188 virtual void setCenter( int x, int y );
189 //! Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
190 virtual void zoom( int x0, int y0, int x1, int y1 );
191 //! Transforms view by rectangle
192 virtual void fitRect( const QRect& );
193 //! Transforms view by selection
194 virtual void fitSelect();
195 //! Transform view by view borders ( if \param keepScale = true, zoom does not change )
196 virtual void fitAll( bool keepScale = false, bool withZ = true );
199 //! Initializes drag process
200 void onStartDragObject();
201 //! Pastes object from clipboard
202 void onPasteObject();
203 //! Cuts object to clipboard
205 //! Copies object to clipboard
208 //! Sets tool tip with \param text to \param theTextReg and on \param theViewReg whan mouse is on \param thePoint
209 void onMaybeTip( QPoint thePoint, QString& text, QFont& font, QRect& theTextReg, QRect& theViewReg );
212 GLViewer_ViewFrame* myViewFrame;
213 GLViewer_Widget* myGLWidget;
214 GLViewer_Rect* myBorder;
215 QColor myBackgroundColor;
228 GLViewer_Grid* myGrid;
229 GLViewer_Compass* myCompass;
233 float* myCurDragPosX;
234 float* myCurDragPosY;
237 QPoint* mypFirstPoint;
238 QPoint* mypLastPoint;
242 GLViewer_Object* myPullingObject;
246 //GLViewer_ObjectTip* myObjectTip;
247 QtxToolTip* myObjectTip;
248 //! flag to block mouse release event just after mouse double-click
249 bool myIsMouseReleaseBlock;
251 QRubberBand* myRectBand; //!< selection rectangle rubber band
255 #pragma warning ( default:4251 )