Salome HOME
no message
[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 /***************************************************************************
7 **  Class:   GLViewer_Viewer
8 **  Descr:   Viewer for QAD-based application
9 **  Module:  QAD
10 **  Created: UI team, 05.09.00
11 ****************************************************************************/
12 #ifndef GLVIEWER_VIEWER_H
13 #define GLVIEWER_VIEWER_H
14
15 #include "GLViewer_Defs.h"
16 #include "GLViewer_ViewFrame.h"
17 #include <SUIT_ViewModel.h>
18
19 #include <qlist.h>
20 #include <qcursor.h>
21 #include <qobject.h>
22 #include <qpixmap.h>
23
24 class GLViewer_Selector;
25 class GLViewer_ViewSketcher;
26 class GLViewer_ViewTransformer;
27
28 class SUIT_Desktop;
29 class SUIT_ViewWindow;
30
31 #ifdef WNT
32 #pragma warning( disable:4251 )
33 #endif
34
35 class GLVIEWER_EXPORT GLViewer_Viewer: public SUIT_ViewModel
36 {
37     Q_OBJECT
38
39 public:
40     enum SelectionMode { NoSelection, Single, Multiple };
41     enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
42                          Zoom, PanGlobal, Pan, Rotate, UserTransform = 100 };
43     enum SketchingType { NoSketching, Rect, UserSketching = 100 };
44
45 public:
46     GLViewer_Viewer( const QString& title );
47     ~GLViewer_Viewer();
48
49 public:
50     virtual void                 setViewManager( SUIT_ViewManager* theViewManager );
51     virtual QString              getType() const { return Type(); }
52     static QString               Type() { return "GLViewer_ViewModel";  }
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 private:
98     void                         handleMouseMove( QMouseEvent* );
99     void                         handleMousePress( QMouseEvent* );
100     void                         handleMouseRelease( QMouseEvent* );
101     void                         handleWheel( QWheelEvent* );
102
103 protected:
104     GLViewer_Selector*           mySelector;        /* selector */
105     SelectionMode                mySelMode;         /* current selection mode */
106     GLViewer_ViewSketcher*       mySketcher;        /* sketch manipulator */
107     GLViewer_ViewTransformer*    myTransformer;     /* transform manipulator */
108 };
109
110 /****************************************************************
111 **  Class: GLViewer_ViewTransformer
112 **
113 *****************************************************************/
114 class GLVIEWER_EXPORT GLViewer_ViewTransformer : public QObject
115 {
116 public:
117     GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
118     ~GLViewer_ViewTransformer();
119
120 public:
121     /*! Returns transformer type */
122     int                          type() const;
123
124     /*! Sets/returns acceleration key ( CTRL by default ) */
125     static int                   accelKey() { return acccelKey; }
126     static void                  setAccelKey( int k ) { acccelKey = k; }
127
128     /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
129     static int                   zoomButton() { return zoomBtn; }
130     static void                  setZoomButton( int b ) { zoomBtn = b; }
131
132     /*! Sets/returns mouse button used for panning ( MB2 by default ) */
133     static int                   panButton() { return panBtn; }
134     static void                  setPanButton( int b ) { panBtn = b; }
135
136     /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
137     static int                   panGlobalButton() { return panGlobalBtn; }
138     static void                  setPanGlobalButton( int b ) { panGlobalBtn = b; }
139
140     /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
141     static int                   fitRectButton() { return fitRectBtn; }
142     static void                  setFitRectButton( int b ) { fitRectBtn = b; }
143
144     virtual void                 exec();
145     virtual bool                 eventFilter( QObject*, QEvent* );
146
147 protected:
148     enum TransformState { Debut, EnTrain, Fin };
149     virtual void                 onTransform( TransformState );
150     void                         initTransform( bool );
151
152 protected:
153     static int                   panBtn;
154     static int                   zoomBtn;
155     static int                   fitRectBtn;
156     static int                   panGlobalBtn;
157
158     static int                   acccelKey;
159
160     GLViewer_Viewer*             myViewer;
161     int                          myType;
162     QCursor                      mySavedCursor;
163     bool                         mySavedMouseTrack;
164     QPoint                       myStart, myCurr;
165     int                          myButtonState;
166     QRect                        myDrawRect;
167     int                          myMajorBtn;
168 };
169
170 /****************************************************************
171 **  Class: GLViewer_ViewSketcher
172 **
173 *****************************************************************/
174 class GLVIEWER_EXPORT GLViewer_ViewSketcher : public QObject
175 {
176 public:
177     GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
178     ~GLViewer_ViewSketcher();
179
180 public:
181     /*! Returns sketcher type */
182     int                          type() const { return myType; }
183
184     /*! Returns result of sketching */
185     void*                        data() const { return myData; }
186
187     /*! Returns current state of mouse/sys kbd buttons */
188     int                          buttonState() const { return myButtonState; }
189
190     /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
191     static int                   sketchButton() { return sketchBtn; }
192     static void                  setSketchButton( int b ) { sketchBtn = b; }
193
194     virtual bool                 eventFilter( QObject*, QEvent* );
195
196 protected:
197     enum SketchState { Debut, EnTrain, Fin };
198     virtual void                 onSketch( SketchState );
199
200 protected:
201     static int                   sketchBtn;
202     GLViewer_Viewer*             myViewer;
203     int                          myType;
204     void*                        myData;
205     QCursor                      mySavedCursor;
206     QPoint                       myStart, myCurr;
207     int                          myButtonState;
208 };
209
210 #ifdef WNT
211 #pragma warning ( default:4251 )
212 #endif
213
214 #endif