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   /// Set AIS_InteractiveContext object in case if it was changed
49   /// or can not be initialized in constructor
50   void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
51
52   /// Returns the feature visibility state.
53   /// \param theFeature a feature instance
54   bool isVisible(ObjectPtr theObject) const;
55
56   /// Display the feature. Obtain the visualized object from the feature.
57   /// \param theFeature a feature instance
58   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
59   /// Returns true if the Feature succesfully displayed
60   void display(ObjectPtr theObject, bool isUpdateViewer = true);
61
62   /// Display the given AIS object. To hide this object use corresponde erase method
63   void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
64
65   /// Redisplay the shape and activate selection of sub-shapes
66   /// \param theFeature a feature instance
67   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
68   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
69
70   /// Display the shape and activate selection of sub-shapes
71   /// \param theFeature a feature instance
72   /// \param theShape a shape
73   /// \param theMode a list of local selection modes
74   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
75   void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
76                               const bool isUpdateViewer = true);
77
78   /// Stop the current selection and color the given features to the selection color
79   /// \param theFeatures a list of features to be disabled
80   /// \param theToStop the boolean state whether it it stopped or non stopped
81   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
82   void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
83                      const bool isUpdateViewer);
84
85   /**
86    * Add presentations which corresponds to the given features to current selection
87    * \param theFeatures a list of features to be selected
88    * isUpdateViewer the parameter whether the viewer should be update immediatelly
89    */
90   void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
91
92   /// Erase the feature and a shape.
93   /// \param theFeature a feature instance
94   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
96
97   /// Erase the given AIS object displayed by corresponded display method
98   void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
99
100   /// Erase all presentations
101   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102   void eraseAll(const bool isUpdateViewer = true);
103
104   /// Erase AIS interactive objects, which has an empty feature in the internal map
105   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
106   void eraseDeletedResults(const bool isUpdateViewer = true);
107
108   void openLocalContext();
109
110   /// Deactivates selection of sub-shapes
111   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
112   void closeLocalContexts(const bool isUpdateViewer = true);
113
114   /// Updates the viewer
115   void updateViewer();
116
117   /// Searches the interactive object by feature
118   /// \param theFeature the feature or NULL if it not visualized
119   /// \return theIO an interactive object
120   boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
121
122   /// Searches the feature by interactive object
123   /// \param theIO an interactive object
124   /// \return feature the feature or NULL if it not visualized
125   ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
126
127   void deactivate(ObjectPtr theFeature);
128
129   void activate(ObjectPtr theFeature);
130
131   /// Activates in local context displayed outside of the context.
132   /// \param theModes - selection modes to activate
133   /// \param theFilter - filter for selection
134   void activateObjectsOutOfContext(const std::list<int>& theModes, 
135                                    Handle(SelectMgr_Filter) theFilter);
136
137   void deactivateObjectsOutOfContext();
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 displayed then returns NoMode.
144   DisplayMode displayMode(ObjectPtr theObject) const;
145
146
147   int objectsCount() const { return myResult2AISObjectMap.size(); }
148
149  protected:
150   /// Deactivate local selection
151   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
152   void closeAllContexts(const bool isUpdateViewer);
153
154   /// Returns currently installed AIS_InteractiveContext
155   Handle(AIS_InteractiveContext) AISContext() const;
156
157   /// Display the feature and a shape. This shape would be associated to the given feature
158   /// \param theFeature a feature instance
159   /// \param theAIS AIS presentation
160   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
161   /// Returns true if the Feature succesfully displayed
162   void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
163                bool isUpdateViewer = true);
164
165   /// Display the shape and activate selection of sub-shapes
166   /// \param theFeature a feature instance
167   /// \param theAIS an AIS object
168   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
169   /// \returns true if the presentation is created
170   //bool redisplay(ObjectPtr theObject,
171   //               boost::shared_ptr<GeomAPI_AISObject> theAIS, 
172   //               const bool isUpdateViewer = true);
173
174   /** Redisplay the shape if it was displayed
175    * \param theFeature a feature instance
176    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
177    */
178   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
179
180  protected:
181   XGUI_Workshop* myWorkshop;
182
183   typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
184   ResultToAISMap myResult2AISObjectMap;
185 };
186
187 #endif