0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[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
bc73b006 17#include <TDataStd_Name.hxx>
7fd59977 18
42cf5bc1 19#include <Standard_DomainError.hxx>
bc73b006 20#include <Standard_Dump.hxx>
42cf5bc1 21#include <Standard_GUID.hxx>
22#include <Standard_Type.hxx>
7fd59977 23#include <TCollection_AsciiString.hxx>
42cf5bc1 24#include <TCollection_ExtendedString.hxx>
42cf5bc1 25#include <TDF_Attribute.hxx>
26#include <TDF_ChildIterator.hxx>
27#include <TDF_Label.hxx>
7fd59977 28#include <TDF_ListIteratorOfAttributeList.hxx>
42cf5bc1 29#include <TDF_RelocationTable.hxx>
30#include <TDF_Tool.hxx>
7fd59977 31
92efcf78 32IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Name,TDF_Attribute)
33
7fd59977 34//=======================================================================
35//function : GetID
36//purpose :
37//=======================================================================
7fd59977 38const Standard_GUID& TDataStd_Name::GetID ()
39{
40 static Standard_GUID TDataStd_NameID("2a96b608-ec8b-11d0-bee7-080009dc3333");
41 return TDataStd_NameID;
42}
43
69f1a899 44//=======================================================================
45//function : SetAttr
46//purpose : Implements Set functionality
47//=======================================================================
48static Handle(TDataStd_Name) SetAttr(const TDF_Label& label,
49 const TCollection_ExtendedString& theString,
50 const Standard_GUID& theGuid)
51{
52 Handle(TDataStd_Name) N;
53 if (!label.FindAttribute(theGuid, N)) {
54 N = new TDataStd_Name ();
55 N->SetID(theGuid);
56 label.AddAttribute(N);
57 }
58 N->Set (theString);
59 return N;
60}
61
7fd59977 62//=======================================================================
63//function : Set
64//purpose :
65//=======================================================================
66Handle(TDataStd_Name) TDataStd_Name::Set
67 (const TDF_Label& label,
68 const TCollection_ExtendedString& theString)
69{
69f1a899 70 return SetAttr(label, theString, GetID());
7fd59977 71}
72
73//=======================================================================
fa53efef 74//function : Set
75//purpose : Set user defined attribute
7fd59977 76//=======================================================================
7fd59977 77
69f1a899 78Handle(TDataStd_Name) TDataStd_Name::Set (const TDF_Label& label,
79 const Standard_GUID& theGuid,
fa53efef 80 const TCollection_ExtendedString& theString)
81{
69f1a899 82 return SetAttr(label, theString, theGuid);
fa53efef 83}
7fd59977 84//=======================================================================
85//function : TDataStd_Name
86//purpose : Empty Constructor
87//=======================================================================
88
4a5eefb9 89TDataStd_Name::TDataStd_Name () : myID(GetID())
69f1a899 90{}
7fd59977 91
92//=======================================================================
93//function : Set
94//purpose :
95//=======================================================================
96void TDataStd_Name::Set (const TCollection_ExtendedString& S)
97{
7fd59977 98 if(myString == S) return;
99
100 Backup();
101 myString = S;
7fd59977 102}
103
104
105
106//=======================================================================
107//function : Get
108//purpose :
109//=======================================================================
110const TCollection_ExtendedString& TDataStd_Name::Get () const
111{
112 return myString;
113}
114
fa53efef 115//=======================================================================
116//function : SetID
117//purpose :
118//=======================================================================
7fd59977 119
fa53efef 120void TDataStd_Name::SetID( const Standard_GUID& theGuid)
121{
122 if(myID == theGuid) return;
123
124 Backup();
125 myID = theGuid;
126}
127
5a1271c8 128//=======================================================================
129//function : SetID
130//purpose : sets default ID
131//=======================================================================
132void TDataStd_Name::SetID()
133{
134 Backup();
135 myID = GetID();
136}
137
fa53efef 138// TDF_Attribute methods
7fd59977 139//=======================================================================
140//function : ID
141//purpose :
142//=======================================================================
143
fa53efef 144const Standard_GUID& TDataStd_Name::ID () const { return myID; }
7fd59977 145
7fd59977 146//=======================================================================
147//function : NewEmpty
148//purpose :
149//=======================================================================
150
151Handle(TDF_Attribute) TDataStd_Name::NewEmpty () const
69f1a899 152{
153 return new TDataStd_Name();
7fd59977 154}
155
156//=======================================================================
157//function : Restore
158//purpose :
159//=======================================================================
160
161void TDataStd_Name::Restore(const Handle(TDF_Attribute)& with)
162{
fa53efef 163 Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (with);
164 myString = anAtt->Get();
165 myID = anAtt->ID();
7fd59977 166}
167
168
169//=======================================================================
170//function : Paste
171//purpose :
172//=======================================================================
173
174void TDataStd_Name::Paste (const Handle(TDF_Attribute)& into,
175 const Handle(TDF_RelocationTable)&/* RT*/) const
176{
69f1a899 177 Handle(TDataStd_Name) anAtt = Handle(TDataStd_Name)::DownCast (into);
178 anAtt->Set (myString);
179 anAtt->SetID(myID);
7fd59977 180}
181
182//=======================================================================
183//function : Dump
184//purpose :
185//=======================================================================
186
187Standard_OStream& TDataStd_Name::Dump (Standard_OStream& anOS) const
188{
189 TDF_Attribute::Dump(anOS);
fa53efef 190 anOS << " Name=|"<<myString<<"|";
191 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
192 myID.ToCString(sguid);
04232180 193 anOS << sguid << std::endl;
7fd59977 194 return anOS;
195}
bc73b006 196
197//=======================================================================
198//function : DumpJson
199//purpose :
200//=======================================================================
201void TDataStd_Name::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
202{
203 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
204
205 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
206
207 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myString)
208 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)
209}