5 #include "XGUI_Constants.h"
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>
19 class XGUI_MainWindow;
21 class XGUI_ViewWindow;
25 class AIS_ListOfInteractive;
29 * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
30 * when each of view window is a one point of view on this scene.
32 class XGUI_EXPORT XGUI_Viewer: public QObject
36 static QString backgroundData(QStringList&, QIntList&, QIntList&);
38 XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
41 //! Creates a new view window
42 QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
44 //! Return pointer on a main window - parent of the Viewer
45 XGUI_MainWindow* mainWindow() const
50 //! Returns OCCT object which manages 3d scene
51 Handle(V3d_Viewer) v3dViewer() const
56 //! Returns OCCT object which manages displaying and selection in 3d scene
57 Handle(AIS_InteractiveContext) AISContext() const
62 //! Returns an active view window or NULL
63 XGUI_ViewWindow* activeViewWindow() const;
65 /// Return objects selected in 3D viewer
66 /// \param theList - list to be filled with selected objects
67 void getSelectedObjects(AIS_ListOfInteractive& theList);
69 /// Return shapes selected in 3D viewer
70 /// \param theList - list to be filled with selected shapes
71 void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
73 /// Selects objects in 3D viewer. Other selected objects are left as selected
74 /// \param theList - list objects to be selected
75 void setObjectsSelected(const AIS_ListOfInteractive& theList);
77 /// Returns true if selection in the viewer is enabled
78 bool isSelectionEnabled() const { return mySelectionEnabled; }
80 /// Enable or disable selectioon in the viewer
81 // \param toEnable - true or false (enable or disable selection)
82 void setSelectionEnabled(bool toEnable) { mySelectionEnabled = toEnable; }
84 /// Select the object in 3D viewer.
85 /// \param theIO - list objects to be selected
86 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
88 //! Trihedron 3d object shown in the viewer
89 Handle(AIS_Trihedron) trihedron() const
94 //! On/Off visibility of the trihedron object
95 void toggleTrihedron();
97 //! Returns true if trihedron is visible
98 bool isTrihedronVisible() const;
100 //! Returns true if trihedron is visible
101 void setTrihedronShown(bool on);
103 //! Returns trihedron size
104 double trihedronSize() const;
106 //! Sets trihedron size
107 void setTrihedronSize(const double sz, bool isRelative);
109 bool trihedronRelative() const
114 void updateTrihedron();
116 //! Compute trihedron size dependent on 3d scene size
117 bool computeTrihedronSize(double& theNewSize, double& theSize);
119 static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
120 Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
121 static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
122 Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
124 typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
125 typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
127 typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
128 typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
130 static InteractionStyle2StatesMap myStateMap;
131 static InteractionStyle2ButtonsMap myButtonMap;
134 void lastViewClosed();
135 void tryCloseView(XGUI_ViewWindow* theWindow);
136 void deleteView(XGUI_ViewWindow* theWindow);
137 void viewCreated(XGUI_ViewWindow* theWindow);
138 void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
139 void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
140 void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
141 void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
142 void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
143 void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
144 void activated(XGUI_ViewWindow* theWindow);
145 void selectionChanged();
148 void onWindowMinimized(QMdiSubWindow*);
149 void onWindowActivated(QMdiSubWindow*);
152 void onViewClosed(QMdiSubWindow*);
153 void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
154 void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
155 void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
158 void addView(QMdiSubWindow* theView);
160 /*! Removes the View from internal Views list.*/
161 void removeView(QMdiSubWindow* theView);
164 XGUI_MainWindow* myMainWindow;
166 Handle(V3d_Viewer) myV3dViewer;
167 Handle(AIS_Trihedron) myTrihedron;
168 Handle(AIS_InteractiveContext) myAISContext;
170 XGUI::InteractionStyle myInteractionStyle;
172 bool myPreselectionEnabled;
173 bool mySelectionEnabled;
174 bool myMultiSelectionEnabled;
177 double myTrihedronSize;
179 QList<QMdiSubWindow*> myViews;
181 QMdiSubWindow* myActiveView;
183 /// Points used for selection management
184 QPoint myStartPnt, myEndPnt, myCurPnt;