Create a script to generate a Topology 22/7822/2
authordemx8as6 <martin.skorupski@highstreet-technologies.com>
Tue, 22 Feb 2022 11:53:13 +0000 (12:53 +0100)
committerMartin Skorupski <martin.skorupski@highstreet-technologies.com>
Thu, 24 Feb 2022 09:12:15 +0000 (09:12 +0000)
- add SVG representation for a topology CEP

Issue-ID: OAM-249
Change-Id: Ie1d006d2a2e4f4433b3759019d84f885f8af76e3
Signed-off-by: demx8as6 <martin.skorupski@highstreet-technologies.com>
code/network-topology-instance-generator/model/python/svg/connection_edge_point.py [new file with mode: 0644]

diff --git a/code/network-topology-instance-generator/model/python/svg/connection_edge_point.py b/code/network-topology-instance-generator/model/python/svg/connection_edge_point.py
new file mode 100644 (file)
index 0000000..1c3b634
--- /dev/null
@@ -0,0 +1,65 @@
+# Copyright 2022 highstreet technologies GmbH
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#!/usr/bin/python
+"""
+Module containing a class representing an SVG Element as Connection Node Edge Point
+"""
+from typing import Dict
+from lxml import etree
+from model.python.svg.svg import Svg
+
+
+class ConnectionEdgePoint(Svg):
+    """
+    Class representing an SVG Element object as Connection Node Edge Point
+    """
+
+    # overwrite
+    def svg_main(self) -> etree.Element:
+        """
+        Mothod generating the main SVG Element shaping the TAPI object
+        :return SVG Element as main representations for the TAPI object
+        """
+        main = etree.Element("ellipse")
+        main.attrib['cx'] = str(self.center_x())
+        main.attrib['cy'] = str(self.center_y())
+        main.attrib['rx'] = str(2 * self.FONTSIZE)
+        main.attrib['ry'] = str(self.FONTSIZE)
+        main.attrib['class'] = " ".join(
+            [self.type_name(), self.tapi_object().role()])
+        return main
+
+    def svg_label(self) -> etree.Element:
+        label = etree.Element('text')
+        label.attrib['x'] = str(self.center_x())
+        # +4px for font-size 14px (think of chars like 'gjy')
+        label.attrib['y'] = str(self.center_y() + 4)
+        label.text = self.__label_by_protocol(self.tapi_object().protocol())
+        return label
+
+    def __label_by_protocol(self, protocol) -> str:
+        mapping: Dict[str, str] = {
+            "netconf": "NC",
+            "ves": "VES",
+            "file": "FTP",
+            "ofh": "OFH",
+            "rest": "REST",
+            "restconf": "RC",
+            "unknown": "-"
+        }
+        search = protocol.split(":")[1]
+        if search in mapping:
+            return mapping[search]
+        return protocol