869b3f5d6eb034b5e3f104dfb83be9fa9b7df557
[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         polygon: ET.Element = ET.SubElement(placemark, "Polygon")
49         outer_boundary: ET.Element = ET.SubElement(polygon, "outerBoundaryIs")
50         linear_ring: ET.Element = ET.SubElement(outer_boundary, "LinearRing")
51         coordinates: ET.Element = ET.SubElement(linear_ring, "coordinates")
52         points: list[Point] = Hexagon.polygon_corners(self.layout, self.position)
53         points.append(points[0])
54
55         method = GeoLocation(self.geoLocation).point_to_geo_location
56         geo_locations: list[GeoLocation] = map(method, points)
57         text:list[str] = []
58         for geo_location in list(geo_locations):
59             text.append(f"{geo_location.longitude},{geo_location.latitude},{geo_location.aboveMeanSeaLevel}")
60         coordinates.text = " ".join(text)
61         return placemark
62
63     def toSvg(self):
64         return None