1 // File: XGUI_Displayer.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef XGUI_Displayer_H
6 #define XGUI_Displayer_H
11 #include <boost/shared_ptr.hpp>
13 #include <GeomAPI_AISObject.h>
15 #include <TopoDS_Shape.hxx>
16 #include <AIS_InteractiveObject.hxx>
17 #include <AIS_InteractiveContext.hxx>
18 #include <NCollection_List.hxx>
20 #include <ModelAPI_Result.h>
22 #include <ModuleBase_Definitions.h>
23 #include <ModuleBase_ViewerPrs.h>
30 class ModelAPI_Feature;
33 /**\class XGUI_Displayer
35 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
37 class XGUI_EXPORT XGUI_Displayer
40 enum DisplayMode { NoMode = -1, Wireframe, Shading };
43 /// \param theViewer the viewer
44 XGUI_Displayer(XGUI_Workshop* theWorkshop);
46 virtual ~XGUI_Displayer();
48 /// Set AIS_InteractiveContext object in case if it was changed
49 /// or can not be initialized in constructor
50 void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
52 /// Returns the feature visibility state.
53 /// \param theFeature a feature instance
54 bool isVisible(ObjectPtr theObject) const;
56 /// Display the feature. Obtain the visualized object from the feature.
57 /// \param theFeature a feature instance
58 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
59 /// Returns true if the Feature succesfully displayed
60 void display(ObjectPtr theObject, bool isUpdateViewer = true);
62 /// Display the given AIS object. To hide this object use corresponde erase method
63 void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
65 /// Redisplay the shape and activate selection of sub-shapes
66 /// \param theFeature a feature instance
67 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
68 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
70 /// Display the shape and activate selection of sub-shapes
71 /// \param theFeature a feature instance
72 /// \param theShape a shape
73 /// \param theMode a list of local selection modes
74 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
75 void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
76 const bool isUpdateViewer = true);
78 /// Stop the current selection and color the given features to the selection color
79 /// \param theFeatures a list of features to be disabled
80 /// \param theToStop the boolean state whether it it stopped or non stopped
81 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
82 void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
83 const bool isUpdateViewer);
86 * Add presentations which corresponds to the given features to current selection
87 * \param theFeatures a list of features to be selected
88 * isUpdateViewer the parameter whether the viewer should be update immediatelly
90 void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
92 /// Erase the feature and a shape.
93 /// \param theFeature a feature instance
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
97 /// Erase the given AIS object displayed by corresponded display method
98 void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
100 /// Erase all presentations
101 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102 void eraseAll(const bool isUpdateViewer = true);
104 /// Erase AIS interactive objects, which has an empty feature in the internal map
105 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
106 void eraseDeletedResults(const bool isUpdateViewer = true);
108 void openLocalContext();
110 /// Deactivates selection of sub-shapes
111 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
112 void closeLocalContexts(const bool isUpdateViewer = true);
114 /// Updates the viewer
117 /// Searches the interactive object by feature
118 /// \param theFeature the feature or NULL if it not visualized
119 /// \return theIO an interactive object
120 boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
122 /// Searches the feature by interactive object
123 /// \param theIO an interactive object
124 /// \return feature the feature or NULL if it not visualized
125 ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
127 void deactivate(ObjectPtr theFeature);
129 void activate(ObjectPtr theFeature);
131 /// Activates in local context displayed outside of the context.
132 /// \param theModes - selection modes to activate
133 /// \param theFilter - filter for selection
134 void activateObjectsOutOfContext(const std::list<int>& theModes,
135 Handle(SelectMgr_Filter) theFilter);
137 void deactivateObjectsOutOfContext();
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 displayed then returns NoMode.
144 DisplayMode displayMode(ObjectPtr theObject) const;
147 int objectsCount() const { return myResult2AISObjectMap.size(); }
150 /// Deactivate local selection
151 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
152 void closeAllContexts(const bool isUpdateViewer);
154 /// Returns currently installed AIS_InteractiveContext
155 Handle(AIS_InteractiveContext) AISContext() const;
157 /// Display the feature and a shape. This shape would be associated to the given feature
158 /// \param theFeature a feature instance
159 /// \param theAIS AIS presentation
160 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
161 /// Returns true if the Feature succesfully displayed
162 void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
163 bool isUpdateViewer = true);
165 /// Display the shape and activate selection of sub-shapes
166 /// \param theFeature a feature instance
167 /// \param theAIS an AIS object
168 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
169 /// \returns true if the presentation is created
170 //bool redisplay(ObjectPtr theObject,
171 // boost::shared_ptr<GeomAPI_AISObject> theAIS,
172 // const bool isUpdateViewer = true);
174 /** Redisplay the shape if it was displayed
175 * \param theFeature a feature instance
176 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
178 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
181 XGUI_Workshop* myWorkshop;
183 typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
184 ResultToAISMap myResult2AISObjectMap;