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