Warnings on vc14 were eliminated
[occt.git] / src / TDataStd / TDataStd_RealArray.cxx
1 // Created on: 1999-06-16
2 // Created by: Sergey RUIN
3 // Copyright (c) 1999-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_DeltaOnModificationOfRealArray.hxx>
21 #include <TDataStd_RealArray.hxx>
22 #include <TDF_Attribute.hxx>
23 #include <TDF_DefaultDeltaOnModification.hxx>
24 #include <TDF_DeltaOnModification.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_RelocationTable.hxx>
27
28 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_RealArray,TDF_Attribute)
29
30 //=======================================================================
31 //function : GetID
32 //purpose  : 
33 //=======================================================================
34 const Standard_GUID& TDataStd_RealArray::GetID() 
35
36   static Standard_GUID TDataStd_RealArrayID ("2a96b61e-ec8b-11d0-bee7-080009dc3333");
37   return TDataStd_RealArrayID; 
38 }
39
40
41 //=======================================================================
42 //function : TDataStd_RealArray
43 //purpose  : Empty Constructor
44 //=======================================================================
45
46 TDataStd_RealArray::TDataStd_RealArray() : myIsDelta(Standard_False){}
47
48 //=======================================================================
49 //function : Init
50 //purpose  : 
51 //=======================================================================
52
53 void TDataStd_RealArray::Init(const Standard_Integer lower,
54                               const Standard_Integer upper)
55 {
56   Backup(); // jfa 15.01.2003 for LH3D1378
57
58   myValue = new TColStd_HArray1OfReal(lower, upper, 0.);
59 }
60
61 //=======================================================================
62 //function : Set
63 //purpose  : 
64 //=======================================================================
65
66 Handle(TDataStd_RealArray) TDataStd_RealArray::Set
67                                           (const TDF_Label&       label,
68                                            const Standard_Integer lower,
69                                            const Standard_Integer upper,
70                                            const Standard_Boolean isDelta) 
71 {
72   Handle(TDataStd_RealArray) A;
73   if (!label.FindAttribute (TDataStd_RealArray::GetID(), A)) {
74     A = new TDataStd_RealArray;
75     A->Init (lower, upper);
76     A->SetDelta(isDelta); 
77     label.AddAttribute(A);
78   }
79   else if (lower != A->Lower() || upper != A->Upper())
80   {
81     A->Init (lower, upper); 
82   }
83   return A;
84 }
85
86
87 //=======================================================================
88 //function : SetValue
89 //purpose  : 
90 //=======================================================================
91
92 void TDataStd_RealArray::SetValue (const Standard_Integer index,
93                                    const Standard_Real value) 
94 {
95   // OCC2932 correction
96   if(myValue.IsNull()) return;
97   if(myValue->Value(index) == value)
98     return;  
99   Backup();
100   myValue->SetValue(index, value);
101 }
102
103
104 //=======================================================================
105 //function : GetValue
106 //purpose  : 
107 //=======================================================================
108
109 Standard_Real TDataStd_RealArray::Value (const Standard_Integer index) const 
110 {
111   if(myValue.IsNull()) return RealFirst();
112   return myValue->Value(index); 
113 }
114
115
116
117 //=======================================================================
118 //function : Lower
119 //purpose  : 
120 //=======================================================================
121 Standard_Integer TDataStd_RealArray::Lower (void) const 
122
123   if(myValue.IsNull()) return 0;
124   return myValue->Lower(); 
125 }
126
127
128 //=======================================================================
129 //function : Upper
130 //purpose  : 
131 //=======================================================================
132 Standard_Integer TDataStd_RealArray::Upper (void) const 
133
134   if(myValue.IsNull()) return 0;
135   return myValue->Upper(); 
136 }
137
138
139 //=======================================================================
140 //function : Length
141 //purpose  : 
142 //=======================================================================
143 Standard_Integer TDataStd_RealArray::Length (void) const 
144 {
145   if(myValue.IsNull()) return 0;
146   return myValue->Length(); 
147 }
148
149
150 //=======================================================================
151 //function : ChangeArray
152 //purpose  : If value of <newArray> differs from <myValue>, Backup 
153 //         : performed and myValue refers to new instance of HArray1OfReal
154 //         : that holds <newArray>
155 //=======================================================================
156
157 void TDataStd_RealArray::ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray,
158                                         const Standard_Boolean isCheckItems) 
159 {
160   Standard_Integer aLower    = newArray->Lower();
161   Standard_Integer anUpper   = newArray->Upper();
162   Standard_Boolean aDimEqual = Standard_False;
163   Standard_Integer i;
164
165   if (Lower() == aLower && Upper() == anUpper ) {
166     aDimEqual = Standard_True;
167     Standard_Boolean isEqual = Standard_True;
168     if(isCheckItems) {
169       for(i = aLower; i <= anUpper; i++) {
170         if(myValue->Value(i) != newArray->Value(i)) {
171           isEqual = Standard_False;
172           break;
173         }
174       }
175       if(isEqual)
176         return;
177     }
178   }
179
180   Backup();
181
182   if(myValue.IsNull() || !aDimEqual) 
183     myValue = new TColStd_HArray1OfReal(aLower, anUpper);
184
185   for(i = aLower; i <= anUpper; i++) 
186     myValue->SetValue(i, newArray->Value(i));
187 }
188
189 //=======================================================================
190 //function : ID
191 //purpose  : 
192 //=======================================================================
193
194 const Standard_GUID& TDataStd_RealArray::ID () const { return GetID(); }
195
196
197 //=======================================================================
198 //function : NewEmpty
199 //purpose  : 
200 //=======================================================================
201
202 Handle(TDF_Attribute) TDataStd_RealArray::NewEmpty () const
203 {  
204   return new TDataStd_RealArray(); 
205 }
206
207 //=======================================================================
208 //function : Restore
209 //purpose  : 
210 //=======================================================================
211
212 void TDataStd_RealArray::Restore(const Handle(TDF_Attribute)& With) 
213 {
214   Standard_Integer i, lower, upper;
215   Handle(TDataStd_RealArray) anArray = Handle(TDataStd_RealArray)::DownCast(With);
216   if(!anArray->myValue.IsNull()) {
217     lower = anArray->Lower();
218     upper = anArray->Upper();
219     myIsDelta = anArray->myIsDelta;
220     myValue = new TColStd_HArray1OfReal(lower, upper);
221     for(i = lower; i<=upper; i++)
222       myValue->SetValue(i, anArray->Value(i)); 
223   }
224   else
225     myValue.Nullify();
226 }
227
228 //=======================================================================
229 //function : Paste
230 //purpose  : 
231 //=======================================================================
232
233 void TDataStd_RealArray::Paste (const Handle(TDF_Attribute)& Into,
234                                 const Handle(TDF_RelocationTable)& ) const
235 {
236   if(!myValue.IsNull()) {    
237     Handle(TDataStd_RealArray) anAtt = Handle(TDataStd_RealArray)::DownCast(Into);
238     if(!anAtt.IsNull()) {
239       anAtt->ChangeArray( myValue, Standard_False );
240       anAtt->SetDelta(myIsDelta);
241     }
242   }
243 }
244
245 //=======================================================================
246 //function : Dump
247 //purpose  : 
248 //=======================================================================
249
250 Standard_OStream& TDataStd_RealArray::Dump (Standard_OStream& anOS) const
251 {  
252   anOS << "\nRealArray::" << this <<" :";
253   if(!myValue.IsNull()) {
254     Standard_Integer i, lower, upper;
255     lower = myValue->Lower();
256     upper = myValue->Upper();
257     for(i = lower; i<=upper; i++)
258       anOS << " " <<myValue->Value(i);
259   }
260   anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
261   anOS << endl;
262   return anOS;
263 }
264
265 //=======================================================================
266 //function : DeltaOnModification
267 //purpose  : 
268 //=======================================================================
269
270 Handle(TDF_DeltaOnModification) TDataStd_RealArray::DeltaOnModification
271 (const Handle(TDF_Attribute)& OldAtt) const
272 {
273   if(myIsDelta)
274     return new TDataStd_DeltaOnModificationOfRealArray(Handle(TDataStd_RealArray)::DownCast (OldAtt));
275   else return new TDF_DefaultDeltaOnModification(OldAtt);
276 }