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.
17 #include <Standard_GUID.hxx>
18 #include <Standard_Type.hxx>
19 #include <TDataStd_ByteArray.hxx>
20 #include <TDataStd_DeltaOnModificationOfByteArray.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_DefaultDeltaOnModification.hxx>
23 #include <TDF_DeltaOnModification.hxx>
24 #include <TDF_Label.hxx>
25 #include <TDF_RelocationTable.hxx>
27 //=======================================================================
30 //=======================================================================
31 const Standard_GUID& TDataStd_ByteArray::GetID()
33 static Standard_GUID TDataStd_ByteArrayID ("FD9B918F-2980-4c66-85E0-D71965475290");
34 return TDataStd_ByteArrayID;
37 //=======================================================================
38 //function : TDataStd_ByteArray
39 //purpose : Empty Constructor
40 //=======================================================================
41 TDataStd_ByteArray::TDataStd_ByteArray() : myIsDelta(Standard_False){}
44 //=======================================================================
47 //=======================================================================
48 void TDataStd_ByteArray::Init(const Standard_Integer lower,
49 const Standard_Integer upper)
54 myValue = new TColStd_HArray1OfByte(lower, upper, 0x00);
57 //=======================================================================
60 //=======================================================================
61 Handle(TDataStd_ByteArray) TDataStd_ByteArray::Set(const TDF_Label& label,
62 const Standard_Integer lower,
63 const Standard_Integer upper,
64 const Standard_Boolean isDelta)
66 Handle(TDataStd_ByteArray) A;
67 if (!label.FindAttribute (TDataStd_ByteArray::GetID(), A))
69 A = new TDataStd_ByteArray;
70 A->Init (lower, upper);
72 label.AddAttribute(A);
77 //=======================================================================
80 //=======================================================================
81 void TDataStd_ByteArray::SetValue (const Standard_Integer index,
82 const Standard_Byte value)
86 if (value == myValue->Value(index))
90 myValue->SetValue(index, value);
93 //=======================================================================
96 //=======================================================================
97 Standard_Byte TDataStd_ByteArray::Value (const Standard_Integer index) const
99 return myValue->Value(index);
102 //=======================================================================
105 //=======================================================================
106 Standard_Integer TDataStd_ByteArray::Lower (void) const
108 if (myValue.IsNull())
110 return myValue->Lower();
113 //=======================================================================
116 //=======================================================================
117 Standard_Integer TDataStd_ByteArray::Upper (void) const
119 if (myValue.IsNull()) return -1;
120 return myValue->Upper();
123 //=======================================================================
126 //=======================================================================
127 Standard_Integer TDataStd_ByteArray::Length (void) const
129 if (myValue.IsNull())
131 return myValue->Length();
134 //=======================================================================
135 //function : ChangeArray
136 //purpose : If value of <newArray> differs from <myValue>, Backup
137 // : performed and myValue refers to new instance of HArray1OfByte
138 // : that holds <newArray>
139 //=======================================================================
140 void TDataStd_ByteArray::ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray,
141 const Standard_Boolean isCheckItems)
144 Standard_Integer aLower = newArray->Lower();
145 Standard_Integer anUpper = newArray->Upper();
146 Standard_Boolean aDimEqual = Standard_False;
149 if ( Lower() == aLower && Upper() == anUpper ) {
150 aDimEqual = Standard_True;
152 Standard_Boolean isEqual = Standard_True;
153 for(i = aLower; i <= anUpper; i++) {
154 if(myValue->Value(i) != newArray->Value(i)) {
155 isEqual = Standard_False;
165 // Handles of myValue of current and backuped attributes will be different!
166 if(myValue.IsNull() || !aDimEqual)
167 myValue = new TColStd_HArray1OfByte(aLower, anUpper);
169 for(i = aLower; i <= anUpper; i++)
170 myValue->SetValue(i, newArray->Value(i));
173 //=======================================================================
176 //=======================================================================
177 const Standard_GUID& TDataStd_ByteArray::ID () const
182 //=======================================================================
183 //function : NewEmpty
185 //=======================================================================
186 Handle(TDF_Attribute) TDataStd_ByteArray::NewEmpty () const
188 return new TDataStd_ByteArray();
191 //=======================================================================
194 //=======================================================================
195 void TDataStd_ByteArray::Restore(const Handle(TDF_Attribute)& With)
197 Handle(TDataStd_ByteArray) anArray = Handle(TDataStd_ByteArray)::DownCast(With);
198 if (!anArray->myValue.IsNull())
200 const TColStd_Array1OfByte& with_array = anArray->myValue->Array1();
201 Standard_Integer lower = with_array.Lower(), i = lower, upper = with_array.Upper();
202 myValue = new TColStd_HArray1OfByte(lower, upper);
203 for (; i <= upper; i++)
204 myValue->SetValue(i, with_array.Value(i));
205 myIsDelta = anArray->myIsDelta;
211 //=======================================================================
214 //=======================================================================
215 void TDataStd_ByteArray::Paste (const Handle(TDF_Attribute)& Into,
216 const Handle(TDF_RelocationTable)& ) const
218 if (!myValue.IsNull())
220 Handle(TDataStd_ByteArray) anAtt = Handle(TDataStd_ByteArray)::DownCast(Into);
223 anAtt->ChangeArray( myValue, Standard_False);
224 anAtt->SetDelta(myIsDelta);
229 //=======================================================================
232 //=======================================================================
233 Standard_OStream& TDataStd_ByteArray::Dump (Standard_OStream& anOS) const
239 //=======================================================================
240 //function : DeltaOnModification
242 //=======================================================================
244 Handle(TDF_DeltaOnModification) TDataStd_ByteArray::DeltaOnModification
245 (const Handle(TDF_Attribute)& OldAttribute) const
248 return new TDataStd_DeltaOnModificationOfByteArray(Handle(TDataStd_ByteArray)::DownCast (OldAttribute));
249 else return new TDF_DefaultDeltaOnModification(OldAttribute);