]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Viewer.h
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 class XGUI_MainWindow;
18 class QMdiSubWindow;
19 class XGUI_ViewWindow;
20 class QMouseEvent;
21 class QKeyEvent;
22
23 class AIS_ListOfInteractive;
24
25 /**\class XGUI_Viewer
26  * \ingroup GUI
27  * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
28  * when each of view window is a one point of view on this scene.
29  */
30 class XGUI_EXPORT XGUI_Viewer: public QObject
31 {
32 Q_OBJECT
33 public:
34   static QString backgroundData(QStringList&, QIntList&, QIntList&);
35
36   XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
37   ~XGUI_Viewer();
38
39   //! Creates a new view window
40   QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
41
42   //! Return pointer on a main window - parent of the Viewer
43   XGUI_MainWindow* mainWindow() const
44   {
45     return myMainWindow;
46   }
47
48   //! Returns OCCT object which manages 3d scene
49   Handle(V3d_Viewer) v3dViewer() const
50   {
51     return myV3dViewer;
52   }
53
54   //! Returns OCCT object which manages displaying and selection in 3d scene
55   Handle(AIS_InteractiveContext) AISContext() const
56   {
57     return myAISContext;
58   }
59
60   //! Activate local selection
61   //! \param theAIS the list of objects
62   //! \param theMode the selection mode
63   //! \param isUpdateViewer the state wether the viewer should be updated immediatelly
64   void setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode,
65                          const bool isUpdateViewer);
66   //! Deactivate local selection
67   //! \param isUpdateViewer the state wether the viewer should be updated immediatelly
68   void setGlobalSelection(const bool isUpdateViewer);
69
70   /// Return objects selected in 3D viewer
71   /// \param theList - list to be filled with selected objects
72   void  getSelectedObjects(AIS_ListOfInteractive& theList);
73
74   /// Return shapes selected in 3D viewer
75   /// \param theList - list to be filled with selected shapes
76   void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
77
78   /// Selects objects in 3D viewer. Other selected objects are left as selected
79   /// \param theList - list objects to be selected
80   void  setObjectsSelected(const AIS_ListOfInteractive& theList);
81
82   /// Select the object in 3D viewer.
83   /// \param theIO - list objects to be selected
84   void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
85
86   //! Trihedron 3d object shown in the viewer
87   Handle(AIS_Trihedron) trihedron() const
88   {
89     return myTrihedron;
90   }
91
92   //! On/Off visibility of the trihedron object
93   void toggleTrihedron();
94
95   //! Returns true if trihedron is visible
96   bool isTrihedronVisible() const;
97
98   //! Returns true if trihedron is visible
99   void setTrihedronShown(bool on);
100
101   //! Returns trihedron size
102   double trihedronSize() const;
103
104   //! Sets trihedron size
105   void setTrihedronSize(const double sz, bool isRelative);
106
107   bool trihedronRelative() const
108   {
109     return myIsRelative;
110   }
111   //! Update trihedron
112   void updateTrihedron();
113
114   //! Compute trihedron size dependent on 3d scene size
115   bool computeTrihedronSize(double& theNewSize, double& theSize);
116
117   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
118                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
119   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
120                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
121
122   //! Sets the view projection
123   /// \param theX the X projection value
124   /// \param theY the Y projection value
125   /// \param theZ the Z projection value
126   void setViewProjection(double theX, double theY, double theZ);
127
128   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
129   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
130
131   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
132   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
133
134   static InteractionStyle2StatesMap myStateMap;
135   static InteractionStyle2ButtonsMap myButtonMap;
136
137 signals:
138   void lastViewClosed();
139   void tryCloseView(XGUI_ViewWindow* theWindow);
140   void deleteView(XGUI_ViewWindow* theWindow);
141   void viewCreated(XGUI_ViewWindow* theWindow);
142   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
143   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
144   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
145   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
146   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
147   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
148   void activated(XGUI_ViewWindow* theWindow);
149   void selectionChanged();
150
151 public slots:
152   void onWindowMinimized(QMdiSubWindow*);
153   void onWindowActivated(QMdiSubWindow*);
154
155 private slots:
156   void onViewClosed(QMdiSubWindow*);
157   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
158   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
159
160 private:
161   void addView(QMdiSubWindow* theView);
162
163   /*! Removes the View from internal Views list.*/
164   void removeView(QMdiSubWindow* theView);
165
166 private:
167   XGUI_MainWindow* myMainWindow;
168
169   Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
170
171   XGUI::InteractionStyle myInteractionStyle;
172
173   bool myPreselectionEnabled;
174   bool mySelectionEnabled;
175   bool myMultiSelectionEnabled;
176   bool myIsRelative;
177
178   double myTrihedronSize;
179   
180   QList<QMdiSubWindow*> myViews;
181
182   QMdiSubWindow* myActiveView;
183 };
184
185 #endif