0031313: Foundation Classes - Dump improvement for classes
[occt.git] / src / TDataStd / TDataStd_RealArray.cxx
CommitLineData
b311480e 1// Created on: 1999-06-16
2// Created by: Sergey RUIN
3// Copyright (c) 1999-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_RealArray.hxx>
42cf5bc1 18
bc73b006 19#include <Standard_Dump.hxx>
42cf5bc1 20#include <Standard_GUID.hxx>
21#include <Standard_Type.hxx>
7fd59977 22#include <TDataStd_DeltaOnModificationOfRealArray.hxx>
42cf5bc1 23#include <TDF_Attribute.hxx>
7fd59977 24#include <TDF_DefaultDeltaOnModification.hxx>
42cf5bc1 25#include <TDF_DeltaOnModification.hxx>
26#include <TDF_Label.hxx>
27#include <TDF_RelocationTable.hxx>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(TDataStd_RealArray,TDF_Attribute)
30
7fd59977 31//=======================================================================
32//function : GetID
33//purpose :
34//=======================================================================
7fd59977 35const Standard_GUID& TDataStd_RealArray::GetID()
36{
37 static Standard_GUID TDataStd_RealArrayID ("2a96b61e-ec8b-11d0-bee7-080009dc3333");
38 return TDataStd_RealArrayID;
39}
40
5a1271c8 41//=======================================================================
42//function : SetAttr
43//purpose : Implements Set functionality
44//=======================================================================
45static Handle(TDataStd_RealArray) SetAttr(const TDF_Label& label,
46 const Standard_Integer lower,
47 const Standard_Integer upper,
48 const Standard_Boolean isDelta,
49 const Standard_GUID& theGuid)
50{
51 Handle(TDataStd_RealArray) A;
52 if (!label.FindAttribute (theGuid, A))
53 {
54 A = new TDataStd_RealArray;
55 A->Init (lower, upper);
56 A->SetDelta(isDelta);
57 A->SetID(theGuid);
58 label.AddAttribute(A);
59 }
60 else if (lower != A->Lower() || upper != A->Upper())
61 {
62 A->Init(lower, upper);
63 }
64 return A;
65}
7fd59977 66
67//=======================================================================
68//function : TDataStd_RealArray
69//purpose : Empty Constructor
70//=======================================================================
71
4a5eefb9 72TDataStd_RealArray::TDataStd_RealArray() : myIsDelta(Standard_False),
73 myID(GetID())
5a1271c8 74{}
7fd59977 75
76//=======================================================================
77//function : Init
78//purpose :
79//=======================================================================
80
81void TDataStd_RealArray::Init(const Standard_Integer lower,
82 const Standard_Integer upper)
83{
5a1271c8 84 Standard_RangeError_Raise_if(upper < lower,"TDataStd_RealArray::Init");
7fd59977 85 Backup(); // jfa 15.01.2003 for LH3D1378
7fd59977 86 myValue = new TColStd_HArray1OfReal(lower, upper, 0.);
87}
88
89//=======================================================================
90//function : Set
91//purpose :
92//=======================================================================
93
94Handle(TDataStd_RealArray) TDataStd_RealArray::Set
95 (const TDF_Label& label,
96 const Standard_Integer lower,
97 const Standard_Integer upper,
5a1271c8 98 const Standard_Boolean isDelta)
7fd59977 99{
5a1271c8 100 return SetAttr(label, lower, upper, isDelta, GetID());
7fd59977 101}
102
5a1271c8 103//=======================================================================
104//function : Set
105//purpose : Set user defined attribute with specific ID
106//=======================================================================
7fd59977 107
5a1271c8 108Handle(TDataStd_RealArray) TDataStd_RealArray::Set
109 (const TDF_Label& label,
110 const Standard_GUID& theGuid,
111 const Standard_Integer lower,
112 const Standard_Integer upper,
113 const Standard_Boolean isDelta)
114{
115 return SetAttr(label, lower, upper, isDelta, theGuid);
116}
7fd59977 117//=======================================================================
118//function : SetValue
119//purpose :
120//=======================================================================
121
122void TDataStd_RealArray::SetValue (const Standard_Integer index,
123 const Standard_Real value)
124{
125 // OCC2932 correction
126 if(myValue.IsNull()) return;
127 if(myValue->Value(index) == value)
5a1271c8 128 return;
7fd59977 129 Backup();
130 myValue->SetValue(index, value);
131}
132
133
134//=======================================================================
135//function : GetValue
136//purpose :
137//=======================================================================
138
139Standard_Real TDataStd_RealArray::Value (const Standard_Integer index) const
140{
141 if(myValue.IsNull()) return RealFirst();
142 return myValue->Value(index);
143}
144
145
146
147//=======================================================================
148//function : Lower
149//purpose :
150//=======================================================================
151Standard_Integer TDataStd_RealArray::Lower (void) const
152{
153 if(myValue.IsNull()) return 0;
154 return myValue->Lower();
155}
156
157
158//=======================================================================
159//function : Upper
160//purpose :
161//=======================================================================
162Standard_Integer TDataStd_RealArray::Upper (void) const
163{
164 if(myValue.IsNull()) return 0;
165 return myValue->Upper();
166}
167
168
169//=======================================================================
170//function : Length
171//purpose :
172//=======================================================================
173Standard_Integer TDataStd_RealArray::Length (void) const
174{
175 if(myValue.IsNull()) return 0;
176 return myValue->Length();
177}
178
179
180//=======================================================================
181//function : ChangeArray
182//purpose : If value of <newArray> differs from <myValue>, Backup
183// : performed and myValue refers to new instance of HArray1OfReal
184// : that holds <newArray>
185//=======================================================================
186
187void TDataStd_RealArray::ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray,
5a1271c8 188 const Standard_Boolean isCheckItems)
7fd59977 189{
190 Standard_Integer aLower = newArray->Lower();
191 Standard_Integer anUpper = newArray->Upper();
192 Standard_Boolean aDimEqual = Standard_False;
193 Standard_Integer i;
194
4efe27fc 195 if (!myValue.IsNull()) {
196 if (Lower() == aLower && Upper() == anUpper ) {
197 aDimEqual = Standard_True;
198 Standard_Boolean isEqual = Standard_True;
199 if(isCheckItems) {
200 for(i = aLower; i <= anUpper; i++) {
201 if(myValue->Value(i) != newArray->Value(i)) {
202 isEqual = Standard_False;
203 break;
204 }
5a1271c8 205 }
4efe27fc 206 if(isEqual)
207 return;
7fd59977 208 }
7fd59977 209 }
210 }
7fd59977 211
212 Backup();
213
a855b7eb 214 if(myValue.IsNull() || !aDimEqual)
7fd59977 215 myValue = new TColStd_HArray1OfReal(aLower, anUpper);
216
217 for(i = aLower; i <= anUpper; i++)
218 myValue->SetValue(i, newArray->Value(i));
219}
220
221//=======================================================================
222//function : ID
223//purpose :
224//=======================================================================
225
5a1271c8 226const Standard_GUID& TDataStd_RealArray::ID () const { return myID; }
227
228//=======================================================================
229//function : SetID
230//purpose :
231//=======================================================================
232
233void TDataStd_RealArray::SetID( const Standard_GUID& theGuid)
234{
235 if(myID == theGuid) return;
236 Backup();
237 myID = theGuid;
238}
239
240//=======================================================================
241//function : SetID
242//purpose : sets default ID
243//=======================================================================
7fd59977 244
5a1271c8 245void TDataStd_RealArray::SetID()
246{
247 Backup();
248 myID = GetID();
249}
7fd59977 250
251//=======================================================================
252//function : NewEmpty
253//purpose :
254//=======================================================================
255
256Handle(TDF_Attribute) TDataStd_RealArray::NewEmpty () const
257{
258 return new TDataStd_RealArray();
259}
260
261//=======================================================================
262//function : Restore
263//purpose :
264//=======================================================================
265
266void TDataStd_RealArray::Restore(const Handle(TDF_Attribute)& With)
267{
268 Standard_Integer i, lower, upper;
269 Handle(TDataStd_RealArray) anArray = Handle(TDataStd_RealArray)::DownCast(With);
270 if(!anArray->myValue.IsNull()) {
271 lower = anArray->Lower();
272 upper = anArray->Upper();
273 myIsDelta = anArray->myIsDelta;
274 myValue = new TColStd_HArray1OfReal(lower, upper);
275 for(i = lower; i<=upper; i++)
276 myValue->SetValue(i, anArray->Value(i));
5a1271c8 277 myID = anArray->ID();
7fd59977 278 }
279 else
280 myValue.Nullify();
281}
282
283//=======================================================================
284//function : Paste
285//purpose :
286//=======================================================================
287
288void TDataStd_RealArray::Paste (const Handle(TDF_Attribute)& Into,
289 const Handle(TDF_RelocationTable)& ) const
290{
291 if(!myValue.IsNull()) {
292 Handle(TDataStd_RealArray) anAtt = Handle(TDataStd_RealArray)::DownCast(Into);
293 if(!anAtt.IsNull()) {
294 anAtt->ChangeArray( myValue, Standard_False );
295 anAtt->SetDelta(myIsDelta);
5a1271c8 296 anAtt->SetID(myID);
7fd59977 297 }
298 }
299}
300
301//=======================================================================
302//function : Dump
303//purpose :
304//=======================================================================
305
306Standard_OStream& TDataStd_RealArray::Dump (Standard_OStream& anOS) const
307{
308 anOS << "\nRealArray::" << this <<" :";
309 if(!myValue.IsNull()) {
310 Standard_Integer i, lower, upper;
311 lower = myValue->Lower();
312 upper = myValue->Upper();
313 for(i = lower; i<=upper; i++)
314 anOS << " " <<myValue->Value(i);
315 }
eb901da6 316 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
5a1271c8 317 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
318 myID.ToCString(sguid);
319 anOS << sguid;
04232180 320 anOS << std::endl;
7fd59977 321 return anOS;
322}
323
324//=======================================================================
325//function : DeltaOnModification
326//purpose :
327//=======================================================================
328
329Handle(TDF_DeltaOnModification) TDataStd_RealArray::DeltaOnModification
330(const Handle(TDF_Attribute)& OldAtt) const
331{
332 if(myIsDelta)
c5f3a425 333 return new TDataStd_DeltaOnModificationOfRealArray(Handle(TDataStd_RealArray)::DownCast (OldAtt));
7fd59977 334 else return new TDF_DefaultDeltaOnModification(OldAtt);
335}
bc73b006 336
337//=======================================================================
338//function : DumpJson
339//purpose :
340//=======================================================================
341void TDataStd_RealArray::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
342{
343 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
344
345 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
346
347 for (TColStd_Array1OfReal::Iterator aValueIt (myValue->Array1()); aValueIt.More(); aValueIt.Next())
348 {
349 const Standard_Real& aValue = aValueIt.Value();
350 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aValue)
351 }
352
353 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsDelta)
354 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)
355}