5eed9e2894ab110cae9e129f19ac0d73eec2e005
[oam.git] / code / network-topology-instance-generator / model / python / svg / connection_edge_point.py
1 # Copyright 2022 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 Module containing a class representing an SVG Element as Connection Node Edge Point
18 """
19 from typing import Dict
20 from lxml import etree
21 from model.python.svg.svg import Svg
22
23
24 class ConnectionEdgePoint(Svg):
25     """
26     Class representing an SVG Element object as Connection Node Edge Point
27     """
28
29     # overwrite
30     def svg_main(self) -> etree.Element:
31         """
32         Mothod generating the main SVG Element shaping the TAPI object
33         :return SVG Element as main representations for the TAPI object
34         """
35         main = etree.Element("ellipse")
36         main.attrib['cx'] = str(self.center_x())
37         main.attrib['cy'] = str(self.center_y())
38         main.attrib['rx'] = str(2 * self.FONTSIZE)
39         main.attrib['ry'] = str(self.FONTSIZE)
40         main.attrib['class'] = " ".join(
41             [self.type_name(), self.tapi_object().role()])
42         return main
43
44     def svg_label(self) -> etree.Element:
45         label = etree.Element('text')
46         label.attrib['x'] = str(self.center_x())
47         # +4px for font-size 14px (think of chars like 'gjy')
48         label.attrib['y'] = str(self.center_y() + 4)
49         label.text = self.__label_by_protocol(self.tapi_object().protocol())
50         return label
51
52     def __label_by_protocol(self, protocol) -> str:
53         mapping: Dict[str, str] = {
54             "netconf": "NC",
55             "ves": "VES",
56             "file": "FTP",
57             "nas":"NAS",
58             "ofh": "OFH",
59             "radio": "RF",
60             "rest": "REST",
61             "restconf": "RC",
62             "unknown": "-"
63         }
64         search = protocol.split(":")[1]
65         if search in mapping:
66             return mapping[search]
67         return protocol