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>
30 class ModelAPI_Feature;
33 /**\class XGUI_Displayer
35 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
37 class XGUI_EXPORT XGUI_Displayer
40 /// \enum DisplayMode display mode
42 /// Mode is not defined
44 /// Wireframe display mode
46 /// Shading display mode
51 /// \param theWorkshop a workshop instance
52 XGUI_Displayer(XGUI_Workshop* theWorkshop);
55 virtual ~XGUI_Displayer();
57 /// Returns the feature visibility state.
58 /// \param theObject an object instance
59 bool isVisible(ObjectPtr theObject) const;
61 /// Display the feature. Obtain the visualized object from the feature.
62 /// \param theObject an object to display
63 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
64 /// Returns true if the Feature succesfully displayed
65 void display(ObjectPtr theObject, bool isUpdateViewer = true);
67 /// Display the given AIS object. To hide this object use corresponde erase method
68 /// \param theAIS AIOS object to display
69 /// \param isUpdate the parameter whether the viewer should be update immediatelly
70 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
73 * Add presentations which corresponds to the given features to current selection
74 * \param theFeatures a list of features to be selected
75 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
77 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
80 /// Unselect all objects
83 /// Erase the feature and a shape.
84 /// \param theObject an object instance
85 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
86 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
88 /// Erase the given AIS object displayed by corresponded display method
89 /// \param theAIS instance of AIS object
90 /// \param isUpdate the parameter whether the viewer should be update immediatelly
91 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
93 /// Erase all presentations
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 void eraseAll(const bool isUpdateViewer = true);
97 /// Deactivates selection of sub-shapes
98 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
99 void closeLocalContexts(const bool isUpdateViewer = true);
101 /// \brief Add selection filter
102 /// \param theFilter a filter instance
103 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
105 /// \brief Remove selection filter
106 /// \param theFilter a filter instance
107 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
109 /// Remove all selection filters
110 void removeFilters();
113 * Sets a flag to the displayer whether the internal viewer can be updated by
114 * the updateViewer method call. If it is not enabled, this method do nothing
115 * \param isEnabled a boolean value
117 bool enableUpdateViewer(const bool isEnabled);
119 /// Updates the viewer
122 /// Searches the interactive object by feature
123 /// \param theObject the object or presentable feature
124 /// \return theIO an interactive object
125 AISObjectPtr getAISObject(ObjectPtr theObject) const;
127 /// Searches the feature by interactive object
128 /// \param theIO an interactive object
129 /// \return feature the feature or NULL if it not visualized
130 ObjectPtr getObject(const AISObjectPtr& theIO) const;
132 /// Searches the feature by interactive object
133 /// \param theIO an interactive object
134 /// \return corresponded object or NULL if it not found
135 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
137 /// Deactivates the given object (not allow selection)
138 /// \param theObject object to deactivate
139 void deactivate(ObjectPtr theObject);
141 /// Activates the given object (it can be selected)
142 /// \param theObject object to activate
143 /// \param theModes - modes on which it has to be activated (can be empty)
144 //void activate(ObjectPtr theObject, const QIntList& theModes);
146 /// Returns the modes of activation
147 /// \param theObject the feature or NULL if it not visualized
148 /// \param theModes - modes on which it is activated (can be empty)
149 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
151 /// Activates the given object with default modes
152 /// \param theObject object to activate
153 //void activate(ObjectPtr theObject);
155 /// Returns true if the given object can be selected
156 /// \param theObject object to check
157 bool isActive(ObjectPtr theObject) const;
159 /// Activates in local context displayed outside of the context.
160 /// \param theModes - modes on which it has to be activated (can be empty)
161 void activateObjects(const QIntList& theModes);
163 /// Activates in local context displayed outside of the context.
164 void deactivateObjects();
166 /// Sets display mode for the given object if this object is displayed
167 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
169 /// Returns current display mode for the given object.
170 /// If object is not dis played then returns NoMode.
171 /// \param theObject object to check
172 DisplayMode displayMode(ObjectPtr theObject) const;
174 /// Displays only objects listed in the list
175 /// \param theList list of objects
176 void showOnly(const QObjectPtrList& theList);
178 /// Returns number of displayed objects
179 int objectsCount() const { return myResult2AISObjectMap.size(); }
181 /// Returns list of displayed objects
182 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
184 /// Returns true if the given object can be shown in shaded mode
185 /// \param theObject object to check
186 bool canBeShaded(ObjectPtr theObject) const;
189 /// Returns currently installed AIS_InteractiveContext
190 Handle(AIS_InteractiveContext) AISContext() const;
192 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
193 /// The context should have only this filter inside. Other filters should be add to the filter
194 Handle(SelectMgr_AndFilter) GetFilter();
196 /// Display the feature and a shape. This shape would be associated to the given feature
197 /// \param theObject an object instance
198 /// \param theAIS AIS presentation
199 /// \param isShading flag to show in shading mode
200 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
201 /// \return true if the object is succesfully displayed
202 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
203 bool isUpdateViewer = true);
205 /** Redisplay the shape if it was displayed
206 * \param theObject an object instance
207 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
209 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
211 /// Activates the interactive object in the local context.
212 /// \param theIO an interactive object
213 /// \param theModes - modes on which it has to be activated (can be empty)
214 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
216 /// Opens local context. Does nothing if it is already opened.
217 void openLocalContext();
219 /** Update the object presentable properties such as color, lines width and other
220 * If the object is result with the color attribute value set, it is used,
221 * otherwise the customize is applyed to the object's feature if it is a custom prs
222 * \param theObject an object instance
223 * \return the true state if there is changes and the presentation is customized
225 bool customizeObject(ObjectPtr theObject);
228 /// Reference to workshop
229 XGUI_Workshop* myWorkshop;
231 /// A container for selection filters
232 Handle(SelectMgr_AndFilter) myAndFilter;
234 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
235 GeomCustomPrsPtr myCustomPrs;
237 /// Definition of a type of map which defines correspondance between objects and presentations
238 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
240 /// A map of displayed objects
241 ResultToAISMap myResult2AISObjectMap;
243 /// Selection modes installed for external objects in local context
244 QIntList myActiveSelectionModes;
246 /// the enable update viewer flag
247 bool myEnableUpdateViewer;