1 // Created on: 2000-09-27
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-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 <TDF_Attribute.hxx>
20 #include <TDF_DataSet.hxx>
21 #include <TDF_Label.hxx>
22 #include <TDF_RelocationTable.hxx>
23 #include <XCAFDoc_GraphNode.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(XCAFDoc_GraphNode,TDF_Attribute)
27 // class methods working on the node:
28 // ===================================
29 //=======================================================================
32 //=======================================================================
33 Standard_Boolean XCAFDoc_GraphNode::Find(const TDF_Label& L,
34 Handle(XCAFDoc_GraphNode)& G)
36 return L.FindAttribute(XCAFDoc_GraphNode::GetDefaultGraphID(), G);
39 //=======================================================================
40 //GraphNode : GetDefaultGraphID
41 //purpose : Static method to get the default ID of a GraphNode
42 //=======================================================================
44 const Standard_GUID& XCAFDoc_GraphNode::GetDefaultGraphID()
46 static Standard_GUID XCAFDoc_GraphNodeID ("efd212f5-6dfd-11d4-b9c8-0060b0ee281b");
47 return XCAFDoc_GraphNodeID;
50 //=======================================================================
52 //purpose : Finds or creates a GraphNode attribute with default ID
53 //=======================================================================
55 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::Set(const TDF_Label& L)
57 Handle(XCAFDoc_GraphNode) GN;
58 if (!L.FindAttribute(XCAFDoc_GraphNode::GetDefaultGraphID(), GN)) {
59 GN = new XCAFDoc_GraphNode();
60 GN->SetGraphID(XCAFDoc_GraphNode::GetDefaultGraphID());
66 //=======================================================================
68 //purpose : Finds or creates a GraphNode attribute with explicit ID
70 //=======================================================================
72 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::Set (const TDF_Label& L,
73 const Standard_GUID& explicitID)
75 Handle(XCAFDoc_GraphNode) GN;
76 if (!L.FindAttribute(explicitID, GN)) {
77 GN = new XCAFDoc_GraphNode ();
78 GN->SetGraphID( explicitID );
87 //=======================================================================
88 //function : XCAFDoc_GraphNode
90 //=======================================================================
92 XCAFDoc_GraphNode::XCAFDoc_GraphNode ()
97 //=======================================================================
98 //function : SetGraphID
100 //=======================================================================
102 void XCAFDoc_GraphNode::SetGraphID (const Standard_GUID& explicitID)
105 myGraphID = explicitID;
110 //=======================================================================
111 //function : SetFather
113 //=======================================================================
115 Standard_Integer XCAFDoc_GraphNode::SetFather(const Handle(XCAFDoc_GraphNode)& F)
118 Standard_Integer Findex = myFathers.Length();
123 //=======================================================================
124 //function : SetChild
126 //=======================================================================
128 Standard_Integer XCAFDoc_GraphNode::SetChild(const Handle(XCAFDoc_GraphNode)& Ch)
131 Standard_Integer Chindex = myChildren.Length();
132 myChildren.Append(Ch);
136 //=======================================================================
137 //function : UnSetFather
139 //=======================================================================
141 void XCAFDoc_GraphNode::UnSetFather(const Handle(XCAFDoc_GraphNode)& F)
143 Standard_Integer Findex = FatherIndex(F);
146 F->UnSetChildlink (this);
152 //=======================================================================
153 //function : UnSetFather
155 //=======================================================================
157 void XCAFDoc_GraphNode::UnSetFather(const Standard_Integer Findex)
161 UnSetFather (GetFather (Findex));
166 //=======================================================================
167 //function : UnSetFatherlink
168 //purpose : Remove link finily
169 //=======================================================================
171 void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F)
174 Standard_Integer Findex = FatherIndex (F);
177 myFathers.Remove( Findex );
181 //=======================================================================
182 //function : UnSetChild
184 //=======================================================================
186 void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch)
188 Standard_Integer Chindex = ChildIndex(Ch);
191 Ch->UnSetFatherlink (this);
197 //=======================================================================
198 //function : UnSetChild
200 //=======================================================================
202 void XCAFDoc_GraphNode::UnSetChild(const Standard_Integer Chindex)
206 UnSetChild (GetChild (Chindex));
211 //=======================================================================
212 //function : UnSetChildlink
213 //purpose : Remove link finily
214 //=======================================================================
216 void XCAFDoc_GraphNode::UnSetChildlink(const Handle(XCAFDoc_GraphNode)& Ch)
219 Standard_Integer Chindex = ChildIndex (Ch);
222 myChildren.Remove (Chindex);
226 //=======================================================================
227 //function : GetFather
229 //=======================================================================
231 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::GetFather(const Standard_Integer Findex) const
233 Handle(XCAFDoc_GraphNode) F = myFathers.Value(Findex);
237 //=======================================================================
238 //function : GetChild
240 //=======================================================================
242 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::GetChild(const Standard_Integer Chindex) const
244 Handle(XCAFDoc_GraphNode) Ch = myChildren.Value(Chindex);
248 //=======================================================================
249 //function : FatherIndex
251 //=======================================================================
253 Standard_Integer XCAFDoc_GraphNode::FatherIndex(const Handle(XCAFDoc_GraphNode)& F) const
255 Standard_Integer Findex = 0;
256 if (NbFathers() != 0)
258 for (Findex = 1 ; Findex <= NbFathers(); Findex++)
260 if (F == myFathers.Value (Findex))
269 //=======================================================================
270 //function : ChildIndex
272 //=======================================================================
274 Standard_Integer XCAFDoc_GraphNode::ChildIndex(const Handle(XCAFDoc_GraphNode)& Ch) const
276 Standard_Integer Chindex;
277 if (NbChildren() != 0)
279 for (Chindex = 1; Chindex <= NbChildren(); Chindex++)
281 if (Ch == myChildren.Value (Chindex))
290 //=======================================================================
291 //function : IsFather
293 //=======================================================================
295 Standard_Boolean XCAFDoc_GraphNode::IsFather(const Handle(XCAFDoc_GraphNode)& Ch) const
297 if ( ChildIndex(Ch) ) return Standard_True;
298 return Standard_False;
301 //=======================================================================
304 //=======================================================================
306 Standard_Boolean XCAFDoc_GraphNode::IsChild(const Handle(XCAFDoc_GraphNode)& F) const
308 if ( FatherIndex(F) ) return Standard_True;
309 return Standard_False;
312 //=======================================================================
313 //function : NbFathers
315 //=======================================================================
317 Standard_Integer XCAFDoc_GraphNode::NbFathers() const
319 return myFathers.Length();
322 //=======================================================================
323 //function : NbChildren
325 //=======================================================================
327 Standard_Integer XCAFDoc_GraphNode::NbChildren() const
329 return myChildren.Length();
334 // Implementation of Attribute methods:
335 // ===================================
337 //=======================================================================
340 //=======================================================================
342 const Standard_GUID& XCAFDoc_GraphNode::ID() const
348 //=======================================================================
351 //=======================================================================
353 void XCAFDoc_GraphNode::Restore(const Handle(TDF_Attribute)& other)
355 Handle(XCAFDoc_GraphNode) F = Handle(XCAFDoc_GraphNode)::DownCast(other);
356 myFathers = F->myFathers;
357 myChildren = F->myChildren;
358 myGraphID = F->myGraphID;
362 //=======================================================================
365 //=======================================================================
367 void XCAFDoc_GraphNode::Paste(const Handle(TDF_Attribute)& into,
368 const Handle(TDF_RelocationTable)& RT) const
370 Handle(XCAFDoc_GraphNode) intof = Handle(XCAFDoc_GraphNode)::DownCast(into);
371 Handle(XCAFDoc_GraphNode) func;
372 Standard_Integer i = 1;
373 for (; i <= NbFathers(); i++) {
374 if (!RT->HasRelocation(myFathers(i), func) && RT->AfterRelocate())
380 intof->SetFather(func);
385 for (; i <= NbChildren(); i++)
387 if (!RT->HasRelocation(myChildren(i), func) && RT->AfterRelocate())
393 intof->SetChild(func);
396 intof->SetGraphID(myGraphID);
400 //=======================================================================
401 //function : NewEmpty
403 //=======================================================================
405 Handle(TDF_Attribute) XCAFDoc_GraphNode::NewEmpty() const
407 Handle(XCAFDoc_GraphNode) G = new XCAFDoc_GraphNode();
408 G->SetGraphID(myGraphID);
413 //=======================================================================
414 //function : References
416 //=======================================================================
418 void XCAFDoc_GraphNode::References(const Handle(TDF_DataSet)& aDataSet) const
421 Handle(XCAFDoc_GraphNode) fct;
422 for ( i = 1; i <= NbChildren(); i++ ) {
425 aDataSet->AddAttribute(fct);
428 for ( i = 1; i <= NbFathers(); i++ ) {
430 if ( !fct.IsNull()) {
431 aDataSet->AddAttribute(fct);
437 //=======================================================================
440 //=======================================================================
442 Standard_OStream& XCAFDoc_GraphNode::Dump (Standard_OStream& anOS) const
444 TDF_Attribute::Dump (anOS);
445 Standard_Integer i = 1;
446 if ( myFathers.Length()!= 0 ) {
448 for (; i <= NbFathers(); i++) {
449 if ( !myFathers(i)->Label().IsNull() )
450 myFathers(i)->Label().EntryDump(anOS);
455 if ( myChildren.Length()!= 0 ) {
457 for (; i <= NbChildren(); i++) {
458 if ( !myChildren(i)->Label().IsNull() )
459 myChildren(i)->Label().EntryDump(anOS);
467 //=======================================================================
468 //function : BeforeForget
470 //=======================================================================
472 void XCAFDoc_GraphNode::BeforeForget()
474 while (myFathers.Length () > 0)
478 while (myChildren.Length () > 0)