a28909db3387721d22ed4301eca3fccd2c71104d
[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 import model.python.hexagon as Hexagon
21 from model.python.point import Point
22 from model.python.geo_location import GeoLocation
23 from model.python.o_ran_node import ORanNode
24 import xml.etree.ElementTree as ET
25
26
27 # Define an abstract O-RAN Node class
28 class Tower(ORanNode):
29     # def __init__(self, **kwargs):
30     #     super().__init__(**kwargs)
31
32     def toKml(self) -> ET.Element:
33         placemark: ET.Element = ET.Element("Placemark")
34         name: ET.Element = ET.SubElement(placemark, "name")
35         name.text = self.name
36         style: ET.Element = ET.SubElement(placemark, "styleUrl")
37         style.text = "#" + self.__class__.__name__
38         multi_geometry: ET.Element = ET.SubElement(placemark, "MultiGeometry")
39         polygon: ET.Element = ET.SubElement(multi_geometry, "Polygon")
40         outer_boundary: ET.Element = ET.SubElement(polygon, "outerBoundaryIs")
41         linear_ring: ET.Element = ET.SubElement(outer_boundary, "LinearRing")
42         coordinates: ET.Element = ET.SubElement(linear_ring, "coordinates")
43
44         points: list[Point] = Hexagon.polygon_corners(self.layout, self.position)
45         points.append(points[0])
46         method = GeoLocation(
47             self.parent.parent.parent.parent.geoLocation
48         ).point_to_geo_location
49         geo_locations: list[GeoLocation] = list(map(method, points))
50         text: list[str] = []
51         for geo_location in geo_locations:
52             text.append(
53                 f"{geo_location.longitude},{geo_location.latitude},{geo_location.aboveMeanSeaLevel}"
54             )
55         coordinates.text = " ".join(text)
56
57         # cells
58         cell_angle = self.parent.parent.parent.parent.parent.configuration()["pattern"]["nr-cell-du"]["cell-angle"]
59         for index in range(int(360 / cell_angle)):
60             line: ET.Element = ET.SubElement(multi_geometry, "LineString")
61             tessellate: ET.Element = ET.SubElement(line, "tessellate")
62             tessellate.text = "1"
63             coordinates: ET.Element = ET.SubElement(line, "coordinates")
64
65             intersect: Point = Point(
66                 (points[2 * index+2].x + points[2 * index + 1].x) / 2,
67                 (points[2 * index+2].y + points[2 * index + 1].y) / 2,
68             )
69             intersect_geo_location: GeoLocation = GeoLocation(
70                 self.parent.parent.parent.parent.geoLocation
71             ).point_to_geo_location(intersect)
72             text: list[str] = []
73             text.append(
74                 f"{intersect_geo_location.longitude},{intersect_geo_location.latitude},{intersect_geo_location.aboveMeanSeaLevel}"
75             )
76             text.append(
77                 f"{self.geoLocation['longitude']},{self.geoLocation['latitude']},{self.geoLocation['aboveMeanSeaLevel']}"
78             )
79             coordinates.text = " ".join(text)
80
81         return placemark
82
83     def toSvg(self) -> None:
84         return None