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>
22 #include <ModuleBase_FilterValidated.h>
24 #include <GeomAPI_ICustomPrs.h>
26 #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
41 /// \enum DisplayMode display mode
43 /// Mode is not defined
45 /// Wireframe display mode
47 /// Shading display mode
52 /// \param theWorkshop a workshop instance
53 XGUI_Displayer(XGUI_Workshop* theWorkshop);
56 virtual ~XGUI_Displayer();
58 /// Returns the feature visibility state.
59 /// \param theObject an object instance
60 bool isVisible(ObjectPtr theObject) const;
62 /// Display the feature. Obtain the visualized object from the feature.
63 /// \param theObject an object to display
64 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
65 /// Returns true if the Feature succesfully displayed
66 void display(ObjectPtr theObject, bool isUpdateViewer = true);
68 /// Display the given AIS object. To hide this object use corresponde erase method
69 /// \param theAIS AIOS object to display
70 /// \param isUpdate the parameter whether the viewer should be update immediatelly
71 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
74 * Add presentations which corresponds to the given features to current selection
75 * \param theFeatures a list of features to be selected
76 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
78 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
81 /// Unselect all objects
84 /// Erase the feature and a shape.
85 /// \param theObject an object instance
86 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
87 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
89 /// Erase the given AIS object displayed by corresponded display method
90 /// \param theAIS instance of AIS object
91 /// \param isUpdate the parameter whether the viewer should be update immediatelly
92 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
94 /// Erase all presentations
95 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
96 void eraseAll(const bool isUpdateViewer = true);
98 /// Deactivates selection of sub-shapes
99 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
100 void closeLocalContexts(const bool isUpdateViewer = true);
102 /// \brief Add selection filter
103 /// \param theFilter a filter instance
104 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
106 /// \brief Remove selection filter
107 /// \param theFilter a filter instance
108 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
110 /// Remove all selection filters
111 void removeFilters();
114 * Sets a flag to the displayer whether the internal viewer can be updated by
115 * the updateViewer method call. If it is not enabled, this method do nothing
116 * \param isEnabled a boolean value
118 bool enableUpdateViewer(const bool isEnabled);
120 /// Updates the viewer
123 /// Searches the interactive object by feature
124 /// \param theObject the object or presentable feature
125 /// \return theIO an interactive object
126 AISObjectPtr getAISObject(ObjectPtr theObject) const;
128 /// Searches the feature by interactive object
129 /// \param theIO an interactive object
130 /// \return feature the feature or NULL if it not visualized
131 ObjectPtr getObject(const AISObjectPtr& theIO) const;
133 /// Searches the feature by interactive object
134 /// \param theIO an interactive object
135 /// \return corresponded object or NULL if it not found
136 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
138 /// Deactivates the given object (not allow selection)
139 /// \param theObject object to deactivate
140 void deactivate(ObjectPtr theObject);
142 /// Activates the given object (it can be selected)
143 /// \param theObject object to activate
144 /// \param theModes - modes on which it has to be activated (can be empty)
145 //void activate(ObjectPtr theObject, const QIntList& theModes);
147 /// Returns the modes of activation
148 /// \param theObject the feature or NULL if it not visualized
149 /// \param theModes - modes on which it is activated (can be empty)
150 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
152 /// Activates the given object with default modes
153 /// \param theObject object to activate
154 //void activate(ObjectPtr theObject);
156 /// Returns true if the given object can be selected
157 /// \param theObject object to check
158 bool isActive(ObjectPtr theObject) const;
160 /// Activates in local context displayed outside of the context.
161 /// \param theModes - modes on which it has to be activated (can be empty)
162 void activateObjects(const QIntList& theModes);
164 /// Activates in local context displayed outside of the context.
165 void deactivateObjects();
167 /// Sets display mode for the given object if this object is displayed
168 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
170 /// Returns current display mode for the given object.
171 /// If object is not dis played then returns NoMode.
172 /// \param theObject object to check
173 DisplayMode displayMode(ObjectPtr theObject) const;
175 /// Displays only objects listed in the list
176 /// \param theList list of objects
177 void showOnly(const QObjectPtrList& theList);
179 /// Returns number of displayed objects
180 int objectsCount() const { return myResult2AISObjectMap.size(); }
182 /// Returns list of displayed objects
183 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
185 /// Returns true if the given object can be shown in shaded mode
186 /// \param theObject object to check
187 bool canBeShaded(ObjectPtr theObject) const;
190 /// Returns currently installed AIS_InteractiveContext
191 Handle(AIS_InteractiveContext) AISContext() const;
193 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
194 /// The context should have only this filter inside. Other filters should be add to the filter
195 Handle(SelectMgr_AndFilter) GetFilter();
197 /// Display the feature and a shape. This shape would be associated to the given feature
198 /// \param theObject an object instance
199 /// \param theAIS AIS presentation
200 /// \param isShading flag to show in shading mode
201 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
202 /// \return true if the object is succesfully displayed
203 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
204 bool isUpdateViewer = true);
206 /** Redisplay the shape if it was displayed
207 * \param theObject an object instance
208 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
210 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
212 /// Activates the interactive object in the local context.
213 /// \param theIO an interactive object
214 /// \param theModes - modes on which it has to be activated (can be empty)
215 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
217 /// Opens local context. Does nothing if it is already opened.
218 void openLocalContext();
220 /** Update the object presentable properties such as color, lines width and other
221 * If the object is result with the color attribute value set, it is used,
222 * otherwise the customize is applyed to the object's feature if it is a custom prs
223 * \param theObject an object instance
224 * \return the true state if there is changes and the presentation is customized
226 bool customizeObject(ObjectPtr theObject);
229 /// Reference to workshop
230 XGUI_Workshop* myWorkshop;
232 /// A container for selection filters
233 Handle(SelectMgr_AndFilter) myAndFilter;
235 Handle(ModuleBase_FilterValidated) myFilterValidated;
237 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
238 GeomCustomPrsPtr myCustomPrs;
240 /// Definition of a type of map which defines correspondance between objects and presentations
241 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
243 /// A map of displayed objects
244 ResultToAISMap myResult2AISObjectMap;
246 /// Selection modes installed for external objects in local context
247 QIntList myActiveSelectionModes;
249 /// the enable update viewer flag
250 bool myEnableUpdateViewer;