1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef XGUI_Displayer_H
22 #define XGUI_Displayer_H
26 #include <GeomAPI_AISObject.h>
27 #include <GeomAPI_ICustomPrs.h>
29 #include <ModelAPI_Result.h>
31 #include <ModuleBase_Definitions.h>
33 #include <AIS_InteractiveObject.hxx>
34 #include <AIS_InteractiveContext.hxx>
35 #include <NCollection_Map.hxx>
36 #include <NCollection_DataMap.hxx>
37 #include <SelectMgr_AndFilter.hxx>
38 #include <TopoDS_Shape.hxx>
45 class ModuleBase_ViewerPrs;
46 class ModelAPI_Feature;
47 class XGUI_SelectionActivate;
51 class VInspectorAPI_CallBack;
54 /**\class XGUI_Displayer
56 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
58 class XGUI_EXPORT XGUI_Displayer: public QObject
62 /// \enum DisplayMode display mode
64 NoMode = -1, ///< Mode is not defined
65 Wireframe, ///< Wireframe display mode
66 Shading ///< Shading display mode
70 /// \param theWorkshop a workshop instance
71 XGUI_Displayer(XGUI_Workshop* theWorkshop);
74 virtual ~XGUI_Displayer();
76 /// Returns the feature visibility state.
77 /// \param theObject an object instance
78 bool isVisible(ObjectPtr theObject) const;
80 /// Display the feature. Obtain the visualized object from the feature.
81 /// \param theObject an object to display
82 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
83 /// \return true if the object visibility state is changed
84 bool display(ObjectPtr theObject, bool theUpdateViewer = true);
86 /// Display the given AIS object.
87 /// This object is not added to the displayer internal map of objects
88 /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in
89 /// order to perform the display with correct flags.
90 /// \param theAIS AIOS object to display
91 /// \param toActivateInSelectionModes boolean value whether the presentation should be
92 /// activated in the current selection modes
93 /// \param theDisplayMode mode how the presentation should be displayed
94 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
95 /// \return true if the object visibility state is changed
96 bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
97 const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true);
99 /// Redisplay the shape if it was displayed
100 /// \param theObject an object instance
101 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
102 /// \return true if the object visibility state is changed
103 bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
105 /// Sends and flushes a signal to redisplay all visualized objects.
106 void redisplayObjects();
108 /// Add presentations to current selection. It unhighlight and deselect the current selection.
109 /// The shape and result components are processed in the values. If the presentation shape is not
110 /// empty, select it, otherwise select the result.
111 /// \param theValues a list of presentation to be selected
112 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
113 void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
114 bool theUpdateViewer = true);
116 /// Unselect all objects
117 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
118 /// \param theUpdateViewer the parameter to update viewer
119 void clearSelected(const bool theUpdateViewer = true);
121 /// Erase the feature and a shape.
122 /// \param theObject an object instance
123 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
124 /// \return true if the object visibility state is changed
125 bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
127 /// Erase the given AIS object displayed by corresponded display method
128 /// \param theAIS instance of AIS object
129 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
130 /// \return true if the object visibility state is changed
131 bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
133 /// Erase all presentations
134 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
135 /// \return true if the object visibility state is changed
136 bool eraseAll(const bool theUpdateViewer = true);
138 /// Remove default selection filters of the module from the current viewer
139 /// \param theAddFilterOnly if is not 'true' it will deactivate all fiters in viewer
140 void deactivateSelectionFilters(const bool theAddFilterOnly = true);
142 /// \brief Add selection filter
143 /// \param theFilter a filter instance
144 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
146 /// \brief Remove selection filter
147 /// \param theFilter a filter instance
148 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
150 /// Returns true if the selection filter is set to the viewer
151 /// \param theFilter a selection filter
152 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
154 /// Remove all selection filters
155 void removeFilters();
157 /// Sets a flag to the displayer whether the internal viewer can be updated by
158 /// the updateViewer method call. If it is not enabled, this method do nothing.
159 /// This state maintain recurse, if the update is blocked twice or three times, the
160 /// viewer will not be updated until it is unblocked necessary times
161 /// (twice or three in the example).
162 /// \param isEnabled a boolean value
163 bool enableUpdateViewer(const bool isEnabled);
165 /// Returns true if the viewer update is not blocked
166 bool isUpdateEnabled() const;
168 /// Updates the viewer
169 void updateViewer() const;
171 /// Searches the interactive object by feature
172 /// \param theObject the object or presentable feature
173 /// \return theIO an interactive object
174 AISObjectPtr getAISObject(ObjectPtr theObject) const;
176 /// Searches the feature by interactive object
177 /// \param theIO an interactive object
178 /// \return feature the feature or NULL if it not visualized
179 ObjectPtr getObject(const AISObjectPtr& theIO) const;
181 /// Searches the feature by interactive object
182 /// \param theIO an interactive object
183 /// \return corresponded object or NULL if it not found
184 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
186 /// Deactivates the given objects (not allow selection)
187 /// \param theObjList - list of objects which has to be deactivated.
188 /// \param theUpdateViewer update viewer flag
189 void deactivateObjects(const QObjectPtrList& theObjList,
190 const bool theUpdateViewer = true);
192 /// Sets display mode for the given object if this object is displayed
193 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
195 /// Returns current display mode for the given object.
196 /// If object is not dis played then returns NoMode.
197 /// \param theObject object to check
198 DisplayMode displayMode(ObjectPtr theObject) const;
200 /// Displays only objects listed in the list
201 /// \param theList list of objects
202 void showOnly(const QObjectPtrList& theList);
204 /// Returns number of displayed objects
205 int objectsCount() const { return myResult2AISObjectMap.size(); }
207 /// Returns list of displayed objects
208 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
210 /// Returns list of displayed objects
211 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
213 /// Returns true if the given object can be shown in shaded mode
214 /// \param theObject object to check
215 bool canBeShaded(ObjectPtr theObject) const;
217 /// Set color on presentation of an object if it is displayed
218 /// \param theObject an object
219 /// \param theColor a color which has to be set
220 /// \param theUpdateViewer update viewer flag
221 /// \return previously defined color on the object
222 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
224 /// Displays/erases thrihedron in current modes. It will be activated or deactivated
225 /// depending on the trihedron visible state and displayer active trihedron state
226 void displayTrihedron(bool theToDisplay) const;
229 void setCallBack(const Handle(VInspectorAPI_CallBack)& theCallBack)
230 { myVCallBack = theCallBack; }
231 Handle(VInspectorAPI_CallBack) getCallBack() const { return myVCallBack; }
234 /// Return true if the object is visible. If the object is feature, it returns true
235 /// if all results of the feature are shown
236 /// \param theDisplayer a displayer
237 /// \param theObject an object
238 /// \return a boolean value
239 static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
242 /// Signal on object display
243 /// \param theObject a data object
244 /// \param theAIS a presentation object
245 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
247 /// Signal on before object erase
248 /// \param theObject a data object
249 /// \param theAIS a presentation object
250 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
253 /// Returns currently installed AIS_InteractiveContext
254 Handle(AIS_InteractiveContext) AISContext() const;
256 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
257 /// The context should have only this filter inside. Other filters should be add to the filter
258 Handle(SelectMgr_AndFilter) GetFilter();
260 /// Display the feature and a shape. This shape would be associated to the given feature
261 /// \param theObject an object instance
262 /// \param theAIS AIS presentation
263 /// \param isShading flag to show in shading mode
264 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
265 /// \return true if the object visibility state is changed
266 bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
267 bool theUpdateViewer = true);
270 /// Update the object presentable properties such as color, lines width and other
271 /// If the object is result with the color attribute value set, it is used,
272 /// otherwise the customize is applyed to the object's feature if it is a custom prs
273 /// \param theObject an object instance
274 /// \return the true state if there is changes and the presentation is customized
275 bool customizeObject(ObjectPtr theObject);
277 /// Append the objects in the internal map. Checks whether the map already contains the object
278 /// \param theObject an object to display
279 /// \param theAIS AIOS object to display
280 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
283 /// Returns an information about alredy displayed objects
284 /// \return a string representation
285 std::string getResult2AISObjectMapInfo() const;
288 /// Returns container of visible presentations for the object. For a feature object,
289 /// the feature results are processed also. The presentations map is not cleared inside.
290 /// \param theObject a feature or result
291 /// \param thePresentations result map of presentations
292 void getPresentations(const ObjectPtr& theObject,
293 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations);
295 /// Sets the shapes selected in the context. It contains logic of the similar method
296 /// in OCCT but improved for performance. The modification is to iterates by a list
297 /// of owners in the context only once.
298 /// \param theContext a viewer context. It has opened local context
299 /// \param theShapesToBeSelected a map of shapes. Owner's shape is searched in the map and the
300 /// owner is selected if it is found there.
301 /// Only first owner is processed(according to OCCT logic)
302 static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
303 const NCollection_DataMap<TopoDS_Shape,
304 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
307 XGUI_SelectionActivate* selectionActivate() const;
310 XGUI_Workshop* myWorkshop; ///< Reference to workshop
312 Handle(VInspectorAPI_CallBack) myVCallBack;
314 Handle(SelectMgr_AndFilter) myAndFilter; ///< A container for selection filters
316 /// A default custom presentation, which is used if the displayed feature is not
317 /// a custom presentation
318 GeomCustomPrsPtr myCustomPrs;
320 /// Definition of a type of map which defines correspondance between objects and presentations
321 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
322 ResultToAISMap myResult2AISObjectMap; ///< A map of displayed objects
324 /// Number of blocking of the viewer update. The viewer is updated only if it is zero
325 int myViewerBlockedRecursiveCount;
327 bool myIsFirstAISContextUse; ///< Flag: first asking of AIS context: trihedron activation
328 mutable bool myNeedUpdate; ///< A flag that update was requested but not done