update shadows to be more like Descendant report

updated _fill function to be iterative.  not recursive.



svn: r16389
This commit is contained in:
Craig J. Anderson 2011-01-16 04:27:43 +00:00
parent 5b9422469b
commit 21772a92db

View File

@ -1,7 +1,10 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2008-2010 Craig J. Anderson ander882@hotmail.com # Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant#
# Copyright (C) 2010 Craig J. Anderson
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@ -129,10 +132,9 @@ class FamilyBox(AncestorBoxBase):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class Line(LineBase): class Line(LineBase):
""" Our line class.""" """ Our line class."""
def __init__(self, start, level): def __init__(self, start):
LineBase.__init__(self, start) LineBase.__init__(self, start)
self.linestr = 'AC2-line' self.linestr = 'AC2-line'
#self.level = level
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -235,11 +237,10 @@ class MakeAncestorTree(object):
order of people inserted into Persons is important. order of people inserted into Persons is important.
makes sure that order is done correctly. makes sure that order is done correctly.
""" """
def __init__(self, dbase, canvas, max_gen, inc_marr, inc_spouses, fill_out): def __init__(self, dbase, canvas, max_gen, inc_marr, fill_out):
self.database = dbase self.database = dbase
self.canvas = canvas self.canvas = canvas
self.inlc_marr = inc_marr self.inlc_marr = inc_marr
self.inc_spouses = inc_spouses
self.max_generations = max_gen self.max_generations = max_gen
self.fill_out = fill_out self.fill_out = fill_out
@ -270,21 +271,21 @@ class MakeAncestorTree(object):
self.canvas.add_box(myself) self.canvas.add_box(myself)
def add_line(self, person, index, father, marriage, mother): def add_line(self, person, father, mother = None):
""" Adds the line connecting the boxes """ """ Adds the line connecting the boxes """
if father is None and mother is None: if father is None and mother is None:
return return
line = Line(person, index) line = Line(person)
if father is not None: if father is not None:
line.add_to(father) line.add_to(father)
if marriage is not None:
line.add_to(marriage)
if mother is not None: if mother is not None:
line.add_to(mother) line.add_to(mother)
self.canvas.add_line(line) self.canvas.add_line(line)
return line
def recurse(self, person_handle, family_handle, index): def recurse(self, person_handle, family_handle, index):
""" traverse the ancestors recursively until either the end """ traverse the ancestors recursively until either the end
of a line is found, or until we reach the maximum number of of a line is found, or until we reach the maximum number of
@ -295,8 +296,8 @@ class MakeAncestorTree(object):
person = self.database.get_person_from_handle(person_handle) person = self.database.get_person_from_handle(person_handle)
if person is None: if person is None:
return self.__fill(index, None, self.fill_out) return self.__fill(index, None,
min(self.fill_out, self.max_generations-X_INDEX(index)-1))
parents_handle = person.get_main_parents_family_handle() parents_handle = person.get_main_parents_family_handle()
father = marrbox = mother = None father = marrbox = mother = None
@ -314,9 +315,10 @@ class MakeAncestorTree(object):
mother = self.recurse(family.get_mother_handle(), parents_handle, mother = self.recurse(family.get_mother_handle(), parents_handle,
(index*2)+1) (index*2)+1)
self.add_line(mybox, index, father, marrbox, mother) self.add_line(mybox, father, mother)
else: else:
mybox = self.__fill(index, person_handle, self.fill_out+1) mybox = self.__fill(index, person_handle,
min(self.fill_out, self.max_generations-X_INDEX(index)-1))
#father = self.__fill(index *2, self.fill_out) #father = self.__fill(index *2, self.fill_out)
#mybox = self.add_person_box(index, person_handle, family_handle) #mybox = self.add_person_box(index, person_handle, family_handle)
#if self.fill_out and self.inlc_marr and (log2(index) + 2) < #if self.fill_out and self.inlc_marr and (log2(index) + 2) <
@ -326,27 +328,94 @@ class MakeAncestorTree(object):
return mybox return mybox
def __fill(self, index, person_handle, levels): def __fill(self, index, person_handle, max_fill):
""" Fills out the Ancestor tree if desired/needed """ """ Fills out the Ancestor tree as desired/needed.
if log2(index) == self.max_generations: this is an iterative apporach.
return None """
if levels == 0:
return None
father = self.__fill(index *2, None, levels-1) if max_fill < 0:
return
##if X_INDEX(index) == self.max_generations:
## return None
mybox = self.add_person_box(index, person_handle, None) ###########################
#list of boxes
#for each generation (max_fill)
__BOXES = [None] * (max_fill+1)
__INDEX = [index]
__LINES = [None] * max_fill
marrbox = None #if __INFO[0][__FILL_AMOUNT] == max_fill or \
if self.inlc_marr and levels > 1 and \ # X_INDEX(index) >= self.max_generations-1:
(log2(index) + 2) <= self.max_generations: if max_fill == 0:
marrbox = self.add_marriage_box(index, None, None) return self.add_person_box(index, None, None)
mother = self.__fill(index *2+1, None, levels-1) ###########################
#Prime the pump
cur_gen = 1
#Cur_gen is the current Generation that we are working with
#use a bottom up iterative approach
while cur_gen > 0:
###########################
#Step 1. this level is blank. add our father
#if __INFO[cur_gen][__INDEX] == 0:
if len(__INDEX) == cur_gen:
__INDEX.append(__INDEX[cur_gen-1]*2)
#we will be adding a father here
self.add_line(mybox, index, father, marrbox, mother) if cur_gen < max_fill:
#But first, go to this father first if we can
cur_gen += 1
else:
#found our father. add him
__BOXES[cur_gen] = self.add_person_box(__INDEX[cur_gen], None, None)
return mybox ###########################
#Step 1.5. Dad has already been made.
elif __INDEX[cur_gen] %2 == 0:
###########################
#Step 2. add our kid
__BOXES[cur_gen-1] = \
self.add_person_box(__INDEX[cur_gen-1],
person_handle if cur_gen == 1 else None,
None)
###########################
#Step 2.3. add our marriage
if self.inlc_marr and cur_gen <= max_fill+1:
self.add_marriage_box(__INDEX[cur_gen-1], None, None)
###########################
#Step 2.6. line part 1
__LINES[cur_gen-1] = self.add_line(__BOXES[cur_gen-1],
__BOXES[cur_gen])
#make sure there is a NEW int.
__INDEX.pop()
#not a refernce that will clobber dada info
__INDEX.append((__INDEX[cur_gen-1] *2) +1)
#__INDEX[cur_gen] +=1
if cur_gen < max_fill:
cur_gen += 1
else:
###########################
#Step 3. Now we can make Mom
__BOXES[cur_gen] = self.add_person_box(__INDEX[cur_gen], None, None)
###########################
#Step 4. Father and Mother are done but only 1/2 line
else:
if cur_gen > 0:
###########################
#Step 2.6. line part 2
__LINES[cur_gen-1].add_to(__BOXES[cur_gen])
__INDEX.pop()
cur_gen -= 1
return __BOXES[0]
def start(self, person_id): def start(self, person_id):
""" go ahead and make it happen """ """ go ahead and make it happen """
@ -355,14 +424,6 @@ class MakeAncestorTree(object):
self.recurse(center_h, None, 1) self.recurse(center_h, None, 1)
if self.inc_spouses and False: #future version
family_handles = center.get_family_handle_list()
for family_handle in family_handles:
family = self.database.get_family_from_handle(family_handle)
spouse_handle = ReportUtils.find_spouse(center, family)
self.add_person_box(1, spouse_handle, family_handle)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Transform Classes # Transform Classes
@ -451,7 +512,7 @@ class MakeReport():
self.canvas.set_box_height_width(box) self.canvas.set_box_height_width(box)
if box.width > self.doc.report_opts.max_box_width: if box.width > self.doc.report_opts.max_box_width:
self.doc.report_opts.max_box_width = box.width #+ box.shadow self.doc.report_opts.max_box_width = box.width + box.shadow
if box.level[1] > 0: if box.level[1] > 0:
if box.level[1] % 2 == 0 and box.height > self.father_ht: if box.level[1] % 2 == 0 and box.height > self.father_ht:
@ -564,10 +625,9 @@ class AncestorTree2(Report):
#make the tree into self.canvas #make the tree into self.canvas
inlc_marr = self.connect.get_val('incmarr') inlc_marr = self.connect.get_val('incmarr')
self.max_generations = self.connect.get_val('maxgen') self.max_generations = self.connect.get_val('maxgen')
show_spouse = 0
fillout = self.connect.get_val('fillout') fillout = self.connect.get_val('fillout')
tree = MakeAncestorTree(database, self.canvas, self.max_generations, tree = MakeAncestorTree(database, self.canvas, self.max_generations,
inlc_marr, (show_spouse > 0), fillout) inlc_marr, fillout)
tree.start(self.connect.get_val('pid')) tree.start(self.connect.get_val('pid'))
tree = None tree = None
@ -887,7 +947,6 @@ class AncestorTree2Options(MenuReportOptions):
para_style.set_description(_('The basic style used for the ' + para_style.set_description(_('The basic style used for the ' +
'text display.')) 'text display.'))
default_style.add_paragraph_style("AC2-Normal", para_style) default_style.add_paragraph_style("AC2-Normal", para_style)
box_shadow = PT2CM(font.get_size()) * .6
font = FontStyle() font = FontStyle()
font.set_size(16) font.set_size(16)
@ -902,7 +961,7 @@ class AncestorTree2Options(MenuReportOptions):
## Draw styles ## Draw styles
graph_style = GraphicsStyle() graph_style = GraphicsStyle()
graph_style.set_paragraph_style("AC2-Normal") graph_style.set_paragraph_style("AC2-Normal")
graph_style.set_shadow(1, box_shadow) #shadow set by text size graph_style.set_shadow(1, PT2CM(9)) #shadow set by text size
graph_style.set_fill_color((255, 255, 255)) graph_style.set_fill_color((255, 255, 255))
default_style.add_draw_style("AC2-box", graph_style) default_style.add_draw_style("AC2-box", graph_style)