]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Displayer.h
Salome HOME
7fbbd814d07e758e733545588f25d6b9d2407f9e
[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    enum DisplayMode { NoMode = -1, Wireframe, Shading };
39
40   /// Constructor
41   /// \param theViewer the viewer
42   XGUI_Displayer(XGUI_Workshop* theWorkshop);
43   /// Destructor
44   virtual ~XGUI_Displayer();
45
46   /// Returns the feature visibility state.
47   /// \param theFeature a feature instance
48   bool isVisible(ObjectPtr theObject) const;
49
50   /// Display the feature. Obtain the visualized object from the feature.
51   /// \param theFeature a feature instance
52   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
53   /// Returns true if the Feature succesfully displayed
54   void display(ObjectPtr theObject, bool isUpdateViewer = true);
55
56   /// Display the given AIS object. To hide this object use corresponde erase method
57   void displayAIS(AISObjectPtr theAIS, bool isUpdate = true);
58
59   /// Stop the current selection and color the given features to the selection color
60   /// \param theFeatures a list of features to be disabled
61   /// \param theToStop the boolean state whether it it stopped or non stopped
62   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
63   void stopSelection(const QObjectPtrList& theFeatures, const bool isStop,
64                      const bool isUpdateViewer);
65
66   /**
67    * Add presentations which corresponds to the given features to current selection
68    * \param theFeatures a list of features to be selected
69    * isUpdateViewer the parameter whether the viewer should be update immediatelly
70    */
71   void setSelected(const QObjectPtrList& theFeatures, bool isUpdateViewer = true);
72
73
74   /// Un select all objects
75   void clearSelected();
76
77   /// Erase the feature and a shape.
78   /// \param theFeature a feature instance
79   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
80   void erase(ObjectPtr theObject, const bool isUpdateViewer = true);
81
82   /// Erase the given AIS object displayed by corresponded display method
83   void eraseAIS(AISObjectPtr theAIS, const bool isUpdate = true);
84
85   /// Erase all presentations
86   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
87   void eraseAll(const bool isUpdateViewer = true);
88
89   /// Erase AIS interactive objects, which has an empty feature in the internal map
90   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
91   void eraseDeletedResults(const bool isUpdateViewer = true);
92
93   /// Opens local context. Does nothing if it is already opened.
94   void openLocalContext();
95
96   /// Deactivates selection of sub-shapes
97   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
98   void closeLocalContexts(const bool isUpdateViewer = true);
99
100   void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
101
102   void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
103
104   void removeFilters();
105
106   /// Updates the viewer
107   void updateViewer();
108
109   /// Searches the interactive object by feature
110   /// \param theFeature the feature or NULL if it not visualized
111   /// \return theIO an interactive object
112   AISObjectPtr getAISObject(ObjectPtr theFeature) const;
113
114   /// Searches the feature by interactive object
115   /// \param theIO an interactive object
116   /// \return feature the feature or NULL if it not visualized
117   ObjectPtr getObject(const AISObjectPtr& theIO) const;
118   ObjectPtr getObject(const Handle(AIS_InteractiveObject)& theIO) const;
119
120   /// Deactivates the given object (not allow selection)
121   void deactivate(ObjectPtr theFeature);
122
123   /// Activates the given object (it can be selected)
124   /// \param theModes - modes on which it has to be activated (can be empty)
125   void activate(ObjectPtr theFeature, const QIntList& theModes);
126
127   /// Activates the given object with default modes
128   void activate(ObjectPtr theFeature);
129
130   /// Returns true if the given object can be selected
131   bool isActive(ObjectPtr theObject) const;
132
133   /// Activates in local context displayed outside of the context.
134   /// \param theModes - modes on which it has to be activated (can be empty)
135   void activateObjects(const QIntList& theModes);
136
137   /// Activates in local context displayed outside of the context.
138   void deactivateObjects();
139
140   /// Sets display mode for the given object if this object is displayed
141   void setDisplayMode(ObjectPtr theObject, DisplayMode theMode, bool toUpdate = true);
142
143   /// Returns current display mode for the given object.
144   /// If object is not dis played then returns NoMode.
145   DisplayMode displayMode(ObjectPtr theObject) const;
146
147
148   /// Displays only objects listed in the list
149   void showOnly(const QObjectPtrList& theList);
150
151   /// Returns number of displayed objects
152   int objectsCount() const { return myResult2AISObjectMap.size(); }
153
154  protected:
155   /// Returns currently installed AIS_InteractiveContext
156   Handle(AIS_InteractiveContext) AISContext() const;
157
158   /// Returns the viewer context top filter. If there is no a filter, it is created and set into
159   /// The context should have only this filter inside. Other filters should be add to the filter
160   Handle(SelectMgr_AndFilter) GetFilter();
161
162   /// Display the feature and a shape. This shape would be associated to the given feature
163   /// \param theFeature a feature instance
164   /// \param theAIS AIS presentation
165   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
166   /// Returns true if the Feature succesfully displayed
167   void display(ObjectPtr theObject, AISObjectPtr theAIS, bool isShading,
168                bool isUpdateViewer = true);
169
170   /// Display the shape and activate selection of sub-shapes
171   /// \param theFeature a feature instance
172   /// \param theAIS an AIS object
173   /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
174   /// \returns true if the presentation is created
175   //bool redisplay(ObjectPtr theObject,
176   //               AISObjectPtr theAIS, 
177   //               const bool isUpdateViewer = true);
178
179   /** Redisplay the shape if it was displayed
180    * \param theFeature a feature instance
181    * \param isUpdateViewer the parameter whether the viewer should be update immediatelly
182    */
183   void redisplay(ObjectPtr theObject, bool isUpdateViewer = true);
184
185  protected:
186   XGUI_Workshop* myWorkshop;
187
188   Handle(SelectMgr_AndFilter) myAndFilter;
189
190   typedef QMap<ObjectPtr, AISObjectPtr> ResultToAISMap;
191   ResultToAISMap myResult2AISObjectMap;
192
193   // A flag of initialization of external objects selection
194   bool myUseExternalObjects;
195   // Selection modes installed for external objects in local context
196   QIntList myActiveSelectionModes;
197 };
198
199 #endif