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>
26 class ModelAPI_Feature;
29 /**\class XGUI_Displayer
31 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
33 class XGUI_EXPORT XGUI_Displayer
36 enum DisplayMode { NoMode = -1, Wireframe, Shading };
39 /// \param theViewer the viewer
40 XGUI_Displayer(XGUI_Workshop* theWorkshop);
42 virtual ~XGUI_Displayer();
44 /// Returns the feature visibility state.
45 /// \param theFeature a feature instance
46 bool isVisible(ObjectPtr theObject) const;
48 /// Display the feature. Obtain the visualized object from the feature.
49 /// \param theFeature a feature instance
50 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
51 /// Returns true if the Feature succesfully displayed
52 void display(ObjectPtr theObject, bool isUpdateViewer = true);
54 /// Display the given AIS object. To hide this object use corresponde erase method
55 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
57 /// Stop the current selection and color the given features to the selection color
58 /// \param theFeatures a list of features to be disabled
59 /// \param theToStop the boolean state whether it it stopped or non stopped
60 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
61 void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
62 const bool isUpdateViewer);
65 * Add presentations which corresponds to the given features to current selection
66 * \param theFeatures a list of features to be selected
67 * isUpdateViewer the parameter whether the viewer should be update immediatelly
69 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
72 /// Un select all objects
75 /// Erase the feature and a shape.
76 /// \param theFeature a feature instance
77 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
78 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
80 /// Erase the given AIS object displayed by corresponded display method
81 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
83 /// Erase all presentations
84 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
85 void eraseAll(const bool isUpdateViewer = true);
87 /// Erase AIS interactive objects, which has an empty feature in the internal map
88 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89 void eraseDeletedResults(const bool isUpdateViewer = true);
91 /// Opens local context. Does nothing if it is already opened.
92 void openLocalContext();
94 /// Deactivates selection of sub-shapes
95 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
96 void closeLocalContexts(const bool isUpdateViewer = true);
98 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
100 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
102 void removeFilters();
104 /// Updates the viewer
107 /// Searches the interactive object by feature
108 /// \param theFeature the feature or NULL if it not visualized
109 /// \return theIO an interactive object
110 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
112 /// Searches the feature by interactive object
113 /// \param theIO an interactive object
114 /// \return feature the feature or NULL if it not visualized
115 ObjectPtr getObject(const AISObjectPtr& theIO) const;
116 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
118 /// Deactivates the given object (not allow selection)
119 void deactivate(ObjectPtr theFeature);
121 /// Activates the given object (it can be selected)
122 /// \param theModes - modes on which it has to be activated (can be empty)
123 void activate(ObjectPtr theFeature, const QIntList& theModes);
125 /// Activates the given object with default modes
126 void activate(ObjectPtr theFeature);
128 /// Returns true if the given object can be selected
129 bool isActive(ObjectPtr theObject) const;
131 /// Activates in local context displayed outside of the context.
132 /// \param theModes - modes on which it has to be activated (can be empty)
133 void activateObjects(const QIntList& theModes);
135 /// Activates in local context displayed outside of the context.
136 void deactivateObjects();
138 /// Sets display mode for the given object if this object is displayed
139 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
141 /// Returns current display mode for the given object.
142 /// If object is not dis played then returns NoMode.
143 DisplayMode displayMode(ObjectPtr theObject) const;
146 /// Displays only objects listed in the list
147 void showOnly(const QObjectPtrList& theList);
149 /// Returns number of displayed objects
150 int objectsCount() const { return myResult2AISObjectMap.size(); }
153 /// Returns currently installed AIS_InteractiveContext
154 Handle(AIS_InteractiveContext) AISContext() const;
156 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
157 /// The context should have only this filter inside. Other filters should be add to the filter
158 Handle(SelectMgr_AndFilter) GetFilter();
160 /// Display the feature and a shape. This shape would be associated to the given feature
161 /// \param theFeature a feature instance
162 /// \param theAIS AIS presentation
163 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
164 /// Returns true if the Feature succesfully displayed
165 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
166 bool isUpdateViewer = true);
168 /// Display the shape and activate selection of sub-shapes
169 /// \param theFeature a feature instance
170 /// \param theAIS an AIS object
171 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
172 /// \returns true if the presentation is created
173 //bool redisplay(ObjectPtr theObject,
174 // AISObjectPtr theAIS,
175 // const bool isUpdateViewer = true);
177 /** Redisplay the shape if it was displayed
178 * \param theFeature a feature instance
179 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
181 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
184 XGUI_Workshop* myWorkshop;
186 Handle(SelectMgr_AndFilter) myAndFilter;
188 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
189 ResultToAISMap myResult2AISObjectMap;
191 // A flag of initialization of external objects selection
192 bool myUseExternalObjects;
193 // Selection modes installed for external objects in local context
194 QIntList myActiveSelectionModes;