<?php
class entidad_img {
var $imagen;
var $posx;
var $posy;
var $ancho;
var $alto;
var $url;
var $texto;
var $factor_texto;
var $lineas_texto;
var $nombre_relacion;
var $obj_relaciones;
function entidad_img($imagen,$x="",$y="") {
$this->imagen=$imagen;
$this->posx=$x;
$this->posy=$y;
$this->factor_texto=14;
$this->alto=20;
}
/**
* @param entidad_img2 $objeto_destino
* @desc Agrega un objeto a un vector de relaciones
*/
function agregar_relacion($objeto_destino,$descripcion=""){
$this->obj_relaciones [] =$objeto_destino;
$this->nombre_relacion [] =$descripcion;
return TRUE;
}
/**
* @desc Grafica la entidad en el lienzo
*/
function graficar_entidad(){
$back = ImageColorAllocate($this->imagen,235,245,246);
$fill = ImageColorAllocate($this->imagen,100,81,150);
$this->ancho= strlen($this->texto)*$this->factor_texto;
ImageFilledRectangle($this->imagen,$this->posx,$this->posy,$this->posx+$this->ancho+1,$this->posy+$this->alto+1,$fill);
ImageFilledRectangle($this->imagen,$this->posx+1,$this->posy+1,$this->posx+$this->ancho,$this->posy+$this->alto,$back);
// el borde
imagefilledellipse ($this->imagen,$this->posx,$this->posy+($this->alto/2),15,$this->alto,$back);
imagefilledarc ($this->imagen,$this->posx,$this->posy+($this->alto/2),15,$this->alto,100,280,$fill,IMG_ARC_NOFILL);
imagefilledellipse ($this->imagen,$this->posx+$this->ancho,$this->posy+($this->alto/2),15,$this->alto,$back);
imagefilledarc ($this->imagen,$this->posx+$this->ancho,$this->posy+($this->alto/2)+1,15,$this->alto,280,100,$fill,IMG_ARC_NOFILL);
$centro_texto=$this->posx+($this->ancho/2)- round(strlen($this->texto)/2*10);
imagettftext($this->imagen,12,0,2+$centro_texto,$this->posy+15,56,"fuentes/tahoma.ttf",$this->texto);
}
/**
* @desc Grafica las Relaciones del obejeto en el lienzo
*/
function graficar_relaciones(){
for ($i=0;$i<count($this->obj_relaciones);$i++){
$desface_angulo=0;
if ($this->posx<$this->obj_relaciones[$i]->posx){
$inicio_x= $this->posx+$this->ancho;
$desface_angulo=pi();
$fin_x= $this->obj_relaciones[$i]->posx;
}else{
$inicio_x= $this->posx;
$fin_x= $this->obj_relaciones[$i]->posx+strlen($this->obj_relaciones[$i]->texto)*$this->factor_texto;
}
if ($this->posy<$this->obj_relaciones[$i]->posy){
$inicio_y= $this->posy+$this->alto;
$fin_y= $this->obj_relaciones[$i]->posy;
}else{
$inicio_y= $this->posy;
$fin_y= $this->obj_relaciones[$i]->posy+$this->alto;
//$desface_angulo=pi();
}
imageline($this->imagen,$inicio_x,$inicio_y,$fin_x,$fin_y,2);
// Pinta la punta
//imagefilledellipse($this->imagen, $fin_x, $fin_y, 7, 7, 15);
$pendiente=($fin_y-$inicio_y)/($fin_x-$inicio_x);
$angulo1=atan ($pendiente);
$angulo2=$angulo1+$desface_angulo;
$nuevo_puntox1=round($fin_x+ (10*cos($angulo2+(pi()/8)))); #300
$nuevo_puntoy1=round($fin_y+ (10*sin($angulo2+(pi()/8)))); #305
$nuevo_puntox2=round($fin_x+ (10*cos($angulo2-(pi()/8)))); #300
$nuevo_puntoy2=round($fin_y+ (10*sin($angulo2-(pi()/8)))); #305
$puntos[0] = $fin_x;
$puntos[1] = $fin_y;
$puntos[2] = $nuevo_puntox1;
$puntos[3] = $nuevo_puntoy1;
$puntos[4] = $nuevo_puntox2;
$puntos[5] = $nuevo_puntoy2;
imagefilledpolygon ($this->imagen,$puntos,3,2);
$pendiente=($fin_y-$inicio_y)/($fin_x-$inicio_x);
// Escribe el nombre de la relacion
$relacion_x=$inicio_x+(($fin_x-$inicio_x)/2);
$relacion_Y=$inicio_y+($relacion_x-$inicio_x)*$pendiente;
imagettftext($this->imagen,8,0,$relacion_x,$relacion_Y,56,"fuentes/tahoma.ttf",$this->nombre_relacion[$i]);
}
}
}