b311480e |
1 | // Created on: 1997-07-31 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <TDataStd_Name.ixx> |
18 | |
19 | #include <TDF_Label.hxx> |
20 | #include <TDF_ChildIterator.hxx> |
21 | #include <TDF_Tool.hxx> |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TDF_ListIteratorOfAttributeList.hxx> |
24 | |
25 | //======================================================================= |
26 | //function : GetID |
27 | //purpose : |
28 | //======================================================================= |
29 | |
30 | const Standard_GUID& TDataStd_Name::GetID () |
31 | { |
32 | static Standard_GUID TDataStd_NameID("2a96b608-ec8b-11d0-bee7-080009dc3333"); |
33 | return TDataStd_NameID; |
34 | } |
35 | |
36 | //======================================================================= |
37 | //function : Set |
38 | //purpose : |
39 | //======================================================================= |
40 | Handle(TDataStd_Name) TDataStd_Name::Set |
41 | (const TDF_Label& label, |
42 | const TCollection_ExtendedString& theString) |
43 | { |
44 | Handle(TDataStd_Name) N; |
45 | if (!label.FindAttribute(TDataStd_Name::GetID(), N)) { |
46 | N = new TDataStd_Name (); |
47 | label.AddAttribute(N); |
48 | } |
49 | N->Set(theString); |
50 | return N; |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : Find |
55 | //purpose : |
56 | //======================================================================= |
57 | // Standard_Boolean TDataStd_Name::Find (const TDF_Label& label, Handle(TDataStd_Name)& name) |
58 | // { |
59 | // Handle(TDataStd_Name) N; |
60 | // if (label.FindAttribute(TDataStd_Name::GetID(), N)) { |
61 | // name = N; |
62 | // return Standard_True; |
63 | // } |
64 | // TDF_Label L = label; |
65 | // while (!L.IsRoot()) { |
66 | // L = L.Father(); |
67 | // if (L.FindAttribute (TDataStd_Name::GetID(), N)) { |
68 | // name = N; |
69 | // return Standard_True; |
70 | // } |
71 | // } |
72 | // return Standard_False; |
73 | // } |
74 | |
75 | //======================================================================= |
76 | //function : IsNamed |
77 | //purpose : |
78 | //======================================================================= |
79 | // Standard_Boolean TDataStd_Name::IsNamed(const TDF_Label& label) |
80 | // { |
81 | // Handle(TDataStd_Name) N; |
82 | |
83 | // return label.FindAttribute(TDataStd_Name::GetID(), N); |
84 | // } |
85 | |
86 | //======================================================================= |
87 | //function : IsEmpty |
88 | //purpose : |
89 | //======================================================================= |
90 | // Standard_Boolean TDataStd_Name::IsEmpty(const TDF_Label& label) |
91 | // { |
92 | // Handle(TDataStd_Name) N; |
93 | // if(label.FindAttribute(TDataStd_Name::GetID(), N)) { |
94 | // return N->IsEmpty(); |
95 | // } |
96 | |
97 | // Standard_DomainError::Raise("There isn't the Name Attribute on the label"); |
98 | // } |
99 | |
100 | //======================================================================= |
101 | //function : Erase |
102 | //purpose : |
103 | //======================================================================= |
104 | // void TDataStd_Name::Erase(const TDF_Label& label) |
105 | // { |
106 | // Handle(TDataStd_Name) N; |
107 | |
108 | // if(label.FindAttribute(TDataStd_Name::GetID(), N)) { |
109 | // N->SetEmpty(); |
110 | // return; |
111 | // } |
112 | |
113 | // Standard_DomainError::Raise("There isn't the Name Attribute on the label"); |
114 | // } |
115 | |
116 | //======================================================================= |
117 | //function : TDataStd_Name |
118 | //purpose : Empty Constructor |
119 | //======================================================================= |
120 | |
258ff83b |
121 | TDataStd_Name::TDataStd_Name () { } |
7fd59977 |
122 | |
123 | //======================================================================= |
124 | //function : Set |
125 | //purpose : |
126 | //======================================================================= |
127 | void TDataStd_Name::Set (const TCollection_ExtendedString& S) |
128 | { |
7fd59977 |
129 | if(myString == S) return; |
130 | |
131 | Backup(); |
132 | myString = S; |
7fd59977 |
133 | } |
134 | |
135 | |
136 | |
137 | //======================================================================= |
138 | //function : Get |
139 | //purpose : |
140 | //======================================================================= |
141 | const TCollection_ExtendedString& TDataStd_Name::Get () const |
142 | { |
143 | return myString; |
144 | } |
145 | |
7fd59977 |
146 | // TDF_Attribute methods |
147 | |
148 | //======================================================================= |
149 | //function : ID |
150 | //purpose : |
151 | //======================================================================= |
152 | |
153 | const Standard_GUID& TDataStd_Name::ID () const { return GetID(); } |
154 | |
155 | |
7fd59977 |
156 | //======================================================================= |
157 | //function : NewEmpty |
158 | //purpose : |
159 | //======================================================================= |
160 | |
161 | Handle(TDF_Attribute) TDataStd_Name::NewEmpty () const |
162 | { |
163 | return new TDataStd_Name(); |
164 | } |
165 | |
166 | //======================================================================= |
167 | //function : Restore |
168 | //purpose : |
169 | //======================================================================= |
170 | |
171 | void TDataStd_Name::Restore(const Handle(TDF_Attribute)& with) |
172 | { |
173 | myString = Handle(TDataStd_Name)::DownCast (with)->Get(); |
174 | } |
175 | |
176 | |
177 | //======================================================================= |
178 | //function : Paste |
179 | //purpose : |
180 | //======================================================================= |
181 | |
182 | void TDataStd_Name::Paste (const Handle(TDF_Attribute)& into, |
183 | const Handle(TDF_RelocationTable)&/* RT*/) const |
184 | { |
185 | Handle(TDataStd_Name)::DownCast (into)->Set (myString); |
186 | } |
187 | |
188 | //======================================================================= |
189 | //function : Dump |
190 | //purpose : |
191 | //======================================================================= |
192 | |
193 | Standard_OStream& TDataStd_Name::Dump (Standard_OStream& anOS) const |
194 | { |
195 | TDF_Attribute::Dump(anOS); |
196 | anOS << " Name=|"<<myString<<"|"<<endl; |
197 | return anOS; |
198 | } |
199 | |
200 | |
201 | //======================================================================= |
202 | //function : Find (by the full path) |
203 | //purpose : Name |
204 | //======================================================================= |
205 | // Standard_Boolean TDataStd_Name::Find (const Handle(TDF_Data)& framework, |
206 | // const TDataStd_ListOfExtendedString& fullPath, |
207 | // Handle(TDataStd_Name)& name) |
208 | // { |
209 | // Handle(TDataStd_Name) Ncurrent; |
210 | // TDF_Label L, root = framework->Root(); |
211 | // TDF_ChildIterator ChItr (root, Standard_True); |
212 | // TCollection_ExtendedString string, first = fullPath.First(); |
213 | // TDataStd_ListOfExtendedString tmpPath; |
214 | // Standard_Boolean IsRootVisited = Standard_False; |
215 | |
216 | // tmpPath.Assign(fullPath); |
217 | // if(tmpPath.Extent() > 0 ) tmpPath.RemoveFirst(); |
218 | |
219 | // while( ChItr.More() ) { |
220 | // if( !IsRootVisited ) L = root; //For the fisrt time visit the root label |
221 | // else L = ChItr.Value(); |
222 | |
223 | // if( L.FindAttribute(TDataStd_Name::GetID(), Ncurrent) ) { |
224 | // string = Ncurrent->Get(); |
225 | // if( (string == first ) && ((string.Length()) == (first.Length())) ) { |
226 | // if( fullPath.Extent() == 1 ) { |
227 | // name = Ncurrent; |
228 | // return Standard_True; |
229 | // } |
230 | // if (Ncurrent->Find(tmpPath, name) ) return Standard_True; |
231 | // } |
232 | // else { |
233 | // if( !Ncurrent->IsEmpty() ) { |
234 | // //The root contains String different from first name in the path |
235 | // if( !IsRootVisited ) return Standard_False; |
236 | // ChItr.NextBrother(); continue; |
237 | // } |
238 | // } |
239 | // } |
240 | |
241 | // if( !IsRootVisited ) { |
242 | // IsRootVisited = Standard_True; |
243 | // continue; |
244 | // } |
245 | |
246 | // ChItr.Next(); |
247 | // } |
248 | // return Standard_False; |
249 | // } |
250 | |
251 | //======================================================================= |
252 | //function : Find (by the relative path) |
253 | //purpose : Name |
254 | //======================================================================= |
255 | // Standard_Boolean TDataStd_Name::Find (const TDF_Label& currentLabel, |
256 | // const TDataStd_ListOfExtendedString& relativePath, |
257 | // Handle(TDataStd_Name)& name) |
258 | // { |
259 | // Handle(TDataStd_Name) Ncurrent; |
260 | // TDF_ChildIterator ChItr (currentLabel, Standard_True); |
261 | // TCollection_ExtendedString string, first = relativePath.First(); |
262 | // TDataStd_ListOfExtendedString tmpPath; |
263 | // tmpPath.Assign(relativePath); |
264 | |
265 | // if( !currentLabel.FindAttribute(TDataStd_Name::GetID(), Ncurrent) ) |
266 | // Standard_DomainError::Raise("There isn't the Name attribute on the label"); |
267 | |
268 | |
269 | // while( ChItr.More() ) { |
270 | // if( ChItr.Value().FindAttribute(TDataStd_Name::GetID(), Ncurrent) ) { |
271 | // string = Ncurrent->Get(); |
272 | // if( (string == first ) && ((string.Length()) == (first.Length())) ) { |
273 | // if( relativePath.Extent() == 1 ) { //it has reached the end of the relative path |
274 | // name = Ncurrent; |
275 | // return Standard_True; |
276 | // } |
277 | // else { |
278 | // if (tmpPath.Extent() > 0) tmpPath.RemoveFirst(); |
279 | // if (Find(ChItr.Value(), tmpPath, Ncurrent)) return Standard_True; |
280 | // } |
281 | // } |
282 | // else { |
283 | // if( !Ncurrent->IsEmpty() ) { |
284 | // ChItr.NextBrother(); continue; |
285 | // } |
286 | // } |
287 | // } |
288 | // ChItr.Next(); |
289 | // } |
290 | |
291 | // return Standard_False; |
292 | // } |
293 | |
294 | |
295 | //======================================================================= |
296 | //function : Find (by the relative path) |
297 | //purpose : NameTool |
298 | //======================================================================= |
299 | // Standard_Boolean TDataStd_Name::Find(const TDF_Label& currentLabel, |
300 | // const TCollection_ExtendedString& string, |
301 | // Handle(TDataStd_Name)& name) |
302 | // { |
303 | // TDataStd_ListOfExtendedString tmpPath; |
304 | // TDataStd_Name::MakePath(string, tmpPath,':'); |
305 | // Handle(TDataStd_Name) Ncurrent; |
306 | // if (TDataStd_Name::Find(currentLabel,Ncurrent)) { |
307 | // return Ncurrent->Find(tmpPath, name); |
308 | // } |
309 | // return Standard_False; |
310 | // } |
311 | |
312 | //======================================================================= |
313 | //function : Find (by the full path) |
314 | //purpose : NameTool |
315 | //======================================================================= |
316 | // Standard_Boolean TDataStd_Name::Find(const Handle(TDF_Data)& framework, |
317 | // const TCollection_ExtendedString& string, |
318 | // Handle(TDataStd_Name)& name) |
319 | // { |
320 | // TDataStd_ListOfExtendedString tmpPath; |
321 | // TDataStd_Name::MakePath(string, tmpPath,':'); |
322 | // return Find(framework, tmpPath, name); |
323 | // } |
324 | |
325 | //======================================================================= |
326 | //function : FullPath |
327 | //purpose : NameTool |
328 | //======================================================================= |
329 | // Standard_Boolean TDataStd_Name::FullPath (TDF_AttributeList& path) const |
330 | // { |
331 | // path.Clear(); |
332 | // if( !IsEmpty() ) path.Append(this); |
333 | // TDF_Label L = Label(); |
334 | // if(L.IsRoot() ) return Standard_True; |
335 | // Handle(TDataStd_Name) Ncur; |
336 | // while ( !L.IsRoot()) { |
337 | // L = L.Father(); |
338 | // if(L.FindAttribute (TDataStd_Name::GetID(), Ncur)) { |
339 | // if( !Ncur->IsEmpty() )path.Prepend(Ncur); |
340 | // } |
341 | // } |
342 | // return Standard_True; |
343 | // } |
344 | |
345 | //======================================================================= |
346 | //function : MakePath |
347 | //purpose : NameTool |
348 | //======================================================================= |
349 | // Standard_Boolean TDataStd_Name::MakePath(const TCollection_ExtendedString& path, |
350 | // TDataStd_ListOfExtendedString& pathlist, |
351 | // const Standard_ExtCharacter Separator) |
352 | // { |
353 | // TCollection_ExtendedString tmpPath = path, str; |
354 | |
355 | // str+=Separator; str+=Separator; |
356 | // if( tmpPath.Search(str) != -1 ) return Standard_False; //Not valid path (contains two adjacent separators) |
357 | |
358 | // if( tmpPath.Search(Separator) == -1 ) { //The path contains only one name. |
359 | // pathlist.Append(path); |
360 | // return Standard_True; |
361 | // } |
362 | // Standard_Integer i; |
363 | // while( (i = tmpPath.SearchFromEnd(Separator) ) != -1 ) { |
364 | // str = tmpPath.Split(i-1); |
365 | // str.Remove(1); |
366 | // pathlist.Prepend(str); |
367 | // } |
368 | // if( tmpPath.Length() > 0 ) pathlist.Prepend(tmpPath); |
369 | // return Standard_True; |
370 | // } |
371 | |
372 | |
373 | //======================================================================= |
374 | //function : MakePath |
375 | //purpose : NameTool |
376 | //======================================================================= |
377 | // Standard_Boolean TDataStd_Name::MakePath(const TDF_AttributeList& pathlist, |
378 | // TCollection_ExtendedString& path, |
379 | // const Standard_ExtCharacter Separator) |
380 | // { |
381 | // TDF_ListIteratorOfAttributeList Itr(pathlist); |
382 | // Handle(TDataStd_Name) N; |
383 | |
384 | // if( pathlist.Extent() == 0 ) return Standard_False; |
385 | // path.Clear(); |
386 | // for(; Itr.More(); Itr.Next() ) { |
387 | // N = Handle(TDataStd_Name)::DownCast(Itr.Value()); |
388 | // path = path + N->Get(); |
389 | // path = path + Separator; |
390 | // } |
391 | // path.Remove(path.Length(), 1); |
392 | // return Standard_True; |
393 | // } |
394 | |
395 | //======================================================================= |
396 | //function : Find (by the relative path) |
397 | //purpose : Name |
398 | //======================================================================= |
399 | // Standard_Boolean TDataStd_Name::Find (const TDataStd_ListOfExtendedString& relativePath, |
400 | // Handle(TDataStd_Name)& name) const |
401 | // { |
402 | // Handle(TDataStd_Name) Ncurrent; |
403 | // TDF_ChildIterator ChItr (Label(), Standard_True); |
404 | // TCollection_ExtendedString string, first = relativePath.First(); |
405 | // TDataStd_ListOfExtendedString tmpPath; |
406 | // tmpPath.Assign(relativePath); |
407 | // // |
408 | // while( ChItr.More() ) { |
409 | // if( ChItr.Value().FindAttribute(TDataStd_Name::GetID(), Ncurrent) ) { |
410 | // string = Ncurrent->Get(); |
411 | // if( (string == first ) && ((string.Length()) == (first.Length())) ) { |
412 | // if( relativePath.Extent() == 1 ) { //it has reached the end of the relative path |
413 | // name = Ncurrent; |
414 | // return Standard_True; |
415 | // } |
416 | // else { |
417 | // if (tmpPath.Extent() > 0) tmpPath.RemoveFirst(); |
418 | // if (Ncurrent->Find(tmpPath, name)) return Standard_True; |
419 | // } |
420 | // } |
421 | // else { |
422 | // if (!Ncurrent->IsEmpty()) { |
423 | // ChItr.NextBrother(); continue; |
424 | // } |
425 | // } |
426 | // } |
427 | // ChItr.Next(); |
428 | // } |
429 | // return Standard_False; |
430 | // } |
431 | |
432 | //======================================================================= |
433 | //function : ChildNames |
434 | //purpose : NameTool |
435 | //======================================================================= |
436 | // Standard_Boolean TDataStd_Name::ChildNames (TDF_AttributeList& list) const |
437 | // { |
438 | // Standard_Boolean found = Standard_False; |
439 | // TDF_ChildIterator ChItr (Label(), Standard_True); |
440 | // Handle(TDataStd_Name) N; |
441 | // list.Clear(); |
442 | // for(; ChItr.More(); ChItr.Next()) { |
443 | // if( ChItr.Value().FindAttribute(TDataStd_Name::GetID(), N) ) { |
444 | // list.Append(N); |
445 | // found = Standard_True; |
446 | // cout << N->Get() << endl; |
447 | // } |
448 | // } |
449 | // return found; |
450 | // } |