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 <TopoDS_Shape.hxx>
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_InteractiveContext.hxx>
17 #include <NCollection_List.hxx>
19 #include <ModelAPI_Feature.h>
21 #include <XGUI_ViewerPrs.h>
28 class ModelAPI_Feature;
31 /**\class XGUI_Displayer
33 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
35 class XGUI_EXPORT XGUI_Displayer
39 /// \param theViewer the viewer
40 XGUI_Displayer(XGUI_Workshop* theWorkshop);
42 virtual ~XGUI_Displayer();
44 /// Set AIS_InteractiveContext object in case if it was changed
45 /// or can not be initialized in constructor
46 void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
48 /// Returns the feature visibility state.
49 /// \param theFeature a feature instance
50 bool isVisible(FeaturePtr theFeature);
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 void display(FeaturePtr theFeature, bool isUpdateViewer = true);
57 /// Display the feature and a shape. This shape would be associated to the given feature
58 /// \param theFeature a feature instance
59 /// \param theShape a shape
60 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
61 void display(FeaturePtr theFeature, const TopoDS_Shape& theShape, bool isUpdateViewer = true);
63 /// Returns a list of viewer selected presentations
64 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
65 /// \return list of presentations
66 std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
69 * Returns list of features currently selected in 3d viewer
71 QFeatureList selectedFeatures() const;
73 /// Returns a list of viewer highlited presentations
74 /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
75 /// \return list of presentations
76 std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
78 /// Display the shape and activate selection of sub-shapes
79 /// \param theFeature a feature instance
80 /// \param theAIS an AIS object
81 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
82 /// \returns true if the presentation is created
83 bool redisplay(FeaturePtr theFeature,
84 Handle(AIS_InteractiveObject) theAIS,
85 const int theSelectionMode, const bool isUpdateViewer = true);
87 /// Redisplay the shape and activate selection of sub-shapes
88 /// \param theFeature a feature instance
89 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
90 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
92 /// Display the shape and activate selection of sub-shapes
93 /// \param theFeature a feature instance
94 /// \param theShape a shape
95 /// \param theMode a list of local selection modes
96 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
97 void activateInLocalContext(FeaturePtr theFeature,
98 const std::list<int>& theModes, const bool isUpdateViewer = true);
100 /// Stop the current selection and color the given features to the selection color
101 /// \param theFeatures a list of features to be disabled
102 /// \param theToStop the boolean state whether it it stopped or non stopped
103 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
104 void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
105 const bool isUpdateViewer);
107 /// Set the features are selected
108 /// \param theFeatures a list of features to be selected
109 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
110 void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
113 * Add presentations which corresponds to the given features to current selection
114 * \param theFeatures a list of features to be selected
115 * isUpdateViewer the parameter whether the viewer should be update immediatelly
117 void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
119 /// Erase the feature and a shape.
120 /// \param theFeature a feature instance
121 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
122 void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
124 /// Erase all presentations
125 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
126 //void EraseAll(const bool isUpdateViewer = true);
128 /// Erase AIS interactive objects, which has an empty feature in the internal map
129 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
130 void eraseDeletedFeatures(const bool isUpdateViewer = true);
132 /// Deactivates selection of sub-shapes
133 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
134 void closeLocalContexts(const bool isUpdateViewer = true);
136 /// Updates the viewer
139 /// Searches the interactive object by feature
140 /// \param theFeature the feature or NULL if it not visualized
141 /// \return theIO an interactive object
142 Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const;
145 /// Searches the feature by interactive object
146 /// \param theIO an interactive object
147 /// \return feature the feature or NULL if it not visualized
148 FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
149 /// Deactivate local selection
150 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
151 void closeAllContexts(const bool isUpdateViewer);
153 /// Returns currently installed AIS_InteractiveContext
154 Handle(AIS_InteractiveContext) AISContext() const;
157 XGUI_Workshop* myWorkshop;
159 typedef std::map<FeaturePtr, Handle(AIS_InteractiveObject) > FeatureToAISMap;
160 FeatureToAISMap myFeature2AISObjectMap;