]> SALOME platform Git repositories - modules/gui.git/blob - src/GLViewer/GLViewer_Viewer.h
Salome HOME
fa6a36f35e9a6ac5bb287829e32d39ddbbdb8394
[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 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
132 {
133 public:
134     GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
135     ~GLViewer_ViewTransformer();
136
137 public:
138     /*! Returns transformer type */
139     int                          type() const;
140
141     /*! Sets/returns acceleration key ( CTRL by default ) */
142     static int                   accelKey() { return acccelKey; }
143     static void                  setAccelKey( int k ) { acccelKey = k; }
144
145     /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
146     static int                   zoomButton() { return zoomBtn; }
147     static void                  setZoomButton( int b ) { zoomBtn = b; }
148
149     /*! Sets/returns mouse button used for panning ( MB2 by default ) */
150     static int                   panButton() { return panBtn; }
151     static void                  setPanButton( int b ) { panBtn = b; }
152
153     /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
154     static int                   panGlobalButton() { return panGlobalBtn; }
155     static void                  setPanGlobalButton( int b ) { panGlobalBtn = b; }
156
157     /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
158     static int                   fitRectButton() { return fitRectBtn; }
159     static void                  setFitRectButton( int b ) { fitRectBtn = b; }
160
161     virtual void                 exec();
162     virtual bool                 eventFilter( QObject*, QEvent* );
163
164 protected:
165     enum TransformState { Debut, EnTrain, Fin };
166     virtual void                 onTransform( TransformState );
167     void                         initTransform( bool );
168
169 protected:
170     static int                   panBtn;
171     static int                   zoomBtn;
172     static int                   fitRectBtn;
173     static int                   panGlobalBtn;
174
175     static int                   acccelKey;
176
177     GLViewer_Viewer*             myViewer;
178     int                          myType;
179     QCursor                      mySavedCursor;
180     bool                         mySavedMouseTrack;
181     QPoint                       myStart, myCurr;
182     int                          myButtonState;
183     QRect                        myDrawRect;
184     int                          myMajorBtn;
185 };
186
187 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
188 {
189 public:
190     GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
191     ~GLViewer_ViewSketcher();
192
193 public:
194     /*! Returns sketcher type */
195     int                          type() const { return myType; }
196
197     /*! Returns result of sketching */
198     void*                        data() const { return myData; }
199
200     /*! Returns current state of mouse/sys kbd buttons */
201     int                          buttonState() const { return myButtonState; }
202
203     /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
204     static int                   sketchButton() { return sketchBtn; }
205     static void                  setSketchButton( int b ) { sketchBtn = b; }
206
207     virtual bool                 eventFilter( QObject*, QEvent* );
208
209 protected:
210     enum SketchState { Debut, EnTrain, Fin };
211     virtual void                 onSketch( SketchState );
212
213 protected:
214     static int                   sketchBtn;
215     GLViewer_Viewer*             myViewer;
216     int                          myType;
217     void*                        myData;
218     QCursor                      mySavedCursor;
219     QPoint                       myStart, myCurr;
220     int                          myButtonState;
221 };
222
223 #ifdef WNT
224 #pragma warning ( default:4251 )
225 #endif
226
227 #endif