예제 #1
0
        void ShowGraph(bool showMes)
        {
            this.groupBoxResult.Controls.Clear();
            Microsoft.Msagl.GraphViewerGdi.GViewer viewer = new Microsoft.Msagl.GraphViewerGdi.GViewer();
            Microsoft.Msagl.Drawing.Graph          graph  = new Microsoft.Msagl.Drawing.Graph("graph");
            graph.CreateGeometryGraph();
            int i = 1;

            foreach (var item in lstPoint)
            {
                Node node = new Node(i.ToString());
                node.Attr.Shape = Shape.Circle;
                graph.AddNode(node);
                i++;
            }

            graph.FindNode((this.start + 1).ToString()).Attr.FillColor = Color.Blue;
            graph.FindNode((this.end + 1).ToString()).Attr.FillColor   = Color.Red;
            viewer.Pan(5, 2);
            for (int j = 0; j < this.soDinh; j++)
            {
                for (int k = 0; k < this.soDinh; k++)
                {
                    if (this.distance[j, k] != this.VOCUNG && this.distance[j, k] != 0)
                    {
                        String tmp = "," + (j + 1).ToString() + "," + (k + 1).ToString() + ",";
                        double dis = Math.Round(this.distance[j, k], 2);
                        if (this.path.Contains(tmp))
                        {
                            if (this.checkBox.Checked)
                            {
                                graph.AddEdge((j + 1).ToString(), dis.ToString(), (k + 1).ToString()).Attr.Color = Color.Green;
                            }
                            else
                            {
                                graph.AddEdge((j + 1).ToString(), (k + 1).ToString()).Attr.Color = Color.Green;
                            }
                            // Microsoft.Msagl.Core.Layout.Node node = new Microsoft.Msagl.Core.Layout.Node(1, 2);
                        }
                        else
                        {
                            if (this.checkBox.Checked)
                            {
                                graph.AddEdge((j + 1).ToString(), dis.ToString(), (k + 1).ToString());
                            }
                            else
                            {
                                graph.AddEdge((j + 1).ToString(), (k + 1).ToString());
                            }
                        }
                    }
                }
            }

            /*graph.AddEdge("A", "C").Attr.Color = Microsoft.Msagl.Drawing.Color.Green;
             * Edge edge = new Edge("14","sonnx","15");
             *
             * graph.AddEdge("14", "sonnx", "15");
             * graph.FindNode("A").Attr.FillColor = Microsoft.Msagl.Drawing.Color.Magenta;
             * graph.FindNode("B").Attr.FillColor = Microsoft.Msagl.Drawing.Color.MistyRose;
             * Microsoft.Msagl.Drawing.Node c = graph.FindNode("C");
             * c.Attr.FillColor = Microsoft.Msagl.Drawing.Color.PaleGreen;
             * c.Attr.Shape = Microsoft.Msagl.Drawing.Shape.Circle;*/


/*
 *
 *          Microsoft.Msagl.Core.Geometry.Point p1 = new Microsoft.Msagl.Core.Geometry.Point(-497.12352212078628, 1689.84931190121);
 *          Microsoft.Msagl.Core.Geometry.Point p2 = new Microsoft.Msagl.Core.Geometry.Point(198.64235142705752, 2139.4677380013277);
 *          Microsoft.Msagl.Core.Geometry.Point bl = new Microsoft.Msagl.Core.Geometry.Point(-5191.0147700187063, -4395.7850131819132);
 *          double gridSize = 553.23948409846571;
 *
 *          GridTraversal grid = new GridTraversal(new Rectangle(bl, bl + new Microsoft.Msagl.Core.Geometry.Point(gridSize, gridSize)), 20);
 *          var tiles = grid.GetTilesIntersectedByLineSeg(p1, p2);
 */


            //bind the graph to the viewer
            viewer.Graph = graph;
            // viewer.Click += new EventHandler(Group_Click);
            //  viewer.MouseClick += new MouseEventHandler(Group_Click);
            this.groupBoxResult.SuspendLayout();
            viewer.Dock = System.Windows.Forms.DockStyle.Fill;
            this.groupBoxResult.Controls.Add(viewer);
            this.groupBoxResult.ResumeLayout();

            if (showMes)
            {
                if (this.daxet[this.end])
                {
                    MessageBox.Show("Độ dài đường đi ngắn nhất " + (Math.Round(d[this.end], 2)).ToString(), "Thành công");
                    this.txtLoTrinh.Text = this.path;
                    this.txtDoDai.Text   = (Math.Round(d[this.end], 2)).ToString();
                }
                else
                {
                    MessageBox.Show("Không tìm được đường đi ngắn nhất", "Có lỗi xảy ra");
                    this.txtLoTrinh.Text = "";
                    this.txtDoDai.Text   = "";
                }
            }
        }