1 // Copyright (C) 2007-2008 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.
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
22 // Author : OPEN CASCADE
23 // File: GLViewer_ViewPort2d.h
24 // Created: November, 2004
26 #ifndef GLVIEWER_VIEWPORT2D_H
27 #define GLVIEWER_VIEWPORT2D_H
36 #include "GLViewer_ViewPort.h"
37 #include "GLViewer_Widget.h"
38 #include "GLViewer_Geom.h"
42 #include <QPaintDevice>
45 #pragma warning( disable:4251 )
48 class GLViewer_Compass;
50 class GLViewer_Object;
51 class GLViewer_ViewFrame;
59 * Class GLViewer_ViewPort
60 * 2D visualisation canvas of GLViewer
62 class GLViewer_ViewPort2d: public GLViewer_ViewPort
67 enum vpDragState{ noDrag, initDrag, inDrag };
70 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
71 ~GLViewer_ViewPort2d();
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 );
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; }
86 //! Sets background color
87 void setBackgroundColor( const QColor& color);
88 //! Returns background color
89 QColor backgroundColor() const;
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; }
96 //! Sets margin of borders
97 void setMargin( GLfloat margin ) { myMargin = margin; }
98 //! Returns margin of borders
99 GLfloat getMargin() const { return myMargin; }
101 //! Returns width of view
102 int getWidth() const { return myWidth; }
103 //! Returns height of view
104 int getHeight() const { return myHeight; }
107 //! Returns scale factors
108 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
110 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
113 void initResize( int width, int height );
116 void startRotation( int, int );
118 void rotate( int, int );
119 //! Completes rotation
122 //! Checks of dragging process state
123 bool isDragProcess(){ return myIsDragProcess; }
126 void turnCompass( GLboolean on );
130 //! Returns unique ID of ViewPort
131 int getViewPortId(){ return myViewPortId; }
134 virtual BlockStatus currentBlock();
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();
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; }
152 //! Returns selection by rect
153 QRect selectionRect();
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;
161 //! Emits after any transformation
162 void vpUpdateValues();
167 void onDragObject( QMouseEvent* );
169 virtual void mouseMoveEvent( QMouseEvent *);
170 virtual void mousePressEvent( QMouseEvent *);
171 virtual void mouseReleaseEvent( QMouseEvent *);
172 virtual void mouseDoubleClickEvent( QMouseEvent *);
174 virtual void paintEvent( QPaintEvent* );
175 virtual void resizeEvent( QResizeEvent* );
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 );
193 //! Initializes drag process
194 void onStartDragObject();
195 //! Pastes object from clipboard
196 void onPasteObject();
197 //! Cuts object to clipboard
199 //! Copies object to clipboard
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 );
206 GLViewer_ViewFrame* myViewFrame;
207 GLViewer_Widget* myGLWidget;
208 GLViewer_Rect* myBorder;
209 QColor myBackgroundColor;
222 GLViewer_Grid* myGrid;
223 GLViewer_Compass* myCompass;
227 float* myCurDragPosX;
228 float* myCurDragPosY;
231 QPoint* mypFirstPoint;
232 QPoint* mypLastPoint;
236 GLViewer_Object* myPullingObject;
240 //GLViewer_ObjectTip* myObjectTip;
241 QtxToolTip* myObjectTip;
242 //! flag to block mouse release event just after mouse double-click
243 bool myIsMouseReleaseBlock;
245 QRubberBand* myRectBand; //!< selection rectangle rubber band
249 #pragma warning ( default:4251 )