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 /// Returns true if the Feature succesfully displayed
68 void 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 void displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
78 bool theUpdateViewer = true);
80 /** Redisplay the shape if it was displayed
81 * \param theObject an object instance
82 * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
84 void redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
87 * Sends and flushes a signal to redisplay all visualized objects.
89 void redisplayObjects();
92 * Add presentations to current selection. It unhighlight and deselect the current selection.
93 * The shape and result components are processed in the values. If the presentation shape is not
94 * empty, select it, otherwise select the result.
95 * \param theValues a list of presentation to be selected
96 * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
98 void setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
101 /// Unselect all objects
102 void clearSelected();
104 /// Erase the feature and a shape.
105 /// \param theObject an object instance
106 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
107 void erase(ObjectPtr theObject, const bool theUpdateViewer = true);
109 /// Erase the given AIS object displayed by corresponded display method
110 /// \param theAIS instance of AIS object
111 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112 void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
114 /// Erase all presentations
115 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
116 void eraseAll(const bool theUpdateViewer = true);
118 /// Deactivates selection of sub-shapes
119 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
120 void closeLocalContexts(const bool theUpdateViewer = true);
122 // Remove default selection filters of the module from the current viewer
123 void deactivateSelectionFilters();
125 /// \brief Add selection filter
126 /// \param theFilter a filter instance
127 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
129 /// \brief Remove selection filter
130 /// \param theFilter a filter instance
131 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
133 /// Returns true if the selection filter is set to the viewer
134 /// \param theFilter a selection filter
135 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
137 /// Remove all selection filters
138 void removeFilters();
141 * Sets a flag to the displayer whether the internal viewer can be updated by
142 * the updateViewer method call. If it is not enabled, this method do nothing
143 * \param isEnabled a boolean value
145 bool enableUpdateViewer(const bool isEnabled);
147 /// Updates the viewer
148 void updateViewer() const;
150 /// Activate interactive context
153 void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
154 const bool theUpdateViewer) const;
156 /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
157 void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
159 /// Searches the interactive object by feature
160 /// \param theObject the object or presentable feature
161 /// \return theIO an interactive object
162 AISObjectPtr getAISObject(ObjectPtr theObject) const;
164 /// Searches the feature by interactive object
165 /// \param theIO an interactive object
166 /// \return feature the feature or NULL if it not visualized
167 ObjectPtr getObject(const AISObjectPtr& theIO) const;
169 /// Searches the feature by interactive object
170 /// \param theIO an interactive object
171 /// \return corresponded object or NULL if it not found
172 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
174 /// Deactivates the given objects (not allow selection)
175 /// \param theObjList - list of objects which has to be deactivated.
176 /// \param theUpdateViewer update viewer flag
177 void deactivateObjects(const QObjectPtrList& theObjList,
178 const bool theUpdateViewer = true);
180 /// Activates the given object (it can be selected)
181 /// \param theObject object to activate
182 /// \param theModes - modes on which it has to be activated (can be empty)
183 //void activate(ObjectPtr theObject, const QIntList& theModes);
185 /// Returns the modes of activation
186 /// \param theObject the feature or NULL if it not visualized
187 /// \param theModes - modes on which it is activated (can be empty)
188 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
190 /// Activates the given object with default modes
191 /// \param theObject object to activate
192 //void activate(ObjectPtr theObject);
194 /// Returns true if the given object can be selected
195 /// \param theObject object to check
196 bool isActive(ObjectPtr theObject) const;
198 /// Activates in local context displayed outside of the context.
199 /// \param theModes - modes on which it has to be activated (can be empty)
200 /// \param theObjList - list of objects which has to be activated.
201 void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
202 const bool theUpdateViewer = true);
204 /// Sets display mode for the given object if this object is displayed
205 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
207 /// Returns current display mode for the given object.
208 /// If object is not dis played then returns NoMode.
209 /// \param theObject object to check
210 DisplayMode displayMode(ObjectPtr theObject) const;
212 /// Displays only objects listed in the list
213 /// \param theList list of objects
214 void showOnly(const QObjectPtrList& theList);
216 /// Returns number of displayed objects
217 int objectsCount() const { return myResult2AISObjectMap.size(); }
219 /// Returns list of displayed objects
220 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
222 /// Returns list of displayed objects
223 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
225 /// Returns true if the given object can be shown in shaded mode
226 /// \param theObject object to check
227 bool canBeShaded(ObjectPtr theObject) const;
229 /// Set color on presentation of an object if it is displayed
230 /// \param theObject an object
231 /// \param theColor a color which has to be set
232 /// \param theUpdateViewer update viewer flag
233 /// \return previously defined color on the object
234 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
237 /// Signal on object display
238 /// \param theObject a data object
239 /// \param theAIS a presentation object
240 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
242 /// Signal on before object erase
243 /// \param theObject a data object
244 /// \param theAIS a presentation object
245 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
248 /// Returns currently installed AIS_InteractiveContext
249 Handle(AIS_InteractiveContext) AISContext() const;
251 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
252 /// The context should have only this filter inside. Other filters should be add to the filter
253 Handle(SelectMgr_AndFilter) GetFilter();
255 /// Display the feature and a shape. This shape would be associated to the given feature
256 /// \param theObject an object instance
257 /// \param theAIS AIS presentation
258 /// \param isShading flag to show in shading mode
259 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
260 /// \return true if the object is succesfully displayed
261 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
262 bool theUpdateViewer = true);
265 /// Activates the interactive object in the local context.
266 /// \param theIO an interactive object
267 /// \param theModes - modes on which it has to be activated (can be empty)
268 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
269 const bool theUpdateViewer) const;
271 /// Deactivates the given object (not allow selection)
272 /// \param theObject object to deactivate
273 void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
275 /// Find a trihedron in a list of displayed presentations and deactivate it.
276 void deactivateTrihedron() const;
278 /// Opens local context. Does nothing if it is already opened.
279 void openLocalContext();
281 /** Update the object presentable properties such as color, lines width and other
282 * If the object is result with the color attribute value set, it is used,
283 * otherwise the customize is applyed to the object's feature if it is a custom prs
284 * \param theObject an object instance
285 * \return the true state if there is changes and the presentation is customized
287 bool customizeObject(ObjectPtr theObject);
289 /// Append the objects in the internal map. Checks whether the map already contains the object
290 /// \param theObject an object to display
291 /// \param theAIS AIOS object to display
292 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
294 /// Returns an information about alredy displayed objects
295 /// \return a string representation
296 std::string getResult2AISObjectMapInfo() const;
299 /// Reference to workshop
300 XGUI_Workshop* myWorkshop;
302 /// A container for selection filters
303 Handle(SelectMgr_AndFilter) myAndFilter;
305 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
306 GeomCustomPrsPtr myCustomPrs;
308 /// Definition of a type of map which defines correspondance between objects and presentations
309 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
311 /// A map of displayed objects
312 ResultToAISMap myResult2AISObjectMap;
314 /// Selection modes installed for external objects in local context
315 QIntList myActiveSelectionModes;
317 /// the enable update viewer flag
318 bool myEnableUpdateViewer;