Salome HOME
Unconditionally redisplay of the update object. Test case is
[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   /**
76    * Add presentations which corresponds to the given features to current selection
77    * \param theFeatures a list of features to be selected
78    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
79    */
80   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
81
82
83   /// Unselect all objects
84   void clearSelected();
85
86   /// Erase the feature and a shape.
87   /// \param theObject an object instance
88   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
90
91   /// Erase the given AIS object displayed by corresponded display method
92   /// \param theAIS instance of AIS object
93   /// \param isUpdate the parameter whether the viewer should be update immediatelly
94   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
95
96   /// Erase all presentations
97   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98   void eraseAll(const bool isUpdateViewer = true);
99
100   /// Deactivates selection of sub-shapes
101   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102   void closeLocalContexts(const bool isUpdateViewer = true);
103
104   /// \brief Add selection filter
105   /// \param theFilter a filter instance
106   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
107
108   /// \brief Remove selection filter
109   /// \param theFilter a filter instance
110   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
111
112   /// Remove all selection filters
113   void removeFilters();
114
115   /**
116    * Sets a flag to the displayer whether the internal viewer can be updated by 
117    * the updateViewer method call. If it is not enabled, this method do nothing
118    * \param isEnabled a boolean value
119    */
120   bool enableUpdateViewer(const bool isEnabled);
121
122   /// Updates the viewer
123   void updateViewer();
124
125   /// Searches the interactive object by feature
126   /// \param theObject the object or presentable feature
127   /// \return theIO an interactive object
128   AISObjectPtr getAISObject(ObjectPtr theObject) const;
129
130   /// Searches the feature by interactive object
131   /// \param theIO an interactive object
132   /// \return feature the feature or NULL if it not visualized
133   ObjectPtr getObject(const AISObjectPtr& theIO) const;
134
135   /// Searches the feature by interactive object
136   /// \param theIO an interactive object
137   /// \return corresponded object or NULL if it not found
138   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
139
140   /// Deactivates the given object (not allow selection)
141   /// \param theObject object to deactivate
142   void deactivate(ObjectPtr theObject);
143
144   /// Activates the given object (it can be selected)
145   /// \param theObject object to activate
146   /// \param theModes - modes on which it has to be activated (can be empty)
147   //void activate(ObjectPtr theObject, const QIntList& theModes);
148
149   /// Returns the modes of activation
150   /// \param theObject the feature or NULL if it not visualized
151   /// \param theModes - modes on which it is activated (can be empty)
152   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
153
154   /// Activates the given object with default modes
155   /// \param theObject object to activate
156   //void activate(ObjectPtr theObject);
157
158   /// Returns true if the given object can be selected
159   /// \param theObject object to check
160   bool isActive(ObjectPtr theObject) const;
161
162   /// Activates in local context displayed outside of the context.
163   /// \param theModes - modes on which it has to be activated (can be empty)
164   void activateObjects(const QIntList& theModes);
165
166   /// Activates in local context displayed outside of the context.
167   void deactivateObjects();
168
169   /// Sets display mode for the given object if this object is displayed
170   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
171
172   /// Returns current display mode for the given object.
173   /// If object is not dis played then returns NoMode.
174   /// \param theObject object to check
175   DisplayMode displayMode(ObjectPtr theObject) const;
176
177   /// Displays only objects listed in the list
178   /// \param theList list of objects
179   void showOnly(const QObjectPtrList& theList);
180
181   /// Returns number of displayed objects
182   int objectsCount() const { return myResult2AISObjectMap.size(); }
183
184   /// Returns list of displayed objects
185   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
186
187   /// Returns list of displayed objects
188   QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
189
190   /// Returns true if the given object can be shown in shaded mode
191   /// \param theObject object to check
192   bool canBeShaded(ObjectPtr theObject) const;
193
194   /// Set color on presentation of an object if it is displayed
195   /// \param theObject an object 
196   /// \param theColor a color which has to be set
197   /// \param theUpdate update viewer flag
198   /// \return previously defined color on the object
199   QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool toUpdate = true);
200
201 signals:
202   /// Signal on object display
203   /// \param theObject a data object
204   /// \param theAIS a presentation object
205   void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
206
207   /// Signal on before object erase
208   /// \param theObject a data object
209   /// \param theAIS a presentation object
210   void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
211
212  protected:
213   /// Returns currently installed AIS_InteractiveContext
214   Handle(AIS_InteractiveContext) AISContext() const;
215
216   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
217   /// The context should have only this filter inside. Other filters should be add to the filter
218   Handle(SelectMgr_AndFilter) GetFilter();
219
220   /// Display the feature and a shape. This shape would be associated to the given feature
221   /// \param theObject an object instance
222   /// \param theAIS AIS presentation
223   /// \param isShading flag to show in shading mode
224   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
225   /// \return true if the object is succesfully displayed
226   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
227                bool isUpdateViewer = true);
228 public:
229   /** Redisplay the shape if it was displayed
230    * \param theObject an object instance
231    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
232    */
233   void redisplay(ObjectPtr theObject, 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