0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TDataStd / TDataStd_Integer.cxx
CommitLineData
b311480e 1// Created on: 1997-03-06
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_Integer.hxx>
42cf5bc1 18
bc73b006 19#include <Standard_Dump.hxx>
42cf5bc1 20#include <Standard_GUID.hxx>
21#include <Standard_Type.hxx>
42cf5bc1 22#include <TDF_Attribute.hxx>
23#include <TDF_Label.hxx>
7fd59977 24#include <TDF_Reference.hxx>
42cf5bc1 25#include <TDF_RelocationTable.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Integer,TDF_Attribute)
28
7fd59977 29//=======================================================================
30//function : GetID
31//purpose :
32//=======================================================================
7fd59977 33const Standard_GUID& TDataStd_Integer::GetID()
34{
35 static Standard_GUID TDataStd_IntegerID ("2a96b606-ec8b-11d0-bee7-080009dc3333");
36 return TDataStd_IntegerID;
37}
38
69f1a899 39//=======================================================================
40//function : SetAttr
41//purpose : Implements Set functionality
42//=======================================================================
43static Handle(TDataStd_Integer) SetAttr(const TDF_Label& label,
44 const Standard_Integer V,
45 const Standard_GUID& theGuid)
46{
47 Handle(TDataStd_Integer) A;
48 if (!label.FindAttribute(theGuid, A)) {
49 A = new TDataStd_Integer ();
50 A->SetID(theGuid);
51 label.AddAttribute(A);
52 }
53 A->Set (V);
54 return A;
55}
7fd59977 56
57//=======================================================================
58//function : Set
59//purpose :
60//=======================================================================
61
62Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L,
63 const Standard_Integer V)
64
65{
69f1a899 66 return SetAttr(L, V, GetID());
7fd59977 67}
68
fa53efef 69//=======================================================================
70//function : Set
71//purpose : Set user defined attribute
72//=======================================================================
73
69f1a899 74Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L,
75 const Standard_GUID& theGuid,
76 const Standard_Integer V)
fa53efef 77{
69f1a899 78 return SetAttr(L, V, theGuid);
fa53efef 79}
7fd59977 80//=======================================================================
81//function : TDataStd_Integer
82//purpose : Empty Constructor
83//=======================================================================
84
85TDataStd_Integer::TDataStd_Integer ()
4a5eefb9 86 : myValue (-1), myID(GetID())
7fd59977 87 { }
88
89
90//=======================================================================
91//function : Set
92//purpose :
93//=======================================================================
94
95void TDataStd_Integer::Set(const Standard_Integer v)
96{
97 // OCC2932 correction
98 if(myValue == v) return;
99
100 Backup();
101 myValue = v;
102}
103
104
105//=======================================================================
106//function : Get
107//purpose :
108//=======================================================================
109
110Standard_Integer TDataStd_Integer::Get () const { return myValue; }
111
112
113//=======================================================================
114//function : IsCaptured
115//purpose :
116//=======================================================================
117
118Standard_Boolean TDataStd_Integer::IsCaptured() const
119{
120 Handle(TDF_Reference) R;
121 return (Label().FindAttribute(TDF_Reference::GetID(),R));
122}
123
124//=======================================================================
125//function : ID
126//purpose :
127//=======================================================================
128
fa53efef 129const Standard_GUID& TDataStd_Integer::ID () const { return myID; }
7fd59977 130
fa53efef 131//=======================================================================
132//function : SetID
133//purpose :
134//=======================================================================
7fd59977 135
fa53efef 136void TDataStd_Integer::SetID( const Standard_GUID& theGuid)
137{
138 if(myID == theGuid) return;
139
140 Backup();
141 myID = theGuid;
142}
5a1271c8 143
144//=======================================================================
145//function : SetID
146//purpose : sets default ID
147//=======================================================================
148void TDataStd_Integer::SetID()
149{
150 Backup();
151 myID = GetID();
152}
153
7fd59977 154//=======================================================================
155//function : NewEmpty
156//purpose :
157//=======================================================================
158
159Handle(TDF_Attribute) TDataStd_Integer::NewEmpty () const
69f1a899 160{
161 return new TDataStd_Integer();
7fd59977 162}
163
164//=======================================================================
165//function : Restore
166//purpose :
167//=======================================================================
168
169void TDataStd_Integer::Restore(const Handle(TDF_Attribute)& With)
170{
fa53efef 171 Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (With);
172 myValue = anInt->Get();
173 myID = anInt->ID();
7fd59977 174}
175
176//=======================================================================
177//function : Paste
178//purpose :
179//=======================================================================
180
181void TDataStd_Integer::Paste (const Handle(TDF_Attribute)& Into,
35e08fe8 182 const Handle(TDF_RelocationTable)& /*RT*/) const
7fd59977 183{
fa53efef 184 Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (Into);
185 anInt->Set(myValue);
186 anInt->SetID(myID);
7fd59977 187}
188
189//=======================================================================
190//function : Dump
191//purpose :
192//=======================================================================
193
194Standard_OStream& TDataStd_Integer::Dump (Standard_OStream& anOS) const
195{
196 anOS << "Integer:: "<< this <<" : ";
197 anOS << myValue;
fa53efef 198 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
199 myID.ToCString(sguid);
200 anOS << sguid;
7fd59977 201//
202 anOS <<"\nAttribute fields: ";
008aef40 203 TDF_Attribute::Dump(anOS);
7fd59977 204 return anOS;
205}
206
bc73b006 207//=======================================================================
208//function : DumpJson
209//purpose :
210//=======================================================================
211void TDataStd_Integer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
212{
213 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
214
215 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
216
217 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValue)
218 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)
219}