352 lines
10 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\PlaceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: PlaceRepository::class)]
// #[ORM\MappedSuperclass]
// #[ORM\InheritanceType("JOINED")]
// #[ORM\DiscriminatorColumn(name: "type", type: "string")]
// #[ORM\DiscriminatorMap(["room" => Room::class, "corridor" => Corridor::class])]
class Place
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer")]
private $id;
#[ORM\Column(type: "string")]
// Either 'C'orridor , 'S'tairs , 'E'levator or 'R'oom
private $type;
#[ORM\OneToMany(targetEntity: PlaceName::class, mappedBy: "place")]
private $names;
#[ORM\OneToMany(targetEntity: RoomUserName::class, mappedBy: "place")]
private $users;
#[ORM\ManyToMany(targetEntity: Floor::class, inversedBy: "places")]
private $floors;
#[ORM\ManyToMany(targetEntity: Place::class, inversedBy: "connectedPlaces")]
private $connection;
#[ORM\ManyToMany(targetEntity: Place::class, mappedBy: "connection")]
private $connectedPlaces;
#[ORM\OneToMany(targetEntity: ThreeDObjectFile::class, mappedBy: "place")]
private $ComplexRepresentation;
#[ORM\OneToMany(targetEntity: Polyhedron::class, mappedBy: "place")]
private $PolyhedronRepresentation;
#[ORM\OneToMany(targetEntity: Cylinder::class, mappedBy: "place")]
private $CylinderRepresentation;
#[ORM\OneToMany(targetEntity: PolySurface::class, mappedBy: "place")]
private $PolySurfaceRepresentation;
#[ORM\ManyToOne(targetEntity: Edition::class, inversedBy: "editedPlace")]
private $editions;
public function __construct()
{
$this->connection = new ArrayCollection();
$this->connectedPlaces = new ArrayCollection();
$this->names = new ArrayCollection();
$this->users = new ArrayCollection();
$this->floors = new ArrayCollection();
$this->ComplexRepresentation = new ArrayCollection();
$this->PolyhedronRepresentation = new ArrayCollection();
$this->CylinderRepresentation = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): bool
{
if ($type == 'C' or $type == 'S' or $type == 'E' or $type == 'R') {
$this->type = $type;
return true;
}
return false;
}
/**
* @return Collection<int, self>
*/
public function getNames(): Collection
{
return $this->names;
}
public function addName(self $name): self
{
if (!$this->names->contains($name)) {
$this->names[] = $name;
}
return $this;
}
public function removeName(self $name): self
{
$this->names->removeElement($name);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getRoomUsers(): Collection
{
return $this->users;
}
public function addRoomUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
}
return $this;
}
public function removeRoomUser(self $user): self
{
$this->users->removeElement($user);
return $this;
}
/**
* @return Collection<int, ThreeDObjectFile>
*/
public function getFloors(): Collection
{
return $this->floors;
}
public function addFloor(Floor $floor): self
{
if (!$this->floors->contains($floor)) {
$this->floors[] = $floor;
}
return $this;
}
public function removeFloor(Floor $floor): self
{
$this->floors->removeElement($floor);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getConnection(): Collection
{
return $this->connection;
}
public function addConnection(self $connection): self
{
if (!$this->connection->contains($connection)) {
$this->connection[] = $connection;
}
return $this;
}
public function removeConnection(self $connection): self
{
$this->connection->removeElement($connection);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getConnectedPlaces(): Collection
{
return $this->connectedPlaces;
}
public function addConnectedPlace(self $connectedPlace): self
{
if (!$this->connectedPlaces->contains($connectedPlace)) {
$this->connectedPlaces[] = $connectedPlace;
$connectedPlace->addConnection($this);
}
return $this;
}
public function removeConnectedPlace(self $connectedPlace): self
{
if ($this->connectedPlaces->removeElement($connectedPlace)) {
$connectedPlace->removeConnection($this);
}
return $this;
}
/**
* @return Collection<int, ThreeDObjectFile>
*/
public function getComplexRepresentation(): Collection
{
return $this->ComplexRepresentation;
}
public function addComplexRepresentation(ThreeDObjectFile $complexRepresentation): self
{
if (!$this->ComplexRepresentation->contains($complexRepresentation)) {
$this->ComplexRepresentation[] = $complexRepresentation;
$complexRepresentation->setRoom($this);
}
return $this;
}
public function removeComplexRepresentation(ThreeDObjectFile $complexRepresentation): self
{
if ($this->ComplexRepresentation->removeElement($complexRepresentation)) {
// set the owning side to null (unless already changed)
if ($complexRepresentation->getRoom() === $this) {
$complexRepresentation->setRoom(null);
}
}
return $this;
}
/**
* @return Collection<int, Polyhedron>
*/
public function getPolyhedronRepresentation(): Collection
{
return $this->PolyhedronRepresentation;
}
public function addPolyhedronRepresentation(Polyhedron $polyhedronRepresentation): self
{
if (!$this->PolyhedronRepresentation->contains($polyhedronRepresentation)) {
$this->PolyhedronRepresentation[] = $polyhedronRepresentation;
$polyhedronRepresentation->setRoom($this);
}
return $this;
}
public function removePolyhedronRepresentation(Polyhedron $polyhedronRepresentation): self
{
if ($this->PolyhedronRepresentation->removeElement($polyhedronRepresentation)) {
// set the owning side to null (unless already changed)
if ($polyhedronRepresentation->getRoom() === $this) {
$polyhedronRepresentation->setRoom(null);
}
}
return $this;
}
/**
* @return Collection<int, Cylinder>
*/
public function getCylinderRepresentation(): Collection
{
return $this->CylinderRepresentation;
}
public function addCylinderRepresentation(Cylinder $cylinderRepresentation): self
{
if (!$this->CylinderRepresentation->contains($cylinderRepresentation)) {
$this->CylinderRepresentation[] = $cylinderRepresentation;
$cylinderRepresentation->setPlace($this);
}
return $this;
}
public function removeCylinderRepresentation(Cylinder $cylinderRepresentation): self
{
if ($this->CylinderRepresentation->removeElement($cylinderRepresentation)) {
// set the owning side to null (unless already changed)
if ($cylinderRepresentation->getPlace() === $this) {
$cylinderRepresentation->setPlace(null);
}
}
return $this;
}
/**
* @return Collection<int, PolySurface>
*/
public function getPolySurfaceRepresentation(): Collection
{
return $this->PolySurfaceRepresentation;
}
public function addPolySurfaceRepresentation(PolySurface $polySurfaceRepresentation): self
{
if (!$this->PolySurfaceRepresentation->contains($polySurfaceRepresentation)) {
$this->PolySurfaceRepresentation[] = $polySurfaceRepresentation;
$polySurfaceRepresentation->setPlace($this);
}
return $this;
}
public function removePolySurfaceRepresentation(PolySurface $polySurfaceRepresentation): self
{
if ($this->PolySurfaceRepresentation->removeElement($polySurfaceRepresentation)) {
// set the owning side to null (unless already changed)
if ($polySurfaceRepresentation->getPlace() === $this) {
$polySurfaceRepresentation->setPlace(null);
}
}
return $this;
}
public function getTwoDRepresentation(string $representation, int $alt) : array
{
if ($representation=='Cylinder') {
$rep = $this->getCylinderRepresentation();
if ($rep != null){
$repPoints = $rep->getCylinderbase()->getPolygonpoint(); //Points in repository format
$Points = new ArrayCollection();
foreach ($repPoints as $p) {
$xy=array([$p->getX(), $p->getY()]);
if (!$Points->contains($xy)){
$Points[] = $xy;
}
}
return $Points;
}
}
elseif ($representation=='PolySurface') {
$rep = $this->getPolySurfaceRepresentation();
if ($rep != null){
$repPoints = $rep->getPolysurfaceComponent()->getPolygonpoint(); //Points in repository format
$Points = new ArrayCollection();
foreach ($repPoints as $p) {
$xy=array([$p->getX(), $p->getY()]);
if (!$Points->contains($xy)){
$Points[] = $xy;
}
}
return $Points;
}
}
else {
return null;
}
}
}