1 // File: GLViewer_Viewer.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 #ifndef GLVIEWER_VIEWER_H
7 #define GLVIEWER_VIEWER_H
9 #include "GLViewer_Defs.h"
10 #include "GLViewer_ViewFrame.h"
11 #include <SUIT_ViewModel.h>
18 class GLViewer_Selector;
19 class GLViewer_ViewSketcher;
20 class GLViewer_ViewTransformer;
23 class SUIT_ViewWindow;
26 #pragma warning( disable:4251 )
30 * Class GLViewer_Object
31 * Base Viewer for GLViewer
33 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
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 };
44 GLViewer_Viewer( const QString& title );
48 virtual void setViewManager( SUIT_ViewManager* theViewManager );
49 virtual QString getType() const { return Type(); }
50 static QString Type() { return "GLViewer_ViewModel"; }
52 virtual void contextMenuPopup( QPopupMenu* );
55 void setSelectionMode( SelectionMode );
56 SelectionMode getSelectionMode() const;
57 GLViewer_Selector* getSelector() const;
59 virtual void update( int = 0 );
61 void activateTransform( int );
62 void activateSketching( int );
64 GLViewer_ViewFrame* getActiveView() const;
67 void selectionChanged( SelectionChangeStatus );
70 virtual void onSketchingStarted();
71 virtual void onSketchingFinished();
72 virtual void onTransformationStarted();
73 virtual void onTransformationFinished();
74 virtual void onSelectionModeChanged();
76 virtual void unhilightDetected();
77 virtual bool eventFilter( QObject*, QEvent* );
79 /* virtual constructors */
80 virtual GLViewer_ViewTransformer* createTransformer( int );
81 virtual GLViewer_ViewSketcher* createSketcher( int );
82 virtual GLViewer_Selector* createSelector();
84 virtual void startOperations( QMouseEvent* ) {}
85 virtual bool updateOperations( QMouseEvent* ) { return false; }
86 virtual void finishOperations( QMouseEvent* ) {}
87 virtual void startOperations( QWheelEvent* ) {}
90 virtual void onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
91 virtual void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
92 virtual void onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
94 virtual void onSelectionCancel();
95 virtual void onSelectionDone( bool add, SelectionChangeStatus status );
97 virtual void onChangeBgColor();
100 void handleMouseMove( QMouseEvent* );
101 void handleMousePress( QMouseEvent* );
102 void handleMouseRelease( QMouseEvent* );
103 void handleWheel( QWheelEvent* );
106 GLViewer_Selector* mySelector; /* selector */
107 SelectionMode mySelMode; /* current selection mode */
108 GLViewer_ViewSketcher* mySketcher; /* sketch manipulator */
109 GLViewer_ViewTransformer* myTransformer; /* transform manipulator */
112 /****************************************************************
113 ** Class: GLViewer_ViewTransformer
115 *****************************************************************/
116 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
119 GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
120 ~GLViewer_ViewTransformer();
123 /*! Returns transformer type */
126 /*! Sets/returns acceleration key ( CTRL by default ) */
127 static int accelKey() { return acccelKey; }
128 static void setAccelKey( int k ) { acccelKey = k; }
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; }
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; }
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; }
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; }
147 virtual bool eventFilter( QObject*, QEvent* );
150 enum TransformState { Debut, EnTrain, Fin };
151 virtual void onTransform( TransformState );
152 void initTransform( bool );
157 static int fitRectBtn;
158 static int panGlobalBtn;
160 static int acccelKey;
162 GLViewer_Viewer* myViewer;
164 QCursor mySavedCursor;
165 bool mySavedMouseTrack;
166 QPoint myStart, myCurr;
172 /****************************************************************
173 ** Class: GLViewer_ViewSketcher
175 *****************************************************************/
176 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
179 GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
180 ~GLViewer_ViewSketcher();
183 /*! Returns sketcher type */
184 int type() const { return myType; }
186 /*! Returns result of sketching */
187 void* data() const { return myData; }
189 /*! Returns current state of mouse/sys kbd buttons */
190 int buttonState() const { return myButtonState; }
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; }
196 virtual bool eventFilter( QObject*, QEvent* );
199 enum SketchState { Debut, EnTrain, Fin };
200 virtual void onSketch( SketchState );
203 static int sketchBtn;
204 GLViewer_Viewer* myViewer;
207 QCursor mySavedCursor;
208 QPoint myStart, myCurr;
213 #pragma warning ( default:4251 )