1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/
19 #include "SUIT_DataObjectIterator.h"
24 SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot )
29 if ( myRoot && fromTrueRoot )
30 myRoot = myRoot->root();
32 myCurrent = myExtremeChild = myRoot;
36 Gets parent for object \a obj.
38 SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
40 SUIT_DataObject* result = 0;
41 if ( obj && obj != myRoot )
42 result = obj->parent();
49 void SUIT_DataObjectIterator::operator++()
51 SUIT_DataObject* aNext = 0;
52 SUIT_DataObject* aParent = 0;
58 if ( myDetourType == DepthLeft || myDetourType == DepthRight )
60 //Depth detour algorithm
61 if ( myCurrent->myChildren.count() > 0 )
63 myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft );
69 aParent = parent( myCurrent );
72 myCurrent = 0; //the tree is passed completely
77 aParent->myChildren.find( myCurrent );
78 if ( myDetourType == DepthLeft )
79 myCurrent = aParent->myChildren.next();
81 myCurrent = aParent->myChildren.prev();
93 else if ( myDetourType == BreadthLeft || myDetourType == BreadthRight )
95 //Breadth detour algorithm
96 aNext = globalSibling( myCurrent, myDetourType == BreadthLeft );
100 for ( SUIT_DataObject* cur = myExtremeChild; cur && !myCurrent; cur = globalSibling( cur, myDetourType == BreadthLeft ) )
102 if ( cur->myChildren.count() > 0 )
104 myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft );
105 myCurrent = myExtremeChild;
117 Gets current data object.
119 SUIT_DataObject* SUIT_DataObjectIterator::current() const
125 Gets depth of current lavel.
127 int SUIT_DataObjectIterator::depth() const
129 return myCurrentLevel;
135 int SUIT_DataObjectIterator::detour() const
141 Gets global sibling for object \a obj
143 SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, bool next ) const
145 SUIT_DataObject* par;
147 if ( obj && ( par = parent( obj ) ) )
149 par->myChildren.find( obj );
150 if ( par->myChildren.next() )
151 return par->myChildren.current();
154 for ( ; par; par = globalSibling( par, next ) )
156 if ( par->myChildren.count() > 0 )
157 return extreme( par->myChildren, next );
167 * Gets first or last data object from list.
168 * Get firls, if \a FromLeft == true, else last.
170 SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const
173 return aList.getFirst();
175 return aList.getLast();
181 SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* root,
182 int start, int end, bool LeftToRight )
183 : SUIT_DataObjectIterator( root, LeftToRight ? BreadthLeft : BreadthRight )
185 myStartLevel = start;
189 myEndLevel = myStartLevel;
191 while ( current() && depth() < myStartLevel )
192 SUIT_DataObjectIterator::operator++();
198 void SUIT_DataObjectLevelIterator::operator++()
202 SUIT_DataObjectIterator::operator++();
203 if ( depth() > myEndLevel )