Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef OCCVIEWER_VIEWWINDOW_H
20 #define OCCVIEWER_VIEWWINDOW_H
21
22 #include "OCCViewer_ViewModel.h"
23 #include "OCCViewer_ViewSketcher.h"
24
25 #include "SUIT_ViewWindow.h"
26
27 #include "QtxAction.h"
28
29 #include <qcursor.h>
30 #include <qvaluelist.h>
31
32 class SUIT_Desktop;
33 class OCCViewer_ViewPort3d;
34
35 class OCCViewer_ClippingDlg;
36 class OCCViewer_SetRotationPointDlg;
37
38 #ifdef WIN32
39 #pragma warning( disable:4251 )
40 #endif
41
42 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
43 {
44   Q_OBJECT
45
46 public:
47   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
48                       PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
49                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW };
50
51   enum RotationPointType{ GRAVITY, SELECTED };
52
53   enum SketchingType { NoSketching, Rect, Polygon };
54
55   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
56         virtual ~OCCViewer_ViewWindow() {};
57
58   OCCViewer_ViewPort3d* getViewPort() { return myViewPort; }
59
60   bool eventFilter(QObject* watched, QEvent* e);
61
62   QToolBar* getToolBar() { return myToolBar; }
63
64   void performRestoring( const viewAspect& );
65   
66   virtual void initLayout();
67
68   void updateEnabledDrawMode();
69
70   void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
71                                  const double dx = 0, const double dy = 0, const double dz = 1);
72
73   bool isCuttingPlane();
74
75   virtual QString   getVisualParameters();
76   virtual void      setVisualParameters( const QString& parameters );
77
78   virtual void            initSketchers();
79   OCCViewer_ViewSketcher* getSketcher( const int );
80
81   void                    activateSketching( int );
82  
83 public slots:
84   void onFrontView();
85   void onViewFitAll();
86   void onBackView();
87   void onTopView();
88   void onBottomView();
89   void onLeftView();
90   void onRightView();
91   void onResetView();
92   void onFitAll();
93   void activateZoom();
94   void activateWindowFit();
95   void activateRotation();
96   void activatePanning();
97   void activateGlobalPanning();
98   void onSetRotationPoint( bool on );
99   void onCloneView();
100   void onClipping( bool on );
101   void onMemorizeView();
102   void onRestoreView();
103   void onTrihedronShow();
104   void setRestoreFlag();
105
106   void activateSetRotationGravity();
107   void activateSetRotationSelected( double theX, double theY, double theZ );
108   void activateStartPointSelection();
109   void updateGravityCoords();
110    
111   virtual void showEvent( QShowEvent * );
112   virtual void hideEvent( QHideEvent * );
113
114 signals:
115   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
116   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
117   void cloneView();
118
119   void Show( QShowEvent * );
120   void Hide( QHideEvent * );
121
122 protected:
123   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
124          ChangeRotationPointId, RotationId,
125          FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, CloneId, ClippingId, MemId, RestoreId,
126          TrihedronShowId };
127
128   typedef QMap<int, QtxAction*> ActionsMap;
129
130   QImage dumpView();
131
132   /* Transformation selected but not started yet */
133   bool transformRequested() const { return ( myOperation != NOTHING ); }
134   void setTransformRequested ( OperationType op );
135
136   /* Transformation is selected and already started */
137   bool          transformInProcess() const { return myEventStarted; }
138   void          setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
139
140   void vpMousePressEvent(QMouseEvent* theEvent);
141   void vpMouseReleaseEvent(QMouseEvent* theEvent);
142   void vpMouseMoveEvent(QMouseEvent* theEvent);
143
144   void resetState();
145   void drawRect();
146
147   void createActions();
148   void createToolBar();
149  
150   virtual OperationType getButtonState(QMouseEvent* theEvent);
151
152   viewAspect getViewParams() const;
153
154   bool computeGravityCenter( double& theX, double& theY, double& theZ );
155
156   virtual void                          onSketchingStarted();
157   virtual void                          onSketchingFinished();
158
159   virtual OCCViewer_ViewSketcher*       createSketcher( int );
160
161   OCCViewer_ViewSketcher*               mypSketcher;
162   QList<OCCViewer_ViewSketcher>         mySketchers;
163
164   int                                   myCurSketch;
165
166   OperationType         myOperation;
167   OCCViewer_Viewer*     myModel;
168   OCCViewer_ViewPort3d* myViewPort;
169
170   RotationPointType     myCurrPointType;
171   RotationPointType     myPrevPointType;
172   gp_Pnt                mySelectedPoint;
173   bool                  myRotationPointSelection;
174
175   int                                   myRestoreFlag;
176
177   int                                   myStartX;
178   int                                   myStartY;
179   int                                   myCurrX;
180   int                                   myCurrY;
181
182   bool                  myEventStarted;       // set when transformation is in process 
183   bool                  myCursorIsHand;                 
184   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
185   bool                  myEnableDrawMode;
186   bool                  myPaintersRedrawing;  // set to draw with external painters 
187  
188   QRect                 myRect;                         
189   QCursor               myCursor;
190
191   QToolBar*  myToolBar;
192   ActionsMap myActionsMap;
193
194   double myCurScale;
195
196 private:
197   OCCViewer_ClippingDlg* myClippingDlg;
198   QtxAction* myClippingAction;
199
200   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
201   QtxAction* mySetRotationPointAction;
202   
203 };
204
205 #ifdef WIN32
206 #pragma warning( default:4251 )
207 #endif
208
209 #endif