/// <summary> /// Change the <see cref="P:Northwoods.Go.GoObject.Parent" /> of an object to be the common subgraph that /// contains two given objects, or if there is no such subgraph, add the object to the given layer. /// </summary> /// <param name="obj">the <see cref="T:Northwoods.Go.GoObject" /> to reparent</param> /// <param name="child1">an object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param> /// <param name="child2">another object that may belong to a <see cref="T:Northwoods.Go.GoSubGraphBase" /></param> /// <param name="behind">whether to add the <paramref name="obj" /> at the beginning of the list /// of the subgraph's children (thus behind all other subgraph children), or at the end of the list /// (thus appearing in front of all the other subgraph children)</param> /// <param name="layer"> /// the <see cref="T:Northwoods.Go.GoLayer" /> to which the <paramref name="obj" /> should be added, /// if there is no common parent <see cref="T:Northwoods.Go.GoSubGraphBase" /> for <paramref name="child1" /> and /// <paramref name="child2" /> /// </param> /// <remarks> /// All of the arguments to this method should be non-null. /// </remarks> public static void ReparentToCommonSubGraph(GoObject obj, GoObject child1, GoObject child2, bool behind, GoLayer layer) { GoSubGraphBase a = FindParentSubGraph(child1); GoSubGraphBase b = FindParentSubGraph(child2); GoObject goObject = GoObject.FindCommonParent(a, b); while (goObject != null && !(goObject is GoSubGraphBase)) { goObject = goObject.Parent; } GoSubGraphBase goSubGraphBase = goObject as GoSubGraphBase; if (obj.Parent == goSubGraphBase && obj.Layer != null) { return; } if (obj.Parent == null && obj.Layer == null) { if (goSubGraphBase != null) { if (behind) { goSubGraphBase.InsertBefore(null, obj); } else { goSubGraphBase.InsertAfter(null, obj); } } else { layer.Add(obj); } } else { GoCollection goCollection = new GoCollection(); goCollection.Add(obj); if (goSubGraphBase != null) { goSubGraphBase.AddCollection(goCollection, reparentLinks: false); } else { layer.AddCollection(goCollection, reparentLinks: false); } } }