]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewWindow.h
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 private slots:
199   void onClose();
200   void onMinimize();
201   void onMaximize();
202
203   void updateToolBar();
204 //  void repaintToolBar();
205
206 private:
207   enum WindowState
208   {
209     MinimizedState,
210     MaximizedState,
211     WindowNormalState
212   };
213
214   bool processWindowControls(QObject *theObj, QEvent *theEvent);
215   bool processViewPort(QEvent *theEvent);
216
217   void vpMousePressEvent(QMouseEvent* theEvent);
218   void vpMouseReleaseEvent(QMouseEvent* theEvent);
219   void vpMouseMoveEvent(QMouseEvent* theEvent);
220
221   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
222
223   void resetState();
224   void drawRect();
225   void endDrawRect();
226
227   bool transformRequested() const;
228   bool setTransformRequested(OperationType);
229
230   // Transformation is selected and already started
231   bool transformInProcess() const
232   {
233     return myEventStarted;
234   }
235   void setTransformInProcess(bool bOn)
236   {
237     myEventStarted = bOn;
238   }
239
240 private:
241   XGUI_Viewer* myViewer;
242
243   QLabel* myPicture;
244   ViewerLabel* myGripWgt;
245   XGUI_ViewPort* myViewPort;
246   ViewerToolbar* myViewBar;
247   ViewerToolbar* myWindowBar;
248   QAction* myMinimizeBtn;
249   QAction* myMaximizeBtn;
250
251   QIcon MinimizeIco;
252   QIcon MaximizeIco;
253   QIcon CloseIco;
254   QIcon RestoreIco;
255
256   bool myMoving;
257   QPoint myMousePnt;
258
259   WindowState myLastState;
260
261   int myStartX;
262   int myStartY;
263   int myCurrX;
264   int myCurrY;
265
266   XGUI::InteractionStyle myInteractionStyle;
267   OperationType myOperation;
268   XGUI::Mode2dType my2dMode;
269
270   int myCurSketch;
271   bool myDrawRect;          // set when a rect is used for selection or magnify 
272   bool myEnableDrawMode;
273   bool myRotationPointSelection;
274   bool myCursorIsHand;
275   bool myIsKeyFree;
276   bool myEventStarted;       // set when transformation is in process 
277   bool myClosable;
278   bool myIsActive;
279
280   QCursor myCursor;
281
282   XGUI::RotationPointType myCurrPointType;
283   XGUI::RotationPointType myPrevPointType;
284
285   gp_Pnt mySelectedPoint;
286
287   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
288
289   typedef QMap<OperationType, bool> MapOfTransformStatus;
290   MapOfTransformStatus myStatus;
291
292   double myCurScale;
293 };
294
295 //******************************************************
296 /*!
297   \class ViewerToolbar
298   \ingroup GUI
299   \brief Provides a toolbar widget with treansparent background over OCCT View window
300 */
301 class ViewerToolbar: public QToolBar
302 {
303 Q_OBJECT
304 public:
305   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort);
306
307 protected slots:
308   void onViewPortResized() { myResize = true; }
309
310 protected:
311   virtual void paintEvent(QPaintEvent* theEvent);
312
313
314
315 private:
316   XGUI_ViewPort* myVPort;
317   bool myResize;
318 };
319
320 //******************************************************
321 /*!
322   \class ViewerToolbar
323   \ingroup GUI
324   \brief Provides a Label widget with treansparent background over OCCT View window
325 */
326 class ViewerLabel: public QLabel
327 {
328 Q_OBJECT
329 public:
330   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort);
331
332 protected slots:
333   void onViewPortResized() { myResize = true; }
334
335 protected:
336   virtual void paintEvent(QPaintEvent* theEvent);
337
338 private:
339   XGUI_ViewPort* myVPort;
340   bool myResize;
341 };
342
343 #endif