It works now!

best commit, worst message, thug life.
topo-mov
LEdoian 1 year ago
parent 694c7386b4
commit 74a4c5e3f0

@ -273,11 +273,12 @@ class HighlightSPDAG(StyleAnnotator):
def __init__(self, vtxid): def __init__(self, vtxid):
self.vtxid = vtxid self.vtxid = vtxid
def annotate(self, topo): def annotate(self, topo):
spd_annot = AnnotatorID(ShortestPathTree, vtxid) spd_annot = AnnotatorID(analysis.ShortestPathTree, (self.vtxid, 'current'))
topo.run_annotator(spd_annot) topo.run_annotator(spd_annot)
annotation = topo.annotations[spd_annot] annotation = topo.annotations[spd_annot]
result = Annotation() result = Annotation()
result.for_edge = {e: {'highlight_colour': (200, 200, 0, 128)} for e in annotation.for_edge.keys()} result.for_edge = {e: {'highlight_colour': (200, 0, 200, 128)} for e in annotation.for_edge.keys()}
result.for_vertex[self.vtxid] = {'highlight_colour': (0, 200, 0, 128)}
return result return result
class HighlightShortestPath(StyleAnnotator): class HighlightShortestPath(StyleAnnotator):
@ -285,8 +286,20 @@ class HighlightShortestPath(StyleAnnotator):
def __init__(self, param): def __init__(self, param):
self.start, self.end = param self.start, self.end = param
def annotate(self, topo): def annotate(self, topo):
spd_annot = AnnotatorID(ShortestPathTree, vtxid) spd_annot = AnnotatorID(analysis.ShortestPathTree, (self.start, 'current'))
topo.run_annotator(spd_annot) topo.run_annotator(spd_annot)
annotation = topo.annotations[spd_annot] annotation = topo.annotations[spd_annot]
result = Annotation() result = Annotation()
... # Highlight start and end
result.for_vertex[self.start] = {'highlight_colour': (0, 200, 0, 128)}
result.for_vertex[self.end] = {'highlight_colour': (200, 0, 100, 128)}
# Find the path by following backward edges of the shortest path DAG, BFS style.
queue = [self.end]
while len(queue) > 0:
v = queue.pop(0)
if v == self.start: continue # no looking further.
previous_edges = topo.topology.vertices[v].incoming_edges & annotation.for_edge.keys()
result.for_edge |= {e: {'highlight_colour': (200, 0, 200, 128), 'width': 5} for e in previous_edges}
queue.extend(e.source for e in previous_edges)
# It is oriented, so there is no need to mark visited vertices.
return result

@ -1,6 +1,6 @@
from PySide6.QtWidgets import QGraphicsItem, QGraphicsRectItem, QGraphicsSimpleTextItem, QGraphicsLineItem from PySide6.QtWidgets import QGraphicsItem, QGraphicsRectItem, QGraphicsSimpleTextItem, QGraphicsLineItem, QMenu
from PySide6.QtCore import QLineF, Qt from PySide6.QtCore import QLineF, Qt
from PySide6.QtGui import QColor, QBrush, QPen from PySide6.QtGui import QColor, QBrush, QPen, QAction
def _rid_to_str(rid): def _rid_to_str(rid):
from ipaddress import IPv4Address from ipaddress import IPv4Address
@ -72,6 +72,21 @@ class RouterGraphicsItem(QGraphicsItem):
self.window.graphicsitems[edge].update_line() self.window.graphicsitems[edge].update_line()
super().mouseMoveEvent(evt) super().mouseMoveEvent(evt)
def contextMenuEvent(self, evt):
menu = QMenu(self.window)
tree_act = QAction('Show routing tree', self.window)
menu.addAction(tree_act)
path_act = object()
if self.window.mode == self.window.Mode.ShortestPathDAG:
path_act = QAction('Show path to here', self.window)
menu.addAction(path_act)
action = menu.exec(evt.screenPos())
if action == tree_act:
self.window.dagMode(self.vertex_id)
if action == path_act:
self.window.shortestPathMode(self.vertex_id)
# Admit we are basically only a wrapper of the icon. # Admit we are basically only a wrapper of the icon.
def boundingRect(self): def boundingRect(self):
return self.icon.boundingRect() return self.icon.boundingRect()

@ -87,10 +87,13 @@ class MainWindow(QtWidgets.QMainWindow):
def create_menus(self): def create_menus(self):
print('Creating menus…') print('Creating menus…')
self.menubar = self.menuBar() self.menubar = self.menuBar()
mode_menu = self.menubar.addMenu('&Mode') mode_menu = self.menubar.addMenu('&Highlight')
short_path_act = QtGui.QAction("Sh. path &DAG", self) edge_weight_act = QtGui.QAction("Edge costs", self)
short_path_act.triggered.connect(self.shortestPathMode) edge_weight_act.triggered.connect(self.edgeWeightMode)
mode_menu.addAction(short_path_act) mode_menu.addAction(edge_weight_act)
topodiff_act = QtGui.QAction("Topology differences", self)
topodiff_act.triggered.connect(self.topoDiffMode)
mode_menu.addAction(topodiff_act)
# Hack! # Hack!
autoload_act = QtGui.QAction("&Load automatically", self) autoload_act = QtGui.QAction("&Load automatically", self)
@ -149,7 +152,7 @@ class MainWindow(QtWidgets.QMainWindow):
@Slot() @Slot()
def load_positions(self): def load_positions(self):
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open vertex positions', '.', 'OSPF files(*.visu);;All files(*)')[0] filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open vertex positions', '.', 'OSPF visualisation files (*.visu);;All files(*)')[0]
if filename == '': return # Do nothing if filename == '': return # Do nothing
self.positions_from_file(filename) self.positions_from_file(filename)
@ -190,15 +193,18 @@ class MainWindow(QtWidgets.QMainWindow):
if oe.cost == 0 or oe.cost > e.cost: if oe.cost == 0 or oe.cost > e.cost:
for_edge[(a,b)] = (e, sty) for_edge[(a,b)] = (e, sty)
# Actually apply the style: # Actually apply the style:
for v, sty in for_vertex.items(): for v in self.visu_graph[0].keys():
sty = for_vertex.get(v, {})
self.graphicsitems[v].apply_style(sty) self.graphicsitems[v].apply_style(sty)
for e, tup in for_edge.items(): for e in self.visu_graph[1]:
self.graphicsitems[e].apply_style(tup[1]) sty = for_edge[e][1] if e in for_edge else {}
self.graphicsitems[e].apply_style(sty)
@Slot() @Slot()
def dagMode(self): def dagMode(self, vtxid):
self.mode = self.Mode.ShortestPathDAG self.mode = self.Mode.ShortestPathDAG
self.highlighter = HighlightSPDAG(...) self.highlighter = HighlightSPDAG(vtxid)
self.start_vertex = vtxid
self.apply_styles() self.apply_styles()
@Slot() @Slot()
@ -214,9 +220,11 @@ class MainWindow(QtWidgets.QMainWindow):
self.apply_styles() self.apply_styles()
@Slot() @Slot()
def shortestPathMode(self): def shortestPathMode(self, vtxid):
self.mode = self.Mode.ShortestPath self.mode = self.Mode.ShortestPath
... self.end_vertex = vtxid
self.highlighter = HighlightShortestPath((self.start_vertex, self.end_vertex))
self.apply_styles()
@Slot() @Slot()
def openRefTopology(self): def openRefTopology(self):

Loading…
Cancel
Save