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 <SelectMgr_AndFilter.hxx>
28 class ModelAPI_Feature;
31 /**\class XGUI_Displayer
33 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
35 class XGUI_EXPORT XGUI_Displayer
38 /// \enum DisplayMode display mode
40 /// Mode is not defined
42 /// Wireframe display mode
44 /// Shading display mode
49 /// \param theWorkshop a workshop instance
50 XGUI_Displayer(XGUI_Workshop* theWorkshop);
53 virtual ~XGUI_Displayer();
55 /// Returns the feature visibility state.
56 /// \param theObject an object instance
57 bool isVisible(ObjectPtr theObject) const;
59 /// Display the feature. Obtain the visualized object from the feature.
60 /// \param theObject an object to display
61 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
62 /// Returns true if the Feature succesfully displayed
63 void display(ObjectPtr theObject, bool isUpdateViewer = true);
65 /// Display the given AIS object. To hide this object use corresponde erase method
66 /// \param theAIS AIOS object to display
67 /// \param isUpdate the parameter whether the viewer should be update immediatelly
68 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
71 * Add presentations which corresponds to the given features to current selection
72 * \param theFeatures a list of features to be selected
73 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
75 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
78 /// Unselect all objects
81 /// Erase the feature and a shape.
82 /// \param theObject an object instance
83 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
86 /// Erase the given AIS object displayed by corresponded display method
87 /// \param theAIS instance of AIS object
88 /// \param isUpdate the parameter whether the viewer should be update immediatelly
89 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
91 /// Erase all presentations
92 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
93 void eraseAll(const bool isUpdateViewer = true);
95 /// Deactivates selection of sub-shapes
96 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
97 void closeLocalContexts(const bool isUpdateViewer = true);
99 /// \brief Add selection filter
100 /// \param theFilter a filter instance
101 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
103 /// \brief Remove selection filter
104 /// \param theFilter a filter instance
105 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
107 /// Remove all selection filters
108 void removeFilters();
111 * Sets a flag to the displayer whether the internal viewer can be updated by
112 * the updateViewer method call. If it is not enabled, this method do nothing
113 * \param isEnabled a boolean value
115 bool enableUpdateViewer(const bool isEnabled);
117 /// Updates the viewer
120 /// Searches the interactive object by feature
121 /// \param theObject the object or presentable feature
122 /// \return theIO an interactive object
123 AISObjectPtr getAISObject(ObjectPtr theObject) const;
125 /// Searches the feature by interactive object
126 /// \param theIO an interactive object
127 /// \return feature the feature or NULL if it not visualized
128 ObjectPtr getObject(const AISObjectPtr& theIO) const;
130 /// Searches the feature by interactive object
131 /// \param theIO an interactive object
132 /// \return corresponded object or NULL if it not found
133 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
135 /// Deactivates the given object (not allow selection)
136 /// \param theObject object to deactivate
137 void deactivate(ObjectPtr theObject);
139 /// Activates the given object (it can be selected)
140 /// \param theObject object to activate
141 /// \param theModes - modes on which it has to be activated (can be empty)
142 //void activate(ObjectPtr theObject, const QIntList& theModes);
144 /// Returns the modes of activation
145 /// \param theObject the feature or NULL if it not visualized
146 /// \param theModes - modes on which it is activated (can be empty)
147 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
149 /// Activates the given object with default modes
150 /// \param theObject object to activate
151 //void activate(ObjectPtr theObject);
153 /// Returns true if the given object can be selected
154 /// \param theObject object to check
155 bool isActive(ObjectPtr theObject) const;
157 /// Activates in local context displayed outside of the context.
158 /// \param theModes - modes on which it has to be activated (can be empty)
159 void activateObjects(const QIntList& theModes);
161 /// Activates in local context displayed outside of the context.
162 void deactivateObjects();
164 /// Sets display mode for the given object if this object is displayed
165 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
167 /// Returns current display mode for the given object.
168 /// If object is not dis played then returns NoMode.
169 /// \param theObject object to check
170 DisplayMode displayMode(ObjectPtr theObject) const;
172 /// Displays only objects listed in the list
173 /// \param theList list of objects
174 void showOnly(const QObjectPtrList& theList);
176 /// Returns number of displayed objects
177 int objectsCount() const { return myResult2AISObjectMap.size(); }
179 /// Returns list of displayed objects
180 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
182 /// Returns true if the given object can be shown in shaded mode
183 /// \param theObject object to check
184 bool canBeShaded(ObjectPtr theObject) const;
187 /// Returns currently installed AIS_InteractiveContext
188 Handle(AIS_InteractiveContext) AISContext() const;
190 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
191 /// The context should have only this filter inside. Other filters should be add to the filter
192 Handle(SelectMgr_AndFilter) GetFilter();
194 /// Display the feature and a shape. This shape would be associated to the given feature
195 /// \param theObject an object instance
196 /// \param theAIS AIS presentation
197 /// \param isShading flag to show in shading mode
198 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
199 /// \return true if the object is succesfully displayed
200 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
201 bool isUpdateViewer = true);
203 /** Redisplay the shape if it was displayed
204 * \param theObject an object instance
205 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
207 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
209 /// Activates the interactive object in the local context.
210 /// \param theIO an interactive object
211 /// \param theModes - modes on which it has to be activated (can be empty)
212 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
214 /// Opens local context. Does nothing if it is already opened.
215 void openLocalContext();
217 /** Update the object presentable properties such as color, lines width and other
218 * If the object is result with the color attribute value set, it is used,
219 * otherwise the customize is applyed to the object's feature if it is a custom prs
220 * \param theObject an object instance
222 void customizeObject(ObjectPtr theObject);
225 /// Reference to workshop
226 XGUI_Workshop* myWorkshop;
228 /// A container for selection filters
229 Handle(SelectMgr_AndFilter) myAndFilter;
231 /// Definition of a type of map which defines correspondance between objects and presentations
232 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
234 /// A map of displayed objects
235 ResultToAISMap myResult2AISObjectMap;
237 /// Selection modes installed for external objects in local context
238 QIntList myActiveSelectionModes;
240 /// the enable update viewer flag
241 bool myEnableUpdateViewer;