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