b311480e |
1 | // Created on: 1999-06-16 |
2 | // Created by: Sergey RUIN |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <TDataStd_RealArray.ixx> |
18 | #include <TDataStd_DeltaOnModificationOfRealArray.hxx> |
19 | #include <TDF_DefaultDeltaOnModification.hxx> |
20 | #define OCC2932 |
21 | |
22 | //======================================================================= |
23 | //function : GetID |
24 | //purpose : |
25 | //======================================================================= |
26 | |
27 | const Standard_GUID& TDataStd_RealArray::GetID() |
28 | { |
29 | static Standard_GUID TDataStd_RealArrayID ("2a96b61e-ec8b-11d0-bee7-080009dc3333"); |
30 | return TDataStd_RealArrayID; |
31 | } |
32 | |
33 | |
34 | //======================================================================= |
35 | //function : TDataStd_RealArray |
36 | //purpose : Empty Constructor |
37 | //======================================================================= |
38 | |
39 | TDataStd_RealArray::TDataStd_RealArray() : myIsDelta(Standard_False){} |
40 | |
41 | //======================================================================= |
42 | //function : Init |
43 | //purpose : |
44 | //======================================================================= |
45 | |
46 | void TDataStd_RealArray::Init(const Standard_Integer lower, |
47 | const Standard_Integer upper) |
48 | { |
49 | Backup(); // jfa 15.01.2003 for LH3D1378 |
50 | |
51 | myValue = new TColStd_HArray1OfReal(lower, upper, 0.); |
52 | } |
53 | |
54 | //======================================================================= |
55 | //function : Set |
56 | //purpose : |
57 | //======================================================================= |
58 | |
59 | Handle(TDataStd_RealArray) TDataStd_RealArray::Set |
60 | (const TDF_Label& label, |
61 | const Standard_Integer lower, |
62 | const Standard_Integer upper, |
63 | const Standard_Boolean isDelta) |
64 | { |
65 | Handle(TDataStd_RealArray) A; |
66 | if (!label.FindAttribute (TDataStd_RealArray::GetID(), A)) { |
67 | A = new TDataStd_RealArray; |
68 | A->Init (lower, upper); |
69 | A->SetDelta(isDelta); |
70 | label.AddAttribute(A); |
71 | } |
72 | else if (lower != A->Lower() || upper != A->Upper()) |
73 | { |
74 | A->Init (lower, upper); |
75 | } |
76 | return A; |
77 | } |
78 | |
79 | |
80 | //======================================================================= |
81 | //function : SetValue |
82 | //purpose : |
83 | //======================================================================= |
84 | |
85 | void TDataStd_RealArray::SetValue (const Standard_Integer index, |
86 | const Standard_Real value) |
87 | { |
88 | // OCC2932 correction |
89 | if(myValue.IsNull()) return; |
90 | if(myValue->Value(index) == value) |
fa13a85d |
91 | return; |
7fd59977 |
92 | Backup(); |
93 | myValue->SetValue(index, value); |
94 | } |
95 | |
96 | |
97 | //======================================================================= |
98 | //function : GetValue |
99 | //purpose : |
100 | //======================================================================= |
101 | |
102 | Standard_Real TDataStd_RealArray::Value (const Standard_Integer index) const |
103 | { |
104 | if(myValue.IsNull()) return RealFirst(); |
105 | return myValue->Value(index); |
106 | } |
107 | |
108 | |
109 | |
110 | //======================================================================= |
111 | //function : Lower |
112 | //purpose : |
113 | //======================================================================= |
114 | Standard_Integer TDataStd_RealArray::Lower (void) const |
115 | { |
116 | if(myValue.IsNull()) return 0; |
117 | return myValue->Lower(); |
118 | } |
119 | |
120 | |
121 | //======================================================================= |
122 | //function : Upper |
123 | //purpose : |
124 | //======================================================================= |
125 | Standard_Integer TDataStd_RealArray::Upper (void) const |
126 | { |
127 | if(myValue.IsNull()) return 0; |
128 | return myValue->Upper(); |
129 | } |
130 | |
131 | |
132 | //======================================================================= |
133 | //function : Length |
134 | //purpose : |
135 | //======================================================================= |
136 | Standard_Integer TDataStd_RealArray::Length (void) const |
137 | { |
138 | if(myValue.IsNull()) return 0; |
139 | return myValue->Length(); |
140 | } |
141 | |
142 | |
143 | //======================================================================= |
144 | //function : ChangeArray |
145 | //purpose : If value of <newArray> differs from <myValue>, Backup |
146 | // : performed and myValue refers to new instance of HArray1OfReal |
147 | // : that holds <newArray> |
148 | //======================================================================= |
149 | |
150 | void TDataStd_RealArray::ChangeArray(const Handle(TColStd_HArray1OfReal)& newArray, |
151 | const Standard_Boolean isCheckItems) |
152 | { |
153 | Standard_Integer aLower = newArray->Lower(); |
154 | Standard_Integer anUpper = newArray->Upper(); |
155 | Standard_Boolean aDimEqual = Standard_False; |
156 | Standard_Integer i; |
157 | |
158 | #ifdef OCC2932 |
a855b7eb |
159 | if (Lower() == aLower && Upper() == anUpper ) { |
7fd59977 |
160 | aDimEqual = Standard_True; |
161 | Standard_Boolean isEqual = Standard_True; |
162 | if(isCheckItems) { |
163 | for(i = aLower; i <= anUpper; i++) { |
164 | if(myValue->Value(i) != newArray->Value(i)) { |
165 | isEqual = Standard_False; |
166 | break; |
167 | } |
168 | } |
169 | if(isEqual) |
170 | return; |
171 | } |
172 | } |
173 | #endif |
174 | |
175 | Backup(); |
176 | |
a855b7eb |
177 | if(myValue.IsNull() || !aDimEqual) |
7fd59977 |
178 | myValue = new TColStd_HArray1OfReal(aLower, anUpper); |
179 | |
180 | for(i = aLower; i <= anUpper; i++) |
181 | myValue->SetValue(i, newArray->Value(i)); |
182 | } |
183 | |
184 | //======================================================================= |
185 | //function : ID |
186 | //purpose : |
187 | //======================================================================= |
188 | |
189 | const Standard_GUID& TDataStd_RealArray::ID () const { return GetID(); } |
190 | |
191 | |
192 | //======================================================================= |
193 | //function : NewEmpty |
194 | //purpose : |
195 | //======================================================================= |
196 | |
197 | Handle(TDF_Attribute) TDataStd_RealArray::NewEmpty () const |
198 | { |
199 | return new TDataStd_RealArray(); |
200 | } |
201 | |
202 | //======================================================================= |
203 | //function : Restore |
204 | //purpose : |
205 | //======================================================================= |
206 | |
207 | void TDataStd_RealArray::Restore(const Handle(TDF_Attribute)& With) |
208 | { |
209 | Standard_Integer i, lower, upper; |
210 | Handle(TDataStd_RealArray) anArray = Handle(TDataStd_RealArray)::DownCast(With); |
211 | if(!anArray->myValue.IsNull()) { |
212 | lower = anArray->Lower(); |
213 | upper = anArray->Upper(); |
214 | myIsDelta = anArray->myIsDelta; |
215 | myValue = new TColStd_HArray1OfReal(lower, upper); |
216 | for(i = lower; i<=upper; i++) |
217 | myValue->SetValue(i, anArray->Value(i)); |
218 | } |
219 | else |
220 | myValue.Nullify(); |
221 | } |
222 | |
223 | //======================================================================= |
224 | //function : Paste |
225 | //purpose : |
226 | //======================================================================= |
227 | |
228 | void TDataStd_RealArray::Paste (const Handle(TDF_Attribute)& Into, |
229 | const Handle(TDF_RelocationTable)& ) const |
230 | { |
231 | if(!myValue.IsNull()) { |
232 | Handle(TDataStd_RealArray) anAtt = Handle(TDataStd_RealArray)::DownCast(Into); |
233 | if(!anAtt.IsNull()) { |
234 | anAtt->ChangeArray( myValue, Standard_False ); |
235 | anAtt->SetDelta(myIsDelta); |
236 | } |
237 | } |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : Dump |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | Standard_OStream& TDataStd_RealArray::Dump (Standard_OStream& anOS) const |
246 | { |
247 | anOS << "\nRealArray::" << this <<" :"; |
248 | if(!myValue.IsNull()) { |
249 | Standard_Integer i, lower, upper; |
250 | lower = myValue->Lower(); |
251 | upper = myValue->Upper(); |
252 | for(i = lower; i<=upper; i++) |
253 | anOS << " " <<myValue->Value(i); |
254 | } |
eb901da6 |
255 | anOS << " Delta is " << (myIsDelta ? "ON":"OFF"); |
7fd59977 |
256 | anOS << endl; |
257 | return anOS; |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : DeltaOnModification |
262 | //purpose : |
263 | //======================================================================= |
264 | |
265 | Handle(TDF_DeltaOnModification) TDataStd_RealArray::DeltaOnModification |
266 | (const Handle(TDF_Attribute)& OldAtt) const |
267 | { |
268 | if(myIsDelta) |
269 | return new TDataStd_DeltaOnModificationOfRealArray(*((Handle(TDataStd_RealArray)*)&OldAtt)); |
270 | else return new TDF_DefaultDeltaOnModification(OldAtt); |
271 | } |