]> SALOME platform Git repositories - modules/gui.git/blob - src/GLViewer/GLViewer_Viewer.h
Salome HOME
*** empty log 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_API 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     virtual void                 contextMenuPopup( QPopupMenu* );
55
56 public:
57     void                         setSelectionMode( SelectionMode );
58     SelectionMode                getSelectionMode() const;
59     GLViewer_Selector*           getSelector() const;
60
61     virtual void                 update( int = 0 );
62
63     void                         activateTransform( int );
64     void                         activateSketching( int );
65
66     GLViewer_ViewFrame*          getActiveView() const;
67
68 signals:
69     void                         selectionChanged( SelectionChangeStatus );
70
71 protected:
72     virtual void                 onSketchingStarted();
73     virtual void                 onSketchingFinished();
74     virtual void                 onTransformationStarted();
75     virtual void                 onTransformationFinished();
76     virtual void                 onSelectionModeChanged();
77
78     virtual void                 unhilightDetected();
79     virtual bool                 eventFilter( QObject*, QEvent* );
80
81     /* virtual constructors */
82     virtual GLViewer_ViewTransformer* createTransformer( int );
83     virtual GLViewer_ViewSketcher*    createSketcher( int );
84     virtual GLViewer_Selector*        createSelector();
85
86     virtual void                 startOperations( QMouseEvent* ) {}
87     virtual bool                 updateOperations( QMouseEvent* ) { return false; }
88     virtual void                 finishOperations( QMouseEvent* ) {}
89     virtual void                 startOperations( QWheelEvent* ) {}
90
91 protected slots:
92     virtual void                 onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
93     virtual void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
94     virtual void                 onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
95
96     virtual void                 onSelectionCancel();
97     virtual void                 onSelectionDone( bool add, SelectionChangeStatus status );
98
99     virtual void                 onChangeBgColor();
100
101 private:
102     void                         handleMouseMove( QMouseEvent* );
103     void                         handleMousePress( QMouseEvent* );
104     void                         handleMouseRelease( QMouseEvent* );
105     void                         handleWheel( QWheelEvent* );
106
107 protected:
108     GLViewer_Selector*           mySelector;        /* selector */
109     SelectionMode                mySelMode;         /* current selection mode */
110     GLViewer_ViewSketcher*       mySketcher;        /* sketch manipulator */
111     GLViewer_ViewTransformer*    myTransformer;     /* transform manipulator */
112 };
113
114 /****************************************************************
115 **  Class: GLViewer_ViewTransformer
116 **
117 *****************************************************************/
118 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
119 {
120 public:
121     GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
122     ~GLViewer_ViewTransformer();
123
124 public:
125     /*! Returns transformer type */
126     int                          type() const;
127
128     /*! Sets/returns acceleration key ( CTRL by default ) */
129     static int                   accelKey() { return acccelKey; }
130     static void                  setAccelKey( int k ) { acccelKey = k; }
131
132     /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
133     static int                   zoomButton() { return zoomBtn; }
134     static void                  setZoomButton( int b ) { zoomBtn = b; }
135
136     /*! Sets/returns mouse button used for panning ( MB2 by default ) */
137     static int                   panButton() { return panBtn; }
138     static void                  setPanButton( int b ) { panBtn = b; }
139
140     /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
141     static int                   panGlobalButton() { return panGlobalBtn; }
142     static void                  setPanGlobalButton( int b ) { panGlobalBtn = b; }
143
144     /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
145     static int                   fitRectButton() { return fitRectBtn; }
146     static void                  setFitRectButton( int b ) { fitRectBtn = b; }
147
148     virtual void                 exec();
149     virtual bool                 eventFilter( QObject*, QEvent* );
150
151 protected:
152     enum TransformState { Debut, EnTrain, Fin };
153     virtual void                 onTransform( TransformState );
154     void                         initTransform( bool );
155
156 protected:
157     static int                   panBtn;
158     static int                   zoomBtn;
159     static int                   fitRectBtn;
160     static int                   panGlobalBtn;
161
162     static int                   acccelKey;
163
164     GLViewer_Viewer*             myViewer;
165     int                          myType;
166     QCursor                      mySavedCursor;
167     bool                         mySavedMouseTrack;
168     QPoint                       myStart, myCurr;
169     int                          myButtonState;
170     QRect                        myDrawRect;
171     int                          myMajorBtn;
172 };
173
174 /****************************************************************
175 **  Class: GLViewer_ViewSketcher
176 **
177 *****************************************************************/
178 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
179 {
180 public:
181     GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
182     ~GLViewer_ViewSketcher();
183
184 public:
185     /*! Returns sketcher type */
186     int                          type() const { return myType; }
187
188     /*! Returns result of sketching */
189     void*                        data() const { return myData; }
190
191     /*! Returns current state of mouse/sys kbd buttons */
192     int                          buttonState() const { return myButtonState; }
193
194     /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
195     static int                   sketchButton() { return sketchBtn; }
196     static void                  setSketchButton( int b ) { sketchBtn = b; }
197
198     virtual bool                 eventFilter( QObject*, QEvent* );
199
200 protected:
201     enum SketchState { Debut, EnTrain, Fin };
202     virtual void                 onSketch( SketchState );
203
204 protected:
205     static int                   sketchBtn;
206     GLViewer_Viewer*             myViewer;
207     int                          myType;
208     void*                        myData;
209     QCursor                      mySavedCursor;
210     QPoint                       myStart, myCurr;
211     int                          myButtonState;
212 };
213
214 #ifdef WNT
215 #pragma warning ( default:4251 )
216 #endif
217
218 #endif