1 // Created by: DAUTRY Philippe
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #include <TDF_LabelNode.hxx>
22 #include <TDF_Data.hxx>
23 #include <TDF_Label.hxx>
25 //=======================================================================
26 //function : TDF_LabelNode
27 //purpose : Constructor with TDF_Data*, only used for root node.
28 //=======================================================================
30 TDF_LabelNode::TDF_LabelNode
32 : myFather (NULL), // The sign it is the root.
33 #ifdef KEEP_LOCAL_ROOT
36 myBrother ((TDF_LabelNode *)aDataPtr),
39 myLastFoundChild (NULL), //jfa 10.01.2003
40 myTag (0), // Always 0 for root.
42 #ifdef KEEP_LOCAL_ROOT
52 //=======================================================================
53 //function : TDF_LabelNode
54 //purpose : Constructor
55 //=======================================================================
57 TDF_LabelNode::TDF_LabelNode
58 (const Standard_Integer aTag, TDF_LabelNode* aFather)
62 myLastFoundChild (NULL), //jfa 10.01.2003
65 #ifdef KEEP_LOCAL_ROOT
69 if (aFather != NULL) {
70 Depth(aFather->Depth() + 1);
71 #ifdef KEEP_LOCAL_ROOT
72 myData = aFather -> Data();
76 myDebugEntry = myFather->myDebugEntry;
82 //=======================================================================
85 //=======================================================================
87 void TDF_LabelNode::Destroy (const TDF_HAllocator& theAllocator)
89 // MSV 21.03.2003: do not delete brother, rather delete all children in a loop
90 // to avoid stack overflow
91 while (myFirstChild != NULL) {
92 TDF_LabelNode* aSecondChild = myFirstChild->Brother();
93 myFirstChild->Destroy (theAllocator);
94 myFirstChild = aSecondChild;
96 myFirstAttribute.Nullify();
97 myFather = myBrother = myFirstChild = myLastFoundChild = NULL;
100 // deallocate memory (does nothing for IncAllocator)
101 theAllocator->Free (this);
104 //=======================================================================
105 //function : AddAttribute
106 //purpose : Adds an attribute at the first or the specified position.
107 //=======================================================================
109 void TDF_LabelNode::AddAttribute
110 (const Handle(TDF_Attribute)& afterAtt,
111 const Handle(TDF_Attribute)& newAtt)
113 newAtt->myFlags = 1; // Valid.
114 newAtt->myLabelNode = this;
115 if (afterAtt.IsNull()) { // Inserts at beginning.
116 newAtt->myNext = myFirstAttribute;
117 myFirstAttribute = newAtt;
119 else { // Inserts at specified place.
120 newAtt->myNext = afterAtt->myNext;
121 afterAtt->myNext = newAtt;
126 //=======================================================================
127 //function : RemoveAttribute
128 //purpose : Removes an attribute from the first or the specified position.
129 //=======================================================================
131 void TDF_LabelNode::RemoveAttribute
132 (const Handle(TDF_Attribute)& afterAtt,
133 const Handle(TDF_Attribute)& oldAtt)
135 oldAtt->myFlags = 0; // Unvalid.
136 oldAtt->myLabelNode = NULL;
137 if (afterAtt.IsNull()) { // Removes from beginning.
138 myFirstAttribute = oldAtt->myNext;
140 else { // Removes from specified place.
141 afterAtt->myNext = oldAtt->myNext;
143 // Nullifier le next induit l'iterateur d'attribut en erreur.
144 //oldAtt->myNext.Nullify();
148 //=======================================================================
149 //function : RootNode
150 //purpose : used for non const object.
151 //=======================================================================
153 TDF_LabelNode* TDF_LabelNode::RootNode ()
155 #ifdef KEEP_LOCAL_ROOT
156 return myData? myData -> myRoot: 0L;
158 TDF_LabelNode* lp = this;
159 while (lp->myFather != NULL) lp = lp->myFather;
165 //=======================================================================
166 //function : RootNode
167 //purpose : used for const object.
168 //=======================================================================
170 const TDF_LabelNode* TDF_LabelNode::RootNode () const
172 #ifdef KEEP_LOCAL_ROOT
173 return myData? myData -> myRoot: 0L;
175 const TDF_LabelNode* lp = this;
176 while (lp->myFather != NULL) lp = lp->myFather;
182 //=======================================================================
185 //=======================================================================
187 TDF_Data * TDF_LabelNode::Data () const
189 #ifdef KEEP_LOCAL_ROOT
192 const TDF_LabelNode* ln = RootNode()->myBrother;
193 return ((TDF_Data*) ln);
198 //=======================================================================
199 //function : AllMayBeModified
201 //=======================================================================
203 void TDF_LabelNode::AllMayBeModified()
205 MayBeModified(Standard_True);
206 if (myFather && !myFather->MayBeModified()) myFather->AllMayBeModified();