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 isUpdateViewer the parameter whether the viewer should be update immediatelly
67 /// Returns true if the Feature succesfully displayed
68 void display(ObjectPtr theObject, bool isUpdateViewer = true);
70 /// Display the given AIS object. To hide this object use corresponde erase method
71 /// \param theAIS AIOS object to display
72 /// \param isUpdate the parameter whether the viewer should be update immediatelly
73 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
75 /** Redisplay the shape if it was displayed
76 * \param theObject an object instance
77 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
79 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
82 * Add presentations which corresponds to the given features to current selection
83 * \param theFeatures a list of features to be selected
84 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
86 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
89 /// Unselect all objects
92 /// Erase the feature and a shape.
93 /// \param theObject an object instance
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
97 /// Erase the given AIS object displayed by corresponded display method
98 /// \param theAIS instance of AIS object
99 /// \param isUpdate the parameter whether the viewer should be update immediatelly
100 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
102 /// Erase all presentations
103 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
104 void eraseAll(const bool isUpdateViewer = true);
106 /// Deactivates selection of sub-shapes
107 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
108 void closeLocalContexts(const bool isUpdateViewer = true);
110 /// \brief Add selection filter
111 /// \param theFilter a filter instance
112 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
114 /// \brief Remove selection filter
115 /// \param theFilter a filter instance
116 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
118 /// Remove all selection filters
119 void removeFilters();
122 * Sets a flag to the displayer whether the internal viewer can be updated by
123 * the updateViewer method call. If it is not enabled, this method do nothing
124 * \param isEnabled a boolean value
126 bool enableUpdateViewer(const bool isEnabled);
128 /// Updates the viewer
131 /// Searches the interactive object by feature
132 /// \param theObject the object or presentable feature
133 /// \return theIO an interactive object
134 AISObjectPtr getAISObject(ObjectPtr theObject) const;
136 /// Searches the feature by interactive object
137 /// \param theIO an interactive object
138 /// \return feature the feature or NULL if it not visualized
139 ObjectPtr getObject(const AISObjectPtr& theIO) const;
141 /// Searches the feature by interactive object
142 /// \param theIO an interactive object
143 /// \return corresponded object or NULL if it not found
144 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
146 /// Deactivates the given object (not allow selection)
147 /// \param theObject object to deactivate
148 void deactivate(ObjectPtr theObject);
150 /// Activates the given object (it can be selected)
151 /// \param theObject object to activate
152 /// \param theModes - modes on which it has to be activated (can be empty)
153 //void activate(ObjectPtr theObject, const QIntList& theModes);
155 /// Returns the modes of activation
156 /// \param theObject the feature or NULL if it not visualized
157 /// \param theModes - modes on which it is activated (can be empty)
158 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
160 /// Activates the given object with default modes
161 /// \param theObject object to activate
162 //void activate(ObjectPtr theObject);
164 /// Returns true if the given object can be selected
165 /// \param theObject object to check
166 bool isActive(ObjectPtr theObject) const;
168 /// Activates in local context displayed outside of the context.
169 /// \param theModes - modes on which it has to be activated (can be empty)
170 void activateObjects(const QIntList& theModes);
172 /// Activates in local context displayed outside of the context.
173 void deactivateObjects();
175 /// Sets display mode for the given object if this object is displayed
176 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
178 /// Returns current display mode for the given object.
179 /// If object is not dis played then returns NoMode.
180 /// \param theObject object to check
181 DisplayMode displayMode(ObjectPtr theObject) const;
183 /// Displays only objects listed in the list
184 /// \param theList list of objects
185 void showOnly(const QObjectPtrList& theList);
187 /// Returns number of displayed objects
188 int objectsCount() const { return myResult2AISObjectMap.size(); }
190 /// Returns list of displayed objects
191 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
193 /// Returns list of displayed objects
194 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
196 /// Returns true if the given object can be shown in shaded mode
197 /// \param theObject object to check
198 bool canBeShaded(ObjectPtr theObject) const;
200 /// Set color on presentation of an object if it is displayed
201 /// \param theObject an object
202 /// \param theColor a color which has to be set
203 /// \param theUpdate update viewer flag
204 /// \return previously defined color on the object
205 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
208 /// Signal on object display
209 /// \param theObject a data object
210 /// \param theAIS a presentation object
211 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
213 /// Signal on before object erase
214 /// \param theObject a data object
215 /// \param theAIS a presentation object
216 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
219 /// Returns currently installed AIS_InteractiveContext
220 Handle(AIS_InteractiveContext) AISContext() const;
222 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
223 /// The context should have only this filter inside. Other filters should be add to the filter
224 Handle(SelectMgr_AndFilter) GetFilter();
226 /// Display the feature and a shape. This shape would be associated to the given feature
227 /// \param theObject an object instance
228 /// \param theAIS AIS presentation
229 /// \param isShading flag to show in shading mode
230 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
231 /// \return true if the object is succesfully displayed
232 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
233 bool isUpdateViewer = true);
236 /// Activates the interactive object in the local context.
237 /// \param theIO an interactive object
238 /// \param theModes - modes on which it has to be activated (can be empty)
239 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
241 /// Opens local context. Does nothing if it is already opened.
242 void openLocalContext();
244 /** Update the object presentable properties such as color, lines width and other
245 * If the object is result with the color attribute value set, it is used,
246 * otherwise the customize is applyed to the object's feature if it is a custom prs
247 * \param theObject an object instance
248 * \return the true state if there is changes and the presentation is customized
250 bool customizeObject(ObjectPtr theObject);
253 /// Reference to workshop
254 XGUI_Workshop* myWorkshop;
256 /// A container for selection filters
257 Handle(SelectMgr_AndFilter) myAndFilter;
259 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
260 GeomCustomPrsPtr myCustomPrs;
262 /// Definition of a type of map which defines correspondance between objects and presentations
263 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
265 /// A map of displayed objects
266 ResultToAISMap myResult2AISObjectMap;
268 /// Selection modes installed for external objects in local context
269 QIntList myActiveSelectionModes;
271 /// the enable update viewer flag
272 bool myEnableUpdateViewer;