Salome HOME
2ce31b14d440ff367f09b444ffa16d647e05acc4
[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 #include <ModuleBase_Definitions.h>
10
11 #include <QString>
12 #include <boost/shared_ptr.hpp>
13
14 #include <GeomAPI_AISObject.h>
15
16 #include <TopoDS_Shape.hxx>
17 #include <AIS_InteractiveObject.hxx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <NCollection_List.hxx>
20
21 #include <ModelAPI_Feature.h>
22
23 #include <XGUI_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(FeaturePtr theFeature);
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   void display(FeaturePtr theFeature, bool isUpdateViewer = true);
58
59   /// Display the feature and a shape. This shape would be associated to the given feature
60   /// \param theFeature a feature instance
61   /// \param theAIS AIS presentation
62   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
63   void display(FeaturePtr theFeature, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
64   
65   /// Returns a list of viewer selected presentations
66   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
67   /// \return list of presentations
68   std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
69
70   /**
71   * Returns list of features currently selected in 3d viewer
72   */
73   QFeatureList selectedFeatures() const;
74
75   /// Returns a list of viewer highlited presentations
76   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
77   /// \return list of presentations
78   std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
79
80   /// Display the shape and activate selection of sub-shapes
81   /// \param theFeature a feature instance
82   /// \param theAIS an AIS object
83   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84   /// \returns true if the presentation is created
85   bool redisplay(FeaturePtr theFeature,
86                  boost::shared_ptr<GeomAPI_AISObject> theAIS, 
87                  const bool isUpdateViewer = true);
88
89   /** Redisplay the shape if it was displayed
90   * \param theFeature a feature instance
91   * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
92   */
93   void redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
94
95   /// Redisplay the shape and activate selection of sub-shapes
96   /// \param theFeature a feature instance
97   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
99
100   /// Display the shape and activate selection of sub-shapes
101   /// \param theFeature a feature instance
102   /// \param theShape a shape
103   /// \param theMode a list of local selection modes
104   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
105   void activateInLocalContext(FeaturePtr theFeature,
106                               const std::list<int>& theModes, const bool isUpdateViewer = true);
107
108   /// Stop the current selection and color the given features to the selection color
109   /// \param theFeatures a list of features to be disabled
110   /// \param theToStop the boolean state whether it it stopped or non stopped
111   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
112   void stopSelection(const QFeatureList& theFeatures, const bool isStop,
113                      const bool isUpdateViewer);
114
115   /**
116   * Add presentations which corresponds to the given features to current selection
117   * \param theFeatures a list of features to be selected
118   * isUpdateViewer the parameter whether the viewer should be update immediatelly
119   */
120   void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
121
122   /// Erase the feature and a shape.
123   /// \param theFeature a feature instance
124   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
125   void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
126
127   /// Erase all presentations
128   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
129   //void EraseAll(const bool isUpdateViewer = true);
130
131   /// Erase AIS interactive objects, which has an empty feature in the internal map
132   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
133   void eraseDeletedFeatures(const bool isUpdateViewer = true);
134
135   /// Deactivates selection of sub-shapes
136   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
137   void closeLocalContexts(const bool isUpdateViewer = true);
138
139   /// Updates the viewer
140   void updateViewer();
141
142   /// Searches the interactive object by feature
143   /// \param theFeature the feature or NULL if it not visualized
144   /// \return theIO an interactive object
145   boost::shared_ptr<GeomAPI_AISObject> getAISObject(FeaturePtr theFeature) const;
146
147 protected:
148   /// Searches the feature by interactive object
149   /// \param theIO an interactive object
150   /// \return feature the feature or NULL if it not visualized
151   FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
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 protected:
160   XGUI_Workshop* myWorkshop;
161
162   typedef std::map<FeaturePtr, boost::shared_ptr<GeomAPI_AISObject> > FeatureToAISMap;
163   FeatureToAISMap myFeature2AISObjectMap;
164 };
165
166
167 #endif