Create a script to generate a Topology
[oam.git] / code / network-topology-instance-generator / model / python / svg / node.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 lxml import etree
20 from model.python.svg.connection_edge_point import ConnectionEdgePoint
21 from model.python.svg.svg import Svg
22
23 class Node(Svg):
24     """
25     Class representing an SVG Element object as Connection Node Edge Point
26     """
27     
28     def label(self) -> str:
29         """
30         Getter for the short label as displayed of the SVG Element
31         :return Label of the TAPI object
32         """
33         self.__label = self.tapi_object().function_label()
34         return self.__label
35
36     def height(self) -> int:
37         """
38         Getter for height of the SVG Element
39         :return Height in pixel
40         """
41         self.__height = 1*ConnectionEdgePoint.width(self) 
42         return self.__height
43
44     # overwrite
45     def svg_main(self) -> etree.Element:
46         """
47         Mothod generating the main SVG Element shaping the TAPI object
48         :return SVG Element as main representations for the TAPI object
49         """
50         main = super().svg_main()
51         main = etree.Element("rect")
52         main.attrib["x"] = str(int(self.center_x() - self.width()/2))
53         main.attrib["y"] = str(int(self.center_y() - self.height()/2))
54         main.attrib["width"] = str(self.width())
55         main.attrib["height"] = str(self.height())
56         main.attrib["rx"] = str(int(self.FONTSIZE / 2))
57         main.attrib['class'] = " ".join(
58             ["node", self.type_name(), self.tapi_object().function_label().lower()])
59         return main