/// <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); }
/// <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); }
/// <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); }