Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  Author : OPEN CASCADE
23 // File:      GLViewer_ViewPort.h
24 // Created:   November, 2004
25 //
26 #ifndef GLVIEWER_VIEWPORT_H
27 #define GLVIEWER_VIEWPORT_H
28
29 #include "GLViewer.h"
30
31 //#include <QList>
32 #include <QColor>
33 //#include <QAction>
34 #include <QWidget>
35
36 //#include <Aspect_Window.hxx>
37
38 class QRect;
39 class QCursor;
40 class QPainter;
41 class GLViewer_ViewSketcher;
42 class GLViewer_ViewTransformer;
43
44 #ifdef WIN32
45 #pragma warning( disable:4251 )
46 #endif
47
48 enum BlockStatus
49 {
50     BS_NoBlock          = 0x0000,
51     BS_Highlighting     = 0x0001,
52     BS_Selection        = 0x0002,
53     BS_Dragging         = 0x0004
54 };
55
56 /*!
57   \class GLViewer_ViewPort
58   Visualisation canvas of GLViewer
59 */
60 class GLVIEWER_API GLViewer_ViewPort: public QWidget
61 {
62     Q_OBJECT
63     friend class GLViewer_ViewSketcher;
64     friend class GLViewer_ViewTransformer;
65
66 public:
67     GLViewer_ViewPort( QWidget* parent );
68     ~GLViewer_ViewPort();
69
70 public:
71     //! Activates/deactivates sketching
72     void                             setSketchingEnabled( bool );
73     //! Checks active status of sketcher
74     bool                             isSketchingEnabled() const;
75     //! Activates/deactivates transformer
76     void                             setTransformEnabled( bool );
77     //! Checks active status of transformer
78     bool                             isTransformEnabled() const;
79
80     //! Returns background color
81     virtual QColor                   backgroundColor() const;
82     //! Sets background color
83     virtual void                     setBackgroundColor( const QColor& );
84
85     //! Redraw external pa inters
86     void                             redrawPainters();
87
88     //! Updates view
89     virtual void                     onUpdate();
90
91     //! Returns blocking status for current started operations
92     virtual BlockStatus              currentBlock(){ return BS_NoBlock; }
93
94 protected:
95     enum ViewType { Type2D, Type3D };
96     void                             selectVisualId( ViewType );
97
98     virtual QPaintDevice*            getPaintDevice() { return this; }
99     virtual void                     contextMenuEvent( QContextMenuEvent * e );
100
101 //! STATICS
102     static void                      createCursors();
103     static void                      destroyCursors();
104     static QCursor*                  getHandCursor() { return handCursor; }
105     static void                      setHandCursor( const QCursor& newCursor );
106     static QCursor*                  getPanCursor() { return panCursor; }
107     static void                      setPanCursor( const QCursor& newCursor );
108     static QCursor*                  getPanglCursor() { return panglCursor; }
109     static void                      setPanglCursor( const QCursor& newCursor );
110     static QCursor*                  getZoomCursor() { return zoomCursor; }
111     static void                      setZoomCursor( const QCursor& newCursor );
112
113 public://ouv
114     static QCursor*                  getDefaultCursor() { return defCursor; }
115     static void                      setDefaultCursor( const QCursor& newCursor );
116     static QCursor*                  getRotCursor() { return rotCursor; }
117     static void                      setRotCursor( const QCursor& newCursor );
118     static QCursor*                  getSketchCursor() { return sketchCursor; }
119     static void                      setSketchCursor( const QCursor& newCursor );
120
121 protected:
122 //! EVENTS
123     virtual void                     paintEvent( QPaintEvent *);
124     virtual void                     mouseMoveEvent( QMouseEvent *);
125     virtual void                     mouseReleaseEvent( QMouseEvent *);
126     virtual void                     mousePressEvent( QMouseEvent *);
127     virtual void                     mouseDoubleClickEvent( QMouseEvent *);
128     virtual void                     keyPressEvent( QKeyEvent *);
129     virtual void                     keyReleaseEvent( QKeyEvent *);
130     virtual void                     wheelEvent( QWheelEvent *);
131
132 //! TO BE REDEFINED
133     virtual void                     reset() = 0;
134     virtual void                     pan( int, int ) = 0;
135     virtual void                     setCenter( int, int ) = 0;    
136     virtual void                     zoom( int, int, int, int ) = 0;
137     virtual void                     fitRect( const QRect& ) = 0;
138     virtual void                     fitSelect() = 0;
139     virtual void                     fitAll( bool keepScale = false, bool withZ = true ) = 0;
140
141 protected slots:
142     virtual void                     onChangeBgColor();
143
144 signals:
145     void                             vpKeyEvent( QKeyEvent* );
146     void                             vpMouseEvent( QMouseEvent* );
147     void                             vpWheelEvent( QWheelEvent* );
148     void                             vpDrawExternal( QPainter* );
149
150     void                             contextMenuRequested( QContextMenuEvent* );
151
152 private:
153     void                             initialize();
154     void                             cleanup();
155
156 protected:
157     //Handle(Aspect_Window)            myWindow;
158     bool                             myEnableSketching;
159     bool                             myEnableTransform;
160     bool                             myPaintersRedrawing;   /* set to draw externally */
161     //QList<QAction>                   myPopupActions;
162
163 private:
164     static int                       nCounter;              /* objects counter */
165     static QCursor*                  defCursor;
166     static QCursor*                  panglCursor;
167     static QCursor*                  handCursor;
168     static QCursor*                  panCursor;
169     static QCursor*                  zoomCursor;
170     static QCursor*                  rotCursor;
171     static QCursor*                  sketchCursor;
172 };
173
174 #ifdef WIN32
175 #pragma warning ( default:4251 )
176 #endif
177
178 #endif