Salome HOME
Some slight improvements and bugs fixing.
[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 <TopoDS_Shape.hxx>
15 #include <AIS_InteractiveObject.hxx>
16 #include <AIS_InteractiveContext.hxx>
17 #include <NCollection_List.hxx>
18
19 #include <ModelAPI_Feature.h>
20
21 #include <XGUI_ViewerPrs.h>
22
23 #include <map>
24 #include <vector>
25 #include <list>
26
27 class XGUI_Viewer;
28 class ModelAPI_Feature;
29 class XGUI_Workshop;
30
31 /**\class XGUI_Displayer
32  * \ingroup GUI
33  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
34  */
35 class XGUI_EXPORT XGUI_Displayer
36 {
37 public:
38   /// Constructor
39   /// \param theViewer the viewer
40   XGUI_Displayer(XGUI_Workshop* theWorkshop);
41   /// Destructor
42   virtual ~XGUI_Displayer();
43
44   /// Set AIS_InteractiveContext object in case if it was changed
45   /// or can not be initialized in constructor
46   void setAISContext(const Handle(AIS_InteractiveContext)& theAIS);
47
48   /// Returns the feature visibility state.
49   /// \param theFeature a feature instance
50   bool isVisible(FeaturePtr theFeature);
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   void display(FeaturePtr theFeature, bool isUpdateViewer = true);
56
57   /// Display the feature and a shape. This shape would be associated to the given feature
58   /// \param theFeature a feature instance
59   /// \param theShape a shape
60   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
61   void display(FeaturePtr theFeature, const TopoDS_Shape& theShape, bool isUpdateViewer = true);
62   
63   /// Returns a list of viewer selected presentations
64   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
65   /// \return list of presentations
66   std::list<XGUI_ViewerPrs> getSelected(const int theShapeTypeToSkip = -1);
67
68   /**
69   * Returns list of features currently selected in 3d viewer
70   */
71   QFeatureList selectedFeatures() const;
72
73   /// Returns a list of viewer highlited presentations
74   /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build
75   /// \return list of presentations
76   std::list<XGUI_ViewerPrs> getHighlighted(const int theShapeTypeToSkip = -1);
77
78   /// Display the shape and activate selection of sub-shapes
79   /// \param theFeature a feature instance
80   /// \param theAIS an AIS object
81   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
82   /// \returns true if the presentation is created
83   bool redisplay(FeaturePtr theFeature,
84                  Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
85
86   /** Redisplay the shape if it was displayed
87   * \param theFeature a feature instance
88   * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
89   */
90   void redisplay(FeaturePtr theFeature, bool isUpdateViewer = true);
91
92   /// Redisplay the shape and activate selection of sub-shapes
93   /// \param theFeature a feature instance
94   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
96
97   /// Display the shape and activate selection of sub-shapes
98   /// \param theFeature a feature instance
99   /// \param theShape a shape
100   /// \param theMode a list of local selection modes
101   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
102   void activateInLocalContext(FeaturePtr theFeature,
103                               const std::list<int>& theModes, const bool isUpdateViewer = true);
104
105   /// Stop the current selection and color the given features to the selection color
106   /// \param theFeatures a list of features to be disabled
107   /// \param theToStop the boolean state whether it it stopped or non stopped
108   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
109   void stopSelection(const QFeatureList& theFeatures, const bool isStop,
110                      const bool isUpdateViewer);
111
112   /**
113   * Add presentations which corresponds to the given features to current selection
114   * \param theFeatures a list of features to be selected
115   * isUpdateViewer the parameter whether the viewer should be update immediatelly
116   */
117   void setSelected(const QFeatureList& theFeatures, bool isUpdateViewer = true);
118
119   /// Erase the feature and a shape.
120   /// \param theFeature a feature instance
121   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
122   void erase(FeaturePtr theFeature, const bool isUpdateViewer = true);
123
124   /// Erase all presentations
125   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
126   //void EraseAll(const bool isUpdateViewer = true);
127
128   /// Erase AIS interactive objects, which has an empty feature in the internal map
129   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
130   void eraseDeletedFeatures(const bool isUpdateViewer = true);
131
132   /// Deactivates selection of sub-shapes
133   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
134   void closeLocalContexts(const bool isUpdateViewer = true);
135
136   /// Updates the viewer
137   void updateViewer();
138
139   /// Searches the interactive object by feature
140   /// \param theFeature the feature or NULL if it not visualized
141   /// \return theIO an interactive object
142   Handle(AIS_InteractiveObject) getAISObject(FeaturePtr theFeature) const;
143
144 protected:
145   /// Searches the feature by interactive object
146   /// \param theIO an interactive object
147   /// \return feature the feature or NULL if it not visualized
148   FeaturePtr getFeature(Handle(AIS_InteractiveObject) theIO) const;
149   /// Deactivate local selection
150   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
151   void closeAllContexts(const bool isUpdateViewer);
152
153   /// Returns currently installed AIS_InteractiveContext
154   Handle(AIS_InteractiveContext) AISContext() const;
155
156 protected:
157   XGUI_Workshop* myWorkshop;
158
159   typedef std::map<FeaturePtr, Handle(AIS_InteractiveObject) > FeatureToAISMap;
160   FeatureToAISMap myFeature2AISObjectMap;
161 };
162
163
164 #endif