예제 #1
0
 /**
  * Draws text on the image
  * @param Point $leftTop Point of the upper left corner
  * @param Color $color
  * @param string $text
  * @return null
  */
 public function drawText(Point $leftTop, Color $color, $text)
 {
     $color = $this->allocateColor($color);
     imageString($this->resource, 2, $leftTop->getX(), $leftTop->getY(), $text, $color);
 }
예제 #2
0
 /**
  * Checks if this node points to the same point as the provided node
  * @return boolean True if both nodes have the same point, false otherwise
  */
 public function equals(Node $node)
 {
     return $this->point->equals($node->point);
 }
 /**
  * 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);
 }
 /**
  * Draws the object on the provided image
  * @param zibo\library\image\Image $image The image to draw upon
  * @param zibo\library\image\Point $point The top left corner to start drawing
  * @return null
  */
 public function draw(Image $image, Point $point)
 {
     $x = $point->getX();
     $y = $point->getY();
     $width = $this->dimension->getWidth();
     $height = $this->dimension->getHeight();
     $textX = $x + $this->paddingLeft;
     // draw the box
     $image->fillRoundedRectangle($point, $this->dimension, 3, $this->backgroundColor);
     $image->drawRoundedRectangle($point, $this->dimension, 3, $this->frontColor);
     // draw the title bar
     $title = $this->meta->getName();
     // . ($this->isLinkModel ? ' (L)' : '');
     $image->drawText(new Point($textX, $point->getY() + $this->paddingTop), $this->frontColor, $title);
     $lineY = $y + 2 * $this->paddingTop + self::CHARACTER_HEIGHT + $this->paddingBottom;
     $image->drawLine(new Point($x, $lineY), new Point($x + $width, $lineY), $this->frontColor);
     // draw the fields
     $fieldY = $lineY + $this->paddingTop;
     $fields = $this->meta->getFields();
     foreach ($fields as $fieldName => $field) {
         $label = '+ ' . $field->getName() . ': ' . $this->getFieldType($field);
         $this->fieldPoints[$fieldName] = new Point($x, ceil($fieldY + $this->paddingTop + 1));
         $image->drawText(new Point($textX, $fieldY), $this->frontColor, $label);
         $fieldY += $this->paddingTop + self::CHARACTER_HEIGHT;
     }
 }
예제 #5
0
 /**
  * Checks of the provided object can be placed on the provided x and y coordinates
  * @param DiagramObject $object Object to check
  * @param zibo\library\image\Point The top left point in the grid for the object
  * @return boolean True if the object can be placed on the provided point, false otherwise
  */
 public function isFreeForDiagramObject(DiagramObject $object, Point $point)
 {
     $dimension = $object->getDimension();
     $x = $point->getX();
     $y = $point->getY();
     $margin = 2 * $this->objectMargin;
     $cellsX = ceil($dimension->getWidth() / $this->cellDimension->getWidth()) + $margin;
     $cellsY = ceil($dimension->getHeight() / $this->cellDimension->getHeight()) + $margin;
     for ($i = 0; $i < $cellsX; $i++) {
         $loopX = $i + $x - $this->objectMargin;
         if (!array_key_exists('' . $loopX, $this->grid)) {
             continue;
         }
         for ($j = 0; $j < $cellsY; $j++) {
             $loopY = $j + $y - $this->objectMargin;
             if (!array_key_exists('' . $loopY, $this->grid[$loopX])) {
                 continue;
             }
             if ($this->grid[$loopX][$loopY]) {
                 throw new DiagramException('Could not set diagram object ' . $object->getId() . ' to ' . $point . ': (' . $loopX . ', ' . $loopY . ') is occupied by ' . $this->grid[$loopX][$loopY]);
                 return false;
             }
         }
     }
     return true;
 }