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