Beispiel #1
0
         public static void Parse(string path, DiagramCanvas diagram) {
            var parser = new PlainParser(path);
            if (parser.ReadLine("graph")) {
               parser.NextToken();
               var size = parser.NextSize();
               diagram.ComputedSize = size;
               diagram.Width = size.Width;
               diagram.Height = size.Height;
               parser._coordTransform = (x, y) => new Point(x, size.Height - y);
            }

            // parse the computed node positions
            while (parser.ReadLine("node")) {
               var node = diagram.Nodes[parser.NextInt()];
               node.ComputedPosition = parser.NextPoint();
            }

            // parse the computed edge paths
            while (parser.ReadLine("edge")) {
               var source = diagram.Nodes[parser.NextInt()];
               var target = diagram.Nodes[parser.NextInt()];
               var points = new PointCollection();
               for (var n = parser.NextInt(); n > 0; n--) {
                  points.Add(parser.NextPoint());
               }
               var tokens = parser.RemainingTokens();
               var role = DiagramEdgeRole.None;
               try { role = (DiagramEdgeRole)Int32.Parse(tokens[tokens.Length - 1].After(1), NumberStyles.HexNumber); } catch { }
               if (role != DiagramEdgeRole.None) {
                  var edge = new DiagramEdge(source, target, role, null);
                  edge.ComputedPath = points;
                  diagram.Edges.Add(edge);
               }
            }

            parser.Close();
         }
Beispiel #2
0
         // parses an edge clause
         private string _parseEdge(Match match) {
            var source = _parseNodeRef(match.Groups[1].Value);
            var target = _parseNodeRef(match.Groups[2].Value);
            var properties = match.Groups[3].Value;
            var role = _parseRole(_parseProperty("color", properties));
            var label = _parseProperty("label", properties);

            if (role != DiagramEdgeRole.None) {
               var edge = new DiagramEdge(source, target, role, label);
               var P = _parseProperty("pos", properties).Split(" ");
               for (var i = 0; i < P.Length; i++) {
                  var p = P[i];
                  if (p.StartsWith("s,")) {
                     edge.ComputedArrowTail = _parsePoint(p.After(1));
                  } else if (p.StartsWith("e,")) {
                     edge.ComputedArrowHead = _parsePoint(p.After(1));
                  } else {
                     edge.ComputedPath.Add(_parsePoint(p));
                  }
               }
               if (label.NotEmpty()) {
                  edge.LabelPos = _parsePoint(_parseProperty("lp", properties));
               }
               _diagram.Edges.Add(edge);
            }
            
            return String.Empty;
         }