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