From 8f56dc6aa44664161b5cafed979994a97b786e77 Mon Sep 17 00:00:00 2001 From: martin-s Date: Thu, 11 Jun 2009 18:28:48 +0000 Subject: [PATCH] Fix:Core:Support for map editing git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2313 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/item.c | 38 ++++++++++++++++++++++++++++++++++++++ navit/navit/item.h | 20 ++++++++++++++++++++ navit/navit/map.c | 19 +++---------------- navit/navit/map.h | 1 + 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/navit/navit/item.c b/navit/navit/item.c index a249415..ec20514 100644 --- a/navit/navit/item.c +++ b/navit/navit/item.c @@ -17,6 +17,7 @@ * Boston, MA 02110-1301, USA. */ +#include #include #include #include "coord.h" @@ -110,6 +111,14 @@ item_coord_get(struct item *it, struct coord *c, int count) } int +item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode) +{ + if (!it->meth->item_coord_set) + return 0; + return it->meth->item_coord_set(it->priv_data, c, count, mode); +} + +int item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel) { int i,ret=it->meth->item_coord_get(it->priv_data, c, count); @@ -165,12 +174,21 @@ item_attr_rewind(struct item *it) { it->meth->item_attr_rewind(it->priv_data); } + int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr) { return it->meth->item_attr_get(it->priv_data, attr_type, attr); } +int +item_attr_set(struct item *it, struct attr *attr, enum change_mode mode) +{ + if (!it->meth->item_attr_set) + return 0; + return it->meth->item_attr_set(it->priv_data, attr, mode); +} + struct item * item_new(char *type, int zoom) { struct item * it; @@ -290,3 +308,23 @@ item_range_contains_item(struct item_range *range, enum item_type type) return 1; return 0; } + +void +item_dump_filedesc(struct item *item, struct map *map, FILE *out) +{ + + int i,count,max=16384; + struct coord ca[max]; + struct attr attr; + + count=item_coord_get(item, ca, item->type < type_line ? 1: max); + if (item->type < type_line) + fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y); + fprintf(out,"type=%s", item_to_name(item->type)); + while (item_attr_get(item, attr_any, &attr)) + fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1)); + fprintf(out,"\n"); + if (item->type >= type_line) + for (i = 0 ; i < count ; i++) + fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y); +} diff --git a/navit/navit/item.h b/navit/navit/item.h index 64dda9f..7445a57 100644 --- a/navit/navit/item.h +++ b/navit/navit/item.h @@ -24,6 +24,8 @@ extern "C" { #endif +#include + enum item_type { #define ITEM2(x,y) type_##y=x, #define ITEM(x) type_##x, @@ -53,12 +55,27 @@ extern int default_flags[]; struct coord; +enum change_mode { + change_mode_delete, + change_mode_modify, + change_mode_append, + change_mode_prepend, +}; + struct item_methods { void (*item_coord_rewind)(void *priv_data); int (*item_coord_get)(void *priv_data, struct coord *c, int count); void (*item_attr_rewind)(void *priv_data); int (*item_attr_get)(void *priv_data, enum attr_type attr_type, struct attr *attr); int (*item_coord_is_node)(void *priv_data); + int (*item_attr_set)(void *priv_data, struct attr *attr, enum change_mode mode); + int (*item_coord_set)(void *priv_data, struct coord *c, int count, enum change_mode mode); + int (*item_type_set)(void *priv_data, enum item_type type); +}; + +struct item_id { + int id_hi; + int id_lo; }; struct item { @@ -85,12 +102,14 @@ struct map_selection; int *item_get_default_flags(enum item_type type); void item_coord_rewind(struct item *it); int item_coord_get(struct item *it, struct coord *c, int count); +int item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode); int item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel); int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection pro); /* does the next returned coordinate mark a node */ int item_coord_is_node(struct item *it); void item_attr_rewind(struct item *it); int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr); +int item_attr_set(struct item *it, struct attr *attr, enum change_mode mode); struct item *item_new(char *type, int zoom); enum item_type item_from_name(const char *name); char *item_to_name(enum item_type item); @@ -101,6 +120,7 @@ void *item_hash_lookup(struct item_hash *h, struct item *item); void item_hash_destroy(struct item_hash *h); int item_range_intersects_range(struct item_range *range1, struct item_range *range2); int item_range_contains_item(struct item_range *range, enum item_type type); +void item_dump_filedesc(struct item *item, struct map *map, FILE *out); /* end of prototypes */ diff --git a/navit/navit/map.c b/navit/navit/map.c index eb8d59a..404090d 100644 --- a/navit/navit/map.c +++ b/navit/navit/map.c @@ -641,22 +641,9 @@ map_dump_filedesc(struct map *map, FILE *out) { struct map_rect *mr=map_rect_new(map, NULL); struct item *item; - int i,count,max=16384; - struct coord ca[max]; - struct attr attr; - - while ((item = map_rect_get_item(mr))) { - count=item_coord_get(item, ca, item->type < type_line ? 1: max); - if (item->type < type_line) - fprintf(out,"mg:0x%x 0x%x ", ca[0].x, ca[0].y); - fprintf(out,"type=%s", item_to_name(item->type)); - while (item_attr_get(item, attr_any, &attr)) - fprintf(out," %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1)); - fprintf(out,"\n"); - if (item->type >= type_line) - for (i = 0 ; i < count ; i++) - fprintf(out,"mg:0x%x 0x%x\n", ca[i].x, ca[i].y); - } + + while ((item = map_rect_get_item(mr))) + item_dump_filedesc(item, map, out); map_rect_destroy(mr); } diff --git a/navit/navit/map.h b/navit/navit/map.h index a0a926b..b43313b 100644 --- a/navit/navit/map.h +++ b/navit/navit/map.h @@ -74,6 +74,7 @@ struct map_methods { struct map_search_priv *(*map_search_new)(struct map_priv *map, struct item *item, struct attr *search, int partial); /**< Function to start a new search on the map */ void (*map_search_destroy)(struct map_search_priv *ms); /**< Function to destroy a map search struct */ struct item * (*map_search_get_item)(struct map_search_priv *ms); /**< Function to get the next item of a search on the map */ + struct item * (*map_rect_create_item)(struct map_rect_priv *mr, enum item_type type); /**< Function to create a new item in the map */ }; /** -- 2.7.4