0029902: Data Exchange, XCAF - provide extended Material definition for visualization...
[occt.git] / src / XCAFDoc / XCAFDoc_AssemblyItemId.cxx
1 // Created on: 2017-02-16
2 // Created by: Sergey NIKONOV
3 // Copyright (c) 2000-2017 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 #include <XCAFDoc_AssemblyItemId.hxx>
17
18 XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId()
19 {
20
21 }
22
23 XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId(const TColStd_ListOfAsciiString& thePath)
24 {
25   Init(thePath);
26 }
27
28 XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId(const TCollection_AsciiString& theString)
29 {
30   Init(theString);
31 }
32
33 void 
34 XCAFDoc_AssemblyItemId::Init(const TColStd_ListOfAsciiString& thePath)
35 {
36   myPath = thePath;
37 }
38
39 void 
40 XCAFDoc_AssemblyItemId::Init(const TCollection_AsciiString& theString)
41 {
42   myPath.Clear();
43
44   for (Standard_Integer iEntry = 1; ; ++iEntry)
45   {
46     TCollection_AsciiString anEntry = theString.Token("/", iEntry);
47     if (anEntry.IsEmpty())
48       break;
49
50     myPath.Append(anEntry);
51   }
52 }
53
54 Standard_Boolean 
55 XCAFDoc_AssemblyItemId::IsNull() const
56 {
57   return myPath.IsEmpty();
58 }
59
60 void 
61 XCAFDoc_AssemblyItemId::Nullify()
62 {
63   myPath.Clear();
64 }
65
66 Standard_Boolean 
67 XCAFDoc_AssemblyItemId::IsChild(const XCAFDoc_AssemblyItemId& theOther) const
68 {
69   if (myPath.Size() <= theOther.myPath.Size())
70     return Standard_False;
71
72   TColStd_ListOfAsciiString::Iterator anIt(myPath), anItOther(theOther.myPath);
73   for (; anItOther.More(); anIt.Next(), anItOther.Next())
74   {
75     if (anIt.Value() != anItOther.Value())
76       return Standard_False;
77   }
78
79   return Standard_True;
80 }
81
82 Standard_Boolean 
83 XCAFDoc_AssemblyItemId::IsDirectChild(const XCAFDoc_AssemblyItemId& theOther) const
84 {
85   return ((myPath.Size() == theOther.myPath.Size() - 1) && IsChild(theOther));
86 }
87
88 Standard_Boolean 
89 XCAFDoc_AssemblyItemId::IsEqual(const XCAFDoc_AssemblyItemId& theOther) const
90 {
91   if (this == &theOther)
92     return Standard_True;
93
94   if (myPath.Size() != theOther.myPath.Size())
95     return Standard_False;
96
97   TColStd_ListOfAsciiString::Iterator anIt(myPath), anItOther(theOther.myPath);
98   for (; anIt.More() && anItOther.More(); anIt.Next(), anItOther.Next())
99   {
100     if (anIt.Value() != anItOther.Value())
101       return Standard_False;
102   }
103
104   return Standard_True;
105 }
106
107 const 
108 TColStd_ListOfAsciiString& XCAFDoc_AssemblyItemId::GetPath() const
109 {
110   return myPath;
111 }
112
113 TCollection_AsciiString 
114 XCAFDoc_AssemblyItemId::ToString() const
115 {
116   TCollection_AsciiString aStr;
117   for (TColStd_ListOfAsciiString::Iterator anIt(myPath); anIt.More(); anIt.Next())
118   {
119     aStr += '/';
120     aStr += anIt.Value();
121   }
122   aStr.Remove(1, 1);
123   return aStr;
124 }