Version: 9.12.0
GLViewer_Viewer.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // Author : OPEN CASCADE
24 // File: GLViewer_Viewer.h
25 // Created: November, 2004
26 //
27 #ifndef GLVIEWER_VIEWER_H
28 #define GLVIEWER_VIEWER_H
29 
30 #include "GLViewer.h"
31 #include "GLViewer_Defs.h"
32 #include <SUIT_ViewModel.h>
33 
34 #include <QCursor>
35 #include <QObject>
36 
37 class QMouseEvent;
38 class QKeyEvent;
39 class QWheelEvent;
40 class QRect;
41 class QRubberBand;
42 
43 class GLViewer_Selector;
46 class GLViewer_ViewFrame;
47 
48 //class SUIT_Desktop;
49 class SUIT_ViewWindow;
50 
51 #ifdef WIN32
52 #pragma warning( disable:4251 )
53 #endif
54 
60 {
61  Q_OBJECT
62 
63 public:
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 };
68 
69 public:
70  GLViewer_Viewer( const QString& title );
71  ~GLViewer_Viewer();
72 
73 public:
74  virtual void setViewManager( SUIT_ViewManager* theViewManager );
75  virtual QString getType() const { return Type(); }
76  static QString Type() { return "GLViewer_ViewModel"; }
77 
78  virtual void contextMenuPopup( QMenu* );
79 
80 public:
81  void setSelectionMode( SelectionMode );
82  SelectionMode getSelectionMode() const;
83  GLViewer_Selector* getSelector() const;
84 
85  virtual void update( int = 0 );
86 
87  void activateTransform( int );
88  void activateSketching( int );
89 
90  GLViewer_ViewFrame* getActiveView() const;
91 
92 signals:
94 
95 protected:
96  virtual void onSketchingStarted();
97  virtual void onSketchingFinished();
98  virtual void onTransformationStarted();
99  virtual void onTransformationFinished();
100  virtual void onSelectionModeChanged();
101 
102  virtual void unhilightDetected();
103  virtual bool eventFilter( QObject*, QEvent* );
104 
105  /* virtual constructors */
106  virtual GLViewer_ViewTransformer* createTransformer( int );
107  virtual GLViewer_ViewSketcher* createSketcher( int );
108  virtual GLViewer_Selector* createSelector();
109 
110  virtual void startOperations( QMouseEvent* ) {}
111  virtual bool updateOperations( QMouseEvent* ) { return false; }
112  virtual void finishOperations( QMouseEvent* ) {}
113  virtual void startOperations( QWheelEvent* ) {}
114 
115 protected slots:
116  virtual void onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
117  virtual void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
118  virtual void onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
119 
120  virtual void onSelectionCancel();
121  virtual void onSelectionDone( bool add, SelectionChangeStatus status );
122 
123  virtual void onChangeBgColor();
124 
125 private:
126  void handleMouseMove( QMouseEvent* );
127  void handleMousePress( QMouseEvent* );
128  void handleMouseRelease( QMouseEvent* );
129  void handleWheel( QWheelEvent* );
130 
131 protected:
132  GLViewer_Selector* mySelector; /* selector */
133  SelectionMode mySelMode; /* current selection mode */
134  GLViewer_ViewSketcher* mySketcher; /* sketch manipulator */
135  GLViewer_ViewTransformer* myTransformer; /* transform manipulator */
136 };
137 
139 {
140 public:
143 
144 public:
146  int type() const;
147 
149  static int accelKey() { return acccelKey; }
150  static void setAccelKey( int k ) { acccelKey = k; }
151 
153  static int zoomButton() { return zoomBtn; }
154  static void setZoomButton( int b ) { zoomBtn = b; }
155 
157  static int panButton() { return panBtn; }
158  static void setPanButton( int b ) { panBtn = b; }
159 
161  static int panGlobalButton() { return panGlobalBtn; }
162  static void setPanGlobalButton( int b ) { panGlobalBtn = b; }
163 
165  static int fitRectButton() { return fitRectBtn; }
166  static void setFitRectButton( int b ) { fitRectBtn = b; }
167 
168  virtual void exec();
169  virtual bool eventFilter( QObject*, QEvent* );
170 
171 protected:
172  enum TransformState { Debut, EnTrain, Fin };
173  virtual void onTransform( TransformState );
174  void initTransform( bool );
175 
176  void drawRect(const QRect& theRect);
177  void endDrawRect();
178 
179 protected:
180  static int panBtn;
181  static int zoomBtn;
182  static int fitRectBtn;
183  static int panGlobalBtn;
184 
185  static int acccelKey;
186 
188  int myType;
189  QCursor mySavedCursor;
191  QPoint myStart, myCurr;
194 
195  QRubberBand* myRectBand;
196 };
197 
199 {
200 public:
203 
204 public:
206  int type() const { return myType; }
207 
209  void* data() const { return myData; }
210 
212  int buttonState() const { return myButtonState; }
213 
215  static int sketchButton() { return sketchBtn; }
216  static void setSketchButton( int b ) { sketchBtn = b; }
217 
218  virtual bool eventFilter( QObject*, QEvent* );
219 
220 protected:
221  enum SketchState { Debut, EnTrain, Fin };
222  virtual void onSketch( SketchState );
223 
224  void drawRect(const QRect& theRect);
225  void endDrawRect();
226 
227 protected:
228  static int sketchBtn;
230  int myType;
231  void* myData;
232  QCursor mySavedCursor;
233  QPoint myStart, myCurr;
235 
236  QRubberBand* myRectBand;
237 };
238 
239 #ifdef WIN32
240 #pragma warning ( default:4251 )
241 #endif
242 
243 #endif
#define GLVIEWER_API
Macro for exports.
Definition: GLViewer.h:37
SelectionChangeStatus
Definition: GLViewer_Defs.h:36
Definition: GLViewer_Selector.h:47
Definition: GLViewer_ViewFrame.h:52
Definition: GLViewer_Viewer.h:199
SketchState
Definition: GLViewer_Viewer.h:221
@ Debut
Definition: GLViewer_Viewer.h:221
QCursor mySavedCursor
Definition: GLViewer_Viewer.h:232
static int sketchBtn
Definition: GLViewer_Viewer.h:228
void * data() const
Definition: GLViewer_Viewer.h:209
QRubberBand * myRectBand
selection rectangle rubber band
Definition: GLViewer_Viewer.h:236
int buttonState() const
Definition: GLViewer_Viewer.h:212
GLViewer_Viewer * myViewer
Definition: GLViewer_Viewer.h:229
int myButtonState
Definition: GLViewer_Viewer.h:234
QPoint myCurr
Definition: GLViewer_Viewer.h:233
static int sketchButton()
Definition: GLViewer_Viewer.h:215
int myType
Definition: GLViewer_Viewer.h:230
int type() const
Definition: GLViewer_Viewer.h:206
void * myData
Definition: GLViewer_Viewer.h:231
static void setSketchButton(int b)
Definition: GLViewer_Viewer.h:216
Definition: GLViewer_Viewer.h:139
static int accelKey()
Definition: GLViewer_Viewer.h:149
static int panGlobalBtn
Definition: GLViewer_Viewer.h:183
TransformState
Definition: GLViewer_Viewer.h:172
@ Debut
Definition: GLViewer_Viewer.h:172
int myMajorBtn
Definition: GLViewer_Viewer.h:193
static int panGlobalButton()
Definition: GLViewer_Viewer.h:161
static int acccelKey
Definition: GLViewer_Viewer.h:185
static int zoomButton()
Definition: GLViewer_Viewer.h:153
static int zoomBtn
Definition: GLViewer_Viewer.h:181
bool mySavedMouseTrack
Definition: GLViewer_Viewer.h:190
GLViewer_Viewer * myViewer
Definition: GLViewer_Viewer.h:187
static int fitRectBtn
Definition: GLViewer_Viewer.h:182
static int panBtn
Definition: GLViewer_Viewer.h:180
static int panButton()
Definition: GLViewer_Viewer.h:157
static int fitRectButton()
Definition: GLViewer_Viewer.h:165
int myButtonState
Definition: GLViewer_Viewer.h:192
static void setPanButton(int b)
Definition: GLViewer_Viewer.h:158
static void setAccelKey(int k)
Definition: GLViewer_Viewer.h:150
static void setFitRectButton(int b)
Definition: GLViewer_Viewer.h:166
QCursor mySavedCursor
Definition: GLViewer_Viewer.h:189
static void setZoomButton(int b)
Definition: GLViewer_Viewer.h:154
QRubberBand * myRectBand
selection rectangle rubber band
Definition: GLViewer_Viewer.h:195
QPoint myCurr
Definition: GLViewer_Viewer.h:191
static void setPanGlobalButton(int b)
Definition: GLViewer_Viewer.h:162
int myType
Definition: GLViewer_Viewer.h:188
Definition: GLViewer_Viewer.h:60
SketchingType
Definition: GLViewer_Viewer.h:67
@ NoSketching
Definition: GLViewer_Viewer.h:67
void selectionChanged(SelectionChangeStatus)
virtual bool updateOperations(QMouseEvent *)
Definition: GLViewer_Viewer.h:111
static QString Type()
Definition: GLViewer_Viewer.h:76
SelectionMode mySelMode
Definition: GLViewer_Viewer.h:133
GLViewer_ViewTransformer * myTransformer
Definition: GLViewer_Viewer.h:135
virtual void startOperations(QWheelEvent *)
Definition: GLViewer_Viewer.h:113
TransformType
Definition: GLViewer_Viewer.h:65
@ Pan
Definition: GLViewer_Viewer.h:66
@ FitAll
Definition: GLViewer_Viewer.h:65
GLViewer_ViewSketcher * mySketcher
Definition: GLViewer_Viewer.h:134
virtual void startOperations(QMouseEvent *)
Definition: GLViewer_Viewer.h:110
SelectionMode
Definition: GLViewer_Viewer.h:64
GLViewer_Selector * mySelector
Definition: GLViewer_Viewer.h:132
virtual QString getType() const
Definition: GLViewer_Viewer.h:75
virtual void finishOperations(QMouseEvent *)
Definition: GLViewer_Viewer.h:112
For more information see QT documentation.
Definition: SUIT_Application.h:42
Definition: SUIT_ViewManager.h:50
Definition: SUIT_ViewModel.h:47
virtual void contextMenuPopup(QMenu *)
Definition: SUIT_ViewModel.h:69
virtual void setViewManager(SUIT_ViewManager *theViewManager)
Definition: SUIT_ViewModel.cxx:85
Definition: SUIT_ViewWindow.h:42
int Type
Definition: VTKViewer_Actor.h:62