1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_ViewPort2d.h
23 // Created: November, 2004
25 #ifndef GLVIEWER_VIEWPORT2D_H
26 #define GLVIEWER_VIEWPORT2D_H
35 #include "GLViewer_ViewPort.h"
36 #include "GLViewer_Widget.h"
37 #include "GLViewer_Geom.h"
42 #include <qpaintdevice.h>
45 #pragma warning( disable:4251 )
48 class GLViewer_Compass;
50 class GLViewer_Object;
51 class GLViewer_ViewFrame;
55 * Class GLViewer_ViewPort
56 * 2D visualisation canvas of GLViewer
58 class GLViewer_ViewPort2d: public GLViewer_ViewPort
63 enum vpDragState{ noDrag, initDrag, inDrag };
66 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
67 ~GLViewer_ViewPort2d();
69 //! On/off rectangular grid
70 void turnGrid( GLboolean on );
71 //! Returns rectangular grid
72 GLViewer_Grid* getGrid() const { return myGrid; }
73 //! Returns grid color
74 void setGridColor( const QColor gridColor, const QColor axisColor );
76 //! Returns parent window
77 GLViewer_ViewFrame* getViewFrame() const { return myViewFrame; }
78 //! Returns painted widget
79 GLViewer_Widget* getGLWidget() const { return myGLWidget; }
80 virtual QPaintDevice* getPaintDevice() { return myGLWidget; }
82 //! Sets background color
83 void setBackgroundColor( const QColor& color);
84 //! Returns background color
85 QColor backgroundColor() const;
87 //! Sets borders of scene
88 void setBorder( GLViewer_Rect* border ) { myBorder = border; }
89 //! Get current borders of scene
90 GLViewer_Rect* getBorder() const { return myBorder; }
92 //! Sets margin of borders
93 void setMargin( GLfloat margin ) { myMargin = margin; }
94 //! Returns margin of borders
95 GLfloat getMargin() const { return myMargin; }
97 //! Returns width of view
98 int getWidth() const { return myWidth; }
99 //! Returns height of view
100 int getHeight() const { return myHeight; }
103 //! Returns scale factors
104 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
106 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
109 void initResize( int width, int height );
112 void startRotation( int, int );
114 void rotate( int, int );
115 //! Completes rotation
118 //! Checks of dragging process state
119 bool isDragProcess(){ return myIsDragProcess; }
122 void turnCompass( GLboolean on );
126 //! Returns unique ID of ViewPort
127 int getViewPortId(){ return myViewPortId; }
130 virtual BlockStatus currentBlock();
132 //! Initializes before selecting by rect
133 void startSelectByRect( int x, int y );
134 //! Draw selecting rectandle
135 void drawSelectByRect( int x, int y );
136 //! Pass rect into selector and update
137 void finishSelectByRect();
139 //! \warnign It is for ouv
140 bool startPulling( GLViewer_Pnt );
141 //! \warnign It is for ouv
142 void drawPulling( GLViewer_Pnt );
143 //! \warnign It is for ouv
144 void finishPulling();
145 //! \warnign It is for ouv
146 bool isPulling() const { return myIsPulling; }
148 //! Returns selection by rect
149 QRect selectionRect();
151 //! Transforms window rect to global rect
152 GLViewer_Rect win2GLV( const QRect& ) const;
153 //! Transforms global rect to window rect
154 QRect GLV2win( const GLViewer_Rect& ) const;
157 //! Emits after any transformation
158 void vpUpdateValues();
163 void onDragObject( QMouseEvent* );
165 virtual void mouseMoveEvent( QMouseEvent *);
166 virtual void mousePressEvent( QMouseEvent *);
167 virtual void mouseReleaseEvent( QMouseEvent *);
168 virtual void mouseDoubleClickEvent( QMouseEvent *);
170 virtual void paintEvent( QPaintEvent* );
171 virtual void resizeEvent( QResizeEvent* );
173 //! Returns view to begin state
174 virtual void reset();
175 //! Sets offset to view
176 virtual void pan( int dx, int dy );
177 //! Sets view center in global coords
178 virtual void setCenter( int x, int y );
179 //! Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
180 virtual void zoom( int x0, int y0, int x1, int y1 );
181 //! Transforms view by certangle
182 virtual void fitRect( const QRect& );
183 //! Transforms view by selection
184 virtual void fitSelect();
185 //! Transform view by view borders ( if \param keepScale = true, zoom does not change )
186 virtual void fitAll( bool keepScale = false, bool withZ = true );
189 //! Initializes drag process
190 void onStartDragObject();
191 //! Pastes object from clipboard
192 void onPasteObject();
193 //! Cuts object to clipboard
195 //! Copies object to clipboard
198 //! Sets tool tip with \param text to \param theTextReg and on \param theViewReg whan mouse is on \param thePoint
199 void onMaybeTip( QPoint thePoint, QString& text, QFont& font, QRect& theTextReg, QRect& theViewReg );
202 GLViewer_ViewFrame* myViewFrame;
203 GLViewer_Widget* myGLWidget;
204 GLViewer_Rect* myBorder;
205 QColor myBackgroundColor;
218 GLViewer_Grid* myGrid;
219 GLViewer_Compass* myCompass;
223 float* myCurDragPosX;
224 float* myCurDragPosY;
227 QPoint* mypFirstPoint;
228 QPoint* mypLastPoint;
232 GLViewer_Object* myPullingObject;
236 //GLViewer_ObjectTip* myObjectTip;
237 QtxToolTip* myObjectTip;
238 //! flag to block mouse release event just after mouse double-click
239 bool myIsMouseReleaseBlock;
243 #pragma warning ( default:4251 )