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>
29 class TDF_RelocationTable;
33 class XCAFDoc_GraphNode;
34 DEFINE_STANDARD_HANDLE(XCAFDoc_GraphNode, TDF_Attribute)
36 //! This attribute allow user multirelation tree of labels.
37 //! This GraphNode is experimental Graph that not control looping and redundance.
38 //! Attribute containing sequence of father's and child's labels.
39 //! Provide create and work with Graph in XCAFDocument.
40 class XCAFDoc_GraphNode : public TDF_Attribute
46 //! class methods working on the node
47 //! ===================================
48 //! Shortcut to search a Graph node attribute with default
49 //! GraphID. Returns true if found.
50 Standard_EXPORT static Standard_Boolean Find (const TDF_Label& L, Handle(XCAFDoc_GraphNode)& G);
52 //! Finds or Creates a GraphNode attribute on the label <L>
53 //! with the default Graph ID, returned by the method
54 //! <GetDefaultGraphID>. Returns the created/found GraphNode
56 Standard_EXPORT static Handle(XCAFDoc_GraphNode) Set (const TDF_Label& L);
58 //! Finds or Creates a GraphNode attribute on the label
59 //! <L>, with an explicit tree ID. <ExplicitGraphID> is
60 //! the ID returned by <TDF_Attribute::ID> method.
61 //! Returns the found/created GraphNode attribute.
62 Standard_EXPORT static Handle(XCAFDoc_GraphNode) Set (const TDF_Label& L, const Standard_GUID& ExplicitGraphID);
64 //! returns a default Graph ID. this ID is used by the
65 //! <Set> method without explicit tree ID.
68 Standard_EXPORT static const Standard_GUID& GetDefaultGraphID();
70 Standard_EXPORT XCAFDoc_GraphNode();
72 Standard_EXPORT void SetGraphID (const Standard_GUID& explicitID);
74 //! Set GraphNode <F> as father of me and returns index of <F>
75 //! in Sequence that containing Fathers GraphNodes.
76 //! return index of <F> from GraphNodeSequnece
77 Standard_EXPORT Standard_Integer SetFather (const Handle(XCAFDoc_GraphNode)& F);
79 //! Set GraphNode <Ch> as child of me and returns index of <Ch>
80 //! in Sequence that containing Children GraphNodes.
81 //! return index of <Ch> from GraphNodeSequnece
82 Standard_EXPORT Standard_Integer SetChild (const Handle(XCAFDoc_GraphNode)& Ch);
84 //! Remove <F> from Fathers GraphNodeSequence.
85 //! and remove link between father and child.
86 Standard_EXPORT void UnSetFather (const Handle(XCAFDoc_GraphNode)& F);
88 //! Remove Father GraphNode by index from Fathers GraphNodeSequence.
89 //! and remove link between father and child.
90 Standard_EXPORT void UnSetFather (const Standard_Integer Findex);
92 //! Remove <Ch> from GraphNodeSequence.
93 //! and remove link between father and child.
94 Standard_EXPORT void UnSetChild (const Handle(XCAFDoc_GraphNode)& Ch);
96 //! Remove Child GraphNode by index from Children GraphNodeSequence.
97 //! and remove link between father and child.
98 Standard_EXPORT void UnSetChild (const Standard_Integer Chindex);
100 //! Return GraphNode by index from GraphNodeSequence.
101 Standard_EXPORT Handle(XCAFDoc_GraphNode) GetFather (const Standard_Integer Findex) const;
103 //! Return GraphNode by index from GraphNodeSequence.
104 Standard_EXPORT Handle(XCAFDoc_GraphNode) GetChild (const Standard_Integer Chindex) const;
106 //! Return index of <F>, or zero if there is no such Graphnode.
107 Standard_EXPORT Standard_Integer FatherIndex (const Handle(XCAFDoc_GraphNode)& F) const;
109 //! Return index of <Ch>, or zero if there is no such Graphnode.
110 Standard_EXPORT Standard_Integer ChildIndex (const Handle(XCAFDoc_GraphNode)& Ch) const;
112 //! returns TRUE if <me> is father of <Ch>.
113 Standard_EXPORT Standard_Boolean IsFather (const Handle(XCAFDoc_GraphNode)& Ch) const;
115 //! returns TRUE if <me> is child of <F>.
116 Standard_EXPORT Standard_Boolean IsChild (const Handle(XCAFDoc_GraphNode)& F) const;
118 //! return Number of Fathers GraphNodes.
119 Standard_EXPORT Standard_Integer NbFathers() const;
121 //! return Number of Childrens GraphNodes.
122 //! Implementation of Attribute methods:
123 //! ===================================
124 Standard_EXPORT Standard_Integer NbChildren() const;
126 //! Returns the Graph ID (default or explicit one depending
127 //! on the Set method used).
128 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
130 Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
132 Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
134 Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
136 Standard_EXPORT virtual void References (const Handle(TDF_DataSet)& aDataSet) const Standard_OVERRIDE;
138 Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
140 Standard_EXPORT virtual void BeforeForget() Standard_OVERRIDE;
142 //! Dumps the content of me into the stream
143 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
148 DEFINE_STANDARD_RTTIEXT(XCAFDoc_GraphNode,TDF_Attribute)
158 //! remove link between father and child.
159 Standard_EXPORT void UnSetFatherlink (const Handle(XCAFDoc_GraphNode)& F);
161 //! remove link between father and child.
162 Standard_EXPORT void UnSetChildlink (const Handle(XCAFDoc_GraphNode)& C);
164 XCAFDoc_GraphNodeSequence myFathers;
165 XCAFDoc_GraphNodeSequence myChildren;
166 Standard_GUID myGraphID;
177 #endif // _XCAFDoc_GraphNode_HeaderFile