Salome HOME
0022077: EDF 2272 : Selection with the Paraview interaction mode in GEOM/SMESH
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
1 // Copyright (C) 2007-2013  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.
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_ClippingDlg;
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;
48         double  centerY;
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
108 typedef QList<viewAspect> viewAspectList;
109
110 #ifdef WIN32
111 #pragma warning( disable:4251 )
112 #endif
113
114 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
115 {
116   Q_OBJECT
117
118 public:
119   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
120          ChangeRotationPointId, RotationId,
121          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
122          ResetId, CloneId, ClippingId, MemId, RestoreId,
123          TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
124          SwitchInteractionStyleId, SwitchZoomingStyleId, MaximizedId, SynchronizeId, UserId };
125
126   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
127                       PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
128                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
129                       CLOCKWISEVIEW, ANTICLOCKWISEVIEW };
130
131   enum RotationPointType{ GRAVITY, SELECTED };
132
133   enum SketchingType { NoSketching, Rect, Polygon };
134
135   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane};
136
137
138   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
139   virtual ~OCCViewer_ViewWindow();
140
141   virtual OCCViewer_ViewWindow* getView( const int ) const;
142
143   virtual OCCViewer_ViewPort3d* getViewPort();
144
145   virtual bool eventFilter(QObject* watched, QEvent* e);
146
147   virtual void performRestoring( const viewAspect&, bool = false );
148   
149   virtual void initLayout();
150
151   virtual void updateEnabledDrawMode();
152
153   virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
154                                 const double dx = 0, const double dy = 0, const double dz = 1);
155
156   virtual void setCuttingPlane( bool on, const gp_Pln thePln );
157
158   virtual bool isCuttingPlane();
159
160   virtual QString   getVisualParameters();
161   virtual void      setVisualParameters( const QString& parameters );
162
163   virtual void                    initSketchers();
164   virtual OCCViewer_ViewSketcher* getSketcher( const int );
165
166   virtual void                    activateSketching( int );
167
168   virtual int                     interactionStyle() const;
169   virtual void                    setInteractionStyle( const int );
170  
171   virtual int                     zoomingStyle() const;
172   virtual void                    setZoomingStyle( const int );
173  
174   void setTransformEnabled( const OperationType, const bool );
175   bool transformEnabled( const OperationType ) const;
176
177
178   void            set2dMode( Mode2dType );
179   Mode2dType      get2dMode() const { return my2dMode; }
180
181   void            setMaximized( bool, bool = true );
182   bool            isMaximized() const;
183   
184   void            setSketcherStyle( bool enable );
185   bool            isSketcherStyle() const;
186
187   virtual QColor  backgroundColor() const;                      // obsolete
188   virtual void    setBackgroundColor( const QColor& );          // obsolete
189
190   virtual Qtx::BackgroundData  background() const;
191   virtual void                 setBackground( const Qtx::BackgroundData& );
192
193   virtual const   viewAspectList& getViewAspects();
194   virtual void                    appendViewAspect( const viewAspect& );
195   virtual void                    updateViewAspects( const viewAspectList& );
196   virtual void                    clearViewAspects();
197
198   virtual SUIT_CameraProperties   cameraProperties();
199
200 public slots:
201   virtual void onFrontView();
202   virtual void onViewFitAll();
203   virtual void onBackView();
204   virtual void onTopView();
205   virtual void onBottomView();
206   virtual void onLeftView();
207   virtual void onRightView();
208   virtual void onClockWiseView();
209   virtual void onAntiClockWiseView();
210   virtual void onResetView();
211   virtual void onFitAll();
212   virtual void activateZoom();
213   virtual void activateWindowFit();
214   virtual void activateRotation();
215   virtual void activatePanning();
216   virtual void activateGlobalPanning();
217   virtual void onSetRotationPoint( bool on );
218   virtual void onCloneView();
219   virtual void onClipping( bool on );
220   virtual void onAxialScale();
221   virtual void onGraduatedAxes();
222   virtual void onAmbientToogle();
223   virtual void onMemorizeView();
224   virtual void onRestoreView();
225   virtual void onTrihedronShow();
226   virtual void setRestoreFlag();
227   virtual void onSwitchInteractionStyle( bool on );
228   virtual void onSwitchZoomingStyle( bool on );
229
230   virtual void activateSetRotationGravity();
231   virtual void activateSetRotationSelected( double theX, double theY, double theZ );
232   virtual void activateStartPointSelection();
233   virtual void updateGravityCoords();
234    
235   virtual void showEvent( QShowEvent * );
236   virtual void hideEvent( QHideEvent * );
237
238   virtual void onMaximizedView();
239
240 signals:
241   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
242   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
243   void viewCloned( SUIT_ViewWindow* );
244
245   void Show( QShowEvent * );
246   void Hide( QHideEvent * );
247   void maximized( OCCViewer_ViewWindow*, bool );
248
249 protected slots:
250   void synchronize( SUIT_ViewWindow* );
251
252 public:
253   virtual QImage dumpView();
254   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
255
256 protected:
257   virtual QString  filter() const;
258
259   /* Transformation selected but not started yet */
260   bool transformRequested() const;
261   bool setTransformRequested ( OperationType );
262
263   /* Transformation is selected and already started */
264   bool          transformInProcess() const;
265   void          setTransformInProcess( bool );
266
267   void vpMousePressEvent(QMouseEvent* theEvent);
268   void vpMouseReleaseEvent(QMouseEvent* theEvent);
269   void vpMouseMoveEvent(QMouseEvent* theEvent);
270
271   void resetState();
272   void drawRect();
273   void endDrawRect();
274
275   void createActions();
276   void createToolBar();
277  
278   virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
279
280   viewAspect getViewParams() const;
281
282   bool computeGravityCenter( double& theX, double& theY, double& theZ );
283
284   virtual void                          onSketchingStarted();
285   virtual void                          onSketchingFinished();
286
287   virtual OCCViewer_ViewSketcher*       createSketcher( int );
288
289   OCCViewer_ViewSketcher*               mypSketcher;
290   QList<OCCViewer_ViewSketcher*>        mySketchers;
291
292   int                                   myCurSketch;
293
294   OperationType         myOperation;
295   OCCViewer_Viewer*     myModel;
296   OCCViewer_ViewPort3d* myViewPort;
297
298   OCCViewer_CubeAxesDlg* myCubeAxesDlg;
299
300   RotationPointType     myCurrPointType;
301   RotationPointType     myPrevPointType;
302   gp_Pnt                mySelectedPoint;
303   bool                  myRotationPointSelection;
304
305   int                                   myRestoreFlag;
306
307   int                                   myStartX;
308   int                                   myStartY;
309   int                                   myCurrX;
310   int                                   myCurrY;
311
312   bool                  myEventStarted;       // set when transformation is in process 
313   bool                  myCursorIsHand;                 
314   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
315   bool                  myEnableDrawMode;
316   bool                  myPaintersRedrawing;  // set to draw with external painters  
317   bool                  IsSketcherStyle;
318   bool                  myIsKeyFree;
319   
320   QCursor               myCursor;
321
322   double myCurScale;
323
324 private:
325   OCCViewer_ClippingDlg* myClippingDlg;
326   QtxAction* myClippingAction;
327
328   OCCViewer_AxialScaleDlg* myScalingDlg;
329
330   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
331   QtxAction* mySetRotationPointAction;
332
333   QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
334
335   int myInteractionStyle;
336
337   typedef QMap<OperationType, bool> MapOfTransformStatus;
338   MapOfTransformStatus myStatus;
339
340   Mode2dType my2dMode;
341
342   Handle(V3d_Plane) myReserveClippingPlane;
343
344   viewAspectList myViewAspects;
345 };
346
347 #ifdef WIN32
348 #pragma warning( default:4251 )
349 #endif
350
351 #endif