]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[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 "XGUI_Constants.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 std::list<XGUI_ViewerPrs>& theFeatures, const bool isStop,
110                      const bool isUpdateViewer);
111
112   /// Set the features are selected
113   /// \param theFeatures a list of features to be selected
114   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
115   void setSelected(const std::list<XGUI_ViewerPrs>& theFeatures, 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   Handle(AIS_InteractiveObject) 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, Handle(AIS_InteractiveObject) > FeatureToAISMap;
165   FeatureToAISMap myFeature2AISObjectMap;
166 };
167
168
169 #endif