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 if it was displayed
88 * \param theFeature a feature instance
89 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
91 void redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
93 /// Redisplay the shape and activate selection of sub-shapes
94 /// \param theFeature a feature instance
95 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
96 //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
98 /// Display the shape and activate selection of sub-shapes
99 /// \param theFeature a feature instance
100 /// \param theShape a shape
101 /// \param theMode a list of local selection modes
102 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
103 void activateInLocalContext(FeaturePtr theFeature,
104 const std::list<int>& theModes, const bool isUpdateViewer = true);
106 /// Stop the current selection and color the given features to the selection color
107 /// \param theFeatures a list of features to be disabled
108 /// \param theToStop the boolean state whether it it stopped or non stopped
109 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
110 void stopSelection(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
111 const bool isUpdateViewer);
113 /// Set the features are selected
114 /// \param theFeatures a list of features to be selected
115 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
116 void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, const bool isUpdateViewer);
119 * Add presentations which corresponds to the given features to current selection
120 * \param theFeatures a list of features to be selected
121 * isUpdateViewer the parameter whether the viewer should be update immediatelly
123 void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
125 /// Erase the feature and a shape.
126 /// \param theFeature a feature instance
127 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
128 void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
130 /// Erase all presentations
131 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
132 //void EraseAll(const bool isUpdateViewer = true);
134 /// Erase AIS interactive objects, which has an empty feature in the internal map
135 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
136 void eraseDeletedFeatures(const bool isUpdateViewer = true);
138 /// Deactivates selection of sub-shapes
139 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
140 void closeLocalContexts(const bool isUpdateViewer = true);
142 /// Updates the viewer
145 /// Searches the interactive object by feature
146 /// \param theFeature the feature or NULL if it not visualized
147 /// \return theIO an interactive object
148 Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const;
151 /// Searches the feature by interactive object
152 /// \param theIO an interactive object
153 /// \return feature the feature or NULL if it not visualized
154 FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
155 /// Deactivate local selection
156 /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
157 void closeAllContexts(const bool isUpdateViewer);
159 /// Returns currently installed AIS_InteractiveContext
160 Handle(AIS_InteractiveContext) AISContext() const;
163 XGUI_Workshop* myWorkshop;
165 typedef std::map<FeaturePtr, Handle(AIS_InteractiveObject) > FeatureToAISMap;
166 FeatureToAISMap myFeature2AISObjectMap;