|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
from birdvisu.annotations import AnnotatedTopology, AnnotatorID
|
|
|
|
|
from birdvisu.annotations.analysis import TopologyDifference, ShortestPathTree
|
|
|
|
|
from birdvisu.annotations.layout import MegaStyler
|
|
|
|
|
from birdvisu.ospfsock import BirdSocketConnection
|
|
|
|
|
from birdvisu.providers import BirdSocketTopologyProvider, OspfFileTopologyProvider, OspfFileParseError
|
|
|
|
|
from birdvisu.topo_v3 import TopologyV3, VertexID
|
|
|
|
@ -100,27 +101,19 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
|
MoveTopology = auto()
|
|
|
|
|
ShortestPath = auto()
|
|
|
|
|
|
|
|
|
|
def __init__(self, *a, **kwa):
|
|
|
|
|
super().__init__(*a, **kwa)
|
|
|
|
|
self.ref_topo_provider = None
|
|
|
|
|
self.cur_topo_provider = None
|
|
|
|
|
self.annotators = self.get_annotators()
|
|
|
|
|
self.annot_topo = None
|
|
|
|
|
self.highlighter = None
|
|
|
|
|
self.tool = self.Tool.MoveTopology
|
|
|
|
|
self.scene = QtWidgets.QGraphicsScene()
|
|
|
|
|
self.view = QtWidgets.QGraphicsView(self.scene)
|
|
|
|
|
self.view.setDragMode(self.view.DragMode.ScrollHandDrag)
|
|
|
|
|
self.setCentralWidget(self.view)
|
|
|
|
|
self.statusbar = self.statusBar()
|
|
|
|
|
self.statusbar.showMessage('Hello!')
|
|
|
|
|
|
|
|
|
|
def create_menus(self):
|
|
|
|
|
print('Creating menus…')
|
|
|
|
|
self.menubar = self.menuBar()
|
|
|
|
|
mode_menu = self.menubar.addMenu('&Mode')
|
|
|
|
|
short_path_act = QtGui.QAction("Sh. path &DAG", self)
|
|
|
|
|
short_path_act.triggered.connect(self.shortestPathMode)
|
|
|
|
|
mode_menu.addAction(short_path_act)
|
|
|
|
|
|
|
|
|
|
# Hack!
|
|
|
|
|
autoload_act = QtGui.QAction("&Load automatically", self)
|
|
|
|
|
autoload_act.triggered.connect(self.autoLoad)
|
|
|
|
|
self.menubar.addAction(autoload_act)
|
|
|
|
|
|
|
|
|
|
topo_menu = self.menubar.addMenu('&Topology')
|
|
|
|
|
open_ref_act = QtGui.QAction("&Load reference", self)
|
|
|
|
|
open_ref_act.triggered.connect(self.openRefTopology)
|
|
|
|
@ -138,10 +131,38 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
|
refresh_act.triggered.connect(self.refreshTopologies)
|
|
|
|
|
topo_menu.addAction(refresh_act)
|
|
|
|
|
|
|
|
|
|
def get_annotators(self):
|
|
|
|
|
return [
|
|
|
|
|
AnnotatorID(TopologyDifference),
|
|
|
|
|
AnnotatorID(ShortestPathTree, (VertexID(
|
|
|
|
|
def __init__(self, *a, **kwa):
|
|
|
|
|
super().__init__(*a, **kwa)
|
|
|
|
|
self.ref_topo_provider = None
|
|
|
|
|
self.cur_topo_provider = None
|
|
|
|
|
self.set_initial_annotators()
|
|
|
|
|
self.annot_topo = None
|
|
|
|
|
self.highlighter = None
|
|
|
|
|
self.tool = self.Tool.MoveTopology
|
|
|
|
|
self.scene = QtWidgets.QGraphicsScene()
|
|
|
|
|
self.view = QtWidgets.QGraphicsView(self.scene)
|
|
|
|
|
self.view.setDragMode(self.view.DragMode.ScrollHandDrag)
|
|
|
|
|
self.setCentralWidget(self.view)
|
|
|
|
|
self.statusbar = self.statusBar()
|
|
|
|
|
self.statusbar.showMessage('Hello!')
|
|
|
|
|
self.create_menus()
|
|
|
|
|
|
|
|
|
|
#Hack
|
|
|
|
|
@Slot()
|
|
|
|
|
def autoLoad(self):
|
|
|
|
|
print('Auto-loading…')
|
|
|
|
|
self.ref_topo_provider = OspfFileTopologyProvider('./empty.ospf')
|
|
|
|
|
self.cur_topo_provider = BirdSocketTopologyProvider(instance='gennet4', area=1, version=2)
|
|
|
|
|
self.refreshTopologies()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_initial_annotators(self):
|
|
|
|
|
# We have three kinds of annotators:
|
|
|
|
|
# - The essential analytic ones (TopologyDifference)
|
|
|
|
|
# - The one that describes the current tool (when that is Annotator backed, like for ShortestPathTree)
|
|
|
|
|
# - The styling ones, that actually help visualise stuff (MegaStyler)
|
|
|
|
|
self.essential_annotators = [AnnotatorID(TopologyDifference)]
|
|
|
|
|
self.current_annotators = [AnnotatorID(ShortestPathTree, (VertexID(
|
|
|
|
|
family=None,
|
|
|
|
|
is_router=True,
|
|
|
|
|
address=None,
|
|
|
|
@ -150,6 +171,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
|
discriminator=None
|
|
|
|
|
), 'current')),
|
|
|
|
|
]
|
|
|
|
|
self.styling_annotators = [AnnotatorID(MegaStyler, tuple(self.essential_annotators + self.current_annotators))]
|
|
|
|
|
|
|
|
|
|
@Slot()
|
|
|
|
|
def shortestPathMode(self):
|
|
|
|
@ -222,15 +244,34 @@ class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
|
combined_topology = TopologyV3.combine_topologies(reference=ref_topo, current=cur_topo)
|
|
|
|
|
combined_topology.freeze()
|
|
|
|
|
self.annot_topo = AnnotatedTopology(combined_topology)
|
|
|
|
|
for ann_id in self.annotators:
|
|
|
|
|
for ann_id in self.essential_annotators + self.current_annotators + self.styling_annotators:
|
|
|
|
|
self.annot_topo.run_annotator(ann_id)
|
|
|
|
|
# Draw it
|
|
|
|
|
self.set_current_highlighter()
|
|
|
|
|
self.ad_hoc_draw_visu()
|
|
|
|
|
self.draw_visu()
|
|
|
|
|
|
|
|
|
|
def draw_visu(self):
|
|
|
|
|
# just take the result of the MegaStyler and create vertices according to the style.
|
|
|
|
|
megastyler = self.styling_annotators[-1]
|
|
|
|
|
assert megastyler.annotator == MegaStyler
|
|
|
|
|
msann = self.annot_topo.annotations[megastyler]
|
|
|
|
|
self.graphicsitems: dict[VertexID, QGraphicsItem] = dict()
|
|
|
|
|
self.topologyitems: dict[QGraphicsItem, VertexID|Edge] = dict()
|
|
|
|
|
for vtxid, style in msann.for_vertex.items():
|
|
|
|
|
gritem = self.create_vertex(vtxid, style)
|
|
|
|
|
self.graphicsitems[vtxid] = gritem
|
|
|
|
|
self.topologyitems[gritem] = vtxid
|
|
|
|
|
self.scene.addItem(gritem)
|
|
|
|
|
for edge, style in msann.for_edge.items():
|
|
|
|
|
gritem = self.create_edge(edge, style)
|
|
|
|
|
self.graphicsitems[edge] = gritem
|
|
|
|
|
self.topologyitems[gritem] = edge
|
|
|
|
|
self.scene.addItem(gritem)
|
|
|
|
|
|
|
|
|
|
def create_vertex(self, vtxid, style):
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
def set_current_highlighter(self):
|
|
|
|
|
# TODO!
|
|
|
|
|
self.highlighter = self.annotators[-1]
|
|
|
|
|
def create_edge(self, edge, style):
|
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
def ad_hoc_draw_visu(self):
|
|
|
|
|
shapes = dict()
|
|
|
|
|