Salome HOME
Copyright update 2022
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
1 // Copyright (C) 2007-2022  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
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
66   bool    gtIsVisible;
67   bool    gtDrawNameX;
68   bool    gtDrawNameY;
69   bool    gtDrawNameZ;
70   QString gtNameX;
71   QString gtNameY;
72   QString gtNameZ;
73   int     gtNameColorRX;
74   int     gtNameColorGX;
75   int     gtNameColorBX;
76   int     gtNameColorRY;
77   int     gtNameColorGY;
78   int     gtNameColorBY;
79   int     gtNameColorRZ;
80   int     gtNameColorGZ;
81   int     gtNameColorBZ;
82   bool    gtDrawValuesX;
83   bool    gtDrawValuesY;
84   bool    gtDrawValuesZ;
85   int     gtNbValuesX;
86   int     gtNbValuesY;
87   int     gtNbValuesZ;
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;
100   bool    gtDrawTickmarksX;
101   bool    gtDrawTickmarksY;
102   bool    gtDrawTickmarksZ;
103   int     gtTickmarkLengthX;
104   int     gtTickmarkLengthY;
105   int     gtTickmarkLengthZ;
106
107 public:
108   viewAspect()
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 ),
132     gtTickmarkLengthX( 0 ), gtTickmarkLengthY( 0 ), gtTickmarkLengthZ( 0 ) {}
133 };
134
135 typedef QList<viewAspect> viewAspectList;
136
137 #ifdef WIN32
138 #pragma warning( disable:4251 )
139 #endif
140
141 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
142 {
143   Q_OBJECT
144
145 public:
146   enum ActionId { 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    RectangleSelectionStyleId, PolygonSelectionStyleId, CircleSelectionStyleId,
156          UserId };
157
158   enum OperationType{ NOVIEWOP, 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 SelectionStyle { RectStyle, PolygonStyle, CyrcleStyle };
168
169   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane };
170
171   enum ProjectionType { Orthographic, Perspective, Stereo };
172   
173   enum StereoType { QuadBuffer, Anaglyph, RowInterlaced, ColumnInterlaced, ChessBoard, SideBySide, OverUnder, SoftPageFlip, NumberOfModes };
174
175   enum AnaglyphFilter { RedCyan, YellowBlue, GreenMagenta };
176
177   enum FocusIODType { Absolute, Relative };
178
179   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
180   virtual ~OCCViewer_ViewWindow();
181
182   virtual OCCViewer_ViewWindow* getView( const int ) const;
183
184   virtual OCCViewer_ViewPort3d* getViewPort();
185
186   virtual bool eventFilter(QObject* watched, QEvent* e);
187
188   virtual void performRestoring( const viewAspect&, bool = false );
189   
190   virtual void initLayout();
191
192   virtual bool enableDrawMode( bool );
193
194   virtual void updateEnabledDrawMode();
195
196   virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
197                                 const double dx = 0, const double dy = 0, const double dz = 1);
198
199   virtual void setCuttingPlane( bool on, const gp_Pln thePln );
200
201   virtual bool isCuttingPlane();
202
203   virtual QString   getVisualParameters();
204   virtual void      setVisualParameters( const QString& parameters );
205
206   virtual void                    initSketchers();
207   virtual OCCViewer_ViewSketcher* getSketcher( const int ) const;
208
209   virtual void                    activateSketching( int );
210
211   virtual int                     interactionStyle() const;
212   virtual void                    setInteractionStyle( const int );
213  
214   virtual int                     zoomingStyle() const;
215   virtual void                    setZoomingStyle( const int );
216
217   virtual bool                    isPreselectionEnabled() const;
218   virtual void                    enablePreselection( bool );   
219   virtual bool                    isSelectionEnabled() const;
220   virtual void                    enableSelection( bool );
221  
222   virtual int                     projectionType() const;
223   virtual void                    setProjectionType( int );
224
225   virtual SelectionStyle          selectionStyle() const;
226   virtual void                    setSelectionStyle(SelectionStyle);
227
228   virtual int                     stereoType() const;
229   virtual void                    setStereoType( const int );
230
231   virtual int                     anaglyphFilter() const;
232   virtual void                    setAnaglyphFilter( const int );
233
234   virtual void                    setStereographicFocus( const int, const double );
235   virtual int                     stereographicFocusType() const;
236   virtual double                  stereographicFocusValue() const;
237
238   virtual void                    setInterocularDistance( const int, const double );
239   virtual int                     interocularDistanceType() const;
240   virtual double                  interocularDistanceValue() const;
241
242   virtual bool                    isReverseStereo() const;
243   virtual void                    setReverseStereo( const bool );
244
245   virtual bool                    isVSync() const;
246   virtual void                    setVSync( const bool );
247
248   virtual bool                    isQuadBufferSupport() const;
249   virtual void                    setQuadBufferSupport( const bool );
250
251   virtual bool                    isAutomaticZoom() const;
252   virtual void                    setAutomaticZoom( const bool );
253
254   void setTransformEnabled( const OperationType, const bool );
255   bool transformEnabled( const OperationType ) const;
256
257   void            set2dMode( Mode2dType );
258   Mode2dType      get2dMode() const { return my2dMode; }
259
260   void            setMaximized( bool, bool = true );
261   bool            isMaximized() const;
262   void            setReturnedTo3dView( bool = true );
263   
264   void            setSketcherStyle( bool enable );
265   bool            isSketcherStyle() const;
266
267   virtual QColor  backgroundColor() const;                      // obsolete
268   virtual void    setBackgroundColor( const QColor& );          // obsolete
269
270   virtual void    showStaticTrihedron( bool );
271
272   virtual Qtx::BackgroundData  background() const;
273   virtual void                 setBackground( const Qtx::BackgroundData& );
274
275   virtual const   viewAspectList& getViewAspects();
276   virtual void                    appendViewAspect( const viewAspect& );
277   virtual void                    updateViewAspects( const viewAspectList& );
278   virtual void                    clearViewAspects();
279
280   virtual SUIT_CameraProperties   cameraProperties();
281
282   bool isActionVisible( ActionId theId ) const;
283   void setActionVisible( ActionId theId, bool isVisible );
284
285   void resetState();
286
287 public slots:
288   virtual void onFrontView();
289   virtual void onViewFitAll();
290   virtual void onBackView();
291   virtual void onClipping(bool on);
292   virtual void onTopView();
293   virtual void onBottomView();
294   virtual void onLeftView();
295   virtual void onRightView();
296   virtual void onClockWiseView();
297   virtual void onAntiClockWiseView();
298   virtual void onProjectionType( QAction* theAction );
299   virtual void onStereoType( bool activate );
300   virtual void onProjectionType();
301   virtual void onResetView();
302   virtual void onFitAll();
303   virtual void onFitSelection();
304   virtual void activateZoom();
305   virtual void activateWindowFit();
306   virtual void activateRotation();
307   virtual void activatePanning();
308   virtual void activateGlobalPanning();
309   virtual void onSetRotationPoint( bool on );
310   virtual void onCloneView();
311   virtual void onAxialScale();
312   virtual void onGraduatedAxes();
313   virtual void onAmbientToogle();
314   virtual void onMemorizeView();
315   virtual void onRestoreView();
316   virtual void onTrihedronShow(bool);
317   virtual void setRestoreFlag();
318   virtual void onSwitchInteractionStyle( bool on );
319   virtual void onSwitchZoomingStyle( bool on );
320   virtual void onSwitchPreselection( bool on );
321   virtual void onSwitchSelection( bool on );
322   virtual void onSwitchSelectionStyle(QAction* theAction);
323   virtual void onRayTracing();
324   virtual void onEnvTexture();
325   virtual void onLightSource();
326   virtual void onPanning();
327
328   virtual void activateSetRotationGravity();
329   virtual void activateSetRotationSelected( double theX, double theY, double theZ );
330   virtual void activateStartPointSelection( TopAbs_ShapeEnum );
331   virtual void updateGravityCoords();
332    
333   virtual void showEvent( QShowEvent * );
334   virtual void hideEvent( QHideEvent * );
335
336   virtual void onMaximizedView();
337   virtual void returnTo3dView();
338
339 signals:
340   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
341   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
342   void viewCloned( SUIT_ViewWindow* );
343
344   void Show( QShowEvent * );
345   void Hide( QHideEvent * );
346   void maximized( OCCViewer_ViewWindow*, bool );
347   void returnedTo3d( );
348
349 protected slots:
350   void synchronize( SUIT_ViewWindow* );
351
352 public:
353   virtual QImage dumpView();
354   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
355
356 protected:
357   virtual QString  filter() const;
358
359   bool isOpenGlStereoSupport() const;
360
361   /* Transformation selected but not started yet */
362   bool transformRequested() const;
363   bool setTransformRequested ( OperationType );
364
365   /* Transformation is selected and already started */
366   bool          transformInProcess() const;
367   void          setTransformInProcess( bool );
368
369   void vpMousePressEvent(QMouseEvent* theEvent);
370   void vpMouseReleaseEvent(QMouseEvent* theEvent);
371   void vpMouseMoveEvent(QMouseEvent* theEvent);
372
373   void drawRect();
374   void endDrawRect();
375
376   void createActions();
377   void createToolBar();
378
379   virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
380
381   viewAspect getViewParams() const;
382
383   bool computeGravityCenter( double& theX, double& theY, double& theZ );
384
385   void projAndPanToGravity(V3d_TypeOfOrientation CamOri);
386
387   virtual void                          onSketchingStarted();
388   virtual void                          onSketchingFinished();
389
390   virtual OCCViewer_ViewSketcher*       createSketcher( int );
391
392   void                                  saveCursor();
393
394   OCCViewer_ViewSketcher*               mypSketcher;
395   QList<OCCViewer_ViewSketcher*>        mySketchers;
396
397   int                                   myCurSketch;
398
399   OperationType         myOperation;
400   OCCViewer_Viewer*     myModel;
401   OCCViewer_ViewPort3d* myViewPort;
402
403   OCCViewer_CubeAxesDlg* myCubeAxesDlg;
404
405   RotationPointType     myCurrPointType;
406   RotationPointType     myPrevPointType;
407   gp_Pnt                mySelectedPoint;
408   bool                  myRotationPointSelection;
409
410   int                                   myRestoreFlag;
411
412   int                                   myStartX;
413   int                                   myStartY;
414   int                                   myCurrX;
415   int                                   myCurrY;
416
417   bool                  myEventStarted;       // set when transformation is in process 
418   bool                  myCursorIsHand;                 
419   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
420   bool                  myEnableDrawMode;
421   bool                  myDrawRectEnabled;
422   bool                  myPaintersRedrawing;  // set to draw with external painters  
423   bool                  IsSketcherStyle;
424   bool                  myIsKeyFree;
425   bool                  myAutomaticZoom;
426   QCursor               myCursor;
427
428   double myCurScale;
429
430 private:
431   OCCViewer_AxialScaleDlg* myScalingDlg;
432
433   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
434   QtxAction* mySetRotationPointAction;
435
436   QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
437
438   bool mySelectionEnabled;
439   bool myPreselectionEnabled;
440   int myInteractionStyle;
441
442   typedef QMap<OperationType, bool> MapOfTransformStatus;
443   MapOfTransformStatus myStatus;
444
445   Mode2dType my2dMode;
446
447   Handle(V3d_Plane) myReserveClipPlane;
448
449   viewAspectList myViewAspects;
450   bool myPanningByBtn;
451 };
452
453 #ifdef WIN32
454 #pragma warning( default:4251 )
455 #endif
456
457 #endif