b311480e |
1 | // Created by: DAUTRY Philippe |
2 | // Copyright (c) 1997-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // ---------------------- |
7fd59977 |
17 | // Version: 0.0 |
b311480e |
18 | //Version Date Purpose |
7fd59977 |
19 | // 0.0 Feb 7 1997 Creation |
20 | |
42cf5bc1 |
21 | #include <TDF_ChildIterator.hxx> |
7fd59977 |
22 | #include <TDF_Label.hxx> |
23 | #include <TDF_LabelNode.hxx> |
24 | #include <TDF_LabelNodePtr.hxx> |
25 | |
26 | #define ChildIterator_UpToBrother \ |
27 | { \ |
28 | while (myNode && (myNode->Depth() > myFirstLevel) && !myNode->Brother()) \ |
29 | myNode = myNode->Father(); \ |
30 | if (myNode && (myNode->Depth() > myFirstLevel) && myNode->Father()) \ |
31 | myNode = myNode->Brother(); \ |
32 | else \ |
33 | myNode = NULL; \ |
34 | } |
35 | |
36 | |
37 | //======================================================================= |
38 | //function : TDF_ChildIterator |
39 | //purpose : |
40 | //======================================================================= |
41 | |
42 | TDF_ChildIterator::TDF_ChildIterator() |
43 | : myNode(NULL), |
44 | myFirstLevel(0) |
45 | {} |
46 | |
47 | |
48 | //======================================================================= |
49 | //function : TDF_ChildIterator |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | TDF_ChildIterator::TDF_ChildIterator |
54 | (const TDF_Label& aLabel, |
55 | const Standard_Boolean allLevels) |
56 | : myNode(aLabel.myLabelNode->FirstChild()), |
57 | myFirstLevel(allLevels ? aLabel.Depth() : -1) |
58 | {} |
59 | |
60 | |
61 | //======================================================================= |
62 | //function : Initialize |
63 | //purpose : |
64 | //======================================================================= |
65 | |
66 | void TDF_ChildIterator::Initialize |
67 | (const TDF_Label& aLabel, |
68 | const Standard_Boolean allLevels) |
69 | { |
70 | myNode = aLabel.myLabelNode->FirstChild(); |
71 | myFirstLevel = allLevels ? aLabel.Depth() : -1; |
72 | } |
73 | |
74 | |
75 | //======================================================================= |
76 | //function : Next |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | void TDF_ChildIterator::Next() |
81 | { |
82 | if (myFirstLevel == -1) { |
83 | myNode = myNode->Brother(); |
84 | } |
85 | else { |
86 | if (myNode->FirstChild()) myNode = myNode->FirstChild(); |
87 | else ChildIterator_UpToBrother; |
88 | } |
89 | } |
90 | |
91 | |
92 | //======================================================================= |
93 | //function : NextBrother |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | void TDF_ChildIterator::NextBrother() |
98 | { |
99 | if ((myFirstLevel == -1) || myNode->Brother()) myNode = myNode->Brother(); |
100 | else ChildIterator_UpToBrother; |
101 | } |