Salome HOME
Merge remote-tracking branch 'origin/Dev_0.6.1' into Dev_0.6.1
[modules/shaper.git] / src / XGUI / XGUI_Displayer.h
1 // File:        XGUI_Displayer.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef XGUI_Displayer_H
6 #define XGUI_Displayer_H
7
8 #include "XGUI.h"
9
10 #include <GeomAPI_AISObject.h>
11 #include <TopoDS_Shape.hxx>
12 #include <AIS_InteractiveObject.hxx>
13 #include <AIS_InteractiveContext.hxx>
14 #include <NCollection_List.hxx>
15
16 #include <ModelAPI_Result.h>
17
18 #include <ModuleBase_Definitions.h>
19 #include <ModuleBase_ViewerPrs.h>
20
21 #include <SelectMgr_AndFilter.hxx>
22
23 #include <QString>
24 #include <QMap>
25
26 class ModelAPI_Feature;
27 class XGUI_Workshop;
28
29 /**\class XGUI_Displayer
30  * \ingroup GUI
31  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
32  */
33 class XGUI_EXPORT XGUI_Displayer
34 {
35  public:
36    enum DisplayMode { NoMode = -1, Wireframe, Shading };
37
38   /// Constructor
39   /// \param theViewer the viewer
40   XGUI_Displayer(XGUI_Workshop* theWorkshop);
41   /// Destructor
42   virtual ~XGUI_Displayer();
43
44   /// Returns the feature visibility state.
45   /// \param theFeature a feature instance
46   bool isVisible(ObjectPtr theObject) const;
47
48   /// Display the feature. Obtain the visualized object from the feature.
49   /// \param theFeature a feature instance
50   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
51   /// Returns true if the Feature succesfully displayed
52   void display(ObjectPtr theObject, bool isUpdateViewer = true);
53
54   /// Display the given AIS object. To hide this object use corresponde erase method
55   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
56
57   /// Stop the current selection and color the given features to the selection color
58   /// \param theFeatures a list of features to be disabled
59   /// \param theToStop the boolean state whether it it stopped or non stopped
60   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
61   void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
62                      const bool isUpdateViewer);
63
64   /**
65    * Add presentations which corresponds to the given features to current selection
66    * \param theFeatures a list of features to be selected
67    * isUpdateViewer the parameter whether the viewer should be update immediatelly
68    */
69   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
70
71
72   /// Un select all objects
73   void clearSelected();
74
75   /// Erase the feature and a shape.
76   /// \param theFeature a feature instance
77   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
78   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
79
80   /// Erase the given AIS object displayed by corresponded display method
81   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
82
83   /// Erase all presentations
84   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
85   void eraseAll(const bool isUpdateViewer = true);
86
87   /// Erase AIS interactive objects, which has an empty feature in the internal map
88   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89   void eraseDeletedResults(const bool isUpdateViewer = true);
90
91   /// Opens local context. Does nothing if it is already opened.
92   void openLocalContext();
93
94   /// Deactivates selection of sub-shapes
95   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
96   void closeLocalContexts(const bool isUpdateViewer = true);
97
98   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
99
100   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
101
102   void removeFilters();
103
104   /// Updates the viewer
105   void updateViewer();
106
107   /// Searches the interactive object by feature
108   /// \param theFeature the feature or NULL if it not visualized
109   /// \return theIO an interactive object
110   AISObjectPtr getAISObject(ObjectPtr theFeature) const;
111
112   /// Searches the feature by interactive object
113   /// \param theIO an interactive object
114   /// \return feature the feature or NULL if it not visualized
115   ObjectPtr getObject(const AISObjectPtr& theIO) const;
116   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
117
118   /// Deactivates the given object (not allow selection)
119   void deactivate(ObjectPtr theFeature);
120
121   /// Activates the given object (it can be selected)
122   /// \param theModes - modes on which it has to be activated (can be empty)
123   void activate(ObjectPtr theFeature, const 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  protected:
153   /// Returns currently installed AIS_InteractiveContext
154   Handle(AIS_InteractiveContext) AISContext() const;
155
156   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
157   /// The context should have only this filter inside. Other filters should be add to the filter
158   Handle(SelectMgr_AndFilter) GetFilter();
159
160   /// Display the feature and a shape. This shape would be associated to the given feature
161   /// \param theFeature a feature instance
162   /// \param theAIS AIS presentation
163   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
164   /// Returns true if the Feature succesfully displayed
165   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
166                bool isUpdateViewer = true);
167
168   /// Display the shape and activate selection of sub-shapes
169   /// \param theFeature a feature instance
170   /// \param theAIS an AIS object
171   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
172   /// \returns true if the presentation is created
173   //bool redisplay(ObjectPtr theObject,
174   //               AISObjectPtr theAIS, 
175   //               const bool isUpdateViewer = true);
176
177   /** Redisplay the shape if it was displayed
178    * \param theFeature a feature instance
179    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
180    */
181   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
182
183  protected:
184   XGUI_Workshop* myWorkshop;
185
186   Handle(SelectMgr_AndFilter) myAndFilter;
187
188   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
189   ResultToAISMap myResult2AISObjectMap;
190
191   // A flag of initialization of external objects selection
192   bool myUseExternalObjects;
193   // Selection modes installed for external objects in local context
194   QIntList myActiveSelectionModes;
195 };
196
197 #endif