Salome HOME
Some slight improvements and bugs fixing.
[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 #include <ModuleBase_Definitions.h>
7
8 #include <QObject>
9 #include <QMap>
10 #include <QList>
11 #include <QPoint>
12 #include <QAction>
13
14 #include <V3d_Viewer.hxx>
15 #include <AIS_InteractiveContext.hxx>
16 #include <AIS_Trihedron.hxx>
17 #include <NCollection_List.hxx>
18 #include <TopoDS_Shape.hxx>
19
20
21 class XGUI_MainWindow;
22 class QMdiSubWindow;
23 class XGUI_ViewWindow;
24 class QMouseEvent;
25 class QKeyEvent;
26
27 class AIS_ListOfInteractive;
28
29 /**\class XGUI_Viewer
30  * \ingroup GUI
31  * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
32  * when each of view window is a one point of view on this scene.
33  */
34 class XGUI_EXPORT XGUI_Viewer: public QObject
35 {
36 Q_OBJECT
37 public:
38   static QString backgroundData(QStringList&, QIntList&, QIntList&);
39
40   XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
41   ~XGUI_Viewer();
42
43   //! Creates a new view window
44   QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
45
46   //! Return pointer on a main window - parent of the Viewer
47   XGUI_MainWindow* mainWindow() const
48   {
49     return myMainWindow;
50   }
51
52   //! Returns OCCT object which manages 3d scene
53   Handle(V3d_Viewer) v3dViewer() const
54   {
55     return myV3dViewer;
56   }
57
58   //! Returns OCCT object which manages displaying and selection in 3d scene
59   Handle(AIS_InteractiveContext) AISContext() const
60   {
61     return myAISContext;
62   }
63
64   //! Returns an active view window or NULL
65   XGUI_ViewWindow* activeViewWindow() const;
66
67   /// Return objects selected in 3D viewer
68   /// \param theList - list to be filled with selected objects
69   void  getSelectedObjects(AIS_ListOfInteractive& theList);
70
71   /// Return shapes selected in 3D viewer
72   /// \param theList - list to be filled with selected shapes
73   void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
74
75   /// Selects objects in 3D viewer. Other selected objects are left as selected
76   /// \param theList - list objects to be selected
77   void  setObjectsSelected(const AIS_ListOfInteractive& theList);
78
79   /// Returns true if selection in the viewer is enabled
80   bool isSelectionEnabled() const { return mySelectionEnabled; }
81
82   /// Enable or disable selectioon in the viewer
83   // \param toEnable - true or false (enable or disable selection)
84   void setSelectionEnabled(bool toEnable);
85
86   /// Returns true if multi-selection in the viewer is enabled
87   bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
88
89   /// Enable or disable selectioon in the viewer
90   // \param toEnable - true or false (enable or disable selection)
91   void setMultiSelectionEnabled(bool toEnable);
92
93   /// Select the object in 3D viewer.
94   /// \param theIO - list objects to be selected
95   void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
96
97   //! Trihedron 3d object shown in the viewer
98   Handle(AIS_Trihedron) trihedron() const
99   {
100     return myTrihedron;
101   }
102
103   //! On/Off visibility of the trihedron object
104   void toggleTrihedron();
105
106   //! Returns true if trihedron is visible
107   bool isTrihedronVisible() const;
108
109   //! Returns true if trihedron is visible
110   void setTrihedronShown(bool on);
111
112   //! Returns trihedron size
113   double trihedronSize() const;
114
115   //! Sets trihedron size
116   void setTrihedronSize(const double sz, bool isRelative);
117
118   bool trihedronRelative() const
119   {
120     return myIsRelative;
121   }
122   //! Update trihedron
123   void updateTrihedron();
124
125   //! Compute trihedron size dependent on 3d scene size
126   bool computeTrihedronSize(double& theNewSize, double& theSize);
127
128   //! Add action to the viewer
129   void addAction(QAction* theAction) { myActions.append(theAction); }
130
131
132   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
133                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
134   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
135                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
136
137   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
138   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
139
140   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
141   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
142
143   static InteractionStyle2StatesMap myStateMap;
144   static InteractionStyle2ButtonsMap myButtonMap;
145
146 signals:
147   void lastViewClosed();
148   void tryCloseView(XGUI_ViewWindow* theWindow);
149   void deleteView(XGUI_ViewWindow* theWindow);
150   void viewCreated(XGUI_ViewWindow* theWindow);
151   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
152   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
153   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
154   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
155   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
156   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
157   void activated(XGUI_ViewWindow* theWindow);
158   void selectionChanged();
159
160   void contextMenuRequested(QContextMenuEvent*);
161
162 public slots:
163   void onWindowMinimized(QMdiSubWindow*);
164   void onWindowActivated(QMdiSubWindow*);
165
166 private slots:
167   void onViewClosed(QMdiSubWindow*);
168   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
169   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
170   void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
171   //void onContextMenuRequested(QContextMenuEvent* theEvent);
172
173 private:
174   void addView(QMdiSubWindow* theView);
175
176   /*! Removes the View from internal Views list.*/
177   void removeView(QMdiSubWindow* theView);
178
179   void updateViewsDrawMode() const;
180
181 private:
182   XGUI_MainWindow* myMainWindow;
183
184   Handle(V3d_Viewer) myV3dViewer;
185   Handle(AIS_Trihedron) myTrihedron;
186   Handle(AIS_InteractiveContext) myAISContext;
187
188   XGUI::InteractionStyle myInteractionStyle;
189
190   bool myPreselectionEnabled;
191   bool mySelectionEnabled;
192   bool myMultiSelectionEnabled;
193   bool myIsRelative;
194
195   double myTrihedronSize;
196   
197   QList<QMdiSubWindow*> myViews;
198
199   QMdiSubWindow* myActiveView;
200
201   /// Points used for selection management
202   QPoint myStartPnt, myEndPnt, myCurPnt;
203
204   /// A counter of created windows
205   int myWndIdCount;
206
207   /// List of Viewer actions
208   QList<QAction*> myActions;
209 };
210
211 #endif