/// <summary> /// If the graph <c>target</c> has parent, it will move to its level (one level closer to the root) /// </summary> /// <param name="target">The graph that is moving</param> /// <param name="flags">The operation flags</param> /// <returns></returns> public static IGraphNode RetreatToParent(this IGraphNode target, graphOperationFlag flags = graphOperationFlag.mergeOnSameName) { if (target.parent != null) { return(target.MoveTo(target.parent, flags)); } return(target); }
/// <summary> /// Graph node <c>graphToMerge</c> transfers all child nodes to <c>graphToMergeWith</c> and disconnects from its parent /// </summary> /// <param name="graphToMerge">The graph to merge.</param> /// <param name="graphToMergeWith">The graph to merge with.</param> /// <param name="flags">The operation flags</param> /// <returns></returns> public static IGraphNode MergeWith(this IGraphNode graphToMerge, IGraphNode graphToMergeWith, graphOperationFlag flags = graphOperationFlag.mergeOnSameName) { foreach (IGraphNode child in graphToMerge) { child.MoveTo(graphToMergeWith, flags); } graphToMerge.parent.RemoveByKey(graphToMerge.name); return(graphToMergeWith); }
/// <summary> /// Moves to new parent node <c>moveInto</c> /// </summary> /// <param name="graphToMove">The graph to move.</param> /// <param name="moveInto">The move into (future parent graph)</param> /// <param name="flags">The operation flags</param> /// <returns>Resulting graph, relevant in case of merging</returns> public static IGraphNode MoveTo(this IGraphNode graphToMove, IGraphNode moveInto, graphOperationFlag flags = graphOperationFlag.mergeOnSameName) { if (moveInto.getChildNames().Contains(graphToMove.name)) { if (flags.HasFlag(graphOperationFlag.mergeOnSameName)) { graphToMove.MergeWith(moveInto[graphToMove.name], flags); } else if (flags.HasFlag(graphOperationFlag.overwriteOnSameName)) { moveInto.RemoveByKey(graphToMove.name); moveInto.Add(graphToMove); } } else { moveInto.Add(graphToMove); } return(graphToMove); }