Ejemplo n.º 1
0
        private bool edge_Exsist(Punkt p1, Punkt p2)
        {
            for (int i = 0; i < polaczenia.Count; i++)
            {
                if ((polaczenia[i].A1.Equals(p1) && polaczenia[i].B1.Equals(p2)) || (polaczenia[i].A1.Equals(p2) && polaczenia[i].B1.Equals(p1)))
                {
                    return(true);
                }
            }


            return(false);
        }
Ejemplo n.º 2
0
        private void add_New_Edge(Punkt startPoint, Punkt endPoint)
        {
            Double X2, X1, Y2, Y1, koszt;

            X2 = endPoint.PointXY.X;
            X1 = startPoint.PointXY.X;
            Y2 = endPoint.PointXY.Y;
            Y1 = startPoint.PointXY.Y;

            if (set_koszt.Text == "")
            {
                koszt = Math.Sqrt((Math.Pow((X2 - X1), 2.0) + Math.Pow((Y2 - Y1), 2.0)));
            }
            else
            {
                koszt = double.Parse(set_koszt.Text);
            }

            //dodanie nowego połączenia do listy połączeń
            polaczenia.Add(new Polaczenie(startPoint, endPoint, Math.Round(koszt, 0)));
        }
Ejemplo n.º 3
0
        private void load_Data(object sender, RoutedEventArgs e)
        {
            nazwy_tla.Clear();
            bacground_paths.Clear();
            punkty.Clear();
            polaczenia.Clear();
            background_map.Children.Clear();
            pointsListBox.Items.Clear();
            edgesListBox.Items.Clear();
            sourcePoint.Items.Clear();
            destinationPoint.Items.Clear();

            MessageBox.Show("Get data to edit! Background should be in the same folder!!");

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Image files (*.csv)|*.csv";

            if (openFileDialog.ShowDialog() == true)
            {
                actual_floor  = 1;
                textBox2.Text = actual_floor.ToString();

                directory_path = System.IO.Path.GetDirectoryName(openFileDialog.FileName) + "\\";


                using (StreamReader sr = new StreamReader(openFileDialog.FileName))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        // załadowanie krawędzi
                        if (line.StartsWith("E:"))
                        {
                            string[] dataString = line.Substring(2).Split(';');

                            // dodanie połączenia do listy połączeń
                            var p1 = punkty.Find(new Predicate <Punkt>((Punkt p) => p.PointName.Equals(dataString[0])));
                            var p2 = punkty.Find(new Predicate <Punkt>((Punkt p) => p.PointName.Equals(dataString[1])));

                            Polaczenie newEdge = new Polaczenie(p1, p2, Double.Parse(dataString[2]));
                            polaczenia.Add(newEdge);
                        }

                        //załadowanie punktów
                        else if (line.StartsWith("P:"))
                        {
                            string[] dataString = line.Substring(2).Split(';');

                            // dodanie punktu do listy punktów
                            Punkt newPoint = new Punkt(dataString[0], Double.Parse(dataString[1]), Double.Parse(dataString[2]), Double.Parse(dataString[3]), dataString[4]);
                            punkty.Add(newPoint);
                        }

                        // załadowanie tła mapy
                        else if (line.StartsWith("G:"))
                        {
                            string[] dataString = line.Substring(2).Split(';');


                            for (int i = 0; i < dataString.Count(); i++)
                            {
                                nazwy_tla.Add(dataString[i]);
                                bacground_paths.Add(directory_path + dataString[i]);
                            }

                            floor_counter = dataString.Count();

                            brush                     = new ImageBrush();
                            brush.ImageSource         = new BitmapImage(new Uri(bacground_paths[actual_floor - 1]));
                            background_map.Background = brush;
                        }
                    }
                }


                if (floor_counter == 1)
                {
                    back_floor.IsEnabled = false;
                    next_floor.IsEnabled = false;
                }
                else
                {
                    next_floor.IsEnabled = true;
                }

                points_iterator = Int32.Parse(punkty[punkty.Count - 1].PointName.Substring(1)); // pobranie id ostatniego punktu
                draw_Points();
                draw_Edges();
                drawing.IsEnabled = true;
            }
        }
Ejemplo n.º 4
0
        private void onMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (draw_points.IsChecked == true)
            {
                points_iterator++;
                add_New_Point(e);
                background_map.Children.Clear();
                pointsListBox.Items.Clear();
                edgesListBox.Items.Clear();
                sourcePoint.Items.Clear();
                destinationPoint.Items.Clear();
                draw_Points();
                draw_Edges();
            }
            else if (draw_edges.IsChecked == true)
            {
                for (int i = 0; i < punkty.Count; i++)
                {
                    if (punkty[i].PointZ == actual_floor)
                    {
                        if ((punkty[i].PointXY.X >= e.GetPosition(background_map).X - 4 && punkty[i].PointXY.X <= e.GetPosition(background_map).X + 4) &&
                            (punkty[i].PointXY.Y >= e.GetPosition(background_map).Y - 4 && punkty[i].PointXY.Y <= e.GetPosition(background_map).Y + 4))
                        {
                            iterator2++;

                            if (iterator2 == 1)
                            {
                                sp = punkty[i];
                            }
                            else if (iterator2 == 2)
                            {
                                ep        = punkty[i];
                                iterator2 = 0;
                                if (sp.Equals(ep))
                                {
                                    MessageBox.Show("You haven't add an edge between the same points!");
                                }
                                else
                                {
                                    if (!edge_Exsist(sp, ep))
                                    {
                                        add_New_Edge(sp, ep);
                                        background_map.Children.Clear();
                                        pointsListBox.Items.Clear();
                                        edgesListBox.Items.Clear();
                                        sourcePoint.Items.Clear();
                                        destinationPoint.Items.Clear();
                                        draw_Points();
                                        draw_Edges();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Edge exsist!!!");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 public Polaczenie(Punkt startPoint, Punkt endPoint, Double koszt)
 {
     this.A    = startPoint;
     this.B    = endPoint;
     this.Waga = koszt;
 }