Salome HOME
Multi-selection widget to be used in the extrusion feature.
[modules/shaper.git] / src / XGUI / XGUI_Displayer.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_Displayer.h
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef XGUI_Displayer_H
8 #define XGUI_Displayer_H
9
10 #include "XGUI.h"
11
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>
17
18 #include <ModelAPI_Result.h>
19
20 #include <ModuleBase_Definitions.h>
21 #include <ModuleBase_ViewerPrs.h>
22 #include <ModuleBase_FilterValidated.h>
23
24 #include <GeomAPI_ICustomPrs.h>
25
26 #include <SelectMgr_AndFilter.hxx>
27
28 #include <QString>
29 #include <QMap>
30
31 class ModelAPI_Feature;
32 class XGUI_Workshop;
33
34 /**\class XGUI_Displayer
35  * \ingroup GUI
36  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
37  */
38 class XGUI_EXPORT XGUI_Displayer
39 {
40  public:
41    /// \enum DisplayMode display mode
42    enum DisplayMode { 
43      /// Mode is not defined
44      NoMode = -1, 
45      /// Wireframe display mode
46      Wireframe, 
47      /// Shading display mode
48      Shading      
49    };
50
51   /// Constructor
52   /// \param theWorkshop a workshop instance
53   XGUI_Displayer(XGUI_Workshop* theWorkshop);
54
55   /// Destructor
56   virtual ~XGUI_Displayer();
57
58   /// Returns the feature visibility state.
59   /// \param theObject an object instance
60   bool isVisible(ObjectPtr theObject) const;
61
62   /// Display the feature. Obtain the visualized object from the feature.
63   /// \param theObject an object to display
64   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
65   /// Returns true if the Feature succesfully displayed
66   void display(ObjectPtr theObject, bool isUpdateViewer = true);
67
68   /// Display the given AIS object. To hide this object use corresponde erase method
69   /// \param theAIS AIOS object to display
70   /// \param isUpdate the parameter whether the viewer should be update immediatelly
71   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
72
73   /**
74    * Add presentations which corresponds to the given features to current selection
75    * \param theFeatures a list of features to be selected
76    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
77    */
78   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
79
80
81   /// Unselect all objects
82   void clearSelected();
83
84   /// Erase the feature and a shape.
85   /// \param theObject an object instance
86   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
87   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
88
89   /// Erase the given AIS object displayed by corresponded display method
90   /// \param theAIS instance of AIS object
91   /// \param isUpdate the parameter whether the viewer should be update immediatelly
92   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
93
94   /// Erase all presentations
95   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
96   void eraseAll(const bool isUpdateViewer = true);
97
98   /// Deactivates selection of sub-shapes
99   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
100   void closeLocalContexts(const bool isUpdateViewer = true);
101
102   /// \brief Add selection filter
103   /// \param theFilter a filter instance
104   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
105
106   /// \brief Remove selection filter
107   /// \param theFilter a filter instance
108   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
109
110   /// Remove all selection filters
111   void removeFilters();
112
113   /**
114    * Sets a flag to the displayer whether the internal viewer can be updated by 
115    * the updateViewer method call. If it is not enabled, this method do nothing
116    * \param isEnabled a boolean value
117    */
118   bool enableUpdateViewer(const bool isEnabled);
119
120   /// Updates the viewer
121   void updateViewer();
122
123   /// Searches the interactive object by feature
124   /// \param theObject the object or presentable feature
125   /// \return theIO an interactive object
126   AISObjectPtr getAISObject(ObjectPtr theObject) const;
127
128   /// Searches the feature by interactive object
129   /// \param theIO an interactive object
130   /// \return feature the feature or NULL if it not visualized
131   ObjectPtr getObject(const AISObjectPtr& theIO) const;
132
133   /// Searches the feature by interactive object
134   /// \param theIO an interactive object
135   /// \return corresponded object or NULL if it not found
136   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
137
138   /// Deactivates the given object (not allow selection)
139   /// \param theObject object to deactivate
140   void deactivate(ObjectPtr theObject);
141
142   /// Activates the given object (it can be selected)
143   /// \param theObject object to activate
144   /// \param theModes - modes on which it has to be activated (can be empty)
145   //void activate(ObjectPtr theObject, const QIntList& theModes);
146
147   /// Returns the modes of activation
148   /// \param theObject the feature or NULL if it not visualized
149   /// \param theModes - modes on which it is activated (can be empty)
150   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
151
152   /// Activates the given object with default modes
153   /// \param theObject object to activate
154   //void activate(ObjectPtr theObject);
155
156   /// Returns true if the given object can be selected
157   /// \param theObject object to check
158   bool isActive(ObjectPtr theObject) const;
159
160   /// Activates in local context displayed outside of the context.
161   /// \param theModes - modes on which it has to be activated (can be empty)
162   void activateObjects(const QIntList& theModes);
163
164   /// Activates in local context displayed outside of the context.
165   void deactivateObjects();
166
167   /// Sets display mode for the given object if this object is displayed
168   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
169
170   /// Returns current display mode for the given object.
171   /// If object is not dis played then returns NoMode.
172   /// \param theObject object to check
173   DisplayMode displayMode(ObjectPtr theObject) const;
174
175   /// Displays only objects listed in the list
176   /// \param theList list of objects
177   void showOnly(const QObjectPtrList& theList);
178
179   /// Returns number of displayed objects
180   int objectsCount() const { return myResult2AISObjectMap.size(); }
181
182   /// Returns list of displayed objects
183   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
184
185   /// Returns true if the given object can be shown in shaded mode
186   /// \param theObject object to check
187   bool canBeShaded(ObjectPtr theObject) const;
188
189  protected:
190   /// Returns currently installed AIS_InteractiveContext
191   Handle(AIS_InteractiveContext) AISContext() const;
192
193   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
194   /// The context should have only this filter inside. Other filters should be add to the filter
195   Handle(SelectMgr_AndFilter) GetFilter();
196
197   /// Display the feature and a shape. This shape would be associated to the given feature
198   /// \param theObject an object instance
199   /// \param theAIS AIS presentation
200   /// \param isShading flag to show in shading mode
201   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
202   /// \return true if the object is succesfully displayed
203   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
204                bool isUpdateViewer = true);
205
206   /** Redisplay the shape if it was displayed
207    * \param theObject an object instance
208    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
209    */
210   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
211
212   /// Activates the interactive object in the local context.
213   /// \param theIO an interactive object
214   /// \param theModes - modes on which it has to be activated (can be empty)
215   void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
216
217   /// Opens local context. Does nothing if it is already opened.
218   void openLocalContext();
219
220   /** Update the object presentable properties such as color, lines width and other
221    * If the object is result with the color attribute value set, it is used,
222    * otherwise the customize is applyed to the object's feature if it is a custom prs
223    * \param theObject an object instance
224    * \return the true state if there is changes and the presentation is customized
225    */
226   bool customizeObject(ObjectPtr theObject);
227
228  protected:
229    /// Reference to workshop
230   XGUI_Workshop* myWorkshop;
231
232   /// A container for selection filters
233   Handle(SelectMgr_AndFilter) myAndFilter;
234
235   Handle(ModuleBase_FilterValidated) myFilterValidated;
236
237   /// A default custom presentation, which is used if the displayed feature is not a custom presentation
238   GeomCustomPrsPtr myCustomPrs;
239
240   /// Definition of a type of map which defines correspondance between objects and presentations
241   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
242
243   /// A map of displayed objects
244   ResultToAISMap myResult2AISObjectMap;
245
246   /// Selection modes installed for external objects in local context
247   QIntList myActiveSelectionModes;
248
249   /// the enable update viewer flag
250   bool myEnableUpdateViewer;  
251 };
252
253 #endif