private void RootNav(UnionData thisNode, Person thisroot) // TODO can use Who { // Navigation to parents - for root only if (thisNode.ParentId == -1 && thisroot.ChildIn.Count > 0) { foreach (var union1 in thisroot.ChildIn) { thisNode.Parents.Add(union1.DadId); thisNode.Parents.Add(union1.MomId); } } }
private UnionData InitNode(Person thisroot, int parentNodeId) { UnionData thisNode = new UnionData(); thisNode.Id = _dex; _dex = _dex + 1; thisNode.PersonId = thisroot.Id; thisNode.ParentId = parentNodeId; thisNode.Who = thisroot; _tree.Add(thisNode); return(thisNode); }
private void MultiParent(UnionData thisNode, Person thisroot)// TODO can use Who { // Non-root node: multiple parents if (thisroot.ChildIn.Count > 1 && thisNode.ParentId != -1) { thisNode.CurrentParents = 0; foreach (var union1 in thisroot.ChildIn) { thisNode.Parents.Add(union1.DadId); thisNode.Parents.Add(union1.MomId); } } }
public void Remove(UnionData node) { // Remove this node AND all its children List <UnionData> toDel = new List <UnionData>(); foreach (var cnode in _tree) { if (cnode.ParentId == node.Id) { toDel.Add(cnode); } } foreach (var unionData in toDel) { Remove(unionData); } _tree.Remove(node); }
public TreeNodeModel <T> GetRightMostChild2() { if (Children.Count == 0) { return(null); } var rmc = Children[Children.Count - 1]; UnionData it = rmc.Item as UnionData; if (it == null) { return(rmc); } while (!it.DrawParentLink) { rmc = rmc.GetPreviousSibling(); it = rmc.Item as UnionData; } return(rmc); }
private void RebuildChildren(UnionData node, Person p) { // Marriage has been changed. // 1. Existing node, children AND descendants need to be removed. // 2. Sub-tree with selected marriage needs to be added. int newUnionNum = node.CurrentMarriage + 1; if (newUnionNum >= p.SpouseIn.Count) { newUnionNum = 0; } UnionData newItem = node.ShallowCopy(); newItem.CurrentMarriage = newUnionNum; Union u = p.SpouseIn.ToArray()[newUnionNum]; newItem.UnionId = u.Id; _data2.Replace(newItem, u); }
public void Replace(UnionData node, Union u) { // A node is being re-created (alternate union). // Replace the existing one and add the new child sub-trees. // NOTE: a replace is necessary to preserve the order of // the person in the tree! UnionData old = null; for (int i = 0; i < _tree.Count; i++) { if (_tree[i].Id == node.Id) { old = _tree[i]; _tree[i] = node; } } Remove(old); // TODO is this even necessary? foreach (var achild in u.Childs) { GetDescendants(achild, node.Id); } }