1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "SUIT_DataObjectIterator.h"
27 SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot )
32 if ( myRoot && fromTrueRoot )
33 myRoot = myRoot->root();
35 myCurrent = myExtremeChild = myRoot;
39 Gets parent for object \a obj.
41 SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
43 SUIT_DataObject* result = 0;
44 if ( obj && obj != myRoot )
45 result = obj->parent();
52 void SUIT_DataObjectIterator::operator++()
54 SUIT_DataObject* aNext = 0;
55 SUIT_DataObject* aParent = 0;
61 if ( myDetourType == DepthLeft || myDetourType == DepthRight )
63 //Depth detour algorithm
64 if ( myCurrent->myChildren.count() > 0 )
66 myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft );
72 aParent = parent( myCurrent );
75 myCurrent = 0; //the tree is passed completely
80 int idx = aParent->myChildren.indexOf( myCurrent );
81 if ( myDetourType == DepthLeft )
82 myCurrent = idx < aParent->myChildren.count() - 1 ? aParent->myChildren[idx + 1] : 0;
84 myCurrent = idx > 0 ? aParent->myChildren[idx - 1] : 0;
96 else if ( myDetourType == BreadthLeft || myDetourType == BreadthRight )
98 //Breadth detour algorithm
99 aNext = globalSibling( myCurrent, myDetourType == BreadthLeft );
103 for ( SUIT_DataObject* cur = myExtremeChild; cur && !myCurrent; cur = globalSibling( cur, myDetourType == BreadthLeft ) )
105 if ( cur->myChildren.count() > 0 )
107 myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft );
108 myCurrent = myExtremeChild;
120 Gets current data object.
122 SUIT_DataObject* SUIT_DataObjectIterator::current() const
128 Gets depth of current lavel.
130 int SUIT_DataObjectIterator::depth() const
132 return myCurrentLevel;
138 int SUIT_DataObjectIterator::detour() const
144 Gets global sibling for object \a obj
146 SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, bool next ) const
148 SUIT_DataObject* par;
150 if ( obj && ( par = parent( obj ) ) )
152 int idx = par->myChildren.indexOf( obj );
153 if ( idx < par->myChildren.count() - 1 )
154 return par->myChildren[idx + 1];
157 for ( ; par; par = globalSibling( par, next ) )
159 if ( par->myChildren.count() > 0 )
160 return extreme( par->myChildren, next );
170 * Gets first or last data object from list.
171 * Get firls, if \a FromLeft == true, else last.
173 SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const
176 return aList.first();
184 SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* root,
185 int start, int end, bool LeftToRight )
186 : SUIT_DataObjectIterator( root, LeftToRight ? BreadthLeft : BreadthRight )
188 myStartLevel = start;
192 myEndLevel = myStartLevel;
194 while ( current() && depth() < myStartLevel )
195 SUIT_DataObjectIterator::operator++();
201 void SUIT_DataObjectLevelIterator::operator++()
205 SUIT_DataObjectIterator::operator++();
206 if ( depth() > myEndLevel )