2
# Gramps - a GTK+/GNOME based genealogy program
4
# Copyright (C) 2003-2004 Donald N. Allingham
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
# $Id: Relationship.py,v 1.12 2004/01/23 14:44:28 rshura Exp $
23
#-------------------------------------------------------------------------
27
#-------------------------------------------------------------------------
31
from gettext import gettext as _
33
#-------------------------------------------------------------------------
37
#-------------------------------------------------------------------------
39
_level_name = [ "", "first", "second", "third", "fourth", "fifth", "sixth",
40
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth",
41
"thirteenth", "fourteenth", "fifteenth", "sixteenth",
42
"seventeenth", "eighteenth", "nineteenth", "twentieth" ]
44
_removed_level = [ "", " once removed", " twice removed", " three times removed",
45
" four times removed", " five times removed", " six times removed",
46
" sevent times removed", " eight times removed", " nine times removed",
47
" ten times removed", " eleven times removed", " twelve times removed",
48
" thirteen times removed", " fourteen times removed", " fifteen times removed",
49
" sixteen times removed", " seventeen times removed", " eighteen times removed",
50
" nineteen times removed", " twenty times removed" ]
52
_parents_level = [ "", "parents", "grandparents", "great grandparents", "second great grandparents",
53
"third great grandparents", "fourth great grandparents",
54
"fifth great grandparents", "sixth great grandparents",
55
"seventh great grandparents", "eighth great grandparents",
56
"ninth great grandparents", "tenth great grandparents",
57
"eleventh great grandparents", "twelfth great grandparents",
58
"thirteenth great grandparents", "fourteenth great grandparents",
59
"fifteenth great grandparents", "sixteenth great grandparents",
60
"seventeenth great grandparents", "eighteenth great grandparents",
61
"nineteenth great grandparents", "twentieth great grandparents", ]
63
_father_level = [ "", "father", "grandfather", "great grandfather", "second great grandfather",
64
"third great grandfather", "fourth great grandfather",
65
"fifth great grandfather", "sixth great grandfather",
66
"seventh great grandfather", "eighth great grandfather",
67
"ninth great grandfather", "tenth great grandfather",
68
"eleventh great grandfather", "twelfth great grandfather",
69
"thirteenth great grandfather", "fourteenth great grandfather",
70
"fifteenth great grandfather", "sixteenth great grandfather",
71
"seventeenth great grandfather", "eighteenth great grandfather",
72
"nineteenth great grandfather", "twentieth great grandfather", ]
74
_mother_level = [ "", "mother", "grandmother", "great grandmother", "second great grandmother",
75
"third great grandmother", "fourth great grandmother",
76
"fifth great grandmother", "sixth great grandmother",
77
"seventh great grandmother", "eighth great grandmother",
78
"ninth great grandmother", "tenth great grandmother",
79
"eleventh great grandmother", "twelfth great grandmother",
80
"thirteenth great grandmother", "fourteenth great grandmother",
81
"fifteenth great grandmother", "sixteenth great grandmother",
82
"seventeenth great grandmother", "eighteenth great grandmother",
83
"nineteenth great grandmother", "twentieth great grandmother", ]
85
_son_level = [ "", "son", "grandson", "great grandson", "second great grandson",
86
"third great grandson", "fourth great grandson",
87
"fifth great grandson", "sixth great grandson",
88
"seventh great grandson", "eighth great grandson",
89
"ninth great grandson", "tenth great grandson",
90
"eleventh great grandson", "twelfth great grandson",
91
"thirteenth great grandson", "fourteenth great grandson",
92
"fifteenth great grandson", "sixteenth great grandson",
93
"seventeenth great grandson", "eighteenth great grandson",
94
"nineteenth great grandson", "twentieth great grandson", ]
96
_daughter_level = [ "", "daughter", "granddaughter", "great granddaughter",
97
"second great granddaughter",
98
"third great granddaughter", "fourth great granddaughter",
99
"fifth great granddaughter", "sixth great granddaughter",
100
"seventh great granddaughter", "eighth great granddaughter",
101
"ninth great granddaughter", "tenth great granddaughter",
102
"eleventh great granddaughter", "twelfth great granddaughter",
103
"thirteenth great granddaughter", "fourteenth great granddaughter",
104
"fifteenth great granddaughter", "sixteenth great granddaughter",
105
"seventeenth great granddaughter", "eighteenth great granddaughter",
106
"nineteenth great granddaughter", "twentieth great granddaughter", ]
108
_sister_level = [ "", "sister", "aunt", "grandaunt", "great grandaunt", "second great grandaunt",
109
"third great grandaunt", "fourth great grandaunt",
110
"fifth great grandaunt", "sixth great grandaunt",
111
"seventh great grandaunt", "eighth great grandaunt",
112
"ninth great grandaunt", "tenth great grandaunt",
113
"eleventh great grandaunt", "twelfth great grandaunt",
114
"thirteenth great grandaunt", "fourteenth great grandaunt",
115
"fifteenth great grandaunt", "sixteenth great grandaunt",
116
"seventeenth great grandaunt", "eighteenth great grandaunt",
117
"nineteenth great grandaunt", "twentieth great grandaunt", ]
119
_brother_level = [ "", "brother", "uncle", "granduncle", "great granduncle", "second great granduncle",
120
"third great granduncle", "fourth great granduncle",
121
"fifth great granduncle", "sixth great granduncle",
122
"seventh great granduncle", "eighth great granduncle",
123
"ninth great granduncle", "tenth great granduncle",
124
"eleventh great granduncle", "twelfth great granduncle",
125
"thirteenth great granduncle", "fourteenth great granduncle",
126
"fifteenth great granduncle", "sixteenth great granduncle",
127
"seventeenth great granduncle", "eighteenth great granduncle",
128
"nineteenth great granduncle", "twentieth great granduncle", ]
130
_nephew_level = [ "", "nephew", "grandnephew", "great grandnephew", "second great grandnephew",
131
"third great grandnephew", "fourth great grandnephew",
132
"fifth great grandnephew", "sixth great grandnephew",
133
"seventh great grandnephew", "eighth great grandnephew",
134
"ninth great grandnephew", "tenth great grandnephew",
135
"eleventh great grandnephew", "twelfth great grandnephew",
136
"thirteenth great grandnephew", "fourteenth great grandnephew",
137
"fifteenth great grandnephew", "sixteenth great grandnephew",
138
"seventeenth great grandnephew", "eighteenth great grandnephew",
139
"nineteenth great grandnephew", "twentieth great grandnephew", ]
141
_niece_level = [ "", "niece", "grandniece", "great grandniece", "second great grandniece",
142
"third great grandniece", "fourth great grandniece",
143
"fifth great grandniece", "sixth great grandniece",
144
"seventh great grandniece", "eighth great grandniece",
145
"ninth great grandniece", "tenth great grandniece",
146
"eleventh great grandniece", "twelfth great grandniece",
147
"thirteenth great grandniece", "fourteenth great grandniece",
148
"fifteenth great grandniece", "sixteenth great grandniece",
149
"seventeenth great grandniece", "eighteenth great grandniece",
150
"nineteenth great grandniece", "twentieth great grandniece", ]
152
#-------------------------------------------------------------------------
156
#-------------------------------------------------------------------------
157
def apply_filter(person,index,plist,pmap):
161
pmap[person.getId()] = index
163
family = person.getMainParents()
165
apply_filter(family.getFather(),index+1,plist,pmap)
166
apply_filter(family.getMother(),index+1,plist,pmap)
168
def get_cousin(level,removed):
169
if removed > len(_removed_level)-1 or level>len(_level_name)-1:
170
return "distant relative"
172
return "%s cousin%s" % (_level_name[level],_removed_level[removed])
174
def get_parents(level):
175
if level>len(_parents_level)-1:
176
return "distant ancestors"
178
return _parents_level[level]
180
def get_father(level):
181
if level>len(_father_level)-1:
182
return "distant ancestor"
184
return _father_level[level]
187
if level>len(_son_level)-1:
188
return "distant descendant"
190
return _son_level[level]
192
def get_mother(level):
193
if level>len(_mother_level)-1:
194
return "distant ancestor"
196
return _mother_level[level]
198
def get_daughter(level):
199
if level>len(_daughter_level)-1:
200
return "distant descendant"
202
return _daughter_level[level]
205
if level>len(_sister_level)-1:
206
return "distant ancestor"
208
return _sister_level[level]
210
def get_uncle(level):
211
if level>len(_brother_level)-1:
212
return "distant ancestor"
214
return _brother_level[level]
216
def get_nephew(level):
217
if level>len(_nephew_level)-1:
218
return "distant descendant"
220
return _nephew_level[level]
222
def get_niece(level):
223
if level>len(_niece_level)-1:
224
return "distant descendant"
226
return _niece_level[level]
228
def is_spouse(orig,other):
229
for f in orig.getFamilyList():
230
if other == f.getFather() or other == f.getMother():
234
def get_relationship(orig_person,other_person):
236
returns a string representing the relationshp between the two people,
237
along with a list of common ancestors (typically father,mother)
246
if orig_person == None:
247
return ("undefined",[])
249
if orig_person == other_person:
251
if is_spouse(orig_person,other_person):
255
apply_filter(orig_person,0,firstList,firstMap)
256
apply_filter(other_person,0,secondList,secondMap)
257
except RuntimeError,msg:
258
return (_("Relationship loop detected"),None)
260
for person in firstList:
261
if person in secondList:
262
new_rank = firstMap[person.getId()]
266
elif new_rank == rank:
267
common.append(person)
276
secondRel = firstMap[person.getId()]
277
firstRel = secondMap[person.getId()]
280
secondRel = firstMap[p1.getId()]
281
firstRel = secondMap[p1.getId()]
284
secondRel = firstMap[person.getId()]
285
firstRel = secondMap[person.getId()]
292
elif other_person.getGender() == RelLib.Person.male:
293
return (get_father(secondRel),common)
295
return (get_mother(secondRel),common)
297
if other_person.getGender() == RelLib.Person.male:
298
return (get_son(firstRel),common)
300
return (get_daughter(firstRel),common)
302
if other_person.getGender() == RelLib.Person.male:
303
return (get_uncle(secondRel),common)
305
return (get_aunt(secondRel),common)
307
if other_person.getGender() == RelLib.Person.male:
308
return (get_nephew(firstRel-1),common)
310
return (get_niece(firstRel-1),common)
312
if secondRel > firstRel:
313
return (get_cousin(firstRel-1,secondRel-firstRel),common)
315
return (get_cousin(secondRel-1,firstRel-secondRel),common)
317
def get_grandparents_string(orig_person,other_person):
319
returns a string representing the relationshp between the two people,
320
along with a list of common ancestors (typically father,mother)
329
if orig_person == None:
330
return ("undefined",[])
332
if orig_person == other_person:
335
apply_filter(orig_person,0,firstList,firstMap)
336
apply_filter(other_person,0,secondList,secondMap)
338
for person in firstList:
339
if person in secondList:
340
new_rank = firstMap[person.getId()]
344
elif new_rank == rank:
345
common.append(person)
354
secondRel = firstMap[person.getId()]
355
firstRel = secondMap[person.getId()]
358
secondRel = firstMap[p1.getId()]
359
firstRel = secondMap[p1.getId()]
362
secondRel = firstMap[person.getId()]
363
firstRel = secondMap[person.getId()]
369
return (get_parents(secondRel),common)