Salome HOME
c6626f6228b99c3e9ac007c8208ce1febc94ec93
[modules/gui.git] / src / GLViewer / GLViewer_Viewer.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_Viewer.h
24 // Created:   November, 2004
25 //
26 #ifndef GLVIEWER_VIEWER_H
27 #define GLVIEWER_VIEWER_H
28
29 #include "GLViewer.h"
30 #include "GLViewer_Defs.h"
31 #include <SUIT_ViewModel.h>
32
33 #include <QCursor>
34 #include <QObject>
35
36 class QMouseEvent;
37 class QKeyEvent;
38 class QWheelEvent;
39 class QRect;
40 class QRubberBand;
41
42 class GLViewer_Selector;
43 class GLViewer_ViewSketcher;
44 class GLViewer_ViewTransformer;
45 class GLViewer_ViewFrame;
46
47 //class SUIT_Desktop;
48 class SUIT_ViewWindow;
49
50 #ifdef WIN32
51 #pragma warning( disable:4251 )
52 #endif
53
54 /*! 
55   \class GLViewer_Object
56   Base Viewer for GLViewer
57 */
58 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
59 {
60     Q_OBJECT
61
62 public:
63     enum SelectionMode { NoSelection, Single, Multiple };
64     enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
65                          Zoom, PanGlobal, Pan, Rotate, UserTransform = 100 };
66     enum SketchingType { NoSketching, Rect, UserSketching = 100 };
67
68 public:
69     GLViewer_Viewer( const QString& title );
70     ~GLViewer_Viewer();
71
72 public:
73     virtual void                 setViewManager( SUIT_ViewManager* theViewManager );
74     virtual QString              getType() const { return Type(); }
75     static QString               Type() { return "GLViewer_ViewModel";  }
76
77     virtual void                 contextMenuPopup( QMenu* );
78
79 public:
80     void                         setSelectionMode( SelectionMode );
81     SelectionMode                getSelectionMode() const;
82     GLViewer_Selector*           getSelector() const;
83
84     virtual void                 update( int = 0 );
85
86     void                         activateTransform( int );
87     void                         activateSketching( int );
88
89     GLViewer_ViewFrame*          getActiveView() const;
90
91 signals:
92     void                         selectionChanged( SelectionChangeStatus );
93
94 protected:
95     virtual void                 onSketchingStarted();
96     virtual void                 onSketchingFinished();
97     virtual void                 onTransformationStarted();
98     virtual void                 onTransformationFinished();
99     virtual void                 onSelectionModeChanged();
100
101     virtual void                 unhilightDetected();
102     virtual bool                 eventFilter( QObject*, QEvent* );
103
104     /* virtual constructors */
105     virtual GLViewer_ViewTransformer* createTransformer( int );
106     virtual GLViewer_ViewSketcher*    createSketcher( int );
107     virtual GLViewer_Selector*        createSelector();
108
109     virtual void                 startOperations( QMouseEvent* ) {}
110     virtual bool                 updateOperations( QMouseEvent* ) { return false; }
111     virtual void                 finishOperations( QMouseEvent* ) {}
112     virtual void                 startOperations( QWheelEvent* ) {}
113
114 protected slots:
115     virtual void                 onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
116     virtual void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
117     virtual void                 onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
118
119     virtual void                 onSelectionCancel();
120     virtual void                 onSelectionDone( bool add, SelectionChangeStatus status );
121
122     virtual void                 onChangeBgColor();
123
124 private:
125     void                         handleMouseMove( QMouseEvent* );
126     void                         handleMousePress( QMouseEvent* );
127     void                         handleMouseRelease( QMouseEvent* );
128     void                         handleWheel( QWheelEvent* );
129
130 protected:
131     GLViewer_Selector*           mySelector;        /* selector */
132     SelectionMode                mySelMode;         /* current selection mode */
133     GLViewer_ViewSketcher*       mySketcher;        /* sketch manipulator */
134     GLViewer_ViewTransformer*    myTransformer;     /* transform manipulator */
135 };
136
137 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
138 {
139 public:
140     GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
141     ~GLViewer_ViewTransformer();
142
143 public:
144     /*! Returns transformer type */
145     int                          type() const;
146
147     /*! Sets/returns acceleration key ( CTRL by default ) */
148     static int                   accelKey() { return acccelKey; }
149     static void                  setAccelKey( int k ) { acccelKey = k; }
150
151     /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
152     static int                   zoomButton() { return zoomBtn; }
153     static void                  setZoomButton( int b ) { zoomBtn = b; }
154
155     /*! Sets/returns mouse button used for panning ( MB2 by default ) */
156     static int                   panButton() { return panBtn; }
157     static void                  setPanButton( int b ) { panBtn = b; }
158
159     /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
160     static int                   panGlobalButton() { return panGlobalBtn; }
161     static void                  setPanGlobalButton( int b ) { panGlobalBtn = b; }
162
163     /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
164     static int                   fitRectButton() { return fitRectBtn; }
165     static void                  setFitRectButton( int b ) { fitRectBtn = b; }
166
167     virtual void                 exec();
168     virtual bool                 eventFilter( QObject*, QEvent* );
169
170 protected:
171     enum TransformState { Debut, EnTrain, Fin };
172     virtual void                 onTransform( TransformState );
173     void                         initTransform( bool );
174
175     void                         drawRect(const QRect& theRect);
176     void                         endDrawRect();
177
178 protected:
179     static int                   panBtn;
180     static int                   zoomBtn;
181     static int                   fitRectBtn;
182     static int                   panGlobalBtn;
183
184     static int                   acccelKey;
185
186     GLViewer_Viewer*             myViewer;
187     int                          myType;
188     QCursor                      mySavedCursor;
189     bool                         mySavedMouseTrack;
190     QPoint                       myStart, myCurr;
191     int                          myButtonState;
192     int                          myMajorBtn;
193
194     QRubberBand*                 myRectBand; //!< selection rectangle rubber band
195 };
196
197 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
198 {
199 public:
200     GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
201     ~GLViewer_ViewSketcher();
202
203 public:
204     /*! Returns sketcher type */
205     int                          type() const { return myType; }
206
207     /*! Returns result of sketching */
208     void*                        data() const { return myData; }
209
210     /*! Returns current state of mouse/sys kbd buttons */
211     int                          buttonState() const { return myButtonState; }
212
213     /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
214     static int                   sketchButton() { return sketchBtn; }
215     static void                  setSketchButton( int b ) { sketchBtn = b; }
216
217     virtual bool                 eventFilter( QObject*, QEvent* );
218
219 protected:
220     enum SketchState { Debut, EnTrain, Fin };
221     virtual void                 onSketch( SketchState );
222
223     void                         drawRect(const QRect& theRect);
224     void                         endDrawRect();
225
226 protected:
227     static int                   sketchBtn;
228     GLViewer_Viewer*             myViewer;
229     int                          myType;
230     void*                        myData;
231     QCursor                      mySavedCursor;
232     QPoint                       myStart, myCurr;
233     int                          myButtonState;
234
235     QRubberBand*                 myRectBand; //!< selection rectangle rubber band
236 };
237
238 #ifdef WIN32
239 #pragma warning ( default:4251 )
240 #endif
241
242 #endif