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 true if the given object can be shown in shaded mode
187 /// \param theObject object to check
188 bool canBeShaded(ObjectPtr theObject) const;
192 /// Signal on object display
193 /// \param theObject a data object
194 /// \param theAIS a presentation object
195 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
197 /// Signal on before object erase
198 /// \param theObject a data object
199 /// \param theAIS a presentation object
200 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
203 /// Returns currently installed AIS_InteractiveContext
204 Handle(AIS_InteractiveContext) AISContext() const;
206 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
207 /// The context should have only this filter inside. Other filters should be add to the filter
208 Handle(SelectMgr_AndFilter) GetFilter();
210 /// Display the feature and a shape. This shape would be associated to the given feature
211 /// \param theObject an object instance
212 /// \param theAIS AIS presentation
213 /// \param isShading flag to show in shading mode
214 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
215 /// \return true if the object is succesfully displayed
216 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
217 bool isUpdateViewer = true);
219 /** Redisplay the shape if it was displayed
220 * \param theObject an object instance
221 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
223 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
225 /// Activates the interactive object in the local context.
226 /// \param theIO an interactive object
227 /// \param theModes - modes on which it has to be activated (can be empty)
228 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
230 /// Opens local context. Does nothing if it is already opened.
231 void openLocalContext();
233 /** Update the object presentable properties such as color, lines width and other
234 * If the object is result with the color attribute value set, it is used,
235 * otherwise the customize is applyed to the object's feature if it is a custom prs
236 * \param theObject an object instance
237 * \return the true state if there is changes and the presentation is customized
239 bool customizeObject(ObjectPtr theObject);
242 /// Reference to workshop
243 XGUI_Workshop* myWorkshop;
245 /// A container for selection filters
246 Handle(SelectMgr_AndFilter) myAndFilter;
248 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
249 GeomCustomPrsPtr myCustomPrs;
251 /// Definition of a type of map which defines correspondance between objects and presentations
252 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
254 /// A map of displayed objects
255 ResultToAISMap myResult2AISObjectMap;
257 /// Selection modes installed for external objects in local context
258 QIntList myActiveSelectionModes;
260 /// the enable update viewer flag
261 bool myEnableUpdateViewer;