1 // File: XGUI_Displayer.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef XGUI_Displayer_H
6 #define XGUI_Displayer_H
9 #include <ModuleBase_Definitions.h>
12 #include <boost/shared_ptr.hpp>
14 #include <GeomAPI_AISObject.h>
16 #include <TopoDS_Shape.hxx>
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <NCollection_List.hxx>
21 #include <ModelAPI_Feature.h>
23 #include <XGUI_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
41 /// \param theViewer the viewer
42 XGUI_Displayer(XGUI_Workshop* theWorkshop);
44 virtual ~XGUI_Displayer();
46 /// Set AIS_InteractiveContext object in case if it was changed
47 /// or can not be initialized in constructor
48 void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
50 /// Returns the feature visibility state.
51 /// \param theFeature a feature instance
52 bool isVisible(FeaturePtr theFeature);
54 /// Display the feature. Obtain the visualized object from the feature.
55 /// \param theFeature a feature instance
56 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
57 /// Returns true if the Feature succesfully displayed
58 bool display(FeaturePtr theFeature, bool isUpdateViewer = true);
60 /// Display the feature and a shape. This shape would be associated to the given feature
61 /// \param theFeature a feature instance
62 /// \param theAIS AIS presentation
63 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
64 /// Returns true if the Feature succesfully displayed
65 bool display(FeaturePtr theFeature, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
67 /// Returns a list of viewer selected presentations
68 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
69 /// \return list of presentations
70 std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
73 * Returns list of features currently selected in 3d viewer
75 QFeatureList selectedFeatures() const;
77 /// Returns a list of viewer highlited presentations
78 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
79 /// \return list of presentations
80 std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
82 /// Display the shape and activate selection of sub-shapes
83 /// \param theFeature a feature instance
84 /// \param theAIS an AIS object
85 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
86 /// \returns true if the presentation is created
87 bool redisplay(FeaturePtr theFeature,
88 boost::shared_ptr<GeomAPI_AISObject> theAIS,
89 const bool isUpdateViewer = true);
91 /** Redisplay the shape if it was displayed
92 * \param theFeature a feature instance
93 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 bool redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
97 /// Redisplay the shape and activate selection of sub-shapes
98 /// \param theFeature a feature instance
99 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
100 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
102 /// Display the shape and activate selection of sub-shapes
103 /// \param theFeature a feature instance
104 /// \param theShape a shape
105 /// \param theMode a list of local selection modes
106 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
107 void activateInLocalContext(FeaturePtr theFeature,
108 const std::list<int>& theModes, const bool isUpdateViewer = true);
110 /// Stop the current selection and color the given features to the selection color
111 /// \param theFeatures a list of features to be disabled
112 /// \param theToStop the boolean state whether it it stopped or non stopped
113 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
114 void stopSelection(const QFeatureList& theFeatures, const bool isStop,
115 const bool isUpdateViewer);
118 * Add presentations which corresponds to the given features to current selection
119 * \param theFeatures a list of features to be selected
120 * isUpdateViewer the parameter whether the viewer should be update immediatelly
122 void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
124 /// Erase the feature and a shape.
125 /// \param theFeature a feature instance
126 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
127 void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
129 /// Erase all presentations
130 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
131 //void EraseAll(const bool isUpdateViewer = true);
133 /// Erase AIS interactive objects, which has an empty feature in the internal map
134 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
135 void eraseDeletedFeatures(const bool isUpdateViewer = true);
137 /// Deactivates selection of sub-shapes
138 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
139 void closeLocalContexts(const bool isUpdateViewer = true);
141 /// Updates the viewer
144 /// Searches the interactive object by feature
145 /// \param theFeature the feature or NULL if it not visualized
146 /// \return theIO an interactive object
147 boost::shared_ptr<GeomAPI_AISObject> getAISObject(FeaturePtr theFeature) const;
150 /// Searches the feature by interactive object
151 /// \param theIO an interactive object
152 /// \return feature the feature or NULL if it not visualized
153 FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
154 /// Deactivate local selection
155 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
156 void closeAllContexts(const bool isUpdateViewer);
158 /// Returns currently installed AIS_InteractiveContext
159 Handle(AIS_InteractiveContext) AISContext() const;
162 XGUI_Workshop* myWorkshop;
164 typedef std::map<FeaturePtr, boost::shared_ptr<GeomAPI_AISObject> > FeatureToAISMap;
165 FeatureToAISMap myFeature2AISObjectMap;