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.hxx>
19 #include <Standard_DomainError.hxx>
20 #include <Standard_Dump.hxx>
21 #include <Standard_GUID.hxx>
22 #include <Standard_Type.hxx>
23 #include <TCollection_AsciiString.hxx>
24 #include <TCollection_ExtendedString.hxx>
25 #include <TDF_Attribute.hxx>
26 #include <TDF_ChildIterator.hxx>
27 #include <TDF_Label.hxx>
28 #include <TDF_ListIteratorOfAttributeList.hxx>
29 #include <TDF_RelocationTable.hxx>
30 #include <TDF_Tool.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Name,TDF_Attribute)
34 //=======================================================================
37 //=======================================================================
38 const Standard_GUID& TDataStd_Name::GetID ()
40 static Standard_GUID TDataStd_NameID("2a96b608-ec8b-11d0-bee7-080009dc3333");
41 return TDataStd_NameID;
44 //=======================================================================
46 //purpose : Implements Set functionality
47 //=======================================================================
48 static Handle(TDataStd_Name) SetAttr(const TDF_Label& label,
49 const TCollection_ExtendedString& theString,
50 const Standard_GUID& theGuid)
52 Handle(TDataStd_Name) N;
53 if (!label.FindAttribute(theGuid, N)) {
54 N = new TDataStd_Name ();
56 label.AddAttribute(N);
62 //=======================================================================
65 //=======================================================================
66 Handle(TDataStd_Name) TDataStd_Name::Set
67 (const TDF_Label& label,
68 const TCollection_ExtendedString& theString)
70 return SetAttr(label, theString, GetID());
73 //=======================================================================
75 //purpose : Set user defined attribute
76 //=======================================================================
78 Handle(TDataStd_Name) TDataStd_Name::Set (const TDF_Label& label,
79 const Standard_GUID& theGuid,
80 const TCollection_ExtendedString& theString)
82 return SetAttr(label, theString, theGuid);
84 //=======================================================================
85 //function : TDataStd_Name
86 //purpose : Empty Constructor
87 //=======================================================================
89 TDataStd_Name::TDataStd_Name () : myID(GetID())
92 //=======================================================================
95 //=======================================================================
96 void TDataStd_Name::Set (const TCollection_ExtendedString& S)
98 if(myString == S) return;
106 //=======================================================================
109 //=======================================================================
110 const TCollection_ExtendedString& TDataStd_Name::Get () const
115 //=======================================================================
118 //=======================================================================
120 void TDataStd_Name::SetID( const Standard_GUID& theGuid)
122 if(myID == theGuid) return;
128 //=======================================================================
130 //purpose : sets default ID
131 //=======================================================================
132 void TDataStd_Name::SetID()
138 // TDF_Attribute methods
139 //=======================================================================
142 //=======================================================================
144 const Standard_GUID& TDataStd_Name::ID () const { return myID; }
146 //=======================================================================
147 //function : NewEmpty
149 //=======================================================================
151 Handle(TDF_Attribute) TDataStd_Name::NewEmpty () const
153 return new TDataStd_Name();
156 //=======================================================================
159 //=======================================================================
161 void TDataStd_Name::Restore(const Handle(TDF_Attribute)& with)
163 Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (with);
164 myString = anAtt->Get();
169 //=======================================================================
172 //=======================================================================
174 void TDataStd_Name::Paste (const Handle(TDF_Attribute)& into,
175 const Handle(TDF_RelocationTable)&/* RT*/) const
177 Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (into);
178 anAtt->Set (myString);
182 //=======================================================================
185 //=======================================================================
187 Standard_OStream& TDataStd_Name::Dump (Standard_OStream& anOS) const
189 TDF_Attribute::Dump(anOS);
190 anOS << " Name=|"<<myString<<"|";
191 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
192 myID.ToCString(sguid);
193 anOS << sguid << std::endl;
197 //=======================================================================
198 //function : DumpJson
200 //=======================================================================
201 void TDataStd_Name::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
203 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
205 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
207 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myString)
208 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)