Пример #1
0
        public static CommandStack Deserialize(string XMLString)
        {
            CommandStack tr = new CommandStack();

            var xe = XElement.Parse(XMLString);

            if (xe.Name != "CommandStack")
            {
                return(null);
            }

            int count = int.Parse((xe.Nodes().First((x) => (x as XElement).Name == "Count") as XElement).Value);

            foreach (var node in xe.Nodes())
            {
                if ((node as XElement).Name == "Count")
                {
                    continue;
                }
                --count;
                tr.Push(UndoSerializer.Deserialize((xe.Nodes().First((x) => (x as XElement).Name == "c" + count.ToString()) as XElement).FirstNode.ToString()));
            }

            return(tr);
        }
        private OutsideSimulatorApp(string title)
            : base(title)
        {
            //
            // Dirtyables...
            //
            ProjMatrix = new Dirtyable<SlimDX.Matrix>(() =>
            {
                return SlimDX.Matrix.PerspectiveFovLH(0.25f * (float)Math.PI, AspectRatio, 0.1f, 10000.0f);
            });

            //
            // Subscribers...
            //
            KeyDownSubscribers = new List<KeyDownSubscriber>();
            KeyUpSubscribers = new List<KeyUpSubscriber>();
            MouseDownSubscribers = new List<MouseDownSubscriber>();
            MouseWheelSubscribers = new List<MouseWheelSubscriber>();
            MouseMoveSubscribers = new List<MouseMoveSubscriber>();
            MouseUpSubscribers = new List<MouseUpSubscriber>();
            TimerTickSubscribers = new List<TimerTickSubscriber>();

            CommandStack = new CommandStack();
            Subscribe(CommandStack);

            RenderEffects = new List<RenderEffect>();
        }
Пример #3
0
        public static CommandStack Deserialize(string XMLString)
        {
            CommandStack tr = new CommandStack();

            var xe = XElement.Parse(XMLString);

            if (xe.Name != "CommandStack")
            {
                return null;
            }

            int count = int.Parse((xe.Nodes().First((x) => (x as XElement).Name == "Count") as XElement).Value);

            foreach (var node in xe.Nodes())
            {
                if ((node as XElement).Name == "Count") continue;
                --count;
                tr.Push(UndoSerializer.Deserialize((xe.Nodes().First((x) => (x as XElement).Name == "c" + count.ToString()) as XElement).FirstNode.ToString()));
            }

            return tr;
        }
        /// <summary>
        ///  Load the scene from a file
        /// </summary>
        public void LoadScene()
        {
            var loadDialog = new OpenFileDialog();
            loadDialog.Filter = "Outside Simulator Scene (*.oss)|*.oss";

            var dr = loadDialog.ShowDialog();
            if (dr != DialogResult.OK)
            {
                MessageBox.Show("LoadScene aborted", "Outside Simulator");
                return;
            }

            var sr = new System.IO.StreamReader(loadDialog.FileName);

            var xe = XElement.Parse(sr.ReadToEnd());

            if (xe.Name != "OutsideSimulatorScene")
            {
                MessageBox.Show("LoadScene failed - file is not a valid OutsideSimulatorScene", "Outside Simulator");
                return;
            }

            var sg = SceneGraph.Deserialize(
                (xe.Nodes().First((x) => (x as XElement).Name == "SceneGraph") as XElement).Nodes().First((x) => (x as XElement).Name == "SceneGraph").ToString()
            );
            // I will add this back in... Maybe.
            //var cs = CommandStack.Deserialize(
            //    (xe.Nodes().First((x) => (x as XElement).Name == "CommandStack") as XElement).Nodes().First((x) => (x as XElement).Name == "CommandStack").ToString()
            //);

            SceneGraph.Children.Remove("Scene");
            SceneGraph.AttachChild("Scene", sg);
            //CommandStack = cs;
            CommandStack = new CommandStack();
        }