1 // File: XGUI_Displayer.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef XGUI_Displayer_H
6 #define XGUI_Displayer_H
10 #include <GeomAPI_AISObject.h>
11 #include <TopoDS_Shape.hxx>
12 #include <AIS_InteractiveObject.hxx>
13 #include <AIS_InteractiveContext.hxx>
14 #include <NCollection_List.hxx>
16 #include <ModelAPI_Result.h>
18 #include <ModuleBase_Definitions.h>
19 #include <ModuleBase_ViewerPrs.h>
21 #include <SelectMgr_AndFilter.hxx>
27 class ModelAPI_Feature;
30 /**\class XGUI_Displayer
32 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
34 class XGUI_EXPORT XGUI_Displayer
37 enum DisplayMode { NoMode = -1, Wireframe, Shading };
40 /// \param theViewer the viewer
41 XGUI_Displayer(XGUI_Workshop* theWorkshop);
43 virtual ~XGUI_Displayer();
45 /// Returns the feature visibility state.
46 /// \param theFeature a feature instance
47 bool isVisible(ObjectPtr theObject) const;
49 /// Display the feature. Obtain the visualized object from the feature.
50 /// \param theFeature a feature instance
51 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
52 /// Returns true if the Feature succesfully displayed
53 void display(ObjectPtr theObject, bool isUpdateViewer = true);
55 /// Display the given AIS object. To hide this object use corresponde erase method
56 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
58 /// Stop the current selection and color the given features to the selection color
59 /// \param theFeatures a list of features to be disabled
60 /// \param theToStop the boolean state whether it it stopped or non stopped
61 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
62 void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
63 const bool isUpdateViewer);
66 * Add presentations which corresponds to the given features to current selection
67 * \param theFeatures a list of features to be selected
68 * isUpdateViewer the parameter whether the viewer should be update immediatelly
70 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
73 /// Un select all objects
76 /// Erase the feature and a shape.
77 /// \param theFeature a feature instance
78 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
79 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
81 /// Erase the given AIS object displayed by corresponded display method
82 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
84 /// Erase all presentations
85 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
86 void eraseAll(const bool isUpdateViewer = true);
88 /// Erase AIS interactive objects, which has an empty feature in the internal map
89 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
90 void eraseDeletedResults(const bool isUpdateViewer = true);
92 /// Opens local context. Does nothing if it is already opened.
93 void openLocalContext();
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 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
101 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
103 void removeFilters();
105 /// Updates the viewer
108 /// Searches the interactive object by feature
109 /// \param theFeature the feature or NULL if it not visualized
110 /// \return theIO an interactive object
111 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
113 /// Searches the feature by interactive object
114 /// \param theIO an interactive object
115 /// \return feature the feature or NULL if it not visualized
116 ObjectPtr getObject(const AISObjectPtr& theIO) const;
117 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
119 /// Deactivates the given object (not allow selection)
120 void deactivate(ObjectPtr theFeature);
122 /// Activates the given object (it can be selected)
123 /// \param theModes - modes on which it has to be activated (can be empty)
124 void activate(ObjectPtr theFeature, const QIntList& theModes);
126 /// Activates the given object with default modes
127 void activate(ObjectPtr theFeature);
129 /// Returns true if the given object can be selected
130 bool isActive(ObjectPtr theObject) const;
132 /// Activates in local context displayed outside of the context.
133 /// \param theModes - modes on which it has to be activated (can be empty)
134 void activateObjects(const QIntList& theModes);
136 /// Activates in local context displayed outside of the context.
137 void deactivateObjects();
139 /// Sets display mode for the given object if this object is displayed
140 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
142 /// Returns current display mode for the given object.
143 /// If object is not dis played then returns NoMode.
144 DisplayMode displayMode(ObjectPtr theObject) const;
147 /// Displays only objects listed in the list
148 void showOnly(const QObjectPtrList& theList);
150 /// Returns number of displayed objects
151 int objectsCount() const { return myResult2AISObjectMap.size(); }
154 /// Returns currently installed AIS_InteractiveContext
155 Handle(AIS_InteractiveContext) AISContext() const;
157 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
158 /// The context should have only this filter inside. Other filters should be add to the filter
159 Handle(SelectMgr_AndFilter) GetFilter();
161 /// Display the feature and a shape. This shape would be associated to the given feature
162 /// \param theFeature a feature instance
163 /// \param theAIS AIS presentation
164 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
165 /// Returns true if the Feature succesfully displayed
166 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
167 bool isUpdateViewer = true);
169 /// Display the shape and activate selection of sub-shapes
170 /// \param theFeature a feature instance
171 /// \param theAIS an AIS object
172 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
173 /// \returns true if the presentation is created
174 //bool redisplay(ObjectPtr theObject,
175 // AISObjectPtr theAIS,
176 // const bool isUpdateViewer = true);
178 /** Redisplay the shape if it was displayed
179 * \param theFeature a feature instance
180 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
182 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
185 XGUI_Workshop* myWorkshop;
187 Handle(SelectMgr_AndFilter) myAndFilter;
189 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
190 ResultToAISMap myResult2AISObjectMap;
192 // A flag of initialization of external objects selection
193 bool myUseExternalObjects;
194 // Selection modes installed for external objects in local context
195 QIntList myActiveSelectionModes;