Salome HOME
Implementation of the following issues:
[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_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;
47         double  centerY;
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
107 typedef QList<viewAspect> viewAspectList;
108
109 #ifdef WIN32
110 #pragma warning( disable:4251 )
111 #endif
112
113 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
114 {
115   Q_OBJECT
116
117 public:
118   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
119          ChangeRotationPointId, RotationId,
120          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
121          ResetId, CloneId, ClippingId, MemId, RestoreId,
122          TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
123          SwitchInteractionStyleId, SwitchZoomingStyleId, 
124          SwitchPreselectionId, SwitchSelectionId,
125          MaximizedId, SynchronizeId, ReturnTo3dViewId,
126          UserId };
127
128   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
129                       PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
130                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
131                       CLOCKWISEVIEW, ANTICLOCKWISEVIEW };
132
133   enum RotationPointType{ GRAVITY, SELECTED };
134
135   enum SketchingType { NoSketching, Rect, Polygon };
136
137   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane};
138
139
140   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
141   virtual ~OCCViewer_ViewWindow();
142
143   virtual OCCViewer_ViewWindow* getView( const int ) const;
144
145   virtual OCCViewer_ViewPort3d* getViewPort();
146
147   virtual bool eventFilter(QObject* watched, QEvent* e);
148
149   virtual void performRestoring( const viewAspect&, bool = false );
150   
151   virtual void initLayout();
152
153   virtual void updateEnabledDrawMode();
154
155   virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
156                                 const double dx = 0, const double dy = 0, const double dz = 1);
157
158   virtual void setCuttingPlane( bool on, const gp_Pln thePln );
159
160   virtual bool isCuttingPlane();
161
162   virtual QString   getVisualParameters();
163   virtual void      setVisualParameters( const QString& parameters );
164
165   virtual void                    initSketchers();
166   virtual OCCViewer_ViewSketcher* getSketcher( const int );
167
168   virtual void                    activateSketching( int );
169
170   virtual int                     interactionStyle() const;
171   virtual void                    setInteractionStyle( const int );
172  
173   virtual int                     zoomingStyle() const;
174   virtual void                    setZoomingStyle( const int );
175
176   virtual bool                    isPreselectionEnabled() const;
177   virtual void                    enablePreselection( bool );   
178   virtual bool                    isSelectionEnabled() const;
179   virtual void                    enableSelection( bool );
180  
181   void setTransformEnabled( const OperationType, const bool );
182   bool transformEnabled( const OperationType ) const;
183
184
185   void            set2dMode( Mode2dType );
186   Mode2dType      get2dMode() const { return my2dMode; }
187
188   void            setMaximized( bool, bool = true );
189   bool            isMaximized() const;
190   void            setReturnedTo3dView( bool = true );
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 onClipping(bool on);
213   virtual void onTopView();
214   virtual void onBottomView();
215   virtual void onLeftView();
216   virtual void onRightView();
217   virtual void onClockWiseView();
218   virtual void onAntiClockWiseView();
219   virtual void onResetView();
220   virtual void onFitAll();
221   virtual void activateZoom();
222   virtual void activateWindowFit();
223   virtual void activateRotation();
224   virtual void activatePanning();
225   virtual void activateGlobalPanning();
226   virtual void onSetRotationPoint( bool on );
227   virtual void onCloneView();
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   virtual void returnTo3dView();
250
251 signals:
252   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
253   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
254   void viewCloned( SUIT_ViewWindow* );
255
256   void Show( QShowEvent * );
257   void Hide( QHideEvent * );
258   void maximized( OCCViewer_ViewWindow*, bool );
259   void returnedTo3d( );
260
261 protected slots:
262   void synchronize( SUIT_ViewWindow* );
263
264 public:
265   virtual QImage dumpView();
266   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
267
268 protected:
269   virtual QString  filter() const;
270
271   /* Transformation selected but not started yet */
272   bool transformRequested() const;
273   bool setTransformRequested ( OperationType );
274
275   /* Transformation is selected and already started */
276   bool          transformInProcess() const;
277   void          setTransformInProcess( bool );
278
279   void vpMousePressEvent(QMouseEvent* theEvent);
280   void vpMouseReleaseEvent(QMouseEvent* theEvent);
281   void vpMouseMoveEvent(QMouseEvent* theEvent);
282
283   void resetState();
284   void drawRect();
285   void endDrawRect();
286
287   void createActions();
288   void createToolBar();
289  
290   virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
291
292   viewAspect getViewParams() const;
293
294   bool computeGravityCenter( double& theX, double& theY, double& theZ );
295
296   virtual void                          onSketchingStarted();
297   virtual void                          onSketchingFinished();
298
299   virtual OCCViewer_ViewSketcher*       createSketcher( int );
300
301   OCCViewer_ViewSketcher*               mypSketcher;
302   QList<OCCViewer_ViewSketcher*>        mySketchers;
303
304   int                                   myCurSketch;
305
306   OperationType         myOperation;
307   OCCViewer_Viewer*     myModel;
308   OCCViewer_ViewPort3d* myViewPort;
309
310   OCCViewer_CubeAxesDlg* myCubeAxesDlg;
311
312   RotationPointType     myCurrPointType;
313   RotationPointType     myPrevPointType;
314   gp_Pnt                mySelectedPoint;
315   bool                  myRotationPointSelection;
316
317   int                                   myRestoreFlag;
318
319   int                                   myStartX;
320   int                                   myStartY;
321   int                                   myCurrX;
322   int                                   myCurrY;
323
324   bool                  myEventStarted;       // set when transformation is in process 
325   bool                  myCursorIsHand;                 
326   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
327   bool                  myEnableDrawMode;
328   bool                  myPaintersRedrawing;  // set to draw with external painters  
329   bool                  IsSketcherStyle;
330   bool                  myIsKeyFree;
331   
332   QCursor               myCursor;
333
334   double myCurScale;
335
336 private:
337   OCCViewer_AxialScaleDlg* myScalingDlg;
338
339   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
340   QtxAction* mySetRotationPointAction;
341
342   QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
343
344   bool mySelectionEnabled;
345   bool myPreselectionEnabled;
346   int myInteractionStyle;
347
348   typedef QMap<OperationType, bool> MapOfTransformStatus;
349   MapOfTransformStatus myStatus;
350
351   Mode2dType my2dMode;
352
353   Handle(V3d_Plane) myReserveClipPlane;
354
355   viewAspectList myViewAspects;
356 };
357
358 #ifdef WIN32
359 #pragma warning( default:4251 )
360 #endif
361
362 #endif