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