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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_GUID.hxx>
19 #include <Standard_Type.hxx>
20 #include <TDataStd_DeltaOnModificationOfIntArray.hxx>
21 #include <TDataStd_IntegerArray.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>
28 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_IntegerArray,TDF_Attribute)
30 //=======================================================================
33 //=======================================================================
34 const Standard_GUID& TDataStd_IntegerArray::GetID()
36 static Standard_GUID TDataStd_IntegerArrayID ("2a96b61d-ec8b-11d0-bee7-080009dc3333");
37 return TDataStd_IntegerArrayID;
40 //=======================================================================
42 //purpose : Implements Set functionality
43 //=======================================================================
44 static Handle(TDataStd_IntegerArray) 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)
50 Handle(TDataStd_IntegerArray) A;
51 if (!label.FindAttribute (theGuid, A))
53 A = new TDataStd_IntegerArray;
54 A->Init (lower, upper);
57 label.AddAttribute(A);
59 else if (lower != A->Lower() || upper != A->Upper())
61 A->Init(lower, upper);
66 //=======================================================================
67 //function : TDataStd_IntegerArray
68 //purpose : Empty Constructor
69 //=======================================================================
71 TDataStd_IntegerArray::TDataStd_IntegerArray()
72 :myIsDelta(Standard_False)
75 //=======================================================================
78 //=======================================================================
80 void TDataStd_IntegerArray::Init(const Standard_Integer lower,
81 const Standard_Integer upper)
83 Standard_RangeError_Raise_if(upper < lower,"TDataStd_IntegerArray::Init");
85 myValue = new TColStd_HArray1OfInteger(lower, upper, 0);
88 //=======================================================================
90 //purpose : isDelta applicable only for new attributes
91 //=======================================================================
93 Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::Set
94 (const TDF_Label& label,
95 const Standard_Integer lower,
96 const Standard_Integer upper,
97 const Standard_Boolean isDelta)
100 return SetAttr(label, lower, upper, isDelta, GetID());
103 //=======================================================================
105 //purpose : Set user defined attribute with specific ID
106 //=======================================================================
108 Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::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)
116 return SetAttr(label, lower, upper, isDelta, theGuid);
118 //=======================================================================
119 //function : SetValue
121 //=======================================================================
123 void TDataStd_IntegerArray::SetValue(const Standard_Integer index, const Standard_Integer value)
125 if(myValue.IsNull()) return;
126 if( myValue->Value(index) == value)
129 myValue->SetValue(index, value);
133 //=======================================================================
134 //function : GetValue
136 //=======================================================================
138 Standard_Integer TDataStd_IntegerArray::Value (const Standard_Integer index) const
140 if(myValue.IsNull()) return 0;
141 return myValue->Value(index);
146 //=======================================================================
149 //=======================================================================
150 Standard_Integer TDataStd_IntegerArray::Lower (void) const
152 if(myValue.IsNull()) return 0;
153 return myValue->Lower();
157 //=======================================================================
160 //=======================================================================
161 Standard_Integer TDataStd_IntegerArray::Upper (void) const
163 if(myValue.IsNull()) return 0;
164 return myValue->Upper();
168 //=======================================================================
171 //=======================================================================
172 Standard_Integer TDataStd_IntegerArray::Length (void) const
174 if(myValue.IsNull()) return 0;
175 return myValue->Length();
179 //=======================================================================
180 //function : ChangeArray
181 //purpose : If value of <newArray> differs from <myValue>, Backup
182 // : performed and myValue refers to new instance of HArray1OfInteger
183 // : that holds <newArray>
184 //=======================================================================
186 void TDataStd_IntegerArray::ChangeArray(const Handle(TColStd_HArray1OfInteger)& newArray,
187 const Standard_Boolean isCheckItems)
189 Standard_Integer aLower = newArray->Lower();
190 Standard_Integer anUpper = newArray->Upper();
191 Standard_Boolean aDimEqual = Standard_False;
194 if(Lower() == aLower && Upper() == anUpper ) {
195 aDimEqual = Standard_True;
197 Standard_Boolean isEqual = Standard_True;
198 for(i = aLower; i <= anUpper; i++) {
199 if(myValue->Value(i) != newArray->Value(i)) {
200 isEqual = Standard_False;
210 // Handles of myValue of current and backuped attributes will be different!
211 if(myValue.IsNull() || !aDimEqual)
212 myValue = new TColStd_HArray1OfInteger(aLower, anUpper);
214 for(i = aLower; i <= anUpper; i++)
215 myValue->SetValue(i, newArray->Value(i));
219 //=======================================================================
222 //=======================================================================
224 const Standard_GUID& TDataStd_IntegerArray::ID () const { return myID; }
226 //=======================================================================
229 //=======================================================================
231 void TDataStd_IntegerArray::SetID( const Standard_GUID& theGuid)
233 if(myID == theGuid) return;
238 //=======================================================================
240 //purpose : sets default ID
241 //=======================================================================
243 void TDataStd_IntegerArray::SetID()
249 //=======================================================================
250 //function : NewEmpty
252 //=======================================================================
254 Handle(TDF_Attribute) TDataStd_IntegerArray::NewEmpty () const
256 return new TDataStd_IntegerArray();
259 //=======================================================================
262 //=======================================================================
264 void TDataStd_IntegerArray::Restore(const Handle(TDF_Attribute)& With)
266 Standard_Integer i, lower, upper;
267 Handle(TDataStd_IntegerArray) anArray = Handle(TDataStd_IntegerArray)::DownCast(With);
268 if(!anArray->myValue.IsNull()) {
269 lower = anArray->Lower();
270 upper = anArray->Upper();
271 myValue = new TColStd_HArray1OfInteger(lower, upper);
272 for(i = lower; i<=upper; i++)
273 myValue->SetValue(i, anArray->Value(i));
274 myIsDelta = anArray->myIsDelta;
275 myID = anArray->ID();
281 //=======================================================================
284 //=======================================================================
286 void TDataStd_IntegerArray::Paste (const Handle(TDF_Attribute)& Into,
287 const Handle(TDF_RelocationTable)& ) const
290 if(!myValue.IsNull()) {
291 Handle(TDataStd_IntegerArray) anAtt = Handle(TDataStd_IntegerArray)::DownCast(Into);
292 if(!anAtt.IsNull()) {
293 anAtt->ChangeArray( myValue, Standard_False );
294 anAtt->SetDelta(myIsDelta);
300 //=======================================================================
303 //=======================================================================
305 Standard_OStream& TDataStd_IntegerArray::Dump (Standard_OStream& anOS) const
307 anOS << "\nIntegerArray:: " << 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);
315 anOS << " Delta is " << (myIsDelta ? "ON":"OFF");
316 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
317 myID.ToCString(sguid);
321 // anOS <<"\nAttribute fields: ";
322 // anOS << TDF_Attribute::Dump(anOS);
327 //=======================================================================
328 //function : DeltaOnModification
330 //=======================================================================
332 Handle(TDF_DeltaOnModification) TDataStd_IntegerArray::DeltaOnModification
333 (const Handle(TDF_Attribute)& OldAttribute) const
336 return new TDataStd_DeltaOnModificationOfIntArray(Handle(TDataStd_IntegerArray)::DownCast (OldAttribute));
337 else return new TDF_DefaultDeltaOnModification(OldAttribute);