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 <GeomAPI_ICustomPrs.h>
25 #include <SelectMgr_AndFilter.hxx>
32 class ModelAPI_Feature;
35 /**\class XGUI_Displayer
37 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
39 class XGUI_EXPORT XGUI_Displayer: public QObject
43 /// \enum DisplayMode display mode
45 /// Mode is not defined
47 /// Wireframe display mode
49 /// Shading display mode
54 /// \param theWorkshop a workshop instance
55 XGUI_Displayer(XGUI_Workshop* theWorkshop);
58 virtual ~XGUI_Displayer();
60 /// Returns the feature visibility state.
61 /// \param theObject an object instance
62 bool isVisible(ObjectPtr theObject) const;
64 /// Display the feature. Obtain the visualized object from the feature.
65 /// \param theObject an object to display
66 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
67 /// \return true if the object visibility state is changed
68 bool display(ObjectPtr theObject, bool theUpdateViewer = true);
70 /// Display the given AIS object. This object is not added to the displayer internal map of objects
71 /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in order
72 /// to perform the display with correct flags.
73 /// \param theAIS AIOS object to display
74 /// \param toActivateInSelectionModes boolean value whether the presentation should be
75 /// activated in the current selection modes
76 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
77 /// \return true if the object visibility state is changed
78 bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
79 bool theUpdateViewer = true);
81 /// Redisplay the shape if it was displayed
82 /// \param theObject an object instance
83 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
84 /// \return true if the object visibility state is changed
85 bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
87 /// Sends and flushes a signal to redisplay all visualized objects.
88 void redisplayObjects();
90 /// Add presentations to current selection. It unhighlight and deselect the current selection.
91 /// The shape and result components are processed in the values. If the presentation shape is not
92 /// empty, select it, otherwise select the result.
93 /// \param theValues a list of presentation to be selected
94 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
95 void setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
97 /// Unselect all objects
100 /// Erase the feature and a shape.
101 /// \param theObject an object instance
102 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
103 /// \return true if the object visibility state is changed
104 bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
106 /// Erase the given AIS object displayed by corresponded display method
107 /// \param theAIS instance of AIS object
108 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
109 /// \return true if the object visibility state is changed
110 bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
112 /// Erase all presentations
113 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
114 /// \return true if the object visibility state is changed
115 bool eraseAll(const bool theUpdateViewer = true);
117 /// Deactivates selection of sub-shapes
118 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
119 void closeLocalContexts(const bool theUpdateViewer = true);
121 // Remove default selection filters of the module from the current viewer
122 void deactivateSelectionFilters();
124 /// \brief Add selection filter
125 /// \param theFilter a filter instance
126 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
128 /// \brief Remove selection filter
129 /// \param theFilter a filter instance
130 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
132 /// Returns true if the selection filter is set to the viewer
133 /// \param theFilter a selection filter
134 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
136 /// Remove all selection filters
137 void removeFilters();
139 /// Sets a flag to the displayer whether the internal viewer can be updated by
140 /// the updateViewer method call. If it is not enabled, this method do nothing
141 /// \param isEnabled a boolean value
142 bool enableUpdateViewer(const bool isEnabled);
144 /// Updates the viewer
145 void updateViewer() const;
147 /// Activate interactive context
150 void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
151 const bool theUpdateViewer) const;
153 /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
154 void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
156 /// Searches the interactive object by feature
157 /// \param theObject the object or presentable feature
158 /// \return theIO an interactive object
159 AISObjectPtr getAISObject(ObjectPtr theObject) const;
161 /// Searches the feature by interactive object
162 /// \param theIO an interactive object
163 /// \return feature the feature or NULL if it not visualized
164 ObjectPtr getObject(const AISObjectPtr& theIO) const;
166 /// Searches the feature by interactive object
167 /// \param theIO an interactive object
168 /// \return corresponded object or NULL if it not found
169 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
171 /// Deactivates the given objects (not allow selection)
172 /// \param theObjList - list of objects which has to be deactivated.
173 /// \param theUpdateViewer update viewer flag
174 void deactivateObjects(const QObjectPtrList& theObjList,
175 const bool theUpdateViewer = true);
177 /// Returns the modes of activation
178 /// \param theObject the feature or NULL if it not visualized
179 /// \param theModes - modes on which it is activated (can be empty)
180 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
182 /// Returns true if the given object can be selected
183 /// \param theObject object to check
184 bool isActive(ObjectPtr theObject) const;
186 /// Activates in local context displayed outside of the context.
187 /// \param theModes - modes on which it has to be activated (can be empty)
188 /// \param theObjList - list of objects which has to be activated.
189 void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
190 const bool theUpdateViewer = true);
192 /// Sets display mode for the given object if this object is displayed
193 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
195 /// Returns current display mode for the given object.
196 /// If object is not dis played then returns NoMode.
197 /// \param theObject object to check
198 DisplayMode displayMode(ObjectPtr theObject) const;
200 /// Displays only objects listed in the list
201 /// \param theList list of objects
202 void showOnly(const QObjectPtrList& theList);
204 /// Returns number of displayed objects
205 int objectsCount() const { return myResult2AISObjectMap.size(); }
207 /// Returns list of displayed objects
208 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
210 /// Returns list of displayed objects
211 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
213 /// Returns true if the given object can be shown in shaded mode
214 /// \param theObject object to check
215 bool canBeShaded(ObjectPtr theObject) const;
217 /// Set color on presentation of an object if it is displayed
218 /// \param theObject an object
219 /// \param theColor a color which has to be set
220 /// \param theUpdateViewer update viewer flag
221 /// \return previously defined color on the object
222 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
225 /// Signal on object display
226 /// \param theObject a data object
227 /// \param theAIS a presentation object
228 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
230 /// Signal on before object erase
231 /// \param theObject a data object
232 /// \param theAIS a presentation object
233 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
236 /// Returns currently installed AIS_InteractiveContext
237 Handle(AIS_InteractiveContext) AISContext() const;
239 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
240 /// The context should have only this filter inside. Other filters should be add to the filter
241 Handle(SelectMgr_AndFilter) GetFilter();
243 /// Display the feature and a shape. This shape would be associated to the given feature
244 /// \param theObject an object instance
245 /// \param theAIS AIS presentation
246 /// \param isShading flag to show in shading mode
247 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
248 /// \return true if the object visibility state is changed
249 bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
250 bool theUpdateViewer = true);
253 /// Activates the interactive object in the local context.
254 /// \param theIO an interactive object
255 /// \param theModes - modes on which it has to be activated (can be empty)
256 /// \return a flag is object activated or not
257 bool activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
258 const bool theUpdateViewer) const;
260 /// Deactivates the given object (not allow selection)
261 /// \param theObject object to deactivate
262 void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
264 /// Find a trihedron in a list of displayed presentations and deactivate it.
265 void deactivateTrihedron() const;
267 /// Opens local context. Does nothing if it is already opened.
268 void openLocalContext();
270 /// Update the object presentable properties such as color, lines width and other
271 /// If the object is result with the color attribute value set, it is used,
272 /// otherwise the customize is applyed to the object's feature if it is a custom prs
273 /// \param theObject an object instance
274 /// \return the true state if there is changes and the presentation is customized
275 bool customizeObject(ObjectPtr theObject);
277 /// Append the objects in the internal map. Checks whether the map already contains the object
278 /// \param theObject an object to display
279 /// \param theAIS AIOS object to display
280 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
282 /// Returns an information about alredy displayed objects
283 /// \return a string representation
284 std::string getResult2AISObjectMapInfo() const;
287 /// Reference to workshop
288 XGUI_Workshop* myWorkshop;
290 /// A container for selection filters
291 Handle(SelectMgr_AndFilter) myAndFilter;
293 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
294 GeomCustomPrsPtr myCustomPrs;
296 /// Definition of a type of map which defines correspondance between objects and presentations
297 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
299 /// A map of displayed objects
300 ResultToAISMap myResult2AISObjectMap;
302 /// Selection modes installed for external objects in local context
303 QIntList myActiveSelectionModes;
305 /// the enable update viewer flag
306 bool myEnableUpdateViewer;