Browse code

Handle polylines. Handle ports in nodes.

Jose.R.Fonseca authored on 02/09/2008 00:00:04
Showing 1 changed files

  • xdot.py index 05591fd..48256e1 100755
... ...
@@ -246,6 +246,25 @@ class PolygonShape(Shape):
246 246
             cr.stroke()
247 247
 
248 248
 
249
+class LineShape(Shape):
250
+
251
+    def __init__(self, pen, points):
252
+        Shape.__init__(self)
253
+        self.pen = pen.copy()
254
+        self.points = points
255
+
256
+    def draw(self, cr, highlight=False):
257
+        x0, y0 = self.points[0]
258
+        cr.move_to(x0, y0)
259
+        for x1, y1 in self.points[1:]:
260
+            cr.line_to(x1, y1)
261
+        pen = self.select_pen(highlight)
262
+        cr.set_dash(pen.dash)
263
+        cr.set_line_width(pen.linewidth)
264
+        cr.set_source_rgba(*pen.color)
265
+        cr.stroke()
266
+
267
+
249 268
 class BezierShape(Shape):
250 269
 
251 270
     def __init__(self, pen, points):
... ...
@@ -543,6 +562,9 @@ class XDotAttrParser:
543 562
                 w = s.read_number()
544 563
                 h = s.read_number()
545 564
                 shapes.append(EllipseShape(pen, x0, y0, w, h))
565
+            elif op == "L":
566
+                p = self.read_polygon()
567
+                shapes.append(LineShape(pen, p))
546 568
             elif op == "B":
547 569
                 p = self.read_polygon()
548 570
                 shapes.append(BezierShape(pen, p))
... ...
@@ -621,8 +643,18 @@ class XDotParser:
621 643
                     parser = XDotAttrParser(self, getattr(edge, attr))
622 644
                     shapes.extend(parser.parse())
623 645
             if shapes:
624
-                src = node_by_name[edge.get_source()]
625
-                dst = node_by_name[edge.get_destination()]
646
+                src_name = edge.get_source()
647
+                dst_name = edge.get_destination()
648
+                try:
649
+                    src = node_by_name[src_name]
650
+                except KeyError:
651
+                    src_name, src_port = src_name.rsplit(':', 1)
652
+                    src = node_by_name[src_name]
653
+                try:
654
+                    dst = node_by_name[dst_name]
655
+                except KeyError:
656
+                    dst_name, dst_port = dst_name.rsplit(':', 1)
657
+                    dst = node_by_name[dst_name]
626 658
                 edges.append(Edge(src, dst, points, shapes))
627 659
 
628 660
         return Graph(width, height, nodes, edges)