示例#1
0
        // 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  = irSubject.GetParentsFamily(false);
            MiniTreeGroup      mtgParents = new MiniTreeGroup();
            MiniTreeIndividual mtiFather  = null;

            if (frParents != null)
            {
                mtiFather = AddToGroup(frParents.Husband.Individual, 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                     alFamily      = irSubject.GetFamilyList();

                    foreach (GDMFamilyRecord fr in alFamily)
                    {
                        GDMIndividualRecord irSpouse = fr.GetSpouseBy(irSubject);

                        if (fr.Husband.Individual != irSubject)
                        {
                            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(fr, 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 (fr.Husband.Individual == irSubject)
                        {
                            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(frParents.Wife.Individual, mtgParents);
                mtgSiblings.RightBox = mtiMother;
            }

            // Return the parents group (which contains the other family groups).
            return(mtgParents);
        }