Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// It moves the element after its current next sibling.
        /// </summary>
        public bool ElementPositionDown(SVGUnit ele)
        {
            SVGErr err = new SVGErr("SvgDoc", "ElementPositionDown");

            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 (IsLastSibling(ele))
            {
                err.Log("Element is already at the last sibling position", SVGErr._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

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

            // fix Next
            if (nxt != null)
            {
                nxt.setPrevious(ele.getPrevious());
                nxt2 = nxt.getNext();
                nxt.setNext(ele);
            }

            // fix Previous
            if (prv != null)
            {
                prv.setNext(nxt);
            }

            // fix Element
            if (IsFirstChild(ele))
            {
                parent.setChild(nxt);
            }

            ele.setPrevious(nxt);
            ele.setNext(nxt2);

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

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

            return(true);
        }