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