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 /// Redisplay the shape and activate selection of sub-shapes
62 /// \param theFeature a feature instance
63 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
64 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
66 /// Display the shape and activate selection of sub-shapes
67 /// \param theFeature a feature instance
68 /// \param theShape a shape
69 /// \param theMode a list of local selection modes
70 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
71 void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
72 const bool isUpdateViewer = true);
74 /// Stop the current selection and color the given features to the selection color
75 /// \param theFeatures a list of features to be disabled
76 /// \param theToStop the boolean state whether it it stopped or non stopped
77 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
78 void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
79 const bool isUpdateViewer);
82 * Add presentations which corresponds to the given features to current selection
83 * \param theFeatures a list of features to be selected
84 * isUpdateViewer the parameter whether the viewer should be update immediatelly
86 void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
88 /// Erase the feature and a shape.
89 /// \param theFeature a feature instance
90 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
91 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
93 /// Erase the given AIS object displayed by corresponded display method
94 void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
96 /// Erase all presentations
97 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98 void eraseAll(const bool isUpdateViewer = true);
100 /// Erase AIS interactive objects, which has an empty feature in the internal map
101 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102 void eraseDeletedResults(const bool isUpdateViewer = true);
104 void openLocalContext();
106 /// Deactivates selection of sub-shapes
107 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
108 void closeLocalContexts(const bool isUpdateViewer = true);
110 /// Updates the viewer
113 /// Searches the interactive object by feature
114 /// \param theFeature the feature or NULL if it not visualized
115 /// \return theIO an interactive object
116 boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
118 /// Searches the feature by interactive object
119 /// \param theIO an interactive object
120 /// \return feature the feature or NULL if it not visualized
121 ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
123 /// Deactivates the given object (not allow selection)
124 void deactivate(ObjectPtr theFeature);
126 /// Activates the given object (it can be selected)
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 - selection modes to activate
134 /// \param theFilter - filter for selection
135 void activateObjectsOutOfContext(const std::list<int>& theModes,
136 Handle(SelectMgr_Filter) theFilter);
138 void deactivateObjectsOutOfContext();
140 /// Sets display mode for the given object if this object is displayed
141 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
143 /// Returns current display mode for the given object.
144 /// If object is not displayed then returns NoMode.
145 DisplayMode displayMode(ObjectPtr theObject) const;
148 int objectsCount() const { return myResult2AISObjectMap.size(); }
151 /// Deactivate local selection
152 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
153 void closeAllContexts(const bool isUpdateViewer);
155 /// Returns currently installed AIS_InteractiveContext
156 Handle(AIS_InteractiveContext) AISContext() const;
158 /// Display the feature and a shape. This shape would be associated to the given feature
159 /// \param theFeature a feature instance
160 /// \param theAIS AIS presentation
161 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
162 /// Returns true if the Feature succesfully displayed
163 void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
164 bool isUpdateViewer = true);
166 /// Display the shape and activate selection of sub-shapes
167 /// \param theFeature a feature instance
168 /// \param theAIS an AIS object
169 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
170 /// \returns true if the presentation is created
171 //bool redisplay(ObjectPtr theObject,
172 // boost::shared_ptr<GeomAPI_AISObject> theAIS,
173 // const bool isUpdateViewer = true);
175 /** Redisplay the shape if it was displayed
176 * \param theFeature a feature instance
177 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
179 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
182 XGUI_Workshop* myWorkshop;
184 typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
185 ResultToAISMap myResult2AISObjectMap;