Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1999-06-16 |
2 | // Created by: Sergey RUIN | |
3 | // Copyright (c) 1999-1999 Matra Datavision | |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS | |
5 | // | |
6 | // The content of this file is subject to the Open CASCADE Technology Public | |
7 | // License Version 6.5 (the "License"). You may not use the content of this file | |
8 | // except in compliance with the License. Please obtain a copy of the License | |
9 | // at http://www.opencascade.org and read it completely before using this file. | |
10 | // | |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
13 | // | |
14 | // The Original Code and all software distributed under the License is | |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
16 | // Initial Developer hereby disclaims all such warranties, including without | |
17 | // limitation, any warranties of merchantability, fitness for a particular | |
18 | // purpose or non-infringement. Please see the License for the specific terms | |
19 | // and conditions governing the rights and limitations under the License. | |
20 | ||
7fd59977 | 21 | |
22 | ||
23 | #include <TDataStd_IntegerArray.ixx> | |
24 | #include <TDataStd_DeltaOnModificationOfIntArray.hxx> | |
25 | #include <TDF_DefaultDeltaOnModification.hxx> | |
26 | #define OCC925 | |
27 | #define OCC2932 | |
28 | ||
29 | //======================================================================= | |
30 | //function : GetID | |
31 | //purpose : | |
32 | //======================================================================= | |
33 | ||
34 | const Standard_GUID& TDataStd_IntegerArray::GetID() | |
35 | { | |
36 | static Standard_GUID TDataStd_IntegerArrayID ("2a96b61d-ec8b-11d0-bee7-080009dc3333"); | |
37 | return TDataStd_IntegerArrayID; | |
38 | } | |
39 | ||
40 | ||
41 | //======================================================================= | |
42 | //function : TDataStd_IntegerArray | |
43 | //purpose : Empty Constructor | |
44 | //======================================================================= | |
45 | ||
46 | TDataStd_IntegerArray::TDataStd_IntegerArray() | |
47 | :myIsDelta(Standard_False) {} | |
48 | ||
49 | //======================================================================= | |
50 | //function : Init | |
51 | //purpose : | |
52 | //======================================================================= | |
53 | ||
54 | void TDataStd_IntegerArray::Init(const Standard_Integer lower, | |
55 | const Standard_Integer upper) | |
56 | { | |
57 | #ifdef OCC925 | |
58 | Backup(); | |
59 | #endif | |
60 | myValue = new TColStd_HArray1OfInteger(lower, upper, 0); | |
61 | } | |
62 | ||
63 | //======================================================================= | |
64 | //function : Set | |
65 | //purpose : isDelta applicable only for new attributes | |
66 | //======================================================================= | |
67 | ||
68 | Handle(TDataStd_IntegerArray) TDataStd_IntegerArray::Set | |
69 | (const TDF_Label& label, | |
70 | const Standard_Integer lower, | |
71 | const Standard_Integer upper, | |
72 | const Standard_Boolean isDelta) | |
73 | ||
74 | { | |
75 | Handle(TDataStd_IntegerArray) A; | |
76 | if (!label.FindAttribute (TDataStd_IntegerArray::GetID(), A)) { | |
77 | A = new TDataStd_IntegerArray; | |
78 | A->Init (lower, upper); | |
79 | A->SetDelta(isDelta); | |
80 | label.AddAttribute(A); | |
81 | } | |
82 | else if (lower != A->Lower() || upper != A->Upper()) | |
83 | { | |
84 | A->Init (lower, upper); | |
85 | } | |
86 | return A; | |
87 | } | |
88 | ||
89 | //======================================================================= | |
90 | //function : SetValue | |
91 | //purpose : | |
92 | //======================================================================= | |
93 | ||
94 | void TDataStd_IntegerArray::SetValue(const Standard_Integer index, const Standard_Integer value) | |
95 | { | |
96 | if(myValue.IsNull()) return; | |
97 | if( myValue->Value(index) == value) | |
fa13a85d | 98 | return; |
7fd59977 | 99 | Backup(); |
100 | myValue->SetValue(index, value); | |
101 | } | |
102 | ||
103 | ||
104 | //======================================================================= | |
105 | //function : GetValue | |
106 | //purpose : | |
107 | //======================================================================= | |
108 | ||
109 | Standard_Integer TDataStd_IntegerArray::Value (const Standard_Integer index) const | |
110 | { | |
111 | if(myValue.IsNull()) return 0; | |
112 | return myValue->Value(index); | |
113 | } | |
114 | ||
115 | ||
116 | ||
117 | //======================================================================= | |
118 | //function : Lower | |
119 | //purpose : | |
120 | //======================================================================= | |
121 | Standard_Integer TDataStd_IntegerArray::Lower (void) const | |
122 | { | |
123 | if(myValue.IsNull()) return 0; | |
124 | return myValue->Lower(); | |
125 | } | |
126 | ||
127 | ||
128 | //======================================================================= | |
129 | //function : Upper | |
130 | //purpose : | |
131 | //======================================================================= | |
132 | Standard_Integer TDataStd_IntegerArray::Upper (void) const | |
133 | { | |
134 | if(myValue.IsNull()) return 0; | |
135 | return myValue->Upper(); | |
136 | } | |
137 | ||
138 | ||
139 | //======================================================================= | |
140 | //function : Length | |
141 | //purpose : | |
142 | //======================================================================= | |
143 | Standard_Integer TDataStd_IntegerArray::Length (void) const | |
144 | { | |
145 | if(myValue.IsNull()) return 0; | |
146 | return myValue->Length(); | |
147 | } | |
148 | ||
149 | ||
150 | //======================================================================= | |
151 | //function : ChangeArray | |
152 | //purpose : If value of <newArray> differs from <myValue>, Backup | |
153 | // : performed and myValue refers to new instance of HArray1OfInteger | |
154 | // : that holds <newArray> | |
155 | //======================================================================= | |
156 | ||
157 | void TDataStd_IntegerArray::ChangeArray(const Handle(TColStd_HArray1OfInteger)& newArray, | |
158 | const Standard_Boolean isCheckItems) | |
159 | { | |
160 | Standard_Integer aLower = newArray->Lower(); | |
161 | Standard_Integer anUpper = newArray->Upper(); | |
162 | Standard_Boolean aDimEqual = Standard_False; | |
163 | Standard_Integer i; | |
164 | #ifdef OCC2932 | |
a855b7eb S |
165 | |
166 | if(Lower() == aLower && Upper() == anUpper ) { | |
7fd59977 | 167 | aDimEqual = Standard_True; |
168 | if(isCheckItems) { | |
169 | Standard_Boolean isEqual = Standard_True; | |
170 | for(i = aLower; i <= anUpper; i++) { | |
171 | if(myValue->Value(i) != newArray->Value(i)) { | |
172 | isEqual = Standard_False; | |
173 | break; | |
174 | } | |
175 | } | |
176 | if(isEqual) | |
177 | return; | |
178 | } | |
179 | } | |
180 | #endif | |
181 | ||
182 | Backup(); | |
183 | // Handles of myValue of current and backuped attributes will be different! | |
a855b7eb | 184 | if(myValue.IsNull() || !aDimEqual) |
7fd59977 | 185 | myValue = new TColStd_HArray1OfInteger(aLower, anUpper); |
186 | ||
187 | for(i = aLower; i <= anUpper; i++) | |
188 | myValue->SetValue(i, newArray->Value(i)); | |
189 | } | |
190 | ||
191 | ||
192 | //======================================================================= | |
193 | //function : ID | |
194 | //purpose : | |
195 | //======================================================================= | |
196 | ||
197 | const Standard_GUID& TDataStd_IntegerArray::ID () const { return GetID(); } | |
198 | ||
199 | ||
200 | //======================================================================= | |
201 | //function : NewEmpty | |
202 | //purpose : | |
203 | //======================================================================= | |
204 | ||
205 | Handle(TDF_Attribute) TDataStd_IntegerArray::NewEmpty () const | |
206 | { | |
207 | return new TDataStd_IntegerArray(); | |
208 | } | |
209 | ||
210 | //======================================================================= | |
211 | //function : Restore | |
212 | //purpose : | |
213 | //======================================================================= | |
214 | ||
215 | void TDataStd_IntegerArray::Restore(const Handle(TDF_Attribute)& With) | |
216 | { | |
217 | Standard_Integer i, lower, upper; | |
218 | Handle(TDataStd_IntegerArray) anArray = Handle(TDataStd_IntegerArray)::DownCast(With); | |
219 | if(!anArray->myValue.IsNull()) { | |
220 | lower = anArray->Lower(); | |
221 | upper = anArray->Upper(); | |
222 | myValue = new TColStd_HArray1OfInteger(lower, upper); | |
223 | for(i = lower; i<=upper; i++) | |
224 | myValue->SetValue(i, anArray->Value(i)); | |
225 | myIsDelta = anArray->myIsDelta; | |
226 | } | |
227 | else | |
228 | myValue.Nullify(); | |
229 | } | |
230 | ||
231 | //======================================================================= | |
232 | //function : Paste | |
233 | //purpose : | |
234 | //======================================================================= | |
235 | ||
236 | void TDataStd_IntegerArray::Paste (const Handle(TDF_Attribute)& Into, | |
237 | const Handle(TDF_RelocationTable)& ) const | |
238 | { | |
239 | ||
240 | if(!myValue.IsNull()) { | |
241 | Handle(TDataStd_IntegerArray) anAtt = Handle(TDataStd_IntegerArray)::DownCast(Into); | |
242 | if(!anAtt.IsNull()) { | |
243 | anAtt->ChangeArray( myValue, Standard_False ); | |
244 | anAtt->SetDelta(myIsDelta); | |
245 | } | |
246 | } | |
247 | } | |
248 | ||
249 | //======================================================================= | |
250 | //function : Dump | |
251 | //purpose : | |
252 | //======================================================================= | |
253 | ||
254 | Standard_OStream& TDataStd_IntegerArray::Dump (Standard_OStream& anOS) const | |
255 | { | |
256 | anOS << "\nIntegerArray:: " << this <<" :"; | |
257 | if(!myValue.IsNull()) { | |
258 | Standard_Integer i, lower, upper; | |
259 | lower = myValue->Lower(); | |
260 | upper = myValue->Upper(); | |
261 | for(i = lower; i<=upper; i++) | |
262 | anOS << " " <<myValue->Value(i); | |
263 | } | |
eb901da6 | 264 | anOS << " Delta is " << (myIsDelta ? "ON":"OFF"); |
7fd59977 | 265 | anOS << endl; |
266 | ||
267 | // anOS <<"\nAttribute fields: "; | |
268 | // anOS << TDF_Attribute::Dump(anOS); | |
269 | ||
270 | return anOS; | |
271 | } | |
272 | ||
273 | //======================================================================= | |
274 | //function : DeltaOnModification | |
275 | //purpose : | |
276 | //======================================================================= | |
277 | ||
278 | Handle(TDF_DeltaOnModification) TDataStd_IntegerArray::DeltaOnModification | |
279 | (const Handle(TDF_Attribute)& OldAttribute) const | |
280 | { | |
281 | if(myIsDelta) | |
282 | return new TDataStd_DeltaOnModificationOfIntArray(*((Handle(TDataStd_IntegerArray)*)&OldAttribute)); | |
283 | else return new TDF_DefaultDeltaOnModification(OldAttribute); | |
284 | } | |
285 | ||
286 |