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