Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OCCViewer_ViewWindow.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 #ifndef OCCVIEWER_VIEWWINDOW_H
24 #define OCCVIEWER_VIEWWINDOW_H
25 
26 #include "OCCViewer.h"
27 #include "Qtx.h"
28 #include "SUIT_ViewWindow.h"
29 #include <gp_Pnt.hxx>
30 #include <V3d_Plane.hxx>
31 #include <TopAbs_ShapeEnum.hxx>
32 
33 class QtxRectRubberBand;
34 class SUIT_Desktop;
39 class OCCViewer_Viewer;
41 class QtxAction;
42 
43 struct viewAspect
44 {
45 public:
46  double scale;
47  double centerX; // deprecated since OCCT 6.7.1
48  double centerY; // deprecated since OCCT 6.7.1
49  double projX;
50  double projY;
51  double projZ;
52  double twist;
53  double atX;
54  double atY;
55  double atZ;
56  double eyeX;
57  double eyeY;
58  double eyeZ;
59  double scaleX;
60  double scaleY;
61  double scaleZ;
62  QString name;
63  bool isVisible;
64  double size;
65  // graduated trihedron
70  QString gtNameX;
71  QString gtNameY;
72  QString gtNameZ;
88  int gtOffsetX;
89  int gtOffsetY;
90  int gtOffsetZ;
91  int gtColorRX;
92  int gtColorGX;
93  int gtColorBX;
94  int gtColorRY;
95  int gtColorGY;
96  int gtColorBY;
97  int gtColorRZ;
98  int gtColorGZ;
99  int gtColorBZ;
106 
107 public:
109  : scale( 0.0 ),
110  centerX( 0.0 ), centerY( 0.0 ),
111  projX( 0.0 ), projY( 0.0 ), projZ( 0.0 ),
112  twist( 0.0 ),
113  atX( 0.0 ), atY( 0.0 ), atZ( 0.0 ),
114  eyeX( 0.0 ), eyeY( 0.0 ), eyeZ( 0.0 ),
115  scaleX( 0.0 ), scaleY( 0.0 ), scaleZ( 0.0 ),
116  name(),
117  isVisible( false ),
118  size( 0.0 ),
119  gtIsVisible( false ),
120  gtDrawNameX( false ), gtDrawNameY( false ), gtDrawNameZ( false ),
121  gtNameX(), gtNameY(), gtNameZ(),
122  gtNameColorRX( 0 ), gtNameColorGX( 0 ), gtNameColorBX( 0 ),
123  gtNameColorRY( 0 ), gtNameColorGY( 0 ), gtNameColorBY( 0 ),
124  gtNameColorRZ( 0 ), gtNameColorGZ( 0 ), gtNameColorBZ( 0 ),
125  gtDrawValuesX( false ), gtDrawValuesY( false ), gtDrawValuesZ( false ),
126  gtNbValuesX( 0 ), gtNbValuesY( 0 ), gtNbValuesZ( 0 ),
127  gtOffsetX( 0 ), gtOffsetY( 0 ), gtOffsetZ( 0 ),
128  gtColorRX( 0 ), gtColorGX( 0 ), gtColorBX( 0 ),
129  gtColorRY( 0 ), gtColorGY( 0 ), gtColorBY( 0 ),
130  gtColorRZ( 0 ), gtColorGZ( 0 ), gtColorBZ( 0 ),
131  gtDrawTickmarksX( false ), gtDrawTickmarksY( false ), gtDrawTickmarksZ( false ),
133 };
134 
136 
137 #ifdef WIN32
138 #pragma warning( disable:4251 )
139 #endif
140 
142 {
143  Q_OBJECT
144 
145 public:
146  enum { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
147  ChangeRotationPointId, RotationId,
148  FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
149  ResetId, CloneId, ClippingId, MemId, RestoreId,
150  TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
151  SwitchInteractionStyleId, SwitchZoomingStyleId,
152  SwitchPreselectionId, SwitchSelectionId,
153  MaximizedId, SynchronizeId, ReturnTo3dViewId,
154  OrthographicId, PerspectiveId, StereoId, RayTracingId, EnvTextureId, LightSourceId,
155  UserId };
156 
157  enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE,
158  PANGLOBAL, WINDOWFIT, FITALLVIEW, FITSELECTION, RESETVIEW,
159  FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
160  CLOCKWISEVIEW, ANTICLOCKWISEVIEW, PROJECTION };
161 
162  enum RotationPointType{ BBCENTER, SELECTED };
163 
164  enum SketchingType { NoSketching, Rect, Polygon };
165 
166  enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane };
167 
168  enum ProjectionType { Orthographic, Perspective, Stereo };
169 
170  enum StereoType { QuadBuffer, Anaglyph, RowInterlaced, ColumnInterlaced, ChessBoard, SideBySide, OverUnder, SoftPageFlip, NumberOfModes };
171 
172  enum AnaglyphFilter { RedCyan, YellowBlue, GreenMagenta };
173 
174  enum FocusIODType { Absolute, Relative };
175 
176  OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
177  virtual ~OCCViewer_ViewWindow();
178 
179  virtual OCCViewer_ViewWindow* getView( const int ) const;
180 
181  virtual OCCViewer_ViewPort3d* getViewPort();
182 
183  virtual bool eventFilter(QObject* watched, QEvent* e);
184 
185  virtual void performRestoring( const viewAspect&, bool = false );
186 
187  virtual void initLayout();
188 
189  virtual bool enableDrawMode( bool );
190 
191  virtual void updateEnabledDrawMode();
192 
193  virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
194  const double dx = 0, const double dy = 0, const double dz = 1);
195 
196  virtual void setCuttingPlane( bool on, const gp_Pln thePln );
197 
198  virtual bool isCuttingPlane();
199 
200  virtual QString getVisualParameters();
201  virtual void setVisualParameters( const QString& parameters );
202 
203  virtual void initSketchers();
204  virtual OCCViewer_ViewSketcher* getSketcher( const int );
205 
206  virtual void activateSketching( int );
207 
208  virtual int interactionStyle() const;
209  virtual void setInteractionStyle( const int );
210 
211  virtual int zoomingStyle() const;
212  virtual void setZoomingStyle( const int );
213 
214  virtual bool isPreselectionEnabled() const;
215  virtual void enablePreselection( bool );
216  virtual bool isSelectionEnabled() const;
217  virtual void enableSelection( bool );
218 
219  virtual int projectionType() const;
220  virtual void setProjectionType( int );
221 
222  virtual int stereoType() const;
223  virtual void setStereoType( const int );
224 
225  virtual int anaglyphFilter() const;
226  virtual void setAnaglyphFilter( const int );
227 
228  virtual void setStereographicFocus( const int, const double );
229  virtual int stereographicFocusType() const;
230  virtual double stereographicFocusValue() const;
231 
232  virtual void setInterocularDistance( const int, const double );
233  virtual int interocularDistanceType() const;
234  virtual double interocularDistanceValue() const;
235 
236  virtual bool isReverseStereo() const;
237  virtual void setReverseStereo( const bool );
238 
239  virtual bool isVSync() const;
240  virtual void setVSync( const bool );
241 
242  virtual bool isQuadBufferSupport() const;
243  virtual void setQuadBufferSupport( const bool );
244 
245  void setTransformEnabled( const OperationType, const bool );
246  bool transformEnabled( const OperationType ) const;
247 
248  void set2dMode( Mode2dType );
249  Mode2dType get2dMode() const { return my2dMode; }
250 
251  void setMaximized( bool, bool = true );
252  bool isMaximized() const;
253  void setReturnedTo3dView( bool = true );
254 
255  void setSketcherStyle( bool enable );
256  bool isSketcherStyle() const;
257 
258  virtual QColor backgroundColor() const; // obsolete
259  virtual void setBackgroundColor( const QColor& ); // obsolete
260 
261  virtual void showStaticTrihedron( bool );
262 
263  virtual Qtx::BackgroundData background() const;
264  virtual void setBackground( const Qtx::BackgroundData& );
265 
266  virtual const viewAspectList& getViewAspects();
267  virtual void appendViewAspect( const viewAspect& );
268  virtual void updateViewAspects( const viewAspectList& );
269  virtual void clearViewAspects();
270 
272 
273 public slots:
274  virtual void onFrontView();
275  virtual void onViewFitAll();
276  virtual void onBackView();
277  virtual void onClipping(bool on);
278  virtual void onTopView();
279  virtual void onBottomView();
280  virtual void onLeftView();
281  virtual void onRightView();
282  virtual void onClockWiseView();
283  virtual void onAntiClockWiseView();
284  virtual void onProjectionType( QAction* theAction );
285  virtual void onStereoType( bool activate );
286  virtual void onProjectionType();
287  virtual void onResetView();
288  virtual void onFitAll();
289  virtual void onFitSelection();
290  virtual void activateZoom();
291  virtual void activateWindowFit();
292  virtual void activateRotation();
293  virtual void activatePanning();
294  virtual void activateGlobalPanning();
295  virtual void onSetRotationPoint( bool on );
296  virtual void onCloneView();
297  virtual void onAxialScale();
298  virtual void onGraduatedAxes();
299  virtual void onAmbientToogle();
300  virtual void onMemorizeView();
301  virtual void onRestoreView();
302  virtual void onTrihedronShow(bool);
303  virtual void setRestoreFlag();
304  virtual void onSwitchInteractionStyle( bool on );
305  virtual void onSwitchZoomingStyle( bool on );
306  virtual void onSwitchPreselection( bool on );
307  virtual void onSwitchSelection( bool on );
308  virtual void onRayTracing();
309  virtual void onEnvTexture();
310  virtual void onLightSource();
311 
312  virtual void activateSetRotationGravity();
313  virtual void activateSetRotationSelected( double theX, double theY, double theZ );
314  virtual void activateStartPointSelection( TopAbs_ShapeEnum );
315  virtual void updateGravityCoords();
316 
317  virtual void showEvent( QShowEvent * );
318  virtual void hideEvent( QHideEvent * );
319 
320  virtual void onMaximizedView();
321  virtual void returnTo3dView();
322 
323 signals:
324  void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
325  void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
326  void viewCloned( SUIT_ViewWindow* );
327 
328  void Show( QShowEvent * );
329  void Hide( QHideEvent * );
330  void maximized( OCCViewer_ViewWindow*, bool );
331  void returnedTo3d( );
332 
333 protected slots:
334  void synchronize( SUIT_ViewWindow* );
335 
336 public:
337  virtual QImage dumpView();
338  virtual bool dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
339 
340 protected:
341  virtual QString filter() const;
342 
343  bool isOpenGlStereoSupport() const;
344 
345  /* Transformation selected but not started yet */
346  bool transformRequested() const;
347  bool setTransformRequested ( OperationType );
348 
349  /* Transformation is selected and already started */
350  bool transformInProcess() const;
351  void setTransformInProcess( bool );
352 
353  void vpMousePressEvent(QMouseEvent* theEvent);
354  void vpMouseReleaseEvent(QMouseEvent* theEvent);
355  void vpMouseMoveEvent(QMouseEvent* theEvent);
356 
357  void resetState();
358  void drawRect();
359  void endDrawRect();
360 
361  void createActions();
362  void createToolBar();
363 
364  virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
365 
366  viewAspect getViewParams() const;
367 
368  bool computeGravityCenter( double& theX, double& theY, double& theZ );
369 
370  virtual void onSketchingStarted();
371  virtual void onSketchingFinished();
372 
373  virtual OCCViewer_ViewSketcher* createSketcher( int );
374 
375  void saveCursor();
376 
379 
381 
385 
387 
392 
394 
395  int myStartX;
396  int myStartY;
397  int myCurrX;
398  int myCurrY;
399 
400  bool myEventStarted; // set when transformation is in process
402  bool myDrawRect; // set when a rect is used for selection or magnify
405  bool myPaintersRedrawing; // set to draw with external painters
408 
409  QCursor myCursor;
410 
411  double myCurScale;
412 
413 private:
415 
418 
420 
424 
425  typedef QMap<OperationType, bool> MapOfTransformStatus;
427 
429 
430  Handle(V3d_Plane) myReserveClipPlane;
431 
432  viewAspectList myViewAspects;
433 };
434 
435 #ifdef WIN32
436 #pragma warning( default:4251 )
437 #endif
438 
439 #endif