/// <summary> /// It returns a string containing current element info for logging purposes. /// </summary> /// <returns></returns> public string ElementInfo() { string sMsg = "InternalId:" + m_nInternalId.ToString(); if (m_Parent != null) { sMsg += " - Parent:" + m_Parent.getInternalId().ToString(); } if (m_Previous != null) { sMsg += " - Previous:" + m_Previous.getInternalId().ToString(); } if (m_Next != null) { sMsg += " - Next:" + m_Next.getInternalId().ToString(); } if (m_Child != null) { sMsg += " - Child:" + m_Child.getInternalId().ToString(); } return(sMsg); }
private bool IsLastSibling(SvgElement ele) { SvgElement last = GetLastSibling(ele); if (last == null) { return(false); } return(ele.getInternalId() == last.getInternalId()); }
// returns true if the given elemebt is the first child private bool IsFirstChild(SvgElement ele) { if (ele.getParent() == null) { return(false); } if (ele.getParent().getChild() == null) { return(false); } return(ele.getInternalId() == ele.getParent().getChild().getInternalId()); }
/// <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); }
// ---------- 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); }