b311480e |
1 | // Created on: 2007-12-04 |
2 | // Created by: Sergey ZARITCHNY |
973c2be1 |
3 | // Copyright (c) 2007-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #include <TDataStd_DeltaOnModificationOfExtStringArray.ixx> |
17 | #include <TDataStd_ExtStringArray.hxx> |
18 | #include <TDF_DeltaOnModification.hxx> |
19 | #include <TDF_Label.hxx> |
20 | #include <TColStd_HArray1OfExtendedString.hxx> |
21 | #include <TColStd_ListOfInteger.hxx> |
22 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
23 | #include <TDF_AttributeIterator.hxx> |
24 | |
25 | #ifdef DEB |
26 | #define MAXUP 1000 |
27 | #endif |
28 | //======================================================================= |
29 | //function : TDataStd_DeltaOnModificationOfExtStringArray |
30 | //purpose : |
31 | //======================================================================= |
32 | |
33 | TDataStd_DeltaOnModificationOfExtStringArray::TDataStd_DeltaOnModificationOfExtStringArray(const Handle(TDataStd_ExtStringArray)& OldAtt) |
34 | : TDF_DeltaOnModification(OldAtt) |
35 | { |
36 | Handle(TDataStd_ExtStringArray) CurrAtt; |
37 | if (Label().FindAttribute(OldAtt->ID(),CurrAtt)) { |
38 | { |
39 | Handle(TColStd_HArray1OfExtendedString) Arr1, Arr2; |
40 | Arr1 = OldAtt->Array(); |
41 | Arr2 = CurrAtt->Array(); |
42 | #ifdef DEB |
43 | if(Arr1.IsNull()) |
44 | cout <<"DeltaOnModificationOfExtStringArray:: Old IntArray is Null" <<endl; |
45 | if(Arr2.IsNull()) |
46 | cout <<"DeltaOnModificationOfExtStringArray:: Current IntArray is Null" <<endl; |
47 | #endif |
48 | |
49 | if(Arr1.IsNull() || Arr2.IsNull()) return; |
50 | if(Arr1 != Arr2) { |
51 | myUp1 = Arr1->Upper(); |
52 | myUp2 = Arr2->Upper(); |
53 | Standard_Integer i, N =0, aCase=0; |
54 | if(myUp1 == myUp2) |
55 | {aCase = 1; N = myUp1;} |
56 | else if(myUp1 < myUp2) |
57 | {aCase = 2; N = myUp1;} |
58 | else |
59 | {aCase = 3; N = myUp2;}//Up1 > Up2 |
60 | |
61 | TColStd_ListOfInteger aList; |
62 | for(i=Arr1->Lower();i <= N; i++) |
63 | if(Arr1->Value(i) != Arr2->Value(i)) |
64 | aList.Append(i); |
65 | if(aCase == 3) { |
66 | for(i = N+1;i <= myUp1; i++) |
67 | aList.Append(i); |
68 | } |
69 | |
70 | if(aList.Extent()) { |
71 | myIndxes = new TColStd_HArray1OfInteger(1,aList.Extent()); |
72 | myValues = new TColStd_HArray1OfExtendedString(1,aList.Extent()); |
73 | TColStd_ListIteratorOfListOfInteger anIt(aList); |
74 | for(i =1;anIt.More();anIt.Next(),i++) { |
75 | myIndxes->SetValue(i, anIt.Value()); |
76 | myValues->SetValue(i, Arr1->Value(anIt.Value())); |
77 | } |
78 | } |
79 | } |
80 | } |
81 | OldAtt->RemoveArray(); |
82 | #ifdef DEB |
83 | if(OldAtt->Array().IsNull()) |
84 | cout << "BackUp Arr is Nullified" << endl; |
85 | #endif |
86 | } |
87 | } |
88 | |
89 | |
90 | //======================================================================= |
91 | //function : Apply |
92 | //purpose : |
93 | //======================================================================= |
94 | |
95 | void TDataStd_DeltaOnModificationOfExtStringArray::Apply() |
96 | { |
97 | |
98 | Handle(TDF_Attribute) TDFAttribute = Attribute(); |
99 | Handle(TDataStd_ExtStringArray) BackAtt = (*((Handle(TDataStd_ExtStringArray)*)&TDFAttribute)); |
100 | if(BackAtt.IsNull()) { |
101 | #ifdef DEB |
102 | cout << "DeltaOnModificationOfExtStringArray::Apply: OldAtt is Null" <<endl; |
103 | #endif |
104 | return; |
105 | } |
106 | |
107 | Handle(TDataStd_ExtStringArray) aCurAtt; |
108 | if (!Label().FindAttribute(BackAtt->ID(),aCurAtt)) { |
109 | |
110 | Label().AddAttribute(BackAtt); |
111 | } |
112 | |
113 | if(aCurAtt.IsNull()) { |
114 | #ifdef DEB |
115 | cout << "DeltaOnModificationOfExtStringArray::Apply: CurAtt is Null" <<endl; |
116 | #endif |
117 | return; |
118 | } |
119 | else |
120 | aCurAtt->Backup(); |
121 | |
122 | Standard_Integer aCase; |
123 | if(myUp1 == myUp2) |
124 | aCase = 1; |
125 | else if(myUp1 < myUp2) |
126 | aCase = 2; |
127 | else |
128 | aCase = 3;//Up1 > Up2 |
129 | |
130 | if (aCase == 1 && (myIndxes.IsNull() || myValues.IsNull())) |
131 | return; |
132 | |
133 | Standard_Integer i; |
134 | Handle(TColStd_HArray1OfExtendedString) aStrArr = aCurAtt->Array(); |
135 | if(aStrArr.IsNull()) return; |
136 | |
137 | if(aCase == 1) |
138 | for(i = 1; i <= myIndxes->Upper();i++) |
139 | aStrArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i)); |
140 | else if(aCase == 2) { |
141 | Handle(TColStd_HArray1OfExtendedString) strArr = |
142 | new TColStd_HArray1OfExtendedString(aStrArr->Lower(), myUp1); |
143 | for(i = aStrArr->Lower(); i <= myUp1 && i <= aStrArr->Upper(); i++) |
144 | strArr->SetValue(i, aStrArr->Value(i)); |
145 | if(!myIndxes.IsNull() && !myValues.IsNull()) |
146 | for(i = 1; i <= myIndxes->Upper();i++) |
147 | strArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i)); |
148 | aCurAtt->myValue = strArr; |
149 | } |
150 | else { // == 3 |
151 | Standard_Integer low = aStrArr->Lower(); |
152 | Handle(TColStd_HArray1OfExtendedString) strArr = |
153 | new TColStd_HArray1OfExtendedString(low, myUp1); |
154 | for(i = aStrArr->Lower(); i <= myUp2 && i <= aStrArr->Upper(); i++) |
155 | strArr->SetValue(i, aStrArr->Value(i)); |
156 | if(!myIndxes.IsNull() && !myValues.IsNull()) |
157 | for(i = 1; i <= myIndxes->Upper();i++) { |
158 | #ifdef DEB |
159 | cout << "i = " << i << " myIndxes->Upper = " << myIndxes->Upper() << endl; |
160 | cout << "myIndxes->Value(i) = " << myIndxes->Value(i) << endl; |
161 | cout << "myValues->Value(i) = " << myValues->Value(i) << endl; |
162 | #endif |
163 | strArr->ChangeArray1().SetValue(myIndxes->Value(i), myValues->Value(i)); |
164 | } |
165 | aCurAtt->myValue = strArr; |
166 | } |
167 | |
168 | |
169 | #ifdef DEB |
170 | cout << " << Array Dump after Delta Apply >>" <<endl; |
171 | Handle(TColStd_HArray1OfExtendedString) aStrArr2 = aCurAtt->Array(); |
172 | for(i=aStrArr2->Lower(); i<= aStrArr2->Upper() && i<= MAXUP;i++) |
173 | cout << aStrArr2->Value(i) << " "; |
174 | cout <<endl; |
175 | #endif |
176 | } |
177 | |
178 | |