diff --git a/src/Controller/MapApiController.php b/src/Controller/MapApiController.php index 9b6fb41..4c71213 100644 --- a/src/Controller/MapApiController.php +++ b/src/Controller/MapApiController.php @@ -22,29 +22,20 @@ class MapApiController extends AbstractController } #[Route('/map/api/get_floor')] - public function get_floor(FloorRepository $rep, int $id): JsonResponse + public function get_floor(FloorRepository $rep, int $id, string $representation): JsonResponse { $floor = $rep->findFloorById($id); - $corridors = $floor->getCorridors(); - $rooms = array(); - foreach ($corridors as $cor){ - foreach ($cor->getConnectedPlaces() as $place) { - if (($place instanceof Room) and !($rooms->contains($place))) { - $rooms[] = $place; - } - } - } - $jsonCorridors = array(); - $jsonRooms = array(); - foreach ($corridors as $cor){ - $jsonCorridors[] = $this->json([ - 'id' => $cor->getId(), - 'name' => $cor->getName(), - 'type' => $cor->getType() - //'polygon' => $cor->getPolyhedronRepresentation() + $places = $floor->getPlace(); + $jsonPlaces = new ArrayCollection(); + foreach ($places as $place){ + $jsonPlaces[] = $this->json([ + 'id' => $place->getId(), + 'name' => $place->getName(), + 'type' => $place->getType(), + 'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude()) ]); } - return array($jsonCorridors, $jsonRooms); + return $jsonPlaces; } #[Route('/map/api/find_room_by_name')] diff --git a/src/Entity/Floor.php b/src/Entity/Floor.php index 579fd91..e91ea78 100644 --- a/src/Entity/Floor.php +++ b/src/Entity/Floor.php @@ -15,6 +15,10 @@ class Floor #[ORM\Column(type: "integer")] private $id; + #[ORM\Id] + #[ORM\Column(type: "integer")] + private $altitude; + #[ORM\ManyToOne(targetEntity: Building::class, inversedBy: "floors")] #[ORM\JoinColumn(nullable: false)] private $building; @@ -42,6 +46,17 @@ class Floor $this->building = $building; return $this; } + + public function getAltitude(): ?int + { + return $this->altitude; + } + + public function setAltitude(int $altitude): self + { + $this->altitude = $altitude; + return $this; + } /** * @return Collection diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 569d3b3..c3e27f9 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -26,7 +26,6 @@ class Place #[ORM\OneToMany(targetEntity: PlaceName::class, mappedBy: "place")] private $names; - #[ORM\OneToMany(targetEntity: RoomUserName::class, mappedBy: "place")] private $users; @@ -35,10 +34,19 @@ class Place #[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; + + public function __construct() { $this->connection = new ArrayCollection(); @@ -46,6 +54,9 @@ class Place $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 @@ -178,4 +189,162 @@ class Place } return $this; } + + /** + * @return Collection + */ + 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 + */ + 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 + */ + public function getCylinderRepresentation(): Collection + { + return $this->CylinderRepresentation; + } + + public function addCylinderRepresentation(Cylinder $cylinderRepresentation): self + { + if (!$this->CylinderRepresentation->contains($cylinderRepresentation)) { + $this->CylinderRepresentation[] = $cylinderRepresentation; + $cylinderRepresentation->setRoom($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->getRoom() === $this) { + $cylinderRepresentation->setRoom(null); + } + } + + return $this; + } + + + /** + * @return Collection + */ + public function getPolySurfaceRepresentation(): Collection + { + return $this->PolySurfaceRepresentation; + } + + public function addPolySurfaceRepresentation(PolySurface $polySurfaceRepresentation): self + { + if (!$this->PolySurfaceRepresentation->contains($polySurfaceRepresentation)) { + $this->PolySurfaceRepresentation[] = $polySurfaceRepresentation; + $polySurfaceRepresentation->setRoom($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->getRoom() === $this) { + $polySurfaceRepresentation->setRoom(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; + } + } } diff --git a/src/Entity/PolySurface.php b/src/Entity/PolySurface.php index 768d6b0..2aa2c6f 100644 --- a/src/Entity/PolySurface.php +++ b/src/Entity/PolySurface.php @@ -18,7 +18,7 @@ class PolySurface #[ORM\OneToMany(targetEntity: PlaneSurface::class, mappedBy: "polySurface")] private $polysurfaceComponent; - #[ORM\ManyToOne(targetEntity: Place::class)] + #[ORM\ManyToOne(targetEntity: Place::class, inversedBy: "PolySurfaceRepresentation")] private $place; public function __construct() @@ -71,5 +71,5 @@ class PolySurface $this->place = $place; return $this; - } + } } diff --git a/src/Repository/CorridorRepository.php b/src/Repository/CorridorRepository.php deleted file mode 100644 index bfa244f..0000000 --- a/src/Repository/CorridorRepository.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * @method Corridor|null find($id, $lockMode = null, $lockVersion = null) - * @method Corridor|null findOneBy(array $criteria, array $orderBy = null) - * @method Corridor[] findAll() - * @method Corridor[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class CorridorRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Corridor::class); - } - - public function add(Corridor $entity, bool $flush = false): void - { - $this->getEntityManager()->persist($entity); - - if ($flush) { - $this->getEntityManager()->flush(); - } - } - - public function remove(Corridor $entity, bool $flush = false): void - { - $this->getEntityManager()->remove($entity); - - if ($flush) { - $this->getEntityManager()->flush(); - } - } - -// /** -// * @return Corridor[] Returns an array of Corridor objects -// */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('c') -// ->andWhere('c.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('c.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } - -// public function findOneBySomeField($value): ?Corridor -// { -// return $this->createQueryBuilder('c') -// ->andWhere('c.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -} diff --git a/src/Repository/PlaceRepository.php b/src/Repository/PlaceRepository.php index 8924637..ed2e3a3 100644 --- a/src/Repository/PlaceRepository.php +++ b/src/Repository/PlaceRepository.php @@ -40,18 +40,31 @@ class PlaceRepository extends ServiceEntityRepository } /** - * @return Place[] Returns an array of Place objects having connection with Corrido + * @return Place[] Returns an array of Place objects */ - public function findPlaceConnectedTo($value): array - { - return $this->createQueryBuilder('p') - ->andWhere('p.connectedPlace = :val') - ->setParameter('val', $value) - ->orderBy('p.id', 'ASC') - ->getQuery() - ->getResult() - ; - } + public function findPlaceByName(string $name): array + { + return $this->createQueryBuilder('p') + ->andWhere('LOWER(p.name) = :val') + ->setParameter('val', strtolower($name)) + ->orderBy('p.id', 'ASC') + ->getQuery() + ->getResult() + ; + } + /** + * @return Place[] Returns an array of Place objects + */ + public function findPlaceById(int $id): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.id = :val') + ->setParameter('val', $id) + ->orderBy('p.id', 'ASC') + ->getQuery() + ->getResult() + ; + } diff --git a/src/Repository/RoomRepository.php b/src/Repository/RoomRepository.php deleted file mode 100644 index 586eac9..0000000 --- a/src/Repository/RoomRepository.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * @method Room|null find($id, $lockMode = null, $lockVersion = null) - * @method Room|null findOneBy(array $criteria, array $orderBy = null) - * @method Room[] findAll() - * @method Room[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class RoomRepository extends ServiceEntityRepository -{ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, Room::class); - } - - public function add(Room $entity, bool $flush = false): void - { - $this->getEntityManager()->persist($entity); - - if ($flush) { - $this->getEntityManager()->flush(); - } - } - - public function remove(Room $entity, bool $flush = false): void - { - $this->getEntityManager()->remove($entity); - - if ($flush) { - $this->getEntityManager()->flush(); - } - } - - /** - * @return Room[] Returns an array of Room objects - */ - public function findRoomByName(string $name): array - { - return $this->createQueryBuilder('r') - ->andWhere('r.name.lower() = :val') - ->setParameter('val', $name.lower()) - ->orderBy('r.id', 'ASC') - ->getQuery() - ->getResult() - ; - } - /** - * @return Room[] Returns an array of Room objects - */ - public function findRoomById(int $id): array - { - return $this->createQueryBuilder('r') - ->andWhere('r.id = :val') - ->setParameter('val', $id) - ->orderBy('r.id', 'ASC') - ->getQuery() - ->getResult() - ; - } -// public function findOneBySomeField($value): ?Room -// { -// return $this->createQueryBuilder('r') -// ->andWhere('r.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } -}