Salome HOME
New design of icons
[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 theUpdateViewer the parameter whether the viewer should be update immediatelly
67   /// Returns true if the Feature succesfully displayed
68   void display(ObjectPtr theObject, bool theUpdateViewer = true);
69
70   /// Display the given AIS object. This object is not added to the displayer internal map of objects
71   /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in order
72   /// to perform the display with correct flags.
73   /// \param theAIS AIOS object to display
74   /// \param toActivateInSelectionModes boolean value whether the presentation should be
75   /// activated in the current selection modes
76   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
77   void displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
78                   bool theUpdateViewer = true);
79
80   /** Redisplay the shape if it was displayed
81    * \param theObject an object instance
82    * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
83    */
84   void redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
85
86   /**
87    * Sends and flushes a signal to redisplay all visualized objects.
88    */
89   void redisplayObjects();
90
91   /**
92    * Add presentations to current selection. It unhighlight and deselect the current selection.
93    * The shape and result components are processed in the values. If the presentation shape is not
94    * empty, select it, otherwise select the result.
95    * \param theValues a list of presentation to be selected
96    * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
97    */
98   void setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
99
100
101   /// Unselect all objects
102   void clearSelected();
103
104   /// Erase the feature and a shape.
105   /// \param theObject an object instance
106   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
107   void erase(ObjectPtr theObject, const bool theUpdateViewer = true);
108
109   /// Erase the given AIS object displayed by corresponded display method
110   /// \param theAIS instance of AIS object
111   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
112   void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
113
114   /// Erase all presentations
115   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
116   void eraseAll(const bool theUpdateViewer = true);
117
118   /// Deactivates selection of sub-shapes
119   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
120   void closeLocalContexts(const bool theUpdateViewer = true);
121
122   // Remove default selection filters of the module from the current viewer
123   void deactivateSelectionFilters();
124
125   /// \brief Add selection filter
126   /// \param theFilter a filter instance
127   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
128
129   /// \brief Remove selection filter
130   /// \param theFilter a filter instance
131   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
132
133   /// Returns true if the selection filter is set to the viewer
134   /// \param theFilter a selection filter
135   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
136
137   /// Remove all selection filters
138   void removeFilters();
139
140   /**
141    * Sets a flag to the displayer whether the internal viewer can be updated by 
142    * the updateViewer method call. If it is not enabled, this method do nothing
143    * \param isEnabled a boolean value
144    */
145   bool enableUpdateViewer(const bool isEnabled);
146
147   /// Updates the viewer
148   void updateViewer() const;
149
150   /// Activate interactive context
151   /// \param theIO
152   /// \param theMode
153   void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
154                    const bool theUpdateViewer) const;
155
156   /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
157   void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
158
159   /// Searches the interactive object by feature
160   /// \param theObject the object or presentable feature
161   /// \return theIO an interactive object
162   AISObjectPtr getAISObject(ObjectPtr theObject) const;
163
164   /// Searches the feature by interactive object
165   /// \param theIO an interactive object
166   /// \return feature the feature or NULL if it not visualized
167   ObjectPtr getObject(const AISObjectPtr& theIO) const;
168
169   /// Searches the feature by interactive object
170   /// \param theIO an interactive object
171   /// \return corresponded object or NULL if it not found
172   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
173
174   /// Deactivates the given objects (not allow selection)
175   /// \param theObjList - list of objects which has to be deactivated.
176   /// \param theUpdateViewer update viewer flag
177   void deactivateObjects(const QObjectPtrList& theObjList,
178                          const bool theUpdateViewer = true);
179
180   /// Activates the given object (it can be selected)
181   /// \param theObject object to activate
182   /// \param theModes - modes on which it has to be activated (can be empty)
183   //void activate(ObjectPtr theObject, const QIntList& theModes);
184
185   /// Returns the modes of activation
186   /// \param theObject the feature or NULL if it not visualized
187   /// \param theModes - modes on which it is activated (can be empty)
188   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
189
190   /// Activates the given object with default modes
191   /// \param theObject object to activate
192   //void activate(ObjectPtr theObject);
193
194   /// Returns true if the given object can be selected
195   /// \param theObject object to check
196   bool isActive(ObjectPtr theObject) const;
197
198   /// Activates in local context displayed outside of the context.
199   /// \param theModes - modes on which it has to be activated (can be empty)
200   /// \param theObjList - list of objects which has to be activated.
201   void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
202                        const bool theUpdateViewer = true);
203
204   /// Sets display mode for the given object if this object is displayed
205   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
206
207   /// Returns current display mode for the given object.
208   /// If object is not dis played then returns NoMode.
209   /// \param theObject object to check
210   DisplayMode displayMode(ObjectPtr theObject) const;
211
212   /// Displays only objects listed in the list
213   /// \param theList list of objects
214   void showOnly(const QObjectPtrList& theList);
215
216   /// Returns number of displayed objects
217   int objectsCount() const { return myResult2AISObjectMap.size(); }
218
219   /// Returns list of displayed objects
220   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
221
222   /// Returns list of displayed objects
223   QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
224
225   /// Returns true if the given object can be shown in shaded mode
226   /// \param theObject object to check
227   bool canBeShaded(ObjectPtr theObject) const;
228
229   /// Set color on presentation of an object if it is displayed
230   /// \param theObject an object 
231   /// \param theColor a color which has to be set
232   /// \param theUpdateViewer update viewer flag
233   /// \return previously defined color on the object
234   QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
235
236 signals:
237   /// Signal on object display
238   /// \param theObject a data object
239   /// \param theAIS a presentation object
240   void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
241
242   /// Signal on before object erase
243   /// \param theObject a data object
244   /// \param theAIS a presentation object
245   void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
246
247  protected:
248   /// Returns currently installed AIS_InteractiveContext
249   Handle(AIS_InteractiveContext) AISContext() const;
250
251   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
252   /// The context should have only this filter inside. Other filters should be add to the filter
253   Handle(SelectMgr_AndFilter) GetFilter();
254
255   /// Display the feature and a shape. This shape would be associated to the given feature
256   /// \param theObject an object instance
257   /// \param theAIS AIS presentation
258   /// \param isShading flag to show in shading mode
259   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
260   /// \return true if the object is succesfully displayed
261   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
262                bool theUpdateViewer = true);
263
264 private:
265   /// Activates the interactive object in the local context.
266   /// \param theIO an interactive object
267   /// \param theModes - modes on which it has to be activated (can be empty)
268   void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
269                 const bool theUpdateViewer) const;
270
271   /// Deactivates the given object (not allow selection)
272   /// \param theObject object to deactivate
273   void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
274
275   /// Find a trihedron in a list of displayed presentations and deactivate it.
276   void deactivateTrihedron() const;
277
278   /// Opens local context. Does nothing if it is already opened.
279   void openLocalContext();
280
281   /** Update the object presentable properties such as color, lines width and other
282    * If the object is result with the color attribute value set, it is used,
283    * otherwise the customize is applyed to the object's feature if it is a custom prs
284    * \param theObject an object instance
285    * \return the true state if there is changes and the presentation is customized
286    */
287   bool customizeObject(ObjectPtr theObject);
288
289   /// Append the objects in the internal map. Checks whether the map already contains the object
290   /// \param theObject an object to display
291   /// \param theAIS AIOS object to display
292   void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
293
294   /// Returns an information about alredy displayed objects
295   /// \return a string representation
296   std::string getResult2AISObjectMapInfo() const;
297
298  protected:
299    /// Reference to workshop
300   XGUI_Workshop* myWorkshop;
301
302   /// A container for selection filters
303   Handle(SelectMgr_AndFilter) myAndFilter;
304
305   /// A default custom presentation, which is used if the displayed feature is not a custom presentation
306   GeomCustomPrsPtr myCustomPrs;
307
308   /// Definition of a type of map which defines correspondance between objects and presentations
309   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
310
311   /// A map of displayed objects
312   ResultToAISMap myResult2AISObjectMap;
313
314   /// Selection modes installed for external objects in local context
315   QIntList myActiveSelectionModes;
316
317   /// the enable update viewer flag
318   bool myEnableUpdateViewer;  
319 };
320
321 #endif