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);
59 /// Stop the current selection and color the given features to the selection color
60 /// \param theFeatures a list of features to be disabled
61 /// \param theToStop the boolean state whether it it stopped or non stopped
62 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
63 void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
64 const bool isUpdateViewer);
67 * Add presentations which corresponds to the given features to current selection
68 * \param theFeatures a list of features to be selected
69 * isUpdateViewer the parameter whether the viewer should be update immediatelly
71 void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
74 /// Un select all objects
77 /// Erase the feature and a shape.
78 /// \param theFeature a feature instance
79 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80 void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
82 /// Erase the given AIS object displayed by corresponded display method
83 void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
85 /// Erase all presentations
86 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
87 void eraseAll(const bool isUpdateViewer = true);
89 /// Erase AIS interactive objects, which has an empty feature in the internal map
90 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
91 //void eraseDeletedResults(const bool isUpdateViewer = true);
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);
97 void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
99 void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
101 void removeFilters();
103 /// Updates the viewer
106 /// Searches the interactive object by feature
107 /// \param theFeature the feature or NULL if it not visualized
108 /// \return theIO an interactive object
109 AISObjectPtr getAISObject(ObjectPtr theFeature) const;
111 /// Searches the feature by interactive object
112 /// \param theIO an interactive object
113 /// \return feature the feature or NULL if it not visualized
114 ObjectPtr getObject(const AISObjectPtr& theIO) const;
115 ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
117 /// Deactivates the given object (not allow selection)
118 void deactivate(ObjectPtr theFeature);
120 /// Activates the given object (it can be selected)
121 /// \param theModes - modes on which it has to be activated (can be empty)
122 void activate(ObjectPtr theFeature, const QIntList& theModes);
124 /// Activates the given object with default modes
125 void activate(ObjectPtr theFeature);
127 /// Returns true if the given object can be selected
128 bool isActive(ObjectPtr theObject) const;
130 /// Activates in local context displayed outside of the context.
131 /// \param theModes - modes on which it has to be activated (can be empty)
132 void activateObjects(const QIntList& theModes);
134 /// Activates in local context displayed outside of the context.
135 void deactivateObjects();
137 /// Sets display mode for the given object if this object is displayed
138 void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
140 /// Returns current display mode for the given object.
141 /// If object is not dis played then returns NoMode.
142 DisplayMode displayMode(ObjectPtr theObject) const;
145 /// Displays only objects listed in the list
146 void showOnly(const QObjectPtrList& theList);
148 /// Returns number of displayed objects
149 int objectsCount() const { return myResult2AISObjectMap.size(); }
152 /// Returns currently installed AIS_InteractiveContext
153 Handle(AIS_InteractiveContext) AISContext() const;
155 /// Returns the viewer context top filter. If there is no a filter, it is created and set into
156 /// The context should have only this filter inside. Other filters should be add to the filter
157 Handle(SelectMgr_AndFilter) GetFilter();
159 /// Display the feature and a shape. This shape would be associated to the given feature
160 /// \param theFeature a feature instance
161 /// \param theAIS AIS presentation
162 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
163 /// Returns true if the Feature succesfully displayed
164 void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
165 bool isUpdateViewer = true);
167 /// Display the shape and activate selection of sub-shapes
168 /// \param theFeature a feature instance
169 /// \param theAIS an AIS object
170 /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
171 /// \returns true if the presentation is created
172 //bool redisplay(ObjectPtr theObject,
173 // AISObjectPtr theAIS,
174 // const bool isUpdateViewer = true);
176 /** Redisplay the shape if it was displayed
177 * \param theFeature a feature instance
178 * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
180 void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
182 /// Opens local context. Does nothing if it is already opened.
183 void openLocalContext();
186 XGUI_Workshop* myWorkshop;
188 Handle(SelectMgr_AndFilter) myAndFilter;
190 typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
191 ResultToAISMap myResult2AISObjectMap;
193 // A flag of initialization of external objects selection
194 //bool myUseExternalObjects;
195 // Selection modes installed for external objects in local context
196 QIntList myActiveSelectionModes;