Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2007-05-29 |
2 | // Created by: Vlad Romashko | |
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_ReferenceArray.ixx> | |
17 | ||
18 | //======================================================================= | |
19 | //function : GetID | |
20 | //purpose : | |
21 | //======================================================================= | |
22 | const Standard_GUID& TDataStd_ReferenceArray::GetID() | |
23 | { | |
24 | static Standard_GUID TDataStd_ReferenceArrayID ("7EE745A6-BB50-446c-BB0B-C195B23AB5CA"); | |
25 | return TDataStd_ReferenceArrayID; | |
26 | } | |
27 | ||
28 | //======================================================================= | |
29 | //function : TDataStd_ReferenceArray | |
30 | //purpose : Empty Constructor | |
31 | //======================================================================= | |
32 | TDataStd_ReferenceArray::TDataStd_ReferenceArray() | |
33 | { | |
34 | ||
35 | } | |
36 | ||
37 | //======================================================================= | |
38 | //function : Init | |
39 | //purpose : | |
40 | //======================================================================= | |
41 | void TDataStd_ReferenceArray::Init(const Standard_Integer lower, | |
42 | const Standard_Integer upper) | |
43 | { | |
a855b7eb | 44 | Standard_RangeError_Raise_if(upper < lower,"TDataStd_ReferenceArray::Init"); |
7fd59977 | 45 | Backup(); |
a855b7eb | 46 | myArray = new TDataStd_HLabelArray1(lower, upper); |
7fd59977 | 47 | } |
48 | ||
49 | //======================================================================= | |
50 | //function : Set | |
51 | //purpose : | |
52 | //======================================================================= | |
53 | Handle(TDataStd_ReferenceArray) TDataStd_ReferenceArray::Set(const TDF_Label& label, | |
54 | const Standard_Integer lower, | |
55 | const Standard_Integer upper) | |
56 | { | |
57 | Handle(TDataStd_ReferenceArray) A; | |
58 | if (!label.FindAttribute (TDataStd_ReferenceArray::GetID(), A)) | |
59 | { | |
60 | A = new TDataStd_ReferenceArray; | |
61 | A->Init (lower, upper); | |
62 | label.AddAttribute(A); | |
63 | } | |
64 | else if (lower != A->Lower() || upper != A->Upper()) | |
65 | { | |
66 | A->Init(lower, upper); | |
67 | } | |
68 | return A; | |
69 | } | |
70 | ||
71 | //======================================================================= | |
72 | //function : SetValue | |
73 | //purpose : | |
74 | //======================================================================= | |
75 | void TDataStd_ReferenceArray::SetValue (const Standard_Integer index, | |
76 | const TDF_Label& value) | |
77 | { | |
fa13a85d | 78 | if(myArray.IsNull()) return; |
7fd59977 | 79 | if (value == myArray->Value(index)) |
80 | return; | |
7fd59977 | 81 | Backup(); |
82 | ||
83 | myArray->SetValue(index, value); | |
84 | } | |
85 | ||
86 | //======================================================================= | |
87 | //function : Value | |
88 | //purpose : | |
89 | //======================================================================= | |
90 | TDF_Label TDataStd_ReferenceArray::Value (const Standard_Integer index) const | |
91 | { | |
92 | return myArray->Value(index); | |
93 | } | |
94 | ||
95 | //======================================================================= | |
96 | //function : Lower | |
97 | //purpose : | |
98 | //======================================================================= | |
99 | Standard_Integer TDataStd_ReferenceArray::Lower () const | |
100 | { | |
101 | if (myArray.IsNull()) | |
102 | return 0; | |
103 | return myArray->Lower(); | |
104 | } | |
105 | ||
106 | //======================================================================= | |
107 | //function : Upper | |
108 | //purpose : | |
109 | //======================================================================= | |
110 | Standard_Integer TDataStd_ReferenceArray::Upper () const | |
111 | { | |
112 | if (myArray.IsNull()) | |
113 | return -1; | |
114 | return myArray->Upper(); | |
115 | } | |
116 | ||
117 | //======================================================================= | |
118 | //function : Length | |
119 | //purpose : | |
120 | //======================================================================= | |
121 | Standard_Integer TDataStd_ReferenceArray::Length () const | |
122 | { | |
123 | if (myArray.IsNull()) | |
124 | return 0; | |
125 | return myArray->Length(); | |
126 | } | |
127 | ||
128 | //======================================================================= | |
129 | //function : InternalArray | |
130 | //purpose : | |
131 | //======================================================================= | |
132 | const Handle(TDataStd_HLabelArray1)& TDataStd_ReferenceArray::InternalArray () const | |
133 | { | |
134 | return myArray; | |
135 | } | |
136 | ||
137 | //======================================================================= | |
138 | //function : SetInternalArray | |
139 | //purpose : | |
140 | //======================================================================= | |
a855b7eb | 141 | void TDataStd_ReferenceArray::SetInternalArray (const Handle(TDataStd_HLabelArray1)& values, |
498ce76b | 142 | const Standard_Boolean) |
7fd59977 | 143 | { |
a855b7eb S |
144 | // myArray = values; |
145 | Standard_Integer aLower = values->Lower(); | |
146 | Standard_Integer anUpper = values->Upper(); | |
147 | Standard_Boolean aDimEqual = Standard_False; | |
148 | Standard_Integer i; | |
149 | ||
150 | #ifdef OCC2932 | |
151 | if (Lower() == aLower && Upper() == anUpper ) { | |
152 | aDimEqual = Standard_True; | |
153 | Standard_Boolean isEqual = Standard_True; | |
154 | if(isCheckItems) { | |
155 | for(i = aLower; i <= anUpper; i++) { | |
156 | if(myArray->Value(i) != values->Value(i)) { | |
157 | isEqual = Standard_False; | |
158 | break; | |
159 | } | |
160 | } | |
161 | if(isEqual) | |
162 | return; | |
163 | } | |
164 | } | |
165 | #endif | |
166 | ||
167 | Backup(); | |
168 | ||
169 | if(myArray.IsNull() || !aDimEqual) | |
170 | myArray = new TDataStd_HLabelArray1(aLower, anUpper); | |
171 | ||
172 | for(i = aLower; i <= anUpper; i++) | |
173 | myArray->SetValue(i, values->Value(i)); | |
7fd59977 | 174 | } |
175 | ||
176 | //======================================================================= | |
177 | //function : ID | |
178 | //purpose : | |
179 | //======================================================================= | |
180 | const Standard_GUID& TDataStd_ReferenceArray::ID () const | |
181 | { | |
a855b7eb | 182 | return GetID(); |
7fd59977 | 183 | } |
184 | ||
185 | //======================================================================= | |
186 | //function : NewEmpty | |
187 | //purpose : | |
188 | //======================================================================= | |
189 | Handle(TDF_Attribute) TDataStd_ReferenceArray::NewEmpty () const | |
190 | { | |
191 | return new TDataStd_ReferenceArray(); | |
192 | } | |
193 | ||
194 | //======================================================================= | |
195 | //function : Restore | |
196 | //purpose : | |
197 | //======================================================================= | |
198 | void TDataStd_ReferenceArray::Restore(const Handle(TDF_Attribute)& With) | |
199 | { | |
200 | Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(With); | |
201 | if (!anArray->myArray.IsNull()) | |
202 | { | |
203 | const TDataStd_LabelArray1& arr = anArray->myArray->Array1(); | |
204 | Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper(); | |
205 | Init(lower, upper); | |
206 | for (; i <= upper; i++) | |
207 | { | |
208 | myArray->SetValue(i, arr.Value(i)); | |
209 | } | |
210 | } | |
211 | else | |
212 | { | |
213 | myArray.Nullify(); | |
214 | } | |
215 | } | |
216 | ||
217 | //======================================================================= | |
218 | //function : Paste | |
219 | //purpose : | |
220 | //======================================================================= | |
221 | void TDataStd_ReferenceArray::Paste (const Handle(TDF_Attribute)& Into, | |
222 | const Handle(TDF_RelocationTable)& RT) const | |
223 | { | |
224 | Handle(TDataStd_ReferenceArray) anArray = Handle(TDataStd_ReferenceArray)::DownCast(Into); | |
225 | if (myArray.IsNull()) | |
226 | { | |
227 | anArray->myArray.Nullify(); | |
228 | return; | |
229 | } | |
230 | const TDataStd_LabelArray1& arr = myArray->Array1(); | |
231 | Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper(); | |
232 | if (lower != anArray->Lower() || upper != anArray->Upper()) | |
233 | anArray->Init(lower, upper); | |
234 | for (; i <= upper; i++) | |
235 | { | |
236 | TDF_Label L = arr.Value(i), rL; | |
237 | if (!L.IsNull()) | |
238 | { | |
239 | if (!RT->HasRelocation(L, rL)) | |
240 | rL = L; | |
241 | anArray->myArray->SetValue(i, rL); | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | //======================================================================= | |
247 | //function : References | |
248 | //purpose : Adds the referenced attributes or labels. | |
249 | //======================================================================= | |
250 | void TDataStd_ReferenceArray::References(const Handle(TDF_DataSet)& aDataSet) const | |
251 | { | |
252 | if (!Label().IsImported() && !myArray.IsNull()) | |
253 | { | |
254 | const TDataStd_LabelArray1& arr = myArray->Array1(); | |
255 | Standard_Integer lower = arr.Lower(), i = lower, upper = arr.Upper(); | |
256 | for (; i <= upper; i++) | |
257 | { | |
258 | if (!arr.Value(i).IsNull()) | |
259 | aDataSet->AddLabel(arr.Value(i)); | |
260 | } | |
261 | } | |
262 | } | |
263 | ||
264 | //======================================================================= | |
265 | //function : Dump | |
266 | //purpose : | |
267 | //======================================================================= | |
268 | Standard_OStream& TDataStd_ReferenceArray::Dump (Standard_OStream& anOS) const | |
269 | { | |
270 | anOS << "ReferenceArray"; | |
271 | return anOS; | |
272 | } |