示例#1
0
        protected void OnAddClick(object obj, EventArgs args)
        {
            var    bodyBox = new BodyBox(menu: this, homogeneous: false, spacing: 3);
            String bString = BodyCombo.ActiveText;

            if (bString != "Custom")
            {
                var body = Examples.solar_system.First(b => b.name == bString);
                if (!(body.parent == null || new_bodies.Exists(b => b.name.Text == body.parent.name)))
                {
                    body = Examples.solar_system_bodies.First(b => b.name == bString);
                }
                bodyBox.body = body;
                bodyBox.ReverseSet();
            }

            bodyBox.name.Text = BodyCombo.ActiveText;
            systembox.PackStart(bodyBox, true, true, 3);
            new_bodies.Add(bodyBox);
            foreach (BodyBox b in new_bodies)
            {
                b.ResetParents();
            }
            this.ShowAll();
        }
示例#2
0
        public void Remove(BodyBox b)
        {
            var name = b.name.Text;

            new_bodies.Remove(b);
            systembox.Remove(b);
            foreach (BodyBox a in new_bodies)
            {
                a.ResetParents();
            }
        }
示例#3
0
        protected void OnLoadClick(object obj, EventArgs args)
        {
            System.Xml.Serialization.XmlSerializer reader =
                new System.Xml.Serialization.XmlSerializer(typeof(SaveData));
            SaveData data = new SaveData(); // To prevent compiler error

            if (temp_savedata != null)
            {
                data          = temp_savedata;
                temp_savedata = null;
            }
            else
            {
                try {
                    var file = new StreamReader(Environment.CurrentDirectory + "//" + filename.Text + ".xml");
                    data = (SaveData)reader.Deserialize(file);
                } catch (IOException) {
                    // Try in the system directory
                    try {
                        var file = new StreamReader(Environment.CurrentDirectory + "//" + SYSTEM_DIRECTORY + "//" + filename.Text + ".xml");
                        data = (SaveData)reader.Deserialize(file);
                    } catch (IOException) {
                        Message("The specified file could not be found. Check that the name is spelt correctly and that it is in the correct directory");
                        // cannot deserialize, exit
                        return;
                    }
                } catch (InvalidOperationException) {
                    Message("The file is not a valid save file of this project");
                    // cannot deserialize, exit
                    return;
                }
            }
            RScale.Value        = data.radius_multiplier;
            LineScale.Value     = data.line_max;
            TimestepScale.Value = data.timestep;
            new_bodies.Clear();
            foreach (Widget w in systembox.Children)
            {
                if (w is BodyBox)
                {
                    systembox.Remove(w);
                }
            }
            for (int i = 0; i < data.bodies.Count; i++)
            {
                var bbox = new BodyBox(menu: this, homogeneous: false, spacing: 3)
                {
                    body = data.bodies[i],
                };
                bbox.CenterButton.Active = data.centers[i];
                if (data.elements != null && data.elements.Count != 0)
                {
                    bbox.SetElements(data.elements[i]);
                    bbox.ReverseSet(false);
                }
                else
                {
                    bbox.ReverseSet();
                }
                new_bodies.Add(bbox);
                systembox.PackStart(bbox, true, true, 3);
            }
            foreach (BodyBox b in new_bodies)
            {
                b.ResetParents();
            }
            this.ShowAll();
        }