5 #include "XGUI_Constants.h"
13 #include <V3d_Viewer.hxx>
14 #include <AIS_InteractiveContext.hxx>
15 #include <AIS_Trihedron.hxx>
16 #include <NCollection_List.hxx>
17 #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 { return mySelectionEnabled; }
81 /// Enable or disable selectioon in the viewer
82 // \param toEnable - true or false (enable or disable selection)
83 void setSelectionEnabled(bool toEnable);
85 /// Returns true if multi-selection in the viewer is enabled
86 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
88 /// Enable or disable selectioon in the viewer
89 // \param toEnable - true or false (enable or disable selection)
90 void setMultiSelectionEnabled(bool toEnable);
92 /// Select the object in 3D viewer.
93 /// \param theIO - list objects to be selected
94 void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
96 //! Trihedron 3d object shown in the viewer
97 Handle(AIS_Trihedron) trihedron() const
102 //! On/Off visibility of the trihedron object
103 void toggleTrihedron();
105 //! Returns true if trihedron is visible
106 bool isTrihedronVisible() const;
108 //! Returns true if trihedron is visible
109 void setTrihedronShown(bool on);
111 //! Returns trihedron size
112 double trihedronSize() const;
114 //! Sets trihedron size
115 void setTrihedronSize(const double sz, bool isRelative);
117 bool trihedronRelative() const
122 void updateTrihedron();
124 //! Compute trihedron size dependent on 3d scene size
125 bool computeTrihedronSize(double& theNewSize, double& theSize);
127 //! Add action to the viewer
128 void addAction(QAction* theAction) { myActions.append(theAction); }
131 static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
132 Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
133 static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
134 Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
136 typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
137 typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
139 typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
140 typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
142 static InteractionStyle2StatesMap myStateMap;
143 static InteractionStyle2ButtonsMap myButtonMap;
146 void lastViewClosed();
147 void tryCloseView(XGUI_ViewWindow* theWindow);
148 void deleteView(XGUI_ViewWindow* theWindow);
149 void viewCreated(XGUI_ViewWindow* theWindow);
150 void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
151 void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
152 void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
153 void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
154 void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
155 void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
156 void activated(XGUI_ViewWindow* theWindow);
157 void selectionChanged();
160 void onWindowMinimized(QMdiSubWindow*);
161 void onWindowActivated(QMdiSubWindow*);
164 void onViewClosed(QMdiSubWindow*);
165 void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
166 void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
167 void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
168 void onContextMenuRequested(QContextMenuEvent* theEvent);
171 void addView(QMdiSubWindow* theView);
173 /*! Removes the View from internal Views list.*/
174 void removeView(QMdiSubWindow* theView);
176 void updateViewsDrawMode() const;
179 XGUI_MainWindow* myMainWindow;
181 Handle(V3d_Viewer) myV3dViewer;
182 Handle(AIS_Trihedron) myTrihedron;
183 Handle(AIS_InteractiveContext) myAISContext;
185 XGUI::InteractionStyle myInteractionStyle;
187 bool myPreselectionEnabled;
188 bool mySelectionEnabled;
189 bool myMultiSelectionEnabled;
192 double myTrihedronSize;
194 QList<QMdiSubWindow*> myViews;
196 QMdiSubWindow* myActiveView;
198 /// Points used for selection management
199 QPoint myStartPnt, myEndPnt, myCurPnt;
201 /// A counter of created windows
204 /// List of Viewer actions
205 QList<QAction*> myActions;