]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Viewer.h
Salome HOME
Provided connection of XGUI Displayer to SALOME OCC Viewer
[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   /// Return objects selected in 3D viewer
61   /// \param theList - list to be filled with selected objects
62   void  getSelectedObjects(AIS_ListOfInteractive& theList);
63
64   /// Return shapes selected in 3D viewer
65   /// \param theList - list to be filled with selected shapes
66   void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
67
68   /// Selects objects in 3D viewer. Other selected objects are left as selected
69   /// \param theList - list objects to be selected
70   void  setObjectsSelected(const AIS_ListOfInteractive& theList);
71
72   /// Select the object in 3D viewer.
73   /// \param theIO - list objects to be selected
74   void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
75
76   //! Trihedron 3d object shown in the viewer
77   Handle(AIS_Trihedron) trihedron() const
78   {
79     return myTrihedron;
80   }
81
82   //! On/Off visibility of the trihedron object
83   void toggleTrihedron();
84
85   //! Returns true if trihedron is visible
86   bool isTrihedronVisible() const;
87
88   //! Returns true if trihedron is visible
89   void setTrihedronShown(bool on);
90
91   //! Returns trihedron size
92   double trihedronSize() const;
93
94   //! Sets trihedron size
95   void setTrihedronSize(const double sz, bool isRelative);
96
97   bool trihedronRelative() const
98   {
99     return myIsRelative;
100   }
101   //! Update trihedron
102   void updateTrihedron();
103
104   //! Compute trihedron size dependent on 3d scene size
105   bool computeTrihedronSize(double& theNewSize, double& theSize);
106
107   static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
108                            Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
109   static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
110                            Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
111
112   //! Sets the view projection
113   /// \param theX the X projection value
114   /// \param theY the Y projection value
115   /// \param theZ the Z projection value
116   void setViewProjection(double theX, double theY, double theZ);
117
118   typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
119   typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
120
121   typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
122   typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
123
124   static InteractionStyle2StatesMap myStateMap;
125   static InteractionStyle2ButtonsMap myButtonMap;
126
127 signals:
128   void lastViewClosed();
129   void tryCloseView(XGUI_ViewWindow* theWindow);
130   void deleteView(XGUI_ViewWindow* theWindow);
131   void viewCreated(XGUI_ViewWindow* theWindow);
132   void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
133   void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
134   void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
135   void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
136   void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
137   void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
138   void activated(XGUI_ViewWindow* theWindow);
139   void selectionChanged();
140
141 public slots:
142   void onWindowMinimized(QMdiSubWindow*);
143   void onWindowActivated(QMdiSubWindow*);
144
145 private slots:
146   void onViewClosed(QMdiSubWindow*);
147   void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
148   void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
149
150 private:
151   void addView(QMdiSubWindow* theView);
152
153   /*! Removes the View from internal Views list.*/
154   void removeView(QMdiSubWindow* theView);
155
156 private:
157   XGUI_MainWindow* myMainWindow;
158
159   Handle(V3d_Viewer) myV3dViewer;
160   Handle(AIS_Trihedron) myTrihedron;
161   Handle(AIS_InteractiveContext) myAISContext;
162
163   XGUI::InteractionStyle myInteractionStyle;
164
165   bool myPreselectionEnabled;
166   bool mySelectionEnabled;
167   bool myMultiSelectionEnabled;
168   bool myIsRelative;
169
170   double myTrihedronSize;
171   
172   QList<QMdiSubWindow*> myViews;
173
174   QMdiSubWindow* myActiveView;
175 };
176
177 #endif