Beispiel #1
0
        private Graphics Draw_New_line(int[] From_XY_index, int[] TO_XY_index, int Path_length)
        {
            Graphics g = Panel_nodes.CreateGraphics();
            //original
            int From_X = Convert.ToInt32(Math.Floor(Panel_nodes.Width * X_location_of_nodes_new[From_XY_index[0]]));
            int From_Y = Convert.ToInt32(Math.Floor(Panel_nodes.Height * Y_location_of_nodes_new[From_XY_index[1]]));
            int To_X   = Convert.ToInt32(Math.Floor(Panel_nodes.Width * X_location_of_nodes_new[TO_XY_index[0]]));
            int To_Y   = Convert.ToInt32(Math.Floor(Panel_nodes.Height * Y_location_of_nodes_new[TO_XY_index[1]]));

            Point From     = new Point(From_X, From_Y + ToolStrip_creat.Height);
            Point To       = new Point(To_X, To_Y + ToolStrip_creat.Height);
            int   Length_X = To_X - From_X;
            int   Length_Y = To_Y - From_Y;

            Rectangle r = new Rectangle(Convert.ToInt32(From_X + 0.5 * Length_X), Convert.ToInt32(From_Y + 0.5 * Length_Y), 100, 100);

            Font ft = new Font("Arial", 15);
            Pen  pn = new Pen(Color.Black, 5);

            pn.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;   //set arrow
            g.DrawLine(pn, From, To);                                   //draw line

            g.DrawString((Path_length).ToString(), ft, Brushes.Red, r); //draw string

            return(g);
        }
Beispiel #2
0
        private Graphics Draw_boundary(Rectangle r)
        {
            Graphics g  = Panel_nodes.CreateGraphics();
            Pen      pn = new Pen(Color.Black, 5);

            g.DrawRectangle(pn, r);
            return(g);
        }
Beispiel #3
0
        private Graphics Draw_temp_line(int[] From_XY_index, int[] To_Cursor_Location, int Path_length)
        {
            Graphics g = Panel_nodes.CreateGraphics();
            //original
            int From_X = Convert.ToInt32(Math.Floor(Panel_nodes.Width * X_location_of_nodes_new[From_XY_index[0]]));
            int From_Y = Convert.ToInt32(Math.Floor(Panel_nodes.Height * Y_location_of_nodes_new[From_XY_index[1]]));
            //int To_X = Convert.ToInt32(Math.Floor(Panel_nodes.Width * X_location_of_nodes_new[TO_XY_index[0]]));
            //int To_Y = Convert.ToInt32(Math.Floor(Panel_nodes.Height * Y_location_of_nodes_new[TO_XY_index[1]]));

            Point From = new Point(From_X, From_Y + ToolStrip_creat.Height);
            Point To   = new Point(To_Cursor_Location[0], To_Cursor_Location[1] + ToolStrip_creat.Height);

            Font ft = new Font("Arial", 15);
            Pen  pn = new Pen(Color.Black, 5);

            pn.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; //set arrow
            g.DrawLine(pn, From, To);                                 //draw line

            return(g);
        }
Beispiel #4
0
        private void Panel_nodes_MouseMove(object sender, MouseEventArgs e)
        {
            Panel_nodes.Refresh();
            //draw temp line
            if (Panel_nodes.Cursor == PathCrusor && whether_draw_TempLine == true)
            {
                nearest_X_End_index = Convert.ToInt32(Nearest_neibhior(X_location_of_nodes_new, (float)e.X / Panel_nodes.Width)[0]);
                nearest_Y_End_index = Convert.ToInt32(Nearest_neibhior(Y_location_of_nodes_new, (float)e.Y / Panel_nodes.Height)[0]);
                int[] From_XY = new int[2];
                int[] To_XY   = new int[2];

                From_XY[0] = nearest_X_start_index;
                From_XY[1] = nearest_Y_start_index;

                To_XY[0] = e.X;
                To_XY[1] = e.Y;


                Draw_temp_line(From_XY, To_XY, 10);
            }
        }
Beispiel #5
0
        private void Button_Clear_Data_Click(object sender, EventArgs e)
        {
            //clean panel
            Graphics c = Panel_nodes.CreateGraphics();

            c.Clear(Panel_nodes.BackColor);

            //Pen pn = new Pen(Color.Transparent, 5);
            //Graphics g = Panel_nodes.CreateGraphics();

            //clear variable
            number_of_nodes_new = 0;
            number_of_pahts_new = 0;
            X_location_of_nodes_new.Clear();
            Y_location_of_nodes_new.Clear();
            nearest_X_End_index   = 0;
            nearest_Y_End_index   = 0;
            nearest_X_start_index = 0;
            nearest_Y_start_index = 0;

            paths_from_to_length_new.Clear();
        }
Beispiel #6
0
        private Graphics Draw_circle(double x, double y, int node_NO)
        {
            int X = Convert.ToInt32(Math.Floor(Panel_nodes.Width * x));
            int Y = Convert.ToInt32(Math.Floor(Panel_nodes.Height * y));
            //MessageBox.Show(X.ToString()+ Y.ToString());
            Graphics  g = Panel_nodes.CreateGraphics();
            Rectangle r = new Rectangle(X - circle_radius, Y - circle_radius + ToolStrip_creat.Height, 2 * circle_radius, 2 * circle_radius);

            StringFormat sr = new StringFormat();

            sr.Alignment     = StringAlignment.Center;
            sr.LineAlignment = StringAlignment.Center;

            Font ft = new Font("Arial", 20);
            Pen  pn = new Pen(Color.Black, 3);

            //g.DrawString()
            g.FillEllipse(Brushes.White, r);
            g.DrawEllipse(pn, r);
            g.DrawString((node_NO + 1).ToString(), ft, Brushes.Black, r, sr);


            return(g);
        }
Beispiel #7
0
        private Graphics Draw_line(int from, int to, int Path_length)
        {
            Graphics g = Panel_nodes.CreateGraphics();
            //original
            double From_X = Panel_nodes.Width * location_of_nodes[from, 0];
            double From_Y = Panel_nodes.Height * location_of_nodes[from, 1];
            double To_X   = Panel_nodes.Width * location_of_nodes[to, 0];
            double To_Y   = Panel_nodes.Height * location_of_nodes[to, 1];

            double Length_X = To_X - From_X;
            double Length_Y = To_Y - From_Y;
            double ratio    = (400 / (Length_X * Length_X + Length_Y * Length_Y));
            double Inner_Circle_To_X_Length = Math.Sqrt(Length_X * Length_X * ratio) + 5;
            double Inner_Circle_To_Y_Length = Math.Sqrt(Length_Y * Length_Y * ratio) + 5;
            Point  From = new Point(Convert.ToInt32(From_X), Convert.ToInt32(From_Y) + ToolStrip_creat.Height);

            if (To_Y < From_Y)//higer
            {
                Inner_Circle_To_Y_Length = -Inner_Circle_To_Y_Length;
            }
            Point To_circle_edge = new Point(Convert.ToInt32(To_X - Inner_Circle_To_X_Length), Convert.ToInt32(To_Y - Inner_Circle_To_Y_Length) + ToolStrip_creat.Height);


            Rectangle r = new Rectangle(Convert.ToInt32(From_X + 0.5 * Length_X), Convert.ToInt32(From_Y + 0.5 * Length_Y), 100, 100);
            //Rectangle r = new Rectangle(Convert.ToInt32( From_X +0.5* Length_X), Convert.ToInt32(From_Y + 0.5 * Length_Y),100,100);
            Font ft = new Font("Arial", 15);
            Pen  pn = new Pen(Color.Black, 5);

            pn.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;   //set arrow
            g.DrawLine(pn, From, To_circle_edge);                       //draw line

            g.DrawString((Path_length).ToString(), ft, Brushes.Red, r); //draw string
            ;

            return(g);
        }
Beispiel #8
0
        private void Button_Open_Click(object sender, EventArgs e)
        {
            All_paths_Lengthes.Clear();
            All_paths.Clear();
            All_paths_time.Clear();



            SAN_Button_Simulate.Enabled = true;
            string[] tmp;
            char[]   seps = { ' ', ',', '@' };//分割子
            //clean panel
            Graphics c = Panel_nodes.CreateGraphics();

            c.Clear(Panel_nodes.BackColor);

            if (OpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                Label_read_file.Text       = "File name:\n" + Path.GetFileName(OpenFileDialog.FileName);
                RichTextBox_Benchmark.Text = "";

                StreamReader sr = new StreamReader(OpenFileDialog.FileName);
                number_of_nodes   = Convert.ToInt32(sr.ReadLine());
                location_of_nodes = new double[number_of_nodes, 2];


                for (int i = 0; i < number_of_nodes; i++)
                {
                    tmp = sr.ReadLine().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                    location_of_nodes[i, 0] = Convert.ToDouble(tmp[0]);
                    location_of_nodes[i, 1] = Convert.ToDouble(tmp[1]);
                }

                number_of_pahts      = Convert.ToInt32(sr.ReadLine());
                paths_from_to_length = new int[number_of_pahts, 3];
                for (int i = 0; i < number_of_pahts; i++)
                {
                    tmp = sr.ReadLine().Split(seps, StringSplitOptions.RemoveEmptyEntries);
                    paths_from_to_length[i, 0] = Convert.ToInt32(tmp[0]);
                    paths_from_to_length[i, 1] = Convert.ToInt32(tmp[1]);
                    paths_from_to_length[i, 2] = Convert.ToInt32(tmp[2]);
                }
                sr.Close();

                //print out on RichBoxText
                RichTextBox_Benchmark.Text += number_of_nodes.ToString() + "\n";
                for (int i = 0; i < number_of_nodes; i++)
                {
                    RichTextBox_Benchmark.Text += location_of_nodes[i, 0].ToString() + " " + location_of_nodes[i, 1].ToString() + "\n";
                }
                RichTextBox_Benchmark.Text += number_of_pahts.ToString() + "\n";
                for (int i = 0; i < number_of_pahts; i++)
                {
                    RichTextBox_Benchmark.Text += paths_from_to_length[i, 0].ToString() + " " + paths_from_to_length[i, 1].ToString() + " " + paths_from_to_length[i, 2].ToString() + "\n";
                }

                //Draw on Panel
                for (int i = 0; i < number_of_pahts; i++)
                {
                    int From   = paths_from_to_length[i, 0];
                    int To     = paths_from_to_length[i, 1];
                    int Length = paths_from_to_length[i, 2];
                    Draw_line(From, To, Length);
                }
                for (int i = 0; i < number_of_nodes; i++)
                {
                    Draw_circle(location_of_nodes[i, 0], location_of_nodes[i, 1], i);
                }
            }

            // path finder
            List <int> l = new List <int>();
            List <int> L = new List <int>();

            Walk_to_next_node(l, 0, 0, L);
            //print out result
            RichTextBox_Benchmark.Text += "\nProssible Paths:\n";
            for (int i = 0; i < All_paths.Count; i++)//mulitple pathes
            {
                //RichTextBox_Benchmark.Text += "\n";
                for (int j = 0; j < All_paths[i].Count; j++) //single path
                {
                    if (j == All_paths[i].Count - 1)         //at line end
                    {
                        RichTextBox_Benchmark.Text += (All_paths[i][j] + 1).ToString() + "\n    Length = " + All_paths_Lengthes[i].Sum().ToString() + "\n";
                    }
                    else//at line middle
                    {
                        RichTextBox_Benchmark.Text += (All_paths[i][j] + 1).ToString() + " -> ";
                    }
                }
            }
        }