Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// It creates a new element copying all attributes from eleToClone; the new
        /// element is inserted under the parent element provided.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToClone">Element to be cloned</param>
        /// <returns></returns>
        public SvgElement CloneElement(SvgElement parent, SvgElement eleToClone)
        {
            // calculate unique id
            string sOldId = eleToClone.GetAttributeStringValue(SvgAttribute._SvgAttribute.attrCore_Id);
            string sNewId = sOldId;

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

                // check if it is unique
                while (GetSvgElement(sNewId) != null)
                {
                    sNewId = sOldId + "_" + i.ToString();
                    i++;
                }
            }

            // clone operation
            SvgElement eleNew = AddElement(parent, eleToClone.getElementName());

            eleNew.CloneAttributeList(eleToClone);

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

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

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

            return(eleNew);
        }
Esempio 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);
        }