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, const bool isUpdateViewer = true);
86 /** Redisplay the shape if it was displayed
87 * \param theFeature a feature instance
88 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
90 void redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
92 /// Redisplay the shape and activate selection of sub-shapes
93 /// \param theFeature a feature instance
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
97 /// Display the shape and activate selection of sub-shapes
98 /// \param theFeature a feature instance
99 /// \param theShape a shape
100 /// \param theMode a list of local selection modes
101 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102 void activateInLocalContext(FeaturePtr theFeature,
103 const std::list<int>& theModes, const bool isUpdateViewer = true);
105 /// Stop the current selection and color the given features to the selection color
106 /// \param theFeatures a list of features to be disabled
107 /// \param theToStop the boolean state whether it it stopped or non stopped
108 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
109 void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
110 const bool isUpdateViewer);
112 /// Set the features are selected
113 /// \param theFeatures a list of features to be selected
114 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
115 void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, 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 Handle(AIS_InteractiveObject) 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, Handle(AIS_InteractiveObject) > FeatureToAISMap;
165 FeatureToAISMap myFeature2AISObjectMap;