예제 #1
0
        private SVGUnit AddMetaData(SVGUnit parent, ref SVGUnit last)
        {
            SVGMetaData metaData = new SVGMetaData(this);

            AddElement(parent, metaData, ref last);
            return(metaData);
        }
예제 #2
0
        /// <summary>
        /// 它返回具有给定XML ID的svgelement。
        /// </summary>
        public SVGUnit GetSvgElement(string sId)
        {
            SVGUnit eleToReturn = null;

            IDictionaryEnumerator e = m_elements.GetEnumerator();

            bool bLoop = e.MoveNext();

            while (bLoop)
            {
                string sValue = "";

                SVGUnit ele = (SVGUnit)e.Value;
                sValue = ele.GetAttributeStringValue(SVGAttribute._SvgAttribute.attrCore_Id);
                if (sValue == sId)
                {
                    eleToReturn = ele;
                    bLoop       = false;
                }

                bLoop = e.MoveNext();
            }

            return(eleToReturn);
        }
예제 #3
0
        private SVGUnit AddUse(SVGUnit parent, ref SVGUnit last)
        {
            SVGUse svgUse = new SVGUse(this);

            AddElement(parent, svgUse, ref last);
            return(svgUse);
        }
예제 #4
0
        private SVGUnit AddSymbols(SVGUnit parent, ref SVGUnit last)
        {
            SVGSymbol svgSymbol = new SVGSymbol(this);

            AddElement(parent, svgSymbol, ref last);
            return(svgSymbol);
        }
예제 #5
0
        private SVGUnit AddDefs(SVGUnit parent, ref SVGUnit last)
        {
            SVGDef svgDef = new SVGDef(this);

            AddElement(parent, svgDef, ref last);
            return(svgDef);
        }
예제 #6
0
        private SVGUnit AddCN_Ref(SVGUnit parent, ref SVGUnit last)
        {
            SVGCN_Ref svgcnRef = new SVGCN_Ref(this);

            AddElement(parent, svgcnRef, ref last);
            return(svgcnRef);
        }
예제 #7
0
        private SVGUnit AddDevicePort(SVGUnit parent, ref SVGUnit last)
        {
            SVGDevicePort port = new SVGDevicePort(this);

            AddElement(parent, port, ref last);

            return(port);
        }
예제 #8
0
        public SVGAnimate AddAnimate(SVGUnit parent, ref SVGUnit last)
        {
            SVGAnimate svgAnimate = new SVGAnimate(this);

            AddElement(parent, svgAnimate, ref last);

            return(svgAnimate);
        }
예제 #9
0
        /// <summary>
        /// 它创建了一个新的svg group元素。
        /// </summary>
        public SVGGroup AddGroup(SVGUnit parent, ref SVGUnit last)
        {
            SVGGroup grp = new SVGGroup(this);

            AddElement(parent, grp, ref last);

            return(grp);
        }
예제 #10
0
        /// <summary>
        /// 它创建了一个新的不支持SVG的元素。
        /// </summary>
        public SVGUnSupported AddUnsupported(SVGUnit parent, string sName, ref SVGUnit last)
        {
            SVGUnSupported uns = new SVGUnSupported(this, sName);

            AddElement(parent, uns, ref last);

            return(uns);
        }
예제 #11
0
        /// <summary>
        /// 它创建了一个新的SVG路径元素。
        /// </summary>
        public SVGPath AddPath(SVGUnit parent, ref SVGUnit last)
        {
            SVGPath path = new SVGPath(this);

            AddElement(parent, path, ref last);

            return(path);
        }
예제 #12
0
        /// <summary>
        /// 它创建一个新的SVG多边形元素。
        /// </summary>
        public SVGPolygon AddPolygon(SVGUnit parent, ref SVGUnit last)
        {
            SVGPolygon poly = new SVGPolygon(this);

            AddElement(parent, poly, ref last);

            return(poly);
        }
예제 #13
0
        /// <summary>
        /// 它创建了一个新的SVG椭圆元素。
        /// </summary>
        public SVGEllipse AddEllipse(SVGUnit parent, ref SVGUnit last)
        {
            SVGEllipse ellipse = new SVGEllipse(this);

            AddElement(parent, ellipse, ref last);

            return(ellipse);
        }
예제 #14
0
        /// <summary>
        /// 它创建了一个新的SVG行元素。
        /// </summary>
        public SVGLine AddLine(SVGUnit parent, ref SVGUnit last)
        {
            SVGLine line = new SVGLine(this);

            AddElement(parent, line, ref last);

            return(line);
        }
예제 #15
0
        /// <summary>
        /// 它创建一个新的svg rect元素。
        /// </summary>
        public SVGRect AddRect(SVGUnit parent, ref SVGUnit last)
        {
            SVGRect rect = new SVGRect(this);

            AddElement(parent, rect, ref last);

            return(rect);
        }
예제 #16
0
        /// <summary>
        /// 它创建了一个新的svg circle元素。
        /// </summary>
        public SVGCircle AddCircle(SVGUnit parent, ref SVGUnit last)
        {
            SVGCircle circle = new SVGCircle(this);

            AddElement(parent, circle, ref last);

            return(circle);
        }
예제 #17
0
        /// <summary>
        /// 它创建了一个新的SVG图像元素。
        /// </summary>
        public SVGImage AddImage(SVGUnit parent, ref SVGUnit last)
        {
            SVGImage img = new SVGImage(this);

            AddElement(parent, img, ref last);

            return(img);
        }
예제 #18
0
        /// <summary>
        /// 它创建一个新的SVG文本元素。
        /// </summary>
        public SVGText AddText(SVGUnit parent, ref SVGUnit last)
        {
            SVGText txt = new SVGText(this);

            AddElement(parent, txt, ref last);

            return(txt);
        }
예제 #19
0
        /// <summary>
        /// 它创建了一个新的svg desc元素。
        /// </summary>
        public SVGDesc AddDesc(SVGUnit parent, ref SVGUnit last)
        {
            SVGDesc desc = new SVGDesc(this);

            AddElement(parent, desc, ref last);

            return(desc);
        }
예제 #20
0
        /// <summary>
        /// 它创建一个新的SVG折线元素。
        /// </summary>
        public SVGPolyline AddPolyline(SVGUnit parent, ref SVGUnit last)
        {
            SVGPolyline poly = new SVGPolyline(this);

            AddElement(parent, poly, ref last);

            return(poly);
        }
예제 #21
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);
        }
예제 #22
0
        private bool IsLastSibling(SVGUnit ele)
        {
            SVGUnit last = GetLastSibling(ele);

            if (last == null)
            {
                return(false);
            }

            return(ele.getInternalId() == last.getInternalId());
        }
예제 #23
0
        private bool IsFirstChild(SVGUnit ele)
        {
            if (ele.getParent() == null)
            {
                return(false);
            }

            if (ele.getParent().getChild() == null)
            {
                return(false);
            }

            return(ele.getInternalId() == ele.getParent().getChild().getInternalId());
        }
예제 #24
0
        /// <summary>
        /// 它将元素在树层次结构中向上移动一级。
        /// </summary>
        public bool ElementLevelUp(SVGUnit ele)
        {
            SVGErr err = new SVGErr("SvgDoc", "ElementLevelUp");

            err.Log("Element to move " + ele.ElementInfo(), SVGErr._LogPriority.Info);

            SVGUnit parent = ele.getParent();

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

                return(false);
            }

            if (parent.getParent() == null)
            {
                err.Log("An element cannot be moved up to the root", SVGErr._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

            SVGUnit nxt = ele.getNext();

            // the first child of the parent became the next
            parent.setChild(nxt);

            if (nxt != null)
            {
                nxt.setPrevious(null);
            }

            // get the last sibling of the parent
            SVGUnit last = GetLastSibling(parent);

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

            ele.setParent(parent.getParent());
            ele.setPrevious(last);
            ele.setNext(null);

            return(true);
        }
예제 #25
0
        private SVGUnit GetLastSibling(SVGUnit ele)
        {
            if (ele == null)
            {
                return(null);
            }

            SVGUnit last = ele;

            while (last.getNext() != null)
            {
                last = last.getNext();
            }

            return(last);
        }
예제 #26
0
        /// <summary>
        /// 它将新元素eletoadd添加为给定父元素的最后一个子元素。
        /// </summary>
        public void AddElement(SVGUnit parent, SVGUnit eleToAdd, ref SVGUnit last)
        {
            SVGErr err = new SVGErr("SvgDoc", "AddElement");

            if (eleToAdd == null || m_root == null)
            {
                err.LogEnd(false);
                return;
            }

            SVGUnit parentToAdd = m_root;

            if (parent != null)
            {
                parentToAdd = parent;
            }

            eleToAdd.setInternalId(m_nNextId++);
            m_elements.Add(eleToAdd.getInternalId(), eleToAdd);

            eleToAdd.setParent(parentToAdd);
            if (parentToAdd.getChild() == null)
            {
                // 元素是第一个子元素
                parentToAdd.setChild(eleToAdd);
                last = eleToAdd;
            }
            else
            {
                // 将元素添加为最后一个同级
                //SvgElement last = GetLastSibling(parentToAdd.getChild());

                if (last != null)
                {
                    last.setNext(eleToAdd);
                    eleToAdd.setPrevious(last);
                    last = eleToAdd;
                }
                else
                {
                    last = parentToAdd.getChild();
                }
            }

            err.Log(eleToAdd.ElementInfo(), SVGErr._LogPriority.Info);
            err.LogEnd(true);
        }
예제 #27
0
        public static DrawObject CreateDrawObject(SVGUnit svge)
        {
            DrawObject o = null;

            switch (svge.getElementType())
            {
            case SVGUnit.SVGUnitType.typeLine:
                o = DrawLineObject.Create((SVGLine)svge);
                break;

            case SVGUnit.SVGUnitType.typeRect:
                o = DrawRectangleObject.Create((SVGRect)svge);
                break;

            case SVGUnit.SVGUnitType.typeEllipse:
                o = DrawEllipseObject.Create((SVGEllipse)svge);
                break;

            case SVGUnit.SVGUnitType.typePolyline:
                o = DrawPolygonObject.Create((SVGPolyline)svge);
                break;

            case SVGUnit.SVGUnitType.typeImage:
                o = DrawImageObject.Create((SVGImage)svge);
                break;

            case SVGUnit.SVGUnitType.typeText:
                o = DrawTextObject.Create((SVGText)svge);
                break;

            case SVGUnit.SVGUnitType.typePath:
                o = DrawPathObject.Create((SVGPath)svge);
                break;

            case SVGUnit.SVGUnitType.typeCircle:
                o = DrawCircleObject.Create((SVGCircle)svge);
                break;

            default:
                break;
            }
            return(o);
        }
예제 #28
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);
        }
예제 #29
0
        public bool LoadModelFromXml(string fileName)
        {
            var svgForm = new WorkspaceHolder {
                Dock = DockStyle.Fill, Name = fileName
            };

            svgForm.svgDrawForm.ToolDone      += OnToolDoneComplete;
            svgForm.svgDrawForm.ItemsSelected += SvgDrawFormItemsSelected;

            svgForm.svgDrawForm.drawArea.Width  = 1600;
            svgForm.svgDrawForm.drawArea.Height = 900;

            XmlTextReader reader = null;

            //XmlReader reader = null;
            //var txt = File.ReadAllText(fileName);
            try
            {
                // FileStream fs = new FileStream(fileName,FileMode.Open);


                //reader =  XmlReader.Create(fileName);
                reader = new XmlTextReader(fileName);//从本地读取xml文件

                SVGErr.Log("DrawArea", "LoadFromXML", "", SVGErr._LogPriority.Info);
                var svg = new SVGWord();
                if (!svg.LoadFromFile(reader))
                {
                    return(false);
                }
                SVGRoot root = svg.GetSvgRoot();

                if (root == null)
                {
                    return(false);
                }
                SVGUnit ele = root.getChild();
                if (ele != null)
                {
                    //1 收集symbol获取svg上的设备
                    //2 从svg元数据中收集symbol之间的关系
                    //3 将所有use的设备实体生成
                    //4 绘制list集合将图素绘制出来
                    SVGFactory.CreateProjectFromXML(ele, svgForm.svgDrawForm.drawArea.GraphicsList);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            tabbedView.Add(svgForm);
            svgForm.Refresh();

            return(true);
        }
예제 #30
0
        /// <summary>
        /// 它将元素移动到当前的上一个同级之前。
        /// </summary>
        public bool ElementPositionUp(SVGUnit ele)
        {
            SVGErr err = new SVGErr("SvgDoc", "ElementPositionUp");

            err.Log("Element to move " + ele.ElementInfo(), SVGErr._LogPriority.Info);

            SVGUnit parent = ele.getParent();

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

                return(false);
            }

            if (IsFirstChild(ele))
            {
                err.Log("Element is already at the first position", SVGErr._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

            SVGUnit nxt  = ele.getNext();
            SVGUnit prv  = ele.getPrevious();
            SVGUnit prv2 = null;

            ele.setNext(null);
            ele.setPrevious(null);

            if (nxt != null)
            {
                nxt.setPrevious(prv);
            }

            if (prv != null)
            {
                prv.setNext(nxt);
                prv2 = prv.getPrevious();
                prv.setPrevious(ele);

                if (IsFirstChild(prv))
                {
                    if (prv.getParent() != null)
                    {
                        prv.getParent().setChild(ele);
                    }
                }
            }

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

            ele.setNext(prv);
            ele.setPrevious(prv2);

            err.Log("Element moved " + ele.ElementInfo(), SVGErr._LogPriority.Info);
            err.LogEnd(true);

            return(true);
        }