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 | |
42cf5bc1 |
16 | |
17 | #include <Standard_GUID.hxx> |
18 | #include <Standard_Type.hxx> |
19 | #include <TDataStd_ReferenceList.hxx> |
20 | #include <TDF_Attribute.hxx> |
21 | #include <TDF_DataSet.hxx> |
22 | #include <TDF_Label.hxx> |
7fd59977 |
23 | #include <TDF_ListIteratorOfLabelList.hxx> |
42cf5bc1 |
24 | #include <TDF_RelocationTable.hxx> |
7fd59977 |
25 | |
92efcf78 |
26 | IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ReferenceList,TDF_Attribute) |
27 | |
7fd59977 |
28 | //======================================================================= |
29 | //function : GetID |
30 | //purpose : |
31 | //======================================================================= |
32 | const Standard_GUID& TDataStd_ReferenceList::GetID() |
33 | { |
34 | static Standard_GUID TDataStd_ReferenceListID ("FCC1A658-59FF-4218-931B-0320A2B469A7"); |
35 | return TDataStd_ReferenceListID; |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : TDataStd_ReferenceList |
40 | //purpose : Empty Constructor |
41 | //======================================================================= |
42 | TDataStd_ReferenceList::TDataStd_ReferenceList() |
43 | { |
44 | |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : Set |
49 | //purpose : |
50 | //======================================================================= |
51 | Handle(TDataStd_ReferenceList) TDataStd_ReferenceList::Set(const TDF_Label& label) |
52 | { |
53 | Handle(TDataStd_ReferenceList) A; |
54 | if (!label.FindAttribute (TDataStd_ReferenceList::GetID(), A)) |
55 | { |
56 | A = new TDataStd_ReferenceList; |
57 | label.AddAttribute(A); |
58 | } |
59 | return A; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : IsEmpty |
64 | //purpose : |
65 | //======================================================================= |
66 | Standard_Boolean TDataStd_ReferenceList::IsEmpty() const |
67 | { |
68 | return myList.IsEmpty(); |
69 | } |
70 | |
71 | //======================================================================= |
72 | //function : Extent |
73 | //purpose : |
74 | //======================================================================= |
75 | Standard_Integer TDataStd_ReferenceList::Extent() const |
76 | { |
77 | return myList.Extent(); |
78 | } |
79 | |
80 | //======================================================================= |
81 | //function : Prepend |
82 | //purpose : |
83 | //======================================================================= |
84 | void TDataStd_ReferenceList::Prepend(const TDF_Label& value) |
85 | { |
86 | Backup(); |
87 | myList.Prepend(value); |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : Append |
92 | //purpose : |
93 | //======================================================================= |
94 | void TDataStd_ReferenceList::Append(const TDF_Label& value) |
95 | { |
96 | Backup(); |
97 | myList.Append(value); |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : InsertBefore |
102 | //purpose : |
103 | //======================================================================= |
104 | Standard_Boolean TDataStd_ReferenceList::InsertBefore(const TDF_Label& value, |
105 | const TDF_Label& before_value) |
106 | { |
107 | TDF_ListIteratorOfLabelList itr(myList); |
108 | for (; itr.More(); itr.Next()) |
109 | { |
110 | if (itr.Value() == before_value) |
111 | { |
112 | Backup(); |
113 | myList.InsertBefore(value, itr); |
114 | return Standard_True; |
115 | } |
116 | } |
117 | return Standard_False; |
118 | } |
119 | |
1ff07227 |
120 | // Inserts the label before the <index> position. |
121 | // The indices start with 1 .. Extent(). |
122 | Standard_Boolean TDataStd_ReferenceList::InsertBefore (const Standard_Integer index, |
123 | const TDF_Label& before_value) |
124 | { |
125 | Standard_Integer i(1); |
126 | Standard_Boolean found(Standard_False); |
127 | TDF_ListIteratorOfLabelList itr(myList); |
128 | for (; itr.More(); itr.Next(), ++i) |
129 | { |
130 | if (i == index) |
131 | { |
132 | Backup(); |
133 | myList.InsertBefore(before_value, itr); |
134 | found = Standard_True; |
135 | break; |
136 | } |
137 | } |
138 | return found; |
139 | } |
140 | |
7fd59977 |
141 | //======================================================================= |
142 | //function : InsertAfter |
143 | //purpose : |
144 | //======================================================================= |
145 | Standard_Boolean TDataStd_ReferenceList::InsertAfter(const TDF_Label& value, |
146 | const TDF_Label& after_value) |
147 | { |
148 | TDF_ListIteratorOfLabelList itr(myList); |
149 | for (; itr.More(); itr.Next()) |
150 | { |
151 | if (itr.Value() == after_value) |
152 | { |
153 | Backup(); |
154 | myList.InsertAfter(value, itr); |
155 | return Standard_True; |
156 | } |
157 | } |
158 | return Standard_False; |
159 | } |
160 | |
1ff07227 |
161 | // Inserts the label after the <index> position. |
162 | // The indices start with 1 .. Extent(). |
163 | Standard_Boolean TDataStd_ReferenceList::InsertAfter (const Standard_Integer index, |
164 | const TDF_Label& after_value) |
165 | { |
166 | Standard_Integer i(1); |
167 | Standard_Boolean found(Standard_False); |
168 | TDF_ListIteratorOfLabelList itr(myList); |
169 | for (; itr.More(); itr.Next(), ++i) |
170 | { |
171 | if (i == index) |
172 | { |
173 | Backup(); |
174 | myList.InsertAfter(after_value, itr); |
175 | found = Standard_True; |
176 | break; |
177 | } |
178 | } |
179 | return found; |
180 | } |
181 | |
7fd59977 |
182 | //======================================================================= |
183 | //function : Remove |
184 | //purpose : |
185 | //======================================================================= |
186 | Standard_Boolean TDataStd_ReferenceList::Remove(const TDF_Label& value) |
187 | { |
188 | TDF_ListIteratorOfLabelList itr(myList); |
189 | for (; itr.More(); itr.Next()) |
190 | { |
191 | if (itr.Value() == value) |
192 | { |
193 | Backup(); |
194 | myList.Remove(itr); |
195 | return Standard_True; |
196 | } |
197 | } |
198 | return Standard_False; |
199 | } |
200 | |
1ff07227 |
201 | //======================================================================= |
202 | //function : Remove |
203 | //purpose : Removes a label at the <index> position. |
204 | //======================================================================= |
205 | Standard_Boolean TDataStd_ReferenceList::Remove (const Standard_Integer index) |
206 | { |
207 | Standard_Integer i(1); |
208 | Standard_Boolean found(Standard_False); |
209 | TDF_ListIteratorOfLabelList itr(myList); |
210 | for (; itr.More(); itr.Next(), ++i) |
211 | { |
212 | if (i == index) |
213 | { |
214 | Backup(); |
215 | myList.Remove(itr); |
216 | found = Standard_True; |
217 | break; |
218 | } |
219 | } |
220 | return found; |
221 | } |
222 | |
7fd59977 |
223 | //======================================================================= |
224 | //function : Clear |
225 | //purpose : |
226 | //======================================================================= |
227 | void TDataStd_ReferenceList::Clear() |
228 | { |
229 | Backup(); |
230 | myList.Clear(); |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : First |
235 | //purpose : |
236 | //======================================================================= |
237 | const TDF_Label& TDataStd_ReferenceList::First() const |
238 | { |
239 | return myList.First(); |
240 | } |
241 | |
242 | //======================================================================= |
243 | //function : Last |
244 | //purpose : |
245 | //======================================================================= |
246 | const TDF_Label& TDataStd_ReferenceList::Last() const |
247 | { |
248 | return myList.Last(); |
249 | } |
250 | |
251 | //======================================================================= |
252 | //function : List |
253 | //purpose : |
254 | //======================================================================= |
255 | const TDF_LabelList& TDataStd_ReferenceList::List() const |
256 | { |
257 | return myList; |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : ID |
262 | //purpose : |
263 | //======================================================================= |
264 | const Standard_GUID& TDataStd_ReferenceList::ID () const |
265 | { |
266 | return GetID(); |
267 | } |
268 | |
269 | //======================================================================= |
270 | //function : NewEmpty |
271 | //purpose : |
272 | //======================================================================= |
273 | Handle(TDF_Attribute) TDataStd_ReferenceList::NewEmpty () const |
274 | { |
275 | return new TDataStd_ReferenceList(); |
276 | } |
277 | |
278 | //======================================================================= |
279 | //function : Restore |
280 | //purpose : |
281 | //======================================================================= |
282 | void TDataStd_ReferenceList::Restore(const Handle(TDF_Attribute)& With) |
283 | { |
284 | myList.Clear(); |
285 | Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(With); |
286 | TDF_ListIteratorOfLabelList itr(aList->List()); |
287 | for (; itr.More(); itr.Next()) |
288 | { |
289 | myList.Append(itr.Value()); |
290 | } |
291 | } |
292 | |
293 | //======================================================================= |
294 | //function : Paste |
295 | //purpose : |
296 | //======================================================================= |
297 | void TDataStd_ReferenceList::Paste (const Handle(TDF_Attribute)& Into, |
298 | const Handle(TDF_RelocationTable)& RT) const |
299 | { |
300 | Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(Into); |
301 | aList->Clear(); |
302 | TDF_ListIteratorOfLabelList itr(myList); |
303 | for (; itr.More(); itr.Next()) |
304 | { |
305 | TDF_Label L = itr.Value(), rL; |
306 | if (!L.IsNull()) |
307 | { |
308 | if (!RT->HasRelocation(L, rL)) |
309 | rL = L; |
310 | aList->Append(rL); |
311 | } |
312 | } |
313 | } |
314 | |
315 | //======================================================================= |
316 | //function : References |
317 | //purpose : Adds the referenced attributes or labels. |
318 | //======================================================================= |
319 | void TDataStd_ReferenceList::References(const Handle(TDF_DataSet)& aDataSet) const |
320 | { |
321 | if (!Label().IsImported()) |
322 | { |
323 | TDF_ListIteratorOfLabelList itr(myList); |
324 | for (; itr.More(); itr.Next()) |
325 | { |
326 | aDataSet->AddLabel(itr.Value()); |
327 | } |
328 | } |
329 | } |
330 | |
331 | //======================================================================= |
332 | //function : Dump |
333 | //purpose : |
334 | //======================================================================= |
335 | Standard_OStream& TDataStd_ReferenceList::Dump (Standard_OStream& anOS) const |
336 | { |
337 | anOS << "ReferenceList"; |
338 | return anOS; |
339 | } |