]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
4902fbceb494e2aaf5b898df48ea22f4aa14af13
[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   /// Stop the current selection and color the given features to the selection color
62   /// \param theFeatures a list of features to be disabled
63   /// \param theToStop the boolean state whether it it stopped or non stopped
64   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
65   void stopSelection(const QList<ObjectPtr>& theFeatures, const bool isStop,
66                      const bool isUpdateViewer);
67
68   /**
69    * Add presentations which corresponds to the given features to current selection
70    * \param theFeatures a list of features to be selected
71    * isUpdateViewer the parameter whether the viewer should be update immediatelly
72    */
73   void setSelected(const QList<ObjectPtr>& theFeatures, bool isUpdateViewer = true);
74
75
76   /// Un select all objects
77   void clearSelected();
78
79   /// Erase the feature and a shape.
80   /// \param theFeature a feature instance
81   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
82   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
83
84   /// Erase the given AIS object displayed by corresponded display method
85   void erase(boost::shared_ptr<GeomAPI_AISObject> theAIS, const bool isUpdate = true);
86
87   /// Erase all presentations
88   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89   void eraseAll(const bool isUpdateViewer = true);
90
91   /// Erase AIS interactive objects, which has an empty feature in the internal map
92   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
93   void eraseDeletedResults(const bool isUpdateViewer = true);
94
95   void openLocalContext();
96
97   /// Deactivates selection of sub-shapes
98   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
99   void closeLocalContexts(const bool isUpdateViewer = true);
100
101   /*
102   * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
103   * It doesn't manages a local context
104   * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
105   */
106   void setSelectionModes(const QIntList& theModes);
107
108   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
109
110   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
111
112   /// Updates the viewer
113   void updateViewer();
114
115   /// Searches the interactive object by feature
116   /// \param theFeature the feature or NULL if it not visualized
117   /// \return theIO an interactive object
118   boost::shared_ptr<GeomAPI_AISObject> getAISObject(ObjectPtr theFeature) const;
119
120   /// Searches the feature by interactive object
121   /// \param theIO an interactive object
122   /// \return feature the feature or NULL if it not visualized
123   ObjectPtr getObject(Handle(AIS_InteractiveObject) theIO) const;
124
125   /// Deactivates the given object (not allow selection)
126   void deactivate(ObjectPtr theFeature);
127
128   /// Activates the given object (it can be selected)
129   void activate(ObjectPtr theFeature, const QIntList& theModes);
130
131   /// Returns true if the given object can be selected
132   bool isActive(ObjectPtr theObject) const;
133
134   /// Activates in local context displayed outside of the context.
135   /// \param theModes - selection modes to activate
136   /// \param theFilter - filter for selection
137   void activateObjectsOutOfContext();
138
139   void deactivateObjectsOutOfContext();
140
141   /// Sets display mode for the given object if this object is displayed
142   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
143
144   /// Returns current display mode for the given object.
145   /// If object is not displayed then returns NoMode.
146   DisplayMode displayMode(ObjectPtr theObject) const;
147
148
149   int objectsCount() const { return myResult2AISObjectMap.size(); }
150
151  protected:
152   /// Deactivate local selection
153   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
154   void closeAllContexts(const bool isUpdateViewer);
155
156   /// Returns currently installed AIS_InteractiveContext
157   Handle(AIS_InteractiveContext) AISContext() const;
158
159   /// Display the feature and a shape. This shape would be associated to the given feature
160   /// \param theFeature a feature instance
161   /// \param theAIS AIS presentation
162   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
163   /// Returns true if the Feature succesfully displayed
164   void display(ObjectPtr theObject, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isShading,
165                bool isUpdateViewer = true);
166
167   /// Display the shape and activate selection of sub-shapes
168   /// \param theFeature a feature instance
169   /// \param theAIS an AIS object
170   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
171   /// \returns true if the presentation is created
172   //bool redisplay(ObjectPtr theObject,
173   //               boost::shared_ptr<GeomAPI_AISObject> theAIS, 
174   //               const bool isUpdateViewer = true);
175
176   /** Redisplay the shape if it was displayed
177    * \param theFeature a feature instance
178    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
179    */
180   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
181
182  protected:
183   XGUI_Workshop* myWorkshop;
184
185   typedef std::map<ObjectPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
186   ResultToAISMap myResult2AISObjectMap;
187 };
188
189 #endif