Salome HOME
fc0476cbba2d4e2882c647c3249eea415ac4f586
[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 XGUI_Viewer
22  * \ingroup GUI
23  * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
24  * when each of view window is a one point of view on this scene.
25  */
26 class XGUI_EXPORT XGUI_Viewer: public QObject
27 {
28 Q_OBJECT
29 public:
30   static QString backgroundData(QStringList&, QIntList&, QIntList&);
31
32   XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
33   ~XGUI_Viewer();
34
35   //! Creates a new view window
36   QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
37
38   //! Return pointer on a main window - parent of the Viewer
39   XGUI_MainWindow* mainWindow() const
40   {
41     return myMainWindow;
42   }
43
44   //! Returns OCCT object which manages 3d scene
45   Handle(V3d_Viewer) v3dViewer() const
46   {
47     return myV3dViewer;
48   }
49
50   //! Returns OCCT object which manages displaying and selection in 3d scene
51   Handle(AIS_InteractiveContext) AISContext() const
52   {
53     return myAISContext;
54   }
55
56   //! Trihedron 3d object shown in the viewer
57   Handle(AIS_Trihedron) trihedron() const
58   {
59     return myTrihedron;
60   }
61
62   //! On/Off visibility of the trihedron object
63   void toggleTrihedron();
64
65   //! Returns true if trihedron is visible
66   bool isTrihedronVisible() const;
67
68   //! Returns true if trihedron is visible
69   void setTrihedronShown(bool on);
70
71   //! Returns trihedron size
72   double trihedronSize() const;
73
74   //! Sets trihedron size
75   void setTrihedronSize(const double sz, bool isRelative);
76
77   bool trihedronRelative() const
78   {
79     return myIsRelative;
80   }
81   //! Update trihedron
82   void updateTrihedron();
83
84   //! Compute trihedron size dependent on 3d scene size
85   bool computeTrihedronSize(double& theNewSize, double& theSize);
86
87   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
88                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
89   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
90                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
91
92   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
93   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
94
95   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
96   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
97
98   static InteractionStyle2StatesMap myStateMap;
99   static InteractionStyle2ButtonsMap myButtonMap;
100
101 signals:
102   void lastViewClosed();
103   void tryCloseView(XGUI_ViewWindow* theWindow);
104   void deleteView(XGUI_ViewWindow* theWindow);
105   void viewCreated(XGUI_ViewWindow* theWindow);
106   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
107   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
108   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
109   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
110   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
111   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
112   void activated(XGUI_ViewWindow* theWindow);
113
114 private slots:
115   void onViewClosed(QMdiSubWindow*);
116   //void onViewMapped();
117   void onWindowActivated(QMdiSubWindow*);
118
119 private:
120   void addView(QMdiSubWindow* theView);
121
122   /*! Removes the View from internal Views list.*/
123   void removeView(QMdiSubWindow* theView);
124
125 private:
126   XGUI_MainWindow* myMainWindow;
127
128   Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
129
130   XGUI::InteractionStyle myInteractionStyle;
131
132   bool myPreselectionEnabled;
133   bool mySelectionEnabled;
134   bool myMultiSelectionEnabled;
135   bool myIsRelative;
136
137   double myTrihedronSize;
138   
139   QList<QMdiSubWindow*> myViews;
140
141   QMdiSubWindow* myActiveView;
142 };
143
144 #endif