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); }
private SVGUnit GetLastSibling(SVGUnit ele) { if (ele == null) { return(null); } SVGUnit last = ele; while (last.getNext() != null) { last = last.getNext(); } return(last); }
/// <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> /// 它将元素移动到当前的上一个同级之前。 /// </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); }
/// <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); }
/// <summary> /// 根据读取的xml生成项目 /// </summary> /// <param name="svg"></param> public static void CreateProjectFromXML(SVGUnit svg, DrawObjectList list) { while (svg != null) { switch (svg.getElementType()) { case SVGUnit.SVGUnitType.def: //将所有symbol读取 SVGUnit defchild = svg.getChild(); while (defchild != null) { if (defchild.getElementType() == SVGUnit.SVGUnitType.symbol) { CreateSysmbolUnit(defchild as SVGSymbol); } defchild = defchild.getNext(); } break; case SVGUnit.SVGUnitType.typeGroup: if (svg.Id == SVGDefine.ConnectLineClass) { SVGGroup group = svg.getChild() as SVGGroup; DrawConnectObject drawConnectObject = DrawConnectObject.Create(group.getChild() as SVGPath); SVGCN_Ref svgcnRef = group.getChild().getNext().getChild() as SVGCN_Ref; var linkDnd = svgcnRef.LinkObjecttlDnd.Split('@'); drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 1, int.Parse(linkDnd[1]), list.GetDeviceList()); linkDnd = svgcnRef.LinkObjectIDznd.Split('@'); drawConnectObject.SetConnectDeviceFromXml(linkDnd[0], 2, int.Parse(linkDnd[1]), list.GetDeviceList()); drawConnectObject.Id = int.Parse(group.Id); list.Add(drawConnectObject); group = group.getNext() as SVGGroup; } else if (svg.Id == SVGDefine.AnimationClass) { } else { SVGGroup group = svg.getChild() as SVGGroup; while (group != null) { var gchild = group.getChild(); switch (gchild.getElementType()) { case SVGUnit.SVGUnitType.use: SVGUse use = gchild as SVGUse; var gDevice = CreateDeviceDrawObjectBase(use, group.Id); //TODO 后期添加到工作组中 list.Add(gDevice); break; default: //TODO 未编排为设备的图素集合,暂时用临时分组表示 var o = SVGDrawFactory.CreateDrawObject(svg); list.Add(o); //vBase = new DeviceDrawObjectBase(0f, 0f, 0f, 0f, group.Id, drawObjects, null, ""); break; } group = group.getNext() as SVGGroup; //获取下一个 } } break; default: break; } svg = svg.getNext(); } }