1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // Author : OPEN CASCADE
23 // File: GLViewer_Viewer.h
24 // Created: November, 2004
26 #ifndef GLVIEWER_VIEWER_H
27 #define GLVIEWER_VIEWER_H
30 #include "GLViewer_Defs.h"
31 #include <SUIT_ViewModel.h>
42 class GLViewer_Selector;
43 class GLViewer_ViewSketcher;
44 class GLViewer_ViewTransformer;
45 class GLViewer_ViewFrame;
48 class SUIT_ViewWindow;
51 #pragma warning( disable:4251 )
55 \class GLViewer_Object
56 Base Viewer for GLViewer
58 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
63 enum SelectionMode { NoSelection, Single, Multiple };
64 enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
65 Zoom, PanGlobal, Pan, Rotate, UserTransform = 100 };
66 enum SketchingType { NoSketching, Rect, UserSketching = 100 };
69 GLViewer_Viewer( const QString& title );
73 virtual void setViewManager( SUIT_ViewManager* theViewManager );
74 virtual QString getType() const { return Type(); }
75 static QString Type() { return "GLViewer_ViewModel"; }
77 virtual void contextMenuPopup( QMenu* );
80 void setSelectionMode( SelectionMode );
81 SelectionMode getSelectionMode() const;
82 GLViewer_Selector* getSelector() const;
84 virtual void update( int = 0 );
86 void activateTransform( int );
87 void activateSketching( int );
89 GLViewer_ViewFrame* getActiveView() const;
92 void selectionChanged( SelectionChangeStatus );
95 virtual void onSketchingStarted();
96 virtual void onSketchingFinished();
97 virtual void onTransformationStarted();
98 virtual void onTransformationFinished();
99 virtual void onSelectionModeChanged();
101 virtual void unhilightDetected();
102 virtual bool eventFilter( QObject*, QEvent* );
104 /* virtual constructors */
105 virtual GLViewer_ViewTransformer* createTransformer( int );
106 virtual GLViewer_ViewSketcher* createSketcher( int );
107 virtual GLViewer_Selector* createSelector();
109 virtual void startOperations( QMouseEvent* ) {}
110 virtual bool updateOperations( QMouseEvent* ) { return false; }
111 virtual void finishOperations( QMouseEvent* ) {}
112 virtual void startOperations( QWheelEvent* ) {}
115 virtual void onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
116 virtual void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
117 virtual void onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
119 virtual void onSelectionCancel();
120 virtual void onSelectionDone( bool add, SelectionChangeStatus status );
122 virtual void onChangeBgColor();
125 void handleMouseMove( QMouseEvent* );
126 void handleMousePress( QMouseEvent* );
127 void handleMouseRelease( QMouseEvent* );
128 void handleWheel( QWheelEvent* );
131 GLViewer_Selector* mySelector; /* selector */
132 SelectionMode mySelMode; /* current selection mode */
133 GLViewer_ViewSketcher* mySketcher; /* sketch manipulator */
134 GLViewer_ViewTransformer* myTransformer; /* transform manipulator */
137 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
140 GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
141 ~GLViewer_ViewTransformer();
144 /*! Returns transformer type */
147 /*! Sets/returns acceleration key ( CTRL by default ) */
148 static int accelKey() { return acccelKey; }
149 static void setAccelKey( int k ) { acccelKey = k; }
151 /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
152 static int zoomButton() { return zoomBtn; }
153 static void setZoomButton( int b ) { zoomBtn = b; }
155 /*! Sets/returns mouse button used for panning ( MB2 by default ) */
156 static int panButton() { return panBtn; }
157 static void setPanButton( int b ) { panBtn = b; }
159 /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
160 static int panGlobalButton() { return panGlobalBtn; }
161 static void setPanGlobalButton( int b ) { panGlobalBtn = b; }
163 /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
164 static int fitRectButton() { return fitRectBtn; }
165 static void setFitRectButton( int b ) { fitRectBtn = b; }
168 virtual bool eventFilter( QObject*, QEvent* );
171 enum TransformState { Debut, EnTrain, Fin };
172 virtual void onTransform( TransformState );
173 void initTransform( bool );
175 void drawRect(const QRect& theRect);
181 static int fitRectBtn;
182 static int panGlobalBtn;
184 static int acccelKey;
186 GLViewer_Viewer* myViewer;
188 QCursor mySavedCursor;
189 bool mySavedMouseTrack;
190 QPoint myStart, myCurr;
194 QRubberBand* myRectBand; //!< selection rectangle rubber band
197 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
200 GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
201 ~GLViewer_ViewSketcher();
204 /*! Returns sketcher type */
205 int type() const { return myType; }
207 /*! Returns result of sketching */
208 void* data() const { return myData; }
210 /*! Returns current state of mouse/sys kbd buttons */
211 int buttonState() const { return myButtonState; }
213 /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
214 static int sketchButton() { return sketchBtn; }
215 static void setSketchButton( int b ) { sketchBtn = b; }
217 virtual bool eventFilter( QObject*, QEvent* );
220 enum SketchState { Debut, EnTrain, Fin };
221 virtual void onSketch( SketchState );
223 void drawRect(const QRect& theRect);
227 static int sketchBtn;
228 GLViewer_Viewer* myViewer;
231 QCursor mySavedCursor;
232 QPoint myStart, myCurr;
235 QRubberBand* myRectBand; //!< selection rectangle rubber band
239 #pragma warning ( default:4251 )