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_Map.hxx>
17 #include <NCollection_DataMap.hxx>
19 #include <ModelAPI_Result.h>
21 #include <ModuleBase_Definitions.h>
23 #include <GeomAPI_ICustomPrs.h>
25 #include <SelectMgr_AndFilter.hxx>
32 class ModuleBase_ViewerPrs;
33 class ModelAPI_Feature;
37 class VInspectorAPI_CallBack;
40 /**\class XGUI_Displayer
42 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
44 class XGUI_EXPORT XGUI_Displayer: public QObject
48 /// \enum DisplayMode display mode
50 /// Mode is not defined
52 /// Wireframe display mode
54 /// Shading display mode
59 /// \param theWorkshop a workshop instance
60 XGUI_Displayer(XGUI_Workshop* theWorkshop);
63 virtual ~XGUI_Displayer();
65 /// Returns the feature visibility state.
66 /// \param theObject an object instance
67 bool isVisible(ObjectPtr theObject) const;
69 /// Display the feature. Obtain the visualized object from the feature.
70 /// \param theObject an object to display
71 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
72 /// \return true if the object visibility state is changed
73 bool display(ObjectPtr theObject, bool theUpdateViewer = true);
75 /// Display the given AIS object.
76 /// This object is not added to the displayer internal map of objects
77 /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in
78 /// order to perform the display with correct flags.
79 /// \param theAIS AIOS object to display
80 /// \param toActivateInSelectionModes boolean value whether the presentation should be
81 /// activated in the current selection modes
82 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
83 /// \return true if the object visibility state is changed
84 bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
85 bool theUpdateViewer = true);
87 /// Redisplay the shape if it was displayed
88 /// \param theObject an object instance
89 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
90 /// \return true if the object visibility state is changed
91 bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
93 /// Sends and flushes a signal to redisplay all visualized objects.
94 void redisplayObjects();
96 /// Add presentations to current selection. It unhighlight and deselect the current selection.
97 /// The shape and result components are processed in the values. If the presentation shape is not
98 /// empty, select it, otherwise select the result.
99 /// \param theValues a list of presentation to be selected
100 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
101 void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
102 bool theUpdateViewer = true);
104 /// Unselect all objects
105 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
106 /// \param theUpdateViewer the parameter to update viewer
107 void clearSelected(const bool theUpdateViewer = true);
109 /// Erase the feature and a shape.
110 /// \param theObject an object instance
111 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112 /// \return true if the object visibility state is changed
113 bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
115 /// Erase the given AIS object displayed by corresponded display method
116 /// \param theAIS instance of AIS object
117 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
118 /// \return true if the object visibility state is changed
119 bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
121 /// Erase all presentations
122 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
123 /// \return true if the object visibility state is changed
124 bool eraseAll(const bool theUpdateViewer = true);
126 /// Deactivates selection of sub-shapes
127 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
128 //void closeLocalContexts(const bool theUpdateViewer = true);
130 /// Remove default selection filters of the module from the current viewer
131 void deactivateSelectionFilters();
133 /// \brief Add selection filter
134 /// \param theFilter a filter instance
135 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
137 /// \brief Remove selection filter
138 /// \param theFilter a filter instance
139 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
141 /// Returns true if the selection filter is set to the viewer
142 /// \param theFilter a selection filter
143 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
145 /// Remove all selection filters
146 void removeFilters();
148 /// Sets a flag to the displayer whether the internal viewer can be updated by
149 /// the updateViewer method call. If it is not enabled, this method do nothing.
150 /// This state maintain recurse, if the update is blocked twice or three times, the
151 /// viewer will not be updated until it is unblocked necessary times
152 /// (twice or three in the example).
153 /// \param isEnabled a boolean value
154 bool enableUpdateViewer(const bool isEnabled);
156 /// Returns true if the viewer update is not blocked
157 bool isUpdateEnabled() const;
159 /// Updates the viewer
160 void updateViewer() const;
162 /// Activate interactive context
163 /// \param theIO an interactive object
164 /// \param theMode activation mode
165 /// \param theUpdateViewer update viewer flag
166 void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
167 const bool theUpdateViewer) const;
169 /// Activate interactive context. It is necessary to call ClearOutdatedSelection
170 /// after deactivation
171 /// \param theIO an interactive object
172 /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
173 void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
175 /// Searches the interactive object by feature
176 /// \param theObject the object or presentable feature
177 /// \return theIO an interactive object
178 AISObjectPtr getAISObject(ObjectPtr theObject) const;
180 /// Searches the feature by interactive object
181 /// \param theIO an interactive object
182 /// \return feature the feature or NULL if it not visualized
183 ObjectPtr getObject(const AISObjectPtr& theIO) const;
185 /// Searches the feature by interactive object
186 /// \param theIO an interactive object
187 /// \return corresponded object or NULL if it not found
188 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
190 /// Deactivates the given objects (not allow selection)
191 /// \param theObjList - list of objects which has to be deactivated.
192 /// \param theUpdateViewer update viewer flag
193 void deactivateObjects(const QObjectPtrList& theObjList,
194 const bool theUpdateViewer = true);
196 /// Returns the modes of activation
197 /// \param theObject the feature or NULL if it not visualized
198 /// \param theModes - modes on which it is activated (can be empty)
199 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
201 /// Returns true if the given object can be selected
202 /// \param theObject object to check
203 bool isActive(ObjectPtr theObject) const;
205 /// Activates in local context displayed outside of the context.
206 /// \param theModes - modes on which it has to be activated (can be empty)
207 /// \param theObjList - list of objects which has to be activated.
208 /// \param theUpdateViewer an update viewer flag
209 void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
210 const bool theUpdateViewer = true);
212 /// Sets display mode for the given object if this object is displayed
213 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
215 /// Returns current display mode for the given object.
216 /// If object is not dis played then returns NoMode.
217 /// \param theObject object to check
218 DisplayMode displayMode(ObjectPtr theObject) const;
220 /// Displays only objects listed in the list
221 /// \param theList list of objects
222 void showOnly(const QObjectPtrList& theList);
224 /// Returns number of displayed objects
225 int objectsCount() const { return myResult2AISObjectMap.size(); }
227 /// Returns list of displayed objects
228 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
230 /// Returns list of displayed objects
231 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
233 /// Returns true if the given object can be shown in shaded mode
234 /// \param theObject object to check
235 bool canBeShaded(ObjectPtr theObject) const;
237 /// Set color on presentation of an object if it is displayed
238 /// \param theObject an object
239 /// \param theColor a color which has to be set
240 /// \param theUpdateViewer update viewer flag
241 /// \return previously defined color on the object
242 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
244 /// Returns Trihedron object if it is displayed
245 Handle(AIS_InteractiveObject) getTrihedron() const;
247 /// Set trihedron active (used in selection) or non active
248 void activateTrihedron(bool theIsActive);
250 /// Displays/erases thrihedron in current modes. It will be activated or deactivated
251 /// depending on the trihedron visible state and displayer active trihedron state
252 void displayTrihedron(bool theToDisplay) const;
254 /// Returns true if the trihedron should be activated in current selection modes
255 bool isTrihedronActive() const { return myIsTrihedronActive; }
257 /// Returns list of currently active selection modes
258 /// Selection modes will be returned according to TopAbs_ShapeEnum
259 QIntList activeSelectionModes() const;
262 void setCallBack(const Handle(VInspectorAPI_CallBack)& theCallBack)
263 { myVCallBack = theCallBack; }
264 Handle(VInspectorAPI_CallBack) getCallBack() const { return myVCallBack; }
266 /// Converts shape type (TopAbs_ShapeEnum) to selection mode
267 /// \param theShapeType a shape type from TopAbs_ShapeEnum
268 static int getSelectionMode(int theShapeType);
270 /// Return true if the object is visible. If the object is feature, it returns true
271 /// if all results of the feature are shown
272 /// \param theDisplayer a displayer
273 /// \param theObject an object
274 /// \return a boolean value
275 static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
278 /// Signal on object display
279 /// \param theObject a data object
280 /// \param theAIS a presentation object
281 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
283 /// Signal on before object erase
284 /// \param theObject a data object
285 /// \param theAIS a presentation object
286 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
289 /// Returns currently installed AIS_InteractiveContext
290 Handle(AIS_InteractiveContext) AISContext() const;
292 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
293 /// The context should have only this filter inside. Other filters should be add to the filter
294 Handle(SelectMgr_AndFilter) GetFilter();
296 /// Display the feature and a shape. This shape would be associated to the given feature
297 /// \param theObject an object instance
298 /// \param theAIS AIS presentation
299 /// \param isShading flag to show in shading mode
300 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
301 /// \return true if the object visibility state is changed
302 bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
303 bool theUpdateViewer = true);
306 /// Activates the interactive object in the local context.
307 /// \param theIO an interactive object
308 /// \param theModes - modes on which it has to be activated (can be empty)
309 /// \return a flag is object activated or not
310 bool activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
311 const bool theUpdateViewer) const;
313 /// Deactivates the given object (not allow selection)
314 /// \param theObject object to deactivate
315 void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
317 /// Find a trihedron in a list of displayed presentations and deactivate it.
318 /// \param theUpdateViewer an update viewer flag
319 void deactivateTrihedron(const bool theUpdateViewer) const;
321 /// Update the object presentable properties such as color, lines width and other
322 /// If the object is result with the color attribute value set, it is used,
323 /// otherwise the customize is applyed to the object's feature if it is a custom prs
324 /// \param theObject an object instance
325 /// \return the true state if there is changes and the presentation is customized
326 bool customizeObject(ObjectPtr theObject);
328 /// Append the objects in the internal map. Checks whether the map already contains the object
329 /// \param theObject an object to display
330 /// \param theAIS AIOS object to display
331 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
334 /// Returns an information about alredy displayed objects
335 /// \return a string representation
336 std::string getResult2AISObjectMapInfo() const;
339 /// Returns container of visible presentations for the object. For a feature object,
340 /// the feature results are processed also. The presentations map is not cleared inside.
341 /// \param theObject a feature or result
342 /// \param thePresentations result map of presentations
343 void getPresentations(const ObjectPtr& theObject,
344 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations);
346 /// Sets the shapes selected in the context. It contains logic of the similar method
347 /// in OCCT but improved for performance. The modification is to iterates by a list
348 /// of owners in the context only once.
349 /// \param theContext a viewer context. It has opened local context
350 /// \param theShapesToBeSelected a map of shapes. Owner's shape is searched in the map and the
351 /// owner is selected if it is found there.
352 /// Only first owner is processed(according to OCCT logic)
353 static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
354 const NCollection_DataMap<TopoDS_Shape,
355 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
358 /// Reference to workshop
359 XGUI_Workshop* myWorkshop;
361 Handle(VInspectorAPI_CallBack) myVCallBack;
363 /// A container for selection filters
364 Handle(SelectMgr_AndFilter) myAndFilter;
366 /// A default custom presentation, which is used if the displayed feature is not
367 /// a custom presentation
368 GeomCustomPrsPtr myCustomPrs;
370 /// Definition of a type of map which defines correspondance between objects and presentations
371 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
373 /// A map of displayed objects
374 ResultToAISMap myResult2AISObjectMap;
376 /// Selection modes installed for external objects in local context
377 QIntList myActiveSelectionModes;
379 /// Number of blocking of the viewer update. The viewer is updated only if it equals zero
380 int myViewerBlockedRecursiveCount;
382 /// Flag: first asking of AIS context: trihedron activation
383 bool myIsFirstAISContextUse;
385 /// Flag: use trihedgon for selection or not
386 bool myIsTrihedronActive;
388 /// A flag that update was requested but not done
389 mutable bool myNeedUpdate;