예제 #1
0
 /**
  * Draws the layers content on the image
  * @param zibo\library\image\Image $image The image to draw upon
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return null
  */
 public function draw(Image $image, Diagram $diagram)
 {
     $grid = $diagram->getGrid();
     $cellDimension = $grid->getCellDimension();
     $margin = $diagram->getMargin();
     $cellWidth = $cellDimension->getWidth();
     $cellHeight = $cellDimension->getHeight();
     $objects = $grid->getDiagramObjects();
     foreach ($objects as $object) {
         $gridPoint = $object->getGridPoint();
         $drawX = $gridPoint->getX() * $cellWidth + $margin;
         $drawY = $gridPoint->getY() * $cellHeight + $margin;
         $drawPoint = new Point($drawX, $drawY);
         $object->draw($image, $drawPoint);
     }
 }
예제 #2
0
 /**
  * Draws the layers content on the image
  * @param zibo\library\image\Image $image The image to draw upon
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return null
  */
 public function draw(Image $image, Diagram $diagram)
 {
     $grid = $diagram->getGrid();
     $width = $image->getWidth();
     $height = $image->getHeight();
     $cellDimension = $grid->getCellDimension();
     $margin = $diagram->getMargin();
     $cellWidth = $cellDimension->getWidth();
     $cellHeight = $cellDimension->getHeight();
     // take margin into account and go out of the image to start the grid
     $loopX = $loopY = $this->helperLocation - 1;
     $x = $margin;
     while ($x > 0) {
         $x -= $cellWidth;
         $loopX--;
     }
     $y = $margin;
     while ($y > 0) {
         $y -= $cellHeight;
         $loopY--;
     }
     // draw the X-axis
     for (; $x < $width; $x += $cellWidth) {
         $loopX++;
         if ($loopX == $this->helperLocation) {
             $color = $this->helperColor;
             $loopX = 0;
         } else {
             $color = $this->gridColor;
         }
         $image->drawLine(new Point($x, 0), new Point($x, $height), $color);
     }
     // draw the Y-axis
     for (; $y < $height; $y += $cellHeight) {
         $loopY++;
         if ($loopY == $this->helperLocation) {
             $color = $this->helperColor;
             $loopY = 0;
         } else {
             $color = $this->gridColor;
         }
         $image->drawLine(new Point(0, $y), new Point($width, $y), $color);
     }
 }
 /**
  * Draws the layers content on the image
  * @param zibo\library\image\Image $image The image to draw upon
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return null
  */
 public function draw(Image $image, Diagram $diagram)
 {
     $grid = $diagram->getGrid();
     $margin = $diagram->getMargin();
     $cellDimension = $grid->getCellDimension();
     $cellWidth = $cellDimension->getWidth();
     $cellHeight = $cellDimension->getHeight();
     $gridDimension = $grid->getGridDimension();
     $gridWidth = $gridDimension->getWidth();
     $gridHeight = $gridDimension->getHeight();
     for ($x = 0; $x <= $gridWidth; $x++) {
         for ($y = 0; $y <= $gridHeight; $y++) {
             if ($grid->isFree(new Point($x, $y))) {
                 continue;
             }
             $pointX = $x * $cellWidth + $margin;
             $pointY = $y * $cellHeight + $margin;
             $point = new Point($pointX, $pointY);
             $image->fillRectangle($point, $cellDimension, $this->color);
         }
     }
 }
예제 #4
0
 /**
  * Gets the point for the provided id of a diagram object
  * @param string|zibo\library\image\Point $id Id of the diagram object or a point
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return zibo\library\image\Point The provided point or the point of the provided diagram object
  */
 private function getDiagramObjectPoint($id, Diagram $diagram)
 {
     if ($id instanceof Point) {
         return $id;
     }
     $grid = $diagram->getGrid();
     $object = $grid->getDiagramObject($point);
     return $object->getGridPoint();
 }
 /**
  * Gets the actual location of the field in the image and updates the begin and end point of the connection
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return null
  */
 public function preDraw(Diagram $diagram)
 {
     $grid = $diagram->getGrid();
     $beginModel = $grid->getDiagramObject($this->begin);
     $endModel = $grid->getDiagramObject($this->end);
     // Get the field points left or right of the model boxes
     $beginFieldPoint = $beginModel->getFieldPoint($this->beginFieldName);
     $endFieldPoint = $endModel->getFieldPoint($this->endFieldName);
     $beginWidth = $beginModel->getDimension()->getWidth();
     $endWidth = $endModel->getDimension()->getWidth();
     $beginX = $beginFieldPoint->getX();
     $endX = $endFieldPoint->getX();
     $beginIsLeft = true;
     $endIsLeft = true;
     if ($beginX < $endX) {
         if ($beginX + $beginWidth < $endX) {
             $beginX += $beginWidth;
             $beginIsLeft = false;
         }
     } else {
         if ($beginX > $endX + $endWidth) {
             $endX += $endWidth;
             $endIsLeft = false;
         }
     }
     $this->beginPoint = new Point($beginX, $beginFieldPoint->getY());
     $this->endPoint = new Point($endX, $endFieldPoint->getY());
     // Now get a point in the grid 2 cells away from the model box
     $margin = $diagram->getMargin();
     $beginGridPoint = $grid->getGridPoint(new Point($this->beginPoint->getX() - $margin, $this->beginPoint->getY() - $margin));
     $endGridPoint = $grid->getGridPoint(new Point($this->endPoint->getX() - $margin, $this->endPoint->getY() - $margin));
     $beginGridX = $beginGridPoint->getX();
     $beginGridY = $beginGridPoint->getY();
     $endGridX = $endGridPoint->getX();
     $endGridY = $endGridPoint->getY();
     $needsUp = $grid->needsUp($beginGridY, $endGridY);
     if ($needsUp === true) {
         $beginGridY--;
         if ($beginGridY != $endGridY) {
             $endGridY++;
         }
     } elseif ($needsUp === false) {
         $beginGridY++;
         if ($beginGridY != $endGridY) {
             $endGridY--;
         }
     }
     $offset = 2;
     if ($beginIsLeft) {
         $beginGridX -= $offset;
     } else {
         $beginGridX += $offset;
     }
     if ($endIsLeft) {
         $endGridX -= $offset;
     } else {
         $endGridX += $offset;
     }
     $beginGridX = max($beginGridX, -1);
     $beginGridY = max($beginGridY, -1);
     $endGridX = max($endGridX, -1);
     $endGridY = max($endGridY, -1);
     $this->begin = new Point($beginGridX, $beginGridY);
     $this->end = new Point($endGridX, $endGridY);
 }
 /**
  * Sets the diagram for the finder
  * @param zibo\library\diagram\Diagram $diagram The diagram we're drawing
  * @return null
  */
 public function setDiagram(Diagram $diagram)
 {
     $this->diagram = $diagram;
     $this->grid = $diagram->getGrid();
 }