Ejemplo n.º 1
0
        /// <summary>
        /// It moves the element one level up in the tree hierarchy.
        /// </summary>
        /// <param name="ele">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementLevelUp(SvgElement ele)
        {
            ErrH err = new ErrH("SvgDoc", "ElementLevelUp");

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

            SvgElement parent = ele.getParent();

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

                return(false);
            }

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

                return(false);
            }

            SvgElement 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
            SvgElement last = GetLastSibling(parent);

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

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

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// It adds the new element eleToAdd as the last children of the given parent element.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToAdd">Element to be added.</param>
        public void AddElement(SvgElement parent, SvgElement eleToAdd, ref SvgElement last)
        {
            ErrH err = new ErrH("SvgDoc", "AddElement");

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

            SvgElement 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)
            {
                // the element is the first child
                parentToAdd.setChild(eleToAdd);
                last = eleToAdd;
            }
            else
            {
                // add the element as the last sibling
                //SvgElement last = GetLastSibling(parentToAdd.getChild());

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

            err.Log(eleToAdd.ElementInfo(), ErrH._LogPriority.Info);
            err.LogEnd(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// It moves the element after its current next sibling.
        /// </summary>
        /// <param name="ele">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionDown(SvgElement ele)
        {
            ErrH err = new ErrH("SvgDoc", "ElementPositionDown");

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

            SvgElement parent = ele.getParent();

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

                return(false);
            }

            if (IsLastSibling(ele))
            {
                err.Log("Element is already at the last sibling position", ErrH._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

            SvgElement nxt  = ele.getNext();
            SvgElement nxt2 = null;
            SvgElement 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(), ErrH._LogPriority.Info);
            err.LogEnd(true);

            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// It moves the element before its current previous sibling.
        /// </summary>
        /// <param name="ele">Element to be moved.</param>
        /// <returns>
        /// true if the operation succeeded.
        /// </returns>
        public bool ElementPositionUp(SvgElement ele)
        {
            ErrH err = new ErrH("SvgDoc", "ElementPositionUp");

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

            SvgElement parent = ele.getParent();

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

                return(false);
            }

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

                return(false);
            }

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

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

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

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

                // check if the Previous is the first child
                if (IsFirstChild(prv))
                {
                    // if yes the moved element has to became the new first child
                    if (prv.getParent() != null)
                    {
                        prv.getParent().setChild(ele);
                    }
                }
            }

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

            // fix Element
            ele.setNext(prv);
            ele.setPrevious(prv2);

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

            return(true);
        }
Ejemplo n.º 5
0
        // ---------- PUBLIC METHODS END

        // ---------- PRIVATE METHODS

        private bool DeleteElement(SvgElement ele, bool bDeleteFromParent)
        {
            ErrH err = new ErrH("SvgDoc", "DeleteElement");

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

                return(false);
            }

            SvgElement parent = ele.getParent();

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

                return(false);
            }

            // set the Next reference of the previous
            if (ele.getPrevious() != null)
            {
                ele.getPrevious().setNext(ele.getNext());
            }

            // set the Previous reference of the next
            if (ele.getNext() != null)
            {
                ele.getNext().setPrevious(ele.getPrevious());
            }

            // check if the element is the first child
            // the bDeleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if (bDeleteFromParent)
            {
                if (IsFirstChild(ele))
                {
                    // set the Child reference of the parent to the next
                    ele.getParent().setChild(ele.getNext());
                }
            }

            // delete its children
            SvgElement child = ele.getChild();

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

            // delete the element from the colloection
            m_elements.Remove(ele.getInternalId());

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

            return(true);
        }