0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / TDataStd / TDataStd_AsciiString.cxx
CommitLineData
b311480e 1// Created on: 2007-07-31
2// Created by: Sergey ZARITCHNY
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
bc73b006 16#include <TDataStd_AsciiString.hxx>
42cf5bc1 17
bc73b006 18#include <Standard_Dump.hxx>
7fd59977 19#include <Standard_GUID.hxx>
42cf5bc1 20#include <Standard_Type.hxx>
21#include <TCollection_AsciiString.hxx>
42cf5bc1 22#include <TDF_Attribute.hxx>
7fd59977 23#include <TDF_Label.hxx>
42cf5bc1 24#include <TDF_RelocationTable.hxx>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(TDataStd_AsciiString,TDF_Attribute)
27
7fd59977 28//=======================================================================
29//function : TDataStd_AsciiString
30//purpose :
31//=======================================================================
4a5eefb9 32TDataStd_AsciiString::TDataStd_AsciiString(): myID(GetID())
7fd59977 33{
34 myString.Clear();
35}
36
37//=======================================================================
38//function : GetID
39//purpose :
40//=======================================================================
41
42const Standard_GUID& TDataStd_AsciiString::GetID()
43{
44 static Standard_GUID theGUID ("3bbefc60-e618-11d4-ba38-0060b0ee18ea");
45 return theGUID;
46}
47
48//=======================================================================
49//function : ID
50//purpose :
51//=======================================================================
52
53const Standard_GUID& TDataStd_AsciiString::ID() const
54{
fa53efef 55 return myID;
7fd59977 56}
57
69f1a899 58//=======================================================================
59//function : SetAttr
60//purpose : Implements Set functionality
61//=======================================================================
62static Handle(TDataStd_AsciiString) SetAttr(
63 const TDF_Label& label,
64 const TCollection_AsciiString& theString,
65 const Standard_GUID& theGuid)
66{
67 Handle(TDataStd_AsciiString) A;
68 if (!label.FindAttribute(theGuid, A)) {
69 A = new TDataStd_AsciiString ();
70 A->SetID(theGuid);
71 label.AddAttribute(A);
72 }
73 A->Set (theString);
74 return A;
75}
76
7fd59977 77//=======================================================================
78//function : Set
79//purpose :
80//=======================================================================
81
82Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set (
83 const TDF_Label& theLabel,
84 const TCollection_AsciiString& theAsciiString)
85{
69f1a899 86 return SetAttr(theLabel, theAsciiString, GetID());
7fd59977 87}
88
fa53efef 89//=======================================================================
90//function : Set
91//purpose : Set user defined attribute
92//=======================================================================
93
69f1a899 94Handle(TDataStd_AsciiString) TDataStd_AsciiString::Set (
95 const TDF_Label& theLabel,
96 const Standard_GUID& theGuid,
97 const TCollection_AsciiString& theAsciiString)
fa53efef 98{
69f1a899 99 return SetAttr(theLabel, theAsciiString, theGuid);
fa53efef 100}
7fd59977 101//=======================================================================
102//function : Set
103//purpose :
104//=======================================================================
105
106void TDataStd_AsciiString::Set (const TCollection_AsciiString& theAsciiString)
107{
fa53efef 108 if(myString == theAsciiString) return;
7fd59977 109 Backup();
110 myString = theAsciiString;
111}
112
113//=======================================================================
114//function : Get
115//purpose :
116//=======================================================================
117
118const TCollection_AsciiString& TDataStd_AsciiString::Get () const
119{
120 return myString;
121}
122
fa53efef 123//=======================================================================
124//function : SetID
125//purpose :
126//=======================================================================
127
128void TDataStd_AsciiString::SetID( const Standard_GUID& theGuid)
129{
130 if(myID == theGuid) return;
131
132 Backup();
133 myID = theGuid;
134}
135
5a1271c8 136//=======================================================================
137//function : SetID
138//purpose : sets default ID
139//=======================================================================
140void TDataStd_AsciiString::SetID()
141{
142 Backup();
143 myID = GetID();
144}
7fd59977 145//=======================================================================
146//function : NewEmpty
147//purpose :
148//=======================================================================
149
150Handle(TDF_Attribute) TDataStd_AsciiString::NewEmpty () const
151{
69f1a899 152 return new TDataStd_AsciiString();
7fd59977 153}
154
155//=======================================================================
156//function : Restore
157//purpose :
158//=======================================================================
159
160void TDataStd_AsciiString::Restore (const Handle(TDF_Attribute)& theWith)
161{
162 Handle(TDataStd_AsciiString) R = Handle(TDataStd_AsciiString)::DownCast(theWith);
163 myString = R->Get();
fa53efef 164 myID = R->ID();
7fd59977 165}
166
167//=======================================================================
168//function : Paste
169//purpose :
170//=======================================================================
171
172void TDataStd_AsciiString::Paste (const Handle(TDF_Attribute)& theInto,
173 const Handle(TDF_RelocationTable)& /* RT */) const
174{
175 Handle(TDataStd_AsciiString) R = Handle(TDataStd_AsciiString)::DownCast (theInto);
176 R->Set(myString);
fa53efef 177 R->SetID(myID);
7fd59977 178}
179
180//=======================================================================
181//function : IsEmpty
182//purpose :
183//=======================================================================
184Standard_Boolean TDataStd_AsciiString::IsEmpty () const
185{
186 return myString.IsEmpty();
187}
188//=======================================================================
189//function : Dump
190//purpose :
191//=======================================================================
192
193Standard_OStream& TDataStd_AsciiString::Dump(Standard_OStream& theOS) const
194{
195 Standard_OStream& anOS = TDF_Attribute::Dump( theOS );
196 anOS << myString;
fa53efef 197 anOS << " Name=|"<<myString<<"|";
198 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
199 myID.ToCString(sguid);
04232180 200 anOS << sguid << "|" <<std::endl;
7fd59977 201 return anOS;
202}
bc73b006 203
204//=======================================================================
205//function : DumpJson
206//purpose :
207//=======================================================================
208void TDataStd_AsciiString::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
209{
210 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
211
212 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
213
214 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myString)
215 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)
216}