b311480e |
1 | // Created on: 2009-04-06 |
2 | // Created by: Sergey ZARITCHNY |
3 | // Copyright (c) 2009-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | |
21 | |
22 | #include <TDataXtd_Shape.ixx> |
23 | #include <TDataStd.hxx> |
24 | #include <TDataXtd.hxx> |
25 | #include <TDF_Label.hxx> |
26 | #include <BRep_Builder.hxx> |
27 | #include <TopoDS_Solid.hxx> |
28 | #include <TNaming_Builder.hxx> |
29 | #include <TNaming_NamedShape.hxx> |
30 | #include <TNaming_Tool.hxx> |
31 | #include <TNaming.hxx> |
32 | |
33 | #define OCC2932 |
34 | //======================================================================= |
35 | //function : Find |
36 | //purpose : |
37 | //======================================================================= |
38 | |
39 | Standard_Boolean TDataXtd_Shape::Find (const TDF_Label& current, |
40 | Handle(TDataXtd_Shape)& S) |
41 | { |
42 | TDF_Label L = current; |
43 | Handle(TDataXtd_Shape) SA; |
44 | if (L.IsNull()) return Standard_False; |
302f96fb |
45 | for(;;) { |
7fd59977 |
46 | if(L.FindAttribute(TDataXtd_Shape::GetID(), SA)) break; |
47 | L = L.Father(); |
48 | if (L.IsNull()) break; |
49 | } |
50 | |
51 | |
52 | if (!SA.IsNull()) { |
53 | S = SA; |
54 | return Standard_True; |
55 | } |
56 | return Standard_False; |
57 | } |
58 | |
59 | |
60 | //======================================================================= |
61 | //function : New |
62 | //purpose : |
63 | //======================================================================= |
64 | |
65 | Handle(TDataXtd_Shape) TDataXtd_Shape::New (const TDF_Label& label) |
66 | { |
67 | if (label.HasAttribute()) { |
68 | Standard_DomainError::Raise("TDataXtd_Shape::New : not an empty label"); |
69 | } |
70 | Handle(TDataXtd_Shape) A = new TDataXtd_Shape (); |
71 | label.AddAttribute(A); |
72 | return A; |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : Set |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | Handle(TDataXtd_Shape) TDataXtd_Shape::Set (const TDF_Label& label, const TopoDS_Shape& shape) |
81 | { |
82 | Handle(TDataXtd_Shape) A; |
83 | if (!label.FindAttribute(TDataXtd_Shape::GetID(),A)) { |
84 | A = TDataXtd_Shape::New (label); |
85 | } |
86 | |
87 | #ifdef OCC2932 |
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 | #endif |
95 | |
96 | TNaming_Builder B(label); |
97 | B.Generated(shape); |
98 | return A; |
99 | } |
100 | |
101 | //======================================================================= |
102 | //function : Get |
103 | //purpose : |
104 | //======================================================================= |
105 | |
106 | TopoDS_Shape TDataXtd_Shape::Get (const TDF_Label& label) |
107 | { |
108 | TopoDS_Shape shape; |
109 | |
110 | Handle(TNaming_NamedShape) NS; |
111 | if( label.FindAttribute(TNaming_NamedShape::GetID(), NS)) { |
112 | shape = TNaming_Tool::GetShape(NS); |
113 | return shape; |
114 | } |
115 | |
116 | shape.Nullify(); |
117 | return shape; |
118 | } |
119 | |
120 | //======================================================================= |
121 | //function : GetID |
122 | //purpose : |
123 | //======================================================================= |
124 | |
125 | const Standard_GUID& TDataXtd_Shape::GetID() |
126 | { |
127 | static Standard_GUID TDataXtd_ShapeID("2a96b620-ec8b-11d0-bee7-080009dc3333"); |
128 | return TDataXtd_ShapeID; |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : TDataXtd_Shape |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | TDataXtd_Shape::TDataXtd_Shape() |
137 | { |
138 | } |
139 | |
140 | //======================================================================= |
141 | //function : ID |
142 | //purpose : |
143 | //======================================================================= |
144 | |
145 | const Standard_GUID& TDataXtd_Shape::ID() const |
146 | { return GetID(); } |
147 | |
148 | |
149 | //======================================================================= |
150 | //function : NewEmpty |
151 | //purpose : |
152 | //======================================================================= |
153 | |
154 | Handle(TDF_Attribute) TDataXtd_Shape::NewEmpty () const |
155 | { |
156 | return new TDataXtd_Shape(); |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : Restore |
161 | //purpose : |
162 | //======================================================================= |
163 | |
35e08fe8 |
164 | void TDataXtd_Shape::Restore(const Handle(TDF_Attribute)& ) |
7fd59977 |
165 | { |
166 | } |
167 | |
168 | //======================================================================= |
169 | //function : Paste |
170 | //purpose : |
171 | //======================================================================= |
172 | |
35e08fe8 |
173 | void TDataXtd_Shape::Paste (const Handle(TDF_Attribute)&, |
174 | const Handle(TDF_RelocationTable)&) const |
7fd59977 |
175 | { |
176 | } |
177 | |
178 | //======================================================================= |
179 | //function : References |
180 | //purpose : |
181 | //======================================================================= |
182 | |
35e08fe8 |
183 | void TDataXtd_Shape::References (const Handle(TDF_DataSet)&) const |
7fd59977 |
184 | { |
185 | } |
186 | |
187 | //======================================================================= |
188 | //function : Dump |
189 | //purpose : |
190 | //======================================================================= |
191 | |
192 | Standard_OStream& TDataXtd_Shape::Dump (Standard_OStream& anOS) const |
193 | { |
194 | anOS << "Shape"; |
195 | return anOS; |
196 | } |