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