Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / XGUI / XGUI_ViewWindow.h
1 #ifndef XGUI_ViewWindow_H
2 #define XGUI_ViewWindow_H
3
4 #include "XGUI.h"
5 #include "XGUI_Constants.h"
6 #include "XGUI_ViewBackground.h"
7
8 #include <QFrame>
9 #include <QIcon>
10 #include <QToolBar>
11 #include <QLabel>
12 #include <QMap>
13
14 #include <V3d_View.hxx>
15 #include <V3d_Viewer.hxx>
16
17 class XGUI_ViewPort;
18 class XGUI_Viewer;
19 class ViewerToolbar;
20 class ViewerLabel;
21 class XGUI_RectRubberBand;
22 class QMdiSubWindow;
23
24 /*!
25   \class XGUI_ViewWindow
26   \ingroup GUI
27   \brief Implements a one view window of 3d viewer object.
28   It contains a view port object (drawing area) and toolbars for view camera and window management.
29   Also it managements events in view port
30 */
31 class XGUI_EXPORT XGUI_ViewWindow: public QFrame
32 {
33 Q_OBJECT
34 public:
35   //! Types of viewer operations
36   enum OperationType
37   {
38     NOTHING,
39     PANVIEW,
40     ZOOMVIEW,
41     ROTATE,
42     PANGLOBAL,
43     WINDOWFIT,
44     FITALLVIEW,
45     RESETVIEW,
46     FRONTVIEW,
47     BACKVIEW,
48     TOPVIEW,
49     BOTTOMVIEW,
50     LEFTVIEW,
51     RIGHTVIEW,
52     CLOCKWISEVIEW,
53     ANTICLOCKWISEVIEW
54   };
55
56   XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType);
57
58   virtual ~XGUI_ViewWindow();
59
60   //! Returns view port object
61   XGUI_ViewPort* viewPort() const
62   {
63     return myViewPort;
64   }
65
66   //! Retrurns current interaction style
67   XGUI::InteractionStyle interactionStyle() const
68   {
69     return myInteractionStyle;
70   }
71
72   //! Disable or enable given operation type
73   void setTransformEnabled(const OperationType, const bool);
74
75   //! Returns true if the given operation type is enabled
76   bool transformEnabled(const OperationType) const;
77
78   //! Returns View background object
79   XGUI_ViewBackground background() const;
80
81   //! Sets View background object
82   void setBackground(const XGUI_ViewBackground& theBackground);
83
84   //! Returns true if the current view window can be closed
85   bool closable() const { return myClosable; }
86
87   //! Sets the current view window closable or not
88   void setClosable( const bool isClosable ) { myClosable = isClosable; }
89
90   //! Enable/Disable drawing of ribbon line
91   void enableDrawMode(bool toEnable) { myEnableDrawMode = toEnable; }
92
93   //! Returns true if ribbon line drawing enabled
94   bool isDrawModeEnabled() const { return myEnableDrawMode; }
95
96   //! Updates drawing mode in the view window
97   void updateEnabledDrawMode();
98
99 signals:
100   //! Emited whien view transformation operation is started
101   void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
102
103   //! Emited whien view transformation operation is finished
104   void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
105
106   //void Show(QShowEvent *);
107   //void Hide(QHideEvent *);
108   //void maximized(XGUI_ViewWindow*, bool);
109   //void returnedTo3d();
110
111   //! Emited before the window closing
112   void tryClosing(XGUI_ViewWindow*);
113
114   //! Emited when window is closing
115   void closed( QMdiSubWindow* );
116
117   //! Emited on mouse press in view port
118   void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
119
120   //! Emited on mouse release in view port
121   void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
122
123   //! Emited on mouse double click in view port
124   void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
125
126   //! Emited on mouse moving in view port
127   void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
128  
129   //! Emited on key press in view port
130   void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
131  
132   //! Emited on key release in view port
133   void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
134  
135   //! Emited on context menu request in view port
136   void contextMenuRequested(QContextMenuEvent *e);
137
138   //void viewModified(XGUI_ViewWindow*);
139   void viewCloned( QMdiSubWindow* theView );
140
141 public slots:
142   //! Start zooming operation
143   void activateZoom();
144
145   //! Start rotation operation
146   void activateRotation();
147
148   //! Start panning operation
149   void activatePanning();
150
151   //! Start window fit operation
152   void activateWindowFit();
153
154   //! Start global panning operation
155   void activateGlobalPanning();
156
157   //! Clone the view window preserving a view point of the current view
158   void cloneView();
159
160   //! Dump the view window into external file (*.bmp *.png *.jpg *.jpeg *.eps *.ps)
161   void dumpView();
162
163   //! Fit all command
164   void fitAll();
165
166   //! Set front view
167   void frontView();
168
169   //! Set back view
170   void backView();
171
172   //! Set top view
173   void topView();
174
175   //! Set bottom view
176   void bottomView();
177
178   //! Set left view
179   void leftView();
180
181   //! Set right view
182   void rightView();
183
184   //! Reset point of view
185   void reset();
186
187   void windowActivated();
188
189   void windowDeactivated();
190
191 protected:
192   virtual void changeEvent(QEvent* theEvent);
193
194   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
195
196   virtual void showEvent(QShowEvent* theEvent);
197
198   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
199
200 private slots:
201   void onClose();
202   void onMinimize();
203   void onMaximize();
204
205   void updateToolBar();
206 //  void repaintToolBar();
207
208 private:
209   enum WindowState
210   {
211     MinimizedState,
212     MaximizedState,
213     WindowNormalState
214   };
215
216   bool processWindowControls(QObject *theObj, QEvent *theEvent);
217   bool processViewPort(QEvent *theEvent);
218
219   void vpMousePressEvent(QMouseEvent* theEvent);
220   void vpMouseReleaseEvent(QMouseEvent* theEvent);
221   void vpMouseMoveEvent(QMouseEvent* theEvent);
222
223   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
224
225   void resetState();
226   void drawRect();
227   void endDrawRect();
228
229   bool transformRequested() const;
230   bool setTransformRequested(OperationType);
231
232   // Transformation is selected and already started
233   bool transformInProcess() const
234   {
235     return myEventStarted;
236   }
237   void setTransformInProcess(bool bOn)
238   {
239     myEventStarted = bOn;
240   }
241
242 private:
243   XGUI_Viewer* myViewer;
244
245   QLabel* myPicture;
246   ViewerLabel* myGripWgt;
247   XGUI_ViewPort* myViewPort;
248   ViewerToolbar* myViewBar;
249   ViewerToolbar* myWindowBar;
250   QAction* myMinimizeBtn;
251   QAction* myMaximizeBtn;
252
253   QIcon MinimizeIco;
254   QIcon MaximizeIco;
255   QIcon CloseIco;
256   QIcon RestoreIco;
257
258   bool myMoving;
259   QPoint myMousePnt;
260
261   WindowState myLastState;
262
263   int myStartX;
264   int myStartY;
265   int myCurrX;
266   int myCurrY;
267
268   XGUI::InteractionStyle myInteractionStyle;
269   OperationType myOperation;
270   XGUI::Mode2dType my2dMode;
271
272   int myCurSketch;
273   bool myDrawRect;          // set when a rect is used for selection or magnify 
274   bool myEnableDrawMode;
275   bool myRotationPointSelection;
276   bool myCursorIsHand;
277   bool myIsKeyFree;
278   bool myEventStarted;       // set when transformation is in process 
279   bool myClosable;
280   bool myIsActive;
281
282   QCursor myCursor;
283
284   XGUI::RotationPointType myCurrPointType;
285   XGUI::RotationPointType myPrevPointType;
286
287   gp_Pnt mySelectedPoint;
288
289   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
290
291   typedef QMap<OperationType, bool> MapOfTransformStatus;
292   MapOfTransformStatus myStatus;
293
294   double myCurScale;
295 };
296
297 //******************************************************
298 /*!
299   \class ViewerToolbar
300   \ingroup GUI
301   \brief Provides a toolbar widget with treansparent background over OCCT View window
302 */
303 class ViewerToolbar: public QToolBar
304 {
305 Q_OBJECT
306 public:
307   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort);
308
309 protected slots:
310   void onViewPortResized() { myResize = true; }
311
312 protected:
313   virtual void paintEvent(QPaintEvent* theEvent);
314
315
316
317 private:
318   XGUI_ViewPort* myVPort;
319   bool myResize;
320 };
321
322 //******************************************************
323 /*!
324   \class ViewerToolbar
325   \ingroup GUI
326   \brief Provides a Label widget with treansparent background over OCCT View window
327 */
328 class ViewerLabel: public QLabel
329 {
330 Q_OBJECT
331 public:
332   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort);
333
334 protected slots:
335   void onViewPortResized() { myResize = true; }
336
337 protected:
338   virtual void paintEvent(QPaintEvent* theEvent);
339
340 private:
341   XGUI_ViewPort* myVPort;
342   bool myResize;
343 };
344
345 #endif