0030773: Application Framework - To allow to inherit existing attributes to reuse...
[occt.git] / src / XCAFDoc / XCAFDoc_AssemblyItemId.cxx
CommitLineData
024d6f77 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
bc73b006 18#include <Standard_Dump.hxx>
19
024d6f77 20XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId()
21{
22
23}
24
25XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId(const TColStd_ListOfAsciiString& thePath)
26{
27 Init(thePath);
28}
29
30XCAFDoc_AssemblyItemId::XCAFDoc_AssemblyItemId(const TCollection_AsciiString& theString)
31{
32 Init(theString);
33}
34
35void
36XCAFDoc_AssemblyItemId::Init(const TColStd_ListOfAsciiString& thePath)
37{
38 myPath = thePath;
39}
40
41void
42XCAFDoc_AssemblyItemId::Init(const TCollection_AsciiString& theString)
43{
44 myPath.Clear();
45
46 for (Standard_Integer iEntry = 1; ; ++iEntry)
47 {
48 TCollection_AsciiString anEntry = theString.Token("/", iEntry);
49 if (anEntry.IsEmpty())
50 break;
51
52 myPath.Append(anEntry);
53 }
54}
55
56Standard_Boolean
57XCAFDoc_AssemblyItemId::IsNull() const
58{
59 return myPath.IsEmpty();
60}
61
62void
63XCAFDoc_AssemblyItemId::Nullify()
64{
65 myPath.Clear();
66}
67
68Standard_Boolean
69XCAFDoc_AssemblyItemId::IsChild(const XCAFDoc_AssemblyItemId& theOther) const
70{
71 if (myPath.Size() <= theOther.myPath.Size())
72 return Standard_False;
73
74 TColStd_ListOfAsciiString::Iterator anIt(myPath), anItOther(theOther.myPath);
75 for (; anItOther.More(); anIt.Next(), anItOther.Next())
76 {
77 if (anIt.Value() != anItOther.Value())
78 return Standard_False;
79 }
80
81 return Standard_True;
82}
83
84Standard_Boolean
85XCAFDoc_AssemblyItemId::IsDirectChild(const XCAFDoc_AssemblyItemId& theOther) const
86{
87 return ((myPath.Size() == theOther.myPath.Size() - 1) && IsChild(theOther));
88}
89
90Standard_Boolean
91XCAFDoc_AssemblyItemId::IsEqual(const XCAFDoc_AssemblyItemId& theOther) const
92{
93 if (this == &theOther)
94 return Standard_True;
95
96 if (myPath.Size() != theOther.myPath.Size())
97 return Standard_False;
98
99 TColStd_ListOfAsciiString::Iterator anIt(myPath), anItOther(theOther.myPath);
100 for (; anIt.More() && anItOther.More(); anIt.Next(), anItOther.Next())
101 {
102 if (anIt.Value() != anItOther.Value())
103 return Standard_False;
104 }
105
106 return Standard_True;
107}
108
109const
110TColStd_ListOfAsciiString& XCAFDoc_AssemblyItemId::GetPath() const
111{
112 return myPath;
113}
114
115TCollection_AsciiString
116XCAFDoc_AssemblyItemId::ToString() const
117{
118 TCollection_AsciiString aStr;
119 for (TColStd_ListOfAsciiString::Iterator anIt(myPath); anIt.More(); anIt.Next())
120 {
121 aStr += '/';
122 aStr += anIt.Value();
123 }
ac293bde 124 aStr.Remove(1, 1);
024d6f77 125 return aStr;
126}
bc73b006 127
128//=======================================================================
129//function : DumpJson
130//purpose :
131//=======================================================================
132void XCAFDoc_AssemblyItemId::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
133{
134 OCCT_DUMP_CLASS_BEGIN (theOStream, XCAFDoc_AssemblyItemId)
135
136 for (TColStd_ListOfAsciiString::Iterator aPathIt (myPath); aPathIt.More(); aPathIt.Next())
137 {
138 TCollection_AsciiString aPath = aPathIt.Value();
139 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aPath)
140 }
141}