Example #1
0
        private void loadSceneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "xml files (*.xml)|*.xml";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                XmlSerializer ser = new XmlSerializer(typeof(DummyXML));
                FileStream    fs  = new FileStream(dialog.FileName, FileMode.Open);
                DummyXML      xml = (DummyXML)ser.Deserialize(fs);
                RefreshTimer.Stop();
                BindingList <Camera> newCameras = new BindingList <Camera>();
                Lights.Clear();
                Figures.Clear();
                xml.Cameras.ForEach(c => newCameras.Add(new Camera(c)));
                xml.Lights.ForEach(l => Lights.Add(new Light(l)));
                xml.Cuboids.ForEach(f => Figures.Add(new Cuboid(f)));
                xml.Spheres.ForEach(f => Figures.Add(new Sphere(f)));
                xml.Cylinders.ForEach(f => Figures.Add(new Cylinder(f)));
                xml.Cones.ForEach(f => Figures.Add(new Cone(f)));
                Cameras = newCameras;
                CameraListBox.DataSource = Cameras;
                CameraListBox.ClearSelected();
                CameraListBox.SetSelected(0, true);
                SelectedCamera = Cameras.First();
                if (Cameras.Count == 1)
                {
                    RemoveCameraButton.Enabled = false;
                }
                else
                {
                    RemoveCameraButton.Enabled = true;
                }
                if (Lights.Count != 0)
                {
                    LightListBox.ClearSelected();
                    LightListBox.SetSelected(0, true);
                    SelectedLight             = Lights[0];
                    LightGroupBox.Enabled     = true;
                    RemoveLightButton.Enabled = true;
                }
                else
                {
                    SelectedLight = null;
                    LightListBox.ClearSelected();
                    LightGroupBox.Enabled     = false;
                    RemoveLightButton.Enabled = false;
                }
                Lights.ResetBindings();
                CameraListBox.SelectedIndex = 0;
                FigureDataGrid.Refresh();
                RefreshTimer.Start();
            }
        }
Example #2
0
        private void saveSceneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "xml files (*.xml)|*.xml";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                List <CameraXML> cams = new List <CameraXML>();
                foreach (Camera c in Cameras)
                {
                    cams.Add(new CameraXML(c));
                }
                List <LightXML> l = new List <LightXML>();
                foreach (Light light in Lights)
                {
                    l.Add(new LightXML(light));
                }

                List <CuboidXML>   cuboids   = new List <CuboidXML>();
                List <SphereXML>   spheres   = new List <SphereXML>();
                List <CylinderXML> cylinders = new List <CylinderXML>();
                List <ConeXML>     cones     = new List <ConeXML>();
                foreach (IFigure f in Figures)
                {
                    if (f is Cuboid)
                    {
                        cuboids.Add(new CuboidXML(f as Cuboid));
                    }
                    else if (f is Sphere)
                    {
                        spheres.Add(new SphereXML(f as Sphere));
                    }
                    else if (f is Cylinder)
                    {
                        cylinders.Add(new CylinderXML(f as Cylinder));
                    }
                    else if (f is Cone)
                    {
                        cones.Add(new ConeXML(f as Cone));
                    }
                }
                DummyXML xml = new DummyXML {
                    Cameras = cams, Lights = l, Cuboids = cuboids, Spheres = spheres, Cylinders = cylinders, Cones = cones
                };
                XmlSerializer ser    = new XmlSerializer(typeof(DummyXML), new Type[] { typeof(CuboidXML), typeof(SphereXML), typeof(CylinderXML), typeof(ConeXML) });
                TextWriter    writer = new StreamWriter(dialog.FileName);
                ser.Serialize(writer, xml);
                writer.Close();
            }
        }