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.
16 #ifndef _XCAFDoc_GraphNode_HeaderFile
17 #define _XCAFDoc_GraphNode_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <XCAFDoc_GraphNodeSequence.hxx>
23 #include <Standard_GUID.hxx>
24 #include <TDF_Attribute.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_OStream.hxx>
31 class TDF_RelocationTable;
35 class XCAFDoc_GraphNode;
36 DEFINE_STANDARD_HANDLE(XCAFDoc_GraphNode, TDF_Attribute)
38 //! This attribute allow user multirelation tree of labels.
39 //! This GraphNode is experimental Graph that not control looping and redundance.
40 //! Attribute containg sequence of father's and child's labels.
41 //! Provide create and work with Graph in XCAFDocument.
42 class XCAFDoc_GraphNode : public TDF_Attribute
48 //! class methods working on the node
49 //! ===================================
50 //! Shortcut to search a Graph node attribute with default
51 //! GraphID. Returns true if found.
52 Standard_EXPORT static Standard_Boolean Find (const TDF_Label& L, Handle(XCAFDoc_GraphNode)& G);
54 //! Finds or Creates a GraphNode attribute on the label <L>
55 //! with the default Graph ID, returned by the method
56 //! <GetDefaultGraphID>. Returns the created/found GraphNode
58 Standard_EXPORT static Handle(XCAFDoc_GraphNode) Set (const TDF_Label& L);
60 //! Finds or Creates a GraphNode attribute on the label
61 //! <L>, with an explicit tree ID. <ExplicitGraphID> is
62 //! the ID returned by <TDF_Attribute::ID> method.
63 //! Returns the found/created GraphNode attribute.
64 Standard_EXPORT static Handle(XCAFDoc_GraphNode) Set (const TDF_Label& L, const Standard_GUID& ExplicitGraphID);
66 //! returns a default Graph ID. this ID is used by the
67 //! <Set> method without explicit tree ID.
70 Standard_EXPORT static const Standard_GUID& GetDefaultGraphID();
72 Standard_EXPORT XCAFDoc_GraphNode();
74 Standard_EXPORT void SetGraphID (const Standard_GUID& explicitID);
76 //! Set GraphNode <F> as father of me and returns index of <F>
77 //! in Sequence that containing Fathers GraphNodes.
78 //! return index of <F> from GraphNodeSequnece
79 Standard_EXPORT Standard_Integer SetFather (const Handle(XCAFDoc_GraphNode)& F);
81 //! Set GraphNode <Ch> as child of me and returns index of <Ch>
82 //! in Sequence that containing Children GraphNodes.
83 //! return index of <Ch> from GraphNodeSequnece
84 Standard_EXPORT Standard_Integer SetChild (const Handle(XCAFDoc_GraphNode)& Ch);
86 //! Remove <F> from Fathers GraphNodeSequence.
87 //! and remove link between father and child.
88 Standard_EXPORT void UnSetFather (const Handle(XCAFDoc_GraphNode)& F);
90 //! Remove Father GraphNode by index from Fathers GraphNodeSequence.
91 //! and remove link between father and child.
92 Standard_EXPORT void UnSetFather (const Standard_Integer Findex);
94 //! Remove <Ch> from GraphNodeSequence.
95 //! and remove link between father and child.
96 Standard_EXPORT void UnSetChild (const Handle(XCAFDoc_GraphNode)& Ch);
98 //! Remove Child GraphNode by index from Children GraphNodeSequence.
99 //! and remove link between father and child.
100 Standard_EXPORT void UnSetChild (const Standard_Integer Chindex);
102 //! Return GraphNode by index from GraphNodeSequence.
103 Standard_EXPORT Handle(XCAFDoc_GraphNode) GetFather (const Standard_Integer Findex) const;
105 //! Return GraphNode by index from GraphNodeSequence.
106 Standard_EXPORT Handle(XCAFDoc_GraphNode) GetChild (const Standard_Integer Chindex) const;
108 //! Return index of <F>, or zero if there is no such Graphnode.
109 Standard_EXPORT Standard_Integer FatherIndex (const Handle(XCAFDoc_GraphNode)& F) const;
111 //! Return index of <Ch>, or zero if there is no such Graphnode.
112 Standard_EXPORT Standard_Integer ChildIndex (const Handle(XCAFDoc_GraphNode)& Ch) const;
114 //! returns TRUE if <me> is father of <Ch>.
115 Standard_EXPORT Standard_Boolean IsFather (const Handle(XCAFDoc_GraphNode)& Ch) const;
117 //! returns TRUE if <me> is child of <F>.
118 Standard_EXPORT Standard_Boolean IsChild (const Handle(XCAFDoc_GraphNode)& F) const;
120 //! return Number of Fathers GraphNodes.
121 Standard_EXPORT Standard_Integer NbFathers() const;
123 //! return Number of Childrens GraphNodes.
124 //! Implementation of Attribute methods:
125 //! ===================================
126 Standard_EXPORT Standard_Integer NbChildren() const;
128 //! Returns the Graph ID (default or explicit one depending
129 //! onthe Set method used).
130 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
132 Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
134 Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
136 Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
138 Standard_EXPORT virtual void References (const Handle(TDF_DataSet)& aDataSet) const Standard_OVERRIDE;
140 Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
142 Standard_EXPORT virtual void BeforeForget() Standard_OVERRIDE;
147 DEFINE_STANDARD_RTTIEXT(XCAFDoc_GraphNode,TDF_Attribute)
157 //! remove link between father and child.
158 Standard_EXPORT void UnSetFatherlink (const Handle(XCAFDoc_GraphNode)& F);
160 //! remove link between father and child.
161 Standard_EXPORT void UnSetChildlink (const Handle(XCAFDoc_GraphNode)& C);
163 XCAFDoc_GraphNodeSequence myFathers;
164 XCAFDoc_GraphNodeSequence myChildren;
165 Standard_GUID myGraphID;
176 #endif // _XCAFDoc_GraphNode_HeaderFile