Example #1
0
        public static ShapeManager LoadFromFile(string filename)
        {
            XDocument    document = XDocument.Load(filename);
            ShapeManager manager  = new ShapeManager();

            foreach (XElement shapeElement in document.Root.Elements())
            {
                if (shapeElement.Name == "StateShape")
                {
                    StateShape state = new StateShape();
                    state.Name     = shapeElement.Attribute("Name").Value;
                    state.Color    = shapeElement.Attribute("Color").Value;
                    state.Position = new Point(int.Parse(shapeElement.Attribute("X").Value), int.Parse(shapeElement.Attribute("Y").Value));
                    state.Radius   = int.Parse(shapeElement.Attribute("R").Value);
                    state.Type     = (StateType)Enum.Parse(typeof(StateType), shapeElement.Attribute("Type").Value);

                    manager.AddShape(state);
                }
                else if (shapeElement.Name == "ArrowShape")
                {
                    ArrowShape arrow = new ArrowShape();
                    arrow.Name         = shapeElement.Attribute("Name").Value;
                    arrow.ControlPoint = new Point(int.Parse(shapeElement.Attribute("X").Value), int.Parse(shapeElement.Attribute("Y").Value));
                    arrow.Radius       = int.Parse(shapeElement.Attribute("R").Value);
                    arrow.Start        = (StateShape)manager.Shapes[StateShape.StateShapeProprity][int.Parse(shapeElement.Attribute("Start").Value)];
                    arrow.End          = (StateShape)manager.Shapes[StateShape.StateShapeProprity][int.Parse(shapeElement.Attribute("End").Value)];

                    arrow.Start.OutArrows.Add(arrow);
                    arrow.End.InArrows.Add(arrow);
                    manager.AddShape(arrow);
                }
            }
            return(manager);
        }
Example #2
0
        public void SaveToFile(string filename)
        {
            XDocument document = new XDocument(
                new XElement("ShapeManager",
                             this.Shapes.Values.SelectMany(v => v).Select(s =>
            {
                StateShape state = s as StateShape;
                ArrowShape arrow = s as ArrowShape;
                if (state != null)
                {
                    return(new XElement("StateShape",
                                        new XAttribute("Name", state.Name),
                                        new XAttribute("Color", state.Color),
                                        new XAttribute("X", state.Position.X),
                                        new XAttribute("Y", state.Position.Y),
                                        new XAttribute("R", state.Radius),
                                        new XAttribute("Type", state.Type)
                                        ));
                }
                else
                {
                    return(new XElement("ArrowShape",
                                        new XAttribute("Name", arrow.Name),
                                        new XAttribute("X", arrow.ControlPoint.X),
                                        new XAttribute("Y", arrow.ControlPoint.Y),
                                        new XAttribute("R", arrow.Radius),
                                        new XAttribute("Start", this.Shapes[StateShape.StateShapeProprity].IndexOf(arrow.Start)),
                                        new XAttribute("End", this.Shapes[StateShape.StateShapeProprity].IndexOf(arrow.End))
                                        ));
                }
            })
                             )
                );

            document.Save(filename);
        }