/[zanavi_public1]/navit/navit/item.c
ZANavi

Contents of /navit/navit/item.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 54 - (hide annotations) (download)
Mon Dec 12 13:41:30 2016 UTC (6 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 29001 byte(s)
v2.0.56
1 zoff99 2 /**
2 zoff99 31 * ZANavi, Zoff Android Navigation system.
3     * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4     *
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.
8     *
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.
13     *
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.
18     */
19    
20     /**
21 zoff99 2 * Navit, a modular navigation system.
22     * Copyright (C) 2005-2008 Navit Team
23     *
24     * This program is free software; you can redistribute it and/or
25     * modify it under the terms of the GNU General Public License
26     * version 2 as published by the Free Software Foundation.
27     *
28     * This program is distributed in the hope that it will be useful,
29     * but WITHOUT ANY WARRANTY; without even the implied warranty of
30     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31     * GNU General Public License for more details.
32     *
33     * You should have received a copy of the GNU General Public License
34     * along with this program; if not, write to the
35     * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36     * Boston, MA 02110-1301, USA.
37     */
38    
39     #include <stdio.h>
40     #include <string.h>
41     #include <glib.h>
42     #include "coord.h"
43     #include "debug.h"
44     #include "item.h"
45     #include "map.h"
46     #include "transform.h"
47    
48 zoff99 27 struct item_name
49     {
50     enum item_type item;
51     char *name;
52 zoff99 2 };
53    
54 zoff99 31 struct item_range item_range_all = { type_none, type_last };
55 zoff99 2
56 zoff99 27 struct default_flags
57     {
58 zoff99 2 enum item_type type;
59     int flags;
60     };
61    
62     struct item busy_item;
63    
64 zoff99 41 struct default_flags default_flags2[] = { { type_street_nopass, NAVIT_AF_PBH }, { type_street_0, NAVIT_AF_ALL }, { type_street_1_city, NAVIT_AF_ALL }, { type_street_2_city, NAVIT_AF_ALL }, { type_street_3_city, NAVIT_AF_ALL }, { type_street_4_city, NAVIT_AF_ALL }, { type_highway_city, NAVIT_AF_MOTORIZED_FAST }, { type_street_1_land, NAVIT_AF_ALL }, { type_street_2_land, NAVIT_AF_ALL }, { type_street_3_land, NAVIT_AF_ALL }, { type_street_4_land, NAVIT_AF_ALL }, { type_street_n_lanes, NAVIT_AF_MOTORIZED_FAST }, { type_highway_land, NAVIT_AF_MOTORIZED_FAST }, { type_roundabout, NAVIT_AF_ALL }, { type_ferry, NAVIT_AF_ALL }, { type_cycleway, NAVIT_AF_PBH }, { type_track_paved, NAVIT_AF_ALL }, { type_track_gravelled, NAVIT_AF_ALL }, { type_track_unpaved, NAVIT_AF_ALL }, { type_track_ground, NAVIT_AF_ALL }, { type_track_grass, NAVIT_AF_ALL }, { type_footway, NAVIT_AF_PBH }, { type_living_street, NAVIT_AF_ALL }, { type_street_service, NAVIT_AF_ALL }, { type_street_parking_lane, NAVIT_AF_ALL }, { type_bridleway, NAVIT_AF_PBH }, { type_path, NAVIT_AF_PBH }, { type_steps, NAVIT_AF_PBH }, { type_ramp_highway_land, NAVIT_AF_MOTORIZED_FAST }, { type_ramp_street_4_city, NAVIT_AF_ALL }, { type_ramp_street_3_city, NAVIT_AF_ALL }, { type_ramp_street_2_city, NAVIT_AF_ALL }, { type_street_pedestrian, NAVIT_AF_PBH }, };
65 zoff99 2
66 zoff99 41
67 zoff99 31 struct item_name item_names[] = {
68 zoff99 2 #define ITEM2(x,y) ITEM(y)
69     #define ITEM(x) { type_##x, #x },
70     #include "item_def.h"
71     #undef ITEM2
72     #undef ITEM
73 zoff99 27 };
74 zoff99 2
75     static GHashTable *default_flags_hash;
76    
77     int *
78     item_get_default_flags(enum item_type type)
79     {
80 zoff99 27 if (!default_flags_hash)
81     {
82 zoff99 2 int i;
83 zoff99 27 default_flags_hash = g_hash_table_new(NULL, NULL);
84     for (i = 0; i < sizeof(default_flags2) / sizeof(struct default_flags); i++)
85     {
86     g_hash_table_insert(default_flags_hash, (void *) (long) default_flags2[i].type, &default_flags2[i].flags);
87 zoff99 2 }
88     }
89 zoff99 27 return g_hash_table_lookup(default_flags_hash, (void *) (long) type);
90 zoff99 2 }
91    
92 zoff99 27 void item_cleanup(void)
93 zoff99 2 {
94     if (default_flags_hash)
95 zoff99 54 {
96 zoff99 2 g_hash_table_destroy(default_flags_hash);
97 zoff99 54 }
98 zoff99 2 }
99    
100 zoff99 27 void item_coord_rewind(struct item *it)
101 zoff99 2 {
102     it->meth->item_coord_rewind(it->priv_data);
103     }
104    
105 zoff99 27 int item_coord_get(struct item *it, struct coord *c, int count)
106 zoff99 2 {
107     return it->meth->item_coord_get(it->priv_data, c, count);
108     }
109    
110 zoff99 27 int item_coord_set(struct item *it, struct coord *c, int count, enum change_mode mode)
111 zoff99 2 {
112     if (!it->meth->item_coord_set)
113 zoff99 40 {
114 zoff99 2 return 0;
115 zoff99 40 }
116    
117 zoff99 2 return it->meth->item_coord_set(it->priv_data, c, count, mode);
118     }
119    
120 zoff99 27 int item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel)
121 zoff99 2 {
122 zoff99 27 int i, ret = it->meth->item_coord_get(it->priv_data, c, count);
123 zoff99 2 struct coord_rect r;
124     struct map_selection *curr;
125 zoff99 54
126 zoff99 2 if (ret <= 0 || !sel)
127 zoff99 54 {
128 zoff99 2 return ret;
129 zoff99 54 }
130    
131 zoff99 27 r.lu = c[0];
132     r.rl = c[0];
133 zoff99 54
134 zoff99 27 for (i = 1; i < ret; i++)
135     {
136 zoff99 2 if (r.lu.x > c[i].x)
137 zoff99 27 r.lu.x = c[i].x;
138 zoff99 54
139 zoff99 2 if (r.rl.x < c[i].x)
140 zoff99 27 r.rl.x = c[i].x;
141 zoff99 54
142 zoff99 2 if (r.rl.y > c[i].y)
143 zoff99 27 r.rl.y = c[i].y;
144 zoff99 54
145 zoff99 2 if (r.lu.y < c[i].y)
146 zoff99 27 r.lu.y = c[i].y;
147 zoff99 2 }
148 zoff99 54
149 zoff99 27 curr = sel;
150 zoff99 54
151 zoff99 27 while (curr)
152     {
153     struct coord_rect *sr = &curr->u.c_rect;
154     if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x && r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
155 zoff99 54 {
156 zoff99 2 return ret;
157 zoff99 54 }
158 zoff99 27 curr = curr->next;
159 zoff99 2 }
160 zoff99 54
161 zoff99 27 return 0;
162 zoff99 2 }
163    
164 zoff99 27 int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to)
165 zoff99 2 {
166 zoff99 27 int ret = item_coord_get(it, c, count);
167 zoff99 2 int i;
168 zoff99 27 enum projection from = map_projection(it->map);
169 zoff99 54
170 zoff99 27 if (from != to)
171     for (i = 0; i < count; i++)
172     transform_from_to(c + i, from, c + i, to);
173 zoff99 54
174 zoff99 2 return ret;
175     }
176    
177 zoff99 27 int item_coord_is_node(struct item *it)
178 zoff99 2 {
179     if (it->meth->item_coord_is_node)
180 zoff99 54 {
181 zoff99 2 return it->meth->item_coord_is_node(it->priv_data);
182 zoff99 54 }
183    
184 zoff99 2 return 0;
185     }
186    
187 zoff99 27 void item_attr_rewind(struct item *it)
188 zoff99 2 {
189     it->meth->item_attr_rewind(it->priv_data);
190     }
191    
192 zoff99 27 int item_attr_get(struct item *it, enum attr_type attr_type, struct attr *attr)
193 zoff99 2 {
194     if (it->meth)
195     {
196     return it->meth->item_attr_get(it->priv_data, attr_type, attr);
197     }
198     else
199     {
200 zoff99 27 dbg(0, "not method found\n");
201 zoff99 2 return 0;
202     }
203     }
204    
205 zoff99 27 int item_attr_set(struct item *it, struct attr *attr, enum change_mode mode)
206 zoff99 2 {
207     if (!it->meth->item_attr_set)
208 zoff99 54 {
209 zoff99 2 return 0;
210 zoff99 54 }
211    
212 zoff99 2 return it->meth->item_attr_set(it->priv_data, attr, mode);
213     }
214    
215     struct item * item_new(char *type, int zoom)
216     {
217     struct item * it;
218    
219     it = g_new0(struct item, 1);
220    
221     /* FIXME evaluate arguments */
222    
223     return it;
224     }
225    
226 zoff99 29 // not working yet!!!!! ------
227     /*
228 zoff99 31 void item_dup(struct item *src, struct item *dst)
229     {
230     int size;
231     void *priv_data;
232 zoff99 29
233 zoff99 31 dst = g_new0(struct item, 1);
234     dst->type=src->type;
235     dst->id_hi=src->id_hi;
236     dst->id_lo=src->id_lo;
237 zoff99 29
238 zoff99 31 dst->priv_data=g_malloc(size);
239     memcpy(dst->priv_data, src->priv_data, size);
240     // int len = (ib->len + 1) * 4;
241 zoff99 29
242 zoff99 31 }
243     */
244 zoff99 29 // not working yet!!!!! ------
245    
246 zoff99 34 // return: 1 -> don't put it into search index
247     // 0 -> yes, put it into search index
248     int item_not_for_search_index(enum item_type i_type)
249     {
250 zoff99 29
251 zoff99 34 if (i_type == type_house_number_interpolation_even)
252     {
253     return 1;
254     }
255     // exclude "unknown street" types from search index --> dont do this, otherwise we dont find all the good things :-)
256     //else if (i_type == type_street_unkn)
257     //{
258     // return 1;
259     //}
260     else if (i_type == type_house_number_interpolation_odd)
261     {
262     return 1;
263     }
264     else if (i_type == type_house_number_interpolation_all)
265     {
266     return 1;
267     }
268     else if (i_type == type_house_number_interpolation_alphabetic)
269     {
270     return 1;
271     }
272     else if (i_type == type_poly_airport)
273     {
274     return 1;
275     }
276     else if (i_type == type_poly_apron)
277     {
278     return 1;
279     }
280     else if (i_type == type_poly_terminal)
281     {
282     return 1;
283     }
284     else if (i_type == type_border_national_park)
285     {
286     return 1;
287     }
288     else if (i_type == type_border_political)
289     {
290     return 1;
291     }
292     else if (i_type == type_height_line_1)
293     {
294     return 1;
295     }
296     else if (i_type == type_height_line_2)
297     {
298     return 1;
299     }
300     else if (i_type == type_height_line_3)
301     {
302     return 1;
303     }
304     else if (i_type == type_poly_wood)
305     {
306     return 1;
307     }
308     else if (i_type == type_poly_greenfield)
309     {
310     return 1;
311     }
312     else if (i_type == type_poly_reservoir)
313     {
314     return 1;
315     }
316     else if (i_type == type_poly_playground)
317     {
318     return 1;
319     }
320     else if (i_type == type_poly_land)
321     {
322     return 1;
323     }
324     else if (i_type == type_poly_marsh)
325     {
326     return 1;
327     }
328     else if (i_type == type_poly_mud)
329     {
330     return 1;
331     }
332     else if (i_type == type_poly_water)
333     {
334     return 1;
335     }
336     else if (i_type == type_poly_wood)
337     {
338     return 1;
339     }
340     else if (i_type == type_poly_place1)
341     {
342     return 1;
343     }
344     else if (i_type == type_poly_place2)
345     {
346     return 1;
347     }
348     else if (i_type == type_poly_place3)
349     {
350     return 1;
351     }
352     else if (i_type == type_poly_place4)
353     {
354     return 1;
355     }
356     else if (i_type == type_poly_place5)
357     {
358     return 1;
359     }
360     else if (i_type == type_poly_place6)
361     {
362     return 1;
363     }
364     else if (i_type == type_ferry)
365     {
366     return 1;
367     }
368     else if (i_type == type_water_canal)
369     {
370     return 1;
371     }
372     else if (i_type == type_water_drain)
373     {
374     return 1;
375     }
376     else if (i_type == type_water_river)
377     {
378     return 1;
379     }
380     else if (i_type == type_poly_water)
381     {
382     return 1;
383     }
384     else if (i_type == type_water_stream)
385     {
386     return 1;
387     }
388     else
389     {
390     return 0;
391     }
392    
393     return 0;
394     }
395    
396     int item_is_town_label_major(enum item_type i_type)
397     {
398     if (i_type == type_town_label_1e6)
399     {
400     return 1;
401     }
402     else if (i_type == type_town_label_2e6)
403     {
404     return 1;
405     }
406     else if (i_type == type_town_label_5e6)
407     {
408     return 1;
409     }
410     else if (i_type == type_town_label_1e7)
411     {
412     return 1;
413     }
414     else
415     {
416     return 0;
417     }
418    
419     return 0;
420     }
421    
422     int item_is_town_label_no_major(enum item_type i_type)
423     {
424     if (i_type == type_town_label_0e0)
425     {
426     return 1;
427     }
428     else if (i_type == type_town_label_1e0)
429     {
430     return 1;
431     }
432     else if (i_type == type_town_label_2e0)
433     {
434     return 1;
435     }
436     else if (i_type == type_town_label_5e0)
437     {
438     return 1;
439     }
440     else if (i_type == type_town_label_1e1)
441     {
442     return 1;
443     }
444     else if (i_type == type_town_label_2e1)
445     {
446     return 1;
447     }
448     else if (i_type == type_town_label_5e1)
449     {
450     return 1;
451     }
452     else if (i_type == type_town_label_1e2)
453     {
454     return 1;
455     }
456     else if (i_type == type_town_label_2e2)
457     {
458     return 1;
459     }
460     else if (i_type == type_town_label_5e2)
461     {
462     return 1;
463     }
464     else if (i_type == type_town_label_1e3)
465     {
466     return 1;
467     }
468     else if (i_type == type_town_label_2e3)
469     {
470     return 1;
471     }
472     else if (i_type == type_town_label_5e3)
473     {
474     return 1;
475     }
476     else if (i_type == type_town_label_1e4)
477     {
478     return 1;
479     }
480     else if (i_type == type_town_label_2e4)
481     {
482     return 1;
483     }
484     else if (i_type == type_town_label_5e4)
485     {
486     return 1;
487     }
488     else if (i_type == type_town_label_1e5)
489     {
490     return 1;
491     }
492     else if (i_type == type_town_label_2e5)
493     {
494     return 1;
495     }
496     else if (i_type == type_town_label_5e5)
497     {
498     return 1;
499     }
500     else if (i_type == type_town_label)
501     {
502     return 1;
503     }
504     /* major town */
505     /*
506     else if (i_type == type_town_label_1e6)
507     {
508     return 1;
509     }
510     else if (i_type == type_town_label_2e6)
511     {
512     return 1;
513     }
514     else if (i_type == type_town_label_5e6)
515     {
516     return 1;
517     }
518     else if (i_type == type_town_label_1e7)
519     {
520     return 1;
521     }
522     */
523     else
524     {
525     return 0;
526     }
527    
528     return 0;
529     }
530    
531     int item_is_district_label(enum item_type i_type)
532     {
533     if (i_type == type_district_label_0e0)
534     {
535     return 1;
536     }
537     else if (i_type == type_district_label_1e0)
538     {
539     return 1;
540     }
541     else if (i_type == type_district_label_2e0)
542     {
543     return 1;
544     }
545     else if (i_type == type_district_label_5e0)
546     {
547     return 1;
548     }
549     else if (i_type == type_district_label_1e1)
550     {
551     return 1;
552     }
553     else if (i_type == type_district_label_2e1)
554     {
555     return 1;
556     }
557     else if (i_type == type_district_label_5e1)
558     {
559     return 1;
560     }
561     else if (i_type == type_district_label_1e2)
562     {
563     return 1;
564     }
565     else if (i_type == type_district_label_2e2)
566     {
567     return 1;
568     }
569     else if (i_type == type_district_label_5e2)
570     {
571     return 1;
572     }
573     else if (i_type == type_district_label_1e3)
574     {
575     return 1;
576     }
577     else if (i_type == type_district_label_2e3)
578     {
579     return 1;
580     }
581     else if (i_type == type_district_label_5e3)
582     {
583     return 1;
584     }
585     else if (i_type == type_district_label_1e4)
586     {
587     return 1;
588     }
589     else if (i_type == type_district_label_2e4)
590     {
591     return 1;
592     }
593     else if (i_type == type_district_label_5e4)
594     {
595     return 1;
596     }
597     else if (i_type == type_district_label_1e5)
598     {
599     return 1;
600     }
601     else if (i_type == type_district_label_2e5)
602     {
603     return 1;
604     }
605     else if (i_type == type_district_label_5e5)
606     {
607     return 1;
608     }
609     else if (i_type == type_district_label_1e6)
610     {
611     return 1;
612     }
613     else if (i_type == type_district_label_2e6)
614     {
615     return 1;
616     }
617     else if (i_type == type_district_label_5e6)
618     {
619     return 1;
620     }
621     else if (i_type == type_district_label_1e7)
622     {
623     return 1;
624     }
625     else if (i_type == type_district_label)
626     {
627     return 1;
628     }
629     else
630     {
631     return 0;
632     }
633    
634     return 0;
635     }
636    
637     int item_is_poi(enum item_type i_type)
638     // int item_is_poi(int item_type i_type)
639     {
640     if (i_type == type_poi_lake)
641     {
642     return 1;
643     }
644     else if (i_type == type_poi_island)
645     {
646     return 1;
647     }
648     else if (i_type == type_poi_land_feature)
649     {
650     return 1;
651     }
652     else if (i_type == type_poi_cape)
653     {
654     return 1;
655     }
656     else if (i_type == type_poi_rock)
657     {
658     return 1;
659     }
660     else if (i_type == type_poi_airport)
661     {
662     return 1;
663     }
664     else if (i_type == type_poi_toll_booth)
665     {
666     return 1;
667     }
668     else if (i_type == type_poi_fuel)
669     {
670     return 1;
671     }
672     else if (i_type == type_poi_hotel)
673     {
674     return 1;
675     }
676     else if (i_type == type_poi_camp_rv)
677     {
678     return 1;
679     }
680     else if (i_type == type_poi_marina)
681     {
682     return 1;
683     }
684     else if (i_type == type_poi_attraction)
685     {
686     return 1;
687     }
688     else if (i_type == type_poi_museum_history)
689     {
690     return 1;
691     }
692     else if (i_type == type_poi_shopping)
693     {
694     return 1;
695     }
696     else if (i_type == type_poi_car_dealer_parts)
697     {
698     return 1;
699     }
700     else if (i_type == type_poi_car_parking)
701     {
702     return 1;
703     }
704     else if (i_type == type_poi_wreck)
705     {
706     return 1;
707     }
708     else if (i_type == type_poi_building)
709     {
710     return 1;
711     }
712     else if (i_type == type_poi_bridge)
713     {
714     return 1;
715     }
716     else if (i_type == type_poi_park)
717     {
718     return 1;
719     }
720     else if (i_type == type_poi_water_feature)
721     {
722     return 1;
723     }
724     else if (i_type == type_poi_bar)
725     {
726     return 1;
727     }
728     else if (i_type == type_poi_picnic)
729     {
730     return 1;
731     }
732     else if (i_type == type_poi_hospital)
733     {
734     return 1;
735     }
736     else if (i_type == type_poi_camping)
737     {
738     return 1;
739     }
740     else if (i_type == type_poi_public_utilities)
741     {
742     return 1;
743     }
744     else if (i_type == type_poi_burgerking)
745     {
746     return 1;
747     }
748     else if (i_type == type_poi_kfc)
749     {
750     return 1;
751     }
752     else if (i_type == type_poi_mcdonalds)
753     {
754     return 1;
755     }
756     else if (i_type == type_poi_wienerwald)
757     {
758     return 1;
759     }
760     else if (i_type == type_poi_dining)
761     {
762     return 1;
763     }
764     else if (i_type == type_poi_fastfood)
765     {
766     return 1;
767     }
768     else if (i_type == type_poi_police)
769     {
770     return 1;
771     }
772     else if (i_type == type_poi_auto_club)
773     {
774     return 1;
775     }
776     else if (i_type == type_poi_autoservice)
777     {
778     return 1;
779     }
780     else if (i_type == type_poi_bank)
781     {
782     return 1;
783     }
784     else if (i_type == type_poi_bay)
785     {
786     return 1;
787     }
788     else if (i_type == type_poi_bend)
789     {
790     return 1;
791     }
792     else if (i_type == type_poi_boat_ramp)
793     {
794     return 1;
795     }
796     else if (i_type == type_poi_border_station)
797     {
798     return 1;
799     }
800     else if (i_type == type_poi_bowling)
801     {
802     return 1;
803     }
804     else if (i_type == type_poi_bus_station)
805     {
806     return 1;
807     }
808     else if (i_type == type_poi_bus_stop)
809     {
810     return 1;
811     }
812     else if (i_type == type_poi_business_service)
813     {
814     return 1;
815     }
816     else if (i_type == type_poi_car_rent)
817     {
818     return 1;
819     }
820     else if (i_type == type_poi_car_wash)
821     {
822     return 1;
823     }
824     else if (i_type == type_poi_casino)
825     {
826     return 1;
827     }
828     else if (i_type == type_poi_cemetery)
829     {
830     return 1;
831     }
832     else if (i_type == type_poi_church)
833     {
834     return 1;
835     }
836     else if (i_type == type_poi_cinema)
837     {
838     return 1;
839     }
840     else if (i_type == type_poi_civil_removeme)
841     {
842     return 1;
843     }
844     else if (i_type == type_poi_communication)
845     {
846     return 1;
847     }
848     else if (i_type == type_poi_concert)
849     {
850     return 1;
851     }
852     else if (i_type == type_poi_cove)
853     {
854     return 1;
855     }
856     else if (i_type == type_poi_crossing)
857     {
858     return 1;
859     }
860     else if (i_type == type_poi_dam)
861     {
862     return 1;
863     }
864     else if (i_type == type_poi_danger_area)
865     {
866     return 1;
867     }
868     else if (i_type == type_poi_danger_sea_wreck)
869     {
870     return 1;
871     }
872     else if (i_type == type_poi_daymark)
873     {
874     return 1;
875     }
876     else if (i_type == type_poi_diving)
877     {
878     return 1;
879     }
880     else if (i_type == type_poi_drinking_water)
881     {
882     return 1;
883     }
884     else if (i_type == type_poi_emergency)
885     {
886     return 1;
887     }
888     else if (i_type == type_poi_fair)
889     {
890     return 1;
891     }
892     else if (i_type == type_poi_firebrigade)
893     {
894     return 1;
895     }
896     else if (i_type == type_poi_fish)
897     {
898     return 1;
899     }
900     else if (i_type == type_poi_forbidden_area)
901     {
902     return 1;
903     }
904     else if (i_type == type_poi_shop_gps)
905     {
906     return 1;
907     }
908     else if (i_type == type_poi_golf)
909     {
910     return 1;
911     }
912     else if (i_type == type_poi_government_building)
913     {
914     return 1;
915     }
916     else if (i_type == type_poi_height)
917     {
918     return 1;
919     }
920     else if (i_type == type_poi_heliport)
921     {
922     return 1;
923     }
924     else if (i_type == type_poi_hotspring)
925     {
926     return 1;
927     }
928     else if (i_type == type_poi_icesport)
929     {
930     return 1;
931     }
932     else if (i_type == type_poi_information)
933     {
934     return 1;
935     }
936     else if (i_type == type_poi_justice)
937     {
938     return 1;
939     }
940     else if (i_type == type_poi_landmark)
941     {
942     return 1;
943     }
944     else if (i_type == type_poi_levee)
945     {
946     return 1;
947     }
948     else if (i_type == type_poi_library)
949     {
950     return 1;
951     }
952     else if (i_type == type_poi_locale)
953     {
954     return 1;
955     }
956     else if (i_type == type_poi_loudspeaker)
957     {
958     return 1;
959     }
960     else if (i_type == type_poi_mall)
961     {
962     return 1;
963     }
964     else if (i_type == type_poi_manmade_feature)
965     {
966     return 1;
967     }
968     else if (i_type == type_poi_marine)
969     {
970     return 1;
971     }
972     else if (i_type == type_poi_marine_type)
973     {
974     return 1;
975     }
976     else if (i_type == type_poi_mark)
977     {
978     return 1;
979     }
980     else if (i_type == type_poi_military)
981     {
982     return 1;
983     }
984     else if (i_type == type_poi_mine)
985     {
986     return 1;
987     }
988     else if (i_type == type_poi_nondangerous)
989     {
990     return 1;
991     }
992     else if (i_type == type_poi_oil_field)
993     {
994     return 1;
995     }
996     else if (i_type == type_poi_personal_service)
997     {
998     return 1;
999     }
1000     else if (i_type == type_poi_pharmacy)
1001     {
1002     return 1;
1003     }
1004     else if (i_type == type_poi_post_removeme)
1005     {
1006     return 1;
1007     }
1008     else if (i_type == type_poi_public_office)
1009     {
1010     return 1;
1011     }
1012     else if (i_type == type_poi_repair_service)
1013     {
1014     return 1;
1015     }
1016     else if (i_type == type_poi_resort)
1017     {
1018     return 1;
1019     }
1020     else if (i_type == type_poi_rest_room_removeme)
1021     {
1022     return 1;
1023     }
1024     else if (i_type == type_poi_restaurant)
1025     {
1026     return 1;
1027     }
1028     else if (i_type == type_poi_restricted_area)
1029     {
1030     return 1;
1031     }
1032     else if (i_type == type_poi_restroom)
1033     {
1034     return 1;
1035     }
1036     else if (i_type == type_poi_sailing)
1037     {
1038     return 1;
1039     }
1040     else if (i_type == type_poi_scenic_area)
1041     {
1042     return 1;
1043     }
1044     else if (i_type == type_poi_school)
1045     {
1046     return 1;
1047     }
1048     else if (i_type == type_poi_service)
1049     {
1050     return 1;
1051     }
1052     else if (i_type == type_poi_shop_apparel)
1053     {
1054     return 1;
1055     }
1056     else if (i_type == type_poi_shop_computer)
1057     {
1058     return 1;
1059     }
1060     else if (i_type == type_poi_shop_department)
1061     {
1062     return 1;
1063     }
1064     else if (i_type == type_poi_shop_furnish_removeme)
1065     {
1066     return 1;
1067     }
1068     else if (i_type == type_poi_shop_grocery)
1069     {
1070     return 1;
1071     }
1072     else if (i_type == type_poi_shop_handg)
1073     {
1074     return 1;
1075     }
1076     else if (i_type == type_poi_shop_merchandise)
1077     {
1078     return 1;
1079     }
1080     else if (i_type == type_poi_shop_retail)
1081     {
1082     return 1;
1083     }
1084     else if (i_type == type_poi_shower)
1085     {
1086     return 1;
1087     }
1088     else if (i_type == type_poi_skiing)
1089     {
1090     return 1;
1091     }
1092     else if (i_type == type_poi_social_service)
1093     {
1094     return 1;
1095     }
1096     else if (i_type == type_poi_sounding)
1097     {
1098     return 1;
1099     }
1100     else if (i_type == type_poi_sport)
1101     {
1102     return 1;
1103     }
1104     else if (i_type == type_poi_stadium)
1105     {
1106     return 1;
1107     }
1108     else if (i_type == type_poi_subdivision_removeme)
1109     {
1110     return 1;
1111     }
1112     else if (i_type == type_poi_swimming)
1113     {
1114     return 1;
1115     }
1116     else if (i_type == type_poi_telephone)
1117     {
1118     return 1;
1119     }
1120     else if (i_type == type_poi_theater)
1121     {
1122     return 1;
1123     }
1124     else if (i_type == type_poi_tide)
1125     {
1126     return 1;
1127     }
1128     else if (i_type == type_poi_tower)
1129     {
1130     return 1;
1131     }
1132     else if (i_type == type_poi_trail)
1133     {
1134     return 1;
1135     }
1136     else if (i_type == type_poi_truck_stop)
1137     {
1138     return 1;
1139     }
1140     else if (i_type == type_poi_tunnel)
1141     {
1142     return 1;
1143     }
1144     else if (i_type == type_poi_wine)
1145     {
1146     return 1;
1147     }
1148     else if (i_type == type_poi_worship)
1149     {
1150     return 1;
1151     }
1152     else if (i_type == type_poi_wrecker)
1153     {
1154     return 1;
1155     }
1156     else if (i_type == type_poi_zoo)
1157     {
1158     return 1;
1159     }
1160     else if (i_type == type_poi_gc_multi)
1161     {
1162     return 1;
1163     }
1164     else if (i_type == type_poi_gc_tradi)
1165     {
1166     return 1;
1167     }
1168     else if (i_type == type_poi_gc_event)
1169     {
1170     return 1;
1171     }
1172     else if (i_type == type_poi_gc_mystery)
1173     {
1174     return 1;
1175     }
1176     else if (i_type == type_poi_gc_question)
1177     {
1178     return 1;
1179     }
1180     else if (i_type == type_poi_gc_stages)
1181     {
1182     return 1;
1183     }
1184     else if (i_type == type_poi_gc_reference)
1185     {
1186     return 1;
1187     }
1188     else if (i_type == type_poi_gc_webcam)
1189     {
1190     return 1;
1191     }
1192     else if (i_type == type_poi_cafe)
1193     {
1194     return 1;
1195     }
1196     else if (i_type == type_poi_peak)
1197     {
1198     return 1;
1199     }
1200     else if (i_type == type_poi_rail_station)
1201     {
1202     return 1;
1203     }
1204     else if (i_type == type_poi_image)
1205     {
1206     return 1;
1207     }
1208     else if (i_type == type_poi_townhall)
1209     {
1210     return 1;
1211     }
1212     else if (i_type == type_poi_level_crossing)
1213     {
1214     return 1;
1215     }
1216     else if (i_type == type_poi_rail_halt)
1217     {
1218     return 1;
1219     }
1220     else if (i_type == type_poi_rail_tram_stop)
1221     {
1222     return 1;
1223     }
1224     else if (i_type == type_poi_wifi)
1225     {
1226     return 1;
1227     }
1228     else if (i_type == type_poi_bench)
1229     {
1230     return 1;
1231     }
1232     else if (i_type == type_poi_biergarten)
1233     {
1234     return 1;
1235     }
1236     else if (i_type == type_poi_boundary_stone)
1237     {
1238     return 1;
1239     }
1240     else if (i_type == type_poi_castle)
1241     {
1242     return 1;
1243     }
1244     else if (i_type == type_poi_hunting_stand)
1245     {
1246     return 1;
1247     }
1248     else if (i_type == type_poi_memorial)
1249     {
1250     return 1;
1251     }
1252     else if (i_type == type_poi_monument)
1253     {
1254     return 1;
1255     }
1256     else if (i_type == type_poi_shelter)
1257     {
1258     return 1;
1259     }
1260     else if (i_type == type_poi_fountain)
1261     {
1262     return 1;
1263     }
1264     else if (i_type == type_poi_potable_water)
1265     {
1266     return 1;
1267     }
1268     else if (i_type == type_poi_toilets)
1269     {
1270     return 1;
1271     }
1272     else if (i_type == type_poi_viewpoint)
1273     {
1274     return 1;
1275     }
1276     else if (i_type == type_poi_ruins)
1277     {
1278     return 1;
1279     }
1280     else if (i_type == type_poi_post_box)
1281     {
1282     return 1;
1283     }
1284     else if (i_type == type_poi_post_office)
1285     {
1286     return 1;
1287     }
1288     else if (i_type == type_poi_school_university)
1289     {
1290     return 1;
1291     }
1292     else if (i_type == type_poi_school_college)
1293     {
1294     return 1;
1295     }
1296     else if (i_type == type_poi_motel)
1297     {
1298     return 1;
1299     }
1300     else if (i_type == type_poi_guesthouse)
1301     {
1302     return 1;
1303     }
1304     else if (i_type == type_poi_hostel)
1305     {
1306     return 1;
1307     }
1308     else if (i_type == type_poi_taxi)
1309     {
1310     return 1;
1311     }
1312     else if (i_type == type_poi_prison)
1313     {
1314     return 1;
1315     }
1316     else if (i_type == type_poi_kindergarten)
1317     {
1318     return 1;
1319     }
1320     else if (i_type == type_poi_shop_butcher)
1321     {
1322     return 1;
1323     }
1324     else if (i_type == type_poi_shop_baker)
1325     {
1326     return 1;
1327     }
1328     else if (i_type == type_poi_shop_kiosk)
1329     {
1330     return 1;
1331     }
1332     else if (i_type == type_poi_soccer)
1333     {
1334     return 1;
1335     }
1336     else if (i_type == type_poi_basketball)
1337     {
1338     return 1;
1339     }
1340     else if (i_type == type_poi_baseball)
1341     {
1342     return 1;
1343     }
1344     else if (i_type == type_poi_climbing)
1345     {
1346     return 1;
1347     }
1348     else if (i_type == type_poi_motor_sport)
1349     {
1350     return 1;
1351     }
1352     else if (i_type == type_poi_tennis)
1353     {
1354     return 1;
1355     }
1356     else if (i_type == type_poi_playground)
1357     {
1358     return 1;
1359     }
1360     else if (i_type == type_poi_vending_machine)
1361     {
1362     return 1;
1363     }
1364     else if (i_type == type_poi_recycling)
1365     {
1366     return 1;
1367     }
1368     else if (i_type == type_poi_hairdresser)
1369     {
1370     return 1;
1371     }
1372     else if (i_type == type_poi_shop_fruit)
1373     {
1374     return 1;
1375     }
1376     else if (i_type == type_poi_shop_bicycle)
1377     {
1378     return 1;
1379     }
1380     else if (i_type == type_poi_shop_florist)
1381     {
1382     return 1;
1383     }
1384     else if (i_type == type_poi_shop_optician)
1385     {
1386     return 1;
1387     }
1388     else if (i_type == type_poi_shop_beverages)
1389     {
1390     return 1;
1391     }
1392     else if (i_type == type_poi_nightclub)
1393     {
1394     return 1;
1395     }
1396     else if (i_type == type_poi_shop_shoes)
1397     {
1398     return 1;
1399     }
1400     else if (i_type == type_poi_tree)
1401     {
1402     return 1;
1403     }
1404     else if (i_type == type_poi_shop_furniture)
1405     {
1406     return 1;
1407     }
1408     else if (i_type == type_poi_shop_parfum)
1409     {
1410     return 1;
1411     }
1412     else if (i_type == type_poi_shop_drugstore)
1413     {
1414     return 1;
1415     }
1416     else if (i_type == type_poi_shop_photo)
1417     {
1418     return 1;
1419     }
1420     else if (i_type == type_poi_atm)
1421     {
1422     return 1;
1423     }
1424     else if (i_type == type_poi_custom1)
1425     {
1426     return 1;
1427     }
1428     else if (i_type == type_poi_custom2)
1429     {
1430     return 1;
1431     }
1432     else if (i_type == type_poi_custom3)
1433     {
1434     return 1;
1435     }
1436     else if (i_type == type_poi_custom4)
1437     {
1438     return 1;
1439     }
1440     else if (i_type == type_poi_custom5)
1441     {
1442     return 1;
1443     }
1444     else if (i_type == type_poi_custom6)
1445     {
1446     return 1;
1447     }
1448     else if (i_type == type_poi_custom7)
1449     {
1450     return 1;
1451     }
1452     else if (i_type == type_poi_custom8)
1453     {
1454     return 1;
1455     }
1456     else if (i_type == type_poi_custom9)
1457     {
1458     return 1;
1459     }
1460     else if (i_type == type_poi_customa)
1461     {
1462     return 1;
1463     }
1464     else if (i_type == type_poi_customb)
1465     {
1466     return 1;
1467     }
1468     else if (i_type == type_poi_customc)
1469     {
1470     return 1;
1471     }
1472     else if (i_type == type_poi_customd)
1473     {
1474     return 1;
1475     }
1476     else if (i_type == type_poi_custome)
1477     {
1478     return 1;
1479     }
1480     else if (i_type == type_poi_customf)
1481     {
1482     return 1;
1483     }
1484     else
1485     {
1486     return 0;
1487     }
1488    
1489     return 0;
1490     }
1491    
1492    
1493 zoff99 27 enum item_type item_from_name(const char *name)
1494 zoff99 2 {
1495     int i;
1496    
1497 zoff99 27 for (i = 0; i < sizeof(item_names) / sizeof(struct item_name); i++)
1498     {
1499     if (!strcmp(item_names[i].name, name))
1500 zoff99 2 return item_names[i].item;
1501     }
1502     return type_none;
1503     }
1504    
1505     char *
1506     item_to_name(enum item_type item)
1507     {
1508     int i;
1509    
1510 zoff99 27 for (i = 0; i < sizeof(item_names) / sizeof(struct item_name); i++)
1511     {
1512 zoff99 2 if (item_names[i].item == item)
1513 zoff99 50 {
1514 zoff99 2 return item_names[i].name;
1515 zoff99 50 }
1516 zoff99 2 }
1517 zoff99 50
1518 zoff99 27 return NULL;
1519 zoff99 2 }
1520    
1521 zoff99 27 struct item_hash
1522     {
1523 zoff99 2 GHashTable *h;
1524     };
1525    
1526 zoff99 27 static guint item_hash_hash(gconstpointer key)
1527 zoff99 2 {
1528 zoff99 27 const struct item *itm = key;
1529     gconstpointer hashkey = (gconstpointer) GINT_TO_POINTER(itm->id_hi ^ itm->id_lo ^ (GPOINTER_TO_INT(itm->map)));
1530 zoff99 2 return g_direct_hash(hashkey);
1531     }
1532    
1533 zoff99 27 static gboolean item_hash_equal(gconstpointer a, gconstpointer b)
1534 zoff99 2 {
1535 zoff99 27 const struct item *itm_a = a;
1536     const struct item *itm_b = b;
1537 zoff99 40
1538 zoff99 2 if (item_is_equal(*itm_a, *itm_b))
1539 zoff99 40 {
1540 zoff99 2 return TRUE;
1541 zoff99 40 }
1542    
1543 zoff99 2 return FALSE;
1544     }
1545    
1546 zoff99 27 unsigned int item_id_hash(const void *key)
1547 zoff99 2 {
1548 zoff99 27 const struct item_id *id = key;
1549     return id->id_hi ^ id->id_lo;
1550 zoff99 2 }
1551    
1552 zoff99 27 int item_id_equal(const void *a, const void *b)
1553 zoff99 2 {
1554 zoff99 27 const struct item_id *id_a = a;
1555     const struct item_id *id_b = b;
1556 zoff99 2 return (id_a->id_hi == id_b->id_hi && id_a->id_lo == id_b->id_lo);
1557     }
1558    
1559     struct item_hash *
1560     item_hash_new(void)
1561     {
1562     struct item_hash *ret=g_new(struct item_hash, 1);
1563    
1564 zoff99 31 ret->h = g_hash_table_new_full(item_hash_hash, item_hash_equal, g_free_func, NULL);
1565 zoff99 2 return ret;
1566     }
1567    
1568 zoff99 27 void item_hash_insert(struct item_hash *h, struct item *item, void *val)
1569 zoff99 2 {
1570     struct item *hitem=g_new(struct item, 1);
1571 zoff99 27 *hitem = *item;
1572 zoff99 29 //dbg(2, "inserting (0x%x,0x%x) into %p\n", item->id_hi, item->id_lo, h->h);
1573 zoff99 2 g_hash_table_insert(h->h, hitem, val);
1574     }
1575    
1576 zoff99 27 int item_hash_remove(struct item_hash *h, struct item *item)
1577 zoff99 2 {
1578     int ret;
1579    
1580 zoff99 29 //dbg(2, "removing (0x%x,0x%x) from %p\n", item->id_hi, item->id_lo, h->h);
1581 zoff99 27 ret = g_hash_table_remove(h->h, item);
1582 zoff99 29 //dbg(2, "ret=%d\n", ret);
1583 zoff99 2
1584     return ret;
1585     }
1586    
1587     void *
1588     item_hash_lookup(struct item_hash *h, struct item *item)
1589     {
1590     return g_hash_table_lookup(h->h, item);
1591     }
1592    
1593 zoff99 27 void item_hash_destroy(struct item_hash *h)
1594 zoff99 2 {
1595     g_hash_table_destroy(h->h);
1596     g_free(h);
1597     }
1598    
1599 zoff99 27 int item_range_intersects_range(struct item_range *range1, struct item_range *range2)
1600 zoff99 2 {
1601     if (range1->max < range2->min)
1602     return 0;
1603     if (range1->min > range2->max)
1604     return 0;
1605     return 1;
1606     }
1607 zoff99 27 int item_range_contains_item(struct item_range *range, enum item_type type)
1608 zoff99 2 {
1609     if (type >= range->min && type <= range->max)
1610     return 1;
1611     return 0;
1612     }
1613    
1614 zoff99 27 void item_dump_attr_stdout(struct item *item, struct map *map)
1615 zoff99 2 {
1616     struct attr attr;
1617 zoff99 31 dbg(0, "type=%d:%s\n", item->type, item_to_name(item->type));
1618 zoff99 2 while (item_attr_get(item, attr_any, &attr))
1619     {
1620 zoff99 31 dbg(0, " %d:%s='%s'", attr.type, attr_to_name(attr.type), attr_to_text(&attr, map, 1));
1621 zoff99 2 // dbg(0," %s\n", attr_to_name(attr.type));
1622     }
1623     }
1624    
1625 zoff99 27 void item_dump_attr(struct item *item, struct map *map, FILE *out)
1626 zoff99 2 {
1627     struct attr attr;
1628 zoff99 27 fprintf(out, "type=%s", item_to_name(item->type));
1629     while (item_attr_get(item, attr_any, &attr))
1630 zoff99 31 {
1631 zoff99 27 fprintf(out, " %s='%s'", attr_to_name(attr.type), attr_to_text(&attr, map, 1));
1632 zoff99 31 }
1633 zoff99 2 }
1634    
1635 zoff99 41 void item_dump_coords(struct item *item, struct map *map)
1636     {
1637    
1638     int i, count, max = 16384;
1639     struct coord *ca = g_alloca(sizeof(struct coord) * max);
1640     struct coord_geo geo;
1641    
1642     count = item_coord_get(item, ca, item->type < type_line ? 1 : max);
1643     if (item->type < type_line)
1644     {
1645     dbg(0, "mg:0x%x 0x%x ", ca[0].x, ca[0].y);
1646    
1647     transform_to_geo(projection_mg, &(ca[0]), &geo);
1648     dbg(0, "http://maps.google.com/maps/api/staticmap?size=512x512&markers=color:red|label:AA|%4.6f,%4.6f\n", geo.lat, geo.lng);
1649    
1650     }
1651    
1652     item_dump_attr_stdout(item, map);
1653    
1654     dbg(0, "\n");
1655    
1656     if (item->type >= type_line)
1657     {
1658     for (i = 0; i < count; i++)
1659     {
1660     dbg(0, "mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
1661    
1662     transform_to_geo(projection_mg, &(ca[i]), &geo);
1663     dbg(0, "http://maps.google.com/maps/api/staticmap?size=512x512&markers=color:red|label:AA|%4.6f,%4.6f\n", geo.lat, geo.lng);
1664    
1665     }
1666     }
1667     }
1668    
1669    
1670 zoff99 27 void item_dump_filedesc(struct item *item, struct map *map, FILE *out)
1671 zoff99 2 {
1672    
1673 zoff99 27 int i, count, max = 16384;
1674     struct coord *ca = g_alloca(sizeof(struct coord) * max);
1675 zoff99 2
1676 zoff99 27 count = item_coord_get(item, ca, item->type < type_line ? 1 : max);
1677     if (item->type < type_line)
1678     fprintf(out, "mg:0x%x 0x%x ", ca[0].x, ca[0].y);
1679 zoff99 2 item_dump_attr(item, map, out);
1680 zoff99 27 fprintf(out, "\n");
1681 zoff99 2 if (item->type >= type_line)
1682 zoff99 27 for (i = 0; i < count; i++)
1683     fprintf(out, "mg:0x%x 0x%x\n", ca[i].x, ca[i].y);
1684 zoff99 2 }
1685 zoff99 41
1686    

   
Visit the ZANavi Wiki