1 // Created on: 1997-03-06
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_Integer.hxx>
19 #include <Standard_Dump.hxx>
20 #include <Standard_GUID.hxx>
21 #include <Standard_Type.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_Reference.hxx>
25 #include <TDF_RelocationTable.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Integer,TDF_Attribute)
29 //=======================================================================
32 //=======================================================================
33 const Standard_GUID& TDataStd_Integer::GetID()
35 static Standard_GUID TDataStd_IntegerID ("2a96b606-ec8b-11d0-bee7-080009dc3333");
36 return TDataStd_IntegerID;
39 //=======================================================================
41 //purpose : Implements Set functionality
42 //=======================================================================
43 static Handle(TDataStd_Integer) SetAttr(const TDF_Label& label,
44 const Standard_Integer V,
45 const Standard_GUID& theGuid)
47 Handle(TDataStd_Integer) A;
48 if (!label.FindAttribute(theGuid, A)) {
49 A = new TDataStd_Integer ();
51 label.AddAttribute(A);
57 //=======================================================================
60 //=======================================================================
62 Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L,
63 const Standard_Integer V)
66 return SetAttr(L, V, GetID());
69 //=======================================================================
71 //purpose : Set user defined attribute
72 //=======================================================================
74 Handle(TDataStd_Integer) TDataStd_Integer::Set (const TDF_Label& L,
75 const Standard_GUID& theGuid,
76 const Standard_Integer V)
78 return SetAttr(L, V, theGuid);
80 //=======================================================================
81 //function : TDataStd_Integer
82 //purpose : Empty Constructor
83 //=======================================================================
85 TDataStd_Integer::TDataStd_Integer ()
86 : myValue (-1), myID(GetID())
90 //=======================================================================
93 //=======================================================================
95 void TDataStd_Integer::Set(const Standard_Integer v)
98 if(myValue == v) return;
105 //=======================================================================
108 //=======================================================================
110 Standard_Integer TDataStd_Integer::Get () const { return myValue; }
113 //=======================================================================
114 //function : IsCaptured
116 //=======================================================================
118 Standard_Boolean TDataStd_Integer::IsCaptured() const
120 Handle(TDF_Reference) R;
121 return (Label().FindAttribute(TDF_Reference::GetID(),R));
124 //=======================================================================
127 //=======================================================================
129 const Standard_GUID& TDataStd_Integer::ID () const { return myID; }
131 //=======================================================================
134 //=======================================================================
136 void TDataStd_Integer::SetID( const Standard_GUID& theGuid)
138 if(myID == theGuid) return;
144 //=======================================================================
146 //purpose : sets default ID
147 //=======================================================================
148 void TDataStd_Integer::SetID()
154 //=======================================================================
155 //function : NewEmpty
157 //=======================================================================
159 Handle(TDF_Attribute) TDataStd_Integer::NewEmpty () const
161 return new TDataStd_Integer();
164 //=======================================================================
167 //=======================================================================
169 void TDataStd_Integer::Restore(const Handle(TDF_Attribute)& With)
171 Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (With);
172 myValue = anInt->Get();
176 //=======================================================================
179 //=======================================================================
181 void TDataStd_Integer::Paste (const Handle(TDF_Attribute)& Into,
182 const Handle(TDF_RelocationTable)& /*RT*/) const
184 Handle(TDataStd_Integer) anInt = Handle(TDataStd_Integer)::DownCast (Into);
189 //=======================================================================
192 //=======================================================================
194 Standard_OStream& TDataStd_Integer::Dump (Standard_OStream& anOS) const
196 anOS << "Integer:: "<< this <<" : ";
198 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
199 myID.ToCString(sguid);
202 anOS <<"\nAttribute fields: ";
203 TDF_Attribute::Dump(anOS);
207 //=======================================================================
208 //function : DumpJson
210 //=======================================================================
211 void TDataStd_Integer::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
213 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
215 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
217 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValue)
218 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)