1 // File: TDF_LabelNode.cxx
3 // Author: DAUTRY Philippe
4 // <fid@fox.paris1.matra-dtv.fr>
5 // Copyright: Matra Datavision 1997
8 // History: Version Date Purpose
9 // 0.0 Feb 6 1997 Creation
10 // MSV 21.03.2003: protect against stack overflow in destructor
13 #include <TDF_LabelNode.hxx>
15 #include <TDF_Data.hxx>
16 #include <TDF_Label.hxx>
18 //=======================================================================
19 //function : TDF_LabelNode
20 //purpose : Constructor with TDF_Data*, only used for root node.
21 //=======================================================================
23 TDF_LabelNode::TDF_LabelNode
25 : myFather (NULL), // The sign it is the root.
26 #ifdef KEEP_LOCAL_ROOT
29 myBrother ((TDF_LabelNode *)aDataPtr),
32 myLastFoundChild (NULL), //jfa 10.01.2003
33 myTag (0), // Always 0 for root.
35 #ifdef KEEP_LOCAL_ROOT
45 //=======================================================================
46 //function : TDF_LabelNode
47 //purpose : Constructor
48 //=======================================================================
50 TDF_LabelNode::TDF_LabelNode
51 (const Standard_Integer aTag, TDF_LabelNode* aFather)
55 myLastFoundChild (NULL), //jfa 10.01.2003
58 #ifdef KEEP_LOCAL_ROOT
62 if (aFather != NULL) {
63 Depth(aFather->Depth() + 1);
64 #ifdef KEEP_LOCAL_ROOT
65 myData = aFather -> Data();
69 myDebugEntry = myFather->myDebugEntry;
75 //=======================================================================
76 //function : ~TDF_LabelNode
78 //=======================================================================
80 TDF_LabelNode::~TDF_LabelNode()
82 // MSV 21.03.2003: do not delete brother, rather delete all children in a loop
83 // to avoid stack overflow
84 while (myFirstChild != NULL) {
85 TDF_LabelNode* aSecondChild = myFirstChild->Brother();
87 myFirstChild = aSecondChild;
89 myFirstAttribute.Nullify();
90 myLastFoundChild = NULL; //jfa 10.01.2003
93 //=======================================================================
94 //function : AddAttribute
95 //purpose : Adds an attribute at the first or the specified position.
96 //=======================================================================
98 void TDF_LabelNode::AddAttribute
99 (const Handle(TDF_Attribute)& afterAtt,
100 const Handle(TDF_Attribute)& newAtt)
102 newAtt->myFlags = 1; // Valid.
103 newAtt->myLabelNode = this;
104 if (afterAtt.IsNull()) { // Inserts at beginning.
105 newAtt->myNext = myFirstAttribute;
106 myFirstAttribute = newAtt;
108 else { // Inserts at specified place.
109 newAtt->myNext = afterAtt->myNext;
110 afterAtt->myNext = newAtt;
115 //=======================================================================
116 //function : RemoveAttribute
117 //purpose : Removes an attribute from the first or the specified position.
118 //=======================================================================
120 void TDF_LabelNode::RemoveAttribute
121 (const Handle(TDF_Attribute)& afterAtt,
122 const Handle(TDF_Attribute)& oldAtt)
124 oldAtt->myFlags = 0; // Unvalid.
125 oldAtt->myLabelNode = NULL;
126 if (afterAtt.IsNull()) { // Removes from beginning.
127 myFirstAttribute = oldAtt->myNext;
129 else { // Removes from specified place.
130 afterAtt->myNext = oldAtt->myNext;
132 // Nullifier le next induit l'iterateur d'attribut en erreur.
133 //oldAtt->myNext.Nullify();
137 //=======================================================================
138 //function : RootNode
139 //purpose : used for non const object.
140 //=======================================================================
142 TDF_LabelNode* TDF_LabelNode::RootNode ()
144 #ifdef KEEP_LOCAL_ROOT
145 return myData? myData -> myRoot: 0L;
147 TDF_LabelNode* lp = this;
148 while (lp->myFather != NULL) lp = lp->myFather;
154 //=======================================================================
155 //function : RootNode
156 //purpose : used for const object.
157 //=======================================================================
159 const TDF_LabelNode* TDF_LabelNode::RootNode () const
161 #ifdef KEEP_LOCAL_ROOT
162 return myData? myData -> myRoot: 0L;
164 const TDF_LabelNode* lp = this;
165 while (lp->myFather != NULL) lp = lp->myFather;
171 //=======================================================================
174 //=======================================================================
176 TDF_Data * TDF_LabelNode::Data () const
178 #ifdef KEEP_LOCAL_ROOT
181 const TDF_LabelNode* ln = RootNode()->myBrother;
182 return ((TDF_Data*) ln);
187 //=======================================================================
188 //function : AllMayBeModified
190 //=======================================================================
192 void TDF_LabelNode::AllMayBeModified()
194 MayBeModified(Standard_True);
195 if (myFather && !myFather->MayBeModified()) myFather->AllMayBeModified();