Salome HOME
Merge from 'master'
[modules/shaper.git] / src / XGUI / XGUI_Viewer.h
1 #ifndef XGUI_Viewer_H
2 #define XGUI_Viewer_H
3
4 #include "XGUI.h"
5 #include "XGUI_Constants.h"
6
7 #include <QObject>
8 #include <QMap>
9 #include <QList>
10 #include <QPoint>
11 #include <QAction>
12
13 #include <V3d_Viewer.hxx>
14 #include <AIS_InteractiveContext.hxx>
15 #include <AIS_Trihedron.hxx>
16 #include <NCollection_List.hxx>
17 #include <TopoDS_Shape.hxx>
18
19
20 class XGUI_MainWindow;
21 class QMdiSubWindow;
22 class XGUI_ViewWindow;
23 class QMouseEvent;
24 class QKeyEvent;
25
26 class AIS_ListOfInteractive;
27
28 /**\class XGUI_Viewer
29  * \ingroup GUI
30  * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
31  * when each of view window is a one point of view on this scene.
32  */
33 class XGUI_EXPORT XGUI_Viewer: public QObject
34 {
35 Q_OBJECT
36 public:
37   static QString backgroundData(QStringList&, QIntList&, QIntList&);
38
39   XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
40   ~XGUI_Viewer();
41
42   //! Creates a new view window
43   QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
44
45   //! Return pointer on a main window - parent of the Viewer
46   XGUI_MainWindow* mainWindow() const
47   {
48     return myMainWindow;
49   }
50
51   //! Returns OCCT object which manages 3d scene
52   Handle(V3d_Viewer) v3dViewer() const
53   {
54     return myV3dViewer;
55   }
56
57   //! Returns OCCT object which manages displaying and selection in 3d scene
58   Handle(AIS_InteractiveContext) AISContext() const
59   {
60     return myAISContext;
61   }
62
63   //! Returns an active view window or NULL
64   XGUI_ViewWindow* activeViewWindow() const;
65
66   /// Return objects selected in 3D viewer
67   /// \param theList - list to be filled with selected objects
68   void  getSelectedObjects(AIS_ListOfInteractive& theList);
69
70   /// Return shapes selected in 3D viewer
71   /// \param theList - list to be filled with selected shapes
72   void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
73
74   /// Selects objects in 3D viewer. Other selected objects are left as selected
75   /// \param theList - list objects to be selected
76   void  setObjectsSelected(const AIS_ListOfInteractive& theList);
77
78   /// Returns true if selection in the viewer is enabled
79   bool isSelectionEnabled() const { return mySelectionEnabled; }
80
81   /// Enable or disable selectioon in the viewer
82   // \param toEnable - true or false (enable or disable selection)
83   void setSelectionEnabled(bool toEnable);
84
85   /// Returns true if multi-selection in the viewer is enabled
86   bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
87
88   /// Enable or disable selectioon in the viewer
89   // \param toEnable - true or false (enable or disable selection)
90   void setMultiSelectionEnabled(bool toEnable);
91
92   /// Select the object in 3D viewer.
93   /// \param theIO - list objects to be selected
94   void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
95
96   //! Trihedron 3d object shown in the viewer
97   Handle(AIS_Trihedron) trihedron() const
98   {
99     return myTrihedron;
100   }
101
102   //! On/Off visibility of the trihedron object
103   void toggleTrihedron();
104
105   //! Returns true if trihedron is visible
106   bool isTrihedronVisible() const;
107
108   //! Returns true if trihedron is visible
109   void setTrihedronShown(bool on);
110
111   //! Returns trihedron size
112   double trihedronSize() const;
113
114   //! Sets trihedron size
115   void setTrihedronSize(const double sz, bool isRelative);
116
117   bool trihedronRelative() const
118   {
119     return myIsRelative;
120   }
121   //! Update trihedron
122   void updateTrihedron();
123
124   //! Compute trihedron size dependent on 3d scene size
125   bool computeTrihedronSize(double& theNewSize, double& theSize);
126
127   //! Add action to the viewer
128   void addAction(QAction* theAction) { myActions.append(theAction); }
129
130
131   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
132                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
133   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
134                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
135
136   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
137   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
138
139   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
140   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
141
142   static InteractionStyle2StatesMap myStateMap;
143   static InteractionStyle2ButtonsMap myButtonMap;
144
145 signals:
146   void lastViewClosed();
147   void tryCloseView(XGUI_ViewWindow* theWindow);
148   void deleteView(XGUI_ViewWindow* theWindow);
149   void viewCreated(XGUI_ViewWindow* theWindow);
150   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
151   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
152   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
153   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
154   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
155   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
156   void activated(XGUI_ViewWindow* theWindow);
157   void selectionChanged();
158
159 public slots:
160   void onWindowMinimized(QMdiSubWindow*);
161   void onWindowActivated(QMdiSubWindow*);
162
163 private slots:
164   void onViewClosed(QMdiSubWindow*);
165   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
166   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
167   void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
168   void onContextMenuRequested(QContextMenuEvent* theEvent);
169
170 private:
171   void addView(QMdiSubWindow* theView);
172
173   /*! Removes the View from internal Views list.*/
174   void removeView(QMdiSubWindow* theView);
175
176   void updateViewsDrawMode() const;
177
178 private:
179   XGUI_MainWindow* myMainWindow;
180
181   Handle(V3d_Viewer) myV3dViewer;
182   Handle(AIS_Trihedron) myTrihedron;
183   Handle(AIS_InteractiveContext) myAISContext;
184
185   XGUI::InteractionStyle myInteractionStyle;
186
187   bool myPreselectionEnabled;
188   bool mySelectionEnabled;
189   bool myMultiSelectionEnabled;
190   bool myIsRelative;
191
192   double myTrihedronSize;
193   
194   QList<QMdiSubWindow*> myViews;
195
196   QMdiSubWindow* myActiveView;
197
198   /// Points used for selection management
199   QPoint myStartPnt, myEndPnt, myCurPnt;
200
201   /// A counter of created windows
202   int myWndIdCount;
203
204   /// List of Viewer actions
205   QList<QAction*> myActions;
206 };
207
208 #endif