Beispiel #1
0
        static void TESTPopulateDb()
        {
            using (SqlServerContext context = new SqlServerContext())
            {
                PlanetarySystem    solarSystem = new PlanetarySystem("Solar system");
                Models.Bodies.Star sun         = new Models.Bodies.Star(
                    center: new Point(0, 0, 0),
                    mass: 2 * Math.Pow(10, 30),
                    radius: 5,
                    velocity: new Vector(0, 0, 0),
                    name: "Sun");

                Planet earth = new Planet(
                    center: new Point(0, 0, 0),
                    mass: 5.972 * Math.Pow(10, 24),
                    radius: 5,
                    velocity: new Vector(new Point(0, 0, 0)),
                    name: "Earth");
                Moon moon = new Moon(
                    center: new Point(0, 0, 0),
                    mass: 7.342 * Math.Pow(10, 22),
                    radius: 5,
                    velocity: new Vector(new Point(0, 0, 0)),
                    name: "Moon");


                solarSystem.SetStar(sun);
                solarSystem.AddPlanetByOrbitalRadius(earth, 150 * Math.Pow(10, 9), 0);
                //solarSystem.AddPlanetByOrbitalSpeed(earth, 29780);
                solarSystem.AddMoonByOrbitalRadius(moon, earth, 384000000, 0);
                //solarSystem.AttachMoonToPlanetByOrbitalSpeed(moon, earth, 1022);

                context.PlanetarySystems.Add(solarSystem);
                context.Stars.Add(sun);
                context.Planets.Add(earth);
                context.Moons.Add(moon);

                Console.WriteLine("presave");
                context.SaveChanges();
            }
        }
Beispiel #2
0
        private void createNewButton_Click(object sender, EventArgs e)
        {
            try
            {
                ClearCreateNewSection();
                double coveredAngle = 0;
                try
                {
                    coveredAngle = double.Parse(createNewCoveredAngleBox.Text);
                }
                catch (Exception exc)
                { }

                double mass             = 0;
                double radius           = 0;
                double orbitalParameter = 0;
                if (createNewTypeBox.SelectedIndex != 0)
                {
                    mass             = MathUtilities.ParseFromExpNotation(double.Parse(createNewMassBox.Text), int.Parse(createNewMassEBox.Text));
                    radius           = MathUtilities.ParseFromExpNotation(double.Parse(createNewRadiusBox.Text), int.Parse(createNewRadiusEBox.Text));
                    orbitalParameter = MathUtilities.ParseFromExpNotation(double.Parse(orbitalParameterBox.Text), int.Parse(orbitalParameterEBox.Text));
                }

                switch (createNewTypeBox.SelectedIndex)
                {
                case 0:
                    currentPlanetarySystem = new PlanetarySystem(createNewNameBox.Text);
                    Star star = new Star(
                        new PlanetSystem.Models.Utilities.Point(0, 0, 0),
                        1,
                        1,
                        createNewNameBox.Text + "\' star");
                    currentPlanetarySystem.SetStar(star);
                    break;

                case 1:
                    Planet planet = new Planet(
                        new PlanetSystem.Models.Utilities.Point(0, 0, 0),
                        mass,
                        radius,
                        createNewNameBox.Text);

                    if (orbitByRadiusRadio.Checked)
                    {
                        currentPlanetarySystem.AddPlanetByOrbitalRadius(
                            planet,
                            orbitalParameter,
                            coveredAngle);
                    }
                    else
                    {
                        currentPlanetarySystem.AddPlanetByOrbitalSpeed(
                            planet,
                            orbitalParameter,
                            coveredAngle);
                    }
                    break;

                case 2:
                    string planetName = createNewPrimeSelectionBox.Text;
                    var    primeQuery = from p in currentPlanetarySystem.Planets
                                        where p.Name == planetName
                                        select p;
                    var  prime = primeQuery.FirstOrDefault();
                    Moon moon  = new Moon(
                        new PlanetSystem.Models.Utilities.Point(0, 0, 0),
                        mass,
                        radius,
                        createNewNameBox.Text);

                    if (orbitByRadiusRadio.Checked)
                    {
                        currentPlanetarySystem.AddMoonByOrbitalRadius(
                            moon,
                            prime,
                            orbitalParameter,
                            coveredAngle);
                    }
                    else
                    {
                        currentPlanetarySystem.AddMoonByOrbitalSpeed(
                            moon,
                            prime,
                            orbitalParameter,
                            coveredAngle);
                    }
                    break;

                case 3:
                    Asteroid asteroid = new Asteroid(
                        new PlanetSystem.Models.Utilities.Point(0, 0, 0),
                        mass,
                        radius,
                        createNewNameBox.Text);
                    currentPlanetarySystem.AddAsteroid(asteroid);
                    break;

                case 4:
                    ArtificialObject artObj = new ArtificialObject(new PlanetSystem.Models.Utilities.Point(0, 0, 0),
                                                                   mass,
                                                                   radius,
                                                                   createNewNameBox.Text);
                    currentPlanetarySystem.AddArtificialObject(artObj);
                    break;
                }
                LoadPlanetarySystemToTree(currentPlanetarySystem);
                Backup();
            }
            catch (Exception exc)
            {
            }
        }