Salome HOME
Sources formated according to the codeing standards
[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   /// Constructor
41   /// \param theViewer the viewer
42   XGUI_Displayer(XGUI_Workshop* theWorkshop);
43   /// Destructor
44   virtual ~XGUI_Displayer();
45
46   /// Set AIS_InteractiveContext object in case if it was changed
47   /// or can not be initialized in constructor
48   void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
49
50   /// Returns the feature visibility state.
51   /// \param theFeature a feature instance
52   bool isVisible(ObjectPtr theObject);
53
54   /// Display the feature. Obtain the visualized object from the feature.
55   /// \param theFeature a feature instance
56   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
57   /// Returns true if the Feature succesfully displayed
58   void display(ObjectPtr theObject, bool isUpdateViewer = true);
59
60   /// Display the given AIS object. To hide this object use corresponde erase method
61   void display(boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdate = true);
62
63   /// Redisplay the shape and activate selection of sub-shapes
64   /// \param theFeature a feature instance
65   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
66   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
67
68   /// Display the shape and activate selection of sub-shapes
69   /// \param theFeature a feature instance
70   /// \param theShape a shape
71   /// \param theMode a list of local selection modes
72   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
73   void activateInLocalContext(ObjectPtr theFeature, const std::list<int>& theModes,
74                               const bool isUpdateViewer = true);
75
76   /// Stop the current selection and color the given features to the selection color
77   /// \param theFeatures a list of features to be disabled
78   /// \param theToStop the boolean state whether it it stopped or non stopped
79   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80   void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
81                      const bool isUpdateViewer);
82
83   /**
84    * Add presentations which corresponds to the given features to current selection
85    * \param theFeatures a list of features to be selected
86    * isUpdateViewer the parameter whether the viewer should be update immediatelly
87    */
88   void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
89
90   /// Erase the feature and a shape.
91   /// \param theFeature a feature instance
92   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
93   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
94
95   /// Erase the given AIS object displayed by corresponded display method
96   void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
97
98   /// Erase all presentations
99   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
100   //void EraseAll(const bool isUpdateViewer = true);
101
102   /// Erase AIS interactive objects, which has an empty feature in the internal map
103   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
104   void eraseDeletedResults(const bool isUpdateViewer = true);
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   void deactivate(ObjectPtr theFeature);
124
125   void activate(ObjectPtr theFeature);
126
127  protected:
128   /// Deactivate local selection
129   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
130   void closeAllContexts(const bool isUpdateViewer);
131
132   /// Returns currently installed AIS_InteractiveContext
133   Handle(AIS_InteractiveContext) AISContext() const;
134
135   /// Display the feature and a shape. This shape would be associated to the given feature
136   /// \param theFeature a feature instance
137   /// \param theAIS AIS presentation
138   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
139   /// Returns true if the Feature succesfully displayed
140   void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS,
141                bool isUpdateViewer = true);
142
143   /// Display the shape and activate selection of sub-shapes
144   /// \param theFeature a feature instance
145   /// \param theAIS an AIS object
146   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
147   /// \returns true if the presentation is created
148   //bool redisplay(ObjectPtr theObject,
149   //               boost::shared_ptr<GeomAPI_AISObject> theAIS, 
150   //               const bool isUpdateViewer = true);
151
152   /** Redisplay the shape if it was displayed
153    * \param theFeature a feature instance
154    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
155    */
156   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
157
158  protected:
159   XGUI_Workshop* myWorkshop;
160
161   typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
162   ResultToAISMap myResult2AISObjectMap;
163 };
164
165 #endif