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