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