1 /*
2  *  "GEDKeeper", the personal genealogical database editor.
3  *  Copyright (C) 2009-2018 by Sergey V. Zhdanovskih.
4  *
5  *  This file is part of "GEDKeeper".
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 using System.Collections.Generic;
22 using GDModel;
23 using GKCore.MVP;
24 using GKCore.MVP.Views;
25 using GKCore.Tools;
26 
27 namespace GKCore.Controllers
28 {
29     /// <summary>
30     ///
31     /// </summary>
32     public class TreeCompareController : DialogController<ITreeCompareDlg>
33     {
34         private string fExternalFile;
35 
TreeCompareController(ITreeCompareDlg view)36         public TreeCompareController(ITreeCompareDlg view) : base(view)
37         {
38         }
39 
UpdateView()40         public override void UpdateView()
41         {
42         }
43 
SelectExternalFile()44         public void SelectExternalFile()
45         {
46             string fileName = AppHost.StdDialogs.GetOpenFile("", "", LangMan.LS(LSID.LSID_GEDCOMFilter), 1, GKData.GEDCOM_EXT);
47             if (string.IsNullOrEmpty(fileName)) return;
48 
49             fExternalFile = fileName;
50             fView.ExternalBase.Text = fileName;
51         }
52 
DuplicateFoundFunc(GDMIndividualRecord indivA, GDMIndividualRecord indivB)53         private void DuplicateFoundFunc(GDMIndividualRecord indivA, GDMIndividualRecord indivB)
54         {
55             fView.CompareOutput.AppendText("    * [" + GKUtils.GetNameString(indivA, true, false) + "]\r\n");
56             fView.CompareOutput.AppendText("      [" + GKUtils.GetNameString(indivB, true, false) + "]\r\n\r\n");
57         }
58 
Match()59         public void Match()
60         {
61             TreeMatchType type = fView.GetTreeMatchType();
62 
63             fView.CompareOutput.Clear();
64             var tree = fBase.Context.Tree;
65 
66             switch (type) {
67                 case TreeMatchType.tmtInternal:
68                     TreeTools.FindDuplicates(tree, tree, 90 /*min: 80-85*/, DuplicateFoundFunc, AppHost.Progress);
69                     break;
70 
71                 case TreeMatchType.tmtExternal:
72                     TreeTools.CompareTree(fBase.Context, fExternalFile, fView.CompareOutput);
73                     break;
74 
75                 case TreeMatchType.tmtAnalysis:
76                     {
77                         List<TreeTools.ULIndividual> uln = TreeTools.GetUnlinkedNamesakes(fBase);
78 
79                         fView.CompareOutput.AppendText("  " + LangMan.LS(LSID.LSID_SearchUnlinkedNamesakes) + ":\r\n");
80                         if (uln != null && uln.Count > 0) {
81                             foreach (TreeTools.ULIndividual indiv in uln) {
82                                 fView.CompareOutput.AppendText("    - [" + indiv.Family + "] " + GKUtils.GetNameString(indiv.IRec, true, false) + "\r\n");
83                             }
84                         } else {
85                             fView.CompareOutput.AppendText("    - not found.");
86                         }
87                         break;
88                     }
89             }
90         }
91     }
92 }
93