src/wcmf/lib/model/visitor/LayoutVisitor.php
private function calculatePosition($obj) {
    $parent = & $obj->getParent();
    if (!$parent) {
      // start here
      $position = new Position(0, 0, 0);
    }
    else {
      $position = new Position(0, 0, 0);
      $parentPos = $this->map[$parent->getOID()];
      $position->y = $parentPos->y + 1;
      $position->z = $parentPos->z + 1;

      $siblings = $parent->getChildren();
      if ($siblings[0]->getOID() == $obj->getOID()) {
        $position->x = $parentPos->x;
      }
      else {
        // find leftmost sibling of object
        for ($i=0; $i<sizeOf($siblings); $i++) {
          if ($siblings[$i]->getOID() == $obj->getOID()) {
            $leftSibling = & $siblings[$i-1];
          }
        }
        // find x-coordinate of rightmost descendant of leftmost sibling
        $maxX = 0;
        $nIter = new NodeIterator($leftSibling);
        foreach($nIter as $oid => $curObject) {
          $curPosition = $this->map[$curObject->getOID()];
          if ($curPosition->x >= $maxX) {
            $maxX = $curPosition->x;
          }
         }
        $position->x = $maxX+2;
        // reposition parents
        while ($parent != null) {
          $this->map[$parent->getOID()]->x += 1;
          $parent = $parent->getParent();
        }
      }
    }
    return $position;
  }
private function calculatePosition($obj) {
    $parent = & $obj->getParent();
    if (!$parent) {
      // start here
      $position = new Position(0, 0, 0);
    }
    else {
      $position = new Position(0, 0, 0);
      $parentPos = $this->map[$parent->getOID()];
      $position->y = $parentPos->y + 1;
      $position->z = $parentPos->z + 1;

      $siblings = $parent->getChildren();
      if ($siblings[0]->getOID() == $obj->getOID()) {
        $position->x = $parentPos->x;
      }
      else {
        // find leftmost sibling of object
        for ($i=0; $i<sizeOf($siblings); $i++) {
          if ($siblings[$i]->getOID() == $obj->getOID()) {
            $leftSibling = & $siblings[$i-1];
          }
        }
        // find x-coordinate of rightmost descendant of leftmost sibling
        $maxX = 0;
        $nIter = new NodeIterator($leftSibling);
        foreach($nIter as $oid => $curObject) {
          $curPosition = $this->map[$curObject->getOID()];
          if ($curPosition->x >= $maxX) {
            $maxX = $curPosition->x;
          }
         }
        $position->x = $maxX+2;
        // reposition parents
        while ($parent != null) {
          $this->map[$parent->getOID()]->x += 1;
          $parent = $parent->getParent();
        }
      }
    }
    return $position;
  }
private function calculatePosition ( $ obj ) { $ parent = & $ obj -> getParent ( ) ; if ( ! $ parent ) { // start here $ position = new Position ( 0 , 0 , 0 ) ; } else { $ position = new Position ( 0 , 0 , 0 ) ; $ parentPos = $ this -> map [ $ parent -> getOID ( ) ] ; $ position -> y = $ parentPos -> y + 1 ; $ position -> z = $ parentPos -> z + 1 ; $ siblings = $ parent -> getChildren ( ) ; if ( $ siblings [ 0 ] -> getOID ( ) == $ obj -> getOID ( ) ) { $ position -> x = $ parentPos -> x ; } else { // find leftmost sibling of object for ( $ i = 0 ; $ i < sizeOf ( $ siblings ) ; $ i ++ ) { if ( $ siblings [ $ i ] -> getOID ( ) == $ obj -> getOID ( ) ) { $ leftSibling = & $ siblings [ $ i - 1 ] ; } } // find x-coordinate of rightmost descendant of leftmost sibling $ maxX = 0 ; $ nIter = new NodeIterator ( $ leftSibling ) ; foreach ( $ nIter as $ oid => $ curObject ) { $ curPosition = $ this -> map [ $ curObject -> getOID ( ) ] ; if ( $ curPosition -> x >= $ maxX ) { $ maxX = $ curPosition -> x ; } } $ position -> x = $ maxX + 2 ; // reposition parents while ( $ parent != null ) { $ this -> map [ $ parent -> getOID ( ) ] -> x += 1 ; $ parent = $ parent -> getParent ( ) ; } } } return $ position ; }
Calculate the object's position using the described algorithm.
@param $obj PersistentObject instance
Calculate the object s position using the described algorithm .