1 // Copyright (C) 2007-2015 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
37 #include "GLViewer_ViewPort.h"
38 #include "GLViewer_Widget.h"
39 #include "GLViewer_Geom.h"
43 #include <QPaintDevice>
46 #pragma warning( disable:4251 )
49 class GLViewer_Compass;
51 class GLViewer_Object;
52 class GLViewer_ViewFrame;
60 * Class GLViewer_ViewPort
61 * 2D visualisation canvas of GLViewer
63 class GLViewer_ViewPort2d: public GLViewer_ViewPort
68 enum vpDragState{ noDrag, initDrag, inDrag };
71 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
72 ~GLViewer_ViewPort2d();
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 );
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; }
87 //! Sets background color
88 void setBackgroundColor( const QColor& color);
89 //! Returns background color
90 QColor backgroundColor() const;
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; }
97 //! Sets margin of borders
98 void setMargin( GLfloat margin ) { myMargin = margin; }
99 //! Returns margin of borders
100 GLfloat getMargin() const { return myMargin; }
102 //! Returns width of view
103 int getWidth() const { return myWidth; }
104 //! Returns height of view
105 int getHeight() const { return myHeight; }
108 //! Returns scale factors
109 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
111 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
114 void initResize( int width, int height );
117 void startRotation( int, int );
119 void rotate( int, int );
120 //! Completes rotation
123 //! Checks of dragging process state
124 bool isDragProcess(){ return myIsDragProcess; }
127 void turnCompass( GLboolean on );
131 //! Returns unique ID of ViewPort
132 int getViewPortId(){ return myViewPortId; }
135 virtual BlockStatus currentBlock();
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();
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; }
153 //! Returns selection by rect
154 QRect selectionRect();
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;
162 //! Emits after any transformation
163 void vpUpdateValues();
168 void onDragObject( QMouseEvent* );
170 virtual void mouseMoveEvent( QMouseEvent *);
171 virtual void mousePressEvent( QMouseEvent *);
172 virtual void mouseReleaseEvent( QMouseEvent *);
173 virtual void mouseDoubleClickEvent( QMouseEvent *);
175 virtual void paintEvent( QPaintEvent* );
176 virtual void resizeEvent( QResizeEvent* );
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 );
194 //! Initializes drag process
195 void onStartDragObject();
196 //! Pastes object from clipboard
197 void onPasteObject();
198 //! Cuts object to clipboard
200 //! Copies object to clipboard
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 );
207 GLViewer_ViewFrame* myViewFrame;
208 GLViewer_Widget* myGLWidget;
209 GLViewer_Rect* myBorder;
210 QColor myBackgroundColor;
223 GLViewer_Grid* myGrid;
224 GLViewer_Compass* myCompass;
228 float* myCurDragPosX;
229 float* myCurDragPosY;
232 QPoint* mypFirstPoint;
233 QPoint* mypLastPoint;
237 GLViewer_Object* myPullingObject;
241 //GLViewer_ObjectTip* myObjectTip;
242 QtxToolTip* myObjectTip;
243 //! flag to block mouse release event just after mouse double-click
244 bool myIsMouseReleaseBlock;
246 QRubberBand* myRectBand; //!< selection rectangle rubber band
250 #pragma warning ( default:4251 )