Пример #1
0
        private void UpdateTreeMap()
        {
            fDataMap.Model.Items.Clear();
            if (fBase == null)
            {
                fDataMap.Invalidate();
                return;
            }

            string hint = fPlugin.LangMan.LS(CLS.LSID_Hint);

            GDMTree tree = fBase.Context.Tree;
            List <GDMIndividualRecord> prepared     = new List <GDMIndividualRecord>();
            List <GDMRecord>           groupRecords = new List <GDMRecord>();

            try {
                int groupNum = 0;
                int num      = tree.RecordsCount;
                for (int i = 0; i < num; i++)
                {
                    GDMRecord rec = tree[i];

                    if (rec.RecordType == GDMRecordType.rtIndividual)
                    {
                        GDMIndividualRecord iRec = rec as GDMIndividualRecord;
                        if (prepared.IndexOf(iRec) < 0)
                        {
                            groupNum++;
                            groupRecords.Clear();

                            TreeTools.WalkTree(tree, iRec, TreeTools.TreeWalkMode.twmAll, groupRecords);

                            int   groupSize = groupRecords.Count;
                            float quality   = 0.0f;
                            for (int j = 0; j < groupSize; j++)
                            {
                                iRec = (GDMIndividualRecord)groupRecords[j];
                                prepared.Add(iRec);

                                quality += iRec.GetCertaintyAssessment();
                            }
                            quality /= groupSize;

                            string name = string.Format(hint, groupNum, groupSize, quality.ToString("0.00"));

                            CreateItem(null, name, groupSize, quality);
                        }
                    }
                }
            } finally {
                groupRecords.Clear();
            }

            fDataMap.UpdateView();
        }
Пример #2
0
        public void BuildBy(GDMIndividualRecord iRec)
        {
            try {
                fRec = iRec;

                if (iRec != null)
                {
                    if (fModel.PreparedIndividuals.IndexOf(iRec.XRef) < 0)
                    {
                        fModel.PreparedIndividuals.Add(iRec.XRef);
                    }

                    var parts = GKUtils.GetNameParts(fModel.Base.Context.Tree, iRec);
                    fSurname    = parts.Surname;
                    fName       = parts.Name;
                    fPatronymic = parts.Patronymic;
                    fNick       = GKUtils.GetNickString(iRec);
                    fSex        = iRec.Sex;

                    TreeChartOptions options = fModel.Options;

                    var        lifeDates  = iRec.GetLifeDates();
                    DateFormat dateFormat = (options.OnlyYears) ? DateFormat.dfYYYY : DateFormat.dfDD_MM_YYYY;

                    IsDead     = (lifeDates.DeathEvent != null);
                    fBirthDate = GKUtils.GEDCOMEventToDateStr(lifeDates.BirthEvent, dateFormat, false);
                    fDeathDate = GKUtils.GEDCOMEventToDateStr(lifeDates.DeathEvent, dateFormat, false);

                    if (!options.OnlyYears)
                    {
                        if (options.ShowPlaces)
                        {
                            fBirthPlace = GKUtils.GetPlaceStr(lifeDates.BirthEvent, false);
                            if (!string.IsNullOrEmpty(fBirthPlace) && !options.SeparateDatesAndPlacesLines)
                            {
                                if (!string.IsNullOrEmpty(fBirthDate))
                                {
                                    fBirthDate += ", ";
                                }
                                fBirthDate += fBirthPlace;
                            }

                            fDeathPlace = GKUtils.GetPlaceStr(lifeDates.DeathEvent, false);
                            if (!string.IsNullOrEmpty(fDeathPlace) && !options.SeparateDatesAndPlacesLines)
                            {
                                if (!string.IsNullOrEmpty(fDeathDate))
                                {
                                    fDeathDate += ", ";
                                }
                                fDeathDate += fDeathPlace;
                            }
                        }

                        if (!string.IsNullOrEmpty(fBirthDate))
                        {
                            fBirthDate = ImportUtils.STD_BIRTH_SIGN + " " + fBirthDate;
                        }
                        if (!string.IsNullOrEmpty(fDeathDate))
                        {
                            fDeathDate = ImportUtils.STD_DEATH_SIGN + " " + fDeathDate;
                        }
                    }

                    if (options.SignsVisible)
                    {
                        EnumSet <SpecialUserRef> signs = EnumSet <SpecialUserRef> .Create();

                        int num = fRec.UserReferences.Count;
                        for (int i = 0; i < num; i++)
                        {
                            string rs = fRec.UserReferences[i].StringValue;

                            for (var cps = SpecialUserRef.urRI_StGeorgeCross; cps <= SpecialUserRef.urLast; cps++)
                            {
                                string sur = LangMan.LS(GKData.SpecialUserRefs[(int)cps].Title);
                                if (rs == sur)
                                {
                                    signs.Include(cps);
                                }
                            }
                        }

                        fSigns = signs;
                    }
                    else
                    {
                        fSigns = EnumSet <SpecialUserRef> .Create();
                    }

                    if (options.PortraitsVisible)
                    {
                        try {
                            fPortrait = PortraitsCache.Instance.GetImage(fModel.Base.Context, iRec);

                            if (fPortrait == null && options.DefaultPortraits)
                            {
                                string resName = (fSex == GDMSex.svFemale) ? "pi_female_140.png" : "pi_male_140.png";
                                fPortrait = AppHost.GfxProvider.LoadResourceImage(resName, false);
                            }
                        } catch (MediaFileNotFoundException) {
                            if (!fModel.HasMediaFail)
                            {
                                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_MediaFileNotLoaded));
                                fModel.HasMediaFail = true;
                            }
                        }
                    }

                    CertaintyAssessment = iRec.GetCertaintyAssessment();
                }
                else
                {
                    fSurname    = "";
                    fName       = "< ? >";
                    fPatronymic = "";
                    fNick       = "";
                    fBirthDate  = "";
                    fBirthPlace = "";
                    fDeathDate  = "";
                    fDeathPlace = "";
                    IsDead      = false;
                    fSex        = GDMSex.svUnknown;
                    fSigns      = EnumSet <SpecialUserRef> .Create();

                    CertaintyAssessment = 0.0f;
                }
            } catch (Exception ex) {
                Logger.WriteError("TreeChartPerson.BuildBy()", ex);
                throw;
            }
        }
Пример #3
0
        public CommonStats GetCommonStats()
        {
            CommonStats stats = new CommonStats();

            int num = fSelectedRecords.Count;

            for (int i = 0; i < num; i++)
            {
                GDMRecord rec = fSelectedRecords[i];
                if (rec.RecordType != GDMRecordType.rtIndividual)
                {
                    continue;
                }

                GDMIndividualRecord ind = (GDMIndividualRecord)rec;
                stats.persons++;

                switch (ind.Sex)
                {
                case GDMSex.svFemale:
                    stats.persons_f++;
                    if (ind.IsLive())
                    {
                        stats.lives_f++;
                        stats.lives++;
                    }
                    break;

                case GDMSex.svMale:
                    stats.persons_m++;
                    if (ind.IsLive())
                    {
                        stats.lives_m++;
                        stats.lives++;
                    }
                    break;
                }

                string vAge = GKUtils.GetAgeStr(ind, -1);
                stats.age.TakeVal(vAge, ind.Sex, true);

                string vLife = GKUtils.GetLifeExpectancyStr(ind);
                stats.life.TakeVal(vLife, ind.Sex, true);

                int chCnt = fTree.GetTotalChildrenCount(ind);
                stats.childs.TakeVal(chCnt, ind.Sex, true);

                int vFba = GKUtils.GetFirstbornAge(ind, GKUtils.GetFirstborn(fTree, ind));
                stats.fba.TakeVal(vFba, ind.Sex, true);

                int mCnt = GKUtils.GetMarriagesCount(ind);
                stats.marr.TakeVal(mCnt, ind.Sex, true);

                int vMAge = GKUtils.GetMarriageAge(fTree, ind);
                stats.mage.TakeVal(vMAge, ind.Sex, true);

                float vCI = ind.GetCertaintyAssessment();
                stats.cIndex.TakeVal(vCI, ind.Sex, false);
            }

            return(stats);
        }
Пример #4
0
        private void GetSimplePersonStat(StatsMode mode, List <StatsItem> values, GDMIndividualRecord iRec)
        {
            string iName = GKUtils.GetNameString(iRec, true, false);

            switch (mode)
            {
            case StatsMode.smAncestors:
                values.Add(new StatsItem(iName, GKUtils.GetAncestorsCount(fTree, iRec) - 1));
                break;

            case StatsMode.smDescendants:
                values.Add(new StatsItem(iName, GKUtils.GetDescendantsCount(fTree, iRec) - 1));
                break;

            case StatsMode.smDescGenerations:
                values.Add(new StatsItem(iName, GKUtils.GetDescGenerations(fTree, iRec)));
                break;

            case StatsMode.smChildsCount:
                values.Add(new StatsItem(iName, fTree.GetTotalChildrenCount(iRec)));
                break;

            case StatsMode.smFirstbornAge:
                values.Add(new StatsItem(iName, GKUtils.GetFirstbornAge(iRec, GKUtils.GetFirstborn(fTree, iRec))));
                break;

            case StatsMode.smMarriages:
                values.Add(new StatsItem(iName, GKUtils.GetMarriagesCount(iRec)));
                break;

            case StatsMode.smMarriageAge:
                values.Add(new StatsItem(iName, GKUtils.GetMarriageAge(fTree, iRec)));
                break;

            case StatsMode.smSurnames:
            case StatsMode.smNames:
            case StatsMode.smPatronymics:
                GetIndiName(mode, values, iRec);
                break;

            case StatsMode.smAge:
                CheckVal(values, GKUtils.GetAgeStr(iRec, -1));
                break;

            case StatsMode.smLifeExpectancy:
                CheckVal(values, GKUtils.GetLifeExpectancyStr(iRec));
                break;

            case StatsMode.smBirthYears:
            case StatsMode.smBirthTenYears:
            case StatsMode.smBirthPlaces:
                GetEventField(mode, values, iRec, GEDCOMTagName.BIRT);
                break;

            case StatsMode.smDeathYears:
            case StatsMode.smDeathTenYears:
            case StatsMode.smDeathPlaces:
                GetEventField(mode, values, iRec, GEDCOMTagName.DEAT);
                break;

            case StatsMode.smChildsDistribution:
                CheckVal(values, fTree.GetTotalChildrenCount(iRec).ToString());
                break;

            case StatsMode.smResidences:
                CheckVal(values, GKUtils.GetResidencePlace(iRec, false));
                break;

            case StatsMode.smOccupation:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName.OCCU));
                break;

            case StatsMode.smReligious:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName.RELI));
                break;

            case StatsMode.smNational:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName.NATI));
                break;

            case StatsMode.smEducation:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName.EDUC));
                break;

            case StatsMode.smCaste:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName.CAST));
                break;

            case StatsMode.smHobby:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._HOBBY));
                break;

            case StatsMode.smAward:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._AWARD));
                break;

            case StatsMode.smMili:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._MILI));
                break;

            case StatsMode.smMiliInd:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._MILI_IND));
                break;

            case StatsMode.smMiliDis:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._MILI_DIS));
                break;

            case StatsMode.smMiliRank:
                CheckVal(values, GKUtils.GetAttributeValue(iRec, GEDCOMTagName._MILI_RANK));
                break;

            case StatsMode.smCertaintyIndex:
                CheckVal(values, string.Format("{0:0.00}", iRec.GetCertaintyAssessment()));
                break;

            case StatsMode.smBirthByMonth:
                GDMCustomEvent ev = iRec.FindEvent(GEDCOMTagType.BIRT);
                if (ev != null)
                {
                    var dtx = ev.Date.Value as GDMDate;
                    if (dtx != null && dtx.Month > 0)
                    {
                        CheckVal(values, dtx.Month.ToString());
                    }
                }
                break;

            case StatsMode.smDemography:
            {
                int lifeExp = GKUtils.GetLifeExpectancy(iRec);
                if (lifeExp > -1)
                {
                    string v = Convert.ToString(lifeExp / 5 * 5);
                    CheckVal(values, v, iRec.Sex);
                }
                break;
            }
            }
        }