Salome HOME
7c1ee1cf7c6c65eb314b96fb90d50e0cff95261f
[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 QList<ObjectPtr>& 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 QList<ObjectPtr>& 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   /// Updates the viewer
109   void updateViewer();
110
111   /// Searches the interactive object by feature
112   /// \param theFeature the feature or NULL if it not visualized
113   /// \return theIO an interactive object
114   AISObjectPtr getAISObject(ObjectPtr theFeature) const;
115
116   /// Searches the feature by interactive object
117   /// \param theIO an interactive object
118   /// \return feature the feature or NULL if it not visualized
119   ObjectPtr getObject(const AISObjectPtr& theIO) const;
120   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
121
122   /// Deactivates the given object (not allow selection)
123   void deactivate(ObjectPtr theFeature);
124
125   /// Activates the given object (it can be selected)
126   /// \param theModes - modes on which it has to be activated (can be empty)
127   void activate(ObjectPtr theFeature, const QIntList& theModes);
128
129   /// Returns true if the given object can be selected
130   bool isActive(ObjectPtr theObject) const;
131
132   /// Activates in local context displayed outside of the context.
133   /// \param theModes - modes on which it has to be activated (can be empty)
134   void activateObjectsOutOfContext(const QIntList& theModes);
135
136   /// Activates in local context displayed outside of the context.
137   void deactivateObjectsOutOfContext();
138
139   /// Sets display mode for the given object if this object is displayed
140   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
141
142   /// Returns current display mode for the given object.
143   /// If object is not displayed then returns NoMode.
144   DisplayMode displayMode(ObjectPtr theObject) const;
145
146
147   int objectsCount() const { return myResult2AISObjectMap.size(); }
148
149  protected:
150   /// Returns currently installed AIS_InteractiveContext
151   Handle(AIS_InteractiveContext) AISContext() const;
152
153   /// Display the feature and a shape. This shape would be associated to the given feature
154   /// \param theFeature a feature instance
155   /// \param theAIS AIS presentation
156   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
157   /// Returns true if the Feature succesfully displayed
158   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
159                bool isUpdateViewer = true);
160
161   /// Display the shape and activate selection of sub-shapes
162   /// \param theFeature a feature instance
163   /// \param theAIS an AIS object
164   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
165   /// \returns true if the presentation is created
166   //bool redisplay(ObjectPtr theObject,
167   //               AISObjectPtr theAIS, 
168   //               const bool isUpdateViewer = true);
169
170   /** Redisplay the shape if it was displayed
171    * \param theFeature a feature instance
172    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
173    */
174   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
175
176  protected:
177   XGUI_Workshop* myWorkshop;
178
179   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
180   ResultToAISMap myResult2AISObjectMap;
181
182   // A flag of initialization of external objects selection
183   bool myUseExternalObjects;
184   // Selection modes installed for external objects in local context
185   QIntList myActiveSelectionModes;
186 };
187
188 #endif