From f40de71d432ef18501481bfd736e82f677953439 Mon Sep 17 00:00:00 2001 From: demx8as6 Date: Tue, 22 Feb 2022 12:53:13 +0100 Subject: [PATCH] Create a script to generate a Topology - add SVG representation for a topology CEP Issue-ID: OAM-249 Change-Id: Ie1d006d2a2e4f4433b3759019d84f885f8af76e3 Signed-off-by: demx8as6 --- .../model/python/svg/connection_edge_point.py | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 code/network-topology-instance-generator/model/python/svg/connection_edge_point.py 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 index 0000000..1c3b634 --- /dev/null +++ b/code/network-topology-instance-generator/model/python/svg/connection_edge_point.py @@ -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 -- 2.16.6