]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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(ResultPtr theResult);
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(ResultPtr 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(ResultPtr theResult, boost::shared_ptr<GeomAPI_AISObject> theAIS, bool isUpdateViewer = true);
66   
67   /// Display the shape and activate selection of sub-shapes
68   /// \param theFeature a feature instance
69   /// \param theAIS an AIS object
70   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
71   /// \returns true if the presentation is created
72   bool redisplay(ResultPtr theFeature,
73                  boost::shared_ptr<GeomAPI_AISObject> theAIS, 
74                  const bool isUpdateViewer = true);
75
76   /** Redisplay the shape if it was displayed
77   * \param theFeature a feature instance
78   * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
79   */
80   bool redisplay(ResultPtr theFeature, bool isUpdateViewer = true);
81
82   /// Redisplay the shape and activate selection of sub-shapes
83   /// \param theFeature a feature instance
84   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
85   //void redisplay(Handle(AIS_InteractiveObject) theAIS, const bool isUpdateViewer = true);
86
87   /// Display the shape and activate selection of sub-shapes
88   /// \param theFeature a feature instance
89   /// \param theShape a shape
90   /// \param theMode a list of local selection modes
91   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
92   void activateInLocalContext(ResultPtr theFeature,
93                               const std::list<int>& theModes, const bool isUpdateViewer = true);
94
95   /// Stop the current selection and color the given features to the selection color
96   /// \param theFeatures a list of features to be disabled
97   /// \param theToStop the boolean state whether it it stopped or non stopped
98   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
99   void stopSelection(const QResultList& theFeatures, const bool isStop,
100                      const bool isUpdateViewer);
101
102   /**
103   * Add presentations which corresponds to the given features to current selection
104   * \param theFeatures a list of features to be selected
105   * isUpdateViewer the parameter whether the viewer should be update immediatelly
106   */
107   void setSelected(const QResultList& theFeatures, bool isUpdateViewer = true);
108
109   /// Erase the feature and a shape.
110   /// \param theFeature a feature instance
111   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
112   void erase(ResultPtr theResult, const bool isUpdateViewer = true);
113
114   /// Erase all presentations
115   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
116   //void EraseAll(const bool isUpdateViewer = true);
117
118   /// Erase AIS interactive objects, which has an empty feature in the internal map
119   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
120   void eraseDeletedResults(const bool isUpdateViewer = true);
121
122   /// Deactivates selection of sub-shapes
123   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
124   void closeLocalContexts(const bool isUpdateViewer = true);
125
126   /// Updates the viewer
127   void updateViewer();
128
129   /// Searches the interactive object by feature
130   /// \param theFeature the feature or NULL if it not visualized
131   /// \return theIO an interactive object
132   boost::shared_ptr<GeomAPI_AISObject> getAISObject(ResultPtr theFeature) const;
133
134   /// Searches the feature by interactive object
135   /// \param theIO an interactive object
136   /// \return feature the feature or NULL if it not visualized
137   ResultPtr getResult(Handle(AIS_InteractiveObject) theIO) const;
138
139 protected:
140   /// Deactivate local selection
141   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
142   void closeAllContexts(const bool isUpdateViewer);
143
144   /// Returns currently installed AIS_InteractiveContext
145   Handle(AIS_InteractiveContext) AISContext() const;
146
147 protected:
148   XGUI_Workshop* myWorkshop;
149
150   typedef std::map<ResultPtr, boost::shared_ptr<GeomAPI_AISObject> > ResultToAISMap;
151   ResultToAISMap myResult2AISObjectMap;
152 };
153
154
155 #endif