Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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   //! Trihedron 3d object shown in the viewer
69   Handle(AIS_Trihedron) trihedron() const
70   {
71     return myTrihedron;
72   }
73
74   //! On/Off visibility of the trihedron object
75   void toggleTrihedron();
76
77   //! Returns true if trihedron is visible
78   bool isTrihedronVisible() const;
79
80   //! Returns true if trihedron is visible
81   void setTrihedronShown(bool on);
82
83   //! Returns trihedron size
84   double trihedronSize() const;
85
86   //! Sets trihedron size
87   void setTrihedronSize(const double sz, bool isRelative);
88
89   bool trihedronRelative() const
90   {
91     return myIsRelative;
92   }
93   //! Update trihedron
94   void updateTrihedron();
95
96   //! Compute trihedron size dependent on 3d scene size
97   bool computeTrihedronSize(double& theNewSize, double& theSize);
98
99   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
100                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
101   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
102                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
103
104   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
105   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
106
107   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
108   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
109
110   static InteractionStyle2StatesMap myStateMap;
111   static InteractionStyle2ButtonsMap myButtonMap;
112
113 signals:
114   void lastViewClosed();
115   void tryCloseView(XGUI_ViewWindow* theWindow);
116   void deleteView(XGUI_ViewWindow* theWindow);
117   void viewCreated(XGUI_ViewWindow* theWindow);
118   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
119   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
120   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
121   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
122   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
123   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
124   void activated(XGUI_ViewWindow* theWindow);
125   void selectionChanged();
126
127 public slots:
128   void onWindowMinimized(QMdiSubWindow*);
129   void onWindowActivated(QMdiSubWindow*);
130
131 private slots:
132   void onViewClosed(QMdiSubWindow*);
133   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
134   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
135
136 private:
137   void addView(QMdiSubWindow* theView);
138
139   /*! Removes the View from internal Views list.*/
140   void removeView(QMdiSubWindow* theView);
141
142 private:
143   XGUI_MainWindow* myMainWindow;
144
145   Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
146
147   XGUI::InteractionStyle myInteractionStyle;
148
149   bool myPreselectionEnabled;
150   bool mySelectionEnabled;
151   bool myMultiSelectionEnabled;
152   bool myIsRelative;
153
154   double myTrihedronSize;
155   
156   QList<QMdiSubWindow*> myViews;
157
158   QMdiSubWindow* myActiveView;
159 };
160
161 #endif