1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_Displayer.h
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef XGUI_Displayer_H
8 #define XGUI_Displayer_H
12 #include <GeomAPI_AISObject.h>
13 #include <TopoDS_Shape.hxx>
14 #include <AIS_InteractiveObject.hxx>
15 #include <AIS_InteractiveContext.hxx>
16 #include <NCollection_List.hxx>
18 #include <ModelAPI_Result.h>
20 #include <ModuleBase_Definitions.h>
21 #include <ModuleBase_ViewerPrs.h>
23 #include <SelectMgr_AndFilter.hxx>
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
38 enum DisplayMode { NoMode = -1, Wireframe, Shading };
41 /// \param theViewer the viewer
42 XGUI_Displayer(XGUI_Workshop* theWorkshop);
44 virtual ~XGUI_Displayer();
46 /// Returns the feature visibility state.
47 /// \param theFeature a feature instance
48 bool isVisible(ObjectPtr theObject) const;
50 /// Display the feature. Obtain the visualized object from the feature.
51 /// \param theFeature a feature instance
52 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
53 /// Returns true if the Feature succesfully displayed
54 void display(ObjectPtr theObject, bool isUpdateViewer = true);
56 /// Display the given AIS object. To hide this object use corresponde erase method
57 void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
60 * Add presentations which corresponds to the given features to current selection
61 * \param theFeatures a list of features to be selected
62 * isUpdateViewer the parameter whether the viewer should be update immediatelly
64 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
67 /// Un select all objects
70 /// Erase the feature and a shape.
71 /// \param theFeature a feature instance
72 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
73 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
75 /// Erase the given AIS object displayed by corresponded display method
76 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
78 /// Erase all presentations
79 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80 void eraseAll(const bool isUpdateViewer = true);
82 /// Deactivates selection of sub-shapes
83 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84 void closeLocalContexts(const bool isUpdateViewer = true);
86 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
88 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
92 /// Updates the viewer
95 /// Searches the interactive object by feature
96 /// \param theFeature the object or presentable feature
97 /// \return theIO an interactive object
98 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
100 /// Searches the feature by interactive object
101 /// \param theIO an interactive object
102 /// \return feature the feature or NULL if it not visualized
103 ObjectPtr getObject(const AISObjectPtr& theIO) const;
104 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
106 /// Deactivates the given object (not allow selection)
107 void deactivate(ObjectPtr theFeature);
109 /// Activates the given object (it can be selected)
110 /// \param theModes - modes on which it has to be activated (can be empty)
111 void activate(ObjectPtr theFeature, const QIntList& theModes);
113 /// Returns the modes of activation
114 /// \param theFeature the feature or NULL if it not visualized
115 /// \param theModes - modes on which it is activated (can be empty)
116 void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
118 /// Activates the given object with default modes
119 void activate(ObjectPtr theFeature);
121 /// Returns true if the given object can be selected
122 bool isActive(ObjectPtr theObject) const;
124 /// Activates in local context displayed outside of the context.
125 /// \param theModes - modes on which it has to be activated (can be empty)
126 void activateObjects(const QIntList& theModes);
128 /// Activates in local context displayed outside of the context.
129 void deactivateObjects();
131 /// Sets display mode for the given object if this object is displayed
132 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
134 /// Returns current display mode for the given object.
135 /// If object is not dis played then returns NoMode.
136 DisplayMode displayMode(ObjectPtr theObject) const;
139 /// Displays only objects listed in the list
140 void showOnly(const QObjectPtrList& theList);
142 /// Returns number of displayed objects
143 int objectsCount() const { return myResult2AISObjectMap.size(); }
145 bool canBeShaded(ObjectPtr theObject) const;
148 /// Returns currently installed AIS_InteractiveContext
149 Handle(AIS_InteractiveContext) AISContext() const;
151 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
152 /// The context should have only this filter inside. Other filters should be add to the filter
153 Handle(SelectMgr_AndFilter) GetFilter();
155 /// Display the feature and a shape. This shape would be associated to the given feature
156 /// \param theFeature a feature instance
157 /// \param theAIS AIS presentation
158 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
159 /// Returns true if the Feature succesfully displayed
160 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
161 bool isUpdateViewer = true);
163 /// Display the shape and activate selection of sub-shapes
164 /// \param theFeature a feature instance
165 /// \param theAIS an AIS object
166 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
167 /// \returns true if the presentation is created
168 //bool redisplay(ObjectPtr theObject,
169 // AISObjectPtr theAIS,
170 // const bool isUpdateViewer = true);
172 /** Redisplay the shape if it was displayed
173 * \param theFeature a feature instance
174 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
176 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
178 /// Opens local context. Does nothing if it is already opened.
179 void openLocalContext();
182 XGUI_Workshop* myWorkshop;
184 Handle(SelectMgr_AndFilter) myAndFilter;
186 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
187 ResultToAISMap myResult2AISObjectMap;
189 // A flag of initialization of external objects selection
190 //bool myUseExternalObjects;
191 // Selection modes installed for external objects in local context
192 QIntList myActiveSelectionModes;