0028714: Dimension of TDataStd_Real is not serialized to document
[occt.git] / src / TDataStd / TDataStd_Real.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
7fd59977 17
42cf5bc1 18#include <Standard_GUID.hxx>
19#include <Standard_Type.hxx>
20#include <TDataStd.hxx>
21#include <TDataStd_Real.hxx>
22#include <TDF_Attribute.hxx>
23#include <TDF_Label.hxx>
24#include <TDF_Reference.hxx>
25#include <TDF_RelocationTable.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Real,TDF_Attribute)
28
7fd59977 29//=======================================================================
30//function : GetID
31//purpose :
32//=======================================================================
7fd59977 33const Standard_GUID& TDataStd_Real::GetID()
34{
35 static Standard_GUID TDataStd_RealID("2a96b60f-ec8b-11d0-bee7-080009dc3333");
36 return TDataStd_RealID;
37}
38
69f1a899 39//=======================================================================
40//function : SetAttr
41//purpose : Implements Set functionality
42//=======================================================================
43static Handle(TDataStd_Real) SetAttr(const TDF_Label& label,
44 const Standard_Real V,
45 const Standard_GUID& theGuid)
46{
47 Handle(TDataStd_Real) A;
48 if (!label.FindAttribute(theGuid, A)) {
49 A = new TDataStd_Real ();
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_Real) TDataStd_Real::Set (const TDF_Label& L,
63 const Standard_Real V)
64{
69f1a899 65 return SetAttr(L, V, GetID());
7fd59977 66}
67
fa53efef 68//=======================================================================
69//function : Set
70//purpose : User defined attribute
71//=======================================================================
72
69f1a899 73Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label& L,
74 const Standard_GUID& theGuid,
fa53efef 75 const Standard_Real V)
76{
69f1a899 77 return SetAttr(L, V, theGuid);
fa53efef 78}
7fd59977 79
80//=======================================================================
81//function : TDataStd_Real
82//purpose : Empty constructor
83//=======================================================================
84
85TDataStd_Real::TDataStd_Real ()
86 : myValue (RealFirst()),
69f1a899 87 myDimension (TDataStd_SCALAR)
7fd59977 88{}
89
90
91
92//=======================================================================
93//function : IsCaptured
94//purpose :
95//=======================================================================
96
97Standard_Boolean TDataStd_Real::IsCaptured() const
98{
99 Handle(TDF_Reference) reference;
100 // pour test
101
102 if (Label().FindAttribute(TDF_Reference::GetID(),reference)) {
fa53efef 103 const TDF_Label& aLabel = reference->Get();
104 return aLabel.IsAttribute (myID);
105
7fd59977 106 }
107 return Standard_False;
108}
109
110
111//=======================================================================
112//function : Set
113//purpose :
114//=======================================================================
115
116void TDataStd_Real::Set(const Standard_Real v)
117{
118 // OCC2932 correction
119 if( myValue == v) return;
120
121 Backup();
122 myValue = v;
123}
124
125//=======================================================================
126//function : Get
127//purpose :
128//=======================================================================
129
130Standard_Real TDataStd_Real::Get() const { return myValue; }
131
132
133//=======================================================================
134//function : SetDimension
135//purpose :
136//=======================================================================
137
138void TDataStd_Real::SetDimension (const TDataStd_RealEnum DIM)
139{
140 // OCC2932 correction
141 if(myDimension == DIM) return;
142
143 Backup();
144 myDimension = DIM;
145}
146
147
148//=======================================================================
149//function : GetDimension
150//purpose :
151//=======================================================================
152
153TDataStd_RealEnum TDataStd_Real::GetDimension () const
154{
155 return myDimension;
156}
157
158
159//=======================================================================
160//function : ID
161//purpose :
162//=======================================================================
163
fa53efef 164const Standard_GUID& TDataStd_Real::ID() const { return myID; }
165
166//=======================================================================
167//function : SetID
168//purpose :
169//=======================================================================
7fd59977 170
fa53efef 171void TDataStd_Real::SetID( const Standard_GUID& theGuid)
172{
173 if(myID == theGuid) return;
7fd59977 174
fa53efef 175 Backup();
176 myID = theGuid;
177}
5a1271c8 178
179//=======================================================================
180//function : SetID
181//purpose : sets default ID
182//=======================================================================
183void TDataStd_Real::SetID()
184{
185 Backup();
186 myID = GetID();
187}
7fd59977 188//=======================================================================
189//function : NewEmpty
190//purpose :
191//=======================================================================
192
193Handle(TDF_Attribute) TDataStd_Real::NewEmpty () const
69f1a899 194{
195 return new TDataStd_Real();
7fd59977 196}
197
198//=======================================================================
199//function : Restore
200//purpose :
201//=======================================================================
202
203void TDataStd_Real::Restore(const Handle(TDF_Attribute)& With)
204{
205 Handle(TDataStd_Real) R = Handle(TDataStd_Real)::DownCast (With);
206 myValue = R->Get();
58e5d30e 207 Standard_DISABLE_DEPRECATION_WARNINGS
7fd59977 208 myDimension = R->GetDimension();
58e5d30e 209 Standard_ENABLE_DEPRECATION_WARNINGS
fa53efef 210 myID = R->ID();
7fd59977 211}
212
213
214
215//=======================================================================
216//function : Paste
217//purpose :
218//=======================================================================
219
220void TDataStd_Real::Paste (const Handle(TDF_Attribute)& Into,
35e08fe8 221 const Handle(TDF_RelocationTable)& /*RT*/) const
7fd59977 222{
223 Handle(TDataStd_Real) R = Handle(TDataStd_Real)::DownCast (Into);
224 R->Set(myValue);
58e5d30e 225 Standard_DISABLE_DEPRECATION_WARNINGS
7fd59977 226 R->SetDimension(myDimension);
58e5d30e 227 Standard_ENABLE_DEPRECATION_WARNINGS
fa53efef 228 R->SetID(myID);
7fd59977 229}
230
231//=======================================================================
232//function : Dump
233//purpose :
234//=======================================================================
235
236Standard_OStream& TDataStd_Real::Dump (Standard_OStream& anOS) const
237{
238 anOS << "Real ";
58e5d30e 239 Standard_DISABLE_DEPRECATION_WARNINGS
240 TDataStd::Print(GetDimension(), anOS);
241 Standard_ENABLE_DEPRECATION_WARNINGS
fa53efef 242 anOS << myValue;
243 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
244 myID.ToCString(sguid);
245 anOS << sguid;
7fd59977 246 return anOS;
247}
248