1 // Created on: 1997-07-31
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <TDataStd_Name.ixx>
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>
25 //=======================================================================
28 //=======================================================================
30 const Standard_GUID& TDataStd_Name::GetID ()
32 static Standard_GUID TDataStd_NameID("2a96b608-ec8b-11d0-bee7-080009dc3333");
33 return TDataStd_NameID;
36 //=======================================================================
39 //=======================================================================
40 Handle(TDataStd_Name) TDataStd_Name::Set
41 (const TDF_Label& label,
42 const TCollection_ExtendedString& theString)
44 Handle(TDataStd_Name) N;
45 if (!label.FindAttribute(TDataStd_Name::GetID(), N)) {
46 N = new TDataStd_Name ();
47 label.AddAttribute(N);
53 //=======================================================================
56 //=======================================================================
57 // Standard_Boolean TDataStd_Name::Find (const TDF_Label& label, Handle(TDataStd_Name)& name)
59 // Handle(TDataStd_Name) N;
60 // if (label.FindAttribute(TDataStd_Name::GetID(), N)) {
62 // return Standard_True;
64 // TDF_Label L = label;
65 // while (!L.IsRoot()) {
67 // if (L.FindAttribute (TDataStd_Name::GetID(), N)) {
69 // return Standard_True;
72 // return Standard_False;
75 //=======================================================================
78 //=======================================================================
79 // Standard_Boolean TDataStd_Name::IsNamed(const TDF_Label& label)
81 // Handle(TDataStd_Name) N;
83 // return label.FindAttribute(TDataStd_Name::GetID(), N);
86 //=======================================================================
89 //=======================================================================
90 // Standard_Boolean TDataStd_Name::IsEmpty(const TDF_Label& label)
92 // Handle(TDataStd_Name) N;
93 // if(label.FindAttribute(TDataStd_Name::GetID(), N)) {
94 // return N->IsEmpty();
97 // Standard_DomainError::Raise("There isn't the Name Attribute on the label");
100 //=======================================================================
103 //=======================================================================
104 // void TDataStd_Name::Erase(const TDF_Label& label)
106 // Handle(TDataStd_Name) N;
108 // if(label.FindAttribute(TDataStd_Name::GetID(), N)) {
113 // Standard_DomainError::Raise("There isn't the Name Attribute on the label");
116 //=======================================================================
117 //function : TDataStd_Name
118 //purpose : Empty Constructor
119 //=======================================================================
121 TDataStd_Name::TDataStd_Name () { }
123 //=======================================================================
126 //=======================================================================
127 void TDataStd_Name::Set (const TCollection_ExtendedString& S)
129 if(myString == S) return;
137 //=======================================================================
140 //=======================================================================
141 const TCollection_ExtendedString& TDataStd_Name::Get () const
146 // TDF_Attribute methods
148 //=======================================================================
151 //=======================================================================
153 const Standard_GUID& TDataStd_Name::ID () const { return GetID(); }
156 //=======================================================================
157 //function : NewEmpty
159 //=======================================================================
161 Handle(TDF_Attribute) TDataStd_Name::NewEmpty () const
163 return new TDataStd_Name();
166 //=======================================================================
169 //=======================================================================
171 void TDataStd_Name::Restore(const Handle(TDF_Attribute)& with)
173 myString = Handle(TDataStd_Name)::DownCast (with)->Get();
177 //=======================================================================
180 //=======================================================================
182 void TDataStd_Name::Paste (const Handle(TDF_Attribute)& into,
183 const Handle(TDF_RelocationTable)&/* RT*/) const
185 Handle(TDataStd_Name)::DownCast (into)->Set (myString);
188 //=======================================================================
191 //=======================================================================
193 Standard_OStream& TDataStd_Name::Dump (Standard_OStream& anOS) const
195 TDF_Attribute::Dump(anOS);
196 anOS << " Name=|"<<myString<<"|"<<endl;
201 //=======================================================================
202 //function : Find (by the full path)
204 //=======================================================================
205 // Standard_Boolean TDataStd_Name::Find (const Handle(TDF_Data)& framework,
206 // const TDataStd_ListOfExtendedString& fullPath,
207 // Handle(TDataStd_Name)& name)
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;
216 // tmpPath.Assign(fullPath);
217 // if(tmpPath.Extent() > 0 ) tmpPath.RemoveFirst();
219 // while( ChItr.More() ) {
220 // if( !IsRootVisited ) L = root; //For the fisrt time visit the root label
221 // else L = ChItr.Value();
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 ) {
228 // return Standard_True;
230 // if (Ncurrent->Find(tmpPath, name) ) return Standard_True;
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;
241 // if( !IsRootVisited ) {
242 // IsRootVisited = Standard_True;
248 // return Standard_False;
251 //=======================================================================
252 //function : Find (by the relative path)
254 //=======================================================================
255 // Standard_Boolean TDataStd_Name::Find (const TDF_Label& currentLabel,
256 // const TDataStd_ListOfExtendedString& relativePath,
257 // Handle(TDataStd_Name)& name)
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);
265 // if( !currentLabel.FindAttribute(TDataStd_Name::GetID(), Ncurrent) )
266 // Standard_DomainError::Raise("There isn't the Name attribute on the label");
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
275 // return Standard_True;
278 // if (tmpPath.Extent() > 0) tmpPath.RemoveFirst();
279 // if (Find(ChItr.Value(), tmpPath, Ncurrent)) return Standard_True;
283 // if( !Ncurrent->IsEmpty() ) {
284 // ChItr.NextBrother(); continue;
291 // return Standard_False;
295 //=======================================================================
296 //function : Find (by the relative path)
298 //=======================================================================
299 // Standard_Boolean TDataStd_Name::Find(const TDF_Label& currentLabel,
300 // const TCollection_ExtendedString& string,
301 // Handle(TDataStd_Name)& name)
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);
309 // return Standard_False;
312 //=======================================================================
313 //function : Find (by the full path)
315 //=======================================================================
316 // Standard_Boolean TDataStd_Name::Find(const Handle(TDF_Data)& framework,
317 // const TCollection_ExtendedString& string,
318 // Handle(TDataStd_Name)& name)
320 // TDataStd_ListOfExtendedString tmpPath;
321 // TDataStd_Name::MakePath(string, tmpPath,':');
322 // return Find(framework, tmpPath, name);
325 //=======================================================================
326 //function : FullPath
328 //=======================================================================
329 // Standard_Boolean TDataStd_Name::FullPath (TDF_AttributeList& path) const
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()) {
338 // if(L.FindAttribute (TDataStd_Name::GetID(), Ncur)) {
339 // if( !Ncur->IsEmpty() )path.Prepend(Ncur);
342 // return Standard_True;
345 //=======================================================================
346 //function : MakePath
348 //=======================================================================
349 // Standard_Boolean TDataStd_Name::MakePath(const TCollection_ExtendedString& path,
350 // TDataStd_ListOfExtendedString& pathlist,
351 // const Standard_ExtCharacter Separator)
353 // TCollection_ExtendedString tmpPath = path, str;
355 // str+=Separator; str+=Separator;
356 // if( tmpPath.Search(str) != -1 ) return Standard_False; //Not valid path (contains two adjacent separators)
358 // if( tmpPath.Search(Separator) == -1 ) { //The path contains only one name.
359 // pathlist.Append(path);
360 // return Standard_True;
362 // Standard_Integer i;
363 // while( (i = tmpPath.SearchFromEnd(Separator) ) != -1 ) {
364 // str = tmpPath.Split(i-1);
366 // pathlist.Prepend(str);
368 // if( tmpPath.Length() > 0 ) pathlist.Prepend(tmpPath);
369 // return Standard_True;
373 //=======================================================================
374 //function : MakePath
376 //=======================================================================
377 // Standard_Boolean TDataStd_Name::MakePath(const TDF_AttributeList& pathlist,
378 // TCollection_ExtendedString& path,
379 // const Standard_ExtCharacter Separator)
381 // TDF_ListIteratorOfAttributeList Itr(pathlist);
382 // Handle(TDataStd_Name) N;
384 // if( pathlist.Extent() == 0 ) return Standard_False;
386 // for(; Itr.More(); Itr.Next() ) {
387 // N = Handle(TDataStd_Name)::DownCast(Itr.Value());
388 // path = path + N->Get();
389 // path = path + Separator;
391 // path.Remove(path.Length(), 1);
392 // return Standard_True;
395 //=======================================================================
396 //function : Find (by the relative path)
398 //=======================================================================
399 // Standard_Boolean TDataStd_Name::Find (const TDataStd_ListOfExtendedString& relativePath,
400 // Handle(TDataStd_Name)& name) const
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);
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
414 // return Standard_True;
417 // if (tmpPath.Extent() > 0) tmpPath.RemoveFirst();
418 // if (Ncurrent->Find(tmpPath, name)) return Standard_True;
422 // if (!Ncurrent->IsEmpty()) {
423 // ChItr.NextBrother(); continue;
429 // return Standard_False;
432 //=======================================================================
433 //function : ChildNames
435 //=======================================================================
436 // Standard_Boolean TDataStd_Name::ChildNames (TDF_AttributeList& list) const
438 // Standard_Boolean found = Standard_False;
439 // TDF_ChildIterator ChItr (Label(), Standard_True);
440 // Handle(TDataStd_Name) N;
442 // for(; ChItr.More(); ChItr.Next()) {
443 // if( ChItr.Value().FindAttribute(TDataStd_Name::GetID(), N) ) {
445 // found = Standard_True;
446 // cout << N->Get() << endl;