Pārlūkot izejas kodu

Easy retrieval of a vertex' outgoing/incoming edges

Joeri Exelmans 2 gadi atpakaļ
vecāks
revīzija
91345310a1
2 mainītis faili ar 6 papildinājumiem un 2 dzēšanām
  1. 2 0
      drawio2py/abstract_syntax.py
  2. 4 2
      drawio2py/parser.py

+ 2 - 0
drawio2py/abstract_syntax.py

@@ -36,6 +36,8 @@ class VertexGeometry(Point):
 @dataclass(eq=False)
 class Vertex(Cell):
 	geometry: VertexGeometry
+	outgoing: List['Edge']
+	incoming: List['Edge']
 
 @dataclass(eq=False)
 class EdgeGeometry(Element):

+ 4 - 2
drawio2py/parser.py

@@ -111,7 +111,7 @@ class Parser:
 
 		geom = Parser.parse_cell_geometry(croot.find(".//mxGeometry"))
 		if geom != None:
-			return Vertex(cid, value, parent, [], properties, style, atts, geom)
+			return Vertex(cid, value, parent, [], properties, style, atts, geom, [], [])
 		else:
 			return Cell(cid, value, parent, [], properties, style, atts)
 
@@ -158,7 +158,7 @@ class Parser:
 			cell_dict = {} # mapping from ID to cell
 			Parser.parse_components(mxgm[0], cell_dict)
 
-			# resolve parent/child references
+			# resolve parent/child, source/target references
 			root = None
 			for cell_id, cell in cell_dict.items():
 				parent_id = cell.parent # cell.parent will be overwritten with the actual cell
@@ -169,8 +169,10 @@ class Parser:
 					cell.parent = cell_dict[parent_id]
 				if isinstance(cell, Edge):
 					if cell.source:
+						cell_dict[cell.source].outgoing.append(cell)
 						cell.source = cell_dict[cell.source]
 					if cell.target:
+						cell_dict[cell.target].incoming.append(cell)
 						cell.target = cell_dict[cell.target]
 
 			if root == None: