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.
16 #include <TDataStd_ReferenceList.hxx>
18 #include <Standard_Dump.hxx>
19 #include <Standard_GUID.hxx>
20 #include <Standard_Type.hxx>
21 #include <TDF_Attribute.hxx>
22 #include <TDF_DataSet.hxx>
23 #include <TDF_Label.hxx>
24 #include <TDF_ListIteratorOfLabelList.hxx>
25 #include <TDF_RelocationTable.hxx>
26 #include <TDF_Tool.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(TDataStd_ReferenceList,TDF_Attribute)
30 //=======================================================================
33 //=======================================================================
34 const Standard_GUID& TDataStd_ReferenceList::GetID()
36 static Standard_GUID TDataStd_ReferenceListID ("FCC1A658-59FF-4218-931B-0320A2B469A7");
37 return TDataStd_ReferenceListID;
40 //=======================================================================
42 //purpose : Implements Set functionality
43 //=======================================================================
44 static Handle(TDataStd_ReferenceList) SetAttr(const TDF_Label& label,
45 const Standard_GUID& theGuid)
47 Handle(TDataStd_ReferenceList) A;
48 if (!label.FindAttribute (theGuid, A))
50 A = new TDataStd_ReferenceList;
52 label.AddAttribute(A);
57 //=======================================================================
58 //function : TDataStd_ReferenceList
59 //purpose : Empty Constructor
60 //=======================================================================
61 TDataStd_ReferenceList::TDataStd_ReferenceList() : myID(GetID())
64 //=======================================================================
67 //=======================================================================
68 Handle(TDataStd_ReferenceList) TDataStd_ReferenceList::Set(const TDF_Label& label)
70 return SetAttr(label, GetID());
73 //=======================================================================
75 //purpose : Set user defined attribute with specific ID
76 //=======================================================================
77 Handle(TDataStd_ReferenceList) TDataStd_ReferenceList::Set(const TDF_Label& label,
78 const Standard_GUID& theGuid)
80 return SetAttr(label, theGuid);
83 //=======================================================================
86 //=======================================================================
87 Standard_Boolean TDataStd_ReferenceList::IsEmpty() const
89 return myList.IsEmpty();
92 //=======================================================================
95 //=======================================================================
96 Standard_Integer TDataStd_ReferenceList::Extent() const
98 return myList.Extent();
101 //=======================================================================
104 //=======================================================================
105 void TDataStd_ReferenceList::Prepend(const TDF_Label& value)
108 myList.Prepend(value);
111 //=======================================================================
114 //=======================================================================
115 void TDataStd_ReferenceList::Append(const TDF_Label& value)
118 myList.Append(value);
121 //=======================================================================
122 //function : InsertBefore
124 //=======================================================================
125 Standard_Boolean TDataStd_ReferenceList::InsertBefore(const TDF_Label& value,
126 const TDF_Label& before_value)
128 TDF_ListIteratorOfLabelList itr(myList);
129 for (; itr.More(); itr.Next())
131 if (itr.Value() == before_value)
134 myList.InsertBefore(value, itr);
135 return Standard_True;
138 return Standard_False;
141 // Inserts the label before the <index> position.
142 // The indices start with 1 .. Extent().
143 Standard_Boolean TDataStd_ReferenceList::InsertBefore (const Standard_Integer index,
144 const TDF_Label& before_value)
146 Standard_Integer i(1);
147 Standard_Boolean found(Standard_False);
148 TDF_ListIteratorOfLabelList itr(myList);
149 for (; itr.More(); itr.Next(), ++i)
154 myList.InsertBefore(before_value, itr);
155 found = Standard_True;
162 //=======================================================================
163 //function : InsertAfter
165 //=======================================================================
166 Standard_Boolean TDataStd_ReferenceList::InsertAfter(const TDF_Label& value,
167 const TDF_Label& after_value)
169 TDF_ListIteratorOfLabelList itr(myList);
170 for (; itr.More(); itr.Next())
172 if (itr.Value() == after_value)
175 myList.InsertAfter(value, itr);
176 return Standard_True;
179 return Standard_False;
182 // Inserts the label after the <index> position.
183 // The indices start with 1 .. Extent().
184 Standard_Boolean TDataStd_ReferenceList::InsertAfter (const Standard_Integer index,
185 const TDF_Label& after_value)
187 Standard_Integer i(1);
188 Standard_Boolean found(Standard_False);
189 TDF_ListIteratorOfLabelList itr(myList);
190 for (; itr.More(); itr.Next(), ++i)
195 myList.InsertAfter(after_value, itr);
196 found = Standard_True;
203 //=======================================================================
206 //=======================================================================
207 Standard_Boolean TDataStd_ReferenceList::Remove(const TDF_Label& value)
209 TDF_ListIteratorOfLabelList itr(myList);
210 for (; itr.More(); itr.Next())
212 if (itr.Value() == value)
216 return Standard_True;
219 return Standard_False;
222 //=======================================================================
224 //purpose : Removes a label at the <index> position.
225 //=======================================================================
226 Standard_Boolean TDataStd_ReferenceList::Remove (const Standard_Integer index)
228 Standard_Integer i(1);
229 Standard_Boolean found(Standard_False);
230 TDF_ListIteratorOfLabelList itr(myList);
231 for (; itr.More(); itr.Next(), ++i)
237 found = Standard_True;
244 //=======================================================================
247 //=======================================================================
248 void TDataStd_ReferenceList::Clear()
254 //=======================================================================
257 //=======================================================================
258 const TDF_Label& TDataStd_ReferenceList::First() const
260 return myList.First();
263 //=======================================================================
266 //=======================================================================
267 const TDF_Label& TDataStd_ReferenceList::Last() const
269 return myList.Last();
272 //=======================================================================
275 //=======================================================================
276 const TDF_LabelList& TDataStd_ReferenceList::List() const
281 //=======================================================================
284 //=======================================================================
285 const Standard_GUID& TDataStd_ReferenceList::ID () const
290 //=======================================================================
293 //=======================================================================
294 void TDataStd_ReferenceList::SetID( const Standard_GUID& theGuid)
296 if(myID == theGuid) return;
301 //=======================================================================
303 //purpose : sets default ID
304 //=======================================================================
305 void TDataStd_ReferenceList::SetID()
311 //=======================================================================
312 //function : NewEmpty
314 //=======================================================================
315 Handle(TDF_Attribute) TDataStd_ReferenceList::NewEmpty () const
317 return new TDataStd_ReferenceList();
320 //=======================================================================
323 //=======================================================================
324 void TDataStd_ReferenceList::Restore(const Handle(TDF_Attribute)& With)
327 Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(With);
328 TDF_ListIteratorOfLabelList itr(aList->List());
329 for (; itr.More(); itr.Next())
331 myList.Append(itr.Value());
336 //=======================================================================
339 //=======================================================================
340 void TDataStd_ReferenceList::Paste (const Handle(TDF_Attribute)& Into,
341 const Handle(TDF_RelocationTable)& RT) const
343 Handle(TDataStd_ReferenceList) aList = Handle(TDataStd_ReferenceList)::DownCast(Into);
345 TDF_ListIteratorOfLabelList itr(myList);
346 for (; itr.More(); itr.Next())
348 TDF_Label L = itr.Value(), rL;
351 if (!RT->HasRelocation(L, rL))
359 //=======================================================================
360 //function : References
361 //purpose : Adds the referenced attributes or labels.
362 //=======================================================================
363 void TDataStd_ReferenceList::References(const Handle(TDF_DataSet)& aDataSet) const
365 if (!Label().IsImported())
367 TDF_ListIteratorOfLabelList itr(myList);
368 for (; itr.More(); itr.Next())
370 aDataSet->AddLabel(itr.Value());
375 //=======================================================================
378 //=======================================================================
379 Standard_OStream& TDataStd_ReferenceList::Dump (Standard_OStream& anOS) const
381 anOS << "\nReferenceList: ";
382 Standard_Character sguid[Standard_GUID_SIZE_ALLOC];
383 myID.ToCString(sguid);
389 //=======================================================================
390 //function : DumpJson
392 //=======================================================================
393 void TDataStd_ReferenceList::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
395 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
397 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, TDF_Attribute)
399 TCollection_AsciiString aLabel;
400 for (TDF_LabelList::Iterator aListIt (myList); aListIt.More(); aListIt.Next())
403 TDF_Tool::Entry (aListIt.Value(), aLabel);
404 OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aLabel)
407 OCCT_DUMP_FIELD_VALUE_GUID (theOStream, myID)