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 /// Returns the feature visibility state.
49 /// \param theFeature a feature instance
50 bool isVisible(ObjectPtr theObject) const;
52 /// Display the feature. Obtain the visualized object from the feature.
53 /// \param theFeature a feature instance
54 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
55 /// Returns true if the Feature succesfully displayed
56 void display(ObjectPtr theObject, bool isUpdateViewer = true);
58 /// Display the given AIS object. To hide this object use corresponde erase method
59 void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
61 /// Stop the current selection and color the given features to the selection color
62 /// \param theFeatures a list of features to be disabled
63 /// \param theToStop the boolean state whether it it stopped or non stopped
64 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
65 void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
66 const bool isUpdateViewer);
69 * Add presentations which corresponds to the given features to current selection
70 * \param theFeatures a list of features to be selected
71 * isUpdateViewer the parameter whether the viewer should be update immediatelly
73 void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
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 erase(boost::shared_ptr<GeomAPI_AISObject> 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 void openLocalContext();
93 /// Deactivates selection of sub-shapes
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 void closeLocalContexts(const bool isUpdateViewer = true);
97 /// Updates the viewer
100 /// Searches the interactive object by feature
101 /// \param theFeature the feature or NULL if it not visualized
102 /// \return theIO an interactive object
103 boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
105 /// Searches the feature by interactive object
106 /// \param theIO an interactive object
107 /// \return feature the feature or NULL if it not visualized
108 ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
110 /// Deactivates the given object (not allow selection)
111 void deactivate(ObjectPtr theFeature);
113 /// Activates the given object (it can be selected)
114 void activate(ObjectPtr theFeature);
116 /// Returns true if the given object can be selected
117 bool isActive(ObjectPtr theObject) const;
119 /// Activates in local context displayed outside of the context.
120 /// \param theModes - selection modes to activate
121 /// \param theFilter - filter for selection
122 void activateObjectsOutOfContext(const std::list<int>& theModes,
123 Handle(SelectMgr_Filter) theFilter);
125 void deactivateObjectsOutOfContext();
127 /// Sets display mode for the given object if this object is displayed
128 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
130 /// Returns current display mode for the given object.
131 /// If object is not displayed then returns NoMode.
132 DisplayMode displayMode(ObjectPtr theObject) const;
135 int objectsCount() const { return myResult2AISObjectMap.size(); }
138 /// Deactivate local selection
139 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
140 void closeAllContexts(const bool isUpdateViewer);
142 /// Returns currently installed AIS_InteractiveContext
143 Handle(AIS_InteractiveContext) AISContext() const;
145 /// Display the feature and a shape. This shape would be associated to the given feature
146 /// \param theFeature a feature instance
147 /// \param theAIS AIS presentation
148 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
149 /// Returns true if the Feature succesfully displayed
150 void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
151 bool isUpdateViewer = true);
153 /// Display the shape and activate selection of sub-shapes
154 /// \param theFeature a feature instance
155 /// \param theAIS an AIS object
156 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
157 /// \returns true if the presentation is created
158 //bool redisplay(ObjectPtr theObject,
159 // boost::shared_ptr<GeomAPI_AISObject> theAIS,
160 // const bool isUpdateViewer = true);
162 /** Redisplay the shape if it was displayed
163 * \param theFeature a feature instance
164 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
166 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
169 XGUI_Workshop* myWorkshop;
171 typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
172 ResultToAISMap myResult2AISObjectMap;