1 // Copyright (C) 2005 OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : OPEN CASCADE
22 // File: GLViewer_Viewer.h
23 // Created: November, 2004
25 #ifndef GLVIEWER_VIEWER_H
26 #define GLVIEWER_VIEWER_H
28 #include "GLViewer_Defs.h"
29 #include "GLViewer_ViewFrame.h"
30 #include <SUIT_ViewModel.h>
37 class GLViewer_Selector;
38 class GLViewer_ViewSketcher;
39 class GLViewer_ViewTransformer;
42 class SUIT_ViewWindow;
45 #pragma warning( disable:4251 )
49 \class GLViewer_Object
50 Base Viewer for GLViewer
52 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
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 };
63 GLViewer_Viewer( const QString& title );
67 virtual void setViewManager( SUIT_ViewManager* theViewManager );
68 virtual QString getType() const { return Type(); }
69 static QString Type() { return "GLViewer_ViewModel"; }
71 virtual void contextMenuPopup( QPopupMenu* );
74 void setSelectionMode( SelectionMode );
75 SelectionMode getSelectionMode() const;
76 GLViewer_Selector* getSelector() const;
78 virtual void update( int = 0 );
80 void activateTransform( int );
81 void activateSketching( int );
83 GLViewer_ViewFrame* getActiveView() const;
86 void selectionChanged( SelectionChangeStatus );
89 virtual void onSketchingStarted();
90 virtual void onSketchingFinished();
91 virtual void onTransformationStarted();
92 virtual void onTransformationFinished();
93 virtual void onSelectionModeChanged();
95 virtual void unhilightDetected();
96 virtual bool eventFilter( QObject*, QEvent* );
98 /* virtual constructors */
99 virtual GLViewer_ViewTransformer* createTransformer( int );
100 virtual GLViewer_ViewSketcher* createSketcher( int );
101 virtual GLViewer_Selector* createSelector();
103 virtual void startOperations( QMouseEvent* ) {}
104 virtual bool updateOperations( QMouseEvent* ) { return false; }
105 virtual void finishOperations( QMouseEvent* ) {}
106 virtual void startOperations( QWheelEvent* ) {}
109 virtual void onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
110 virtual void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
111 virtual void onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
113 virtual void onSelectionCancel();
114 virtual void onSelectionDone( bool add, SelectionChangeStatus status );
116 virtual void onChangeBgColor();
119 void handleMouseMove( QMouseEvent* );
120 void handleMousePress( QMouseEvent* );
121 void handleMouseRelease( QMouseEvent* );
122 void handleWheel( QWheelEvent* );
125 GLViewer_Selector* mySelector; /* selector */
126 SelectionMode mySelMode; /* current selection mode */
127 GLViewer_ViewSketcher* mySketcher; /* sketch manipulator */
128 GLViewer_ViewTransformer* myTransformer; /* transform manipulator */
131 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
134 GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
135 ~GLViewer_ViewTransformer();
138 /*! Returns transformer type */
141 /*! Sets/returns acceleration key ( CTRL by default ) */
142 static int accelKey() { return acccelKey; }
143 static void setAccelKey( int k ) { acccelKey = k; }
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; }
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; }
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; }
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; }
162 virtual bool eventFilter( QObject*, QEvent* );
165 enum TransformState { Debut, EnTrain, Fin };
166 virtual void onTransform( TransformState );
167 void initTransform( bool );
172 static int fitRectBtn;
173 static int panGlobalBtn;
175 static int acccelKey;
177 GLViewer_Viewer* myViewer;
179 QCursor mySavedCursor;
180 bool mySavedMouseTrack;
181 QPoint myStart, myCurr;
187 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
190 GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
191 ~GLViewer_ViewSketcher();
194 /*! Returns sketcher type */
195 int type() const { return myType; }
197 /*! Returns result of sketching */
198 void* data() const { return myData; }
200 /*! Returns current state of mouse/sys kbd buttons */
201 int buttonState() const { return myButtonState; }
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; }
207 virtual bool eventFilter( QObject*, QEvent* );
210 enum SketchState { Debut, EnTrain, Fin };
211 virtual void onSketch( SketchState );
214 static int sketchBtn;
215 GLViewer_Viewer* myViewer;
218 QCursor mySavedCursor;
219 QPoint myStart, myCurr;
224 #pragma warning ( default:4251 )