1 // File: GLViewer_ViewPort2d.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 /* GLViewer_ViewPort2d Header File */
15 #include "GLViewer_ViewPort.h"
16 #include "GLViewer_Drawer.h"
20 class GLViewer_ViewFrame;
21 class GLViewer_Object;
25 /***************************************************************************
26 ** Class: GLViewer_RectangularGrid
27 ** Descr: OpenGL Grid for GLViewer_ViewPort2d
29 ** Created: UI team, 16.09.02
30 ****************************************************************************/
31 #ifndef GLVIEWER_RECTANGULARGRID_H
32 #define GLVIEWER_RECTANGULARGRID_H
34 class GLVIEWER_EXPORT GLViewer_RectangularGrid
37 GLViewer_RectangularGrid();
38 GLViewer_RectangularGrid( float, float, float, float, float, float, float, float, float, float );
39 ~GLViewer_RectangularGrid();
43 void setGridColor( GLfloat, GLfloat, GLfloat );
44 void setAxisColor( GLfloat, GLfloat, GLfloat );
45 void setGridWidth( float );
46 void setCenterRadius( int );
48 void setSize( float, float );
49 void setPan( float, float );
50 bool setZoom( float );
51 void setResize( float, float, float );
53 void getSize( float&, float& ) const;
54 void getPan( float&, float& ) const;
55 void getScale( float&, float& ) const;
57 void setScaleFactor( int );
64 GLfloat myGridColor[3];
65 GLfloat myAxisColor[3];
77 GLfloat myCenterWidth;
85 /***************************************************************************
86 ** Class: GLViewer_ViewPort2d
87 ** Descr: OpenGL ViewPort 2D
89 ** Created: UI team, 02.09.02
90 ****************************************************************************/
92 //********* class compass for viewport******************
93 class GLVIEWER_EXPORT GLViewer_Compass {
95 enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
97 GLViewer_Compass( const QColor& color = QColor ( 0, 255, 0 ),
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; }
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; };
111 void setSize( const int size ){mySize=size;};
112 int getSize(){ return mySize; };
114 void setPos( const Position pos ){myPos=pos;};
115 int getPos(){ return myPos; };
117 void setColor( const QColor& color ){myCol=color;};
118 QColor getColor(){ return myCol; };
120 void setArrowWidthTop( const int WidthTop ){ if( WidthTop<myArrowWidthBottom ||
121 WidthTop>mySize ) return;
122 myArrowWidthTop=WidthTop; };
123 int getArrowWidthTop(){return myArrowWidthTop;};
125 void setArrowWidthBottom( const int WidthBot ){ if( WidthBot>myArrowWidthTop || WidthBot<1 )return;
126 myArrowWidthBottom=WidthBot; };
127 int getArrowWidthBottom(){return myArrowWidthBottom;};
129 void setArrowHeightTop( const int HeightTop ){ if( HeightTop>(2*mySize-myArrowHeightBottom ) ||
131 myArrowHeightTop=HeightTop;};
132 int getArrowHeightTop(){return myArrowHeightTop;};
134 void setArrowHeightBottom( const int HeightBot ){ if( HeightBot>( 2*mySize-myArrowHeightTop ) ||
136 myArrowHeightBottom=HeightBot;};
137 int getArrowHeightBottom(){return myArrowHeightBottom;};
139 GLViewer_TexFont* getFont();
140 void setFont( QFont theFont ){ delete myFont; myFont = new GLViewer_TexFont( &theFont ); }
148 int myArrowWidthBottom;
149 int myArrowHeightTop;
150 int myArrowHeightBottom;
151 GLViewer_TexFont* myFont;
156 #ifndef GLVIEWER_VIEWPORT2D_H
157 #define GLVIEWER_VIEWPORT2D_H
161 #include <qpaintdevice.h>
164 #include "GLViewer_Widget.h"
168 class GLViewer_ViewPort2d: public GLViewer_ViewPort
172 enum vpDragState{ noDrag, initDrag, inDrag };
175 GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
176 ~GLViewer_ViewPort2d();
178 void turnGrid( GLboolean on );
179 GLViewer_RectangularGrid* getGrid() const { return myGrid; }
180 void setGridColor( const QColor gridColor, const QColor axisColor );
182 GLViewer_ViewFrame* getViewFrame() const { return myViewFrame; }
183 GLViewer_Widget* getGLWidget() const { return myGLWidget; }
184 virtual QPaintDevice* getPaintDevice() { return myGLWidget; }
186 void setBackgroundColor( const QColor& color);
187 QColor backgroundColor() const;
189 void setBorder( QRect* border ) { myBorder = border; }
190 QRect* getBorder() const { return myBorder; }
192 void setMargin( GLfloat margin ) { myMargin = margin; }
193 GLfloat getMargin() const { return myMargin; }
195 int getHeight() const { return myHeight; }
196 int getWidth() const { return myWidth; }
198 void getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
199 void getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
201 void initResize( int, int );
203 void startRotation( int, int );
204 void rotate( int, int );
207 bool isDragProcess(){ return myIsDragProcess; }
209 void turnCompass( GLboolean on );
212 int getViewPortId(){ return myViewPortId; }
214 virtual BlockStatus currentBlock();
216 void startSelectByRect( int, int );
217 void drawSelectByRect( int, int );
218 void finishSelectByRect();
220 bool startPulling( GLViewer_Pnt );
221 void drawPulling( GLViewer_Pnt );
222 void finishPulling();
223 bool isPulling() const { return myIsPulling; }
226 QRect selectionRect();
228 GLViewer_Rect win2GLV( const QRect& ) const;
229 QRect GLV2win( const GLViewer_Rect& ) const;
232 void vpUpdateValues();
236 void onCreatePopup();
237 void onCreatePopup( QPopupMenu* );
238 void onDestroyPopup( QPopupMenu* );
240 void onDragObject( QMouseEvent* );
242 virtual void mouseMoveEvent( QMouseEvent *);
243 virtual void mousePressEvent( QMouseEvent *);
244 virtual void mouseReleaseEvent( QMouseEvent *);
246 virtual void paintEvent( QPaintEvent* );
247 virtual void resizeEvent( QResizeEvent* );
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 );
258 void onStartDragObject();
259 void onPasteObject();
263 void onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& );
266 GLViewer_Widget* myGLWidget;
267 QColor myBackgroundColor;
278 GLViewer_RectangularGrid* myGrid;
279 GLViewer_ViewFrame* myViewFrame;
285 float* myCurDragPosX;
286 float* myCurDragPosY;
288 GLViewer_Compass* myCompass;
291 QPoint* mypFirstPoint;
292 QPoint* mypLastPoint;
296 GLViewer_Object* myPullingObject;
300 //GLViewer_ObjectTip* myObjectTip;
301 QtxToolTip* myObjectTip;