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