From: martin-s Date: Fri, 12 Dec 2008 21:25:37 +0000 (+0000) Subject: Fixed:Core:Improved map querying api X-Git-Tag: navit-0.5.0.5194svn~3373 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a45fd6bce30eb97dabf1111f5b4cf8018b4160e;p=profile%2Fivi%2Fnavit.git Fixed:Core:Improved map querying api git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1785 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/navit/data/binfile/binfile.c b/navit/navit/data/binfile/binfile.c index d37dbd3..1dc2871 100644 --- a/navit/navit/data/binfile/binfile.c +++ b/navit/navit/data/binfile/binfile.c @@ -26,9 +26,9 @@ #include "debug.h" #include "plugin.h" #include "projection.h" +#include "item.h" #include "map.h" #include "maptype.h" -#include "item.h" #include "attr.h" #include "coord.h" #include "transform.h" @@ -534,11 +534,7 @@ selection_contains(struct map_selection *sel, struct coord_rect *r, struct minma return 1; while (sel) { if (coord_rect_overlap(r, &sel->u.c_rect)) { - order=sel->order[0]; - if (sel->order[1] > order) - order=sel->order[1]; - if (sel->order[2] > order) - order=sel->order[2]; + order=sel->order; dbg(1,"min %d max %d order %d\n", mima->min, mima->max, order); if (!mima->min && !mima->max) return 1; @@ -640,7 +636,6 @@ binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, struct map_search_priv *msp; struct map_selection *ms; struct item *town; - int i; /* * NOTE: If you implement search for other attributes than attr_town_name and attr_street_name, @@ -668,10 +663,8 @@ binmap_search_new(struct map_priv *map, struct item *item, struct attr *search, break; ms = g_new(struct map_selection, 1); ms->next = NULL; - for (i = 0; i < layer_end; i++) - { - ms->order[i] = 18; - } + ms->range = item_range_all; /* FIXME */ + ms->order = 18; map_rec = map_rect_new_binfile(map, ms); town = map_rect_get_item_byid_binfile(map_rec, item->id_hi, item->id_lo); if (town) { diff --git a/navit/navit/data/garmin/garmin.c b/navit/navit/data/garmin/garmin.c index 52436ae..e7666a4 100644 --- a/navit/navit/data/garmin/garmin.c +++ b/navit/navit/data/garmin/garmin.c @@ -774,10 +774,7 @@ struct nl2gl_t nl2gl[] = { static int get_level(struct map_selection *sel) { - int l; - l = max(sel->order[layer_town], sel->order[layer_street]); - l = max(l, sel->order[layer_poly]); - return l; + return sel->order; } static int @@ -792,8 +789,7 @@ garmin_get_selection(struct map_rect_priv *map, struct map_selection *sel) /* levels we do not deal w/ them */ int flags = 0; - if (sel && sel->order[layer_town] == 0 && sel->order[layer_poly] == 0 - && sel->order[layer_street]) { + if (sel && sel->range.min == type_street_0 && sel->range.max == type_ferry) { // Get all roads flags = GO_GET_ROUTABLE; } else if (sel) diff --git a/navit/navit/data/mg/map.c b/navit/navit/data/mg/map.c index c6e4c67..160fbbb 100644 --- a/navit/navit/data/mg/map.c +++ b/navit/navit/data/mg/map.c @@ -156,6 +156,21 @@ static char *mg_country_postal_prefix(int isonum) return NULL; } +struct item_range town_ranges[]={ + {type_town_label,type_port_label}, +}; + +struct item_range street_ranges[]={ + {type_street_nopass,type_street_unkn}, +}; + +struct item_range poly_ranges[]={ + {type_border_country,type_water_line}, + {type_street_unkn,type_street_unkn}, + {type_area,type_last}, +}; + + static int file_next(struct map_rect_priv *mr) { @@ -173,16 +188,18 @@ file_next(struct map_rect_priv *mr) case file_strname_stn: continue; case file_town_twn: - layer=layer_town; + if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, town_ranges, sizeof(town_ranges)/sizeof(struct item_range))) + continue; break; case file_street_str: - layer=layer_street; + if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, street_ranges, sizeof(street_ranges)/sizeof(struct item_range))) + continue; break; default: - layer=layer_poly; + if (mr->cur_sel && !map_selection_contains_item_range(mr->cur_sel, 0, poly_ranges, sizeof(poly_ranges)/sizeof(struct item_range))) + continue; + break; } - if (mr->cur_sel && !mr->cur_sel->order[layer]) - continue; if (debug) printf("current file: '%s'\n", file[mr->current_file]); mr->cur_sel=mr->xsel; diff --git a/navit/navit/data/mg/poly.c b/navit/navit/data/mg/poly.c index db96fdc..2618a89 100644 --- a/navit/navit/data/mg/poly.c +++ b/navit/navit/data/mg/poly.c @@ -132,7 +132,7 @@ poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item) poly->poly_num++; r.lu=poly->c[0]; r.rl=poly->c[1]; - if (mr->cur_sel && (poly->order > mr->cur_sel->order[layer_poly]*3 || !coord_rect_overlap(&mr->cur_sel->u.c_rect, &r))) { + if (mr->cur_sel && (poly->order > mr->cur_sel->order*3 || !coord_rect_overlap(&mr->cur_sel->u.c_rect, &r))) { poly->subpoly_num_all+=poly->polys; mr->b.p=poly->poly_next; continue; @@ -228,6 +228,11 @@ poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item) dbg(0,"Unknown poly type 0x%x '%s' 0x%x,0x%x\n", poly->type,poly->name,r.lu.x,r.lu.y); item->type=type_street_unkn; } + if (!map_selection_contains_item(mr->cur_sel, 0, item->type)) { + poly->subpoly_num_all+=poly->polys; + mr->b.p=poly->poly_next; + continue; + } } else mr->b.p=poly->subpoly_next; dbg(1,"%d %d %s\n", poly->subpoly_num_all, mr->b.block_num, poly->name); diff --git a/navit/navit/data/mg/street.c b/navit/navit/data/mg/street.c index c3ba435..cf9701a 100644 --- a/navit/navit/data/mg/street.c +++ b/navit/navit/data/mg/street.c @@ -335,7 +335,7 @@ street_get(struct map_rect_priv *mr, struct street_priv *street, struct item *it if (mr->b.p == mr->b.p_start) { street_get_data(street, &mr->b.p); street->name_file=mr->m->file[file_strname_stn]; - if (mr->cur_sel && street->header->order > limit[mr->cur_sel->order[layer_street]]) + if (mr->cur_sel && street->header->order > limit[mr->cur_sel->order]) return 0; street->end=mr->b.end; street->ref=&mr->b.b->r.lu; @@ -428,6 +428,9 @@ street_get(struct map_rect_priv *mr, struct street_priv *street, struct item *it item->type=type_street_unkn; dbg(0,"unknown type 0x%x\n",street->str->type); } + if (!map_selection_contains_item(mr->cur_sel, 0, item->type)) { + return 0; + } #if 0 coord_debug=(street->str->unknown2 != 0x40 || street->str->unknown3 != 0x40); if (coord_debug) { diff --git a/navit/navit/data/mg/town.c b/navit/navit/data/mg/town.c index 6641038..aedf34a 100644 --- a/navit/navit/data/mg/town.c +++ b/navit/navit/data/mg/town.c @@ -155,7 +155,7 @@ town_get(struct map_rect_priv *mr, struct town_priv *twn, struct item *item) twn->cidx=0; twn->aidx=0; twn->attr_next=attr_label; - if (! mr->cur_sel || (twn->order <= limit[mr->cur_sel->order[layer_town]] && coord_rect_contains(&mr->cur_sel->u.c_rect,&twn->c))) { + if (! mr->cur_sel || (twn->order <= limit[mr->cur_sel->order] && coord_rect_contains(&mr->cur_sel->u.c_rect,&twn->c))) { switch(twn->type) { case 1: size=twn->size; @@ -183,11 +183,13 @@ town_get(struct map_rect_priv *mr, struct town_priv *twn, struct item *item) printf("unknown town type 0x%x '%s' '%s' 0x%x,0x%x\n", twn->type, twn->name, twn->district, twn->c.x, twn->c.y); item->type=type_town_label; } - item->id_hi=twn->country | (mr->current_file << 16); - item->id_lo=twn->id; - item->priv_data=twn; - item->meth=&town_meth; - return 1; + if (map_selection_contains_item(mr->cur_sel, 0, item->type)) { + item->id_hi=twn->country | (mr->current_file << 16); + item->id_lo=twn->id; + item->priv_data=twn; + item->meth=&town_meth; + return 1; + } } } } diff --git a/navit/navit/data/poi_geodownload/poi_geodownload.c b/navit/navit/data/poi_geodownload/poi_geodownload.c index 229457b..3545cde 100644 --- a/navit/navit/data/poi_geodownload/poi_geodownload.c +++ b/navit/navit/data/poi_geodownload/poi_geodownload.c @@ -3,8 +3,8 @@ #include "debug.h" #include "coord.h" #include "projection.h" -#include "map.h" #include "item.h" +#include "map.h" #include "plugin.h" diff --git a/navit/navit/data/textfile/textfile.c b/navit/navit/data/textfile/textfile.c index aca093a..aa2fa01 100644 --- a/navit/navit/data/textfile/textfile.c +++ b/navit/navit/data/textfile/textfile.c @@ -26,9 +26,9 @@ #include "debug.h" #include "plugin.h" #include "projection.h" +#include "item.h" #include "map.h" #include "maptype.h" -#include "item.h" #include "attr.h" #include "transform.h" #include "file.h" @@ -226,7 +226,7 @@ map_rect_new_textfile(struct map_priv *map, struct map_selection *sel) g_free(oargs); for (lay=layer_town ; lay < layer_end ; lay++) { oargs=args; - args=g_strdup_printf("%s%s%d", oargs, sep, sel->order[lay]); + args=g_strdup_printf("%s%s%d", oargs, sep, sel->order); g_free(oargs); sep=","; } diff --git a/navit/navit/graphics.c b/navit/navit/graphics.c index d6a2805..f5e55bc 100644 --- a/navit/navit/graphics.c +++ b/navit/navit/graphics.c @@ -36,6 +36,7 @@ #include "point.h" #include "graphics.h" #include "projection.h" +#include "item.h" #include "map.h" #include "coord.h" #include "transform.h" diff --git a/navit/navit/gui/internal/gui_internal.c b/navit/navit/gui/internal/gui_internal.c index b02df0d..7689a7f 100644 --- a/navit/navit/gui/internal/gui_internal.c +++ b/navit/navit/gui/internal/gui_internal.c @@ -1823,7 +1823,7 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm) gui_internal_cmd_view_on_map, wm)); } if (display_items) { - int i,dist=10; + int dist=10; struct mapset *ms; struct mapset_handle *h; struct map_rect *mr; @@ -1845,9 +1845,8 @@ gui_internal_cmd_position(struct gui_priv *this, struct widget *wm) sel.u.c_rect.lu.y=c.y+dist; sel.u.c_rect.rl.x=c.x+dist; sel.u.c_rect.rl.y=c.y-dist; - for (i = 0 ; i < layer_end ; i++) { - sel.order[i]=18; - } + sel.order=18; + sel.range=item_range_all; h=mapset_open(ms); while ((m=mapset_next(h,1))) { mr=map_rect_new(m, &sel); diff --git a/navit/navit/item.c b/navit/navit/item.c index e0c3e31..73444a0 100644 --- a/navit/navit/item.c +++ b/navit/navit/item.c @@ -28,6 +28,8 @@ struct item_name { char *name; }; +struct item_range item_range_all = { type_none, type_last }; + struct item_name item_names[]={ #define ITEM2(x,y) ITEM(y) @@ -182,3 +184,20 @@ item_hash_destroy(struct item_hash *h) g_hash_table_destroy(h->h); g_free(h); } + +int +item_range_intersects_range(struct item_range *range1, struct item_range *range2) +{ + if (range1->max < range2->min) + return 0; + if (range1->min > range2->max) + return 0; + return 1; +} +int +item_range_contains_item(struct item_range *range, enum item_type type) +{ + if (type >= range->min && type <= range->max) + return 1; + return 0; +} diff --git a/navit/navit/item.h b/navit/navit/item.h index 460f119..48b5fd1 100644 --- a/navit/navit/item.h +++ b/navit/navit/item.h @@ -66,6 +66,10 @@ struct item { void *priv_data; }; +struct item_range { + enum item_type min,max; +} item_range_all; + /* prototypes */ enum attr_type; enum item_type; diff --git a/navit/navit/item_def.h b/navit/navit/item_def.h index cd32312..75e20e8 100644 --- a/navit/navit/item_def.h +++ b/navit/navit/item_def.h @@ -500,3 +500,4 @@ ITEM(poly_street_1) ITEM(poly_street_2) ITEM(poly_street_3) ITEM(poly_wetland) +ITEM2(0xffffffff,last) diff --git a/navit/navit/map.c b/navit/navit/map.c index d36e0de..e8da215 100644 --- a/navit/navit/map.c +++ b/navit/navit/map.c @@ -43,10 +43,10 @@ #include "debug.h" #include "coord.h" #include "projection.h" +#include "item.h" #include "map.h" #include "maptype.h" #include "transform.h" -#include "item.h" #include "plugin.h" #include "callback.h" #include "country.h" @@ -466,9 +466,8 @@ map_selection_rect_new(struct pcoord *center, int distance, int order) { int i; struct map_selection *ret=g_new0(struct map_selection, 1); - for (i = 0 ; i < layer_end ; i++) { - ret->order[i]=order; - } + ret->order=order; + ret->range=item_range_all; ret->u.c_rect.lu.x=center->x-distance; ret->u.c_rect.lu.y=center->y+distance; ret->u.c_rect.rl.x=center->x+distance; @@ -565,6 +564,64 @@ map_selection_contains_item_rect(struct map_selection *sel, struct item *item) } + +/** + * @brief Checks if a selection contains a item range + * + * This function checks if a selection contains at least one of the items in range + * + * @param sel The selection to be checked + * @param follow Whether the next pointer of the selection should be followed + * @param ranges The item ranges to be checked + * @count the number of elements in ranges + * @return True if there is a match, false otherwise + */ + +int +map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count) +{ + int i; + if (! sel) + return 1; + while (sel) { + for (i = 0 ; i < count ; i++) { + if (item_range_intersects_range(&sel->range, &range[i])) + return 1; + } + if (! follow) + break; + sel=sel->next; + } + return 0; +} +/** + * @brief Checks if a selection contains a item + * + * This function checks if a selection contains a item type + * + * @param sel The selection to be checked + * @param follow Whether the next pointer of the selection should be followed + * @param item The item type to be checked + * @return True if there is a match, false otherwise + */ + +int +map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type) +{ + if (! sel) + return 1; + while (sel) { + if (item_range_contains_item(&sel->range, type)) + return 1; + if (! follow) + break; + sel=sel->next; + } + return 0; +} + + + /** * @brief Checks if a pointer points to the private data of a map * diff --git a/navit/navit/map.h b/navit/navit/map.h index aac9291..663a540 100644 --- a/navit/navit/map.h +++ b/navit/navit/map.h @@ -50,7 +50,8 @@ struct map_selection { struct coord_rect c_rect; /**< For building the rectangle based on coordinates */ struct point_rect p_rect; /**< For building the rectangle based on points */ } u; - int order[layer_end]; /**< Holds the order to be selected for each layer of items */ + int order; /**< Holds the order */ + struct item_range range; /**< Range of items which should be delivered */ }; /** diff --git a/navit/navit/maptype.c b/navit/navit/maptype.c index eb4c163..cb77a1d 100644 --- a/navit/navit/maptype.c +++ b/navit/navit/maptype.c @@ -20,6 +20,7 @@ #include #include "debug.h" #include "projection.h" +#include "item.h" #include "map.h" #include "maptype.h" diff --git a/navit/navit/navit.c b/navit/navit/navit.c index 100b030..2c7c32e 100644 --- a/navit/navit/navit.c +++ b/navit/navit/navit.c @@ -1154,9 +1154,8 @@ navit_window_items_open(struct navit *this_, struct navit_window_items *nwi) sel.order[layer_street]=18; sel.order[layer_poly]=18; #else - sel.order[layer_town]=0; - sel.order[layer_street]=0; - sel.order[layer_poly]=0; + sel.order=0; + sel.range=item_range_all; #endif center=transform_center(this_->trans); sel.u.c_rect.lu.x=center->x-dist; diff --git a/navit/navit/popup.c b/navit/navit/popup.c index 1637605..0a694de 100644 --- a/navit/navit/popup.c +++ b/navit/navit/popup.c @@ -32,9 +32,9 @@ #include "point.h" #include "transform.h" #include "projection.h" +#include "item.h" #include "map.h" #include "graphics.h" -#include "item.h" #include "callback.h" #include "route.h" #include "navit_nls.h" diff --git a/navit/navit/route.c b/navit/navit/route.c index 2e9cd37..17de90b 100644 --- a/navit/navit/route.c +++ b/navit/navit/route.c @@ -54,9 +54,9 @@ #include "profile.h" #include "coord.h" #include "projection.h" +#include "item.h" #include "map.h" #include "mapset.h" -#include "item.h" #include "route.h" #include "track.h" #include "point.h" @@ -638,9 +638,9 @@ route_rect(int order, struct coord *c1, struct coord *c2, int rel, int abs) printf("%s:Out of memory\n", __FUNCTION__); return sel; } - sel->order[layer_town]=0; - sel->order[layer_poly]=0; - sel->order[layer_street]=order; + sel->order=order; + sel->range.min=route_item_first; + sel->range.max=route_item_last; dbg(1,"%p %p\n", c1, c2); dx=c1->x-c2->x; dy=c1->y-c2->y; diff --git a/navit/navit/search.c b/navit/navit/search.c index fd4c4b3..16d223d 100644 --- a/navit/navit/search.c +++ b/navit/navit/search.c @@ -21,10 +21,10 @@ #include #include "debug.h" #include "projection.h" +#include "item.h" #include "map.h" #include "mapset.h" #include "coord.h" -#include "item.h" #include "search.h" struct search_list_level { diff --git a/navit/navit/transform.c b/navit/navit/transform.c index 0ace912..3eda8a5 100644 --- a/navit/navit/transform.c +++ b/navit/navit/transform.c @@ -26,11 +26,11 @@ #include "config.h" #include "coord.h" #include "debug.h" +#include "item.h" #include "map.h" #include "transform.h" #include "projection.h" #include "point.h" -#include "item.h" struct transformation { int angle; /* Rotation angle */ @@ -264,7 +264,6 @@ transform_get_selection(struct transformation *this_, enum projection pro, int o struct map_selection *ret,*curri,*curro; struct coord_geo g; - int i; ret=map_selection_dup(this_->map_sel); curri=this_->map_sel; @@ -279,8 +278,8 @@ transform_get_selection(struct transformation *this_, enum projection pro, int o dbg(1,": - %f,%f\n", g.lat, g.lng); } dbg(1,"transform rect for %d is %d,%d - %d,%d\n", pro, curro->u.c_rect.lu.x, curro->u.c_rect.lu.y, curro->u.c_rect.rl.x, curro->u.c_rect.rl.y); - for (i = 0 ; i < layer_end ; i++) - curro->order[i]+=order; + curro->order+=order; + curro->range=item_range_all; curri=curri->next; curro=curro->next; }