0029940: The method TPrsStd_AISPresentation::SetSelectionMode() seems useless for...
[occt.git] / src / TDataXtd / TDataXtd_Shape.cxx
1 // Created on: 2009-04-06
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BRep_Builder.hxx>
18 #include <Standard_GUID.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDataStd.hxx>
21 #include <TDataXtd.hxx>
22 #include <TDataXtd_Shape.hxx>
23 #include <TDF_Attribute.hxx>
24 #include <TDF_DataSet.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_RelocationTable.hxx>
27 #include <TNaming.hxx>
28 #include <TNaming_Builder.hxx>
29 #include <TNaming_NamedShape.hxx>
30 #include <TNaming_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Solid.hxx>
33
34 IMPLEMENT_STANDARD_RTTIEXT(TDataXtd_Shape,TDF_Attribute)
35
36 //=======================================================================
37 //function : Find
38 //purpose  : 
39 //=======================================================================
40 Standard_Boolean TDataXtd_Shape::Find (const TDF_Label& current,
41                                       Handle(TDataXtd_Shape)& S) 
42 {  
43   TDF_Label L = current;
44   Handle(TDataXtd_Shape) SA;
45   if (L.IsNull()) return Standard_False; 
46   for(;;) {
47     if(L.FindAttribute(TDataXtd_Shape::GetID(), SA))  break;
48     L = L.Father();
49     if (L.IsNull()) break; 
50   }
51   
52   
53   if (!SA.IsNull()) { 
54     S = SA;
55     return Standard_True; 
56   }
57   return Standard_False; 
58 }
59
60
61 //=======================================================================
62 //function : New
63 //purpose  : 
64 //=======================================================================
65
66 Handle(TDataXtd_Shape) TDataXtd_Shape::New (const TDF_Label& label)
67 {  
68   if (label.HasAttribute()) {
69     throw Standard_DomainError("TDataXtd_Shape::New : not an empty label");
70   }
71   Handle(TDataXtd_Shape) A = new TDataXtd_Shape ();  
72   label.AddAttribute(A);                     
73   return A;
74 }
75
76 //=======================================================================
77 //function : Set
78 //purpose  : 
79 //=======================================================================
80
81 Handle(TDataXtd_Shape) TDataXtd_Shape::Set (const TDF_Label& label, const TopoDS_Shape& shape)
82 {
83   Handle(TDataXtd_Shape) A;  
84   if (!label.FindAttribute(TDataXtd_Shape::GetID(),A)) { 
85     A = TDataXtd_Shape::New (label);
86   }  
87
88   Handle(TNaming_NamedShape) aNS;
89   if(label.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
90     if(!aNS->Get().IsNull())
91       if(aNS->Get() == shape)
92         return A;
93   }
94
95   TNaming_Builder B(label);
96   B.Generated(shape);
97   return A; 
98 }
99
100 //=======================================================================
101 //function : Get
102 //purpose  : 
103 //=======================================================================
104
105 TopoDS_Shape TDataXtd_Shape::Get (const TDF_Label& label)
106 {
107   TopoDS_Shape shape;
108
109   Handle(TNaming_NamedShape) NS;
110   if( label.FindAttribute(TNaming_NamedShape::GetID(), NS)) {
111     shape = TNaming_Tool::GetShape(NS);
112     return shape;
113   }
114
115   shape.Nullify();  
116   return shape; 
117 }
118
119 //=======================================================================
120 //function : GetID
121 //purpose  : 
122 //=======================================================================
123
124 const Standard_GUID& TDataXtd_Shape::GetID() 
125 {
126   static Standard_GUID TDataXtd_ShapeID("2a96b620-ec8b-11d0-bee7-080009dc3333");
127   return TDataXtd_ShapeID;
128 }
129
130 //=======================================================================
131 //function : TDataXtd_Shape
132 //purpose  : 
133 //=======================================================================
134
135 TDataXtd_Shape::TDataXtd_Shape()
136 {
137 }
138
139 //=======================================================================
140 //function : ID
141 //purpose  : 
142 //=======================================================================
143
144 const Standard_GUID& TDataXtd_Shape::ID() const
145 { return GetID(); }
146
147
148 //=======================================================================
149 //function : NewEmpty
150 //purpose  : 
151 //=======================================================================
152
153 Handle(TDF_Attribute) TDataXtd_Shape::NewEmpty () const
154 {  
155   return new TDataXtd_Shape(); 
156 }
157
158 //=======================================================================
159 //function : Restore
160 //purpose  : 
161 //=======================================================================
162
163 void TDataXtd_Shape::Restore(const Handle(TDF_Attribute)& ) 
164 {  
165 }
166
167 //=======================================================================
168 //function : Paste
169 //purpose  : 
170 //=======================================================================
171
172 void TDataXtd_Shape::Paste (const Handle(TDF_Attribute)&,
173                            const Handle(TDF_RelocationTable)&) const
174 {  
175 }
176
177 //=======================================================================
178 //function : References
179 //purpose  : 
180 //=======================================================================
181
182 void TDataXtd_Shape::References (const Handle(TDF_DataSet)&) const
183 {  
184 }
185  
186 //=======================================================================
187 //function : Dump
188 //purpose  : 
189 //=======================================================================
190
191 Standard_OStream& TDataXtd_Shape::Dump (Standard_OStream& anOS) const
192 {  
193   anOS << "Shape";
194   return anOS;
195 }