Salome HOME
Minor fix for notebokk access
[modules/kernel.git] / src / DF / DF_ChildIterator.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "DF_ChildIterator.hxx"
21
22 //Constructor
23 DF_ChildIterator::DF_ChildIterator(const DF_Label& theLabel, bool allLevels)
24   :_root(NULL), _current(NULL)
25 {
26   Init(theLabel, allLevels);
27 }
28
29 DF_ChildIterator::DF_ChildIterator()
30   :_root(NULL), _current(NULL)
31 {
32 }
33
34 DF_ChildIterator::~DF_ChildIterator() 
35 {
36   _root = NULL;
37   _current = NULL;
38 }
39
40 //Initializes the iterator
41 void DF_ChildIterator::Init(const DF_Label& theLabel, bool allLevels)
42 {
43   _root = theLabel._node;
44   _allLevels = allLevels;
45   if(_root) _current = _root->_firstChild;
46 }
47
48 //Returns a current Label
49 DF_Label DF_ChildIterator::Value()
50 {
51   return DF_Label(_current);
52 }
53
54 //Returns true if there is a current Label
55 bool DF_ChildIterator::More()
56 {
57   return _current!=0;
58 }
59
60 //Moves to the next Label
61 void DF_ChildIterator::Next()
62 {
63   if(!_allLevels) {
64     _current = _current->_next; //Move to the next brother
65     return;
66   }
67   else {
68     if(_current->_firstChild) { //Go down to the first child
69       _current = _current->_firstChild;
70     }
71     else {
72       if(_current->_next) { //Next Brother
73         _current = _current->_next;
74       }
75       else {
76         if(_current->_father && _current->_father != _root) {
77           DF_LabelNode *father = _current->_father;
78           _current = father->_next;
79           if(!_current) {
80             while(father && father != _root) {
81               father = father->_father;
82               if(father->_next) break;
83             } 
84             if(father == _root) father = NULL;
85             if(father) _current = father->_next;
86             else _current = NULL;
87           }
88         }
89         else {
90           _current = NULL; //We iterate the whole sub tree
91         }
92       }
93     }
94   }
95 }
96