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