Salome HOME
Sources formated according to the codeing standards
[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 #include <ModuleBase_Definitions.h>
7
8 #include <QObject>
9 #include <QMap>
10 #include <QList>
11 #include <QPoint>
12 #include <QAction>
13
14 #include <V3d_Viewer.hxx>
15 #include <AIS_InteractiveContext.hxx>
16 #include <AIS_Trihedron.hxx>
17 #include <NCollection_List.hxx>
18 #include <TopoDS_Shape.hxx>
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
80   {
81     return mySelectionEnabled;
82   }
83
84   /// Enable or disable selectioon in the viewer
85   // \param toEnable - true or false (enable or disable selection)
86   void setSelectionEnabled(bool toEnable);
87
88   /// Returns true if multi-selection in the viewer is enabled
89   bool isMultiSelectionEnabled() const
90   {
91     return myMultiSelectionEnabled;
92   }
93
94   /// Enable or disable selectioon in the viewer
95   // \param toEnable - true or false (enable or disable selection)
96   void setMultiSelectionEnabled(bool toEnable);
97
98   /// Select the object in 3D viewer.
99   /// \param theIO - list objects to be selected
100   void setSelected(const Handle(AIS_InteractiveObject)& theIO)
101   {
102     myAISContext->SetSelected(theIO);
103   }
104
105   //! Trihedron 3d object shown in the viewer
106   Handle(AIS_Trihedron) trihedron() const
107   {
108     return myTrihedron;
109   }
110
111   //! On/Off visibility of the trihedron object
112   void toggleTrihedron();
113
114   //! Returns true if trihedron is visible
115   bool isTrihedronVisible() const;
116
117   //! Returns true if trihedron is visible
118   void setTrihedronShown(bool on);
119
120   //! Returns trihedron size
121   double trihedronSize() const;
122
123   //! Sets trihedron size
124   void setTrihedronSize(const double sz, bool isRelative);
125
126   bool trihedronRelative() const
127   {
128     return myIsRelative;
129   }
130   //! Update trihedron
131   void updateTrihedron();
132
133   //! Compute trihedron size dependent on 3d scene size
134   bool computeTrihedronSize(double& theNewSize, double& theSize);
135
136   //! Add action to the viewer
137   void addAction(QAction* theAction)
138   {
139     myActions.append(theAction);
140   }
141
142   void updateFromResources();
143
144   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
145                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
146   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
147                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
148
149   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
150   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
151
152   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
153   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
154
155   static InteractionStyle2StatesMap myStateMap;
156   static InteractionStyle2ButtonsMap myButtonMap;
157
158 signals:
159   void lastViewClosed();
160   void tryCloseView(XGUI_ViewWindow* theWindow);
161   void deleteView(XGUI_ViewWindow* theWindow);
162   void viewCreated(XGUI_ViewWindow* theWindow);
163   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
164   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
165   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
166   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
167   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
168   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
169   void activated(XGUI_ViewWindow* theWindow);
170   void selectionChanged();
171
172   void contextMenuRequested(QContextMenuEvent*);
173
174  public slots:
175   void onWindowMinimized(QMdiSubWindow*);
176   void onWindowActivated(QMdiSubWindow*);
177
178  private slots:
179   void onViewClosed(QMdiSubWindow*);
180   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
181   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
182   void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
183   //void onContextMenuRequested(QContextMenuEvent* theEvent);
184
185  private:
186   void addView(QMdiSubWindow* theView);
187
188   /*! Removes the View from internal Views list.*/
189   void removeView(QMdiSubWindow* theView);
190
191   void updateViewsDrawMode() const;
192
193  private:
194   XGUI_MainWindow* myMainWindow;
195
196   Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
197
198   XGUI::InteractionStyle myInteractionStyle;
199
200   bool myPreselectionEnabled;
201   bool mySelectionEnabled;
202   bool myMultiSelectionEnabled;
203   bool myIsRelative;
204
205   double myTrihedronSize;
206
207   QList<QMdiSubWindow*> myViews;
208
209   QMdiSubWindow* myActiveView;
210
211   /// Points used for selection management
212   QPoint myStartPnt, myEndPnt, myCurPnt;
213
214   /// A counter of created windows
215   int myWndIdCount;
216
217   /// List of Viewer actions
218   QList<QAction*> myActions;
219 };
220
221 #endif