Salome HOME
Implement level() method for the SUIT_DataObject class
authorvsr <vsr@opencascade.com>
Tue, 28 Jun 2005 09:13:24 +0000 (09:13 +0000)
committervsr <vsr@opencascade.com>
Tue, 28 Jun 2005 09:13:24 +0000 (09:13 +0000)
src/SUIT/SUIT_DataObject.cxx
src/SUIT/SUIT_DataObject.h

index c4f31bb0e0cc4c64f4b47e1a9a1201eb4295ced0..839fffdeef6493e6b2746001863074f9b77e5285 100755 (executable)
@@ -123,6 +123,22 @@ SUIT_DataObject* SUIT_DataObject::childObject( const int idx ) const
   return child;
 }
 
+/*!
+    Returns the level of the object in the data tree.
+    0 means that object is top-level.
+*/
+
+int SUIT_DataObject::level() const
+{
+  int lev = 0;
+  SUIT_DataObject* p = parent();
+  while ( p ) {
+    p = p->parent();
+    lev++;
+  }
+  return lev;
+}
+
 /*!
     Returns the next data object in the child list of the parent.
 */
index cc4cf374c42e06c3cdfa62a8d3a8bf3c0132969b..eef2fb87b594515b3dcbe26720e83f2ea45927b7 100755 (executable)
@@ -36,6 +36,7 @@ public:
   int                         childCount() const;
   int                         childPos( const SUIT_DataObject* ) const;
   SUIT_DataObject*            childObject( const int ) const;
+  int                         level() const;
 
   SUIT_DataObject*            nextBrother() const;
   SUIT_DataObject*            prevBrother() const;