Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GLViewer_Viewer.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, 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:
93  void selectionChanged( SelectionChangeStatus );
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