Exemplo n.º 1
0
        private bool DeleteElement(SVGUnit ele, bool bDeleteFromParent)
        {
            SVGErr err = new SVGErr("SvgDoc", "DeleteElement");

            if (ele == null)
            {
                err.LogEnd(false);

                return(false);
            }

            SVGUnit parent = ele.getParent();

            if (parent == null)
            {
                err.Log("root node cannot be delete!", SVGErr._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

            if (ele.getPrevious() != null)
            {
                ele.getPrevious().setNext(ele.getNext());
            }

            if (ele.getNext() != null)
            {
                ele.getNext().setPrevious(ele.getPrevious());
            }

            if (bDeleteFromParent)
            {
                if (IsFirstChild(ele))
                {
                    ele.getParent().setChild(ele.getNext());
                }
            }

            SVGUnit child = ele.getChild();

            while (child != null)
            {
                DeleteElement(child, false);
                child = child.getNext();
            }

            m_elements.Remove(ele.getInternalId());

            err.Log(ele.ElementInfo(), SVGErr._LogPriority.Info);
            err.LogEnd(true);

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 它创建了一个新的元素,从eletoclone复制所有属性;新的
        /// 元素插入到提供的父元素下。
        /// </summary>
        public SVGUnit CloneElement(SVGUnit parent, SVGUnit eleToClone, SVGUnit last)
        {
            string sOldId = eleToClone.GetAttributeStringValue(SVGAttribute._SvgAttribute.attrCore_Id);
            string sNewId = sOldId;

            if (sOldId != "")
            {
                int i = 1;

                while (GetSvgElement(sNewId) != null)
                {
                    sNewId = sOldId + "_" + i.ToString();
                    i++;
                }
            }

            SVGUnit eleNew = AddElement(parent, eleToClone.getElementName(), ref last);

            eleNew.CloneAttributeList(eleToClone);

            if (sNewId != "")
            {
                eleNew.SetAttributeValue(SVGAttribute._SvgAttribute.attrCore_Id, sNewId);
            }

            if (eleToClone.getChild() != null)
            {
                eleNew.setChild(CloneElement(eleNew, eleToClone.getChild(), last));

                if (eleToClone.getChild().getNext() != null)
                {
                    eleNew.getChild().setNext(CloneElement(eleNew, eleToClone.getChild().getNext(), last));
                }
            }

            return(eleNew);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 它创建一个从文件读取的SVG文档。
        /// 如果当前文档存在,则会将其销毁。
        /// </summary>
        public bool LoadFromFile(XmlReader reader)
        {
            SVGErr err = new SVGErr("SvgDoc", "LoadFromFile");

            err.LogParameter("sFilename", reader.BaseURI);

            if (m_root != null)
            {
                m_root    = null;
                m_nNextId = 1;
                m_elements.Clear();
            }

            bool bResult = true;

            try
            {
                string  tmp;
                SVGUnit eleParent = null;
                SVGUnit eleLast   = null;

                try
                {
                    // 分析文件并显示每个节点。
                    while (reader.Read() && bResult)
                    {
                        switch (reader.NodeType)
                        {
                        case XmlNodeType.Attribute:
                            tmp = reader.Name;
                            tmp = reader.Value;
                            break;

                        case XmlNodeType.Element:    //找到一个标签
                        {
                            SVGUnit ele = AddElement(eleParent, reader.Name, ref eleLast);

                            if (ele == null)
                            {
                                err.Log("Svg element cannot be added. Name: " + reader.Name,
                                        SVGErr._LogPriority.Warning);
                                bResult = false;
                            }
                            else
                            {
                                eleParent = ele;

                                if (reader.IsEmptyElement)
                                {
                                    if (eleParent != null)
                                    {
                                        eleParent = eleParent.getParent();
                                    }
                                }

                                bool bLoop = reader.MoveToFirstAttribute();
                                while (bLoop)    //直到读完属性为止
                                {
                                    if (!ele.SetAttributeValue(reader.Name, reader.Value))
                                    {
                                        err.Log("Read AttributeValue : " + reader.Value, SVGErr._LogPriority.Warning);
                                    }

                                    bLoop = reader.MoveToNextAttribute();
                                }
                            }
                        }
                        break;

                        case XmlNodeType.Text:
                            if (eleParent != null)
                            {
                                eleParent.setElementValue(reader.Value);
                            }

                            break;

                        case XmlNodeType.CDATA:

                            err.Log("Unexpected item: " + reader.Value, SVGErr._LogPriority.Warning);
                            break;

                        case XmlNodeType.ProcessingInstruction:

                            err.Log("Unexpected item: " + reader.Value, SVGErr._LogPriority.Warning);
                            break;

                        case XmlNodeType.Comment:

                            err.Log("Unexpected item: " + reader.Value, SVGErr._LogPriority.Warning);
                            break;

                        case XmlNodeType.XmlDeclaration:
                            m_sXmlDeclaration = "<?xml " + reader.Value + "?>";
                            break;

                        case XmlNodeType.Document:
                            err.Log("Unexpected item: " + reader.Value, SVGErr._LogPriority.Warning);
                            break;

                        case XmlNodeType.DocumentType:
                        {
                            string sDTD1;
                            string sDTD2;

                            sDTD1 = reader.GetAttribute("PUBLIC");
                            sDTD2 = reader.GetAttribute("SYSTEM");

                            m_sXmlDocType = "<!DOCTYPE svg PUBLIC \"" + sDTD1 + "\" \"" + sDTD2 + "\">";
                        }
                        break;

                        case XmlNodeType.EntityReference:
                            err.Log("Unexpected item: " + reader.Value, SVGErr._LogPriority.Warning);
                            break;

                        case XmlNodeType.EndElement:
                            if (eleParent != null)
                            {
                                eleParent = eleParent.getParent();
                                eleLast   = null;
                                if (eleParent != null)
                                {
                                    var templast = eleParent.getChild();
                                    while (templast != null)
                                    {
                                        eleLast  = templast;
                                        templast = templast.getNext();
                                    }
                                }
                            }

                            break;
                        } // switch
                    }     // while
                }         // read try
                catch (XmlException xmle)
                {
                    err.LogException(xmle);
                    err.LogParameter("Line Number", xmle.LineNumber.ToString());
                    err.LogParameter("Line Position", xmle.LinePosition.ToString());

                    bResult = false;
                }
                catch (Exception e)
                {
                    err.LogException(e);
                    bResult = false;
                }
                finally
                {
                    reader.Close();
                }
            }
            catch
            {
                err.LogUnhandledException();
                bResult = false;
            }

            err.LogEnd(bResult);

            return(bResult);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据读取的xml生成项目
        /// </summary>
        /// <param name="svg"></param>
        public static void CreateProjectFromXML(SVGUnit svg, DrawObjectList list)
        {
            while (svg != null)
            {
                switch (svg.getElementType())
                {
                case SVGUnit.SVGUnitType.def:    //将所有symbol读取
                    SVGUnit defchild = svg.getChild();
                    while (defchild != null)
                    {
                        if (defchild.getElementType() == SVGUnit.SVGUnitType.symbol)
                        {
                            CreateSysmbolUnit(defchild as SVGSymbol);
                        }

                        defchild = defchild.getNext();
                    }
                    break;

                case SVGUnit.SVGUnitType.typeGroup:
                    if (svg.Id == SVGDefine.ConnectLineClass)
                    {
                        SVGGroup          group             = svg.getChild() as SVGGroup;
                        DrawConnectObject drawConnectObject = DrawConnectObject.Create(group.getChild() as SVGPath);
                        SVGCN_Ref         svgcnRef          = group.getChild().getNext().getChild() as SVGCN_Ref;
                        var linkDnd = svgcnRef.LinkObjecttlDnd.Split('@');

                        drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 1, int.Parse(linkDnd[1]), list.GetDeviceList());
                        linkDnd = svgcnRef.LinkObjectIDznd.Split('@');
                        drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 2, int.Parse(linkDnd[1]), list.GetDeviceList());

                        drawConnectObject.Id = int.Parse(group.Id);
                        list.Add(drawConnectObject);
                        group = group.getNext() as SVGGroup;
                    }
                    else if (svg.Id == SVGDefine.AnimationClass)
                    {
                    }
                    else
                    {
                        SVGGroup group = svg.getChild() as SVGGroup;
                        while (group != null)
                        {
                            var gchild = group.getChild();
                            switch (gchild.getElementType())
                            {
                            case SVGUnit.SVGUnitType.use:
                                SVGUse use     = gchild as SVGUse;
                                var    gDevice = CreateDeviceDrawObjectBase(use, group.Id);     //TODO 后期添加到工作组中
                                list.Add(gDevice);
                                break;

                            default:
                                //TODO 未编排为设备的图素集合,暂时用临时分组表示
                                var o = SVGDrawFactory.CreateDrawObject(svg);
                                list.Add(o);
                                //vBase = new DeviceDrawObjectBase(0f, 0f, 0f, 0f, group.Id, drawObjects, null, "");
                                break;
                            }
                            group = group.getNext() as SVGGroup;    //获取下一个
                        }
                    }


                    break;

                default: break;
                }

                svg = svg.getNext();
            }
        }