Ejemplo n.º 1
0
        private void BtnCreateRandom_OnClick(object sender, RoutedEventArgs e)
        {
            var count       = 0d;
            var inputDialog = new NumberInputWindow("Select Node count", 0, 300, 0);

            if (inputDialog.ShowDialog() == true)
            {
                count = inputDialog.Answer;
                DrawCanvas.Children.Clear();
                MainNetwork = new NodeNetwork(DrawCanvas);
            }

            while (MainNetwork.Nodes.Count < count)
            {
                var rnd      = new Random();
                var x        = rnd.Next(0, 1670);
                var y        = rnd.Next(0, 1000);
                var canPlace = true;

                foreach (var iNode in MainNetwork.Nodes)
                {
                    if (Math.Sqrt(Math.Pow(iNode.GetLocation().X - x, 2) +
                                  Math.Pow(iNode.GetLocation().Y - y, 2)) < 25)
                    {
                        canPlace = false;
                    }
                }

                if (canPlace)
                {
                    MainNetwork.AddNode(new Node(new Point(x, y)));
                }
            }
        }
Ejemplo n.º 2
0
        private void BtnAutoConnect_OnClick(object sender, RoutedEventArgs e)
        {
            var distance    = 0d;
            var inputDialog = new NumberInputWindow("Please give the max. distance between connected nodes", 0, 1000, 0);

            if (inputDialog.ShowDialog() == true)
            {
                distance = inputDialog.Answer;
            }

            foreach (var iNode in MainNetwork.Nodes)
            {
                foreach (var jNode in MainNetwork.Nodes)
                {
                    if (iNode != jNode && Node.GetDistance(iNode, jNode) < distance && !iNode.Connections.Contains(jNode) && !jNode.Connections.Contains(iNode))
                    {
                        iNode.Connections.Add(jNode);
                        jNode.Connections.Add(iNode);
                        //Create Visual Connection
                        var connection = new Line();
                        MainNetwork.VisualConnections.Add(connection);
                        connection.X1              = iNode.GetLocation().X;
                        connection.X2              = jNode.GetLocation().X;
                        connection.Y1              = iNode.GetLocation().Y;
                        connection.Y2              = jNode.GetLocation().Y;
                        connection.Stroke          = new SolidColorBrush(Color.FromRgb(0, 0, 0));
                        connection.StrokeThickness = 4;
                        DrawCanvas.Children.Add(connection);
                    }
                }
            }
        }