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 <TopoDS_Shape.hxx>
28 #include <AIS_InteractiveObject.hxx>
29 #include <AIS_InteractiveContext.hxx>
30 #include <NCollection_Map.hxx>
31 #include <NCollection_DataMap.hxx>
33 #include <ModelAPI_Result.h>
35 #include <ModuleBase_Definitions.h>
37 #include <GeomAPI_ICustomPrs.h>
39 #include <SelectMgr_AndFilter.hxx>
46 class ModuleBase_ViewerPrs;
47 class ModelAPI_Feature;
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 /// Mode is not defined
66 /// Wireframe display mode
68 /// Shading display mode
73 /// \param theWorkshop a workshop instance
74 XGUI_Displayer(XGUI_Workshop* theWorkshop);
77 virtual ~XGUI_Displayer();
79 /// Returns the feature visibility state.
80 /// \param theObject an object instance
81 bool isVisible(ObjectPtr theObject) const;
83 /// Display the feature. Obtain the visualized object from the feature.
84 /// \param theObject an object to display
85 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
86 /// \return true if the object visibility state is changed
87 bool display(ObjectPtr theObject, bool theUpdateViewer = true);
89 /// Display the given AIS object.
90 /// This object is not added to the displayer internal map of objects
91 /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in
92 /// order to perform the display with correct flags.
93 /// \param theAIS AIOS object to display
94 /// \param toActivateInSelectionModes boolean value whether the presentation should be
95 /// activated in the current selection modes
96 /// \param theDisplayMode mode how the presentation should be displayed
97 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
98 /// \return true if the object visibility state is changed
99 bool displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
100 const Standard_Integer theDisplayMode = 0, bool theUpdateViewer = true);
102 /// Redisplay the shape if it was displayed
103 /// \param theObject an object instance
104 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
105 /// \return true if the object visibility state is changed
106 bool redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
108 /// Sends and flushes a signal to redisplay all visualized objects.
109 void redisplayObjects();
111 /// Add presentations to current selection. It unhighlight and deselect the current selection.
112 /// The shape and result components are processed in the values. If the presentation shape is not
113 /// empty, select it, otherwise select the result.
114 /// \param theValues a list of presentation to be selected
115 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
116 void setSelected(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
117 bool theUpdateViewer = true);
119 /// Unselect all objects
120 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
121 /// \param theUpdateViewer the parameter to update viewer
122 void clearSelected(const bool theUpdateViewer = true);
124 /// Erase the feature and a shape.
125 /// \param theObject an object instance
126 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
127 /// \return true if the object visibility state is changed
128 bool erase(ObjectPtr theObject, const bool theUpdateViewer = true);
130 /// Erase the given AIS object displayed by corresponded display method
131 /// \param theAIS instance of AIS object
132 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
133 /// \return true if the object visibility state is changed
134 bool eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
136 /// Erase all presentations
137 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
138 /// \return true if the object visibility state is changed
139 bool eraseAll(const bool theUpdateViewer = true);
141 /// Deactivates selection of sub-shapes
142 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
143 //void closeLocalContexts(const bool theUpdateViewer = true);
145 /// Remove default selection filters of the module from the current viewer
146 void deactivateSelectionFilters();
148 /// \brief Add selection filter
149 /// \param theFilter a filter instance
150 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
152 /// \brief Remove selection filter
153 /// \param theFilter a filter instance
154 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
156 /// Returns true if the selection filter is set to the viewer
157 /// \param theFilter a selection filter
158 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
160 /// Remove all selection filters
161 void removeFilters();
163 /// Sets a flag to the displayer whether the internal viewer can be updated by
164 /// the updateViewer method call. If it is not enabled, this method do nothing.
165 /// This state maintain recurse, if the update is blocked twice or three times, the
166 /// viewer will not be updated until it is unblocked necessary times
167 /// (twice or three in the example).
168 /// \param isEnabled a boolean value
169 bool enableUpdateViewer(const bool isEnabled);
171 /// Returns true if the viewer update is not blocked
172 bool isUpdateEnabled() const;
174 /// Updates the viewer
175 void updateViewer() const;
177 /// Activate interactive context
178 /// \param theIO an interactive object
179 /// \param theMode activation mode
180 /// \param theUpdateViewer update viewer flag
181 void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
182 const bool theUpdateViewer) const;
184 /// Activate interactive context. It is necessary to call ClearOutdatedSelection
185 /// after deactivation
186 /// \param theIO an interactive object
187 /// \param theMode a mode to deactivate. When theMode=-1 then all modes will be deactivated
188 void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
190 /// Searches the interactive object by feature
191 /// \param theObject the object or presentable feature
192 /// \return theIO an interactive object
193 AISObjectPtr getAISObject(ObjectPtr theObject) const;
195 /// Searches the feature by interactive object
196 /// \param theIO an interactive object
197 /// \return feature the feature or NULL if it not visualized
198 ObjectPtr getObject(const AISObjectPtr& theIO) const;
200 /// Searches the feature by interactive object
201 /// \param theIO an interactive object
202 /// \return corresponded object or NULL if it not found
203 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
205 /// Deactivates the given objects (not allow selection)
206 /// \param theObjList - list of objects which has to be deactivated.
207 /// \param theUpdateViewer update viewer flag
208 void deactivateObjects(const QObjectPtrList& theObjList,
209 const bool theUpdateViewer = true);
211 /// Returns the modes of activation
212 /// \param theObject the feature or NULL if it not visualized
213 /// \param theModes - modes on which it is activated (can be empty)
214 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
216 /// Returns true if the given object can be selected
217 /// \param theObject object to check
218 bool isActive(ObjectPtr theObject) const;
220 /// Activates in local context displayed outside of the context.
221 /// \param theModes - modes on which it has to be activated (can be empty)
222 /// \param theObjList - list of objects which has to be activated.
223 /// \param theUpdateViewer an update viewer flag
224 void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
225 const bool theUpdateViewer = true);
227 /// Sets display mode for the given object if this object is displayed
228 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
230 /// Returns current display mode for the given object.
231 /// If object is not dis played then returns NoMode.
232 /// \param theObject object to check
233 DisplayMode displayMode(ObjectPtr theObject) const;
235 /// Displays only objects listed in the list
236 /// \param theList list of objects
237 void showOnly(const QObjectPtrList& theList);
239 /// Returns number of displayed objects
240 int objectsCount() const { return myResult2AISObjectMap.size(); }
242 /// Returns list of displayed objects
243 QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
245 /// Returns list of displayed objects
246 QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
248 /// Returns true if the given object can be shown in shaded mode
249 /// \param theObject object to check
250 bool canBeShaded(ObjectPtr theObject) const;
252 /// Set color on presentation of an object if it is displayed
253 /// \param theObject an object
254 /// \param theColor a color which has to be set
255 /// \param theUpdateViewer update viewer flag
256 /// \return previously defined color on the object
257 QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
259 /// Returns Trihedron object if it is displayed
260 Handle(AIS_InteractiveObject) getTrihedron() const;
262 /// Set trihedron active (used in selection) or non active
263 void activateTrihedron(bool theIsActive);
265 /// Displays/erases thrihedron in current modes. It will be activated or deactivated
266 /// depending on the trihedron visible state and displayer active trihedron state
267 void displayTrihedron(bool theToDisplay) const;
269 /// Returns true if the trihedron should be activated in current selection modes
270 bool isTrihedronActive() const { return myIsTrihedronActive; }
272 /// Returns list of currently active selection modes
273 /// Selection modes will be returned according to TopAbs_ShapeEnum
274 QIntList activeSelectionModes() const;
277 void setCallBack(const Handle(VInspectorAPI_CallBack)& theCallBack)
278 { myVCallBack = theCallBack; }
279 Handle(VInspectorAPI_CallBack) getCallBack() const { return myVCallBack; }
281 /// Converts shape type (TopAbs_ShapeEnum) to selection mode
282 /// \param theShapeType a shape type from TopAbs_ShapeEnum
283 static int getSelectionMode(int theShapeType);
285 /// Return true if the object is visible. If the object is feature, it returns true
286 /// if all results of the feature are shown
287 /// \param theDisplayer a displayer
288 /// \param theObject an object
289 /// \return a boolean value
290 static bool isVisible(XGUI_Displayer* theDisplayer, const ObjectPtr& theObject);
293 /// Signal on object display
294 /// \param theObject a data object
295 /// \param theAIS a presentation object
296 void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
298 /// Signal on before object erase
299 /// \param theObject a data object
300 /// \param theAIS a presentation object
301 void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
304 /// Returns currently installed AIS_InteractiveContext
305 Handle(AIS_InteractiveContext) AISContext() const;
307 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
308 /// The context should have only this filter inside. Other filters should be add to the filter
309 Handle(SelectMgr_AndFilter) GetFilter();
311 /// Display the feature and a shape. This shape would be associated to the given feature
312 /// \param theObject an object instance
313 /// \param theAIS AIS presentation
314 /// \param isShading flag to show in shading mode
315 /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
316 /// \return true if the object visibility state is changed
317 bool display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
318 bool theUpdateViewer = true);
321 /// Activates the interactive object in the local context.
322 /// \param theIO an interactive object
323 /// \param theModes - modes on which it has to be activated (can be empty)
324 /// \return a flag is object activated or not
325 bool activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
326 const bool theUpdateViewer) const;
328 /// Deactivates the given object (not allow selection)
329 /// \param theObject object to deactivate
330 void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
332 /// Find a trihedron in a list of displayed presentations and deactivate it.
333 /// \param theUpdateViewer an update viewer flag
334 void deactivateTrihedron(const bool theUpdateViewer) const;
336 /// Update the object presentable properties such as color, lines width and other
337 /// If the object is result with the color attribute value set, it is used,
338 /// otherwise the customize is applyed to the object's feature if it is a custom prs
339 /// \param theObject an object instance
340 /// \return the true state if there is changes and the presentation is customized
341 bool customizeObject(ObjectPtr theObject);
343 /// Append the objects in the internal map. Checks whether the map already contains the object
344 /// \param theObject an object to display
345 /// \param theAIS AIOS object to display
346 void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
349 /// Returns an information about alredy displayed objects
350 /// \return a string representation
351 std::string getResult2AISObjectMapInfo() const;
354 /// Returns container of visible presentations for the object. For a feature object,
355 /// the feature results are processed also. The presentations map is not cleared inside.
356 /// \param theObject a feature or result
357 /// \param thePresentations result map of presentations
358 void getPresentations(const ObjectPtr& theObject,
359 NCollection_Map<Handle(AIS_InteractiveObject)>& thePresentations);
361 /// Sets the shapes selected in the context. It contains logic of the similar method
362 /// in OCCT but improved for performance. The modification is to iterates by a list
363 /// of owners in the context only once.
364 /// \param theContext a viewer context. It has opened local context
365 /// \param theShapesToBeSelected a map of shapes. Owner's shape is searched in the map and the
366 /// owner is selected if it is found there.
367 /// Only first owner is processed(according to OCCT logic)
368 static void AddOrRemoveSelectedShapes(Handle(AIS_InteractiveContext) theContext,
369 const NCollection_DataMap<TopoDS_Shape,
370 NCollection_Map<Handle(AIS_InteractiveObject)>>& theShapesToBeSelected);
373 /// Reference to workshop
374 XGUI_Workshop* myWorkshop;
376 Handle(VInspectorAPI_CallBack) myVCallBack;
378 /// A container for selection filters
379 Handle(SelectMgr_AndFilter) myAndFilter;
381 /// A default custom presentation, which is used if the displayed feature is not
382 /// a custom presentation
383 GeomCustomPrsPtr myCustomPrs;
385 /// Definition of a type of map which defines correspondance between objects and presentations
386 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
388 /// A map of displayed objects
389 ResultToAISMap myResult2AISObjectMap;
391 /// Selection modes installed for external objects in local context
392 QIntList myActiveSelectionModes;
394 /// Number of blocking of the viewer update. The viewer is updated only if it equals zero
395 int myViewerBlockedRecursiveCount;
397 /// Flag: first asking of AIS context: trihedron activation
398 bool myIsFirstAISContextUse;
400 /// Flag: use trihedgon for selection or not
401 bool myIsTrihedronActive;
403 /// A flag that update was requested but not done
404 mutable bool myNeedUpdate;