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);
76 * Add presentations which corresponds to the given features to current selection
77 * \param theFeatures a list of features to be selected
78 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
83 /// Unselect all objects
86 /// Erase the feature and a shape.
87 /// \param theObject an object instance
88 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
91 /// Erase the given AIS object displayed by corresponded display method
92 /// \param theAIS instance of AIS object
93 /// \param isUpdate the parameter whether the viewer should be update immediatelly
94 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
96 /// Erase all presentations
97 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98 void eraseAll(const bool isUpdateViewer = true);
100 /// Deactivates selection of sub-shapes
101 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102 void closeLocalContexts(const bool isUpdateViewer = true);
104 /// \brief Add selection filter
105 /// \param theFilter a filter instance
106 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
108 /// \brief Remove selection filter
109 /// \param theFilter a filter instance
110 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
112 /// Remove all selection filters
113 void removeFilters();
116 * Sets a flag to the displayer whether the internal viewer can be updated by
117 * the updateViewer method call. If it is not enabled, this method do nothing
118 * \param isEnabled a boolean value
120 bool enableUpdateViewer(const bool isEnabled);
122 /// Updates the viewer
125 /// Searches the interactive object by feature
126 /// \param theObject the object or presentable feature
127 /// \return theIO an interactive object
128 AISObjectPtr getAISObject(ObjectPtr theObject) const;
130 /// Searches the feature by interactive object
131 /// \param theIO an interactive object
132 /// \return feature the feature or NULL if it not visualized
133 ObjectPtr getObject(const AISObjectPtr& theIO) const;
135 /// Searches the feature by interactive object
136 /// \param theIO an interactive object
137 /// \return corresponded object or NULL if it not found
138 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
140 /// Deactivates the given object (not allow selection)
141 /// \param theObject object to deactivate
142 void deactivate(ObjectPtr theObject);
144 /// Activates the given object (it can be selected)
145 /// \param theObject object to activate
146 /// \param theModes - modes on which it has to be activated (can be empty)
147 //void activate(ObjectPtr theObject, const QIntList& theModes);
149 /// Returns the modes of activation
150 /// \param theObject the feature or NULL if it not visualized
151 /// \param theModes - modes on which it is activated (can be empty)
152 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
154 /// Activates the given object with default modes
155 /// \param theObject object to activate
156 //void activate(ObjectPtr theObject);
158 /// Returns true if the given object can be selected
159 /// \param theObject object to check
160 bool isActive(ObjectPtr theObject) const;
162 /// Activates in local context displayed outside of the context.
163 /// \param theModes - modes on which it has to be activated (can be empty)
164 void activateObjects(const QIntList& theModes);
166 /// Activates in local context displayed outside of the context.
167 void deactivateObjects();
169 /// Sets display mode for the given object if this object is displayed
170 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
172 /// Returns current display mode for the given object.
173 /// If object is not dis played then returns NoMode.
174 /// \param theObject object to check
175 DisplayMode displayMode(ObjectPtr theObject) const;
177 /// Displays only objects listed in the list
178 /// \param theList list of objects
179 void showOnly(const QObjectPtrList& theList);
181 /// Returns number of displayed objects
182 int objectsCount() const { return myResult2AISObjectMap.size(); }
184 /// Returns list of displayed objects
185 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
187 /// Returns list of displayed objects
188 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
190 /// Returns true if the given object can be shown in shaded mode
191 /// \param theObject object to check
192 bool canBeShaded(ObjectPtr theObject) const;
194 /// Set color on presentation of an object if it is displayed
195 /// \param theObject an object
196 /// \param theColor a color which has to be set
197 /// \param theUpdate update viewer flag
198 /// \return previously defined color on the object
199 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
202 /// Signal on object display
203 /// \param theObject a data object
204 /// \param theAIS a presentation object
205 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
207 /// Signal on before object erase
208 /// \param theObject a data object
209 /// \param theAIS a presentation object
210 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
213 /// Returns currently installed AIS_InteractiveContext
214 Handle(AIS_InteractiveContext) AISContext() const;
216 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
217 /// The context should have only this filter inside. Other filters should be add to the filter
218 Handle(SelectMgr_AndFilter) GetFilter();
220 /// Display the feature and a shape. This shape would be associated to the given feature
221 /// \param theObject an object instance
222 /// \param theAIS AIS presentation
223 /// \param isShading flag to show in shading mode
224 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
225 /// \return true if the object is succesfully displayed
226 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
227 bool isUpdateViewer = true);
229 /** Redisplay the shape if it was displayed
230 * \param theObject an object instance
231 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
233 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
235 /// Activates the interactive object in the local context.
236 /// \param theIO an interactive object
237 /// \param theModes - modes on which it has to be activated (can be empty)
238 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
240 /// Opens local context. Does nothing if it is already opened.
241 void openLocalContext();
243 /** Update the object presentable properties such as color, lines width and other
244 * If the object is result with the color attribute value set, it is used,
245 * otherwise the customize is applyed to the object's feature if it is a custom prs
246 * \param theObject an object instance
247 * \return the true state if there is changes and the presentation is customized
249 bool customizeObject(ObjectPtr theObject);
252 /// Reference to workshop
253 XGUI_Workshop* myWorkshop;
255 /// A container for selection filters
256 Handle(SelectMgr_AndFilter) myAndFilter;
258 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
259 GeomCustomPrsPtr myCustomPrs;
261 /// Definition of a type of map which defines correspondance between objects and presentations
262 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
264 /// A map of displayed objects
265 ResultToAISMap myResult2AISObjectMap;
267 /// Selection modes installed for external objects in local context
268 QIntList myActiveSelectionModes;
270 /// the enable update viewer flag
271 bool myEnableUpdateViewer;