1 // File: XGUI_Displayer.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef XGUI_Displayer_H
6 #define XGUI_Displayer_H
10 #include <GeomAPI_AISObject.h>
11 #include <TopoDS_Shape.hxx>
12 #include <AIS_InteractiveObject.hxx>
13 #include <AIS_InteractiveContext.hxx>
14 #include <NCollection_List.hxx>
16 #include <ModelAPI_Result.h>
18 #include <ModuleBase_Definitions.h>
19 #include <ModuleBase_ViewerPrs.h>
25 class ModelAPI_Feature;
28 /**\class XGUI_Displayer
30 * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
32 class XGUI_EXPORT XGUI_Displayer
35 enum DisplayMode { NoMode = -1, Wireframe, Shading };
38 /// \param theViewer the viewer
39 XGUI_Displayer(XGUI_Workshop* theWorkshop);
41 virtual ~XGUI_Displayer();
43 /// Returns the feature visibility state.
44 /// \param theFeature a feature instance
45 bool isVisible(ObjectPtr theObject) const;
47 /// Display the feature. Obtain the visualized object from the feature.
48 /// \param theFeature a feature instance
49 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
50 /// Returns true if the Feature succesfully displayed
51 void display(ObjectPtr theObject, bool isUpdateViewer = true);
53 /// Display the given AIS object. To hide this object use corresponde erase method
54 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
56 /// Stop the current selection and color the given features to the selection color
57 /// \param theFeatures a list of features to be disabled
58 /// \param theToStop the boolean state whether it it stopped or non stopped
59 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
60 void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
61 const bool isUpdateViewer);
64 * Add presentations which corresponds to the given features to current selection
65 * \param theFeatures a list of features to be selected
66 * isUpdateViewer the parameter whether the viewer should be update immediatelly
68 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
71 /// Un select all objects
74 /// Erase the feature and a shape.
75 /// \param theFeature a feature instance
76 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
77 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
79 /// Erase the given AIS object displayed by corresponded display method
80 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
82 /// Erase all presentations
83 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84 void eraseAll(const bool isUpdateViewer = true);
86 /// Erase AIS interactive objects, which has an empty feature in the internal map
87 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
88 void eraseDeletedResults(const bool isUpdateViewer = true);
90 /// Opens local context. Does nothing if it is already opened.
91 void openLocalContext();
93 /// Deactivates selection of sub-shapes
94 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95 void closeLocalContexts(const bool isUpdateViewer = true);
98 * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
99 * It doesn't manages a local context
100 * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
102 void setSelectionModes(const QIntList& theModes);
104 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
106 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
108 void removeFilters();
110 /// Updates the viewer
113 /// Searches the interactive object by feature
114 /// \param theFeature the feature or NULL if it not visualized
115 /// \return theIO an interactive object
116 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
118 /// Searches the feature by interactive object
119 /// \param theIO an interactive object
120 /// \return feature the feature or NULL if it not visualized
121 ObjectPtr getObject(const AISObjectPtr& theIO) const;
122 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
124 /// Deactivates the given object (not allow selection)
125 void deactivate(ObjectPtr theFeature);
127 /// Activates the given object (it can be selected)
128 /// \param theModes - modes on which it has to be activated (can be empty)
129 void activate(ObjectPtr theFeature, const QIntList& theModes);
131 /// Activates the given object with default modes
132 void activate(ObjectPtr theFeature);
134 /// Returns true if the given object can be selected
135 bool isActive(ObjectPtr theObject) const;
137 /// Activates in local context displayed outside of the context.
138 /// \param theModes - modes on which it has to be activated (can be empty)
139 void activateObjectsOutOfContext(const QIntList& theModes);
141 /// Activates in local context displayed outside of the context.
142 void deactivateObjectsOutOfContext();
144 /// Sets display mode for the given object if this object is displayed
145 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
147 /// Returns current display mode for the given object.
148 /// If object is not displayed then returns NoMode.
149 DisplayMode displayMode(ObjectPtr theObject) const;
152 int objectsCount() const { return myResult2AISObjectMap.size(); }
155 /// Returns currently installed AIS_InteractiveContext
156 Handle(AIS_InteractiveContext) AISContext() const;
158 /// Display the feature and a shape. This shape would be associated to the given feature
159 /// \param theFeature a feature instance
160 /// \param theAIS AIS presentation
161 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
162 /// Returns true if the Feature succesfully displayed
163 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
164 bool isUpdateViewer = true);
166 /// Display the shape and activate selection of sub-shapes
167 /// \param theFeature a feature instance
168 /// \param theAIS an AIS object
169 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
170 /// \returns true if the presentation is created
171 //bool redisplay(ObjectPtr theObject,
172 // AISObjectPtr theAIS,
173 // const bool isUpdateViewer = true);
175 /** Redisplay the shape if it was displayed
176 * \param theFeature a feature instance
177 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
179 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
182 XGUI_Workshop* myWorkshop;
184 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
185 ResultToAISMap myResult2AISObjectMap;
187 // A flag of initialization of external objects selection
188 bool myUseExternalObjects;
189 // Selection modes installed for external objects in local context
190 QIntList myActiveSelectionModes;