Salome HOME
f563223280a444faf49eeeea1918cae78bb1210f
[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 <GeomAPI_AISObject.h>
11 #include <TopoDS_Shape.hxx>
12 #include <AIS_InteractiveObject.hxx>
13 #include <AIS_InteractiveContext.hxx>
14 #include <NCollection_List.hxx>
15
16 #include <ModelAPI_Result.h>
17
18 #include <ModuleBase_Definitions.h>
19 #include <ModuleBase_ViewerPrs.h>
20
21 #include <QString>
22 #include <QMap>
23
24 class XGUI_Viewer;
25 class ModelAPI_Feature;
26 class XGUI_Workshop;
27
28 /**\class XGUI_Displayer
29  * \ingroup GUI
30  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
31  */
32 class XGUI_EXPORT XGUI_Displayer
33 {
34  public:
35    enum DisplayMode { NoMode = -1, Wireframe, Shading };
36
37   /// Constructor
38   /// \param theViewer the viewer
39   XGUI_Displayer(XGUI_Workshop* theWorkshop);
40   /// Destructor
41   virtual ~XGUI_Displayer();
42
43   /// Returns the feature visibility state.
44   /// \param theFeature a feature instance
45   bool isVisible(ObjectPtr theObject) const;
46
47   /// Display the feature. Obtain the visualized object from the feature.
48   /// \param theFeature a feature instance
49   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
50   /// Returns true if the Feature succesfully displayed
51   void display(ObjectPtr theObject, bool isUpdateViewer = true);
52
53   /// Display the given AIS object. To hide this object use corresponde erase method
54   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
55
56   /// Stop the current selection and color the given features to the selection color
57   /// \param theFeatures a list of features to be disabled
58   /// \param theToStop the boolean state whether it it stopped or non stopped
59   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
60   void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
61                      const bool isUpdateViewer);
62
63   /**
64    * Add presentations which corresponds to the given features to current selection
65    * \param theFeatures a list of features to be selected
66    * isUpdateViewer the parameter whether the viewer should be update immediatelly
67    */
68   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
69
70
71   /// Un select all objects
72   void clearSelected();
73
74   /// Erase the feature and a shape.
75   /// \param theFeature a feature instance
76   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
77   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
78
79   /// Erase the given AIS object displayed by corresponded display method
80   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
81
82   /// Erase all presentations
83   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
84   void eraseAll(const bool isUpdateViewer = true);
85
86   /// Erase AIS interactive objects, which has an empty feature in the internal map
87   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
88   void eraseDeletedResults(const bool isUpdateViewer = true);
89
90   /// Opens local context. Does nothing if it is already opened.
91   void openLocalContext();
92
93   /// Deactivates selection of sub-shapes
94   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
95   void closeLocalContexts(const bool isUpdateViewer = true);
96
97   /*
98   * Set modes of selections. Selection mode has to be defined by TopAbs_ShapeEnum.
99   * It doesn't manages a local context
100   * \param theModes - list of selection modes. If the list is empty then all selectoin modes will be cleared.
101   */
102   void setSelectionModes(const QIntList& theModes);
103
104   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
105
106   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
107
108   void removeFilters();
109
110   /// Updates the viewer
111   void updateViewer();
112
113   /// Searches the interactive object by feature
114   /// \param theFeature the feature or NULL if it not visualized
115   /// \return theIO an interactive object
116   AISObjectPtr getAISObject(ObjectPtr theFeature) const;
117
118   /// Searches the feature by interactive object
119   /// \param theIO an interactive object
120   /// \return feature the feature or NULL if it not visualized
121   ObjectPtr getObject(const AISObjectPtr& theIO) const;
122   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
123
124   /// Deactivates the given object (not allow selection)
125   void deactivate(ObjectPtr theFeature);
126
127   /// Activates the given object (it can be selected)
128   /// \param theModes - modes on which it has to be activated (can be empty)
129   void activate(ObjectPtr theFeature, const QIntList& theModes);
130
131   /// Activates the given object with default modes
132   void activate(ObjectPtr theFeature);
133
134   /// Returns true if the given object can be selected
135   bool isActive(ObjectPtr theObject) const;
136
137   /// Activates in local context displayed outside of the context.
138   /// \param theModes - modes on which it has to be activated (can be empty)
139   void activateObjectsOutOfContext(const QIntList& theModes);
140
141   /// Activates in local context displayed outside of the context.
142   void deactivateObjectsOutOfContext();
143
144   /// Sets display mode for the given object if this object is displayed
145   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
146
147   /// Returns current display mode for the given object.
148   /// If object is not displayed then returns NoMode.
149   DisplayMode displayMode(ObjectPtr theObject) const;
150
151
152   int objectsCount() const { return myResult2AISObjectMap.size(); }
153
154  protected:
155   /// Returns currently installed AIS_InteractiveContext
156   Handle(AIS_InteractiveContext) AISContext() const;
157
158   /// Display the feature and a shape. This shape would be associated to the given feature
159   /// \param theFeature a feature instance
160   /// \param theAIS AIS presentation
161   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
162   /// Returns true if the Feature succesfully displayed
163   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
164                bool isUpdateViewer = true);
165
166   /// Display the shape and activate selection of sub-shapes
167   /// \param theFeature a feature instance
168   /// \param theAIS an AIS object
169   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
170   /// \returns true if the presentation is created
171   //bool redisplay(ObjectPtr theObject,
172   //               AISObjectPtr theAIS, 
173   //               const bool isUpdateViewer = true);
174
175   /** Redisplay the shape if it was displayed
176    * \param theFeature a feature instance
177    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
178    */
179   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
180
181  protected:
182   XGUI_Workshop* myWorkshop;
183
184   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
185   ResultToAISMap myResult2AISObjectMap;
186
187   // A flag of initialization of external objects selection
188   bool myUseExternalObjects;
189   // Selection modes installed for external objects in local context
190   QIntList myActiveSelectionModes;
191 };
192
193 #endif