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 /// Updates the viewer
111 /// Searches the interactive object by feature
112 /// \param theFeature the feature or NULL if it not visualized
113 /// \return theIO an interactive object
114 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
116 /// Searches the feature by interactive object
117 /// \param theIO an interactive object
118 /// \return feature the feature or NULL if it not visualized
119 ObjectPtr getObject(const AISObjectPtr& theIO) const;
120 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
122 /// Deactivates the given object (not allow selection)
123 void deactivate(ObjectPtr theFeature);
125 /// Activates the given object (it can be selected)
126 /// \param theModes - modes on which it has to be activated (can be empty)
127 void activate(ObjectPtr theFeature, const QIntList& theModes);
129 /// Activates the given object with default modes
130 void activate(ObjectPtr theFeature);
132 /// Returns true if the given object can be selected
133 bool isActive(ObjectPtr theObject) const;
135 /// Activates in local context displayed outside of the context.
136 /// \param theModes - modes on which it has to be activated (can be empty)
137 void activateObjectsOutOfContext(const QIntList& theModes);
139 /// Activates in local context displayed outside of the context.
140 void deactivateObjectsOutOfContext();
142 /// Sets display mode for the given object if this object is displayed
143 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
145 /// Returns current display mode for the given object.
146 /// If object is not displayed then returns NoMode.
147 DisplayMode displayMode(ObjectPtr theObject) const;
150 int objectsCount() const { return myResult2AISObjectMap.size(); }
153 /// Returns currently installed AIS_InteractiveContext
154 Handle(AIS_InteractiveContext) AISContext() const;
156 /// Display the feature and a shape. This shape would be associated to the given feature
157 /// \param theFeature a feature instance
158 /// \param theAIS AIS presentation
159 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
160 /// Returns true if the Feature succesfully displayed
161 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
162 bool isUpdateViewer = true);
164 /// Display the shape and activate selection of sub-shapes
165 /// \param theFeature a feature instance
166 /// \param theAIS an AIS object
167 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
168 /// \returns true if the presentation is created
169 //bool redisplay(ObjectPtr theObject,
170 // AISObjectPtr theAIS,
171 // const bool isUpdateViewer = true);
173 /** Redisplay the shape if it was displayed
174 * \param theFeature a feature instance
175 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
177 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
180 XGUI_Workshop* myWorkshop;
182 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
183 ResultToAISMap myResult2AISObjectMap;
185 // A flag of initialization of external objects selection
186 bool myUseExternalObjects;
187 // Selection modes installed for external objects in local context
188 QIntList myActiveSelectionModes;