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