Reformat files according to template
[oam.git] / code / network-generator / network_generation / model / python / nr_cell_du.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 3GPP new radio cell du (NrCellDu)
19 """
20 import xml.etree.ElementTree as ET
21 from typing import overload
22
23 import network_generation.model.python.hexagon as Hexagon
24 from network_generation.model.python.geo_location import GeoLocation
25 from network_generation.model.python.o_ran_node import ORanNode
26 from network_generation.model.python.o_ran_object import IORanObject
27 from network_generation.model.python.o_ran_termination_point import (
28     ORanTerminationPoint,
29 )
30 from network_generation.model.python.point import Point
31
32
33 # Define the "INrCellDu" interface
34 class INrCellDu(IORanObject):
35     def __init__(self, cell_angel: int, azimuth: int, **kwargs):
36         super().__init__(**kwargs)
37         self._cell_angle = cell_angel
38         self._azimuth = azimuth
39
40
41 # Define an abstract O-RAN Node class
42 class NrCellDu(ORanNode, INrCellDu):
43     def __init__(self, cell_data: INrCellDu = None, **kwargs):
44         super().__init__(cell_data, **kwargs)
45         self._cell_angle = (
46             cell_data["cellAngle"]
47             if cell_data and "cellAngle" in cell_data
48             else 120
49         )
50         self._azimuth = (
51             cell_data["azimuth"] if cell_data and "azimuth" in cell_data else 0
52         )
53
54     @property
55     def termination_points(self) -> list[ORanTerminationPoint]:
56         result: list[ORanTerminationPoint] = super().termination_points
57         result.append(
58             ORanTerminationPoint({"id": self.name, "name": self.name})
59         )
60         return result
61
62     def to_topology_nodes(self) -> list[dict[str, dict]]:
63         # a cell is not a node it is a Termination Point
64         result: list[dict[str, dict]] = []  # super().to_topology_nodes()
65         return result
66
67     def to_topology_links(self) -> list[dict[str, dict]]:
68         # as a cell is not a node, it does not have links
69         result: list[dict[str, dict]] = []  # super().to_topology_links()
70         return result
71
72     def toKml(self) -> ET.Element:
73         placemark: ET.Element = ET.Element("Placemark")
74         name: ET.Element = ET.SubElement(placemark, "name")
75         name.text = self.name
76         style: ET.Element = ET.SubElement(placemark, "styleUrl")
77         style.text = "#" + self.__class__.__name__
78         multi_geometry: ET.Element = ET.SubElement(placemark, "MultiGeometry")
79         polygon: ET.Element = ET.SubElement(multi_geometry, "Polygon")
80         outer_boundary: ET.Element = ET.SubElement(polygon, "outerBoundaryIs")
81         linear_ring: ET.Element = ET.SubElement(outer_boundary, "LinearRing")
82         coordinates: ET.Element = ET.SubElement(linear_ring, "coordinates")
83
84         points: list[Point] = Hexagon.polygon_corners(
85             self.layout, self.position
86         )
87         method = GeoLocation(
88             self.parent.parent.parent.parent.parent.parent.geoLocation
89         ).point_to_geo_location
90         geo_locations: list[GeoLocation] = list(map(method, points))
91         text: list[str] = []
92
93         index: int = 1 + int(self._azimuth / self._cell_angle)
94         network_center: GeoLocation = GeoLocation(
95             self.parent.parent.parent.parent.parent.parent.geoLocation
96         )
97
98         intersect1: Point = Point(
99             (points[(2 * index + 1) % 6].x + points[(2 * index + 2) % 6].x)
100             / 2,
101             (points[(2 * index + 1) % 6].y + points[(2 * index + 2) % 6].y)
102             / 2,
103         )
104         intersect_geo_location1: GeoLocation = (
105             network_center.point_to_geo_location(intersect1)
106         )
107
108         intersect2: Point = Point(
109             (points[(2 * index + 3) % 6].x + points[(2 * index + 4) % 6].x)
110             / 2,
111             (points[(2 * index + 3) % 6].y + points[(2 * index + 4) % 6].y)
112             / 2,
113         )
114         intersect_geo_location2: GeoLocation = (
115             network_center.point_to_geo_location(intersect2)
116         )
117
118         tower: GeoLocation = GeoLocation(self.geoLocation)
119
120         cell_polygon: list[GeoLocation] = []
121         cell_polygon.append(tower)
122         cell_polygon.append(intersect_geo_location1)
123         cell_polygon.append(geo_locations[(2 * index + 2) % 6])
124         cell_polygon.append(geo_locations[(2 * index + 3) % 6])
125         cell_polygon.append(intersect_geo_location2)
126         # close polygon
127         cell_polygon.append(tower)
128
129         for geo_location in cell_polygon:
130             text.append(
131                 f"{'%.6f' % geo_location.longitude},{'%.6f' % geo_location.latitude},{'%.6f' % geo_location.aboveMeanSeaLevel}"
132             )
133         coordinates.text = " ".join(text)
134
135         return placemark
136
137     def toSvg(self) -> None:
138         return None