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