2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2004-05-05 07:34:30 +05:30
|
|
|
# Copyright (C) 2000-2004 Donald N. Allingham
|
2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2004-05-05 07:34:30 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
class GraphLayout:
|
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
def __init__(self,database,plist,person_handle):
|
2004-05-05 07:34:30 +05:30
|
|
|
self.database = database
|
2002-10-20 19:55:16 +05:30
|
|
|
self.plist = plist
|
2004-07-28 07:59:07 +05:30
|
|
|
self.person_handle = person_handle
|
2002-10-20 19:55:16 +05:30
|
|
|
self.v = []
|
|
|
|
self.e = []
|
|
|
|
self.maxx = 0
|
|
|
|
self.maxy = 0
|
|
|
|
|
|
|
|
def max_size(self):
|
|
|
|
return (self.maxx,self.maxy)
|
|
|
|
|
|
|
|
def layout(self):
|
|
|
|
return ([],[])
|
|
|
|
|
|
|
|
class DescendLine(GraphLayout):
|
|
|
|
|
|
|
|
def layout(self):
|
|
|
|
self.elist = [(0,0)]
|
2004-07-28 07:59:07 +05:30
|
|
|
self.space_for(self.person_handle)
|
2002-10-20 19:55:16 +05:30
|
|
|
return (self.v,self.e[1:])
|
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
def space_for(self,person_handle,level=1.0,pos=1.0):
|
2002-10-20 19:55:16 +05:30
|
|
|
last = self.elist[-1]
|
|
|
|
self.elist.append((level,pos))
|
|
|
|
self.e.append((last[0],last[1],level,pos))
|
2004-07-28 07:59:07 +05:30
|
|
|
self.v.append((person_handle,level,pos))
|
2002-10-20 19:55:16 +05:30
|
|
|
if level > self.maxx:
|
|
|
|
self.maxx = level
|
|
|
|
if pos > self.maxy:
|
|
|
|
self.maxy = pos
|
|
|
|
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for family_handle in person.get_family_handle_list():
|
2004-08-20 03:05:16 +05:30
|
|
|
family = self.database.get_family_from_handle(family_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in family.get_child_handle_list():
|
|
|
|
self.space_for(child_handle,level+1.0,pos)
|
|
|
|
pos = pos + max(self.depth(child_handle),1)
|
2002-10-20 19:55:16 +05:30
|
|
|
if pos > self.maxy:
|
|
|
|
self.maxy = pos
|
|
|
|
self.elist.pop()
|
|
|
|
|
2004-07-28 07:59:07 +05:30
|
|
|
def depth(self,person_handle,val=0):
|
2004-08-07 10:46:57 +05:30
|
|
|
person = self.database.get_person_from_handle(person_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
for family_handle in person.get_family_handle_list():
|
2004-08-20 03:05:16 +05:30
|
|
|
family = self.database.get_family_from_handle(family_handle)
|
2004-07-28 07:59:07 +05:30
|
|
|
clist = family.get_child_handle_list()
|
2002-10-20 19:55:16 +05:30
|
|
|
val = val + len(clist)
|
2004-07-28 07:59:07 +05:30
|
|
|
for child_handle in clist:
|
|
|
|
d = self.depth(child_handle)
|
2002-10-28 19:06:39 +05:30
|
|
|
if d > 0:
|
|
|
|
val = val + d - 1 #first child is always on the same
|
|
|
|
return val #row as the parent, so subtract 1
|