1 // Created on: 1997-02-04
2 // Created by: DAUTRY Philippe
3 // Copyright (c) 1997-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 _TDF_Label_HeaderFile
18 #define _TDF_Label_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <TDF_LabelNodePtr.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_OStream.hxx>
27 #include <TDF_AttributeIndexedMap.hxx>
34 //! This class provides basic operations to define
35 //! a label in a data structure.
36 //! A label is a feature in the feature hierarchy. A
37 //! label is always connected to a Data from TDF.
38 //! To a label is attached attributes containing the
39 //! software components information.
41 //! Label information:
43 //! It is possible to know the tag, the father, the
44 //! depth in the tree of the label, if the label is
45 //! root, null or equal to another label.
48 //! Some methods useful on a label.
52 //! It is possible to get an attribute in accordance
53 //! to an ID, or the yougest previous version of a
54 //! current attribute.
62 //! Constructs an empty label object.
65 //! Nullifies the label.
68 //! Returns the Data owning <me>.
69 Handle(TDF_Data) Data() const;
71 //! Returns the tag of the label.
72 //! This is the integer assigned randomly to a label
73 //! in a data framework. This integer is used to
74 //! identify this label in an entry.
75 Standard_Integer Tag() const;
77 //! Returns the label father. This label may be null
78 //! if the label is root.
79 const TDF_Label Father() const;
81 //! Returns True if the <aLabel> is null, i.e. it has
82 //! not been included in the data framework.
83 Standard_Boolean IsNull() const;
85 //! Sets or unsets <me> and all its descendants as
86 //! imported label, according to <aStatus>.
87 Standard_EXPORT void Imported (const Standard_Boolean aStatus) const;
89 //! Returns True if the <aLabel> is imported.
90 Standard_Boolean IsImported() const;
92 //! Returns True if the <aLabel> is equal to me (same
94 Standard_Boolean IsEqual (const TDF_Label& aLabel) const;
95 Standard_Boolean operator == (const TDF_Label& aLabel) const
97 return IsEqual(aLabel);
100 Standard_Boolean IsDifferent (const TDF_Label& aLabel) const;
101 Standard_Boolean operator != (const TDF_Label& aLabel) const
103 return IsDifferent(aLabel);
106 Standard_Boolean IsRoot() const;
108 //! Returns true if <me> owns an attribute with <anID> as ID.
109 Standard_EXPORT Standard_Boolean IsAttribute (const Standard_GUID& anID) const;
111 //! Adds an Attribute to the current label. Raises if
112 //! there is already one.
113 Standard_EXPORT void AddAttribute (const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append = Standard_True) const;
115 //! Forgets an Attribute from the current label,
116 //! setting its forgotten status true and its valid
117 //! status false. Raises if the attribute is not in
119 Standard_EXPORT void ForgetAttribute (const Handle(TDF_Attribute)& anAttribute) const;
121 //! Forgets the Attribute of GUID <aguid> from the
122 //! current label . If the attribute doesn't exist
123 //! returns False. Otherwise returns True.
124 Standard_EXPORT Standard_Boolean ForgetAttribute (const Standard_GUID& aguid) const;
126 //! Forgets all the attributes. Does it on also on the
127 //! sub-labels if <clearChildren> is set to true. Of
128 //! course, this method is compatible with Transaction
129 //! & Delta mechanisms.
130 Standard_EXPORT void ForgetAllAttributes (const Standard_Boolean clearChildren = Standard_True) const;
132 //! Undo Forget action, setting its forgotten status
133 //! false and its valid status true. Raises if the
134 //! attribute is not in the structure.
135 Standard_EXPORT void ResumeAttribute (const Handle(TDF_Attribute)& anAttribute) const;
137 //! Finds an attribute of the current label, according
139 //! If anAttribute is not a valid one, false is returned.
141 //! The method returns True if found, False otherwise.
143 //! A removed attribute cannot be found.
144 Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const;
146 //! Safe variant of FindAttribute() for arbitrary type of argument
148 Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const
150 Handle(TDF_Attribute) anAttr;
151 return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull();
154 //! Finds an attribute of the current label, according
155 //! to <anID> and <aTransaction>. This attribute
156 //! has/had to be a valid one for the given
157 //! transaction index . So, this attribute is not
158 //! necessary a valid one.
160 //! The method returns True if found, False otherwise.
162 //! A removed attribute cannot be found nor a backuped
163 //! attribute of a removed one.
164 Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, const Standard_Integer aTransaction, Handle(TDF_Attribute)& anAttribute) const;
166 //! Returns true if <me> or a DESCENDANT of <me> owns
167 //! attributes not yet available in transaction 0. It
168 //! means at least one of their attributes is new,
169 //! modified or deleted.
170 Standard_Boolean MayBeModified() const;
172 //! Returns true if <me> owns attributes not yet
173 //! available in transaction 0. It means at least one
174 //! attribute is new, modified or deleted.
175 Standard_Boolean AttributesModified() const;
177 //! Returns true if this label has at least one attribute.
178 Standard_EXPORT Standard_Boolean HasAttribute() const;
180 //! Returns the number of attributes.
181 Standard_EXPORT Standard_Integer NbAttributes() const;
183 //! Returns the depth of the label in the data framework.
184 //! This corresponds to the number of fathers which
185 //! this label has, and is used in determining
186 //! whether a label is root, null or equivalent to another label.
188 //! Standard_NullObject if this label is null. This is
189 //! because a null object can have no depth.
190 Standard_EXPORT Standard_Integer Depth() const;
192 //! Returns True if <me> is a descendant of
193 //! <aLabel>. Attention: every label is its own
195 Standard_EXPORT Standard_Boolean IsDescendant (const TDF_Label& aLabel) const;
197 //! Returns the root label Root of the data structure.
198 //! This has a depth of 0.
200 //! Standard_NullObject if this label is null. This is
201 //! because a null object can have no depth.
202 Standard_EXPORT const TDF_Label Root() const;
204 //! Returns true if this label has at least one child.
205 Standard_Boolean HasChild() const;
207 //! Returns the number of children.
208 Standard_EXPORT Standard_Integer NbChildren() const;
210 //! Finds a child label having <aTag> as tag. Creates
211 //! The tag aTag identifies the label which will be the parent.
212 //! If create is true and no child label is found, a new one is created.
214 //! //creating a label with tag 10 at Root
215 //! TDF_Label lab1 = aDF->Root().FindChild(10);
216 //! //creating labels 7 and 2 on label 10
217 //! TDF_Label lab2 = lab1.FindChild(7);
218 //! TDF_Label lab3 = lab1.FindChild(2);
219 Standard_EXPORT TDF_Label FindChild (const Standard_Integer aTag, const Standard_Boolean create = Standard_True) const;
221 //! Create a new child label of me using autoamtic
222 //! delivery tags provided by TagSource.
223 TDF_Label NewChild() const;
225 //! Returns the current transaction index.
226 Standard_EXPORT Standard_Integer Transaction() const;
228 //! Returns true if node address of <me> is lower than
229 //! <otherLabel> one. Used to quickly sort labels (not
230 //! on entry criterion).
233 Standard_EXPORT Standard_Boolean HasLowerNode (const TDF_Label& otherLabel) const;
235 //! Returns true if node address of <me> is greater
236 //! than <otherLabel> one. Used to quickly sort labels
237 //! (not on entry criterion).
240 Standard_EXPORT Standard_Boolean HasGreaterNode (const TDF_Label& otherLabel) const;
242 //! Dumps the minimum information about <me> on
244 Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const;
245 Standard_OStream& operator<< (Standard_OStream& anOS) const
250 //! Dumps the label on <aStream> and its attributes
251 //! rank in <aMap> if their IDs are kept by <IDFilter>.
252 Standard_EXPORT void ExtendedDump (Standard_OStream& anOS, const TDF_IDFilter& aFilter, TDF_AttributeIndexedMap& aMap) const;
254 //! Dumps the label entry.
255 Standard_EXPORT void EntryDump (Standard_OStream& anOS) const;
258 friend class TDF_ChildIterator;
259 friend class TDF_Attribute;
260 friend class TDF_AttributeIterator;
261 friend class TDF_Data;
262 friend class TDF_LabelMapHasher;
274 //! Reserved to the friends.
275 TDF_Label(const TDF_LabelNodePtr& aNode);
277 //! Adds an Attribute to <toNode>. Raises if there is
279 Standard_EXPORT void AddToNode (const TDF_LabelNodePtr& toNode, const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append) const;
281 //! Forgets an Attribute from <fromNode>. Raises if
282 //! the attribute is not in the structure.
283 Standard_EXPORT void ForgetFromNode (const TDF_LabelNodePtr& fromNode, const Handle(TDF_Attribute)& anAttribute) const;
285 //! Resumes a forgotten Attribute to <toNode>. Raises
286 //! if the attribute is not in the structure.
287 Standard_EXPORT void ResumeToNode (const TDF_LabelNodePtr& fromNode, const Handle(TDF_Attribute)& anAttribute) const;
289 Standard_EXPORT TDF_LabelNodePtr FindOrAddChild (const Standard_Integer aTag, const Standard_Boolean create) const;
291 Standard_EXPORT void InternalDump (Standard_OStream& anOS, const TDF_IDFilter& aFilter, TDF_AttributeIndexedMap& aMap, const Standard_Boolean extended) const;
294 TDF_LabelNodePtr myLabelNode;
300 #include <TDF_Label.lxx>
306 #endif // _TDF_Label_HeaderFile