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 "XGUI_Constants.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 void display(FeaturePtr theFeature, bool isUpdateViewer = true);
59 /// Display the feature and a shape. This shape would be associated to the given feature
60 /// \param theFeature a feature instance
61 /// \param theAIS AIS presentation
62 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
63 void display(FeaturePtr theFeature, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
65 /// Returns a list of viewer selected presentations
66 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
67 /// \return list of presentations
68 std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
71 * Returns list of features currently selected in 3d viewer
73 QFeatureList selectedFeatures() const;
75 /// Returns a list of viewer highlited presentations
76 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
77 /// \return list of presentations
78 std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
80 /// Display the shape and activate selection of sub-shapes
81 /// \param theFeature a feature instance
82 /// \param theAIS an AIS object
83 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84 /// \returns true if the presentation is created
85 bool redisplay(FeaturePtr theFeature,
86 boost::shared_ptr<GeomAPI_AISObject> theAIS,
87 const bool isUpdateViewer = true);
89 /** Redisplay the shape if it was displayed
90 * \param theFeature a feature instance
91 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
93 void redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
95 /// Redisplay the shape and activate selection of sub-shapes
96 /// \param theFeature a feature instance
97 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
100 /// Display the shape and activate selection of sub-shapes
101 /// \param theFeature a feature instance
102 /// \param theShape a shape
103 /// \param theMode a list of local selection modes
104 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
105 void activateInLocalContext(FeaturePtr theFeature,
106 const std::list<int>& theModes, const bool isUpdateViewer = true);
108 /// Stop the current selection and color the given features to the selection color
109 /// \param theFeatures a list of features to be disabled
110 /// \param theToStop the boolean state whether it it stopped or non stopped
111 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
112 void stopSelection(const QFeatureList& theFeatures, const bool isStop,
113 const bool isUpdateViewer);
116 * Add presentations which corresponds to the given features to current selection
117 * \param theFeatures a list of features to be selected
118 * isUpdateViewer the parameter whether the viewer should be update immediatelly
120 void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
122 /// Erase the feature and a shape.
123 /// \param theFeature a feature instance
124 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
125 void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
127 /// Erase all presentations
128 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
129 //void EraseAll(const bool isUpdateViewer = true);
131 /// Erase AIS interactive objects, which has an empty feature in the internal map
132 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
133 void eraseDeletedFeatures(const bool isUpdateViewer = true);
135 /// Deactivates selection of sub-shapes
136 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
137 void closeLocalContexts(const bool isUpdateViewer = true);
139 /// Updates the viewer
142 /// Searches the interactive object by feature
143 /// \param theFeature the feature or NULL if it not visualized
144 /// \return theIO an interactive object
145 boost::shared_ptr<GeomAPI_AISObject> getAISObject(FeaturePtr theFeature) const;
148 /// Searches the feature by interactive object
149 /// \param theIO an interactive object
150 /// \return feature the feature or NULL if it not visualized
151 FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
152 /// Deactivate local selection
153 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
154 void closeAllContexts(const bool isUpdateViewer);
156 /// Returns currently installed AIS_InteractiveContext
157 Handle(AIS_InteractiveContext) AISContext() const;
160 XGUI_Workshop* myWorkshop;
162 typedef std::map<FeaturePtr, boost::shared_ptr<GeomAPI_AISObject> > FeatureToAISMap;
163 FeatureToAISMap myFeature2AISObjectMap;