Salome HOME
439b40cd683e5d22cc4bdbbcf9f0f1ac65024d15
[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/
18 //
19 #ifndef OCCVIEWER_VIEWWINDOW_H
20 #define OCCVIEWER_VIEWWINDOW_H
21
22 #include "OCCViewer_ViewModel.h"
23
24 #include "SUIT_ViewWindow.h"
25
26 #include "QtxAction.h"
27
28 #include <qcursor.h>
29 #include <qvaluelist.h>
30
31 class SUIT_Desktop;
32 class OCCViewer_ViewPort3d;
33
34 class OCCViewer_ClippingDlg;
35
36 #ifdef WIN32
37 #pragma warning( disable:4251 )
38 #endif
39
40 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
41 {
42   Q_OBJECT
43
44 public:
45   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
46                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW };
47
48   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
49         virtual ~OCCViewer_ViewWindow() {};
50
51   OCCViewer_ViewPort3d* getViewPort() { return myViewPort; }
52
53   bool eventFilter(QObject* watched, QEvent* e);
54
55   QToolBar* getToolBar() { return myToolBar; }
56
57   void performRestoring( const viewAspect& );
58   
59   virtual void initLayout();
60
61   void updateEnabledDrawMode();
62
63   void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
64                                  const double dx = 0, const double dy = 0, const double dz = 1);
65
66   bool isCuttingPlane();
67
68   virtual QString   getVisualParameters();
69   virtual void      setVisualParameters( const QString& parameters );
70  
71 public slots:
72   void onFrontView();
73   void onViewFitAll();
74   void onBackView();
75   void onTopView();
76   void onBottomView();
77   void onLeftView();
78   void onRightView();
79   void onResetView();
80   void onFitAll();
81   void activateZoom();
82   void activateWindowFit();
83   void activateRotation();
84   void activatePanning();
85   void activateGlobalPanning();
86   void onCloneView();
87   void onClipping( bool on );
88   void onMemorizeView();
89   void onRestoreView();
90   void onTrihedronShow();
91   void setRestoreFlag();
92   
93 signals:
94   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
95   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
96   void cloneView();
97
98 protected:
99   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId,
100          FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, CloneId, ClippingId, MemId, RestoreId,
101          TrihedronShowId };
102
103   typedef QMap<int, QtxAction*> ActionsMap;
104
105   QImage dumpView();
106
107   /* Transformation selected but not started yet */
108   bool transformRequested() const { return ( myOperation != NOTHING ); }
109   void setTransformRequested ( OperationType op );
110
111   /* Transformation is selected and already started */
112   bool          transformInProcess() const { return myEventStarted; }
113   void          setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
114
115   void vpMousePressEvent(QMouseEvent* theEvent);
116   void vpMouseReleaseEvent(QMouseEvent* theEvent);
117   void vpMouseMoveEvent(QMouseEvent* theEvent);
118
119   void resetState();
120   void drawRect();
121
122   void createActions();
123   void createToolBar();
124  
125   virtual OperationType getButtonState(QMouseEvent* theEvent);
126
127   viewAspect getViewParams() const;
128
129   OperationType         myOperation;
130   OCCViewer_Viewer*     myModel;
131   OCCViewer_ViewPort3d* myViewPort;
132
133   int                                   myRestoreFlag;
134
135   int                                   myStartX;
136   int                                   myStartY;
137   int                                   myCurrX;
138   int                                   myCurrY;
139
140   bool                  myEventStarted;       // set when transformation is in process 
141   bool                  myCursorIsHand;                 
142   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
143   bool                  myEnableDrawMode;
144   bool                  myPaintersRedrawing;  // set to draw with external painters 
145  
146   QRect                 myRect;                         
147   QCursor               myCursor;
148
149   QToolBar*  myToolBar;
150   ActionsMap myActionsMap;
151
152   double myCurScale;
153
154 private:
155   OCCViewer_ClippingDlg* myClippingDlg;
156   QtxAction* myClippingAction;
157   
158 };
159
160 #ifdef WIN32
161 #pragma warning( default:4251 )
162 #endif
163
164 #endif