Skip to content

Commit

Permalink
Added mode for displaying parents' ages in tree diagrams (fix #600)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Oct 24, 2024
1 parent 852d81b commit b2c201f
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 4 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>??.??.2024 [v2.32.0 &amp; v3.8.0]</b><ul>
<li>Added mode for displaying parents' ages in tree diagrams.
<li>Added an option to simplify the form of woman single surnames in extended mode (output without brackets if there are no other surnames).
<li>Added protection against problems with folders in Windows if the file name has a space before the extension.
<li>Added statistics type on parents' ages at child's birth.
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>??.??.2024 [v2.32.0 &amp; v3.8.0]</b><ul>
<li>Добавлен режим отображения возрастов родителей в диаграммах деревьев.
<li>Добавлена опция упрощения формы единственных фамилий женщин в расширенном режиме (вывод без скобок, если других фамилий нет).
<li>Добавлена защита от проблем с папками в Windows, если в имени файла перед расширением есть пробел.
<li>Добавлен тип статистики по возрастам родителей при рождении ребенка.
Expand Down
37 changes: 34 additions & 3 deletions projects/GKCore/GKCore/Charts/TreeChartModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class TreeChartModel : ChartModel
private float fPicScale;
private IImage[] fSignsPic;
private IBrush fSolidBlack;
private IBrush fSolidF, fSolidM;
private int fSpouseDistance;
private ITimer fTimer;
private GDMTree fTree;
Expand Down Expand Up @@ -420,6 +421,8 @@ public void Assign(TreeChartModel sourceModel)
fScale = sourceModel.fScale;
fSignsPic = sourceModel.fSignsPic;
fSolidBlack = sourceModel.fSolidBlack;
fSolidF = sourceModel.fSolidF;
fSolidM = sourceModel.fSolidM;
fSpouseDistance = sourceModel.fSpouseDistance;
fTree = sourceModel.fTree;
}
Expand Down Expand Up @@ -526,6 +529,8 @@ private void VisitAncestors(TreeChartPerson personNode, bool dupFlag)
personNode.Mother = VisitParent(personNode, iMother, personNode.Generation - 1, isDup, divorced, adopted, commonLaw);
}

personNode.SetParents();

if (personNode.Father != null && personNode.Mother != null && fOptions.Kinship) {
fGraph.AddRelation(personNode.Father.Node, personNode.Mother.Node, RelationKind.rkSpouse, RelationKind.rkSpouse, (!commonLaw ? RelationExt.None : RelationExt.CommonLaw));
}
Expand Down Expand Up @@ -821,6 +826,7 @@ private TreeChartPerson VisitPerson(TreeChartPerson parent, GDMIndividualRecord
child.Father = ft;
child.Mother = mt;
child.SetFlag(descFlag);
child.SetParents();

GDMChildToFamilyLink childLink = childRec.FindChildToFamilyLink(family);
var adopted = (childLink != null && (childLink.PedigreeLinkageType == GDMPedigreeLinkageType.plAdopted));
Expand Down Expand Up @@ -1633,6 +1639,8 @@ public void InitGraphics()
fLineDottedDecorativePen = fRenderer.CreatePen(clrDecor, 1f, new float[] {4.0F, 2.0F});
fLineDottedSelectedPen = fRenderer.CreatePen(clrLine, 2.4f, new float[] { 4.0F, 2.0F });
fSolidBlack = fRenderer.CreateBrush(fClrBlack);
fSolidF = fRenderer.CreateBrush(ChartRenderer.GetColor(BSDColors.Red));
fSolidM = fRenderer.CreateBrush(ChartRenderer.GetColor(BSDColors.Blue));

var clrGreen = ChartRenderer.GetColor(BSDColors.ForestGreen);
fLineTMSYPen = fRenderer.CreatePen(clrGreen, 2.4f, new float[] { 4.0F, 2.0F });
Expand All @@ -1649,6 +1657,8 @@ private void DoneGraphics()
if (fLineDottedDecorativePen != null) fLineDottedDecorativePen.Dispose();
if (fLineDottedSelectedPen != null) fLineDottedSelectedPen.Dispose();
if (fSolidBlack != null) fSolidBlack.Dispose();
if (fSolidF != null) fSolidF.Dispose();
if (fSolidM != null) fSolidM.Dispose();
}

public ExtRect GetExpanderRect(ExtRect personRect)
Expand Down Expand Up @@ -1936,6 +1946,18 @@ private bool IsDottedLines(TreeChartPerson person)
return (person != null && person.HasFlag(PersonFlag.pfAdopted) && fOptions.DottedLinesOfAdoptedChildren);
}

private void DrawParentAges(TreeChartPerson person, int pY, int crY)
{
if (!fOptions.ParentAges || (string.IsNullOrEmpty(person.FatherAge) && string.IsNullOrEmpty(person.MotherAge)))
return;

var tH = (int)fRenderer.GetTextSize("0", fDrawFont).Height;
int aY = (!fOptions.InvertedTree) ? crY + (pY - crY - tH) / 2 : pY + (crY - pY - tH) / 2;

DrawText(person.FatherAge, person.PtX - 4, aY, 3, fSolidM);
DrawText(person.MotherAge, person.PtX + 4, aY, 2, fSolidF);
}

private void DrawAncestors(TreeChartPerson person, ChartDrawMode drawMode, bool isTracked)
{
if (person.IsCollapsed || (person.Father == null && person.Mother == null)) {
Expand All @@ -1955,18 +1977,21 @@ private void DrawAncestors(TreeChartPerson person, ChartDrawMode drawMode, bool
Draw(person.Father, TreeChartKind.ckAncestors, drawMode);
Draw(person.Mother, TreeChartKind.ckAncestors, drawMode);

int crY, parY;
int crY, parY, pY;
if (!fOptions.InvertedTree) {
pY = person.PtY;
crY = person.PtY - fLevelDistance / 2;
parY = (person.Father != null) ? person.Father.PtY + person.Father.Height : person.Mother.PtY + person.Mother.Height;
} else {
pY = person.PtY + person.Height;
crY = person.PtY + person.Height + fLevelDistance / 2;
parY = (person.Father != null) ? person.Father.PtY : person.Mother.PtY;
}

bool dotted = IsDottedLines(person);

DrawLine(person.PtX, crY, person.PtX, person.PtY, dotted, isTrackedAncestors, isMatchedFather || isMatchedMother); // v
DrawLine(person.PtX, crY, person.PtX, pY, dotted, isTrackedAncestors, isMatchedFather || isMatchedMother); // v
DrawParentAges(person, pY, crY);

string marrDate = null;

Expand Down Expand Up @@ -1995,6 +2020,11 @@ private void DrawAncestors(TreeChartPerson person, ChartDrawMode drawMode, bool
}

private void DrawText(string text, float x, float y, int quad, bool offset = true)
{
DrawText(text, x, y, quad, fSolidBlack, offset);
}

private void DrawText(string text, float x, float y, int quad, IBrush brush, bool offset = true)
{
if (string.IsNullOrEmpty(text))
return;
Expand All @@ -2021,7 +2051,7 @@ private void DrawText(string text, float x, float y, int quad, bool offset = tru
break;
}

fRenderer.DrawString(text, fDrawFont, fSolidBlack, x, y);
fRenderer.DrawString(text, fDrawFont, brush, x, y);
}

private void DrawDescendants(TreeChartPerson person, ChartDrawMode drawMode, bool isTracked)
Expand Down Expand Up @@ -2138,6 +2168,7 @@ private void DrawDescendants(TreeChartPerson person, ChartDrawMode drawMode, boo
}

DrawLine(child.PtX, chY, child.PtX, crY, dotted, isTrackedChild, isMatchedChild); // v
DrawParentAges(child, chY, crY);
}

// vertical line from the horizontal junction of spouses to the horizontal junction of children
Expand Down
36 changes: 36 additions & 0 deletions projects/GKCore/GKCore/Charts/TreeChartPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using BSLib;
using BSLib.DataViz.SmartGraph;
using GDModel;
using GDModel.Providers.GEDCOM;
using GKCore.Design.Graphics;
using GKCore.Import;
using GKCore.Options;
Expand Down Expand Up @@ -92,6 +93,8 @@ public class TreeChartPerson
public float CertaintyAssessment;
public TreeChartPerson Father;
public TreeChartPerson Mother;
public string FatherAge;
public string MotherAge;
public int Generation;
public string Kinship;
public string[] Lines;
Expand Down Expand Up @@ -413,6 +416,39 @@ public void BuildBy(GDMIndividualRecord iRec)
}
}

public void SetParents()
{
if (!fModel.Options.ParentAges || fRec == null) return;

FatherAge = string.Empty;
MotherAge = string.Empty;

GDMCustomEvent evt = fRec.FindEvent(GEDCOMTagName.BIRT);
if (evt == null) return;
int childYear = evt.GetChronologicalYear();
if (childYear == 0) return;

if (Father != null && Father.Rec != null) {
evt = Father.Rec.FindEvent(GEDCOMTagName.BIRT);
if (evt != null) {
int parentYear = evt.GetChronologicalYear();
if (parentYear != 0) {
FatherAge = (childYear - parentYear).ToString();
}
}
}

if (Mother != null && Mother.Rec != null) {
evt = Mother.Rec.FindEvent(GEDCOMTagName.BIRT);
if (evt != null) {
int parentYear = evt.GetChronologicalYear();
if (parentYear != 0) {
MotherAge = (childYear - parentYear).ToString();
}
}
}
}

internal static int InitInfoSize(TreeChartOptions options)
{
int lines = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ public override void SetLocale()
GetControl<IMenuItem>("miTrackSelectedLines").Text = LangMan.LS(LSID.TrackSelectedLines);
GetControl<IMenuItem>("miTrackMatchedSources").Text = LangMan.LS(LSID.TrackMatchedSources);
GetControl<IMenuItem>("miHideDescSpouses").Text = LangMan.LS(LSID.HideDescSpouses);
GetControl<IMenuItem>("miParentAges").Text = LangMan.LS(LSID.ParentsAge);

SetToolTip("tbModes", LangMan.LS(LSID.ModesTip));
SetToolTip("tbImageSave", LangMan.LS(LSID.ImageSaveTip));
Expand Down
7 changes: 7 additions & 0 deletions projects/GKCore/GKCore/Options/TreeChartOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public sealed class TreeChartOptions : IOptions
public bool TrackSelectedLines;
public bool TrackMatchedSources;
public bool FullNameOnOneLine;
public bool ParentAges;

public IColor MaleColor;
public IColor FemaleColor;
Expand Down Expand Up @@ -177,6 +178,7 @@ public void ResetDefaults()
UseExtraControls = true;
UseInlineImagesInSvg = true;
ExtendedTree = false;
ParentAges = false;
}

public void Assign(IOptions source)
Expand Down Expand Up @@ -240,6 +242,7 @@ public void Assign(IOptions source)
UseExtraControls = srcOptions.UseExtraControls;
UseInlineImagesInSvg = srcOptions.UseInlineImagesInSvg;
ExtendedTree = srcOptions.ExtendedTree;
ParentAges = srcOptions.ParentAges;
}

public void LoadFromFile(IniFile iniFile)
Expand Down Expand Up @@ -310,6 +313,8 @@ public void LoadFromFile(IniFile iniFile)
TrackSelectedLines = iniFile.ReadBool("Chart", "TrackSelectedLines", true);
TrackMatchedSources = iniFile.ReadBool("Chart", "TrackMatchedSources", false);
FullNameOnOneLine = iniFile.ReadBool("Chart", "FullNameOnOneLine", false);

ParentAges = iniFile.ReadBool("Chart", "ParentAges", false);
}

public void SaveToFile(IniFile iniFile)
Expand Down Expand Up @@ -380,6 +385,8 @@ public void SaveToFile(IniFile iniFile)
iniFile.WriteBool("Chart", "TrackSelectedLines", TrackSelectedLines);
iniFile.WriteBool("Chart", "TrackMatchedSources", TrackMatchedSources);
iniFile.WriteBool("Chart", "FullNameOnOneLine", FullNameOnOneLine);

iniFile.WriteBool("Chart", "ParentAges", ParentAges);
}
}
}
11 changes: 10 additions & 1 deletion projects/GKv2/GEDKeeper2/GKUI/Forms/TreeChartWin.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions projects/GKv2/GEDKeeper2/GKUI/Forms/TreeChartWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public TreeChartWin(IBaseWindow baseWin)

miTrackMatchedSources.Checked = fTreeBox.Options.TrackMatchedSources;

miParentAges.Checked = fTreeBox.Options.ParentAges;

miTraceSelected.Checked = fTreeBox.Options.TraceSelected;
fTreeBox.TraceSelected = fTreeBox.Options.TraceSelected;

Expand Down Expand Up @@ -422,6 +424,17 @@ private void miTrackMatchedSources_Click(object sender, EventArgs e)
fTreeBox.Invalidate();
}

private void miParentAges_Click(object sender, EventArgs e)
{
miParentAges.Checked = !miParentAges.Checked;
fTreeBox.Options.ParentAges = miParentAges.Checked;
if (fTreeBox.Options.ParentAges) {
GenChart();
} else {
fTreeBox.Invalidate();
}
}

private void miFillColor_Click(object sender, EventArgs e)
{
using (var colorDialog1 = new ColorDialog()) {
Expand Down
17 changes: 17 additions & 0 deletions projects/GKv3/GEDKeeper3/GKUI/Forms/TreeChartWin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public partial class TreeChartWin : PrintableForm, ITreeChartWin
private GKDropDownToolItem tbBorders;
private ContextMenu MenuBorders;
private CheckMenuItem miHideDescSpouses;
private CheckMenuItem miParentAges;

#pragma warning restore CS0169, CS0649, IDE0044, IDE0051
#endregion
Expand Down Expand Up @@ -151,6 +152,8 @@ public TreeChartWin(IBaseWindow baseWin)

miTrackMatchedSources.Checked = fTreeBox.Options.TrackMatchedSources;

miParentAges.Checked = fTreeBox.Options.ParentAges;

miTraceSelected.Checked = fTreeBox.Options.TraceSelected;
fTreeBox.TraceSelected = fTreeBox.Options.TraceSelected;

Expand Down Expand Up @@ -208,6 +211,9 @@ private void InitializeComponent()
miTrackMatchedSources = new CheckMenuItem();
miTrackMatchedSources.Click += miTrackMatchedSources_Click;

miParentAges = new CheckMenuItem();
miParentAges.Click += miParentAges_Click;

miFillColor = new ButtonMenuItem();
miFillColor.Click += miFillColor_Click;

Expand All @@ -227,6 +233,7 @@ private void InitializeComponent()
miXRefVisible,
miTrackSelectedLines,
miTrackMatchedSources,
miParentAges,
new SeparatorMenuItem(),
miFillColor,
miFillImage,
Expand Down Expand Up @@ -582,6 +589,16 @@ private void miTrackMatchedSources_Click(object sender, EventArgs e)
fTreeBox.Invalidate();
}

private void miParentAges_Click(object sender, EventArgs e)
{
fTreeBox.Options.ParentAges = miParentAges.Checked;
if (fTreeBox.Options.ParentAges) {
GenChart();
} else {
fTreeBox.Invalidate();
}
}

private void miFillColor_Click(object sender, EventArgs e)
{
using (var colorDialog1 = new ColorDialog()) {
Expand Down

0 comments on commit b2c201f

Please sign in to comment.