Skip to content

Commit

Permalink
Minor improvements (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Dec 3, 2024
1 parent 3d8ea12 commit f7ac2d0
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
12 changes: 6 additions & 6 deletions projects/GKCore/GDModel/GDMIndividualRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ public override void ReplaceXRefs(GDMXRefReplacer map)
fSpouseToFamilyLinks.ReplaceXRefs(map);
}

public sealed class LifeDatesRet
public sealed class LifeEvents
{
public readonly GDMCustomEvent BirthEvent;
public readonly GDMCustomEvent DeathEvent;

public readonly GDMCustomEvent BaptismEvent;
public readonly GDMCustomEvent BurialEvent;

public LifeDatesRet(GDMCustomEvent birthEvent, GDMCustomEvent deathEvent, GDMCustomEvent baptismEvent, GDMCustomEvent burialEvent)
public LifeEvents(GDMCustomEvent birthEvent, GDMCustomEvent deathEvent, GDMCustomEvent baptismEvent, GDMCustomEvent burialEvent)
{
BirthEvent = birthEvent;
DeathEvent = deathEvent;
Expand All @@ -407,7 +407,7 @@ public LifeDatesRet(GDMCustomEvent birthEvent, GDMCustomEvent deathEvent, GDMCus
}
}

public LifeDatesRet GetLifeDates(bool ext = false)
public LifeEvents GetLifeEvents(bool ext = false)
{
GDMCustomEvent birthEvent = null;
GDMCustomEvent deathEvent = null;
Expand All @@ -432,7 +432,7 @@ public LifeDatesRet GetLifeDates(bool ext = false)
}
}

return new LifeDatesRet(birthEvent, deathEvent, baptismEvent, burialEvent);
return new LifeEvents(birthEvent, deathEvent, baptismEvent, burialEvent);
}

public GDMPersonalName GetPrimaryPersonalName()
Expand Down Expand Up @@ -500,8 +500,8 @@ public override float IsMatch(GDMTag tag, MatchParams matchParams)
// 0% name match would be pointless checking other details
if (nameMatch != 0.0f && matchParams.DatesCheck)
{
var dates = GetLifeDates();
var indiDates = indi.GetLifeDates();
var dates = GetLifeEvents();
var indiDates = indi.GetLifeEvents();

if (dates.BirthEvent != null && indiDates.BirthEvent != null) {
birthMatch = dates.BirthEvent.IsMatch(indiDates.BirthEvent, matchParams);
Expand Down
16 changes: 15 additions & 1 deletion projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -591,13 +591,27 @@ public void CollectTips(StringList tipsList)
throw new ArgumentNullException("tipsList");

try {
bool onlyAlive = true;
var dtNow = DateTime.Now;

bool firstTip = true;
var indiEnum = fTree.GetEnumerator<GDMIndividualRecord>();
GDMIndividualRecord iRec;
while (indiEnum.MoveNext(out iRec)) {
var lifeEvents = iRec.GetLifeEvents(true);

if (onlyAlive) {
if (lifeEvents.DeathEvent != null || lifeEvents.BurialEvent != null) continue;
}

int years;
bool anniversary;
int days = GKUtils.GetDaysForBirth(iRec, true, out years, out anniversary);

if (lifeEvents.BirthEvent == null) continue;
var dt = lifeEvents.BirthEvent.Date.Value as GDMDate;
if (dt == null || !dt.IsValidDate()) continue;

int days = GKUtils.GetDaysFor(dt, dtNow, out years, out anniversary);
if (days < 0 || days >= 3) continue;

if (firstTip) {
Expand Down
2 changes: 1 addition & 1 deletion projects/GKCore/GKCore/Charts/TreeChartPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void BuildBy(GDMIndividualRecord iRec)

TreeChartOptions options = fModel.Options;

var lifeDates = iRec.GetLifeDates(true);
var lifeDates = iRec.GetLifeEvents(true);
GDMCustomEvent birthEvent = lifeDates.BirthEvent;
GDMCustomEvent deathEvent = lifeDates.DeathEvent;
string birthSign = ImportUtils.STD_BIRTH_SIGN;
Expand Down
6 changes: 3 additions & 3 deletions projects/GKCore/GKCore/GKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ public static int GetLifeExpectancy(GDMIndividualRecord iRec)
if (iRec == null) return result;

try {
var lifeDates = iRec.GetLifeDates();
var lifeDates = iRec.GetLifeEvents();
result = GetEventsYearsDiff(lifeDates.BirthEvent, lifeDates.DeathEvent, false);
} catch (Exception ex) {
Logger.WriteError("GKUtils.GetLifeExpectancy()", ex);
Expand All @@ -1249,7 +1249,7 @@ public static int GetAge(GDMIndividualRecord iRec, int toYear)
if (iRec == null) return result;

try {
var lifeDates = iRec.GetLifeDates();
var lifeDates = iRec.GetLifeEvents();
result = GetAgeLD(lifeDates, toYear);
} catch (Exception ex) {
Logger.WriteError("GKUtils.GetAge()", ex);
Expand All @@ -1258,7 +1258,7 @@ public static int GetAge(GDMIndividualRecord iRec, int toYear)
return result;
}

public static int GetAgeLD(GDMIndividualRecord.LifeDatesRet lifeDates, int toYear)
public static int GetAgeLD(GDMIndividualRecord.LifeEvents lifeDates, int toYear)
{
int result = -1;
if (lifeDates == null) return result;
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/GEDmill/GMHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public static string ConstructName(string surname, string firstName)

public static string GetLifeDatesStr(GDMIndividualRecord record)
{
var lifeDates = record.GetLifeDates();
var lifeDates = record.GetLifeEvents();
string birthDate = GKUtils.GEDCOMEventToDateStr(lifeDates.BirthEvent, DateFormat.dfYYYY, false);
string deathDate = GKUtils.GEDCOMEventToDateStr(lifeDates.DeathEvent, DateFormat.dfYYYY, false);
return birthDate + " - " + deathDate;
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/GEDmill/HTML/CreatorRecordIndividual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public bool Create(Stats stats, MTTree miniTree)

RemoveLoneOccupation();

var lifeDatesX = fIndiRec.GetLifeDates();
var lifeDatesX = fIndiRec.GetLifeEvents();
fActualBirthday = (lifeDatesX.BirthEvent == null) ? null : lifeDatesX.BirthEvent.Date;
fActualDeathday = (lifeDatesX.DeathEvent == null) ? null : lifeDatesX.DeathEvent.Date;

Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/GEDmill/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ private void SetIndividualSubItems(ListViewItem lvItem, GDMIndividualRecord ir)
string surname, firstName;
GMHelper.CapitaliseName(ir.GetPrimaryPersonalName(), out firstName, out surname);

var lifeDatesX = ir.GetLifeDates();
var lifeDatesX = ir.GetLifeEvents();
var birthDate = (lifeDatesX.BirthEvent == null) ? 0 : lifeDatesX.BirthEvent.Date.GetChronologicalYear();
var deathDate = (lifeDatesX.DeathEvent == null) ? 0 : lifeDatesX.DeathEvent.Date.GetChronologicalYear();
string uref = (ir.HasUserReferences) ? ir.UserReferences[0].StringValue : "";
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/GKStdReports/ContemporariesReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ContemporariesReport(IBaseWindow baseWin, GDMIndividualRecord selectedPer

private Range<int> GetIndividualDates(GDMIndividualRecord iRec)
{
var dates = iRec.GetLifeDates();
var dates = iRec.GetLifeEvents();

int yBirth = (dates.BirthEvent == null) ? 0 : dates.BirthEvent.GetChronologicalYear();
int yDeath = (dates.DeathEvent == null) ? 0 : dates.DeathEvent.GetChronologicalYear();
Expand Down

0 comments on commit f7ac2d0

Please sign in to comment.