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