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>
31 class ModelAPI_Feature;
34 /**\class XGUI_Displayer
36 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
38 class XGUI_EXPORT XGUI_Displayer: public QObject
42 /// \enum DisplayMode display mode
44 /// Mode is not defined
46 /// Wireframe display mode
48 /// Shading display mode
53 /// \param theWorkshop a workshop instance
54 XGUI_Displayer(XGUI_Workshop* theWorkshop);
57 virtual ~XGUI_Displayer();
59 /// Returns the feature visibility state.
60 /// \param theObject an object instance
61 bool isVisible(ObjectPtr theObject) const;
63 /// Display the feature. Obtain the visualized object from the feature.
64 /// \param theObject an object to display
65 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
66 /// Returns true if the Feature succesfully displayed
67 void display(ObjectPtr theObject, bool isUpdateViewer = true);
69 /// Display the given AIS object. To hide this object use corresponde erase method
70 /// \param theAIS AIOS object to display
71 /// \param isUpdate the parameter whether the viewer should be update immediatelly
72 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
75 * Add presentations which corresponds to the given features to current selection
76 * \param theFeatures a list of features to be selected
77 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
79 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
82 /// Unselect all objects
85 /// Erase the feature and a shape.
86 /// \param theObject an object instance
87 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
88 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
90 /// Erase the given AIS object displayed by corresponded display method
91 /// \param theAIS instance of AIS object
92 /// \param isUpdate the parameter whether the viewer should be update immediatelly
93 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
95 /// Erase all presentations
96 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
97 void eraseAll(const bool isUpdateViewer = true);
99 /// Deactivates selection of sub-shapes
100 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
101 void closeLocalContexts(const bool isUpdateViewer = true);
103 /// \brief Add selection filter
104 /// \param theFilter a filter instance
105 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
107 /// \brief Remove selection filter
108 /// \param theFilter a filter instance
109 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
111 /// Remove all selection filters
112 void removeFilters();
115 * Sets a flag to the displayer whether the internal viewer can be updated by
116 * the updateViewer method call. If it is not enabled, this method do nothing
117 * \param isEnabled a boolean value
119 bool enableUpdateViewer(const bool isEnabled);
121 /// Updates the viewer
124 /// Searches the interactive object by feature
125 /// \param theObject the object or presentable feature
126 /// \return theIO an interactive object
127 AISObjectPtr getAISObject(ObjectPtr theObject) const;
129 /// Searches the feature by interactive object
130 /// \param theIO an interactive object
131 /// \return feature the feature or NULL if it not visualized
132 ObjectPtr getObject(const AISObjectPtr& theIO) const;
134 /// Searches the feature by interactive object
135 /// \param theIO an interactive object
136 /// \return corresponded object or NULL if it not found
137 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
139 /// Deactivates the given object (not allow selection)
140 /// \param theObject object to deactivate
141 void deactivate(ObjectPtr theObject);
143 /// Activates the given object (it can be selected)
144 /// \param theObject object to activate
145 /// \param theModes - modes on which it has to be activated (can be empty)
146 //void activate(ObjectPtr theObject, const QIntList& theModes);
148 /// Returns the modes of activation
149 /// \param theObject the feature or NULL if it not visualized
150 /// \param theModes - modes on which it is activated (can be empty)
151 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
153 /// Activates the given object with default modes
154 /// \param theObject object to activate
155 //void activate(ObjectPtr theObject);
157 /// Returns true if the given object can be selected
158 /// \param theObject object to check
159 bool isActive(ObjectPtr theObject) const;
161 /// Activates in local context displayed outside of the context.
162 /// \param theModes - modes on which it has to be activated (can be empty)
163 void activateObjects(const QIntList& theModes);
165 /// Activates in local context displayed outside of the context.
166 void deactivateObjects();
168 /// Sets display mode for the given object if this object is displayed
169 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
171 /// Returns current display mode for the given object.
172 /// If object is not dis played then returns NoMode.
173 /// \param theObject object to check
174 DisplayMode displayMode(ObjectPtr theObject) const;
176 /// Displays only objects listed in the list
177 /// \param theList list of objects
178 void showOnly(const QObjectPtrList& theList);
180 /// Returns number of displayed objects
181 int objectsCount() const { return myResult2AISObjectMap.size(); }
183 /// Returns list of displayed objects
184 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
186 /// Returns list of displayed objects
187 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
189 /// Returns true if the given object can be shown in shaded mode
190 /// \param theObject object to check
191 bool canBeShaded(ObjectPtr theObject) const;
195 /// Signal on object display
196 /// \param theObject a data object
197 /// \param theAIS a presentation object
198 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
200 /// Signal on before object erase
201 /// \param theObject a data object
202 /// \param theAIS a presentation object
203 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
206 /// Returns currently installed AIS_InteractiveContext
207 Handle(AIS_InteractiveContext) AISContext() const;
209 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
210 /// The context should have only this filter inside. Other filters should be add to the filter
211 Handle(SelectMgr_AndFilter) GetFilter();
213 /// Display the feature and a shape. This shape would be associated to the given feature
214 /// \param theObject an object instance
215 /// \param theAIS AIS presentation
216 /// \param isShading flag to show in shading mode
217 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
218 /// \return true if the object is succesfully displayed
219 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
220 bool isUpdateViewer = true);
222 /** Redisplay the shape if it was displayed
223 * \param theObject an object instance
224 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
226 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
228 /// Activates the interactive object in the local context.
229 /// \param theIO an interactive object
230 /// \param theModes - modes on which it has to be activated (can be empty)
231 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
233 /// Opens local context. Does nothing if it is already opened.
234 void openLocalContext();
236 /** Update the object presentable properties such as color, lines width and other
237 * If the object is result with the color attribute value set, it is used,
238 * otherwise the customize is applyed to the object's feature if it is a custom prs
239 * \param theObject an object instance
240 * \return the true state if there is changes and the presentation is customized
242 bool customizeObject(ObjectPtr theObject);
245 /// Reference to workshop
246 XGUI_Workshop* myWorkshop;
248 /// A container for selection filters
249 Handle(SelectMgr_AndFilter) myAndFilter;
251 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
252 GeomCustomPrsPtr myCustomPrs;
254 /// Definition of a type of map which defines correspondance between objects and presentations
255 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
257 /// A map of displayed objects
258 ResultToAISMap myResult2AISObjectMap;
260 /// Selection modes installed for external objects in local context
261 QIntList myActiveSelectionModes;
263 /// the enable update viewer flag
264 bool myEnableUpdateViewer;