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