37 |
#undef SERVER_EDITABLE |
#undef SERVER_EDITABLE |
38 |
|
|
39 |
typedef struct { |
typedef struct { |
|
appdata_t *appdata; |
|
40 |
project_t *project; |
project_t *project; |
41 |
settings_t *settings; |
settings_t *settings; |
42 |
GtkWidget *dialog, *fsize, *diff_stat, *diff_remove; |
GtkWidget *dialog, *fsize, *diff_stat, *diff_remove; |
56 |
|
|
57 |
/* ------------ project file io ------------- */ |
/* ------------ project file io ------------- */ |
58 |
|
|
|
/* Limit a proposed zoom factor to sane ranges. |
|
|
* Specifically the map is allowed to be no smaller than the viewport. |
|
|
* This function has a counterpart in map_limit_zoom() |
|
|
*/ |
|
|
|
|
|
static gdouble project_limit_zoom(project_t *project, map_t *map) { |
|
|
bounds_t bounds; |
|
|
|
|
|
gdouble zoom = 0.25; |
|
|
|
|
|
/* calculate map zone which will be used as a reference for all */ |
|
|
/* drawing/projection later on */ |
|
|
pos_t center = { (project->max.lat + project->min.lat)/2, |
|
|
(project->max.lon + project->min.lon)/2 }; |
|
|
|
|
|
pos2lpos_center(¢er, &bounds.center); |
|
|
|
|
|
/* the scale is needed to accomodate for "streching" */ |
|
|
/* by the mercartor projection */ |
|
|
bounds.scale = cos(DEG2RAD(center.lat)); |
|
|
|
|
|
pos2lpos_center(&project->min, &bounds.min); |
|
|
bounds.min.x -= bounds.center.x; |
|
|
bounds.min.y -= bounds.center.y; |
|
|
bounds.min.x *= bounds.scale; |
|
|
bounds.min.y *= bounds.scale; |
|
|
|
|
|
pos2lpos_center(&project->max, &bounds.max); |
|
|
bounds.max.x -= bounds.center.x; |
|
|
bounds.max.y -= bounds.center.y; |
|
|
bounds.max.x *= bounds.scale; |
|
|
bounds.max.y *= bounds.scale; |
|
|
|
|
|
// Data rect minimum and maximum |
|
|
gint min_x, min_y, max_x, max_y; |
|
|
min_y = bounds.min.y; |
|
|
max_y = bounds.max.y; |
|
|
|
|
|
printf("min %d %d max %d %d\n", min_x, min_y, max_x, max_y); |
|
|
|
|
|
/* get size of visible area in pixels and convert to meters of intended */ |
|
|
/* zoom by deviding by zoom (which is basically pix/m) */ |
|
|
gint aw_cu = |
|
|
canvas_get_viewport_width(map->canvas, CANVAS_UNIT_PIXEL) / zoom; |
|
|
gint ah_cu = |
|
|
canvas_get_viewport_height(map->canvas, CANVAS_UNIT_PIXEL) / zoom; |
|
|
|
|
|
if (ah_cu < aw_cu) { |
|
|
gint lim_h = ah_cu*0.95; |
|
|
if (max_y-min_y < lim_h) { |
|
|
gdouble corr = ((gdouble)max_y-min_y) / (gdouble)lim_h; |
|
|
zoom /= corr; |
|
|
} |
|
|
} |
|
|
else { |
|
|
gint lim_w = aw_cu*0.95; |
|
|
if (bounds.max.x-bounds.min.x < lim_w) { |
|
|
gdouble corr = ((gdouble)bounds.max.x-bounds.min.x) / (gdouble)lim_w; |
|
|
zoom /= corr; |
|
|
} |
|
|
} |
|
|
return zoom; |
|
|
} |
|
|
|
|
59 |
static gboolean project_read(appdata_t *appdata, |
static gboolean project_read(appdata_t *appdata, |
60 |
char *project_file, project_t *project) { |
char *project_file, project_t *project) { |
|
gboolean found_map_entry = FALSE; |
|
61 |
|
|
62 |
LIBXML_TEST_VERSION; |
LIBXML_TEST_VERSION; |
63 |
|
|
104 |
|
|
105 |
} else if(project->map_state && |
} else if(project->map_state && |
106 |
strcasecmp((char*)node->name, "map") == 0) { |
strcasecmp((char*)node->name, "map") == 0) { |
|
found_map_entry = TRUE; |
|
107 |
|
|
108 |
if((str = (char*)xmlGetProp(node, BAD_CAST "zoom"))) { |
if((str = (char*)xmlGetProp(node, BAD_CAST "zoom"))) { |
109 |
project->map_state->zoom = g_ascii_strtod(str, NULL); |
project->map_state->zoom = g_ascii_strtod(str, NULL); |
186 |
} |
} |
187 |
} |
} |
188 |
|
|
|
if(!found_map_entry && project->map_state) { |
|
|
printf("loaded project w/o map entry\n"); |
|
|
|
|
|
printf("map size = %d x %d\n", |
|
|
appdata->map->canvas->widget->allocation.width/2, |
|
|
appdata->map->canvas->widget->allocation.height/2); |
|
|
|
|
|
gdouble pix_per_meter = project_limit_zoom(project, appdata->map); |
|
|
printf("pix per meter = %f\n", pix_per_meter); |
|
|
|
|
|
// printf("scroll = %f x %f\n", |
|
|
// appdata->map->canvas->widget->allocation.width/2/pix_per_meter, |
|
|
// appdata->map->canvas->widget->allocation.height/2/pix_per_meter); |
|
|
|
|
|
// scroll-offset-x="-1089" scroll-offset-y="-802"/> |
|
|
|
|
|
project->map_state->scroll_offset.x = 1000; |
|
|
project->map_state->scroll_offset.y = 1000; |
|
|
} |
|
|
|
|
189 |
xmlFreeDoc(doc); |
xmlFreeDoc(doc); |
190 |
xmlCleanupParser(); |
xmlCleanupParser(); |
191 |
|
|
874 |
str = g_strdup(_("Not downloaded!")); |
str = g_strdup(_("Not downloaded!")); |
875 |
|
|
876 |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
877 |
GTK_RESPONSE_ACCEPT, FALSE); |
GTK_RESPONSE_ACCEPT, !context->is_new); |
878 |
|
|
879 |
} else { |
} else { |
880 |
gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, NULL); |
gtk_widget_modify_fg(context->fsize, GTK_STATE_NORMAL, NULL); |
887 |
str = g_strdup_printf(_("Outdated, please download!")); |
str = g_strdup_printf(_("Outdated, please download!")); |
888 |
|
|
889 |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), |
890 |
GTK_RESPONSE_ACCEPT, !context->project->data_dirty); |
GTK_RESPONSE_ACCEPT, !context->is_new || |
891 |
|
!context->project->data_dirty); |
892 |
} |
} |
893 |
|
|
894 |
if(str) { |
if(str) { |
947 |
|
|
948 |
/* (re-) download area */ |
/* (re-) download area */ |
949 |
if(osm_download(GTK_WIDGET(context->dialog), |
if(osm_download(GTK_WIDGET(context->dialog), |
950 |
context->appdata->settings, context->project)) |
context->area_edit.appdata->settings, context->project)) |
951 |
context->project->data_dirty = FALSE; |
context->project->data_dirty = FALSE; |
952 |
|
|
953 |
project_filesize(context); |
project_filesize(context); |
1018 |
return ok; |
return ok; |
1019 |
|
|
1020 |
/* ------------ project edit dialog ------------- */ |
/* ------------ project edit dialog ------------- */ |
1021 |
|
|
1022 |
project_context_t *context = g_new0(project_context_t, 1); |
project_context_t *context = g_new0(project_context_t, 1); |
|
context->appdata = appdata; |
|
1023 |
context->project = project; |
context->project = project; |
1024 |
context->area_edit.settings = context->settings = settings; |
context->area_edit.settings = context->settings = settings; |
1025 |
|
context->area_edit.appdata = appdata; |
1026 |
context->is_new = is_new; |
context->is_new = is_new; |
1027 |
|
|
1028 |
context->area_edit.min = &project->min; |
context->area_edit.min = &project->min; |
1029 |
context->area_edit.max = &project->max; |
context->area_edit.max = &project->max; |
|
#ifdef USE_HILDON |
|
|
context->area_edit.mmpos = &appdata->mmpos; |
|
|
context->area_edit.osso_context = appdata->osso_context; |
|
|
#endif |
|
1030 |
|
|
1031 |
/* cancel is enabled for "new" projects only */ |
/* cancel is enabled for "new" projects only */ |
1032 |
if(is_new) { |
if(is_new) { |