0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / TPrsStd / TPrsStd_AISPresentation.hxx
1 // Created on: 1998-09-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _TPrsStd_AISPresentation_HeaderFile
18 #define _TPrsStd_AISPresentation_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <Standard_GUID.hxx>
24 #include <Standard_Real.hxx>
25 #include <Quantity_NameOfColor.hxx>
26 #include <Graphic3d_NameOfMaterial.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <TDF_Attribute.hxx>
30 #include <TDataXtd_Presentation.hxx>
31 #include <AIS_InteractiveContext.hxx>
32
33 class AIS_InteractiveObject;
34 class Standard_GUID;
35 class TDF_Label;
36 class TDF_Attribute;
37 class TDF_RelocationTable;
38 class TDF_AttributeDelta;
39
40 class TPrsStd_AISPresentation;
41 DEFINE_STANDARD_HANDLE(TPrsStd_AISPresentation, TDF_Attribute)
42
43 //! An attribute to associate an
44 //! AIS_InteractiveObject to a label in an AIS viewer.
45 //! This attribute works in collaboration with TPrsStd_AISViewer.
46 //! Note that all the Set... and Unset... attribute
47 //! methods as well as the query methods for
48 //! visualization attributes and the HasOwn... test
49 //! methods are shortcuts to the respective
50 //! AIS_InteractiveObject settings.
51 class TPrsStd_AISPresentation : public TDF_Attribute
52 {
53
54 public:
55
56   
57   //! Returns the GUID for TPrsStd_AISPresentation attributes.
58   Standard_EXPORT static const Standard_GUID& GetID();
59   
60   //! Creates or retrieves the presentation attribute on
61   //! the label L, and sets the GUID driver.
62   Standard_EXPORT static Handle(TPrsStd_AISPresentation) Set (const TDF_Label& L, const Standard_GUID& driver);
63   
64   //! Delete (if exist) the presentation attribute associated to the label <L>.
65   Standard_EXPORT static void Unset (const TDF_Label& L);
66   
67   //! Creates or retrieves the AISPresentation
68   //! attribute attached to master.
69   //! The GUID of the driver will be the GUID of master.
70   //! master is the attribute you want to display.
71   Standard_EXPORT static Handle(TPrsStd_AISPresentation) Set (const Handle(TDF_Attribute)& master);
72   
73   Standard_EXPORT TPrsStd_AISPresentation();
74   
75   Standard_EXPORT void SetDisplayed (const Standard_Boolean B);
76   
77   //! Display presentation of object in AIS viewer.
78   //! If <update> = True then AISObject is recomputed and all
79   //! the visualization settings are applied
80   Standard_EXPORT void Display (const Standard_Boolean update = Standard_False);
81   
82   //! Removes the presentation of this AIS
83   //! presentation attribute from the TPrsStd_AISViewer.
84   //! If remove is true, this AIS presentation attribute
85   //! is removed from the interactive context.
86   Standard_EXPORT void Erase (const Standard_Boolean remove = Standard_False);
87   
88   //! Recompute presentation of object and apply the visualization settings
89   Standard_EXPORT void Update();
90   
91   Standard_EXPORT Standard_GUID GetDriverGUID() const;
92   
93   Standard_EXPORT void SetDriverGUID (const Standard_GUID& guid);
94   
95
96   //! Returns true if this AIS presentation attribute is displayed.
97   Standard_EXPORT Standard_Boolean IsDisplayed() const;
98   
99   //! Returns AIS_InteractiveObject stored in the presentation attribute
100   Standard_EXPORT Handle(AIS_InteractiveObject) GetAIS() const;
101   
102
103   //! Returns the material setting for this presentation attribute.
104   Standard_EXPORT Graphic3d_NameOfMaterial Material() const;
105   
106   //! Sets the material aName for this presentation  attribute.
107   Standard_EXPORT void SetMaterial (const Graphic3d_NameOfMaterial aName);
108   
109   //! Returns true if this presentation attribute already has a material setting.
110   Standard_EXPORT Standard_Boolean HasOwnMaterial() const;
111   
112   //! Removes the material setting from this presentation attribute.
113   Standard_EXPORT void UnsetMaterial();
114   
115
116   //! Sets the transparency value aValue for this
117   //! presentation attribute.
118   //! This value is 0.6 by default.
119   Standard_EXPORT void SetTransparency (const Standard_Real aValue = 0.6);
120   
121   Standard_EXPORT Standard_Real Transparency() const;
122   
123   //! Returns true if this presentation attribute already has a transparency setting.
124   Standard_EXPORT Standard_Boolean HasOwnTransparency() const;
125   
126   //! Removes the transparency setting from this presentation attribute.
127   Standard_EXPORT void UnsetTransparency();
128   
129   Standard_EXPORT Quantity_NameOfColor Color() const;
130   
131   //! Sets the color aColor for this presentation attribute.
132   Standard_EXPORT void SetColor (const Quantity_NameOfColor aColor);
133   
134   //! Returns true if this presentation attribute already has a color setting.
135   Standard_EXPORT Standard_Boolean HasOwnColor() const;
136   
137   //! Removes the color setting from this presentation attribute.
138   Standard_EXPORT void UnsetColor();
139   
140   Standard_EXPORT Standard_Real Width() const;
141   
142   //! Sets the width aWidth for this presentation attribute.
143   Standard_EXPORT void SetWidth (const Standard_Real aWidth);
144   
145   //! Returns true if this presentation attribute already has a width setting.
146   Standard_EXPORT Standard_Boolean HasOwnWidth() const;
147   
148   //! Removes the width setting from this presentation attribute.
149   Standard_EXPORT void UnsetWidth();
150   
151   Standard_EXPORT Standard_Integer Mode() const;
152   
153   Standard_EXPORT void SetMode (const Standard_Integer theMode);
154   
155   Standard_EXPORT Standard_Boolean HasOwnMode() const;
156   
157   Standard_EXPORT void UnsetMode();
158
159   //! Returns selection mode(s) of the attribute.
160   //! It starts with 1 .. GetNbSelectionModes().
161   Standard_EXPORT Standard_Integer GetNbSelectionModes() const;
162   Standard_EXPORT Standard_Integer SelectionMode(const int index = 1) const;
163
164   //! Sets selection mode.
165   //! If "theTransaction" flag is OFF, modification of the attribute doesn't influence the transaction mechanism
166   //! (the attribute doesn't participate in undo/redo because of this modification).
167   //! Certainly, if any other data of the attribute is modified (display mode, color, ...),
168   //! the attribute will be included into undo/redo.
169   Standard_EXPORT void SetSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
170   Standard_EXPORT void AddSelectionMode(const Standard_Integer theSelectionMode, const Standard_Boolean theTransaction = Standard_True);
171
172   Standard_EXPORT Standard_Boolean HasOwnSelectionMode() const;
173   
174   //! Clears all selection modes of the attribute.
175   Standard_EXPORT void UnsetSelectionMode();
176   
177   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
178   
179   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
180   
181   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
182   
183   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
184   
185   Standard_EXPORT virtual Handle(TDF_Attribute) BackupCopy() const Standard_OVERRIDE;
186   
187   Standard_EXPORT virtual void AfterAddition() Standard_OVERRIDE;
188   
189   Standard_EXPORT virtual void BeforeRemoval() Standard_OVERRIDE;
190   
191   Standard_EXPORT virtual void BeforeForget() Standard_OVERRIDE;
192   
193   Standard_EXPORT virtual void AfterResume() Standard_OVERRIDE;
194   
195   Standard_EXPORT virtual Standard_Boolean BeforeUndo (const Handle(TDF_AttributeDelta)& anAttDelta, const Standard_Boolean forceIt = Standard_False) Standard_OVERRIDE;
196   
197   //! update AIS viewer according to delta
198   Standard_EXPORT virtual Standard_Boolean AfterUndo (const Handle(TDF_AttributeDelta)& anAttDelta, const Standard_Boolean forceIt = Standard_False) Standard_OVERRIDE;
199
200   DEFINE_STANDARD_RTTIEXT(TPrsStd_AISPresentation,TDF_Attribute)
201
202 protected:
203
204   //! Returns attribute storing presentation data
205   Standard_EXPORT virtual Handle(TDataXtd_Presentation) getData () const;
206
207 private:
208
209   Handle(AIS_InteractiveContext) getAISContext() const;
210
211   //! Activates selection mode of the interactive object.
212   //! It is called internally on change of selection mode and AISUpdate().
213   void ActivateSelectionMode();
214   
215   //! Updates AIS_InteractiveObject stored in the attribute
216   //! and applies the visualization settings
217   Standard_EXPORT void AISUpdate();
218   
219   //! Displays AIS_InteractiveObject stored in the attribute
220   Standard_EXPORT void AISDisplay();
221   
222   //! Erases AIS_InteractiveObject stored in the attribute in
223   //! the viewer; If <remove> = True then AISObject is removed
224   //! from AIS_InteractiveContext instead of simple erasing in the viewer
225   Standard_EXPORT void AISErase (const Standard_Boolean remove = Standard_False);
226
227 private:
228   Handle(AIS_InteractiveObject) myAIS;
229 };
230
231 #endif // _TPrsStd_AISPresentation_HeaderFile