예제 #1
0
 /// <summary>
 /// Encodes the given mxGraphModel by writing a (flat) XML sequence
 /// of cell nodes as produced by the mxCellCodec. The sequence is
 /// wrapped-up in a node with the name root.
 /// </summary>
 protected override void EncodeObject(mxCodec enc, Object obj, XmlNode node)
 {
     if (obj is mxGraphModel)
     {
         XmlNode      rootNode = enc.Document.CreateElement("root");
         mxGraphModel model    = (mxGraphModel)obj;
         enc.EncodeCell((mxICell)model.Root, rootNode, true);
         node.AppendChild(rootNode);
     }
 }
예제 #2
0
        /// <summary>
        /// Reads the cells into the graph model. All cells are children of the root
        /// element in the node.
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object into)
        {
            if (node is XmlElement)
            {
                XmlElement elt = (XmlElement)node;
                mxGraphModel model = null;

                if (into is mxGraphModel)
                {
                    model = (mxGraphModel)into;
                }
                else
                {
                    model = new mxGraphModel();
                }

                // Reads the cells into the graph model. All cells
                // are children of the root element in the node.
                XmlNode root = elt.GetElementsByTagName("root")[0];
                mxICell rootCell = null;

                if (root != null)
                {
                    XmlNode tmp = root.FirstChild;

                    while (tmp != null)
                    {
                        mxICell cell = dec.DecodeCell(tmp, true);

                        if (cell != null && cell.Parent == null)
                        {
                            rootCell = cell;
                        }

                        tmp = tmp.NextSibling;
                    }

                    root.ParentNode.RemoveChild(root);
                }

                // Sets the root on the model if one has been decoded
                if (rootCell != null)
                {
                    model.Root = rootCell;
                }
            }

            return node;
        }
예제 #3
0
        /// <summary>
        /// Reads the cells into the graph model. All cells are children of the root
        /// element in the node.
        /// </summary>
        public override XmlNode BeforeDecode(mxCodec dec, XmlNode node, Object into)
        {
            if (node is XmlElement)
            {
                XmlElement   elt   = (XmlElement)node;
                mxGraphModel model = null;

                if (into is mxGraphModel)
                {
                    model = (mxGraphModel)into;
                }
                else
                {
                    model = new mxGraphModel();
                }

                // Reads the cells into the graph model. All cells
                // are children of the root element in the node.
                XmlNode root     = elt.GetElementsByTagName("root")[0];
                mxICell rootCell = null;

                if (root != null)
                {
                    XmlNode tmp = root.FirstChild;

                    while (tmp != null)
                    {
                        mxICell cell = dec.DecodeCell(tmp, true);

                        if (cell != null && cell.Parent == null)
                        {
                            rootCell = cell;
                        }

                        tmp = tmp.NextSibling;
                    }

                    root.ParentNode.RemoveChild(root);
                }

                // Sets the root on the model if one has been decoded
                if (rootCell != null)
                {
                    model.Root = rootCell;
                }
            }

            return(node);
        }