public FreeChargeSettings(FreeCharge charge)
        {
            InitializeComponent();

            lblLocation.Content = "Location : (" + charge.RenderTransform.Value.OffsetX + "," +
                                  charge.RenderTransform.Value.OffsetY + ")";
        }
Пример #2
0
        private void AddNewFreeChargeClick(object sender, RoutedEventArgs e)
        {
            var freecharge = new FreeCharge();

            freecharge.Margin              = new Thickness(0, 0, 0, 0);
            freecharge.VerticalAlignment   = VerticalAlignment.Top;
            freecharge.HorizontalAlignment = HorizontalAlignment.Left;
            freecharge.MyCharge            = new Charge();
            freecharge.Height              = 12;
            freecharge.Width = 12;

            string chargename = "Free-charge " + (TotalFrees() + 1).ToString(CultureInfo.InvariantCulture);
            int    counter    = 1;

            while (CheckExistingChargeWithName(chargename))
            {
                counter++;
                chargename = "Free-charge " + (TotalFrees() + counter).ToString(CultureInfo.InvariantCulture);
            }
            freecharge.MyCharge.Name = chargename;

            var group = new TransformGroup();

            var transfer = new TranslateTransform
            {
                X = Helper.RandomNumber(10, (int)gridField.Width - 45),
                Y = Helper.Clamp(Helper.RandomNumber(10, ((int)gridField.Height - 35) / 2), 0,
                                 (int)gridField.Height - 65)
            };

            gridField.Children.Add(freecharge);
            group.Children.Add(transfer);
            freecharge.StartPoint      = new Point(transfer.X, transfer.Y);
            freecharge.RenderTransform = group;

            FieldOutline.Update();
        }
Пример #3
0
        public int NearestDistancetoNegative(FreeCharge freeCharge)
        {
            int nearestDistance = 100000;
            var location1       = new Point((int)freeCharge.RenderTransform.Value.OffsetX,
                                            (int)freeCharge.RenderTransform.Value.OffsetY);

            foreach (object uiElement in gridField.Children)
            {
                if (uiElement.GetType() == typeof(NegativeCharge))
                {
                    var location2 = new Point((int)((NegativeCharge)uiElement).RenderTransform.Value.OffsetX + 16,
                                              (int)((NegativeCharge)uiElement).RenderTransform.Value.OffsetY + 16);

                    var distance = (int)Helper.Distance(location1, location2);
                    if (distance < nearestDistance)
                    {
                        nearestDistance = distance;
                    }
                }
            }


            return(nearestDistance);
        }
        private void BtnDrawClick(object sender, RoutedEventArgs e)
        {
            if (cmbFloat.SelectedIndex == -1 || cmbStatic.SelectedIndex == -1)
            {
                MessageBox.Show("Fill all fields!!");
                return;
            }

            int duration = 10;
            var startloc = new Point((double)integerUDStartX.Value, (double)integerUDStartY.Value);

            if (integerUDDuration.Value != null)
            {
                duration = (int)integerUDDuration.Value;
            }

            var slver = new Solver(_charges, _surfaces, ImageHieght, ImageWidth);

            slver.SolveIt();


            FreeCharge     freeCharge     = null;
            PositiveCharge positiveCharge = null;
            NegativeCharge negativeCharge = null;

            IEnumerable <UIElement> allitems = MainWindow.Instance.GetListOfItems();

            foreach (UIElement chargeitem in allitems)
            {
                if (chargeitem.GetType() == typeof(FreeCharge))
                {
                    string name = ((FreeCharge)chargeitem).MyCharge.Name;
                    if ((string)cmbFloat.SelectedValue == name)
                    {
                        freeCharge = ((FreeCharge)chargeitem);
                    }
                }
                else if (chargeitem.GetType() == typeof(PositiveCharge))
                {
                    string name = ((PositiveCharge)chargeitem).MyCharge.Name;
                    if ((string)cmbStatic.SelectedValue == name)
                    {
                        positiveCharge = ((PositiveCharge)chargeitem);
                    }
                }
                else if (chargeitem.GetType() == typeof(NegativeCharge))
                {
                    string name = ((NegativeCharge)chargeitem).MyCharge.Name;
                    if ((string)cmbStatic.SelectedValue == name)
                    {
                        negativeCharge = ((NegativeCharge)chargeitem);
                    }
                }
            }


            if (freeCharge != null)
            {
                var Orgins = new Point();
                if (positiveCharge != null)
                {
                    Orgins = new Point(positiveCharge.RenderTransform.Value.OffsetX,
                                       positiveCharge.RenderTransform.Value.OffsetY);
                }
                else if (negativeCharge != null)
                {
                    Orgins = new Point(negativeCharge.RenderTransform.Value.OffsetX,
                                       negativeCharge.RenderTransform.Value.OffsetY);
                }

                var returnedData = (List <Point>)slver.ChargeChargeDistance(freeCharge, Orgins, duration, startloc);

                var graphOutput = new GraphWindow("Distance", "Time");
                graphOutput.DrawThis(returnedData, Brushes.DarkRed, Brushes.DarkMagenta, "Distance");

                if (returnedData != null)
                {
                    IEnumerable <Point> velcocity = Helper.CalculateVelocity(returnedData);
                    graphOutput.DrawThis(velcocity, Brushes.DodgerBlue, Brushes.LightSkyBlue, "Velocity");
                }


                graphOutput.Show();
            }


            Close();
        }