1 // Created on: 1999-06-10
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _TDataStd_TreeNode_HeaderFile
18 #define _TDataStd_TreeNode_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_Type.hxx>
23 #include <TDataStd_PtrTreeNode.hxx>
24 #include <Standard_GUID.hxx>
25 #include <TDF_Attribute.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_Integer.hxx>
28 #include <Standard_OStream.hxx>
29 class TDataStd_ChildNodeIterator;
32 class TDF_AttributeDelta;
34 class TDF_RelocationTable;
38 class TDataStd_TreeNode;
39 DEFINE_STANDARD_HANDLE(TDataStd_TreeNode, TDF_Attribute)
41 //! Allows you to define an explicit tree of labels
42 //! which you can also edit.
43 //! Without this class, the data structure cannot be fully edited.
44 //! This service is required if for presentation
45 //! purposes, you want to create an application with
46 //! a tree which allows you to organize and link data
47 //! as a function of application features.
48 class TDataStd_TreeNode : public TDF_Attribute
54 //! class methods working on the node
55 //! ===================================
56 //! Returns true if the tree node T is found on the label L.
57 //! Otherwise, false is returned.
58 Standard_EXPORT static Standard_Boolean Find (const TDF_Label& L, Handle(TDataStd_TreeNode)& T);
60 //! Finds or Creates a TreeNode attribute on the label <L>
61 //! with the default tree ID, returned by the method
62 //! <GetDefaultTreeID>. Returns the created/found TreeNode
64 Standard_EXPORT static Handle(TDataStd_TreeNode) Set (const TDF_Label& L);
66 //! Finds or Creates a TreeNode attribute on the label
67 //! <L>, with an explicit tree ID. <ExplicitTreeID> is
68 //! the ID returned by <TDF_Attribute::ID> method.
69 //! Returns the found/created TreeNode attribute.
70 Standard_EXPORT static Handle(TDataStd_TreeNode) Set (const TDF_Label& L, const Standard_GUID& ExplicitTreeID);
72 //! returns a default tree ID. this ID is used by the
73 //! <Set> method without explicit tree ID.
76 Standard_EXPORT static const Standard_GUID& GetDefaultTreeID();
78 Standard_EXPORT TDataStd_TreeNode();
80 //! Insert the TreeNode <Child> as last child of <me>. If
81 //! the insertion is successful <me> becomes the Father of <Child>.
82 Standard_EXPORT Standard_Boolean Append (const Handle(TDataStd_TreeNode)& Child);
84 //! Insert the the TreeNode <Child> as first child of
85 //! <me>. If the insertion is successful <me> becomes the Father of <Child>
86 Standard_EXPORT Standard_Boolean Prepend (const Handle(TDataStd_TreeNode)& Child);
88 //! Inserts the TreeNode <Node> before <me>. If insertion is successful <me>
89 //! and <Node> belongs to the same Father.
90 Standard_EXPORT Standard_Boolean InsertBefore (const Handle(TDataStd_TreeNode)& Node);
92 //! Inserts the TreeNode <Node> after <me>. If insertion is successful <me>
93 //! and <Node> belongs to the same Father.
94 Standard_EXPORT Standard_Boolean InsertAfter (const Handle(TDataStd_TreeNode)& Node);
96 //! Removes this tree node attribute from its father
97 //! node. The result is that this attribute becomes a root node.
98 Standard_EXPORT Standard_Boolean Remove();
100 //! Returns the depth of this tree node in the overall tree node structure.
101 //! In other words, the number of father tree nodes of this one is returned.
102 Standard_EXPORT Standard_Integer Depth() const;
104 //! Returns the number of child nodes.
105 //! If <allLevels> is true, the method counts children of all levels
106 //! (children of children ...)
107 Standard_EXPORT Standard_Integer NbChildren (const Standard_Boolean allLevels = Standard_False) const;
109 //! Returns true if this tree node attribute is an
110 //! ascendant of of. In other words, if it is a father or
111 //! the father of a father of of.
112 Standard_EXPORT Standard_Boolean IsAscendant (const Handle(TDataStd_TreeNode)& of) const;
114 //! Returns true if this tree node attribute is a
115 //! descendant of of. In other words, if it is a child or
116 //! the child of a child of of.
117 Standard_EXPORT Standard_Boolean IsDescendant (const Handle(TDataStd_TreeNode)& of) const;
119 //! Returns true if this tree node attribute is the
120 //! ultimate father in the tree.
121 Standard_EXPORT Standard_Boolean IsRoot() const;
123 //! Returns the ultimate father of this tree node attribute.
124 Standard_EXPORT Handle(TDataStd_TreeNode) Root() const;
126 //! Returns true if this tree node attribute is a father of of.
127 Standard_EXPORT Standard_Boolean IsFather (const Handle(TDataStd_TreeNode)& of) const;
129 //! Returns true if this tree node attribute is a child of of.
130 Standard_EXPORT Standard_Boolean IsChild (const Handle(TDataStd_TreeNode)& of) const;
132 //! Returns true if this tree node attribute has a father tree node.
133 Standard_Boolean HasFather() const;
135 //! Returns the father TreeNode of <me>. Null if root.
136 Standard_EXPORT Handle(TDataStd_TreeNode) Father() const;
138 //! Returns true if this tree node attribute has a next tree node.
139 Standard_Boolean HasNext() const;
141 //! Returns the next tree node in this tree node attribute.
143 //! This tree node is null if it is the last one in this
144 //! tree node attribute.Returns the next TreeNode of <me>. Null if last.
145 Standard_EXPORT Handle(TDataStd_TreeNode) Next() const;
147 //! Returns true if this tree node attribute has a previous tree node.
148 Standard_Boolean HasPrevious() const;
150 //! Returns the previous tree node of this tree node attribute.
152 //! This tree node is null if it is the first one in this tree node attribute.
153 Standard_EXPORT Handle(TDataStd_TreeNode) Previous() const;
155 //! Returns true if this tree node attribute has a first child tree node.
156 Standard_Boolean HasFirst() const;
158 //! Returns the first child tree node in this tree node object.
159 Standard_EXPORT Handle(TDataStd_TreeNode) First() const;
161 //! Returns true if this tree node attribute has a last child tree node.
162 Standard_Boolean HasLast() const;
164 //! Returns the last child tree node in this tree node object.
165 Standard_EXPORT Handle(TDataStd_TreeNode) Last();
167 //! Returns the last child tree node in this tree node object.
170 Standard_EXPORT Handle(TDataStd_TreeNode) FindLast();
172 Standard_EXPORT void SetTreeID (const Standard_GUID& explicitID);
174 Standard_EXPORT void SetFather (const Handle(TDataStd_TreeNode)& F);
176 Standard_EXPORT void SetNext (const Handle(TDataStd_TreeNode)& F);
178 Standard_EXPORT void SetPrevious (const Handle(TDataStd_TreeNode)& F);
180 Standard_EXPORT void SetFirst (const Handle(TDataStd_TreeNode)& F);
182 //! TreeNode callback:
183 //! ==================
184 Standard_EXPORT void SetLast (const Handle(TDataStd_TreeNode)& F);
186 //! Connect the TreeNode to its father child list
187 Standard_EXPORT virtual void AfterAddition() Standard_OVERRIDE;
189 //! Disconnect the TreeNode from its Father child list
190 Standard_EXPORT virtual void BeforeForget() Standard_OVERRIDE;
192 //! Reconnect the TreeNode to its father child list.
193 Standard_EXPORT virtual void AfterResume() Standard_OVERRIDE;
195 //! Disconnect the TreeNode, if necessary.
196 Standard_EXPORT virtual Standard_Boolean BeforeUndo (const Handle(TDF_AttributeDelta)& anAttDelta, const Standard_Boolean forceIt = Standard_False) Standard_OVERRIDE;
198 //! Reconnect the TreeNode, if necessary.
199 //! Implementation of Attribute methods:
200 //! ===================================
201 Standard_EXPORT virtual Standard_Boolean AfterUndo (const Handle(TDF_AttributeDelta)& anAttDelta, const Standard_Boolean forceIt = Standard_False) Standard_OVERRIDE;
203 //! Returns the tree ID (default or explicit one depending
204 //! onthe Set method used).
205 Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
207 Standard_EXPORT virtual void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
209 Standard_EXPORT virtual void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
211 Standard_EXPORT virtual Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
213 Standard_EXPORT virtual void References (const Handle(TDF_DataSet)& aDataSet) const Standard_OVERRIDE;
215 Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& anOS) const Standard_OVERRIDE;
217 //! Dumps the content of me into the stream
218 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
221 friend class TDataStd_ChildNodeIterator;
224 DEFINE_STANDARD_RTTIEXT(TDataStd_TreeNode,TDF_Attribute)
234 TDataStd_PtrTreeNode myFather;
235 TDataStd_PtrTreeNode myPrevious;
236 TDataStd_PtrTreeNode myNext;
237 TDataStd_PtrTreeNode myFirst;
238 TDataStd_PtrTreeNode myLast;
239 Standard_GUID myTreeID;
245 #include <TDataStd_TreeNode.lxx>
251 #endif // _TDataStd_TreeNode_HeaderFile