} // DrawPoints public void DrawLines(int[] trail, Grid graph) { GeometryGroup linesGroup = new GeometryGroup(); LineGeometry line = new LineGeometry(); int city = 1; for (; city < trail.Length; city++) { line = new LineGeometry(); line.StartPoint = new Point(cities.GetLocation(trail[city - 1]).X, cities.GetLocation(trail[city - 1]).Y); line.EndPoint = new Point(cities.GetLocation(trail[city]).X, cities.GetLocation(trail[city]).Y); linesGroup.Children.Add(line); } line = new LineGeometry(); line.StartPoint = new Point(cities.GetLocation(trail[city - 1]).X, cities.GetLocation(trail[city - 1]).Y); line.EndPoint = new Point(cities.GetLocation(trail[0]).X, cities.GetLocation(trail[0]).Y); linesGroup.Children.Add(line); Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.Data = linesGroup; if (graph.Children.Count > 1) { graph.Children.Remove(graph.Children[1]); } graph.Children.Add(myPath); }
public void DrawPoints(object sender, RoutedEventArgs e) { CancelCalculation(); ClearTextBox(); int nCities; if (!Int32.TryParse(textB_countCities.Text, out nCities)) { textB_countCities.Background = Brushes.Coral; errorTB.Push(textB_countCities); return; } cities = new Cities(nCities); cities.Generate((int)graph1.Width); GeometryGroup cityGroup = new GeometryGroup(); for (int i = 0; i < cities.NumCities; i++) { Location l = cities.GetLocation(i); // формирование точек на карте EllipseGeometry city = new EllipseGeometry(); city.Center = new Point(l.X, l.Y); city.RadiusX = 4; city.RadiusY = 4; cityGroup.Children.Add(city); } Path[] myPath = new Path[5]; for (int i = 0; i < 5; i++) { myPath[i] = new Path(); myPath[i].Fill = Brushes.Plum; myPath[i].Stroke = Brushes.Black; myPath[i].Data = cityGroup; graphs[i].Children.Clear(); graphs[i].Children.Add(myPath[i]); } button_CalcBF.IsEnabled = true; button_CalcAC.IsEnabled = true; button_CalcGA.IsEnabled = true; button_CalcSA.IsEnabled = true; button_CalcBB.IsEnabled = true; button_save.IsEnabled = true; } // DrawPoints