fe5ab4d9827e0dfe9a7b23c1704c903db50af0b1
[occt.git] / src / TDataStd / TDataStd_Real.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
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>
26
27 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_Real,TDF_Attribute)
28
29 //=======================================================================
30 //function : GetID
31 //purpose  : 
32 //=======================================================================
33 const Standard_GUID& TDataStd_Real::GetID() 
34 {
35   static Standard_GUID TDataStd_RealID("2a96b60f-ec8b-11d0-bee7-080009dc3333");
36   return TDataStd_RealID;
37 }
38
39 //=======================================================================
40 //function : SetAttr
41 //purpose  : Implements Set functionality
42 //=======================================================================
43 static 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 }
56
57 //=======================================================================
58 //function : Set
59 //purpose  : 
60 //=======================================================================
61
62 Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label&    L,
63                                           const Standard_Real V) 
64 {
65   return SetAttr(L, V, GetID());
66 }
67
68 //=======================================================================
69 //function : Set
70 //purpose  : User defined attribute
71 //=======================================================================
72
73 Handle(TDataStd_Real) TDataStd_Real::Set (const TDF_Label&    L,
74                                           const Standard_GUID& theGuid,
75                                           const Standard_Real V) 
76 {
77   return SetAttr(L, V, theGuid);
78 }
79
80 //=======================================================================
81 //function : TDataStd_Real
82 //purpose  : Empty constructor
83 //=======================================================================
84
85 TDataStd_Real::TDataStd_Real ()
86      : myValue     (RealFirst()),
87        myDimension (TDataStd_SCALAR)
88 {}
89
90
91
92 //=======================================================================
93 //function : IsCaptured
94 //purpose  : 
95 //=======================================================================
96
97 Standard_Boolean TDataStd_Real::IsCaptured() const
98 {
99   Handle(TDF_Reference) reference;
100   // pour test
101
102   if (Label().FindAttribute(TDF_Reference::GetID(),reference)) {
103     const TDF_Label& aLabel = reference->Get(); 
104     return aLabel.IsAttribute (myID);
105
106   }
107   return Standard_False;
108 }
109
110
111 //=======================================================================
112 //function : Set
113 //purpose  : 
114 //=======================================================================
115
116 void 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
130 Standard_Real TDataStd_Real::Get() const { return myValue; }
131
132
133 //=======================================================================
134 //function : SetDimension 
135 //purpose  : 
136 //=======================================================================
137
138 void 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
153 TDataStd_RealEnum TDataStd_Real::GetDimension () const
154 {
155   return myDimension;
156 }
157
158
159 //=======================================================================
160 //function : ID
161 //purpose  : 
162 //=======================================================================
163
164 const Standard_GUID& TDataStd_Real::ID() const { return myID; }
165
166 //=======================================================================
167 //function : SetID
168 //purpose  :
169 //=======================================================================
170
171 void TDataStd_Real::SetID( const Standard_GUID&  theGuid)
172 {  
173   if(myID == theGuid) return;
174
175   Backup();
176   myID = theGuid;
177 }
178
179 //=======================================================================
180 //function : SetID
181 //purpose  : sets default ID
182 //=======================================================================
183 void TDataStd_Real::SetID()
184 {
185   Backup();
186   myID = GetID();
187 }
188 //=======================================================================
189 //function : NewEmpty
190 //purpose  : 
191 //=======================================================================
192
193 Handle(TDF_Attribute) TDataStd_Real::NewEmpty () const
194 {
195   return new TDataStd_Real();
196 }
197
198 //=======================================================================
199 //function : Restore
200 //purpose  : 
201 //=======================================================================
202
203 void TDataStd_Real::Restore(const Handle(TDF_Attribute)& With) 
204 {
205   Handle(TDataStd_Real) R = Handle(TDataStd_Real)::DownCast (With);
206   myValue = R->Get();
207   myDimension = R->GetDimension();
208   myID = R->ID();
209 }
210
211
212
213 //=======================================================================
214 //function : Paste
215 //purpose  : 
216 //=======================================================================
217
218 void TDataStd_Real::Paste (const Handle(TDF_Attribute)& Into,
219                            const Handle(TDF_RelocationTable)& /*RT*/) const
220
221   Handle(TDataStd_Real) R = Handle(TDataStd_Real)::DownCast (Into);
222   R->Set(myValue);
223   R->SetDimension(myDimension);
224   R->SetID(myID);
225 }
226
227 //=======================================================================
228 //function : Dump
229 //purpose  : 
230 //=======================================================================
231
232 Standard_OStream& TDataStd_Real::Dump (Standard_OStream& anOS) const
233 {  
234   anOS << "Real "; 
235   TDataStd::Print(GetDimension(),anOS);
236   anOS << myValue; 
237   Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
238   myID.ToCString(sguid);
239   anOS << sguid;
240   return anOS;
241 }
242