Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom.git into Dev_1.1.0
[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
89   /// Unselect all objects
90   void clearSelected();
91
92   /// Erase the feature and a shape.
93   /// \param theObject an object instance
94   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
96
97   /// Erase the given AIS object displayed by corresponded display method
98   /// \param theAIS instance of AIS object
99   /// \param isUpdate the parameter whether the viewer should be update immediatelly
100   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
101
102   /// Erase all presentations
103   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
104   void eraseAll(const bool isUpdateViewer = true);
105
106   /// Deactivates selection of sub-shapes
107   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
108   void closeLocalContexts(const bool isUpdateViewer = true);
109
110   /// \brief Add selection filter
111   /// \param theFilter a filter instance
112   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
113
114   /// \brief Remove selection filter
115   /// \param theFilter a filter instance
116   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
117
118   /// Remove all selection filters
119   void removeFilters();
120
121   /**
122    * Sets a flag to the displayer whether the internal viewer can be updated by 
123    * the updateViewer method call. If it is not enabled, this method do nothing
124    * \param isEnabled a boolean value
125    */
126   bool enableUpdateViewer(const bool isEnabled);
127
128   /// Updates the viewer
129   void updateViewer();
130
131   /// Searches the interactive object by feature
132   /// \param theObject the object or presentable feature
133   /// \return theIO an interactive object
134   AISObjectPtr getAISObject(ObjectPtr theObject) const;
135
136   /// Searches the feature by interactive object
137   /// \param theIO an interactive object
138   /// \return feature the feature or NULL if it not visualized
139   ObjectPtr getObject(const AISObjectPtr& theIO) const;
140
141   /// Searches the feature by interactive object
142   /// \param theIO an interactive object
143   /// \return corresponded object or NULL if it not found
144   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
145
146   /// Deactivates the given object (not allow selection)
147   /// \param theObject object to deactivate
148   void deactivate(ObjectPtr theObject);
149
150   /// Activates the given object (it can be selected)
151   /// \param theObject object to activate
152   /// \param theModes - modes on which it has to be activated (can be empty)
153   //void activate(ObjectPtr theObject, const QIntList& theModes);
154
155   /// Returns the modes of activation
156   /// \param theObject the feature or NULL if it not visualized
157   /// \param theModes - modes on which it is activated (can be empty)
158   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
159
160   /// Activates the given object with default modes
161   /// \param theObject object to activate
162   //void activate(ObjectPtr theObject);
163
164   /// Returns true if the given object can be selected
165   /// \param theObject object to check
166   bool isActive(ObjectPtr theObject) const;
167
168   /// Activates in local context displayed outside of the context.
169   /// \param theModes - modes on which it has to be activated (can be empty)
170   void activateObjects(const QIntList& theModes);
171
172   /// Activates in local context displayed outside of the context.
173   void deactivateObjects();
174
175   /// Sets display mode for the given object if this object is displayed
176   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
177
178   /// Returns current display mode for the given object.
179   /// If object is not dis played then returns NoMode.
180   /// \param theObject object to check
181   DisplayMode displayMode(ObjectPtr theObject) const;
182
183   /// Displays only objects listed in the list
184   /// \param theList list of objects
185   void showOnly(const QObjectPtrList& theList);
186
187   /// Returns number of displayed objects
188   int objectsCount() const { return myResult2AISObjectMap.size(); }
189
190   /// Returns list of displayed objects
191   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
192
193   /// Returns list of displayed objects
194   QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
195
196   /// Returns true if the given object can be shown in shaded mode
197   /// \param theObject object to check
198   bool canBeShaded(ObjectPtr theObject) const;
199
200   /// Set color on presentation of an object if it is displayed
201   /// \param theObject an object 
202   /// \param theColor a color which has to be set
203   /// \param toUpdate update viewer flag
204   /// \return previously defined color on the object
205   QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
206
207 signals:
208   /// Signal on object display
209   /// \param theObject a data object
210   /// \param theAIS a presentation object
211   void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
212
213   /// Signal on before object erase
214   /// \param theObject a data object
215   /// \param theAIS a presentation object
216   void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
217
218  protected:
219   /// Returns currently installed AIS_InteractiveContext
220   Handle(AIS_InteractiveContext) AISContext() const;
221
222   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
223   /// The context should have only this filter inside. Other filters should be add to the filter
224   Handle(SelectMgr_AndFilter) GetFilter();
225
226   /// Display the feature and a shape. This shape would be associated to the given feature
227   /// \param theObject an object instance
228   /// \param theAIS AIS presentation
229   /// \param isShading flag to show in shading mode
230   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
231   /// \return true if the object is succesfully displayed
232   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
233                bool isUpdateViewer = true);
234
235 private:
236   /// Activates the interactive object in the local context.
237   /// \param theIO an interactive object
238   /// \param theModes - modes on which it has to be activated (can be empty)
239   void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes) const;
240
241   /// Opens local context. Does nothing if it is already opened.
242   void openLocalContext();
243
244   /** Update the object presentable properties such as color, lines width and other
245    * If the object is result with the color attribute value set, it is used,
246    * otherwise the customize is applyed to the object's feature if it is a custom prs
247    * \param theObject an object instance
248    * \return the true state if there is changes and the presentation is customized
249    */
250   bool customizeObject(ObjectPtr theObject);
251
252  protected:
253    /// Reference to workshop
254   XGUI_Workshop* myWorkshop;
255
256   /// A container for selection filters
257   Handle(SelectMgr_AndFilter) myAndFilter;
258
259   /// A default custom presentation, which is used if the displayed feature is not a custom presentation
260   GeomCustomPrsPtr myCustomPrs;
261
262   /// Definition of a type of map which defines correspondance between objects and presentations
263   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
264
265   /// A map of displayed objects
266   ResultToAISMap myResult2AISObjectMap;
267
268   /// Selection modes installed for external objects in local context
269   QIntList myActiveSelectionModes;
270
271   /// the enable update viewer flag
272   bool myEnableUpdateViewer;  
273 };
274
275 #endif