1 // Created on: 2007-12-05
2 // Created by: Sergey ZARITCHNY
3 // Copyright (c) 2007-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <TDataStd_DeltaOnModificationOfByteArray.ixx>
22 #include <TDataStd_ByteArray.hxx>
23 #include <TDF_DeltaOnModification.hxx>
24 #include <TDF_Label.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColStd_HArray1OfByte.hxx>
27 #include <TColStd_ListOfInteger.hxx>
28 #include <TColStd_ListIteratorOfListOfInteger.hxx>
29 #include <TDF_AttributeIterator.hxx>
34 //=======================================================================
35 //function : TDataStd_DeltaOnModificationOfByteArray
37 //=======================================================================
39 TDataStd_DeltaOnModificationOfByteArray::TDataStd_DeltaOnModificationOfByteArray(const Handle(TDataStd_ByteArray)& OldAtt)
40 : TDF_DeltaOnModification(OldAtt)
42 Handle(TDataStd_ByteArray) CurrAtt;
43 if (Label().FindAttribute(OldAtt->ID(),CurrAtt)) {
45 Handle(TColStd_HArray1OfByte) Arr1, Arr2;
46 Arr1 = OldAtt->InternalArray();
47 Arr2 = CurrAtt->InternalArray();
50 cout <<"DeltaOnModificationOfByteArray:: Old ByteArray is Null" <<endl;
52 cout <<"DeltaOnModificationOfByteArray:: Current ByteArray is Null" <<endl;
55 if(Arr1.IsNull() || Arr2.IsNull()) return;
57 myUp1 = Arr1->Upper();
58 myUp2 = Arr2->Upper();
59 Standard_Integer i, N=0, aCase=0;
61 {aCase = 1; N = myUp1;}
62 else if(myUp1 < myUp2)
63 {aCase = 2; N = myUp1;}
65 {aCase = 3; N = myUp2;}//Up1 > Up2
67 TColStd_ListOfInteger aList;
68 for(i=Arr1->Lower();i<= N; i++)
69 if(Arr1->Value(i) != Arr2->Value(i))
72 for(i = N+1;i <= myUp1; i++)
77 myIndxes = new TColStd_HArray1OfInteger(1,aList.Extent());
78 myValues = new TColStd_HArray1OfByte(1,aList.Extent());
79 TColStd_ListIteratorOfListOfInteger anIt(aList);
80 for(i =1;anIt.More();anIt.Next(),i++) {
81 myIndxes->SetValue(i, anIt.Value());
82 myValues->SetValue(i, Arr1->Value(anIt.Value()));
87 OldAtt->RemoveArray();
89 if(OldAtt->InternalArray().IsNull())
90 cout << "BackUp Arr is Nullified" << endl;
96 //=======================================================================
99 //=======================================================================
101 void TDataStd_DeltaOnModificationOfByteArray::Apply()
104 Handle(TDF_Attribute) TDFAttribute = Attribute();
105 Handle(TDataStd_ByteArray) BackAtt = (*((Handle(TDataStd_ByteArray)*)&TDFAttribute));
106 if(BackAtt.IsNull()) {
108 cout << "DeltaOnModificationOfByteArray::Apply: OldAtt is Null" <<endl;
113 Handle(TDataStd_ByteArray) aCurAtt;
114 if (!Label().FindAttribute(BackAtt->ID(),aCurAtt)) {
116 Label().AddAttribute(BackAtt);
119 if(aCurAtt.IsNull()) {
121 cout << "DeltaOnModificationOfByteArray::Apply: CurAtt is Null" <<endl;
128 Standard_Integer aCase;
131 else if(myUp1 < myUp2)
134 aCase = 3;//Up1 > Up2
136 if (aCase == 1 && (myIndxes.IsNull() || myValues.IsNull()))
140 Handle(TColStd_HArray1OfByte) BArr = aCurAtt->InternalArray();
141 if(BArr.IsNull()) return;
143 for(i = 1; i <= myIndxes->Upper();i++)
144 BArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));
145 else if(aCase == 2) {
146 Handle(TColStd_HArray1OfByte) byteArr = new TColStd_HArray1OfByte(BArr->Lower(), myUp1);
147 for(i = BArr->Lower(); i <= myUp1 && i <= BArr->Upper(); i++)
148 byteArr->SetValue(i, BArr->Value(i));
149 if(!myIndxes.IsNull() && !myValues.IsNull())
150 for(i = 1; i <= myIndxes->Upper();i++)
151 byteArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));
152 aCurAtt->myValue = byteArr;
155 Standard_Integer low = BArr->Lower();
156 Handle(TColStd_HArray1OfByte) byteArr = new TColStd_HArray1OfByte(low, myUp1);
157 for(i = BArr->Lower(); i <= myUp2 && i <= BArr->Upper(); i++)
158 byteArr->SetValue(i, BArr->Value(i));
159 if(!myIndxes.IsNull() && !myValues.IsNull())
160 for(i = 1; i <= myIndxes->Upper();i++) {
162 cout << "i = " << i << " myIndxes->Upper = " << myIndxes->Upper() << endl;
163 cout << "myIndxes->Value(i) = " << myIndxes->Value(i) << endl;
164 cout << "myValues->Value(i) = " << myValues->Value(i) << endl;
166 byteArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i));
168 aCurAtt->myValue = byteArr;
172 cout << " << Array Dump after Delta Apply >>" <<endl;
173 Handle(TColStd_HArray1OfByte) BArr2 = aCurAtt->InternalArray();
174 for(i=BArr2->Lower(); i<=BArr2->Upper() && i<= MAXUP;i++)
175 cout << BArr2->Value(i) << " ";