1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <TDataStd_ByteArray.ixx>
17 #include <TDataStd_DeltaOnModificationOfByteArray.hxx>
18 #include <TDF_DefaultDeltaOnModification.hxx>
20 //=======================================================================
23 //=======================================================================
24 const Standard_GUID& TDataStd_ByteArray::GetID()
26 static Standard_GUID TDataStd_ByteArrayID ("FD9B918F-2980-4c66-85E0-D71965475290");
27 return TDataStd_ByteArrayID;
30 //=======================================================================
31 //function : TDataStd_ByteArray
32 //purpose : Empty Constructor
33 //=======================================================================
34 TDataStd_ByteArray::TDataStd_ByteArray() : myIsDelta(Standard_False){}
37 //=======================================================================
40 //=======================================================================
41 void TDataStd_ByteArray::Init(const Standard_Integer lower,
42 const Standard_Integer upper)
47 myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
50 //=======================================================================
53 //=======================================================================
54 Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
55 const Standard_Integer lower,
56 const Standard_Integer upper,
57 const Standard_Boolean isDelta)
59 Handle(TDataStd_ByteArray) A;
60 if (!label.FindAttribute (TDataStd_ByteArray::GetID(), A))
62 A = new TDataStd_ByteArray;
63 A->Init (lower, upper);
65 label.AddAttribute(A);
70 //=======================================================================
73 //=======================================================================
74 void TDataStd_ByteArray::SetValue (const Standard_Integer index,
75 const Standard_Byte value)
79 if (value == myValue->Value(index))
83 myValue->SetValue(index, value);
86 //=======================================================================
89 //=======================================================================
90 Standard_Byte TDataStd_ByteArray::Value (const Standard_Integer index) const
92 return myValue->Value(index);
95 //=======================================================================
98 //=======================================================================
99 Standard_Integer TDataStd_ByteArray::Lower (void) const
101 if (myValue.IsNull())
103 return myValue->Lower();
106 //=======================================================================
109 //=======================================================================
110 Standard_Integer TDataStd_ByteArray::Upper (void) const
112 if (myValue.IsNull()) return -1;
113 return myValue->Upper();
116 //=======================================================================
119 //=======================================================================
120 Standard_Integer TDataStd_ByteArray::Length (void) const
122 if (myValue.IsNull())
124 return myValue->Length();
127 //=======================================================================
128 //function : ChangeArray
129 //purpose : If value of <newArray> differs from <myValue>, Backup
130 // : performed and myValue refers to new instance of HArray1OfByte
131 // : that holds <newArray>
132 //=======================================================================
133 void TDataStd_ByteArray::ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray,
134 const Standard_Boolean isCheckItems)
137 Standard_Integer aLower = newArray->Lower();
138 Standard_Integer anUpper = newArray->Upper();
139 Standard_Boolean aDimEqual = Standard_False;
142 if ( Lower() == aLower && Upper() == anUpper ) {
143 aDimEqual = Standard_True;
145 Standard_Boolean isEqual = Standard_True;
146 for(i = aLower; i <= anUpper; i++) {
147 if(myValue->Value(i) != newArray->Value(i)) {
148 isEqual = Standard_False;
158 // Handles of myValue of current and backuped attributes will be different!
159 if(myValue.IsNull() || !aDimEqual)
160 myValue = new TColStd_HArray1OfByte(aLower, anUpper);
162 for(i = aLower; i <= anUpper; i++)
163 myValue->SetValue(i, newArray->Value(i));
166 //=======================================================================
169 //=======================================================================
170 const Standard_GUID& TDataStd_ByteArray::ID () const
175 //=======================================================================
176 //function : NewEmpty
178 //=======================================================================
179 Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty () const
181 return new TDataStd_ByteArray();
184 //=======================================================================
187 //=======================================================================
188 void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With)
190 Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
191 if (!anArray->myValue.IsNull())
193 const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
194 Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
195 myValue = new TColStd_HArray1OfByte(lower, upper);
196 for (; i <= upper; i++)
197 myValue->SetValue(i, with_array.Value(i));
198 myIsDelta = anArray->myIsDelta;
204 //=======================================================================
207 //=======================================================================
208 void TDataStd_ByteArray::Paste (const Handle(TDF_Attribute)& Into,
209 const Handle(TDF_RelocationTable)& ) const
211 if (!myValue.IsNull())
213 Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
216 anAtt->ChangeArray( myValue, Standard_False);
217 anAtt->SetDelta(myIsDelta);
222 //=======================================================================
225 //=======================================================================
226 Standard_OStream& TDataStd_ByteArray::Dump (Standard_OStream& anOS) const
232 //=======================================================================
233 //function : DeltaOnModification
235 //=======================================================================
237 Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification
238 (const Handle(TDF_Attribute)& OldAttribute) const
241 return new TDataStd_DeltaOnModificationOfByteArray(Handle(TDataStd_ByteArray)::DownCast (OldAttribute));
242 else return new TDF_DefaultDeltaOnModification(OldAttribute);