]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewWindow.h
Salome HOME
Resources XML file created
[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 { return myClosable; }
87
88   //! Sets the current view window closable or not
89   void setClosable( const bool isClosable ) { myClosable = isClosable; }
90
91   //! Enable/Disable drawing of ribbon line
92   void enableDrawMode(bool toEnable) { myEnableDrawMode = toEnable; }
93
94   //! Returns true if ribbon line drawing enabled
95   bool isDrawModeEnabled() const { return myEnableDrawMode; }
96
97   //! Updates drawing mode in the view window
98   void updateEnabledDrawMode();
99
100 signals:
101   //! Emited whien view transformation operation is started
102   void vpTransformationStarted(XGUI_ViewWindow::OperationType type);
103
104   //! Emited whien view transformation operation is finished
105   void vpTransformationFinished(XGUI_ViewWindow::OperationType type);
106
107   //void Show(QShowEvent *);
108   //void Hide(QHideEvent *);
109   //void maximized(XGUI_ViewWindow*, bool);
110   //void returnedTo3d();
111
112   //! Emited before the window closing
113   void tryClosing(XGUI_ViewWindow*);
114
115   //! Emited when window is closing
116   void closed( QMdiSubWindow* );
117
118   //! Emited on mouse press in view port
119   void mousePressed(XGUI_ViewWindow*, QMouseEvent*);
120
121   //! Emited on mouse release in view port
122   void mouseReleased(XGUI_ViewWindow*, QMouseEvent*);
123
124   //! Emited on mouse double click in view port
125   void mouseDoubleClicked(XGUI_ViewWindow*, QMouseEvent*);
126
127   //! Emited on mouse moving in view port
128   void mouseMoving(XGUI_ViewWindow*, QMouseEvent*);
129  
130   //! Emited on key press in view port
131   void keyPressed(XGUI_ViewWindow*, QKeyEvent*);
132  
133   //! Emited on key release in view port
134   void keyReleased(XGUI_ViewWindow*, QKeyEvent*);
135  
136   //! Emited on context menu request in view port
137   void contextMenuRequested(QContextMenuEvent *e);
138
139   //void viewModified(XGUI_ViewWindow*);
140   void viewCloned( QMdiSubWindow* theView );
141
142 public slots:
143   //! Start zooming operation
144   void activateZoom();
145
146   //! Start rotation operation
147   void activateRotation();
148
149   //! Start panning operation
150   void activatePanning();
151
152   //! Start window fit operation
153   void activateWindowFit();
154
155   //! Start global panning operation
156   void activateGlobalPanning();
157
158   //! Clone the view window preserving a view point of the current view
159   void cloneView();
160
161   //! Dump the view window into external file (*.bmp *.png *.jpg *.jpeg *.eps *.ps)
162   void dumpView();
163
164   //! Fit all command
165   void fitAll();
166
167   //! Set front view
168   void frontView();
169
170   //! Set back view
171   void backView();
172
173   //! Set top view
174   void topView();
175
176   //! Set bottom view
177   void bottomView();
178
179   //! Set left view
180   void leftView();
181
182   //! Set right view
183   void rightView();
184
185   //! Reset point of view
186   void reset();
187
188   void windowActivated();
189
190   void windowDeactivated();
191
192 protected:
193   virtual void changeEvent(QEvent* theEvent);
194
195   virtual bool eventFilter(QObject *theObj, QEvent *theEvent);
196
197   virtual void showEvent(QShowEvent* theEvent);
198
199   virtual void contextMenuEvent(QContextMenuEvent* theEvent);
200
201 private slots:
202   void onClose();
203   void onMinimize();
204   void onMaximize();
205
206   void updateToolBar();
207 //  void repaintToolBar();
208
209 private:
210   enum WindowState
211   {
212     MinimizedState,
213     MaximizedState,
214     WindowNormalState
215   };
216
217   bool processWindowControls(QObject *theObj, QEvent *theEvent);
218   bool processViewPort(QEvent *theEvent);
219
220   void vpMousePressEvent(QMouseEvent* theEvent);
221   void vpMouseReleaseEvent(QMouseEvent* theEvent);
222   void vpMouseMoveEvent(QMouseEvent* theEvent);
223
224   OperationType getButtonState(QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle);
225
226   void resetState();
227   void drawRect();
228   void endDrawRect();
229
230   bool transformRequested() const;
231   bool setTransformRequested(OperationType);
232
233   // Transformation is selected and already started
234   bool transformInProcess() const
235   {
236     return myEventStarted;
237   }
238   void setTransformInProcess(bool bOn)
239   {
240     myEventStarted = bOn;
241   }
242
243 private:
244   XGUI_Viewer* myViewer;
245
246   QLabel* myPicture;
247   ViewerLabel* myGripWgt;
248   XGUI_ViewPort* myViewPort;
249   ViewerToolbar* myViewBar;
250   ViewerToolbar* myWindowBar;
251   QAction* myMinimizeBtn;
252   QAction* myMaximizeBtn;
253
254   QIcon MinimizeIco;
255   QIcon MaximizeIco;
256   QIcon CloseIco;
257   QIcon RestoreIco;
258
259   bool myMoving;
260   QPoint myMousePnt;
261
262   WindowState myLastState;
263
264   int myStartX;
265   int myStartY;
266   int myCurrX;
267   int myCurrY;
268
269   XGUI::InteractionStyle myInteractionStyle;
270   OperationType myOperation;
271   XGUI::Mode2dType my2dMode;
272
273   int myCurSketch;
274   bool myDrawRect;          // set when a rect is used for selection or magnify 
275   bool myEnableDrawMode;
276   bool myRotationPointSelection;
277   bool myCursorIsHand;
278   bool myIsKeyFree;
279   bool myEventStarted;       // set when transformation is in process 
280   bool myClosable;
281   bool myIsActive;
282
283   QCursor myCursor;
284
285   XGUI::RotationPointType myCurrPointType;
286   XGUI::RotationPointType myPrevPointType;
287
288   gp_Pnt mySelectedPoint;
289
290   XGUI_RectRubberBand* myRectBand; //!< selection rectangle rubber band
291
292   typedef QMap<OperationType, bool> MapOfTransformStatus;
293   MapOfTransformStatus myStatus;
294
295   double myCurScale;
296 };
297
298 //******************************************************
299 /*!
300   \class ViewerToolbar
301   \ingroup GUI
302   \brief Provides a toolbar widget with treansparent background over OCCT View window
303 */
304 class ViewerToolbar: public QToolBar
305 {
306 Q_OBJECT
307 public:
308   ViewerToolbar(QWidget* theParent, XGUI_ViewPort* thePort);
309
310 protected slots:
311   void onViewPortResized() { myResize = true; }
312
313 protected:
314   virtual void paintEvent(QPaintEvent* theEvent);
315
316
317
318 private:
319   XGUI_ViewPort* myVPort;
320   bool myResize;
321 };
322
323 //******************************************************
324 /*!
325   \class ViewerToolbar
326   \ingroup GUI
327   \brief Provides a Label widget with treansparent background over OCCT View window
328 */
329 class ViewerLabel: public QLabel
330 {
331 Q_OBJECT
332 public:
333   ViewerLabel(QWidget* theParent, XGUI_ViewPort* thePort);
334
335 protected slots:
336   void onViewPortResized() { myResize = true; }
337
338 protected:
339   virtual void paintEvent(QPaintEvent* theEvent);
340
341 private:
342   XGUI_ViewPort* myVPort;
343   bool myResize;
344 };
345
346 #endif