]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
Issue #849 (#775) Crash in second study during sketch operation
[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 <GeomAPI_ICustomPrs.h>
24
25 #include <SelectMgr_AndFilter.hxx>
26
27 #include <QString>
28 #include <QMap>
29 #include <QObject>
30 #include <QColor>
31
32 class ModelAPI_Feature;
33 class XGUI_Workshop;
34
35 /**\class XGUI_Displayer
36  * \ingroup GUI
37  * \brief Displayer. Provides mechanizm of display/erase of objects in the viewer
38  */
39 class XGUI_EXPORT XGUI_Displayer: public QObject
40 {
41   Q_OBJECT
42  public:
43    /// \enum DisplayMode display mode
44    enum DisplayMode { 
45      /// Mode is not defined
46      NoMode = -1, 
47      /// Wireframe display mode
48      Wireframe, 
49      /// Shading display mode
50      Shading      
51    };
52
53   /// Constructor
54   /// \param theWorkshop a workshop instance
55   XGUI_Displayer(XGUI_Workshop* theWorkshop);
56
57   /// Destructor
58   virtual ~XGUI_Displayer();
59
60   /// Returns the feature visibility state.
61   /// \param theObject an object instance
62   bool isVisible(ObjectPtr theObject) const;
63
64   /// Display the feature. Obtain the visualized object from the feature.
65   /// \param theObject an object to display
66   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
67   /// Returns true if the Feature succesfully displayed
68   void display(ObjectPtr theObject, bool theUpdateViewer = true);
69
70   /// Display the given AIS object. This object is not added to the displayer internal map of objects
71   /// So, it can not be obtained from displayer. This is just a wrap method of OCC display in order
72   /// to perform the display with correct flags.
73   /// \param theAIS AIOS object to display
74   /// \param toActivateInSelectionModes boolean value whether the presentation should be
75   /// activated in the current selection modes
76   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
77   void displayAIS(AISObjectPtr theAIS, const bool toActivateInSelectionModes,
78                   bool theUpdateViewer = true);
79
80   /** Redisplay the shape if it was displayed
81    * \param theObject an object instance
82    * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
83    */
84   void redisplay(ObjectPtr theObject, bool theUpdateViewer = true);
85
86   /**
87    * Add presentations to current selection. It unhighlight and deselect the current selection.
88    * The shape and result components are processed in the values. If the presentation shape is not
89    * empty, select it, otherwise select the result.
90    * \param theValues a list of presentation to be selected
91    * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
92    */
93   void setSelected(const  QList<ModuleBase_ViewerPrs>& theValues, bool theUpdateViewer = true);
94
95
96   /// Unselect all objects
97   void clearSelected();
98
99   /// Erase the feature and a shape.
100   /// \param theObject an object instance
101   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
102   void erase(ObjectPtr theObject, const bool theUpdateViewer = true);
103
104   /// Erase the given AIS object displayed by corresponded display method
105   /// \param theAIS instance of AIS object
106   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
107   void eraseAIS(AISObjectPtr theAIS, const bool theUpdateViewer = true);
108
109   /// Erase all presentations
110   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
111   void eraseAll(const bool theUpdateViewer = true);
112
113   /// Deactivates selection of sub-shapes
114   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
115   void closeLocalContexts(const bool theUpdateViewer = true);
116
117   /// \brief Add selection filter
118   /// \param theFilter a filter instance
119   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
120
121   /// \brief Remove selection filter
122   /// \param theFilter a filter instance
123   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
124
125   /// Returns true if the selection filter is set to the viewer
126   /// \param theFilter a selection filter
127   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
128
129   /// Remove all selection filters
130   void removeFilters();
131
132   /**
133    * Sets a flag to the displayer whether the internal viewer can be updated by 
134    * the updateViewer method call. If it is not enabled, this method do nothing
135    * \param isEnabled a boolean value
136    */
137   bool enableUpdateViewer(const bool isEnabled);
138
139   /// Updates the viewer
140   void updateViewer() const;
141
142   /// Activate interactive context
143   /// \param theIO
144   /// \param theMode
145   void activateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode,
146                    const bool theUpdateViewer) const;
147
148   /// Activate interactive context. It is necessary to call ClearOutdatedSelection after deactivation
149   void deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, const int theMode = -1) const;
150
151   /// Searches the interactive object by feature
152   /// \param theObject the object or presentable feature
153   /// \return theIO an interactive object
154   AISObjectPtr getAISObject(ObjectPtr theObject) const;
155
156   /// Searches the feature by interactive object
157   /// \param theIO an interactive object
158   /// \return feature the feature or NULL if it not visualized
159   ObjectPtr getObject(const AISObjectPtr& theIO) const;
160
161   /// Searches the feature by interactive object
162   /// \param theIO an interactive object
163   /// \return corresponded object or NULL if it not found
164   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
165
166   /// Deactivates the given object (not allow selection)
167   /// \param theObject object to deactivate
168   void deactivate(ObjectPtr theObject, const bool theUpdateViewer);
169
170   /// Activates the given object (it can be selected)
171   /// \param theObject object to activate
172   /// \param theModes - modes on which it has to be activated (can be empty)
173   //void activate(ObjectPtr theObject, const QIntList& theModes);
174
175   /// Returns the modes of activation
176   /// \param theObject the feature or NULL if it not visualized
177   /// \param theModes - modes on which it is activated (can be empty)
178   void getModesOfActivation(ObjectPtr theObject, QIntList& theModes);
179
180   /// Activates the given object with default modes
181   /// \param theObject object to activate
182   //void activate(ObjectPtr theObject);
183
184   /// Returns true if the given object can be selected
185   /// \param theObject object to check
186   bool isActive(ObjectPtr theObject) const;
187
188   /// Activates in local context displayed outside of the context.
189   /// \param theModes - modes on which it has to be activated (can be empty)
190   /// \param theObjList - list of objects which has to be activated.
191   void activateObjects(const QIntList& theModes, const QObjectPtrList& theObjList,
192                        const bool theUpdateViewer = true);
193
194   /// Sets display mode for the given object if this object is displayed
195   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool theUpdateViewer = true);
196
197   /// Returns current display mode for the given object.
198   /// If object is not dis played then returns NoMode.
199   /// \param theObject object to check
200   DisplayMode displayMode(ObjectPtr theObject) const;
201
202   /// Displays only objects listed in the list
203   /// \param theList list of objects
204   void showOnly(const QObjectPtrList& theList);
205
206   /// Returns number of displayed objects
207   int objectsCount() const { return myResult2AISObjectMap.size(); }
208
209   /// Returns list of displayed objects
210   QObjectPtrList displayedObjects() const { return myResult2AISObjectMap.keys(); }
211
212   /// Returns list of displayed objects
213   QList<AISObjectPtr> displayedPresentations() const { return myResult2AISObjectMap.values(); }
214
215   /// Returns true if the given object can be shown in shaded mode
216   /// \param theObject object to check
217   bool canBeShaded(ObjectPtr theObject) const;
218
219   /// Set color on presentation of an object if it is displayed
220   /// \param theObject an object 
221   /// \param theColor a color which has to be set
222   /// \param theUpdateViewer update viewer flag
223   /// \return previously defined color on the object
224   QColor setObjectColor(ObjectPtr theObject, const QColor& theColor, bool theUpdateViewer = true);
225
226 signals:
227   /// Signal on object display
228   /// \param theObject a data object
229   /// \param theAIS a presentation object
230   void objectDisplayed(ObjectPtr theObject, AISObjectPtr theAIS);
231
232   /// Signal on before object erase
233   /// \param theObject a data object
234   /// \param theAIS a presentation object
235   void beforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS);
236
237  protected:
238   /// Returns currently installed AIS_InteractiveContext
239   Handle(AIS_InteractiveContext) AISContext() const;
240
241   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
242   /// The context should have only this filter inside. Other filters should be add to the filter
243   Handle(SelectMgr_AndFilter) GetFilter();
244
245   /// Display the feature and a shape. This shape would be associated to the given feature
246   /// \param theObject an object instance
247   /// \param theAIS AIS presentation
248   /// \param isShading flag to show in shading mode
249   /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
250   /// \return true if the object is succesfully displayed
251   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
252                bool theUpdateViewer = true);
253
254 private:
255   /// Activates the interactive object in the local context.
256   /// \param theIO an interactive object
257   /// \param theModes - modes on which it has to be activated (can be empty)
258   void activate(const Handle(AIS_InteractiveObject)& theIO, const QIntList& theModes,
259                 const bool theUpdateViewer) const;
260
261   /// Find a trihedron in a list of displayed presentations and deactivate it.
262   void deactivateTrihedron() const;
263
264   /// Opens local context. Does nothing if it is already opened.
265   void openLocalContext();
266
267   /** Update the object presentable properties such as color, lines width and other
268    * If the object is result with the color attribute value set, it is used,
269    * otherwise the customize is applyed to the object's feature if it is a custom prs
270    * \param theObject an object instance
271    * \return the true state if there is changes and the presentation is customized
272    */
273   bool customizeObject(ObjectPtr theObject);
274
275   /// Append the objects in the internal map. Checks whether the map already contains the object
276   /// \param theObject an object to display
277   /// \param theAIS AIOS object to display
278   void appendResultObject(ObjectPtr theObject, AISObjectPtr theAIS);
279
280   /// Returns an information about alredy displayed objects
281   /// \return a string representation
282   std::string getResult2AISObjectMapInfo() const;
283
284  protected:
285    /// Reference to workshop
286   XGUI_Workshop* myWorkshop;
287
288   /// A container for selection filters
289   Handle(SelectMgr_AndFilter) myAndFilter;
290
291   /// A default custom presentation, which is used if the displayed feature is not a custom presentation
292   GeomCustomPrsPtr myCustomPrs;
293
294   /// Definition of a type of map which defines correspondance between objects and presentations
295   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
296
297   /// A map of displayed objects
298   ResultToAISMap myResult2AISObjectMap;
299
300   /// Selection modes installed for external objects in local context
301   QIntList myActiveSelectionModes;
302
303   /// the enable update viewer flag
304   bool myEnableUpdateViewer;  
305 };
306
307 #endif