From 645a9e055bf8dc90c9ee67db6b4e088afe567ac1 Mon Sep 17 00:00:00 2001 From: martin-s Date: Sun, 6 Jul 2008 19:53:18 +0000 Subject: [PATCH] Add:Tools:Initial working on using map as source for osm2navit git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1201 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/binding/python/binding_python.c | 2 +- navit/navit/map.c | 15 ++-- navit/navit/map.h | 2 +- navit/navit/navigation.c | 13 ++- navit/navit/navit.c | 4 +- navit/navit/osm2navit.c | 119 ++++++++++++++++++++++++++-- navit/navit/route.c | 14 ++-- navit/navit/xmlconfig.c | 5 +- 8 files changed, 139 insertions(+), 35 deletions(-) diff --git a/navit/navit/binding/python/binding_python.c b/navit/navit/binding/python/binding_python.c index 39bd4d4..b3e3ec2 100644 --- a/navit/navit/binding/python/binding_python.c +++ b/navit/navit/binding/python/binding_python.c @@ -194,7 +194,7 @@ map_new_py(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "ss:navit.map", &type, &filename)) return NULL; ret=PyObject_NEW(mapObject, &map_Type); - ret->m=map_new(type,NULL); + ret->m=map_new(NULL); return (PyObject *)ret; } diff --git a/navit/navit/map.c b/navit/navit/map.c index 103315a..39d89be 100644 --- a/navit/navit/map.c +++ b/navit/navit/map.c @@ -46,22 +46,26 @@ struct map_rect { }; struct map * -map_new(const char *type, struct attr **attrs) +map_new(struct attr **attrs) { struct map *m; struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs); struct attr *data=attr_search(attrs, NULL, attr_data); + struct attr *type=attr_search(attrs, NULL, attr_type); - - maptype_new=plugin_get_map_type(type); + if (! type) { + dbg(0,"missing type\n"); + return NULL; + } + maptype_new=plugin_get_map_type(type->u.str); if (! maptype_new) { - dbg(0,"invalid type '%s'\n", type); + dbg(0,"invalid type '%s'\n", type->u.str); return NULL; } m=g_new0(struct map, 1); m->active=1; - m->type=g_strdup(type); + m->type=g_strdup(type->u.str); if (data) m->filename=g_strdup(data->u.str); m->priv=maptype_new(&m->meth, attrs); @@ -128,6 +132,7 @@ map_set_attr(struct map *this_, struct attr *attr) } if (attr_updated) callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr); + return 1; } void diff --git a/navit/navit/map.h b/navit/navit/map.h index 5caa3dd..fefe4e1 100644 --- a/navit/navit/map.h +++ b/navit/navit/map.h @@ -155,7 +155,7 @@ struct map_priv; struct map_rect; struct map_search; struct map_selection; -struct map *map_new(const char *type, struct attr **attrs); +struct map *map_new(struct attr **attrs); char *map_get_filename(struct map *this_); char *map_get_type(struct map *this_); int map_get_active(struct map *this_); diff --git a/navit/navit/navigation.c b/navit/navit/navigation.c index 511627f..01964a5 100644 --- a/navit/navit/navigation.c +++ b/navit/navit/navigation.c @@ -833,16 +833,13 @@ navigation_unregister_callback(struct navigation *this_, enum attr_type type, st struct map * navigation_get_map(struct navigation *this_) { - struct attr navigation_attr; - struct attr data_attr; - struct attr *attrs_navigation[]={&navigation_attr, &data_attr, NULL}; - navigation_attr.type=attr_navigation; - navigation_attr.u.navigation=this_; - data_attr.type=attr_data; - data_attr.u.str=""; + struct attr type_attr={attr_type, {"navigation"}}; + struct attr navigation_attr={attr_navigation, .u.navigation=this_}; + struct attr data_attr={attr_data, {""}}; + struct attr *attrs_navigation[]={&type_attr, &navigation_attr, &data_attr, NULL}; if (! this_->map) - this_->map=map_new("navigation",attrs_navigation); + this_->map=map_new(attrs_navigation); return this_->map; } diff --git a/navit/navit/navit.c b/navit/navit/navit.c index 951a724..beb7baf 100644 --- a/navit/navit/navit.c +++ b/navit/navit/navit.c @@ -793,7 +793,7 @@ navit_add_bookmarks_from_file(struct navit *this_) struct attr type={attr_type, {"textfile"}}, data={attr_data, {"bookmark.txt"}}; struct attr *attrs[]={&type, &data, NULL}; - this_->bookmark=map_new("textfile", attrs); + this_->bookmark=map_new(attrs); } static void @@ -802,7 +802,7 @@ navit_add_former_destinations_from_file(struct navit *this_) struct attr type={attr_type, {"textfile"}}, data={attr_data, {"destination.txt"}}; struct attr *attrs[]={&type, &data, NULL}; - this_->former_destination=map_new("textfile", attrs); + this_->former_destination=map_new(attrs); } diff --git a/navit/navit/osm2navit.c b/navit/navit/osm2navit.c index 41f6adc..ecbafb2 100644 --- a/navit/navit/osm2navit.c +++ b/navit/navit/osm2navit.c @@ -2191,6 +2191,53 @@ phase34(int phase, int maxnamelen, FILE *ways_in, FILE *nodes_in, FILE *tilesdir } +static void +dump_coord(struct coord *c) +{ + printf("0x%x 0x%x",c->x, c->y); +} + +static void +dump(FILE *in) +{ + struct item_bin *ib; + struct coord *c; + struct attr_bin *a; + struct attr attr; + int *attr_start; + int *attr_end; + int i; + char *str; + while ((ib=read_item(in))) { + c=(struct coord *)(ib+1); + if (ib->type < type_line) { + dump_coord(c); + printf(" "); + } + attr_start=(int *)(ib+1)+ib->clen; + attr_end=(int *)ib+ib->len+1; + printf("type=%s", item_to_name(ib->type)); + while (attr_start < attr_end) { + a=(struct attr_bin *)(attr_start); + attr_start+=a->len+1; + attr.type=a->type; + attr_data_set(&attr, (a+1)); + str=attr_to_text(&attr, NULL, 1); + printf(" %s=\"%s\"", attr_to_name(a->type), str); + g_free(str); + } + printf(" debug=\"length=%d\"", ib->len); + printf("\n"); + if (ib->type >= type_line) { + for (i = 0 ; i < ib->clen/2 ; i++) { + dump_coord(c+i); + printf("\n"); + } + + } + } +} + static int phase3(FILE *ways_in, FILE *nodes_in, FILE *tilesdir_out) { @@ -2458,17 +2505,29 @@ usage(FILE *f) exit(1); } +static void +process_binfile(FILE *in, FILE *out) +{ + struct item_bin *ib; + while ((ib=read_item(in))) { + fwrite(ib, (ib->len+1)*4, 1, out); + } +} + int main(int argc, char **argv) { FILE *ways=NULL,*ways_split=NULL,*nodes=NULL,*tilesdir,*zipdir,*res; char *map=g_strdup(attrmap); - int c,start=1,end=4,dump_coordinates=0; + int i,c,start=1,end=4,dump_coordinates=0; int keep_tmpfiles=0; int process_nodes=1, process_ways=1; int compression_level=9; + int output=0; + int input=0; char *result,*dbstr=NULL; FILE* input_file = stdin; - + struct plugins *plugins=NULL; + struct attr **attrs; while (1) { #if 0 @@ -2477,30 +2536,37 @@ int main(int argc, char **argv) int option_index = 0; static struct option long_options[] = { {"attr-debug-level", 1, 0, 'a'}, + {"binfile", 0, 0, 'b'}, {"compression-level", 1, 0, 'z'}, {"coverage", 0, 0, 'o'}, #ifdef HAVE_POSTGRESQL {"db", 1, 0, 'd'}, #endif {"dedupe-ways", 0, 0, 'w'}, + {"dump", 0, 0, 'D'}, {"end", 1, 0, 'e'}, {"help", 0, 0, 'h'}, {"keep-tmpfiles", 0, 0, 'k'}, {"nodes-only", 0, 0, 'N'}, + {"map", 1, 0, 'm'}, + {"plugin", 1, 0, 'p'}, {"start", 1, 0, 's'}, {"input-file", 1, 0, 'i'}, {"ignore-unknown", 0, 0, 'n'}, {"ways-only", 0, 0, 'W'}, {0, 0, 0, 0} }; - c = getopt_long (argc, argv, "Nni:Wa:c" + c = getopt_long (argc, argv, "DNWa:bc" #ifdef HAVE_POSTGRESQL "d:" #endif - "e:hks:w", long_options, &option_index); + "e:hi:knm:ps:w", long_options, &option_index); if (c == -1) break; switch (c) { + case 'D': + output=1; + break; case 'N': process_ways=0; break; @@ -2510,6 +2576,9 @@ int main(int argc, char **argv) case 'a': attr_debug_level=atoi(optarg); break; + case 'b': + input=1; + break; case 'c': dump_coordinates=1; break; @@ -2524,6 +2593,14 @@ int main(int argc, char **argv) case 'h': usage(stdout); break; + case 'm': + attrs=(struct attr*[]){ + &(struct attr){attr_type,{"textfile"}}, + &(struct attr){attr_data,{"bookmark.txt"}}, + NULL}; + map_new(attrs); + fprintf(stderr,"optarg=%s\n", optarg); + break; case 'n': fprintf(stderr,"I will IGNORE unknown types\n"); ignore_unkown=1; @@ -2535,6 +2612,12 @@ int main(int argc, char **argv) case 'o': coverage=1; break; + case 'p': + if (! plugins) + plugins=plugins_new(); + attrs=(struct attr*[]){&(struct attr){attr_path,{optarg}},NULL}; + plugins_add_path(plugins, attrs); + break; case 's': start=atoi(optarg); break; @@ -2560,8 +2643,10 @@ int main(int argc, char **argv) } } - if (optind != argc-1) + if (optind != argc-(output == 1 ? 0:1)) usage(stderr); + if (plugins) + plugins_init(plugins); result=argv[optind]; build_attrmap(map); #ifdef GENERATE_INDEX @@ -2569,6 +2654,7 @@ int main(int argc, char **argv) #endif + if (input == 0) { if (start == 1) { if (process_ways) ways=fopen("ways.tmp","wb+"); @@ -2617,6 +2703,29 @@ int main(int argc, char **argv) node_buffer.size=0; if (end == 2) exit(0); + } else { + ways_split=fopen("ways_split.tmp","wb+"); + process_binfile(stdin, ways_split); + fclose(ways_split); + } + if (output == 1) { + fprintf(stderr,"PROGRESS: Phase 3: dumping\n"); + if (process_nodes) { + nodes=fopen("nodes.tmp","rb"); + if (nodes) { + dump(nodes); + fclose(nodes); + } + } + if (process_ways) { + ways_split=fopen("ways_split.tmp","rb"); + if (ways_split) { + dump(ways_split); + fclose(ways_split); + } + } + exit(0); + } if (start <= 3) { phase=3; fprintf(stderr,"PROGRESS: Phase 3: generating tiles\n"); diff --git a/navit/navit/route.c b/navit/navit/route.c index 97688a3..739f070 100644 --- a/navit/navit/route.c +++ b/navit/navit/route.c @@ -1760,16 +1760,12 @@ route_graph_map_new(struct map_methods *meth, struct attr **attrs) static struct map * route_get_map_helper(struct route *this_, struct map **map, char *type) { - struct attr route_attr; - struct attr data_attr; - struct attr *attrs_route[]={&route_attr, &data_attr, NULL}; - route_attr.type=attr_route; - route_attr.u.route=this_; - data_attr.type=attr_data; - data_attr.u.str=""; - + struct attr type_attr={attr_type,{"route"}}; + struct attr route_attr={attr_route,.u.route=this_}; + struct attr data_attr={attr_data,{""}}; + struct attr *attrs_route[]={&type_attr, &route_attr, &data_attr, NULL}; if (! *map) - *map=map_new(type,attrs_route); + *map=map_new(attrs_route); return *map; } diff --git a/navit/navit/xmlconfig.c b/navit/navit/xmlconfig.c index 85ef621..84756b2 100644 --- a/navit/navit/xmlconfig.c +++ b/navit/navit/xmlconfig.c @@ -451,11 +451,8 @@ static int xmlconfig_map(struct xmlstate *state) { struct attr **attrs; - const char *type=find_attribute(state, "type", 1); - if (! type) - return 0; attrs=convert_to_attrs(state); - state->element_attr.u.data = map_new(type, attrs); + state->element_attr.u.data = map_new(attrs); if (! state->element_attr.u.data) return 0; if (!find_boolean(state, "active", 1, 0)) -- 2.7.4