/// <summary> /// Inserts the given cell into its parent and terminal cells. /// </summary> /// <param name="cell"></param> public void InsertIntoGraph(mxICell cell) { mxICell parent = cell.Parent; mxICell source = cell.GetTerminal(true); mxICell target = cell.GetTerminal(false); // Fixes possible inconsistencies during insert into graph cell.SetTerminal(null, false); cell.SetTerminal(null, true); cell.Parent = null; if (parent != null) { parent.Insert(cell); } if (source != null) { source.InsertEdge(cell, true); } if (target != null) { target.InsertEdge(cell, false); } }
/// <summary> /// Inner helper method for cloning cells recursively. /// </summary> protected Object CloneCell(Object cell, Hashtable mapping, bool includeChildren) { if (cell is mxICell) { mxICell mxc = (mxICell)mapping[cell]; if (mxc == null) { mxc = (mxICell)((mxICell)cell).Clone(); mapping[cell] = mxc; if (includeChildren) { int childCount = GetChildCount(cell); for (int i = 0; i < childCount; i++) { Object clone = CloneCell(GetChildAt(cell, i), mapping, true); mxc.Insert((mxICell)clone); } } } return(mxc); } return(null); }
/// <summary> /// Clones the children of the source cell into the given target cell in /// this model and adds an entry to the mapping that maps from the source /// cell to the target cell with the same id or the clone of the source cell /// that was inserted into this model. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cloneAllEdges"></param> /// <param name="mapping"></param> protected void MergeChildrenImpl(mxICell from, mxICell to, bool cloneAllEdges, Dictionary <Object, Object> mapping) { BeginUpdate(); try { int childCount = from.ChildCount(); for (int i = 0; i < childCount; i++) { mxICell cell = from.GetChildAt(i); String id = cell.Id; mxICell target = (mxICell)((id != null && (!IsEdge(cell) || !cloneAllEdges)) ? GetCell(id) : null); // Clones and adds the child if no cell exists for the id if (target == null) { mxCell clone = (mxCell)cell.Clone(); clone.Id = id; // Do *NOT* use model.add as this will move the edge away // from the parent in updateEdgeParent if maintainEdgeParent // is enabled in the target model target = to.Insert(clone); CellAdded(target); } // Stores the mapping for later reconnecting edges mapping[cell] = target; // Recurses MergeChildrenImpl(cell, target, cloneAllEdges, mapping); } } finally { EndUpdate(); } }
/// <summary> /// Clones the children of the source cell into the given target cell in /// this model and adds an entry to the mapping that maps from the source /// cell to the target cell with the same id or the clone of the source cell /// that was inserted into this model. /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <param name="cloneAllEdges"></param> /// <param name="mapping"></param> protected void MergeChildrenImpl(mxICell from, mxICell to, bool cloneAllEdges, Dictionary<Object, Object> mapping) { BeginUpdate(); try { int childCount = from.ChildCount(); for (int i = 0; i < childCount; i++) { mxICell cell = from.GetChildAt(i); String id = cell.Id; mxICell target = (mxICell) ((id != null && (!IsEdge(cell) || !cloneAllEdges)) ? GetCell(id) : null); // Clones and adds the child if no cell exists for the id if (target == null) { mxCell clone = (mxCell) cell.Clone(); clone.Id = id; // Do *NOT* use model.add as this will move the edge away // from the parent in updateEdgeParent if maintainEdgeParent // is enabled in the target model target = to.Insert(clone); CellAdded(target); } // Stores the mapping for later reconnecting edges mapping[cell] = target; // Recurses MergeChildrenImpl(cell, target, cloneAllEdges, mapping); } } finally { EndUpdate(); } }