1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Displayer.h
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef XGUI_Displayer_H
8 #define XGUI_Displayer_H
12 #include <GeomAPI_AISObject.h>
13 #include <TopoDS_Shape.hxx>
14 #include <AIS_InteractiveObject.hxx>
15 #include <AIS_InteractiveContext.hxx>
16 #include <NCollection_List.hxx>
18 #include <ModelAPI_Result.h>
20 #include <ModuleBase_Definitions.h>
21 #include <ModuleBase_ViewerPrs.h>
23 #include <SelectMgr_AndFilter.hxx>
28 class ModelAPI_Feature;
31 /**\class XGUI_Displayer
33 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
35 class XGUI_EXPORT XGUI_Displayer
38 /// Enumeration of possible display mode
40 NoMode = -1, /// Mode is not defined
41 Wireframe, /// Wireframe display mode
42 Shading /// Shading display mode
46 /// \param theWorkshop a workshop instance
47 XGUI_Displayer(XGUI_Workshop* theWorkshop);
50 virtual ~XGUI_Displayer();
52 /// Returns the feature visibility state.
53 /// \param theObject an object instance
54 bool isVisible(ObjectPtr theObject) const;
56 /// Display the feature. Obtain the visualized object from the feature.
57 /// \param theObject an object to display
58 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
59 /// Returns true if the Feature succesfully displayed
60 void display(ObjectPtr theObject, bool isUpdateViewer = true);
62 /// Display the given AIS object. To hide this object use corresponde erase method
63 /// \param theAIS AIOS object to display
64 /// \param isUpdate the parameter whether the viewer should be update immediatelly
65 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
68 * Add presentations which corresponds to the given features to current selection
69 * \param theFeatures a list of features to be selected
70 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
72 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
75 /// Unselect all objects
78 /// Erase the feature and a shape.
79 /// \param theObject an object instance
80 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
81 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
83 /// Erase the given AIS object displayed by corresponded display method
84 /// \param theAIS instance of AIS object
85 /// \param isUpdate the parameter whether the viewer should be update immediatelly
86 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
88 /// Erase all presentations
89 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
90 void eraseAll(const bool isUpdateViewer = true);
92 /// Deactivates selection of sub-shapes
93 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
94 void closeLocalContexts(const bool isUpdateViewer = true);
96 /// \brief Add selection filter
97 /// \param theFilter a filter instance
98 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
100 /// \brief Remove selection filter
101 /// \param theFilter a filter instance
102 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
104 /// Remove all selection filters
105 void removeFilters();
108 * Sets a flag to the displayer whether the internal viewer can be updated by
109 * the updateViewer method call. If it is not enabled, this method do nothing
110 * \param isEnabled a boolean value
112 bool enableUpdateViewer(const bool isEnabled);
114 /// Updates the viewer
117 /// Searches the interactive object by feature
118 /// \param theObject the object or presentable feature
119 /// \return theIO an interactive object
120 AISObjectPtr getAISObject(ObjectPtr theObject) const;
122 /// Searches the feature by interactive object
123 /// \param theIO an interactive object
124 /// \return feature the feature or NULL if it not visualized
125 ObjectPtr getObject(const AISObjectPtr& theIO) const;
127 /// Searches the feature by interactive object
128 /// \param theIO an interactive object
129 /// \return corresponded object or NULL if it not found
130 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
132 /// Deactivates the given object (not allow selection)
133 /// \param theObject object to deactivate
134 void deactivate(ObjectPtr theObject);
136 /// Activates the given object (it can be selected)
137 /// \param theObject object to activate
138 /// \param theModes - modes on which it has to be activated (can be empty)
139 void activate(ObjectPtr theObject, const QIntList& theModes);
141 /// Returns the modes of activation
142 /// \param theObject the feature or NULL if it not visualized
143 /// \param theModes - modes on which it is activated (can be empty)
144 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
146 /// Activates the given object with default modes
147 /// \param theObject object to activate
148 void activate(ObjectPtr theObject);
150 /// Returns true if the given object can be selected
151 /// \param theObject object to check
152 bool isActive(ObjectPtr theObject) const;
154 /// Activates in local context displayed outside of the context.
155 /// \param theModes - modes on which it has to be activated (can be empty)
156 void activateObjects(const QIntList& theModes);
158 /// Activates in local context displayed outside of the context.
159 void deactivateObjects();
161 /// Sets display mode for the given object if this object is displayed
162 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
164 /// Returns current display mode for the given object.
165 /// If object is not dis played then returns NoMode.
166 /// \param theObject object to check
167 DisplayMode displayMode(ObjectPtr theObject) const;
169 /// Displays only objects listed in the list
170 /// \param theList list of objects
171 void showOnly(const QObjectPtrList& theList);
173 /// Returns number of displayed objects
174 int objectsCount() const { return myResult2AISObjectMap.size(); }
176 /// Returns list of displayed objects
177 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
179 /// Returns true if the given object can be shown in shaded mode
180 /// \param theObject object to check
181 bool canBeShaded(ObjectPtr theObject) const;
184 /// Returns currently installed AIS_InteractiveContext
185 Handle(AIS_InteractiveContext) AISContext() const;
187 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
188 /// The context should have only this filter inside. Other filters should be add to the filter
189 Handle(SelectMgr_AndFilter) GetFilter();
191 /// Display the feature and a shape. This shape would be associated to the given feature
192 /// \param theObject an object instance
193 /// \param theAIS AIS presentation
194 /// \param isShading flag to show in shading mode
195 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
196 /// \return true if the object is succesfully displayed
197 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
198 bool isUpdateViewer = true);
200 /** Redisplay the shape if it was displayed
201 * \param theObject an object instance
202 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
204 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
206 /// Opens local context. Does nothing if it is already opened.
207 void openLocalContext();
210 /// Reference to workshop
211 XGUI_Workshop* myWorkshop;
213 /// A container for selection filters
214 Handle(SelectMgr_AndFilter) myAndFilter;
216 /// Definition of a type of map which defines correspondance between objects and presentations
217 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
219 /// A map of displayed objects
220 ResultToAISMap myResult2AISObjectMap;
222 /// Selection modes installed for external objects in local context
223 QIntList myActiveSelectionModes;
225 /// the enable update viewer flag
226 bool myEnableUpdateViewer;