From 5ea2f5548a963cea88ff8c7e21800e1e0b835be7 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Fri, 14 Jul 2023 16:45:24 +0200 Subject: [PATCH] poor_mans_visualisation: Add a topo-v3 dumb visualiser Now we can see something. It does not do anything, but uses topo-v3. Is that progress? :-) --- poor_mans_visualisation.py | 68 ++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/poor_mans_visualisation.py b/poor_mans_visualisation.py index 7965f92..d9cae1f 100755 --- a/poor_mans_visualisation.py +++ b/poor_mans_visualisation.py @@ -13,7 +13,7 @@ if len(sys.argv) > 1: ref_topo = OspfFileTopologyProvider(ref_topo_file).get_topology() try: - cur_topo = BirdSocketTopologyProvider(instance='ospfv2', area=1).get_topology() + cur_topo = BirdSocketTopologyProvider(instance='ospf1', area=0).get_topology() except OSError as e: raise NotImplementedError('Cannot create a mock topology atm') from e @@ -50,37 +50,61 @@ for ann_id in annotators: # Show it -from birdvisu.visualisation import annotators -from birdvisu import maps_new +#from birdvisu.visualisation import annotators +#from birdvisu import maps_new # annotators.create_qgritems does not like being run without Qt initialization. from PySide6 import QtCore, QtGui, QtWidgets app = QtWidgets.QApplication([]) -annotated_topology = maps_new.annotate_topology(combined_topology, - # A semi-canonical set of annotators: - [ - annotators.extract_positions, - annotators.random_position, - annotators.assign_brushes, - annotators.create_qgritems, - ] - ) - +#annotated_topology = maps_new.annotate_topology(combined_topology, +# # A semi-canonical set of annotators: +# [ +# annotators.extract_positions, +# annotators.random_position, +# annotators.assign_brushes, +# annotators.create_qgritems, +# ] +# ) + +from random import randint + +shapes = dict() +for k, v in annot_topo.topology.vertices.items(): + size = 30 if k.is_router else 10 + x, y = randint(0, 1920), randint(0, 1080) + shape = QtWidgets.QGraphicsRectItem(-size/2, -size/2, size, size) + shape.setPos(x,y) + # TODO:brush + label_text = str(IPv4Address(k.router_id)) if k.is_router else str(k.address) # Surprisingly works for all the possible addresses. + label = QtWidgets.QGraphicsSimpleTextItem(label_text, parent=shape) + label.setY(size*0.8) + text_width = label.boundingRect().width() + label.setX(-text_width/2) + shapes[k] = shape + +for e in annot_topo.topology.edges: + start = shapes[e.source].pos() + end = shapes[e.target].pos() + qlinef = QtCore.QLineF(start, end) + line = QtWidgets.QGraphicsLineItem(qlinef) + shapes[e] = line # Render the widget scene = QtWidgets.QGraphicsScene() -for tagsrc in [ - annotated_topology.router_annotations.values(), - annotated_topology.network_annotations.values(), - annotated_topology.link_annotations.values(), - ]: - for taglist in tagsrc: - assert len(taglist) > 0 - assert isinstance(taglist[-1], QtWidgets.QGraphicsItem) - scene.addItem(taglist[-1]) +#for tagsrc in [ +# annotated_topology.router_annotations.values(), +# annotated_topology.network_annotations.values(), +# annotated_topology.link_annotations.values(), +# ]: +# for taglist in tagsrc: +# assert len(taglist) > 0 +# assert isinstance(taglist[-1], QtWidgets.QGraphicsItem) +# scene.addItem(taglist[-1]) + +for sh in shapes.values(): scene.addItem(sh) view = QtWidgets.QGraphicsView(scene) #view.show()