Add Cell representation to Tower in KML
[oam.git] / code / network-generator / model / python / tower.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/usr/bin/python
16
17 """
18 A Class representing a Tower to mount O-RAN RUx
19 """
20 from typing import Any, Dict
21
22 import model.python.hexagon as Hexagon
23 from model.python.hexagon import Hex, Layout, Point
24 from model.python.geo_location import GeoLocation
25
26 from model.python.o_ran_object import IORanObject
27 from model.python.o_ran_node import ORanNode
28 import xml.etree.ElementTree as ET
29
30
31 # Define the "ITower" interface
32 class ITower(IORanObject):
33     def __init__(self, layout: Layout, hex: Hex = None, **kwargs):
34         super().__init__(**kwargs)
35
36
37 # Define an abstract O-RAN Node class
38 class Tower(ORanNode, ITower):
39     def __init__(self, tower_data: ITower = None, **kwargs):
40         super().__init__(tower_data, **kwargs)
41
42     def toKml(self):
43         placemark: ET.Element = ET.Element("Placemark")
44         name: ET.Element = ET.SubElement(placemark, "name")
45         name.text = self.name
46         style: ET.Element = ET.SubElement(placemark, "styleUrl")
47         style.text = "#" + self.__class__.__name__
48         multi_geometry: ET.Element = ET.SubElement(placemark, "MultiGeometry")
49         polygon: ET.Element = ET.SubElement(multi_geometry, "Polygon")
50         outer_boundary: ET.Element = ET.SubElement(polygon, "outerBoundaryIs")
51         linear_ring: ET.Element = ET.SubElement(outer_boundary, "LinearRing")
52         coordinates: ET.Element = ET.SubElement(linear_ring, "coordinates")
53         points: list[Point] = Hexagon.polygon_corners(self.layout, self.position)
54         points.append(points[0])
55         method = GeoLocation(self.geoLocation).point_to_geo_location
56         geo_locations: list[GeoLocation] = list(map(method, points))
57         text: list[str] = []
58         for geo_location in geo_locations:
59             text.append(
60                 f"{geo_location.longitude},{geo_location.latitude},{geo_location.aboveMeanSeaLevel}"
61             )
62         coordinates.text = " ".join(text)
63
64         # cells
65         cell_angle = self.parent.parent.parent.parent.parent.configuration()["pattern"][
66             "o-ran-ru"
67         ]["cell-angle"]
68         for index in range(int(360 / cell_angle)):
69             line: ET.Element = ET.SubElement(multi_geometry, "LineString")
70             tessellate: ET.Element = ET.SubElement(line, "tessellate")
71             tessellate.text = "1"
72             coordinates: ET.Element = ET.SubElement(line, "coordinates")
73             
74             intersect: Point = Point(
75                 points[2 * index].x - points[2 * index + 1].x / 2,
76                 points[2 * index].y - points[2 * index + 1].y / 2,
77             )
78             intersect_geo_location: GeoLocation = GeoLocation(
79                 self.geoLocation
80             ).point_to_geo_location(intersect)
81             text: list[str] = []
82             text.append(
83                 f"{intersect_geo_location.longitude},{intersect_geo_location.latitude},{intersect_geo_location.aboveMeanSeaLevel}"
84             )
85             text.append(
86                 f"{self.geoLocation['longitude']},{self.geoLocation['latitude']},{self.geoLocation['aboveMeanSeaLevel']}"
87             )
88             coordinates.text = " ".join(text)
89
90         return placemark
91
92     def toSvg(self):
93         return None