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