Commit | Line | Data |
---|---|---|
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_IntegerArray.hxx> |
42cf5bc1 | 18 | |
bc73b006 | 19 | #include <Standard_Dump.hxx> |
42cf5bc1 | 20 | #include <Standard_GUID.hxx> |
21 | #include <Standard_Type.hxx> | |
7fd59977 | 22 | #include <TDataStd_DeltaOnModificationOfIntArray.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 | 29 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntegerArray,TDF_Attribute) |
30 | ||
7fd59977 | 31 | //======================================================================= |
32 | //function : GetID | |
33 | //purpose : | |
34 | //======================================================================= | |
7fd59977 | 35 | const Standard_GUID& TDataStd_IntegerArray::GetID() |
36 | { | |
37 | static Standard_GUID TDataStd_IntegerArrayID ("2a96b61d-ec8b-11d0-bee7-080009dc3333"); | |
38 | return TDataStd_IntegerArrayID; | |
39 | } | |
40 | ||
5a1271c8 | 41 | //======================================================================= |
42 | //function : SetAttr | |
43 | //purpose : Implements Set functionality | |
44 | //======================================================================= | |
45 | static Handle(TDataStd_IntegerArray) 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_IntegerArray) A; | |
52 | if (!label.FindAttribute (theGuid, A)) | |
53 | { | |
54 | A = new TDataStd_IntegerArray; | |
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_IntegerArray | |
69 | //purpose : Empty Constructor | |
70 | //======================================================================= | |
71 | ||
72 | TDataStd_IntegerArray::TDataStd_IntegerArray() | |
4a5eefb9 | 73 | :myIsDelta(Standard_False), myID(GetID()) |
5a1271c8 | 74 | {} |
7fd59977 | 75 | |
76 | //======================================================================= | |
77 | //function : Init | |
78 | //purpose : | |
79 | //======================================================================= | |
80 | ||
81 | void TDataStd_IntegerArray::Init(const Standard_Integer lower, | |
82 | const Standard_Integer upper) | |
83 | { | |
5a1271c8 | 84 | Standard_RangeError_Raise_if(upper < lower,"TDataStd_IntegerArray::Init"); |
7fd59977 | 85 | Backup(); |
7fd59977 | 86 | myValue = new TColStd_HArray1OfInteger(lower, upper, 0); |
87 | } | |
88 | ||
89 | //======================================================================= | |
90 | //function : Set | |
91 | //purpose : isDelta applicable only for new attributes | |
92 | //======================================================================= | |
93 | ||
94 | Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::Set | |
95 | (const TDF_Label& label, | |
96 | const Standard_Integer lower, | |
97 | const Standard_Integer upper, | |
5a1271c8 | 98 | const Standard_Boolean isDelta) |
7fd59977 | 99 | |
100 | { | |
5a1271c8 | 101 | return SetAttr(label, lower, upper, isDelta, GetID()); |
7fd59977 | 102 | } |
103 | ||
5a1271c8 | 104 | //======================================================================= |
105 | //function : Set | |
106 | //purpose : Set user defined attribute with specific ID | |
107 | //======================================================================= | |
108 | ||
109 | Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::Set | |
110 | (const TDF_Label& label, | |
111 | const Standard_GUID& theGuid, | |
112 | const Standard_Integer lower, | |
113 | const Standard_Integer upper, | |
114 | const Standard_Boolean isDelta) | |
115 | ||
116 | { | |
117 | return SetAttr(label, lower, upper, isDelta, theGuid); | |
118 | } | |
7fd59977 | 119 | //======================================================================= |
120 | //function : SetValue | |
121 | //purpose : | |
122 | //======================================================================= | |
123 | ||
124 | void TDataStd_IntegerArray::SetValue(const Standard_Integer index, const Standard_Integer value) | |
125 | { | |
126 | if(myValue.IsNull()) return; | |
127 | if( myValue->Value(index) == value) | |
fa13a85d | 128 | return; |
7fd59977 | 129 | Backup(); |
130 | myValue->SetValue(index, value); | |
131 | } | |
132 | ||
133 | ||
134 | //======================================================================= | |
135 | //function : GetValue | |
136 | //purpose : | |
137 | //======================================================================= | |
138 | ||
139 | Standard_Integer TDataStd_IntegerArray::Value (const Standard_Integer index) const | |
140 | { | |
141 | if(myValue.IsNull()) return 0; | |
142 | return myValue->Value(index); | |
143 | } | |
144 | ||
145 | ||
146 | ||
147 | //======================================================================= | |
148 | //function : Lower | |
149 | //purpose : | |
150 | //======================================================================= | |
151 | Standard_Integer TDataStd_IntegerArray::Lower (void) const | |
152 | { | |
153 | if(myValue.IsNull()) return 0; | |
154 | return myValue->Lower(); | |
155 | } | |
156 | ||
157 | ||
158 | //======================================================================= | |
159 | //function : Upper | |
160 | //purpose : | |
161 | //======================================================================= | |
162 | Standard_Integer TDataStd_IntegerArray::Upper (void) const | |
163 | { | |
164 | if(myValue.IsNull()) return 0; | |
165 | return myValue->Upper(); | |
166 | } | |
167 | ||
168 | ||
169 | //======================================================================= | |
170 | //function : Length | |
171 | //purpose : | |
172 | //======================================================================= | |
173 | Standard_Integer TDataStd_IntegerArray::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 HArray1OfInteger | |
184 | // : that holds <newArray> | |
185 | //======================================================================= | |
186 | ||
187 | void TDataStd_IntegerArray::ChangeArray(const Handle(TColStd_HArray1OfInteger)& 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; | |
a855b7eb S |
194 | |
195 | if(Lower() == aLower && Upper() == anUpper ) { | |
7fd59977 | 196 | aDimEqual = Standard_True; |
197 | if(isCheckItems) { | |
198 | Standard_Boolean isEqual = Standard_True; | |
199 | for(i = aLower; i <= anUpper; i++) { | |
5a1271c8 | 200 | if(myValue->Value(i) != newArray->Value(i)) { |
201 | isEqual = Standard_False; | |
202 | break; | |
203 | } | |
7fd59977 | 204 | } |
205 | if(isEqual) | |
5a1271c8 | 206 | return; |
7fd59977 | 207 | } |
208 | } | |
5a1271c8 | 209 | |
7fd59977 | 210 | Backup(); |
211 | // Handles of myValue of current and backuped attributes will be different! | |
a855b7eb | 212 | if(myValue.IsNull() || !aDimEqual) |
7fd59977 | 213 | myValue = new TColStd_HArray1OfInteger(aLower, anUpper); |
214 | ||
215 | for(i = aLower; i <= anUpper; i++) | |
216 | myValue->SetValue(i, newArray->Value(i)); | |
217 | } | |
218 | ||
219 | ||
220 | //======================================================================= | |
221 | //function : ID | |
222 | //purpose : | |
223 | //======================================================================= | |
224 | ||
5a1271c8 | 225 | const Standard_GUID& TDataStd_IntegerArray::ID () const { return myID; } |
7fd59977 | 226 | |
5a1271c8 | 227 | //======================================================================= |
228 | //function : SetID | |
229 | //purpose : | |
230 | //======================================================================= | |
231 | ||
232 | void TDataStd_IntegerArray::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 | //======================================================================= | |
243 | ||
244 | void TDataStd_IntegerArray::SetID() | |
245 | { | |
246 | Backup(); | |
247 | myID = GetID(); | |
248 | } | |
7fd59977 | 249 | |
250 | //======================================================================= | |
251 | //function : NewEmpty | |
252 | //purpose : | |
253 | //======================================================================= | |
254 | ||
255 | Handle(TDF_Attribute) TDataStd_IntegerArray::NewEmpty () const | |
256 | { | |
257 | return new TDataStd_IntegerArray(); | |
258 | } | |
259 | ||
260 | //======================================================================= | |
261 | //function : Restore | |
262 | //purpose : | |
263 | //======================================================================= | |
264 | ||
265 | void TDataStd_IntegerArray::Restore(const Handle(TDF_Attribute)& With) | |
266 | { | |
267 | Standard_Integer i, lower, upper; | |
268 | Handle(TDataStd_IntegerArray) anArray = Handle(TDataStd_IntegerArray)::DownCast(With); | |
269 | if(!anArray->myValue.IsNull()) { | |
270 | lower = anArray->Lower(); | |
271 | upper = anArray->Upper(); | |
272 | myValue = new TColStd_HArray1OfInteger(lower, upper); | |
273 | for(i = lower; i<=upper; i++) | |
274 | myValue->SetValue(i, anArray->Value(i)); | |
275 | myIsDelta = anArray->myIsDelta; | |
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_IntegerArray::Paste (const Handle(TDF_Attribute)& Into, | |
288 | const Handle(TDF_RelocationTable)& ) const | |
289 | { | |
290 | ||
291 | if(!myValue.IsNull()) { | |
292 | Handle(TDataStd_IntegerArray) anAtt = Handle(TDataStd_IntegerArray)::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 | ||
306 | Standard_OStream& TDataStd_IntegerArray::Dump (Standard_OStream& anOS) const | |
307 | { | |
308 | anOS << "\nIntegerArray:: " << 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 | |
322 | // anOS <<"\nAttribute fields: "; | |
323 | // anOS << TDF_Attribute::Dump(anOS); | |
324 | ||
325 | return anOS; | |
326 | } | |
327 | ||
328 | //======================================================================= | |
329 | //function : DeltaOnModification | |
330 | //purpose : | |
331 | //======================================================================= | |
332 | ||
333 | Handle(TDF_DeltaOnModification) TDataStd_IntegerArray::DeltaOnModification | |
334 | (const Handle(TDF_Attribute)& OldAttribute) const | |
335 | { | |
336 | if(myIsDelta) | |
c5f3a425 | 337 | return new TDataStd_DeltaOnModificationOfIntArray(Handle(TDataStd_IntegerArray)::DownCast (OldAttribute)); |
7fd59977 | 338 | else return new TDF_DefaultDeltaOnModification(OldAttribute); |
339 | } | |
bc73b006 | 340 | |
341 | //======================================================================= | |
342 | //function : DumpJson | |
343 | //purpose : | |
344 | //======================================================================= | |
345 | void TDataStd_IntegerArray::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const | |
346 | { | |
347 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) | |
348 | ||
349 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute) | |
350 | ||
351 | for (TColStd_Array1OfInteger::Iterator aValueIt (myValue->Array1()); aValueIt.More(); aValueIt.Next()) | |
352 | { | |
353 | const Standard_Integer& aValue = aValueIt.Value(); | |
354 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, aValue) | |
355 | } | |
356 | ||
357 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsDelta) | |
358 | OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID) | |
359 | } |