1 // Created on: 2000-09-27
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
22 #include <XCAFDoc_GraphNode.ixx>
24 // class methods working on the node:
25 // ===================================
27 //=======================================================================
30 //=======================================================================
32 Standard_Boolean XCAFDoc_GraphNode::Find(const TDF_Label& L,
33 Handle(XCAFDoc_GraphNode)& G)
35 return L.FindAttribute(XCAFDoc_GraphNode::GetDefaultGraphID(), G);
38 //=======================================================================
39 //GraphNode : GetDefaultGraphID
40 //purpose : Static method to get the default ID of a GraphNode
41 //=======================================================================
43 const Standard_GUID& XCAFDoc_GraphNode::GetDefaultGraphID()
45 static Standard_GUID XCAFDoc_GraphNodeID ("efd212f5-6dfd-11d4-b9c8-0060b0ee281b");
46 return XCAFDoc_GraphNodeID;
49 //=======================================================================
51 //purpose : Finds or creates a GraphNode attribute with default ID
52 //=======================================================================
54 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::Set(const TDF_Label& L)
56 Handle(XCAFDoc_GraphNode) GN;
57 if (!L.FindAttribute(XCAFDoc_GraphNode::GetDefaultGraphID(), GN)) {
58 GN = new XCAFDoc_GraphNode();
59 GN->SetGraphID(XCAFDoc_GraphNode::GetDefaultGraphID());
65 //=======================================================================
67 //purpose : Finds or creates a GraphNode attribute with explicit ID
69 //=======================================================================
71 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::Set (const TDF_Label& L,
72 const Standard_GUID& explicitID)
74 Handle(XCAFDoc_GraphNode) GN;
75 if (!L.FindAttribute(explicitID, GN)) {
76 GN = new XCAFDoc_GraphNode ();
77 GN->SetGraphID( explicitID );
86 //=======================================================================
87 //function : XCAFDoc_GraphNode
89 //=======================================================================
91 XCAFDoc_GraphNode::XCAFDoc_GraphNode ()
96 //=======================================================================
97 //function : SetGraphID
99 //=======================================================================
101 void XCAFDoc_GraphNode::SetGraphID (const Standard_GUID& explicitID)
104 myGraphID = explicitID;
109 //=======================================================================
110 //function : SetFather
112 //=======================================================================
114 Standard_Integer XCAFDoc_GraphNode::SetFather(const Handle(XCAFDoc_GraphNode)& F)
117 Standard_Integer Findex = myFathers.Length();
122 //=======================================================================
123 //function : SetChild
125 //=======================================================================
127 Standard_Integer XCAFDoc_GraphNode::SetChild(const Handle(XCAFDoc_GraphNode)& Ch)
130 Standard_Integer Chindex = myChildren.Length();
131 myChildren.Append(Ch);
135 //=======================================================================
136 //function : UnSetFather
138 //=======================================================================
140 void XCAFDoc_GraphNode::UnSetFather(const Handle(XCAFDoc_GraphNode)& F)
143 Standard_Integer Findex = FatherIndex(F);
145 F->UnSetChildlink(this);
150 //=======================================================================
151 //function : UnSetFather
153 //=======================================================================
155 void XCAFDoc_GraphNode::UnSetFather(const Standard_Integer Findex)
158 UnSetFather( GetFather(Findex) );
162 //=======================================================================
163 //function : UnSetFatherlink
164 //purpose : Remove link finily
165 //=======================================================================
167 void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F)
169 myFathers.Remove( FatherIndex(F) );
172 //=======================================================================
173 //function : UnSetChild
175 //=======================================================================
177 void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch)
180 Standard_Integer Chindex = ChildIndex(Ch);
182 Ch->UnSetFatherlink(this);
187 //=======================================================================
188 //function : UnSetChild
190 //=======================================================================
192 void XCAFDoc_GraphNode::UnSetChild(const Standard_Integer Chindex)
195 UnSetChild( GetChild(Chindex) );
199 //=======================================================================
200 //function : UnSetChildlink
201 //purpose : Remove link finily
202 //=======================================================================
204 void XCAFDoc_GraphNode::UnSetChildlink(const Handle(XCAFDoc_GraphNode)& Ch)
206 myChildren.Remove( ChildIndex(Ch) );
209 //=======================================================================
210 //function : GetFather
212 //=======================================================================
214 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::GetFather(const Standard_Integer Findex) const
216 Handle(XCAFDoc_GraphNode) F = myFathers.Value(Findex);
220 //=======================================================================
221 //function : GetChild
223 //=======================================================================
225 Handle(XCAFDoc_GraphNode) XCAFDoc_GraphNode::GetChild(const Standard_Integer Chindex) const
227 Handle(XCAFDoc_GraphNode) Ch = myChildren.Value(Chindex);
231 //=======================================================================
232 //function : FatherIndex
234 //=======================================================================
236 Standard_Integer XCAFDoc_GraphNode::FatherIndex(const Handle(XCAFDoc_GraphNode)& F) const
238 Standard_Integer Findex = 0;
239 if (NbFathers()!=0) {
240 for (Findex = 1 ; Findex <= NbFathers(); Findex++) {
241 if ( F == myFathers.Value(Findex)) return Findex;
247 //=======================================================================
248 //function : ChildIndex
250 //=======================================================================
252 Standard_Integer XCAFDoc_GraphNode::ChildIndex(const Handle(XCAFDoc_GraphNode)& Ch) const
254 Standard_Integer Chindex;
255 if (NbChildren()!=0) {
256 for (Chindex = 1; Chindex <= NbChildren(); Chindex++) {
257 if ( Ch == myChildren.Value(Chindex)) return Chindex;
263 //=======================================================================
264 //function : IsFather
266 //=======================================================================
268 Standard_Boolean XCAFDoc_GraphNode::IsFather(const Handle(XCAFDoc_GraphNode)& Ch) const
270 if ( ChildIndex(Ch) ) return Standard_True;
271 return Standard_False;
274 //=======================================================================
277 //=======================================================================
279 Standard_Boolean XCAFDoc_GraphNode::IsChild(const Handle(XCAFDoc_GraphNode)& F) const
281 if ( FatherIndex(F) ) return Standard_True;
282 return Standard_False;
285 //=======================================================================
286 //function : NbFathers
288 //=======================================================================
290 Standard_Integer XCAFDoc_GraphNode::NbFathers() const
292 return myFathers.Length();
295 //=======================================================================
296 //function : NbChildren
298 //=======================================================================
300 Standard_Integer XCAFDoc_GraphNode::NbChildren() const
302 return myChildren.Length();
307 // Implementation of Attribute methods:
308 // ===================================
310 //=======================================================================
313 //=======================================================================
315 const Standard_GUID& XCAFDoc_GraphNode::ID() const
321 //=======================================================================
324 //=======================================================================
326 void XCAFDoc_GraphNode::Restore(const Handle(TDF_Attribute)& other)
328 Handle(XCAFDoc_GraphNode) F = Handle(XCAFDoc_GraphNode)::DownCast(other);
329 myFathers = F->myFathers;
330 myChildren = F->myChildren;
331 myGraphID = F->myGraphID;
335 //=======================================================================
338 //=======================================================================
340 void XCAFDoc_GraphNode::Paste(const Handle(TDF_Attribute)& into,
341 const Handle(TDF_RelocationTable)& RT) const
343 Handle(XCAFDoc_GraphNode) intof = Handle(XCAFDoc_GraphNode)::DownCast(into);
344 Handle(XCAFDoc_GraphNode) func;
345 Standard_Integer i = 1;
346 for (; i <= NbFathers(); i++) {
347 if (!RT->HasRelocation(myFathers(i), func) && RT->AfterRelocate()) {
350 intof->SetFather(func);
354 for (; i <= NbChildren(); i++) {
355 if (!RT->HasRelocation(myChildren(i), func) && RT->AfterRelocate()) {
358 intof->SetFather(func);
360 intof->SetGraphID(myGraphID);
364 //=======================================================================
365 //function : NewEmpty
367 //=======================================================================
369 Handle(TDF_Attribute) XCAFDoc_GraphNode::NewEmpty() const
371 Handle(XCAFDoc_GraphNode) G = new XCAFDoc_GraphNode();
372 G->SetGraphID(myGraphID);
377 //=======================================================================
378 //function : References
380 //=======================================================================
382 void XCAFDoc_GraphNode::References(const Handle(TDF_DataSet)& aDataSet) const
385 Handle(XCAFDoc_GraphNode) fct;
386 for ( i = 1; i <= NbChildren(); i++ ) {
389 aDataSet->AddAttribute(fct);
392 for ( i = 1; i <= NbFathers(); i++ ) {
394 if ( !fct.IsNull()) {
395 aDataSet->AddAttribute(fct);
401 //=======================================================================
404 //=======================================================================
406 Standard_OStream& XCAFDoc_GraphNode::Dump (Standard_OStream& anOS) const
408 TDF_Attribute::Dump (anOS);
409 Standard_Integer i = 1;
410 if ( myFathers.Length()!= 0 ) {
412 for (; i <= NbFathers(); i++) {
413 if ( !myFathers(i)->Label().IsNull() )
414 myFathers(i)->Label().EntryDump(anOS);
419 if ( myChildren.Length()!= 0 ) {
421 for (; i <= NbChildren(); i++) {
422 if ( !myChildren(i)->Label().IsNull() )
423 myChildren(i)->Label().EntryDump(anOS);
431 //=======================================================================
432 //function : BeforeForget
434 //=======================================================================
436 void XCAFDoc_GraphNode::BeforeForget()
438 while ( myFathers.Length() > 0 )
440 while ( myChildren.Length() > 0 )