Salome HOME
Support both 5.5 and 5.6 version of ParaView
[modules/gui.git] / src / SUIT / SUIT_DataObjectIterator.cxx
index 2b2869a59a7fbb842ae03d062c83fdb930c7b48a..8028d27914485c70d5b5b6d100e6676182887a05 100644 (file)
@@ -1,9 +1,33 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "SUIT_DataObjectIterator.h"
 
+/*!
+  Constructor.
+*/
 SUIT_DataObjectIterator::SUIT_DataObjectIterator( SUIT_DataObject* root, const int det, const bool fromTrueRoot )
 : myRoot( root ),
-myDetourType( det ),
-myCurrentLevel( 0 )
+myDetourType( det )
 {
   if ( myRoot && fromTrueRoot )
     myRoot = myRoot->root();
@@ -11,6 +35,9 @@ myCurrentLevel( 0 )
   myCurrent = myExtremeChild = myRoot;
 }
 
+/*!
+  Gets parent for object \a obj.
+*/
 SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
 {
   SUIT_DataObject* result = 0;
@@ -19,6 +46,9 @@ SUIT_DataObject* SUIT_DataObjectIterator::parent( SUIT_DataObject* obj ) const
   return result;
 }
 
+/*!
+  Increment operator.
+*/
 void SUIT_DataObjectIterator::operator++()
 {
   SUIT_DataObject* aNext = 0;
@@ -34,7 +64,7 @@ void SUIT_DataObjectIterator::operator++()
       if ( myCurrent->myChildren.count() > 0 )
       {
         myCurrent = extreme( myCurrent->myChildren, myDetourType == DepthLeft );
-        myCurrentLevel++;
+        myChildrenIndexes.append(myDetourType == DepthLeft ? 0 : myCurrent->myChildren.size() - 1);
       }
       else do
       {
@@ -47,18 +77,22 @@ void SUIT_DataObjectIterator::operator++()
         }
         else
         {
-          aParent->myChildren.find( myCurrent );
-          if ( myDetourType == DepthLeft )
-            myCurrent = aParent->myChildren.next();
-          else
-            myCurrent = aParent->myChildren.prev();
-          if ( !myCurrent )
+          int idx = myChildrenIndexes.last();
+          if (myDetourType == DepthLeft && idx < aParent->myChildren.count() - 1) 
           {
-            myCurrent = aParent;
-            myCurrentLevel--;
+            myChildrenIndexes.last()++;
+            myCurrent = aParent->myChildren[idx + 1];
+            exit = true;
           }
-          else
+          else if (myDetourType == DepthRight && idx > 0) 
+          {
+            myChildrenIndexes.last()--;
+            myCurrent = aParent->myChildren[idx - 1];
             exit = true;
+          } else {
+            myCurrent = aParent;
+            myChildrenIndexes.removeLast();
+          }
         }
       }
       while ( !exit );
@@ -76,7 +110,7 @@ void SUIT_DataObjectIterator::operator++()
           {
             myExtremeChild = extreme( cur->myChildren, myDetourType == BreadthLeft );
             myCurrent = myExtremeChild;
-            myCurrentLevel++;
+            myChildrenIndexes.append(myDetourType == BreadthLeft ? 0 : myCurrent->myChildren.size() - 1);
           }
         }
       }
@@ -86,30 +120,42 @@ void SUIT_DataObjectIterator::operator++()
   }
 }
 
+/*!
+  Gets current data object.
+*/
 SUIT_DataObject* SUIT_DataObjectIterator::current() const
 {
   return myCurrent;
 }
 
+/*!
+  Gets depth of current lavel.
+*/
 int SUIT_DataObjectIterator::depth() const
 {
-  return myCurrentLevel;
+  return myChildrenIndexes.size();
 }
 
+/*!
+  Gets detour type.
+*/
 int SUIT_DataObjectIterator::detour() const
 {
   return myDetourType;
 }
 
+/*!
+  Gets global sibling for object \a obj
+*/
 SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, bool next ) const
 {
   SUIT_DataObject* par;
 
   if ( obj && ( par = parent( obj ) ) )
   {
-    par->myChildren.find( obj );
-    if ( par->myChildren.next() )
-      return par->myChildren.current();
+    int idx = par->myChildren.indexOf( obj );
+    if ( idx < par->myChildren.count() - 1 )
+      return par->myChildren[idx + 1];
     else
     {
       for ( ; par; par = globalSibling( par, next ) )
@@ -124,15 +170,21 @@ SUIT_DataObject* SUIT_DataObjectIterator::globalSibling( SUIT_DataObject* obj, b
     return 0;
 }
 
+/*!
+ * Gets first or last data object from list.
+ * Get firls, if \a FromLeft == true, else last.
+ */
 SUIT_DataObject* SUIT_DataObjectIterator::extreme( DataObjectList& aList, bool FromLeft ) const
 {
   if ( FromLeft )
-    return aList.getFirst();
+    return aList.first();
   else
-    return aList.getLast();
+    return aList.last();
 }
 
-
+/*!
+  Constructor.
+*/
 SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* root,
                                                             int start, int end, bool LeftToRight )
 : SUIT_DataObjectIterator( root, LeftToRight ? BreadthLeft : BreadthRight )
@@ -147,6 +199,9 @@ SUIT_DataObjectLevelIterator::SUIT_DataObjectLevelIterator( SUIT_DataObject* roo
     SUIT_DataObjectIterator::operator++();
 }
 
+/*!
+  Increment operator.
+*/
 void SUIT_DataObjectLevelIterator::operator++()
 {
   if ( myCurrent )