From 9268cc0319cf3218a2980d4408f419e0762ca149 Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Sun, 15 May 2011 17:39:17 +0000 Subject: [PATCH] Geography : animation preference parameters. svn: r17504 --- src/plugins/lib/maps/constants.py | 3 + src/plugins/lib/maps/geography.py | 21 ++++--- src/plugins/view/geoperson.py | 91 ++++++++++++++++++++++++++++--- 3 files changed, 100 insertions(+), 15 deletions(-) diff --git a/src/plugins/lib/maps/constants.py b/src/plugins/lib/maps/constants.py index 34a7ea772..559d4ee95 100644 --- a/src/plugins/lib/maps/constants.py +++ b/src/plugins/lib/maps/constants.py @@ -29,6 +29,8 @@ #------------------------------------------------------------------------- from gen.ggettext import gettext as _ import gen.lib +import os +import const import osmgpsmap #------------------------------------------------------------------------- @@ -36,6 +38,7 @@ import osmgpsmap # Constants # #------------------------------------------------------------------------- +GEOGRAPHY_PATH = os.path.join(const.HOME_DIR, "maps") ICONS = { gen.lib.EventType.BIRTH : 'gramps-geo-birth', diff --git a/src/plugins/lib/maps/geography.py b/src/plugins/lib/maps/geography.py index 8b18cf0b2..57b095255 100644 --- a/src/plugins/lib/maps/geography.py +++ b/src/plugins/lib/maps/geography.py @@ -69,13 +69,6 @@ from config import config from gui.editors import EditPlace, EditEvent, EditFamily, EditPerson from gui.selectors.selectplace import SelectPlace -#------------------------------------------------------------------------- -# -# Constants -# -#------------------------------------------------------------------------- -GEOGRAPHY_PATH = os.path.join(const.HOME_DIR, "maps") - #------------------------------------------------------------------------- # # Functions @@ -717,7 +710,7 @@ class GeoGraphyView(osmGpsMap, NavigationView): """ The function which is used to create the configuration window. """ - return [self.map_options] + return [self.map_options, self.specific_options] def config_zoom_and_position(self, client, cnxn_id, entry, data): """ @@ -742,6 +735,18 @@ class GeoGraphyView(osmGpsMap, NavigationView): self.set_crosshair(config.get("geography.show_cross")) pass + def specific_options(self, configdialog): + """ + Add specific entry to the preference menu. + Must be done in the associated view. + """ + table = gtk.Table(2, 2) + table.set_border_width(12) + table.set_col_spacings(6) + table.set_row_spacings(6) + configdialog.add_text(table, _('Nothing for this view.'), 1) + return _('Specific parameters'), table + def map_options(self, configdialog): """ Function that builds the widget in the configuration dialog diff --git a/src/plugins/view/geoperson.py b/src/plugins/view/geoperson.py index 3427f0bfe..0930092d2 100644 --- a/src/plugins/view/geoperson.py +++ b/src/plugins/view/geoperson.py @@ -67,6 +67,7 @@ from gui.selectors.selectplace import SelectPlace from Filters.SideBar import PersonSidebarFilter from gui.views.navigationview import NavigationView import Bookmarks +import constants from Utils import navigation_label from maps.geography import GeoGraphyView @@ -114,6 +115,28 @@ class GeoPerson(GeoGraphyView): """ The view used to render person map. """ + CONFIGSETTINGS = ( + ('geography.path', constants.GEOGRAPHY_PATH), + + ('geography.zoom', 10), + ('geography.show_cross', True), + ('geography.lock', False), + ('geography.center-lat', 0.0), + ('geography.center-lon', 0.0), + + #('geography.gps_mode', GPS_DISABLED), + #('geography.gps_update_rate', float(1.0)), + #('geography.max_gps_zoom', 16), + #('geography.gps_increment', GPS_INCREMENT), + + ('geography.map_service', constants.OPENSTREETMAP), + + # specific to geoperson : + + ('geography.steps', 20), + ('geography.maximum_lon_lat', 30), + ('geography.speed', 100), + ) def __init__(self, pdata, dbstate, uistate, nav_group=0): GeoGraphyView.__init__(self, _("Person places map"), @@ -208,9 +231,18 @@ class GeoPerson(GeoGraphyView): heading = 1 if index == 0 and stepyear == 0: self.remove_all_gps() + self.large_move = False self.osm.gps_add(startlat, startlon, heading) endlat = float(marks[ni][3]) endlon = float(marks[ni][4]) + max_lon_lat = float(self._config.get("geography.maximum_lon_lat")) / 10 + if stepyear < 9000: + if (( abs(float(endlat) - float(startlat)) > max_lon_lat ) or + ( abs(float(endlon) - float(startlon)) > max_lon_lat )): + self.large_move = True + stepyear = 9000 + else: + self.large_move = False # year format = YYYYMMDD ( for sort ) startyear = str(marks[i][6])[0:4] endyear = str(marks[ni][6])[0:4] @@ -218,11 +250,17 @@ class GeoPerson(GeoGraphyView): years = int(endyear) - int(startyear) if years < 1: years = 1 - latstep = ( endlat - startlat ) / years - lonstep = ( endlon - startlon ) / years - stepyear = 1 if stepyear < 1 else stepyear - startlat += ( latstep * stepyear ) - startlon += ( lonstep * stepyear ) + if stepyear > 8999: + latstep = ( endlat - startlat ) / self._config.get("geography.steps") + lonstep = ( endlon - startlon ) / self._config.get("geography.steps") + startlat += ( latstep * (stepyear - 8999) ) + startlon += ( lonstep * (stepyear - 8999) ) + else: + latstep = ( endlat - startlat ) / years + lonstep = ( endlon - startlon ) / years + stepyear = 1 if stepyear < 1 else stepyear + startlat += ( latstep * stepyear ) + startlon += ( lonstep * stepyear ) self.osm.gps_add(startlat, startlon, heading) stepyear += 1 difflat = round(( startlat - endlat ) if startlat > endlat else \ @@ -231,10 +269,16 @@ class GeoPerson(GeoGraphyView): ( endlon - startlon ), 8) if ( difflat == 0.0 and difflon == 0.0 ): i += 1 + self.large_move = False stepyear = 1 - # 100ms => 1s per 10 years. + # if geography.speed = 100 => 100ms => 1s per 10 years. # For a 100 years person, it takes 10 secondes. - glib.timeout_add(100, self.animate, menu, marks, i, stepyear) + # if large_move, one step is the difflat or difflon / geography.steps + # in this case, stepyear is >= 9000 + # large move means longitude or latitude differences greater than geography.maximum_lon_lat + # degrees. + glib.timeout_add(self._config.get("geography.speed"), self.animate, + menu, marks, i, stepyear) return False def _createmap(self,obj): @@ -446,3 +490,36 @@ class GeoPerson(GeoGraphyView): """ return (("Person Filter",), ()) + + def specific_options(self, configdialog): + """ + Add specific entry to the preference menu. + Must be done in the associated view. + """ + table = gtk.Table(2, 2) + table.set_border_width(12) + table.set_col_spacings(6) + table.set_row_spacings(6) + configdialog.add_text(table, + _('Animation speed in milliseconds (big value means slower)'), + 1) + self.config_size_slider = configdialog.add_slider(table, + "", + 2, 'geography.speed', + (100, 1000)) + configdialog.add_text(table, + _('How many steps between two markers when we are on large move ?'), + 3) + self.config_size_slider = configdialog.add_slider(table, + "", + 4, 'geography.steps', + (10, 100)) + configdialog.add_text(table, + _('The minimum latitude/longitude to select large move.\n' + 'The value is in tenth of degree.'), + 5) + self.config_size_slider = configdialog.add_slider(table, + "", + 6, 'geography.maximum_lon_lat', + (5, 50)) + return _('The animation parameters'), table