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 theUpdateViewer the parameter whether the viewer should be update immediatelly
67 /// Returns true if the Feature succesfully displayed
68 void display(ObjectPtr theObject, bool theUpdateViewer = true);
70 /// Display the given AIS object. To hide this object use corresponde erase method
71 /// \param theAIS AIOS object to display
72 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
73 void displayAIS(AISObjectPtr theAIS, bool theUpdateViewer = true);
75 /** Redisplay the shape if it was displayed
76 * \param theObject an object instance
77 * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
79 void redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
82 * Add presentations to current selection. It unhighlight and deselect the current selection.
83 * The shape and result components are processed in the values. If the presentation shape is not
84 * empty, select it, otherwise select the result.
85 * \param theValues a list of presentation to be selected
86 * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
88 void setSelected(const QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
91 /// Unselect all objects
94 /// Erase the feature and a shape.
95 /// \param theObject an object instance
96 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
97 void erase(ObjectPtr theObject, const bool theUpdateViewer = true);
99 /// Erase the given AIS object displayed by corresponded display method
100 /// \param theAIS instance of AIS object
101 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
102 void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
104 /// Erase all presentations
105 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
106 void eraseAll(const bool theUpdateViewer = true);
108 /// Deactivates selection of sub-shapes
109 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
110 void closeLocalContexts(const bool theUpdateViewer = true);
112 /// \brief Add selection filter
113 /// \param theFilter a filter instance
114 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
116 /// \brief Remove selection filter
117 /// \param theFilter a filter instance
118 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
120 /// Returns true if the selection filter is set to the viewer
121 /// \param theFilter a selection filter
122 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
124 /// Remove all selection filters
125 void removeFilters();
128 * Sets a flag to the displayer whether the internal viewer can be updated by
129 * the updateViewer method call. If it is not enabled, this method do nothing
130 * \param isEnabled a boolean value
132 bool enableUpdateViewer(const bool isEnabled);
134 /// Updates the viewer
135 void updateViewer() const;
137 /// Activate interactive context
140 void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
141 const bool theUpdateViewer) const;
143 /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
144 void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
146 /// Searches the interactive object by feature
147 /// \param theObject the object or presentable feature
148 /// \return theIO an interactive object
149 AISObjectPtr getAISObject(ObjectPtr theObject) const;
151 /// Searches the feature by interactive object
152 /// \param theIO an interactive object
153 /// \return feature the feature or NULL if it not visualized
154 ObjectPtr getObject(const AISObjectPtr& theIO) const;
156 /// Searches the feature by interactive object
157 /// \param theIO an interactive object
158 /// \return corresponded object or NULL if it not found
159 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
161 /// Deactivates the given object (not allow selection)
162 /// \param theObject object to deactivate
163 void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
165 /// Activates the given object (it can be selected)
166 /// \param theObject object to activate
167 /// \param theModes - modes on which it has to be activated (can be empty)
168 //void activate(ObjectPtr theObject, const QIntList& theModes);
170 /// Returns the modes of activation
171 /// \param theObject the feature or NULL if it not visualized
172 /// \param theModes - modes on which it is activated (can be empty)
173 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
175 /// Activates the given object with default modes
176 /// \param theObject object to activate
177 //void activate(ObjectPtr theObject);
179 /// Returns true if the given object can be selected
180 /// \param theObject object to check
181 bool isActive(ObjectPtr theObject) const;
183 /// Activates in local context displayed outside of the context.
184 /// \param theModes - modes on which it has to be activated (can be empty)
185 /// \param theObjList - list of objects which has to be activated.
186 void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
187 const bool theUpdateViewer = true);
189 /// Sets display mode for the given object if this object is displayed
190 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
192 /// Returns current display mode for the given object.
193 /// If object is not dis played then returns NoMode.
194 /// \param theObject object to check
195 DisplayMode displayMode(ObjectPtr theObject) const;
197 /// Displays only objects listed in the list
198 /// \param theList list of objects
199 void showOnly(const QObjectPtrList& theList);
201 /// Returns number of displayed objects
202 int objectsCount() const { return myResult2AISObjectMap.size(); }
204 /// Returns list of displayed objects
205 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
207 /// Returns list of displayed objects
208 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
210 /// Returns true if the given object can be shown in shaded mode
211 /// \param theObject object to check
212 bool canBeShaded(ObjectPtr theObject) const;
214 /// Set color on presentation of an object if it is displayed
215 /// \param theObject an object
216 /// \param theColor a color which has to be set
217 /// \param theUpdateViewer update viewer flag
218 /// \return previously defined color on the object
219 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
222 /// Signal on object display
223 /// \param theObject a data object
224 /// \param theAIS a presentation object
225 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
227 /// Signal on before object erase
228 /// \param theObject a data object
229 /// \param theAIS a presentation object
230 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
233 /// Returns currently installed AIS_InteractiveContext
234 Handle(AIS_InteractiveContext) AISContext() const;
236 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
237 /// The context should have only this filter inside. Other filters should be add to the filter
238 Handle(SelectMgr_AndFilter) GetFilter();
240 /// Display the feature and a shape. This shape would be associated to the given feature
241 /// \param theObject an object instance
242 /// \param theAIS AIS presentation
243 /// \param isShading flag to show in shading mode
244 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
245 /// \return true if the object is succesfully displayed
246 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
247 bool theUpdateViewer = true);
250 /// Activates the interactive object in the local context.
251 /// \param theIO an interactive object
252 /// \param theModes - modes on which it has to be activated (can be empty)
253 void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
254 const bool theUpdateViewer) const;
256 /// Find a trihedron in a list of displayed presentations and deactivate it.
257 void deactivateTrihedron() const;
259 /// Opens local context. Does nothing if it is already opened.
260 void openLocalContext();
262 /** Update the object presentable properties such as color, lines width and other
263 * If the object is result with the color attribute value set, it is used,
264 * otherwise the customize is applyed to the object's feature if it is a custom prs
265 * \param theObject an object instance
266 * \return the true state if there is changes and the presentation is customized
268 bool customizeObject(ObjectPtr theObject);
270 /// Append the objects in the internal map. Checks whether the map already contains the object
271 /// \param theObject an object to display
272 /// \param theAIS AIOS object to display
273 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
275 /// Returns an information about alredy displayed objects
276 /// \return a string representation
277 std::string getResult2AISObjectMapInfo() const;
280 /// Reference to workshop
281 XGUI_Workshop* myWorkshop;
283 /// A container for selection filters
284 Handle(SelectMgr_AndFilter) myAndFilter;
286 /// A default custom presentation, which is used if the displayed feature is not a custom presentation
287 GeomCustomPrsPtr myCustomPrs;
289 /// Definition of a type of map which defines correspondance between objects and presentations
290 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
292 /// A map of displayed objects
293 ResultToAISMap myResult2AISObjectMap;
295 /// Selection modes installed for external objects in local context
296 QIntList myActiveSelectionModes;
298 /// the enable update viewer flag
299 bool myEnableUpdateViewer;