]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Viewer.h
Salome HOME
c7a2492f1fda250990112f6ca7ab1f198113c146
[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   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
123   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
124
125   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
126   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
127
128   static InteractionStyle2StatesMap myStateMap;
129   static InteractionStyle2ButtonsMap myButtonMap;
130
131 signals:
132   void lastViewClosed();
133   void tryCloseView(XGUI_ViewWindow* theWindow);
134   void deleteView(XGUI_ViewWindow* theWindow);
135   void viewCreated(XGUI_ViewWindow* theWindow);
136   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
137   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
138   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
139   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
140   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
141   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
142   void activated(XGUI_ViewWindow* theWindow);
143   void selectionChanged();
144
145 public slots:
146   void onWindowMinimized(QMdiSubWindow*);
147   void onWindowActivated(QMdiSubWindow*);
148
149 private slots:
150   void onViewClosed(QMdiSubWindow*);
151   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
152   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
153
154 private:
155   void addView(QMdiSubWindow* theView);
156
157   /*! Removes the View from internal Views list.*/
158   void removeView(QMdiSubWindow* theView);
159
160 private:
161   XGUI_MainWindow* myMainWindow;
162
163   Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
164
165   XGUI::InteractionStyle myInteractionStyle;
166
167   bool myPreselectionEnabled;
168   bool mySelectionEnabled;
169   bool myMultiSelectionEnabled;
170   bool myIsRelative;
171
172   double myTrihedronSize;
173   
174   QList<QMdiSubWindow*> myViews;
175
176   QMdiSubWindow* myActiveView;
177 };
178
179 #endif