Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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 <QString>
11 #include <boost/shared_ptr.hpp>
12
13 #include <GeomAPI_AISObject.h>
14
15 #include <TopoDS_Shape.hxx>
16 #include <AIS_InteractiveObject.hxx>
17 #include <AIS_InteractiveContext.hxx>
18 #include <NCollection_List.hxx>
19
20 #include <ModelAPI_Result.h>
21
22 #include <ModuleBase_Definitions.h>
23 #include <ModuleBase_ViewerPrs.h>
24
25 #include <map>
26 #include <vector>
27 #include <list>
28
29 class XGUI_Viewer;
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 { NoMode = -1, Wireframe, Shading };
41
42   /// Constructor
43   /// \param theViewer the viewer
44   XGUI_Displayer(XGUI_Workshop* theWorkshop);
45   /// Destructor
46   virtual ~XGUI_Displayer();
47
48   /// Returns the feature visibility state.
49   /// \param theFeature a feature instance
50   bool isVisible(ObjectPtr theObject) const;
51
52   /// Display the feature. Obtain the visualized object from the feature.
53   /// \param theFeature a feature instance
54   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
55   /// Returns true if the Feature succesfully displayed
56   void display(ObjectPtr theObject, bool isUpdateViewer = true);
57
58   /// Display the given AIS object. To hide this object use corresponde erase method
59   void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
60
61   /// Redisplay the shape and activate selection of sub-shapes
62   /// \param theFeature a feature instance
63   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
64   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
65
66   /// Display the shape and activate selection of sub-shapes
67   /// \param theFeature a feature instance
68   /// \param theShape a shape
69   /// \param theMode a list of local selection modes
70   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
71   void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
72                               const bool isUpdateViewer = true);
73
74   /// Stop the current selection and color the given features to the selection color
75   /// \param theFeatures a list of features to be disabled
76   /// \param theToStop the boolean state whether it it stopped or non stopped
77   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
78   void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
79                      const bool isUpdateViewer);
80
81   /**
82    * Add presentations which corresponds to the given features to current selection
83    * \param theFeatures a list of features to be selected
84    * isUpdateViewer the parameter whether the viewer should be update immediatelly
85    */
86   void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
87
88   /// Erase the feature and a shape.
89   /// \param theFeature a feature instance
90   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
91   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
92
93   /// Erase the given AIS object displayed by corresponded display method
94   void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
95
96   /// Erase all presentations
97   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98   void eraseAll(const bool isUpdateViewer = true);
99
100   /// Erase AIS interactive objects, which has an empty feature in the internal map
101   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102   void eraseDeletedResults(const bool isUpdateViewer = true);
103
104   void openLocalContext();
105
106   /// Deactivates selection of sub-shapes
107   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
108   void closeLocalContexts(const bool isUpdateViewer = true);
109
110   /// Updates the viewer
111   void updateViewer();
112
113   /// Searches the interactive object by feature
114   /// \param theFeature the feature or NULL if it not visualized
115   /// \return theIO an interactive object
116   boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
117
118   /// Searches the feature by interactive object
119   /// \param theIO an interactive object
120   /// \return feature the feature or NULL if it not visualized
121   ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
122
123   /// Deactivates the given object (not allow selection)
124   void deactivate(ObjectPtr theFeature);
125
126   /// Activates the given object (it can be selected)
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 - selection modes to activate
134   /// \param theFilter - filter for selection
135   void activateObjectsOutOfContext(const std::list<int>& theModes, 
136                                    Handle(SelectMgr_Filter) theFilter);
137
138   void deactivateObjectsOutOfContext();
139
140   /// Sets display mode for the given object if this object is displayed
141   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
142
143   /// Returns current display mode for the given object.
144   /// If object is not displayed then returns NoMode.
145   DisplayMode displayMode(ObjectPtr theObject) const;
146
147
148   int objectsCount() const { return myResult2AISObjectMap.size(); }
149
150  protected:
151   /// Deactivate local selection
152   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
153   void closeAllContexts(const bool isUpdateViewer);
154
155   /// Returns currently installed AIS_InteractiveContext
156   Handle(AIS_InteractiveContext) AISContext() const;
157
158   /// Display the feature and a shape. This shape would be associated to the given feature
159   /// \param theFeature a feature instance
160   /// \param theAIS AIS presentation
161   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
162   /// Returns true if the Feature succesfully displayed
163   void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
164                bool isUpdateViewer = true);
165
166   /// Display the shape and activate selection of sub-shapes
167   /// \param theFeature a feature instance
168   /// \param theAIS an AIS object
169   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
170   /// \returns true if the presentation is created
171   //bool redisplay(ObjectPtr theObject,
172   //               boost::shared_ptr<GeomAPI_AISObject> theAIS, 
173   //               const bool isUpdateViewer = true);
174
175   /** Redisplay the shape if it was displayed
176    * \param theFeature a feature instance
177    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
178    */
179   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
180
181  protected:
182   XGUI_Workshop* myWorkshop;
183
184   typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
185   ResultToAISMap myResult2AISObjectMap;
186 };
187
188 #endif