0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TDF / TDF_Label.hxx
CommitLineData
42cf5bc1 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
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _TDF_Label_HeaderFile
18#define _TDF_Label_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <TDF_LabelNodePtr.hxx>
25#include <Standard_Integer.hxx>
42cf5bc1 26#include <Standard_OStream.hxx>
27#include <TDF_AttributeIndexedMap.hxx>
42cf5bc1 28class TDF_Attribute;
42cf5bc1 29class TDF_Data;
42cf5bc1 30class Standard_GUID;
31class TDF_IDFilter;
32
33
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.
40//!
41//! Label information:
42//!
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.
46//!
47//! Comfort methods:
48//! Some methods useful on a label.
49//!
50//! Attributes:
51//!
52//! It is possible to get an attribute in accordance
53//! to an ID, or the yougest previous version of a
54//! current attribute.
55class TDF_Label
56{
57public:
58
59 DEFINE_STANDARD_ALLOC
60
61
62 //! Constructs an empty label object.
63 TDF_Label();
64
65 //! Nullifies the label.
66 void Nullify();
67
68 //! Returns the Data owning <me>.
69 Handle(TDF_Data) Data() const;
70
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;
76
77 //! Returns the label father. This label may be null
78 //! if the label is root.
79 const TDF_Label Father() const;
80
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;
84
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;
88
89 //! Returns True if the <aLabel> is imported.
90 Standard_Boolean IsImported() const;
91
92 //! Returns True if the <aLabel> is equal to me (same
93 //! LabelNode*).
94 Standard_Boolean IsEqual (const TDF_Label& aLabel) const;
95 Standard_Boolean operator == (const TDF_Label& aLabel) const
96{
97 return IsEqual(aLabel);
98}
99
100 Standard_Boolean IsDifferent (const TDF_Label& aLabel) const;
101 Standard_Boolean operator != (const TDF_Label& aLabel) const
102{
103 return IsDifferent(aLabel);
104}
105
106 Standard_Boolean IsRoot() const;
107
108 //! Returns true if <me> owns an attribute with <anID> as ID.
109 Standard_EXPORT Standard_Boolean IsAttribute (const Standard_GUID& anID) const;
110
111 //! Adds an Attribute to the current label. Raises if
112 //! there is already one.
bd6f0d2f 113 Standard_EXPORT void AddAttribute (const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append = Standard_True) const;
42cf5bc1 114
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
118 //! the structure.
119 Standard_EXPORT void ForgetAttribute (const Handle(TDF_Attribute)& anAttribute) const;
120
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;
125
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
03ca365a 129 //! & Delta mechanisms.
42cf5bc1 130 Standard_EXPORT void ForgetAllAttributes (const Standard_Boolean clearChildren = Standard_True) const;
131
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;
136
137 //! Finds an attribute of the current label, according
138 //! to <anID>.
139 //! If anAttribute is not a valid one, false is returned.
140 //!
141 //! The method returns True if found, False otherwise.
142 //!
143 //! A removed attribute cannot be found.
144 Standard_EXPORT Standard_Boolean FindAttribute (const Standard_GUID& anID, Handle(TDF_Attribute)& anAttribute) const;
145
aa00364d 146 //! Safe variant of FindAttribute() for arbitrary type of argument
147 template <class T>
148 Standard_Boolean FindAttribute (const Standard_GUID& theID, Handle(T)& theAttr) const
149 {
c2100640 150 Handle(TDF_Attribute) anAttr;
aa00364d 151 return FindAttribute (theID, anAttr) && ! (theAttr = Handle(T)::DownCast(anAttr)).IsNull();
152 }
153
42cf5bc1 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.
159 //!
160 //! The method returns True if found, False otherwise.
161 //!
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;
165
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;
171
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;
176
177 //! Returns true if this label has at least one attribute.
178 Standard_EXPORT Standard_Boolean HasAttribute() const;
179
180 //! Returns the number of attributes.
181 Standard_EXPORT Standard_Integer NbAttributes() const;
182
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.
187 //! Exceptions:
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;
191
192 //! Returns True if <me> is a descendant of
193 //! <aLabel>. Attention: every label is its own
194 //! descendant.
195 Standard_EXPORT Standard_Boolean IsDescendant (const TDF_Label& aLabel) const;
196
197 //! Returns the root label Root of the data structure.
198 //! This has a depth of 0.
199 //! Exceptions:
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;
203
204 //! Returns true if this label has at least one child.
205 Standard_Boolean HasChild() const;
206
207 //! Returns the number of children.
208 Standard_EXPORT Standard_Integer NbChildren() const;
209
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.
213 //! Example:
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;
220
221 //! Create a new child label of me using autoamtic
222 //! delivery tags provided by TagSource.
223 TDF_Label NewChild() const;
224
225 //! Returns the current transaction index.
226 Standard_EXPORT Standard_Integer Transaction() const;
227
228 //! Returns true if node address of <me> is lower than
229 //! <otherLabel> one. Used to quickly sort labels (not
230 //! on entry criterion).
231 //!
232 //! -C++: inline
233 Standard_EXPORT Standard_Boolean HasLowerNode (const TDF_Label& otherLabel) const;
234
235 //! Returns true if node address of <me> is greater
236 //! than <otherLabel> one. Used to quickly sort labels
237 //! (not on entry criterion).
238 //!
239 //! -C++: inline
240 Standard_EXPORT Standard_Boolean HasGreaterNode (const TDF_Label& otherLabel) const;
241
242 //! Dumps the minimum information about <me> on
243 //! <aStream>.
244 Standard_EXPORT Standard_OStream& Dump (Standard_OStream& anOS) const;
245Standard_OStream& operator<< (Standard_OStream& anOS) const
246{
247 return Dump(anOS);
248}
249
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;
253
254 //! Dumps the label entry.
255 Standard_EXPORT void EntryDump (Standard_OStream& anOS) const;
256
257
258friend class TDF_ChildIterator;
259friend class TDF_Attribute;
260friend class TDF_AttributeIterator;
261friend class TDF_Data;
42cf5bc1 262
1103eb60 263template<class T>
264friend struct std::hash;
42cf5bc1 265
266protected:
267
268
269
270
271
272private:
273
274
275 //! Reserved to the friends.
276 TDF_Label(const TDF_LabelNodePtr& aNode);
277
278 //! Adds an Attribute to <toNode>. Raises if there is
279 //! already one.
0f3d1d7c 280 Standard_EXPORT void AddToNode (const TDF_LabelNodePtr& toNode, const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append) const;
42cf5bc1 281
282 //! Forgets an Attribute from <fromNode>. Raises if
283 //! the attribute is not in the structure.
284 Standard_EXPORT void ForgetFromNode (const TDF_LabelNodePtr& fromNode, const Handle(TDF_Attribute)& anAttribute) const;
285
286 //! Resumes a forgotten Attribute to <toNode>. Raises
287 //! if the attribute is not in the structure.
288 Standard_EXPORT void ResumeToNode (const TDF_LabelNodePtr& fromNode, const Handle(TDF_Attribute)& anAttribute) const;
289
290 Standard_EXPORT TDF_LabelNodePtr FindOrAddChild (const Standard_Integer aTag, const Standard_Boolean create) const;
291
292 Standard_EXPORT void InternalDump (Standard_OStream& anOS, const TDF_IDFilter& aFilter, TDF_AttributeIndexedMap& aMap, const Standard_Boolean extended) const;
293
294
295 TDF_LabelNodePtr myLabelNode;
296
297
298};
299
300
301#include <TDF_Label.lxx>
302
303
304
305
306
307#endif // _TDF_Label_HeaderFile