Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
1 //  Copyright (C) 2007-2008  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 #ifndef OCCVIEWER_VIEWWINDOW_H
23 #define OCCVIEWER_VIEWWINDOW_H
24
25 #include "OCCViewer.h"
26 #include "SUIT_ViewWindow.h"
27 #include <gp_Pnt.hxx>
28
29 class QtxRectRubberBand;
30 class SUIT_Desktop;
31 class OCCViewer_ViewPort3d;
32 class OCCViewer_ViewSketcher;
33 class OCCViewer_ClippingDlg;
34 class OCCViewer_AxialScaleDlg;
35 class OCCViewer_SetRotationPointDlg;
36 class OCCViewer_Viewer;
37 class viewAspect;
38 class QtxAction;
39
40 #ifdef WIN32
41 #pragma warning( disable:4251 )
42 #endif
43
44 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
45 {
46   Q_OBJECT
47
48 public:
49   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
50          ChangeRotationPointId, RotationId,
51          FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, CloneId, ClippingId, MemId, RestoreId,
52          TrihedronShowId, AxialScaleId };
53
54   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
55                       PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
56                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW };
57
58   enum RotationPointType{ GRAVITY, SELECTED };
59
60   enum SketchingType { NoSketching, Rect, Polygon };
61
62   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
63   virtual ~OCCViewer_ViewWindow();
64
65   OCCViewer_ViewPort3d* getViewPort();
66
67   bool eventFilter(QObject* watched, QEvent* e);
68
69   void performRestoring( const viewAspect& );
70   
71   virtual void initLayout();
72
73   void updateEnabledDrawMode();
74
75   void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
76                                  const double dx = 0, const double dy = 0, const double dz = 1);
77
78   bool isCuttingPlane();
79
80   virtual QString   getVisualParameters();
81   virtual void      setVisualParameters( const QString& parameters );
82
83   virtual void            initSketchers();
84   OCCViewer_ViewSketcher* getSketcher( const int );
85
86   void                    activateSketching( int );
87  
88 public slots:
89   void onFrontView();
90   void onViewFitAll();
91   void onBackView();
92   void onTopView();
93   void onBottomView();
94   void onLeftView();
95   void onRightView();
96   void onResetView();
97   void onFitAll();
98   void activateZoom();
99   void activateWindowFit();
100   void activateRotation();
101   void activatePanning();
102   void activateGlobalPanning();
103   void onSetRotationPoint( bool on );
104   void onCloneView();
105   void onClipping( bool on );
106   void onAxialScale();
107   void onMemorizeView();
108   void onRestoreView();
109   void onTrihedronShow();
110   void setRestoreFlag();
111
112   void activateSetRotationGravity();
113   void activateSetRotationSelected( double theX, double theY, double theZ );
114   void activateStartPointSelection();
115   void updateGravityCoords();
116    
117   virtual void showEvent( QShowEvent * );
118   virtual void hideEvent( QHideEvent * );
119
120
121 signals:
122   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
123   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
124   void viewCloned( SUIT_ViewWindow* );
125
126   void Show( QShowEvent * );
127   void Hide( QHideEvent * );
128
129 protected:
130   virtual QImage dumpView();
131   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
132   virtual QString  filter() const;
133
134   /* Transformation selected but not started yet */
135   bool transformRequested() const;
136   void setTransformRequested ( OperationType );
137
138   /* Transformation is selected and already started */
139   bool          transformInProcess() const;
140   void          setTransformInProcess( bool );
141
142   void vpMousePressEvent(QMouseEvent* theEvent);
143   void vpMouseReleaseEvent(QMouseEvent* theEvent);
144   void vpMouseMoveEvent(QMouseEvent* theEvent);
145
146   void resetState();
147   void drawRect();
148   void endDrawRect();
149
150   void createActions();
151   void createToolBar();
152  
153   virtual OperationType getButtonState(QMouseEvent* theEvent);
154
155   viewAspect getViewParams() const;
156
157   bool computeGravityCenter( double& theX, double& theY, double& theZ );
158
159   virtual void                          onSketchingStarted();
160   virtual void                          onSketchingFinished();
161
162   virtual OCCViewer_ViewSketcher*       createSketcher( int );
163
164   OCCViewer_ViewSketcher*               mypSketcher;
165   QList<OCCViewer_ViewSketcher*>        mySketchers;
166
167   int                                   myCurSketch;
168
169   OperationType         myOperation;
170   OCCViewer_Viewer*     myModel;
171   OCCViewer_ViewPort3d* myViewPort;
172
173   RotationPointType     myCurrPointType;
174   RotationPointType     myPrevPointType;
175   gp_Pnt                mySelectedPoint;
176   bool                  myRotationPointSelection;
177
178   int                                   myRestoreFlag;
179
180   int                                   myStartX;
181   int                                   myStartY;
182   int                                   myCurrX;
183   int                                   myCurrY;
184
185   bool                  myEventStarted;       // set when transformation is in process 
186   bool                  myCursorIsHand;                 
187   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
188   bool                  myEnableDrawMode;
189   bool                  myPaintersRedrawing;  // set to draw with external painters 
190  
191   QCursor               myCursor;
192
193   double myCurScale;
194
195 private:
196   OCCViewer_ClippingDlg* myClippingDlg;
197   QtxAction* myClippingAction;
198
199   OCCViewer_AxialScaleDlg* myScalingDlg;
200
201   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
202   QtxAction* mySetRotationPointAction;
203
204   QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
205 };
206
207 #ifdef WIN32
208 #pragma warning( default:4251 )
209 #endif
210
211 #endif