public static void ParseProperties(XmlElement itemnode, object dataobject)
 {
     foreach (XmlElement propertynode in itemnode.ChildNodes)
     {
         XmlUtil.ParseProperty(propertynode, dataobject);
     }
 }
Exemple #2
0
        /// <summary>
        /// 加载文件
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public bool Load(string filename)
        {
            try
            {
                StreamReader sr = new StreamReader(filename);
                //XmlTextReader rd = new XmlTextReader(sr);
                XmlDocument doc = new XmlDocument();
                doc.Load(sr);
                sr.Dispose();
                XmlElement root = doc.DocumentElement;
                if (root.Name != "CanvasDataModel")
                {
                    return(false);
                }

                m_layers.Clear();
                m_undoBuffer.Clear();
                m_undoBuffer.Dirty = false;
                foreach (XmlElement childnode in root.ChildNodes)
                {
                    if (childnode.Name == "backgroundlayer")
                    {
                        XmlUtil.ParseProperties(childnode, m_backgroundLayer);
                        continue;
                    }
                    if (childnode.Name == "gridlayer")
                    {
                        XmlUtil.ParseProperties(childnode, m_gridLayer);
                        continue;
                    }
                    if (childnode.Name == "layer")
                    {
                        DrawingLayer l = DrawingLayer.NewLayer(childnode as XmlElement);
                        m_layers.Add(l);
                    }

                    if (childnode.Name == "property")
                    {
                        XmlUtil.ParseProperty(childnode, this);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                DefaultLayer();
                Console.WriteLine("Load exception - {0}", e.Message);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// 新绘制图层
        /// </summary>
        /// <param name="xmlelement"></param>
        /// <returns></returns>
        public static DrawingLayer NewLayer(XmlElement xmlelement)
        {
            string id = xmlelement.GetAttribute("Id");

            if (id.Length == 0)
            {
                id = Guid.NewGuid().ToString();
            }

            DrawingLayer layer = new DrawingLayer(id, string.Empty, Color.White, 0.0f);

            foreach (XmlElement node in xmlelement.ChildNodes)
            {
                XmlUtil.ParseProperty(node, layer);
                if (node.Name != "items")
                {
                    continue;
                }

                foreach (XmlElement itemnode in node.ChildNodes)
                {
                    object item = DataModel.NewDrawObject(itemnode.Name);
                    if (item == null)
                    {
                        continue;
                    }

                    if (item != null)
                    {
                        XmlUtil.ParseProperties(itemnode, item);
                    }

                    if (item is ISerialize)
                    {
                        ((ISerialize)item).AfterSerializedIn();
                    }

                    if (item is IDrawObject)
                    {
                        layer.AddObject(item as IDrawObject);
                    }
                }
            }
            return(layer);
        }