Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom into Dev_0.7.1
[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 { NoMode = -1, Wireframe, Shading };
39
40   /// Constructor
41   /// \param theViewer the viewer
42   XGUI_Displayer(XGUI_Workshop* theWorkshop);
43   /// Destructor
44   virtual ~XGUI_Displayer();
45
46   /// Returns the feature visibility state.
47   /// \param theFeature a feature instance
48   bool isVisible(ObjectPtr theObject) const;
49
50   /// Display the feature. Obtain the visualized object from the feature.
51   /// \param theFeature a feature instance
52   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
53   /// Returns true if the Feature succesfully displayed
54   void display(ObjectPtr theObject, bool isUpdateViewer = true);
55
56   /// Display the given AIS object. To hide this object use corresponde erase method
57   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
58
59   /**
60    * Add presentations which corresponds to the given features to current selection
61    * \param theFeatures a list of features to be selected
62    * isUpdateViewer the parameter whether the viewer should be update immediatelly
63    */
64   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
65
66
67   /// Un select all objects
68   void clearSelected();
69
70   /// Erase the feature and a shape.
71   /// \param theFeature a feature instance
72   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
73   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
74
75   /// Erase the given AIS object displayed by corresponded display method
76   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
77
78   /// Erase all presentations
79   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80   void eraseAll(const bool isUpdateViewer = true);
81
82   /// Deactivates selection of sub-shapes
83   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84   void closeLocalContexts(const bool isUpdateViewer = true);
85
86   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
87
88   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
89
90   void removeFilters();
91
92   /**
93    * Sets a flag to the displayer whether the internal viewer can be updated by 
94    * the updateViewer method call. If it is not enabled, this method do nothing
95    * \param isEnabled a boolean value
96    */
97   bool enableUpdateViewer(const bool isEnabled);
98
99   /// Updates the viewer
100   void updateViewer();
101
102   /// Searches the interactive object by feature
103   /// \param theFeature the object or presentable feature
104   /// \return theIO an interactive object
105   AISObjectPtr getAISObject(ObjectPtr theFeature) const;
106
107   /// Searches the feature by interactive object
108   /// \param theIO an interactive object
109   /// \return feature the feature or NULL if it not visualized
110   ObjectPtr getObject(const AISObjectPtr& theIO) const;
111   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
112
113   /// Deactivates the given object (not allow selection)
114   void deactivate(ObjectPtr theFeature);
115
116   /// Activates the given object (it can be selected)
117   /// \param theModes - modes on which it has to be activated (can be empty)
118   void activate(ObjectPtr theFeature, const QIntList& theModes);
119
120   /// Returns the modes of activation
121   /// \param theFeature the feature or NULL if it not visualized
122   /// \param theModes - modes on which it is activated (can be empty)
123   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
124
125   /// Activates the given object with default modes
126   void activate(ObjectPtr theFeature);
127
128   /// Returns true if the given object can be selected
129   bool isActive(ObjectPtr theObject) const;
130
131   /// Activates in local context displayed outside of the context.
132   /// \param theModes - modes on which it has to be activated (can be empty)
133   void activateObjects(const QIntList& theModes);
134
135   /// Activates in local context displayed outside of the context.
136   void deactivateObjects();
137
138   /// Sets display mode for the given object if this object is displayed
139   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
140
141   /// Returns current display mode for the given object.
142   /// If object is not dis played then returns NoMode.
143   DisplayMode displayMode(ObjectPtr theObject) const;
144
145
146   /// Displays only objects listed in the list
147   void showOnly(const QObjectPtrList& theList);
148
149   /// Returns number of displayed objects
150   int objectsCount() const { return myResult2AISObjectMap.size(); }
151
152   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
153
154   /// Returns true if the given object can be shown in shaded mode
155   bool canBeShaded(ObjectPtr theObject) const;
156
157  protected:
158   /// Returns currently installed AIS_InteractiveContext
159   Handle(AIS_InteractiveContext) AISContext() const;
160
161   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
162   /// The context should have only this filter inside. Other filters should be add to the filter
163   Handle(SelectMgr_AndFilter) GetFilter();
164
165   /// Display the feature and a shape. This shape would be associated to the given feature
166   /// \param theFeature a feature instance
167   /// \param theAIS AIS presentation
168   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
169   /// Returns true if the Feature succesfully displayed
170   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
171                bool isUpdateViewer = true);
172
173   /// Display the shape and activate selection of sub-shapes
174   /// \param theFeature a feature instance
175   /// \param theAIS an AIS object
176   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
177   /// \returns true if the presentation is created
178   //bool redisplay(ObjectPtr theObject,
179   //               AISObjectPtr theAIS, 
180   //               const bool isUpdateViewer = true);
181
182   /** Redisplay the shape if it was displayed
183    * \param theFeature a feature instance
184    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
185    */
186   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
187
188   /// Opens local context. Does nothing if it is already opened.
189   void openLocalContext();
190
191  protected:
192   XGUI_Workshop* myWorkshop;
193
194   Handle(SelectMgr_AndFilter) myAndFilter;
195
196   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
197   ResultToAISMap myResult2AISObjectMap;
198
199   // A flag of initialization of external objects selection
200   //bool myUseExternalObjects;
201   // Selection modes installed for external objects in local context
202   QIntList myActiveSelectionModes;
203
204   bool myEnableUpdateViewer;  /// the enable update viewer flag
205 };
206
207 #endif