2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
25 poly_coord_rewind(void *priv_data)
27 struct poly_priv *poly=priv_data;
29 poly->p=poly->subpoly_start;
34 poly_coord_get(void *priv_data, struct coord *c, int count)
36 struct poly_priv *poly=priv_data;
40 if (poly->p >= poly->subpoly_next)
42 c->x=get_u32_unal(&poly->p);
43 c->y=get_u32_unal(&poly->p);
51 poly_attr_rewind(void *priv_data)
53 struct poly_priv *poly=priv_data;
59 poly_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
61 struct poly_priv *poly=priv_data;
66 while (poly->attr_next != attr_none) {
67 if (poly_attr_get(poly, poly->attr_next, attr))
72 attr->u.str=poly->name;
73 poly->attr_next=attr_none;
83 static struct item_methods poly_meth = {
91 poly_get_data(struct poly_priv *poly, unsigned char **p)
93 poly->c[0].x=get_u32_unal(p);
94 poly->c[0].y=get_u32_unal(p);
95 poly->c[1].x=get_u32_unal(p);
96 poly->c[1].y=get_u32_unal(p);
97 *p+=sizeof(struct coord);
98 poly->name=(char *)(*p);
105 poly->polys=get_u32_unal(p);
106 poly->count=(unsigned int *)(*p); (*p)+=poly->polys*sizeof(unsigned int);
107 poly->count_sum=get_u32_unal(p);
111 poly_get(struct map_rect_priv *mr, struct poly_priv *poly, struct item *item)
116 if (mr->b.p >= mr->b.end)
118 if (mr->b.p == mr->b.p_start) {
121 poly->subpoly_num_all=0;
122 poly->poly_next=mr->b.p;
123 item->meth=&poly_meth;
125 if (poly->poly_num >= block_get_count(mr->b.b))
127 if (!poly->subpoly_num) {
128 mr->b.p=poly->poly_next;
129 item->id_lo=mr->b.p-mr->file->begin;
130 poly_get_data(poly, &mr->b.p);
131 poly->poly_next=mr->b.p+poly->count_sum*sizeof(struct coord);
135 if (mr->cur_sel && (poly->order > mr->cur_sel->order*3 || !coord_rect_overlap(&mr->cur_sel->u.c_rect, &r))) {
136 poly->subpoly_num_all+=poly->polys;
137 mr->b.p=poly->poly_next;
142 item->type=type_poly_wood;
145 item->type=type_poly_town;
148 item->type=type_poly_cemetery;
151 item->type=type_poly_building;
154 item->type=type_poly_museum;
157 item->type=type_poly_place;
160 item->type=type_poly_commercial_center;
163 item->type=type_poly_industry;
166 /* FIXME: what is this ?*/
167 item->type=type_poly_place;
170 item->type=type_poly_car_parking;
173 item->type=type_poly_airport;
176 item->type=type_poly_station;
179 item->type=type_poly_hospital;
182 item->type=type_poly_hospital;
185 item->type=type_poly_university;
188 item->type=type_poly_university;
191 item->type=type_poly_park;
194 item->type=type_poly_sport;
197 item->type=type_poly_sport;
200 item->type=type_poly_golf_course;
203 item->type=type_poly_national_park;
206 item->type=type_poly_nature_park;
209 item->type=type_poly_water;
212 item->type=type_water_line;
215 /* FIXME: what is this ?*/
216 item->type=type_border_state;
219 item->type=type_border_country;
222 item->type=type_border_state;
225 item->type=type_rail;
228 dbg(0,"Unknown poly type 0x%x '%s' 0x%x,0x%x\n", poly->type,poly->name,r.lu.x,r.lu.y);
229 item->type=type_street_unkn;
231 if (!map_selection_contains_item(mr->cur_sel, 0, item->type)) {
232 poly->subpoly_num_all+=poly->polys;
233 mr->b.p=poly->poly_next;
237 mr->b.p=poly->subpoly_next;
238 dbg(1,"%d %d %s\n", poly->subpoly_num_all, mr->b.block_num, poly->name);
239 item->id_lo=poly->subpoly_num_all | (mr->b.block_num << 16);
240 item->id_hi=(mr->current_file << 16);
241 dbg(1,"0x%x 0x%x\n", item->id_lo, item->id_hi);
242 poly->subpoly_next=mr->b.p+L(poly->count[poly->subpoly_num])*sizeof(struct coord);
244 poly->subpoly_num_all++;
245 if (poly->subpoly_num >= poly->polys)
247 poly->subpoly_start=poly->p=mr->b.p;
248 item->priv_data=poly;
249 poly->attr_next=attr_label;
255 poly_get_byid(struct map_rect_priv *mr, struct poly_priv *poly, int id_hi, int id_lo, struct item *item)
257 int count=id_lo & 0xffff;
259 block_get_byindex(mr->m->file[mr->current_file], id_lo >> 16, &mr->b);
260 while (count-- >= 0) {
261 ret=poly_get(mr, poly, item);