// Creates a CMiniTreeIndividual for the individual specified and adds it to the group. // Informs neighbouring boxes about this box. // bCreateLink decides whether to make this box a clickable link in the HTML. public MiniTreeIndividual AddIndividual(GDMIndividualRecord ir, string firstnames, string surname, string date, bool createLink, bool createStalk, bool highlight, bool concealed, bool shade) { MiniTreeIndividual mti = new MiniTreeIndividual(ir, firstnames, surname, date, createLink, createStalk, highlight, concealed, shade, CConfig.Instance.ConserveTreeWidth); if (fMembers == null) { fMembers = new List <MiniTreeObject>(); } fMembers.Add(mti); fIndividuals++; if (createStalk) { fStalkedIndividuals++; } mti.LeftObject = fLastAddedObject; if (fLastAddedObject != null) { fLastAddedObject.RightObject = mti; } fLastAddedObject = mti; return(mti); }
public MiniTreeGroup() { fMembers = null; fSize = new SizeF(0.0f, 0.0f); fParent = null; fIndividuals = 0; fStalkedIndividuals = 0; fBoxLeft = null; fBoxRight = null; fLastAddedObject = null; fCrossbar = ECrossbar.Solid; }
// Add a box for the individual to the specified group. private static MiniTreeIndividual AddToGroup(GDMIndividualRecord ir, MiniTreeGroup mtg) { MiniTreeIndividual mti = null; if (Exists(ir)) { CBoxText boxtext = new CBoxText(ir); mti = mtg.AddIndividual(ir, boxtext.FirstName, boxtext.Surname, boxtext.Date, true, false, false, boxtext.Concealed, true); } else { mti = mtg.AddIndividual(null, "", CConfig.Instance.UnknownName, " ", false, false, false, false, true); } return(mti); }
// Shifts this object and all objects to its right, until one can't move. public override float PullRight(float amount) { if (fMembers != null) { // This couple had children // Shift the underhanging group members. // Find the leftmost underhanging member and shift it right. // That will interact with other members to find max possible shift amount. MiniTreeIndividual mtiLeftmost = null; float min = 0; bool first = true; foreach (MiniTreeObject obj in fMembers) { var mtIndi = obj as MiniTreeIndividual; if (mtIndi != null) { if (first || mtIndi.Right < min) { min = mtIndi.Right; mtiLeftmost = mtIndi; } first = false; } } if (mtiLeftmost != null) { amount = mtiLeftmost.PushRight(amount); } } // Now shift left object right. MiniTreeObject mtoLeft = LeftObject; if (mtoLeft != null) { amount = mtoLeft.PullRight(amount); } return(amount); }
// Shifts this object and all objects to its left, until one can't move. public override float PullLeft(float amount) { // Did this couple have children? if (fMembers != null) { // Shift the underhanging group members // Find the rightmost underhanging member and shift it left. // That will interact with other members to find max possible shift amount. MiniTreeIndividual mtiRightmost = null; float max = 0; bool first = true; foreach (MiniTreeObject obj in fMembers) { var mtIndi = obj as MiniTreeIndividual; if (mtIndi != null) { if (first || mtIndi.Left > max) { max = mtIndi.Left; mtiRightmost = mtIndi; } first = false; } } if (mtiRightmost != null) { amount = mtiRightmost.PushLeft(amount); } } // Now shift right object left. MiniTreeObject mtoRight = RightObject; if (mtoRight != null) { amount = mtoRight.PullLeft(amount); } return(amount); }
// Calculate size required for tree by iterating through individuals and building a data structure. protected MiniTreeGroup CreateDataStructure(GDMIndividualRecord irSubject) { // Add subject's frParents GDMFamilyRecord frParents = fTree.GetParentsFamily(irSubject); MiniTreeGroup mtgParents = new MiniTreeGroup(); MiniTreeIndividual mtiFather = null; if (frParents != null) { mtiFather = AddToGroup(fTree.GetPtrValue(frParents.Husband), mtgParents); } // Create a group for the subejct and their siblings. MiniTreeGroup mtgSiblings = new MiniTreeGroup(); // Keeps count of subject's siblings (including subject) int nSiblings = 0; // Keeps track of last added sibling, to hook up to next added sibling. MiniTreeIndividual mtiRightmostSibling = null; // Keeps track of last added child, to hook up to next added child. MiniTreeIndividual mtiRightmostChild = null; // For each sibling (including the subject) while (true) { GDMIndividualRecord irSibling = GetChild(frParents, nSiblings, irSubject); if (irSibling == null) { break; } if (irSibling == irSubject) { // Add spouses and children of subject, (and subject too, if we need to put wife after them.) MiniTreeGroup mtgOffspring = null; bool bAddedSubject = false; int nSpouses = 0; MiniTreeGroup.ECrossbar ecbCrossbar = MiniTreeGroup.ECrossbar.Solid; var indiFamilies = GMHelper.GetFamilyList(fTree, irSubject); foreach (GDMFamilyRecord famRec in indiFamilies) { GDMIndividualRecord irSpouse = fTree.GetSpouseBy(famRec, irSubject); if (famRec.Husband.XRef != irSubject.XRef) { mtiRightmostSibling = AddToGroup(irSpouse, mtgSiblings); // Subject is female so all but last husband have dotted bars ecbCrossbar = MiniTreeGroup.ECrossbar.DottedLeft; } else if (Exists(irSubject) && !bAddedSubject) { // Subject is male, so need to put them in now, before their children. // (Otherwise they get added as a regular sibling later) CBoxText boxtext = new CBoxText(irSubject); mtiRightmostSibling = mtgSiblings.AddIndividual(irSubject, boxtext.FirstName, boxtext.Surname, boxtext.Date, false, frParents != null, true, boxtext.Concealed, false); // To stop subject being added as regular sibling. bAddedSubject = true; } int nGrandchildren = 0; GDMIndividualRecord irGrandchild = null; // If we have already added an offspring box (from previous marriage) need connect this box to it as its right box. if (mtgOffspring != null) { mtgOffspring.RightBox = mtiRightmostSibling; } // Create a box for the offspring of this marriage mtgOffspring = new MiniTreeGroup(); // Set crossbar that joins subject to spouse according to whether this is subject's first spouse. mtgOffspring.fCrossbar = ecbCrossbar; // Add children by this spouse MiniTreeIndividual mtiChild = null; while ((irGrandchild = GetChild(famRec, nGrandchildren, null)) != null) { if (Exists(irGrandchild)) { CBoxText boxtext = new CBoxText(irGrandchild); mtiChild = mtgOffspring.AddIndividual(irGrandchild, boxtext.FirstName, boxtext.Surname, boxtext.Date, true, true, false, boxtext.Concealed, false); // Hook this up to any children by previous spouses. if (nGrandchildren == 0 && mtiRightmostChild != null) { mtiRightmostChild.RightObjectAlien = mtiChild; mtiChild.LeftObjectAlien = mtiRightmostChild; } } nGrandchildren++; } // If we added anything, record it as the right-most child ready to hook to children by next spouse. if (mtiChild != null) { mtiRightmostChild = mtiChild; } // Add the subjects children to the siblings group mtgSiblings.AddGroup(mtgOffspring); // Hook the offspring group to the previous sibling if (mtgOffspring != null) { mtgOffspring.LeftBox = mtiRightmostSibling; } // If subject is husband then we need to add their wife now. if (famRec.Husband.XRef == irSubject.XRef) { ecbCrossbar = MiniTreeGroup.ECrossbar.DottedRight; // Hook up to previous rightmost sibling and set this as new rightmost sibling. mtiRightmostSibling = AddToGroup(irSpouse, mtgSiblings); // Hook the wife up as box on right of offspring box. if (mtgOffspring != null) { mtgOffspring.RightBox = mtiRightmostSibling; } } nSpouses++; } if (!bAddedSubject) { CBoxText boxtext = new CBoxText(irSubject); MiniTreeIndividual mtiWife = mtgSiblings.AddIndividual(irSubject, boxtext.FirstName, boxtext.Surname, boxtext.Date, false, frParents != null, true, boxtext.Concealed, false); if (mtgOffspring != null) { mtgOffspring.fCrossbar = MiniTreeGroup.ECrossbar.Solid; mtgOffspring.RightBox = mtiWife; } } } else if (Exists(irSibling)) { // A sibling (not the subject). CBoxText boxtext = new CBoxText(irSibling); mtgSiblings.AddIndividual(irSibling, boxtext.FirstName, boxtext.Surname, boxtext.Date, true, frParents != null, true, boxtext.Concealed, false); } nSiblings++; } // Add siblings group after subject's father mtgParents.AddGroup(mtgSiblings); // Hook up to subject's father mtgSiblings.LeftBox = mtiFather; // Add subject's mother if (frParents != null) { MiniTreeIndividual mtiMother = AddToGroup(fTree.GetPtrValue(frParents.Wife), mtgParents); mtgSiblings.RightBox = mtiMother; } // Return the parents group (which contains the other family groups). return(mtgParents); }