1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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>
23 #include <TDF_ListIteratorOfLabelList.hxx>
24 #include <TDF_RelocationTable.hxx>
26 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ReferenceList,TDF_Attribute)
28 //=======================================================================
31 //=======================================================================
32 const Standard_GUID& TDataStd_ReferenceList::GetID()
34 static Standard_GUID TDataStd_ReferenceListID ("FCC1A658-59FF-4218-931B-0320A2B469A7");
35 return TDataStd_ReferenceListID;
38 //=======================================================================
40 //purpose : Implements Set functionality
41 //=======================================================================
42 static Handle(TDataStd_ReferenceList) SetAttr(const TDF_Label& label,
43 const Standard_GUID& theGuid)
45 Handle(TDataStd_ReferenceList) A;
46 if (!label.FindAttribute (theGuid, A))
48 A = new TDataStd_ReferenceList;
50 label.AddAttribute(A);
55 //=======================================================================
56 //function : TDataStd_ReferenceList
57 //purpose : Empty Constructor
58 //=======================================================================
59 TDataStd_ReferenceList::TDataStd_ReferenceList() : myID(GetID())
62 //=======================================================================
65 //=======================================================================
66 Handle(TDataStd_ReferenceList) TDataStd_ReferenceList::Set(const TDF_Label& label)
68 return SetAttr(label, GetID());
71 //=======================================================================
73 //purpose : Set user defined attribute with specific ID
74 //=======================================================================
75 Handle(TDataStd_ReferenceList) TDataStd_ReferenceList::Set(const TDF_Label& label,
76 const Standard_GUID& theGuid)
78 return SetAttr(label, theGuid);
81 //=======================================================================
84 //=======================================================================
85 Standard_Boolean TDataStd_ReferenceList::IsEmpty() const
87 return myList.IsEmpty();
90 //=======================================================================
93 //=======================================================================
94 Standard_Integer TDataStd_ReferenceList::Extent() const
96 return myList.Extent();
99 //=======================================================================
102 //=======================================================================
103 void TDataStd_ReferenceList::Prepend(const TDF_Label& value)
106 myList.Prepend(value);
109 //=======================================================================
112 //=======================================================================
113 void TDataStd_ReferenceList::Append(const TDF_Label& value)
116 myList.Append(value);
119 //=======================================================================
120 //function : InsertBefore
122 //=======================================================================
123 Standard_Boolean TDataStd_ReferenceList::InsertBefore(const TDF_Label& value,
124 const TDF_Label& before_value)
126 TDF_ListIteratorOfLabelList itr(myList);
127 for (; itr.More(); itr.Next())
129 if (itr.Value() == before_value)
132 myList.InsertBefore(value, itr);
133 return Standard_True;
136 return Standard_False;
139 // Inserts the label before the <index> position.
140 // The indices start with 1 .. Extent().
141 Standard_Boolean TDataStd_ReferenceList::InsertBefore (const Standard_Integer index,
142 const TDF_Label& before_value)
144 Standard_Integer i(1);
145 Standard_Boolean found(Standard_False);
146 TDF_ListIteratorOfLabelList itr(myList);
147 for (; itr.More(); itr.Next(), ++i)
152 myList.InsertBefore(before_value, itr);
153 found = Standard_True;
160 //=======================================================================
161 //function : InsertAfter
163 //=======================================================================
164 Standard_Boolean TDataStd_ReferenceList::InsertAfter(const TDF_Label& value,
165 const TDF_Label& after_value)
167 TDF_ListIteratorOfLabelList itr(myList);
168 for (; itr.More(); itr.Next())
170 if (itr.Value() == after_value)
173 myList.InsertAfter(value, itr);
174 return Standard_True;
177 return Standard_False;
180 // Inserts the label after the <index> position.
181 // The indices start with 1 .. Extent().
182 Standard_Boolean TDataStd_ReferenceList::InsertAfter (const Standard_Integer index,
183 const TDF_Label& after_value)
185 Standard_Integer i(1);
186 Standard_Boolean found(Standard_False);
187 TDF_ListIteratorOfLabelList itr(myList);
188 for (; itr.More(); itr.Next(), ++i)
193 myList.InsertAfter(after_value, itr);
194 found = Standard_True;
201 //=======================================================================
204 //=======================================================================
205 Standard_Boolean TDataStd_ReferenceList::Remove(const TDF_Label& value)
207 TDF_ListIteratorOfLabelList itr(myList);
208 for (; itr.More(); itr.Next())
210 if (itr.Value() == value)
214 return Standard_True;
217 return Standard_False;
220 //=======================================================================
222 //purpose : Removes a label at the <index> position.
223 //=======================================================================
224 Standard_Boolean TDataStd_ReferenceList::Remove (const Standard_Integer index)
226 Standard_Integer i(1);
227 Standard_Boolean found(Standard_False);
228 TDF_ListIteratorOfLabelList itr(myList);
229 for (; itr.More(); itr.Next(), ++i)
235 found = Standard_True;
242 //=======================================================================
245 //=======================================================================
246 void TDataStd_ReferenceList::Clear()
252 //=======================================================================
255 //=======================================================================
256 const TDF_Label& TDataStd_ReferenceList::First() const
258 return myList.First();
261 //=======================================================================
264 //=======================================================================
265 const TDF_Label& TDataStd_ReferenceList::Last() const
267 return myList.Last();
270 //=======================================================================
273 //=======================================================================
274 const TDF_LabelList& TDataStd_ReferenceList::List() const
279 //=======================================================================
282 //=======================================================================
283 const Standard_GUID& TDataStd_ReferenceList::ID () const
288 //=======================================================================
291 //=======================================================================
292 void TDataStd_ReferenceList::SetID( const Standard_GUID& theGuid)
294 if(myID == theGuid) return;
299 //=======================================================================
301 //purpose : sets default ID
302 //=======================================================================
303 void TDataStd_ReferenceList::SetID()
309 //=======================================================================
310 //function : NewEmpty
312 //=======================================================================
313 Handle(TDF_Attribute) TDataStd_ReferenceList::NewEmpty () const
315 return new TDataStd_ReferenceList();
318 //=======================================================================
321 //=======================================================================
322 void TDataStd_ReferenceList::Restore(const Handle(TDF_Attribute)& With)
325 Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(With);
326 TDF_ListIteratorOfLabelList itr(aList->List());
327 for (; itr.More(); itr.Next())
329 myList.Append(itr.Value());
334 //=======================================================================
337 //=======================================================================
338 void TDataStd_ReferenceList::Paste (const Handle(TDF_Attribute)& Into,
339 const Handle(TDF_RelocationTable)& RT) const
341 Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(Into);
343 TDF_ListIteratorOfLabelList itr(myList);
344 for (; itr.More(); itr.Next())
346 TDF_Label L = itr.Value(), rL;
349 if (!RT->HasRelocation(L, rL))
357 //=======================================================================
358 //function : References
359 //purpose : Adds the referenced attributes or labels.
360 //=======================================================================
361 void TDataStd_ReferenceList::References(const Handle(TDF_DataSet)& aDataSet) const
363 if (!Label().IsImported())
365 TDF_ListIteratorOfLabelList itr(myList);
366 for (; itr.More(); itr.Next())
368 aDataSet->AddLabel(itr.Value());
373 //=======================================================================
376 //=======================================================================
377 Standard_OStream& TDataStd_ReferenceList::Dump (Standard_OStream& anOS) const
379 anOS << "\nReferenceList: ";
380 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
381 myID.ToCString(sguid);