示例#1
0
        private static void SearchKGInt(Vertex prevNode, GDMIndividualRecord iRec,
                                        KinshipsGraph graph, RelationKind relation, RelationKind inverseRelation)
        {
            if (iRec == null)
            {
                return;
            }

            Vertex currNode = graph.FindVertex(iRec.XRef);

            if (currNode != null)
            {
                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }

                return;
            }
            else
            {
                currNode = graph.AddIndividual(iRec);

                if (prevNode != null)
                {
                    graph.AddRelation(prevNode, currNode, relation, inverseRelation);
                }
            }

            if (iRec.ChildToFamilyLinks.Count > 0)
            {
                GDMFamilyRecord fam = iRec.GetParentsFamily();
                if (fam != null)
                {
                    GDMIndividualRecord father, mother;
                    father = fam.Husband.Individual;
                    mother = fam.Wife.Individual;

                    SearchKGInt(currNode, father, graph, RelationKind.rkParent, RelationKind.rkChild);
                    SearchKGInt(currNode, mother, graph, RelationKind.rkParent, RelationKind.rkChild);
                }
            }

            int num = iRec.SpouseToFamilyLinks.Count;

            for (int i = 0; i < num; i++)
            {
                GDMFamilyRecord     family = iRec.SpouseToFamilyLinks[i].Family;
                GDMIndividualRecord spouse = ((iRec.Sex == GDMSex.svMale) ? family.Wife.Individual : family.Husband.Individual);

                SearchKGInt(currNode, spouse, graph, RelationKind.rkSpouse, RelationKind.rkSpouse);

                int num2 = family.Children.Count;
                for (int j = 0; j < num2; j++)
                {
                    GDMIndividualRecord child = family.Children[j].Individual;
                    SearchKGInt(currNode, child, graph, RelationKind.rkChild, RelationKind.rkParent);
                }
            }
        }
示例#2
0
        public void ImportNames(GDMIndividualRecord iRec)
        {
            if (iRec == null)
            {
                return;
            }

            try {
                string childName, childPat;
                var    parts = GKUtils.GetNameParts(iRec, false);
                childName = parts.Name;
                childPat  = parts.Patronymic;

                GDMSex iSex = iRec.Sex;
                SetNameSex(childName, iSex);

                GDMFamilyRecord     fam    = iRec.GetParentsFamily();
                GDMIndividualRecord father = (fam == null) ? null : fam.Husband.Individual;

                if (father != null)
                {
                    string fatherName;
                    parts      = GKUtils.GetNameParts(father, false);
                    fatherName = parts.Name;

                    if (IsComparable(fatherName, childPat))
                    {
                        SetName(fatherName, childPat, iSex);
                    }
                }
            } catch (Exception ex) {
                Logger.WriteError("NamesTable.ImportName()", ex);
            }
        }
示例#3
0
        private static bool CheckPersonsEx(GDMIndividualRecord rec1, GDMIndividualRecord rec2)
        {
            GDMFamilyRecord fam1 = rec1.GetParentsFamily();
            GDMFamilyRecord fam2 = rec2.GetParentsFamily();

            return(!Equals(fam1, fam2));
        }
示例#4
0
        public object gt_get_person_parents_family(object recPtr)
        {
            GDMIndividualRecord rec = recPtr as GDMIndividualRecord;

            if (rec == null)
            {
                return(null);
            }

            GDMFamilyRecord fam = rec.GetParentsFamily();

            return(fam);
        }
示例#5
0
        // TODO: rollback changes when exception!
        private void ParseSource()
        {
            int srcYear;

            if (!int.TryParse(edSourceYear.Text, out srcYear))
            {
                ShowError(fLangMan.LS(FLS.LSID_SourceYearInvalid));
                return;
            }

            string srcName = cbSource.Text;
            string srcPage = edPage.Text;
            string place   = edPlace.Text;

            GDMSourceRecord srcRec = null;

            if (!string.IsNullOrEmpty(srcName))
            {
                srcRec = fBase.Context.FindSource(srcName);
                if (srcRec == null)
                {
                    srcRec            = fBase.Context.Tree.CreateSource();
                    srcRec.ShortTitle = srcName;
                }
            }

            GDMIndividualRecord iMain = null;

            int num = dataGridView1.Rows.Count;

            for (int r = 0; r < num; r++)
            {
                DataGridViewRow row = dataGridView1.Rows[r];

                string lnk     = CheckStr((string)row.Cells[0].Value);
                string nm      = CheckStr((string)row.Cells[1].Value);
                string pt      = CheckStr((string)row.Cells[2].Value);
                string fm      = CheckStr((string)row.Cells[3].Value);
                string age     = CheckStr((string)row.Cells[4].Value);
                string comment = CheckStr((string)row.Cells[5].Value);

                if (!string.IsNullOrEmpty(lnk))
                {
                    PersonLink link = GetLinkByName(lnk);
                    if (link == PersonLink.plNone)
                    {
                        continue;
                    }

                    GDMSex sx = fBase.Context.DefineSex(nm, pt);
                    GDMIndividualRecord iRec = fBase.Context.CreatePersonEx(nm, pt, fm, sx, false);

                    if (!string.IsNullOrEmpty(age) && ConvertHelper.IsDigits(age))
                    {
                        int birthYear = srcYear - int.Parse(age);
                        fBase.Context.CreateEventEx(iRec, GEDCOMTagName.BIRT, "ABT " + birthYear.ToString(), "");
                    }

                    if (!string.IsNullOrEmpty(place))
                    {
                        GDMCustomEvent evt = fBase.Context.CreateEventEx(iRec, GEDCOMTagName.RESI, "", "");
                        evt.Place.StringValue = place;
                    }

                    if (!string.IsNullOrEmpty(comment))
                    {
                        GDMNoteRecord noteRec = fBase.Context.Tree.CreateNote();
                        noteRec.SetNoteText(comment);
                        iRec.AddNote(noteRec);
                    }

                    if (srcRec != null)
                    {
                        iRec.AddSource(srcRec, srcPage, 0);
                    }

                    fBase.NotifyRecord(iRec, RecordAction.raAdd);

                    GDMFamilyRecord family = null;

                    if (link == PersonLink.plPerson)
                    {
                        iMain = iRec;
                        string evName = "";

                        if (rbSK_Met.Checked)
                        {
                            switch (cbEventType.SelectedIndex)
                            {
                            case  0:
                                evName = GEDCOMTagName.BIRT;
                                break;

                            case  1:
                                evName = GEDCOMTagName.DEAT;
                                break;

                            case  2:
                                evName = GEDCOMTagName.MARR;
                                break;
                            }
                        }

                        if (evName == GEDCOMTagName.BIRT || evName == GEDCOMTagName.DEAT)
                        {
                            GDMCustomEvent evt = fBase.Context.CreateEventEx(iRec, evName, GDMDate.CreateByFormattedStr(edEventDate.Text, false), "");
                            evt.Place.StringValue = place;
                        }
                        else if (evName == GEDCOMTagName.MARR)
                        {
                            family = iRec.GetMarriageFamily(true);
                            GDMCustomEvent evt = fBase.Context.CreateEventEx(family, evName, GDMDate.CreateByFormattedStr(edEventDate.Text, false), "");
                            evt.Place.StringValue = place;
                        }
                    }
                    else
                    {
                        if (iMain == null)
                        {
                            throw new PersonScanException(fLangMan.LS(FLS.LSID_BasePersonInvalid));
                        }
                        else
                        {
                            switch (link)
                            {
                            case PersonLink.plFather:
                            case PersonLink.plMother:
                                family = iMain.GetParentsFamily(true);
                                family.AddSpouse(iRec);
                                break;

                            case PersonLink.plGodparent:
                                iMain.AddAssociation(fLangMan.LS(FLS.LSID_PLGodparent), iRec);
                                break;

                            case PersonLink.plSpouse:
                                family = iMain.GetMarriageFamily(true);
                                family.AddSpouse(iRec);
                                break;

                            case PersonLink.plChild:
                                family = iMain.GetMarriageFamily(true);
                                family.AddChild(iRec);
                                break;
                            }
                        }
                    }
                }
            }

            InitSourceControls();
        }
示例#6
0
        private void ExposePerson(GDMIndividualRecord iRec, string iName)
        {
            fWriter.BeginParagraph(TextAlignment.taLeft, 0, 0, 0, true);
            fWriter.AddParagraphChunkAnchor(iName, fBoldFont, iRec.XRef);
            fWriter.AddParagraphChunk(GKUtils.GetPedigreeLifeStr(iRec, PedigreeFormat.Compact), fTextFont);
            fWriter.EndParagraph();

            IImage image = fBase.Context.GetPrimaryBitmap(iRec, 0, 0, false);

            fWriter.AddImage(image);

            GDMIndividualRecord father, mother;
            GDMFamilyRecord     fam = iRec.GetParentsFamily();

            if (fam == null)
            {
                father = null;
                mother = null;
            }
            else
            {
                father = fam.Husband.Individual;
                mother = fam.Wife.Individual;
            }

            if (father != null)
            {
                fWriter.BeginParagraph(TextAlignment.taLeft, 0, 0, 0);
                fWriter.AddParagraphChunk(LangMan.LS(LSID.LSID_Father) + ": ", fTextFont);
                fWriter.AddParagraphChunkLink(GKUtils.GetNameString(father, true, false), fLinkFont, father.XRef);
                fWriter.EndParagraph();
            }

            if (mother != null)
            {
                fWriter.BeginParagraph(TextAlignment.taLeft, 0, 0, 0);
                fWriter.AddParagraphChunk(LangMan.LS(LSID.LSID_Mother) + ": ", fTextFont);
                fWriter.AddParagraphChunkLink(GKUtils.GetNameString(mother, true, false), fLinkFont, mother.XRef);
                fWriter.EndParagraph();
            }

            if (IncludeEvents && iRec.Events.Count != 0)
            {
                int num = iRec.Events.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMCustomEvent evt     = iRec.Events[i];
                    var            evtType = evt.GetTagType();
                    if (evtType == GEDCOMTagType.BIRT || evtType == GEDCOMTagType.DEAT)
                    {
                        continue;
                    }

                    string evtName = GKUtils.GetEventName(evt);
                    string evtVal  = evt.StringValue;
                    string evtDesc = GKUtils.GetEventDesc(evt, false);

                    string tmp = evtName + ": " + evtVal;
                    if (evtVal != "")
                    {
                        tmp += ", ";
                    }
                    tmp += evtDesc;

                    fWriter.AddParagraph(tmp, fTextFont);
                }
            }

            if (IncludeNotes && iRec.Notes.Count != 0)
            {
                int num = iRec.Notes.Count;
                for (int i = 0; i < num; i++)
                {
                    GDMNotes note = iRec.Notes[i];
                    fWriter.AddParagraph(GKUtils.MergeStrings(note.Lines), fTextFont);
                }
            }
        }
示例#7
0
        private AncPersonSegment TraverseAncestors(GDMIndividualRecord iRec, float v, int gen, float rad, float ro, int prevSteps, int groupIndex)
        {
            try
            {
                fIndividualsCount++;

                if (fGroupsMode && groupIndex == -1)
                {
                    AncPersonSegment otherSegment = (AncPersonSegment)FindSegmentByRec(iRec);
                    if (otherSegment != null)
                    {
                        fGroupCount++;
                        groupIndex = fGroupCount;
                        TraverseGroups(otherSegment, groupIndex);
                    }
                }

                int   genSize = 1 << gen;
                float ang     = (360.0f / genSize);

                int idx = prevSteps + (int)(v / ang);
                AncPersonSegment segment = SetSegmentParams(idx, iRec, rad, groupIndex);

                if (segment != null && gen < fVisibleGenerations)
                {
                    float inRad  = rad;
                    float extRad = rad + fGenWidth;

                    segment.IntRad = inRad - 50;
                    segment.ExtRad = extRad - 50;

                    GDMIndividualRecord father = null, mother = null;
                    GDMFamilyRecord     fam = iRec.GetParentsFamily();
                    if (fam != null && fBase.Context.IsRecordAccess(fam.Restriction))
                    {
                        father = fam.Husband.Individual;
                        mother = fam.Wife.Individual;
                    }

                    int ps = prevSteps + genSize;

                    if (father != null)
                    {
                        v -= (Math.Abs(ang - ro) / 2.0f);
                        segment.FatherSegment = TraverseAncestors(father, v, gen + 1, rad + fGenWidth, ro / 2.0f, ps, groupIndex);
                    }

                    if (mother != null)
                    {
                        v += (ang / 2.0f);
                        segment.MotherSegment = TraverseAncestors(mother, v, gen + 1, rad + fGenWidth, ro / 2.0f, ps, groupIndex);
                    }
                }

                return(segment);
            }
            catch
            {
                return(null);
            }
        }
示例#8
0
        public void BuildAncTree()
        {
            fSegments.Clear();

            const float startRad = CircleChartModel.CENTER_RAD - 50;
            float       inRad    = startRad;

            AncPersonSegment segment = new AncPersonSegment(0);

            DefineSegment(segment, 0, 0, inRad, 0 - 90.0f, 360.0f);
            fSegments.Add(segment);

            int maxSteps = 1;

            for (int gen = 1; gen <= fVisibleGenerations; gen++)
            {
                inRad = startRad + ((gen - 1) * fGenWidth);
                float extRad = inRad + fGenWidth;

                maxSteps *= 2;
                float wedgeAngle = (360.0f / maxSteps);

                for (int step = 0; step < maxSteps; step++)
                {
                    float startAngle = (step * wedgeAngle) - 90.0f;

                    segment = new AncPersonSegment(gen);
                    DefineSegment(segment, 0, inRad, extRad, startAngle, wedgeAngle);
                    fSegments.Add(segment);
                }
            }

            // traverse tree
            fGroupCount       = -1;
            fIndividualsCount = 0;
            if (fRootPerson == null)
            {
                return;
            }

            fIndividualsCount++;
            AncPersonSegment rootSegment = SetSegmentParams(0, fRootPerson, 0, -1);

            if (rootSegment == null)
            {
                return;
            }

            rootSegment.WedgeAngle = 360.0f;

            GDMIndividualRecord father = null, mother = null;
            GDMFamilyRecord     fam = fRootPerson.GetParentsFamily();

            if (fam != null && fBase.Context.IsRecordAccess(fam.Restriction))
            {
                father = fam.Husband.Individual;
                mother = fam.Wife.Individual;
            }

            if (mother != null)
            {
                rootSegment.MotherSegment = TraverseAncestors(mother, 90f, 1, CircleChartModel.CENTER_RAD, 90.0f, 1, -1);
            }

            if (father != null)
            {
                rootSegment.FatherSegment = TraverseAncestors(father, 270.0f, 1, CircleChartModel.CENTER_RAD, 90.0f, 1, -1);
            }
        }
示例#9
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);
        }