示例#1
0
文件: Form1.cs 项目: kirixik/GraphX
 private GraphExample GenerateGraph()
 {
     //FOR DETAILED EXPLANATION please see SimpleGraph example project
     var dataGraph = new GraphExample();
     for (int i = 1; i < 10; i++)
     {
         var dataVertex = new DataVertex("MyVertex " + i) { ID = i };
         dataGraph.AddVertex(dataVertex);
     }
     var vlist = dataGraph.Vertices.ToList();
     //Then create two edges optionaly defining Text property to show who are connected
     var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
     dataGraph.AddEdge(dataEdge);
     dataEdge = new DataEdge(vlist[2], vlist[3]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[3]) };
     dataGraph.AddEdge(dataEdge);
     return dataGraph;
 }
示例#2
0
        private void button4_Click(object sender, EventArgs e)
        {
            var    links      = new Dictionary <string, Link>();
            var    states     = new HashSet <string>();
            string initState  = "";
            string finalState = "";

            for (int i = 0; i < txtFSMTable.Lines.Count(); i++)
            {
                string   line          = txtFSMTable.Lines[i];
                string[] StateAndLinks = line.Split(':');
                string   StateName     = StateAndLinks[0].Trim(' ');
                states.Add(StateName);
                if (i == 0)
                {
                    initState = StateName;
                }
                if (i == txtFSMTable.Lines.Count() - 1)
                {
                    finalState = StateName;
                }
                links.Add(StateName, new Link());

                if (StateAndLinks[1] != "") // Парсим переходы к другим состояниям
                {
                    foreach (string LinkPair in StateAndLinks[1].Split(','))
                    {
                        string[] SymAndDestState = LinkPair.Split('-');
                        string   Symbol          = SymAndDestState[0].Trim(' ').Substring(1); //.Substring(1);
                        string   DestState       = SymAndDestState[1].Trim(' ');
                        states.Add(DestState);
                        links[StateName].Add(Symbol, DestState);
                    }
                }
            }
            parser = new fsm.Parser(states, links, initState, finalState);
            var dataGraph = new GraphExample();

            foreach (string vs in states)
            {
                var dataVertex = new DataVertex(vs);
                dataGraph.AddVertex(dataVertex);
            }
            var      vlist = dataGraph.Vertices.ToList();
            DataEdge edge;

            //Then create two edges optionaly defining Text property to show who are connected
            foreach (string state in states)
            {
                if (links.ContainsKey(state))
                {
                    foreach (KeyValuePair <string, string> link in links[state])
                    {
                        var vA = vlist.Find(x => x.Text.Equals(state));
                        var vB = vlist.Find(x => x.Text.Equals(link.Value));
                        edge = new DataEdge(vA, vB)
                        {
                            Text = link.Key
                        };
                        dataGraph.AddEdge(edge);
                    }
                }
            }
            _gArea.LogicCore.Graph = dataGraph;
            _gArea.GenerateGraph(true);
            _gArea.RelayoutGraph();
            _gArea.SetVerticesDrag(true, true);
            _zoomctrl.ZoomToFill();
        }