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