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