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>
21 class XGUI_MainWindow;
23 class XGUI_ViewWindow;
27 class AIS_ListOfInteractive;
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.
34 class XGUI_EXPORT XGUI_Viewer: public QObject
38 static QString backgroundData(QStringList&, QIntList&, QIntList&);
40 XGUI_Viewer(XGUI_MainWindow* theParent, bool DisplayTrihedron = true);
43 //! Creates a new view window
44 QMdiSubWindow* createView(V3d_TypeOfView theType = V3d_ORTHOGRAPHIC);
46 //! Return pointer on a main window - parent of the Viewer
47 XGUI_MainWindow* mainWindow() const
52 //! Returns OCCT object which manages 3d scene
53 Handle(V3d_Viewer) v3dViewer() const
58 //! Returns OCCT object which manages displaying and selection in 3d scene
59 Handle(AIS_InteractiveContext) AISContext() const
64 //! Returns an active view window or NULL
65 XGUI_ViewWindow* activeViewWindow() const;
67 /// Return objects selected in 3D viewer
68 /// \param theList - list to be filled with selected objects
69 void getSelectedObjects(AIS_ListOfInteractive& theList);
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);
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);
79 /// Returns true if selection in the viewer is enabled
80 bool isSelectionEnabled() const { return mySelectionEnabled; }
82 /// Enable or disable selectioon in the viewer
83 // \param toEnable - true or false (enable or disable selection)
84 void setSelectionEnabled(bool toEnable);
86 /// Returns true if multi-selection in the viewer is enabled
87 bool isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
89 /// Enable or disable selectioon in the viewer
90 // \param toEnable - true or false (enable or disable selection)
91 void setMultiSelectionEnabled(bool toEnable);
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); }
97 //! Trihedron 3d object shown in the viewer
98 Handle(AIS_Trihedron) trihedron() const
103 //! On/Off visibility of the trihedron object
104 void toggleTrihedron();
106 //! Returns true if trihedron is visible
107 bool isTrihedronVisible() const;
109 //! Returns true if trihedron is visible
110 void setTrihedronShown(bool on);
112 //! Returns trihedron size
113 double trihedronSize() const;
115 //! Sets trihedron size
116 void setTrihedronSize(const double sz, bool isRelative);
118 bool trihedronRelative() const
123 void updateTrihedron();
125 //! Compute trihedron size dependent on 3d scene size
126 bool computeTrihedronSize(double& theNewSize, double& theSize);
128 //! Add action to the viewer
129 void addAction(QAction* theAction) { myActions.append(theAction); }
131 void updateFromResources();
133 static void setHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
134 Qt::KeyboardModifiers theState, Qt::MouseButtons theButton);
135 static void getHotButton(XGUI::InteractionStyle theInteractionStyle, XGUI::HotOperation theOper,
136 Qt::KeyboardModifiers& theState, Qt::MouseButtons& theButton);
138 typedef QMap<XGUI::HotOperation, Qt::KeyboardModifiers> StatesMap;
139 typedef QMap<XGUI::HotOperation, Qt::MouseButtons> ButtonsMap;
141 typedef QMap<XGUI::InteractionStyle, StatesMap> InteractionStyle2StatesMap;
142 typedef QMap<XGUI::InteractionStyle, ButtonsMap> InteractionStyle2ButtonsMap;
144 static InteractionStyle2StatesMap myStateMap;
145 static InteractionStyle2ButtonsMap myButtonMap;
148 void lastViewClosed();
149 void tryCloseView(XGUI_ViewWindow* theWindow);
150 void deleteView(XGUI_ViewWindow* theWindow);
151 void viewCreated(XGUI_ViewWindow* theWindow);
152 void mousePress(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
153 void mouseRelease(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
154 void mouseDoubleClick(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
155 void mouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
156 void keyPress(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
157 void keyRelease(XGUI_ViewWindow* theWindow, QKeyEvent* theEvent);
158 void activated(XGUI_ViewWindow* theWindow);
159 void selectionChanged();
161 void contextMenuRequested(QContextMenuEvent*);
164 void onWindowMinimized(QMdiSubWindow*);
165 void onWindowActivated(QMdiSubWindow*);
168 void onViewClosed(QMdiSubWindow*);
169 void onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
170 void onMouseReleased(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
171 void onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent);
172 //void onContextMenuRequested(QContextMenuEvent* theEvent);
175 void addView(QMdiSubWindow* theView);
177 /*! Removes the View from internal Views list.*/
178 void removeView(QMdiSubWindow* theView);
180 void updateViewsDrawMode() const;
183 XGUI_MainWindow* myMainWindow;
185 Handle(V3d_Viewer) myV3dViewer;
186 Handle(AIS_Trihedron) myTrihedron;
187 Handle(AIS_InteractiveContext) myAISContext;
189 XGUI::InteractionStyle myInteractionStyle;
191 bool myPreselectionEnabled;
192 bool mySelectionEnabled;
193 bool myMultiSelectionEnabled;
196 double myTrihedronSize;
198 QList<QMdiSubWindow*> myViews;
200 QMdiSubWindow* myActiveView;
202 /// Points used for selection management
203 QPoint myStartPnt, myEndPnt, myCurPnt;
205 /// A counter of created windows
208 /// List of Viewer actions
209 QList<QAction*> myActions;