]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
75f424311721f4573a9f8535fe50b70e80a5a66d
[modules/shaper.git] / src / XGUI / XGUI_Displayer.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        XGUI_Displayer.h
4 // Created:     20 Apr 2014
5 // Author:      Natalia ERMOLAEVA
6
7 #ifndef XGUI_Displayer_H
8 #define XGUI_Displayer_H
9
10 #include "XGUI.h"
11
12 #include <GeomAPI_AISObject.h>
13 #include <TopoDS_Shape.hxx>
14 #include <AIS_InteractiveObject.hxx>
15 #include <AIS_InteractiveContext.hxx>
16 #include <NCollection_List.hxx>
17
18 #include <ModelAPI_Result.h>
19
20 #include <ModuleBase_Definitions.h>
21 #include <ModuleBase_ViewerPrs.h>
22
23 #include <SelectMgr_AndFilter.hxx>
24
25 #include <QString>
26 #include <QMap>
27
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    /// Enumeration of possible display mode
39    enum DisplayMode { 
40      NoMode = -1, /// Mode is not defined
41      Wireframe,   /// Wireframe display mode
42      Shading      /// Shading display mode
43    };
44
45   /// Constructor
46   /// \param theWorkshop a workshop instance
47   XGUI_Displayer(XGUI_Workshop* theWorkshop);
48
49   /// Destructor
50   virtual ~XGUI_Displayer();
51
52   /// Returns the feature visibility state.
53   /// \param theObject an object instance
54   bool isVisible(ObjectPtr theObject) const;
55
56   /// Display the feature. Obtain the visualized object from the feature.
57   /// \param theObject an object to display
58   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
59   /// Returns true if the Feature succesfully displayed
60   void display(ObjectPtr theObject, bool isUpdateViewer = true);
61
62   /// Display the given AIS object. To hide this object use corresponde erase method
63   /// \param theAIS AIOS object to display
64   /// \param isUpdate the parameter whether the viewer should be update immediatelly
65   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
66
67   /**
68    * Add presentations which corresponds to the given features to current selection
69    * \param theFeatures a list of features to be selected
70    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
71    */
72   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
73
74
75   /// Unselect all objects
76   void clearSelected();
77
78   /// Erase the feature and a shape.
79   /// \param theObject an object instance
80   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
81   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
82
83   /// Erase the given AIS object displayed by corresponded display method
84   /// \param theAIS instance of AIS object
85   /// \param isUpdate the parameter whether the viewer should be update immediatelly
86   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
87
88   /// Erase all presentations
89   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
90   void eraseAll(const bool isUpdateViewer = true);
91
92   /// Deactivates selection of sub-shapes
93   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
94   void closeLocalContexts(const bool isUpdateViewer = true);
95
96   /// \brief Add selection filter
97   /// \param theFilter a filter instance
98   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
99
100   /// \brief Remove selection filter
101   /// \param theFilter a filter instance
102   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
103
104   /// Remove all selection filters
105   void removeFilters();
106
107   /**
108    * Sets a flag to the displayer whether the internal viewer can be updated by 
109    * the updateViewer method call. If it is not enabled, this method do nothing
110    * \param isEnabled a boolean value
111    */
112   bool enableUpdateViewer(const bool isEnabled);
113
114   /// Updates the viewer
115   void updateViewer();
116
117   /// Searches the interactive object by feature
118   /// \param theObject the object or presentable feature
119   /// \return theIO an interactive object
120   AISObjectPtr getAISObject(ObjectPtr theObject) const;
121
122   /// Searches the feature by interactive object
123   /// \param theIO an interactive object
124   /// \return feature the feature or NULL if it not visualized
125   ObjectPtr getObject(const AISObjectPtr& theIO) const;
126
127   /// Searches the feature by interactive object
128   /// \param theIO an interactive object
129   /// \return corresponded object or NULL if it not found
130   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
131
132   /// Deactivates the given object (not allow selection)
133   /// \param theObject object to deactivate
134   void deactivate(ObjectPtr theObject);
135
136   /// Activates the given object (it can be selected)
137   /// \param theObject object to activate
138   /// \param theModes - modes on which it has to be activated (can be empty)
139   void activate(ObjectPtr theObject, const QIntList& theModes);
140
141   /// Returns the modes of activation
142   /// \param theObject the feature or NULL if it not visualized
143   /// \param theModes - modes on which it is activated (can be empty)
144   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
145
146   /// Activates the given object with default modes
147   /// \param theObject object to activate
148   void activate(ObjectPtr theObject);
149
150   /// Returns true if the given object can be selected
151   /// \param theObject object to check
152   bool isActive(ObjectPtr theObject) const;
153
154   /// Activates in local context displayed outside of the context.
155   /// \param theModes - modes on which it has to be activated (can be empty)
156   void activateObjects(const QIntList& theModes);
157
158   /// Activates in local context displayed outside of the context.
159   void deactivateObjects();
160
161   /// Sets display mode for the given object if this object is displayed
162   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
163
164   /// Returns current display mode for the given object.
165   /// If object is not dis played then returns NoMode.
166   /// \param theObject object to check
167   DisplayMode displayMode(ObjectPtr theObject) const;
168
169   /// Displays only objects listed in the list
170   /// \param theList list of objects
171   void showOnly(const QObjectPtrList& theList);
172
173   /// Returns number of displayed objects
174   int objectsCount() const { return myResult2AISObjectMap.size(); }
175
176   /// Returns list of displayed objects
177   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
178
179   /// Returns true if the given object can be shown in shaded mode
180   /// \param theObject object to check
181   bool canBeShaded(ObjectPtr theObject) const;
182
183  protected:
184   /// Returns currently installed AIS_InteractiveContext
185   Handle(AIS_InteractiveContext) AISContext() const;
186
187   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
188   /// The context should have only this filter inside. Other filters should be add to the filter
189   Handle(SelectMgr_AndFilter) GetFilter();
190
191   /// Display the feature and a shape. This shape would be associated to the given feature
192   /// \param theObject an object instance
193   /// \param theAIS AIS presentation
194   /// \param isShading flag to show in shading mode
195   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
196   /// \return true if the object is succesfully displayed
197   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
198                bool isUpdateViewer = true);
199
200   /** Redisplay the shape if it was displayed
201    * \param theObject an object instance
202    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
203    */
204   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
205
206   /// Opens local context. Does nothing if it is already opened.
207   void openLocalContext();
208
209  protected:
210    /// Reference to workshop
211   XGUI_Workshop* myWorkshop;
212
213   /// A container for selection filters
214   Handle(SelectMgr_AndFilter) myAndFilter;
215
216   /// Definition of a type of map which defines correspondance between objects and presentations
217   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
218
219   /// A map of displayed objects
220   ResultToAISMap myResult2AISObjectMap;
221
222   /// Selection modes installed for external objects in local context
223   QIntList myActiveSelectionModes;
224
225   /// the enable update viewer flag
226   bool myEnableUpdateViewer;  
227 };
228
229 #endif