5 #include "XGUI_Constants.h"
6 #include <ModuleBase_Definitions.h>
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>
20 class XGUI_MainWindow;
22 class XGUI_ViewWindow;
26 class AIS_ListOfInteractive;
30 * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
31 * when each of view window is a one point of view on this scene.
33 class XGUI_EXPORT XGUI_Viewer : public QObject
37 static QString backgroundData(QStringList&, QIntList&, QIntList&);
39 XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
42 //! Creates a new view window
43 QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
45 //! Return pointer on a main window - parent of the Viewer
46 XGUI_MainWindow* mainWindow() const
51 //! Returns OCCT object which manages 3d scene
52 Handle(V3d_Viewer) v3dViewer() const
57 //! Returns OCCT object which manages displaying and selection in 3d scene
58 Handle(AIS_InteractiveContext) AISContext() const
63 //! Returns an active view window or NULL
64 XGUI_ViewWindow* activeViewWindow() const;
66 /// Return objects selected in 3D viewer
67 /// \param theList - list to be filled with selected objects
68 void getSelectedObjects(AIS_ListOfInteractive& theList);
70 /// Return shapes selected in 3D viewer
71 /// \param theList - list to be filled with selected shapes
72 void getSelectedShapes(NCollection_List<TopoDS_Shape>& theList);
74 /// Selects objects in 3D viewer. Other selected objects are left as selected
75 /// \param theList - list objects to be selected
76 void setObjectsSelected(const AIS_ListOfInteractive& theList);
78 /// Returns true if selection in the viewer is enabled
79 bool isSelectionEnabled() const
81 return mySelectionEnabled;
84 /// Enable or disable selectioon in the viewer
85 // \param toEnable - true or false (enable or disable selection)
86 void setSelectionEnabled(bool toEnable);
88 /// Returns true if multi-selection in the viewer is enabled
89 bool isMultiSelectionEnabled() const
91 return myMultiSelectionEnabled;
94 /// Enable or disable selectioon in the viewer
95 // \param toEnable - true or false (enable or disable selection)
96 void setMultiSelectionEnabled(bool toEnable);
98 /// Select the object in 3D viewer.
99 /// \param theIO - list objects to be selected
100 void setSelected(const Handle(AIS_InteractiveObject)& theIO)
102 myAISContext->SetSelected(theIO);
105 //! Trihedron 3d object shown in the viewer
106 Handle(AIS_Trihedron) trihedron() const
111 //! On/Off visibility of the trihedron object
112 void toggleTrihedron();
114 //! Returns true if trihedron is visible
115 bool isTrihedronVisible() const;
117 //! Returns true if trihedron is visible
118 void setTrihedronShown(bool on);
120 //! Returns trihedron size
121 double trihedronSize() const;
123 //! Sets trihedron size
124 void setTrihedronSize(const double sz, bool isRelative);
126 bool trihedronRelative() const
131 void updateTrihedron();
133 //! Compute trihedron size dependent on 3d scene size
134 bool computeTrihedronSize(double& theNewSize, double& theSize);
136 //! Add action to the viewer
137 void addAction(QAction* theAction)
139 myActions.append(theAction);
142 void updateFromResources();
144 static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
145 Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
146 static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
147 Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
149 typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
150 typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
152 typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
153 typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
155 static InteractionStyle2StatesMap myStateMap;
156 static InteractionStyle2ButtonsMap myButtonMap;
159 void lastViewClosed();
160 void tryCloseView(XGUI_ViewWindow* theWindow);
161 void deleteView(XGUI_ViewWindow* theWindow);
162 void viewCreated(XGUI_ViewWindow* theWindow);
163 void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
164 void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
165 void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
166 void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
167 void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
168 void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
169 void activated(XGUI_ViewWindow* theWindow);
170 void selectionChanged();
172 void contextMenuRequested(QContextMenuEvent*);
175 void onWindowMinimized(QMdiSubWindow*);
176 void onWindowActivated(QMdiSubWindow*);
179 void onViewClosed(QMdiSubWindow*);
180 void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
181 void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
182 void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
183 //void onContextMenuRequested(QContextMenuEvent* theEvent);
186 void addView(QMdiSubWindow* theView);
188 /*! Removes the View from internal Views list.*/
189 void removeView(QMdiSubWindow* theView);
191 void updateViewsDrawMode() const;
194 XGUI_MainWindow* myMainWindow;
196 Handle(V3d_Viewer) myV3dViewer;Handle(AIS_Trihedron) myTrihedron;Handle(AIS_InteractiveContext) myAISContext;
198 XGUI::InteractionStyle myInteractionStyle;
200 bool myPreselectionEnabled;
201 bool mySelectionEnabled;
202 bool myMultiSelectionEnabled;
205 double myTrihedronSize;
207 QList<QMdiSubWindow*> myViews;
209 QMdiSubWindow* myActiveView;
211 /// Points used for selection management
212 QPoint myStartPnt, myEndPnt, myCurPnt;
214 /// A counter of created windows
217 /// List of Viewer actions
218 QList<QAction*> myActions;