Skip to content

Commit

Permalink
Added calling of ancestor, descendant and all persons maps from tree …
Browse files Browse the repository at this point in the history
…diagrams
  • Loading branch information
Serg-Norseman committed Jan 30, 2025
1 parent 7fbb3e3 commit cabd30b
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 14 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>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Added calling of ancestor, descendant and all persons maps from tree diagrams.</li>
<li>Added a number of checks for adding invalid links between different records.</li>
<li>Added functions for moving multimedia files between absolute and relative paths, archive and storage.</li>
<li>Minor improvements.</li>
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>??.??.2025 [v2.32.1 &amp; v3.8.1]</b></p>
<ul>
<li>Добавлен вызов карт предков, потомков и всех персон из диаграмм деревьев.</li>
<li>Добавлен ряд проверок на добавление недопустимых ссылок между различными записями.</li>
<li>Добавлены функции перемещения мультимедиа-файлов между абсолютными и относительными путями, архивом и хранилищем.</li>
<li>Мелкие улучшения.</li>
Expand Down
45 changes: 44 additions & 1 deletion projects/GKCore/GKCore/Charts/TreeChartModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -2329,5 +2329,48 @@ public static bool CheckTreeChartSize(GDMTree tree, GDMIndividualRecord iRec, Tr

return result;
}

#region Maps

public List<GDMIndividualRecord> GetAncestors(TreeChartPerson person)
{
var result = new HashSet<GDMIndividualRecord>();
GetAncestors(person, result);
return result.ToList();
}

private void GetAncestors(TreeChartPerson person, HashSet<GDMIndividualRecord> ancestors)
{
if (person == null || person.Rec == null) return;

ancestors.Add(person.Rec);

if (person.Father != null) GetAncestors(person.Father, ancestors);
if (person.Mother != null) GetAncestors(person.Mother, ancestors);
}

public List<GDMIndividualRecord> GetDescendants(TreeChartPerson person)
{
var result = new HashSet<GDMIndividualRecord>();
GetDescendants(person, result);
return result.ToList();
}

private void GetDescendants(TreeChartPerson person, HashSet<GDMIndividualRecord> descendants)
{
if (person == null || person.Rec == null) return;

int childrenCount = person.GetChildsCount();
for (int i = 0; i < childrenCount; i++) {
GetDescendants(person.GetChild(i), descendants);
}

int spousesCount = person.GetSpousesCount();
for (int i = 0; i < spousesCount; i++) {
GetDescendants(person.GetSpouse(i), descendants);
}
}

#endregion
}
}
45 changes: 45 additions & 0 deletions projects/GKCore/GKCore/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,5 +1520,50 @@ public static void ShowMap_Indi(IBaseWindow baseWin, GDMLocationRecord locRec)

ShowMap(baseWin, geoPoints);
}

public static void ShowMap_IndiList(IBaseWindow baseWin, List<GDMIndividualRecord> indiList)
{
var tree = baseWin.Context.Tree;

var locations = new Dictionary<GDMLocationRecord, HashSet<GDMIndividualRecord>>();

for (int i = 0; i < indiList.Count; i++) {
var indiRec = indiList[i];

var locs = new HashSet<GDMLocationRecord>();
GKUtils.GetIndividualLocations(tree, indiRec, locs);

foreach (var locRec in locs) {
if (locRec.Map.IsEmpty()) continue;

HashSet<GDMIndividualRecord> indiSet = null;
if (!locations.TryGetValue(locRec, out indiSet)) {
indiSet = new HashSet<GDMIndividualRecord>();
locations.Add(locRec, indiSet);
}
indiSet.Add(indiRec);
}
}

var locName = new StringBuilder();
var geoPoints = new List<GeoPoint>();
foreach (var location in locations) {
var locRec = location.Key;
var indiSet = location.Value;

locName.AppendLine(GKUtils.GetRecordName(tree, locRec, false));
var mapPt = locRec.Map;

foreach (var iRec in indiSet) {
string iName = GKUtils.GetRecordName(tree, iRec, false);
locName.AppendLine(iName);
}

geoPoints.Add(new GeoPoint(mapPt.Lati, mapPt.Long, locName.ToString()));
locName.Clear();
}

ShowMap(baseWin, geoPoints);
}
}
}
43 changes: 41 additions & 2 deletions projects/GKCore/GKCore/Controllers/TreeChartWinController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand All @@ -18,13 +18,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using GDModel;
using GKCore.Charts;
using GKCore.Design.Controls;
using GKCore.Design;
using GKCore.Design.Controls;
using GKCore.Design.Views;
using GKCore.Maps;
using GKCore.Options;
using GKCore.Tools;
using GKCore.Types;

namespace GKCore.Controllers
Expand Down Expand Up @@ -332,6 +337,35 @@ public void SetupDepth()
GetControl<IButtonToolItem>("tbGensDescendants").Visible = treeOptions.SeparateDepth;
}

public void ShowMapAncestors()
{
TreeChartPerson p = fView.TreeBox.Selected;
if (p != null) {
var selectedIndividuals = fView.TreeBox.Model.GetAncestors(p);
BaseController.ShowMap_IndiList(fBase, selectedIndividuals);
}
}

public void ShowMapDescendants()
{
TreeChartPerson p = fView.TreeBox.Selected;
if (p != null) {
var selectedIndividuals = fView.TreeBox.Model.GetDescendants(p);
BaseController.ShowMap_IndiList(fBase, selectedIndividuals);
}
}

public void ShowMapAll()
{
var selectedIndividuals = new List<GDMIndividualRecord>();
var model = fView.TreeBox.Model;
for (int i = 0; i < model.Persons.Count; i++) {
GDMIndividualRecord indiRec = model.Persons[i].Rec;
if (indiRec != null) selectedIndividuals.Add(indiRec);
}
BaseController.ShowMap_IndiList(fBase, selectedIndividuals);
}

public override void SetLocale()
{
GetControl<IButtonToolItem>("tbGensCommon").Text = LangMan.LS(LSID.Generations);
Expand Down Expand Up @@ -382,6 +416,11 @@ public override void SetLocale()
GetControl<IMenuItem>("miRebuildKinships").Text = LangMan.LS(LSID.RebuildKinships);
GetControl<IMenuItem>("miSelectColor").Text = LangMan.LS(LSID.SelectColor);

GetControl<IMenuItem>("miMaps").Text = LangMan.LS(LSID.MIMap);
GetControl<IMenuItem>("miMapAncestors").Text = LangMan.LS(LSID.Ancestors);
GetControl<IMenuItem>("miMapDescendants").Text = LangMan.LS(LSID.Descendants);
GetControl<IMenuItem>("miMapAll").Text = LangMan.LS(LSID.TM_Both);

GetControl<IMenuItem>("miFillColor").Text = LangMan.LS(LSID.FillColor);
GetControl<IMenuItem>("miFillImage").Text = LangMan.LS(LSID.FillImage);
GetControl<IMenuItem>("miTraceSelected").Text = LangMan.LS(LSID.TM_TraceSelected);
Expand Down
25 changes: 18 additions & 7 deletions projects/GKCore/GKCore/GKUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,19 @@ public static void GetLocationIndividuals(GDMTree tree, GDMLocationRecord locRec
}
}

public static void GetIndividualLocations(GDMTree tree, GDMIndividualRecord indiRec, HashSet<GDMLocationRecord> locationRecords)
{
if (indiRec == null || !indiRec.HasEvents) return;

for (int j = 0, num2 = indiRec.Events.Count; j < num2; j++) {
GDMCustomEvent evt = indiRec.Events[j];
if (!evt.HasPlace) continue;

var locRec = tree.GetPtrValue<GDMLocationRecord>(evt.Place.Location);
if (locRec != null) locationRecords.Add(locRec);
}
}

public static string HyperLink(string xref, string text)
{
string result;
Expand Down Expand Up @@ -1098,8 +1111,7 @@ public static string GetPedigreeLifeStr(GDMIndividualRecord iRec, PedigreeFormat
string result = "";

switch (fmt) {
case PedigreeFormat.Excess:
{
case PedigreeFormat.Excess: {
string ds = GetBirthDate(iRec, GlobalOptions.Instance.DefDateFormat, true);
if (ds == "") {
ds = "?";
Expand All @@ -1118,8 +1130,7 @@ public static string GetPedigreeLifeStr(GDMIndividualRecord iRec, PedigreeFormat
}
break;

case PedigreeFormat.Compact:
{
case PedigreeFormat.Compact: {
string ds, ps;

GetEventDatePlace(iRec, GEDCOMTagName.BIRT, GlobalOptions.Instance.DefDateFormat, true, true, out ds, out ps);
Expand Down Expand Up @@ -2013,7 +2024,7 @@ public static Stream LoadResourceStream(Type baseType, string resName)

public static string GetRelativePath(string fromFileName, string toFileName)
{
var fromPath = Path.GetDirectoryName(fromFileName)+ Path.DirectorySeparatorChar;
var fromPath = Path.GetDirectoryName(fromFileName) + Path.DirectorySeparatorChar;

var fromUri = new Uri(fromPath);
var toUri = new Uri(toFileName);
Expand Down Expand Up @@ -2640,7 +2651,7 @@ public static void ShowFamilyInfo(IBaseContext baseContext, GDMFamilyRecord fami
summary.EndUpdate();
}
} catch (Exception ex) {
Logger.WriteError("GKUtils.ShowFamilyInfo()" , ex);
Logger.WriteError("GKUtils.ShowFamilyInfo()", ex);
}
}

Expand Down Expand Up @@ -2976,7 +2987,7 @@ public static void ShowRepositoryInfo(IBaseContext baseContext, GDMRepositoryRec
GDMRecord rec = tree[i];

if (rec.RecordType == GDMRecordType.rtSource) {
GDMSourceRecord srcRec = (GDMSourceRecord) rec;
GDMSourceRecord srcRec = (GDMSourceRecord)rec;

int num2 = srcRec.RepositoryCitations.Count;
for (int j = 0; j < num2; j++) {
Expand Down
12 changes: 11 additions & 1 deletion projects/GKv2/GEDKeeper2/GKUI/Forms/MapsViewerWin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2025 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -137,8 +137,16 @@ public MapsViewerWin(IBaseWindow baseWin)
}
}

private void SetControlsPanelVisible(bool visible)
{
this.tbLoadPlaces.Visible = visible;
this.PageControl1.Visible = visible;
}

public void ShowFixedPoints(IEnumerable<GeoPoint> points)
{
SetControlsPanelVisible(false);

fController.ShowFixedPoints(points);
}

Expand Down Expand Up @@ -223,6 +231,8 @@ private void tbLoadPlaces_Click(object sender, EventArgs e)

private void tbClear_Click(object sender, EventArgs e)
{
SetControlsPanelVisible(true);

fMapBrowser.Objects.Clear();
}

Expand Down
48 changes: 48 additions & 0 deletions 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.

Loading

0 comments on commit cabd30b

Please sign in to comment.