1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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
23 // Author : OPEN CASCADE
24 // File: GLViewer_Viewer.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_VIEWER_H
28 #define GLVIEWER_VIEWER_H
31 #include "GLViewer_Defs.h"
32 #include <SUIT_ViewModel.h>
43 class GLViewer_Selector;
44 class GLViewer_ViewSketcher;
45 class GLViewer_ViewTransformer;
46 class GLViewer_ViewFrame;
49 class SUIT_ViewWindow;
52 #pragma warning( disable:4251 )
56 \class GLViewer_Object
57 Base Viewer for GLViewer
59 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
64 enum SelectionMode { NoSelection, Single, Multiple };
65 enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
66 Zoom, PanGlobal, Pan, Rotate, UserTransform = 100 };
67 enum SketchingType { NoSketching, Rect, UserSketching = 100 };
70 GLViewer_Viewer( const QString& title );
74 virtual void setViewManager( SUIT_ViewManager* theViewManager );
75 virtual QString getType() const { return Type(); }
76 static QString Type() { return "GLViewer_ViewModel"; }
78 virtual void contextMenuPopup( QMenu* );
81 void setSelectionMode( SelectionMode );
82 SelectionMode getSelectionMode() const;
83 GLViewer_Selector* getSelector() const;
85 virtual void update( int = 0 );
87 void activateTransform( int );
88 void activateSketching( int );
90 GLViewer_ViewFrame* getActiveView() const;
93 void selectionChanged( SelectionChangeStatus );
96 virtual void onSketchingStarted();
97 virtual void onSketchingFinished();
98 virtual void onTransformationStarted();
99 virtual void onTransformationFinished();
100 virtual void onSelectionModeChanged();
102 virtual void unhilightDetected();
103 virtual bool eventFilter( QObject*, QEvent* );
105 /* virtual constructors */
106 virtual GLViewer_ViewTransformer* createTransformer( int );
107 virtual GLViewer_ViewSketcher* createSketcher( int );
108 virtual GLViewer_Selector* createSelector();
110 virtual void startOperations( QMouseEvent* ) {}
111 virtual bool updateOperations( QMouseEvent* ) { return false; }
112 virtual void finishOperations( QMouseEvent* ) {}
113 virtual void startOperations( QWheelEvent* ) {}
116 virtual void onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
117 virtual void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
118 virtual void onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
120 virtual void onSelectionCancel();
121 virtual void onSelectionDone( bool add, SelectionChangeStatus status );
123 virtual void onChangeBgColor();
126 void handleMouseMove( QMouseEvent* );
127 void handleMousePress( QMouseEvent* );
128 void handleMouseRelease( QMouseEvent* );
129 void handleWheel( QWheelEvent* );
132 GLViewer_Selector* mySelector; /* selector */
133 SelectionMode mySelMode; /* current selection mode */
134 GLViewer_ViewSketcher* mySketcher; /* sketch manipulator */
135 GLViewer_ViewTransformer* myTransformer; /* transform manipulator */
138 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
141 GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
142 ~GLViewer_ViewTransformer();
145 /*! Returns transformer type */
148 /*! Sets/returns acceleration key ( CTRL by default ) */
149 static int accelKey() { return acccelKey; }
150 static void setAccelKey( int k ) { acccelKey = k; }
152 /*! Sets/returns mouse button used for zooming ( MB1 by default ) */
153 static int zoomButton() { return zoomBtn; }
154 static void setZoomButton( int b ) { zoomBtn = b; }
156 /*! Sets/returns mouse button used for panning ( MB2 by default ) */
157 static int panButton() { return panBtn; }
158 static void setPanButton( int b ) { panBtn = b; }
160 /*! Sets/returns mouse button used for global pan ( MB1 by default ) */
161 static int panGlobalButton() { return panGlobalBtn; }
162 static void setPanGlobalButton( int b ) { panGlobalBtn = b; }
164 /*! Sets/returns mouse button used for fit area ( MB1 by default ) */
165 static int fitRectButton() { return fitRectBtn; }
166 static void setFitRectButton( int b ) { fitRectBtn = b; }
169 virtual bool eventFilter( QObject*, QEvent* );
172 enum TransformState { Debut, EnTrain, Fin };
173 virtual void onTransform( TransformState );
174 void initTransform( bool );
176 void drawRect(const QRect& theRect);
182 static int fitRectBtn;
183 static int panGlobalBtn;
185 static int acccelKey;
187 GLViewer_Viewer* myViewer;
189 QCursor mySavedCursor;
190 bool mySavedMouseTrack;
191 QPoint myStart, myCurr;
195 QRubberBand* myRectBand; //!< selection rectangle rubber band
198 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
201 GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
202 ~GLViewer_ViewSketcher();
205 /*! Returns sketcher type */
206 int type() const { return myType; }
208 /*! Returns result of sketching */
209 void* data() const { return myData; }
211 /*! Returns current state of mouse/sys kbd buttons */
212 int buttonState() const { return myButtonState; }
214 /*! Sets/returns mouse button used for sketching ( MB1 by default ) */
215 static int sketchButton() { return sketchBtn; }
216 static void setSketchButton( int b ) { sketchBtn = b; }
218 virtual bool eventFilter( QObject*, QEvent* );
221 enum SketchState { Debut, EnTrain, Fin };
222 virtual void onSketch( SketchState );
224 void drawRect(const QRect& theRect);
228 static int sketchBtn;
229 GLViewer_Viewer* myViewer;
232 QCursor mySavedCursor;
233 QPoint myStart, myCurr;
236 QRubberBand* myRectBand; //!< selection rectangle rubber band
240 #pragma warning ( default:4251 )