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