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

Contents of /navit/navit/map.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28 - (hide annotations) (download)
Sun Jun 17 08:12:47 2012 UTC (11 years, 9 months ago) by zoff99
File MIME type: text/plain
File size: 21238 byte(s)
lots of new stuff and fixes
1 zoff99 2 /**
2     * Navit, a modular navigation system.
3     * Copyright (C) 2005-2008 Navit Team
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     /** @file
21     *
22     * @brief Contains code that makes navit able to load maps
23     *
24     * This file contains the code that makes navit able to load maps. Because
25     * navit is able to open maps in different formats, this code does not handle
26     * any map format itself. This is done by map plugins which register to this
27     * code by calling plugin_register_map_type().
28     *
29     * When opening a new map, the map plugin will return a pointer to a map_priv
30     * struct, which can be defined by the map plugin and contains whatever private
31     * data the map plugin needs to access the map. This pointer will also be used
32     * as a "handle" to access the map opened.
33     *
34     * A common task is to create a "map rect". A map rect is a rectangular part of
35     * the map, that one can for example retrieve items from. It is not possible to
36     * retrieve items directly from the complete map. Creating a map rect returns a
37     * pointer to a map_rect_priv, which contains private data for the map rect and
38     * will be used as "handle" for this map rect.
39     */
40    
41     #include <glib.h>
42     #include <string.h>
43     #include "debug.h"
44     #include "coord.h"
45     #include "projection.h"
46     #include "item.h"
47     #include "map.h"
48     #include "maptype.h"
49     #include "transform.h"
50     #include "plugin.h"
51     #include "callback.h"
52     #include "country.h"
53    
54     /**
55     * @brief Opens a new map
56     *
57     * This function opens a new map based on the attributes passed. This function
58     * takes the attribute "attr_type" to determine which type of map to open and passes
59     * all attributes to the map plugin's function that was specified in the
60     * plugin_register_new_map_type()-call.
61     *
62     * Note that every plugin should accept an attribute of type "attr_data" to be passed
63     * with the filename of the map to be opened as value.
64     *
65     * @param attrs Attributes specifying which map to open, see description
66     * @return The opened map or NULL on failure
67     */
68     struct map *
69     map_new(struct attr *parent, struct attr **attrs)
70     {
71 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
72     dbg(0,"+#+:enter\n");
73     #endif
74 zoff99 2 struct map *m;
75     struct map_priv *(*maptype_new)(struct map_methods *meth, struct attr **attrs, struct callback_list *cbl);
76 zoff99 28 struct attr *type = attr_search(attrs, NULL, attr_type);
77 zoff99 2
78 zoff99 28 if (!type)
79 zoff99 2 {
80 zoff99 28 dbg(0, "missing type\n");
81 zoff99 2 return NULL;
82     }
83     //dbg(0,"type='%s'\n", type->u.str);
84 zoff99 28 maptype_new = plugin_get_map_type(type->u.str);
85     if (!maptype_new)
86 zoff99 2 {
87 zoff99 28 dbg(0, "invalid type '%s'\n", type->u.str);
88 zoff99 2 return NULL;
89     }
90     //dbg(0,"MM 1");
91    
92     m=g_new0(struct map, 1);
93 zoff99 28 m->attrs = attr_list_dup(attrs);
94     m->attr_cbl = callback_list_new();
95 zoff99 2 //dbg(0,"MM 2");
96 zoff99 28 m->priv = maptype_new(&m->meth, attrs, m->attr_cbl);
97 zoff99 2 //dbg(0,"MM 3");
98 zoff99 28 if (!m->priv)
99 zoff99 2 {
100     m->refcount = 1;
101     //dbg(0,"MM 4");
102     map_destroy(m);
103     //dbg(0,"MM 5");
104 zoff99 28 m = NULL;
105 zoff99 2 }
106 zoff99 28 else
107     {
108 zoff99 2 m->refcount = 0;
109     }
110     //dbg(0,"MM 6");
111     return m;
112     }
113    
114 zoff99 28 void map_ref(struct map* m)
115 zoff99 2 {
116 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
117     dbg(0,"+#+:enter\n");
118     #endif
119 zoff99 2 m->refcount++;
120     }
121    
122     /**
123     * @brief Gets an attribute from a map
124     *
125     * @param this_ The map the attribute should be read from
126     * @param type The type of the attribute to be read
127     * @param attr Pointer to an attrib-structure where the attribute should be written to
128     * @param iter (NOT IMPLEMENTED) Used to iterate through all attributes of a type. Set this to NULL to get the first attribute, set this to an attr_iter to get the next attribute
129     * @return True if the attribute type was found, false if not
130     */
131 zoff99 28 int map_get_attr(struct map *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
132 zoff99 2 {
133 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
134     dbg(0,"+#+:enter\n");
135     #endif
136     int ret = 0;
137 zoff99 2 if (this_->meth.map_get_attr)
138 zoff99 28 ret = this_->meth.map_get_attr(this_->priv, type, attr);
139 zoff99 2 if (!ret)
140 zoff99 28 ret = attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
141 zoff99 2 return ret;
142     }
143    
144     /**
145     * @brief Sets an attribute of a map
146     *
147     * This sets an attribute of a map, overwriting an attribute of the same type if it
148     * already exists. This function also calls all the callbacks that are registred
149     * to be called when attributes change.
150     *
151     * @param this_ The map to set the attribute of
152     * @param attr The attribute to set
153     * @return True if the attr could be set, false otherwise
154     */
155 zoff99 28 int map_set_attr(struct map *this_, struct attr *attr)
156 zoff99 2 {
157 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
158     dbg(0,"+#+:enter\n");
159     #endif
160     this_->attrs = attr_generic_set_attr(this_->attrs, attr);
161 zoff99 2 if (this_->meth.map_set_attr)
162     this_->meth.map_set_attr(this_->priv, attr);
163     callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
164     return 1;
165     }
166    
167     /**
168     * @brief Registers a new callback for attribute-change
169     *
170     * This function registers a new callback function that should be called if the attributes
171     * of the map change.
172     *
173     * @param this_ The map to associate the callback with
174     * @param cb The callback to add
175     */
176 zoff99 28 void map_add_callback(struct map *this_, struct callback *cb)
177 zoff99 2 {
178 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
179     dbg(0,"+#+:enter\n");
180     #endif
181 zoff99 2 callback_list_add(this_->attr_cbl, cb);
182     }
183    
184     /**
185     * @brief Removes a callback from the list of attribute-change callbacks
186     *
187     * This function removes one callback from the list of callbacks functions that should be called
188     * when attributes of the map change.
189     *
190     * @param this_ The map to remove the callback from
191     * @param cb The callback to remove
192     */
193 zoff99 28 void map_remove_callback(struct map *this_, struct callback *cb)
194 zoff99 2 {
195 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
196     dbg(0,"+#+:enter\n");
197     #endif
198 zoff99 2 callback_list_remove(this_->attr_cbl, cb);
199     }
200    
201     /**
202     * @brief Checks if strings from a map have to be converted
203     *
204     * @param this_ Map to be checked for the need to convert strings
205     * @return True if strings from the map have to be converted, false otherwise
206     */
207 zoff99 28 int map_requires_conversion(struct map *this_)
208 zoff99 2 {
209 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
210     dbg(0,"+#+:enter\n");
211     #endif
212 zoff99 2 return (this_->meth.charset != NULL && strcmp(this_->meth.charset, "utf-8"));
213     }
214    
215     /**
216     * @brief Converts a string from a map
217     *
218     * @param this_ The map the string to be converted is from
219     * @param str The string to be converted
220     * @return The converted string. It has to be map_convert_free()d after use.
221     */
222     char *
223     map_convert_string(struct map *this_, char *str)
224     {
225 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
226     dbg(0,"+#+:enter\n");
227     #endif
228     return g_convert(str, -1, "utf-8", this_->meth.charset, NULL, NULL, NULL);
229 zoff99 2 }
230    
231     /**
232     * @brief Frees the memory allocated for a converted string
233     *
234     * @param str The string to be freed
235     */
236 zoff99 28 void map_convert_free(char *str)
237 zoff99 2 {
238 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
239     dbg(0,"+#+:enter\n");
240     #endif
241 zoff99 2 g_free(str);
242     }
243    
244     /**
245     * @brief Returns the projection of a map
246     *
247     * @param this_ The map to return the projection of
248     * @return The projection of the map
249     */
250 zoff99 28 enum projection map_projection(struct map *this_)
251 zoff99 2 {
252 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
253     dbg(0,"+#+:enter\n");
254     #endif
255 zoff99 2 return this_->meth.pro;
256     }
257    
258     /**
259     * @brief Sets the projection of a map
260     *
261     * @param this_ The map to set the projection of
262     * @param pro The projection to be set
263     */
264 zoff99 28 void map_set_projection(struct map *this_, enum projection pro)
265 zoff99 2 {
266 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
267     dbg(0,"+#+:enter\n");
268     #endif
269     this_->meth.pro = pro;
270 zoff99 2 }
271    
272 zoff99 28 void map_destroy_do(struct map *m)
273 zoff99 2 {
274 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
275     dbg(0,"+#+:enter\n");
276     #endif
277 zoff99 2 if (m->priv)
278     m->meth.map_destroy(m->priv);
279     attr_list_free(m->attrs);
280     callback_list_destroy(m->attr_cbl);
281     g_free(m);
282     }
283    
284     /**
285     * @brief Destroys an opened map
286     *
287     * @param m The map to be destroyed
288     */
289 zoff99 28 void map_destroy(struct map *m)
290 zoff99 2 {
291 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
292     dbg(0,"+#+:enter\n");
293     #endif
294 zoff99 2 if (!m)
295     return;
296    
297 zoff99 28 if (0 < m->refcount)
298     {
299 zoff99 2 m->refcount--;
300     }
301 zoff99 28 if (0 == m->refcount)
302     {
303 zoff99 2 map_destroy_do(m);
304     }
305     }
306    
307     /**
308     * @brief Creates a new map rect
309     *
310     * This creates a new map rect, which can be used to retrieve items from a map. If
311     * sel is a linked-list of selections, all of them will be used. If you pass NULL as
312     * sel, this means "get me the whole map".
313     *
314     * @param m The map to build the rect on
315     * @param sel Map selection to choose the rectangle - may be NULL, see description
316     * @return A new map rect
317     */
318     struct map_rect *
319     map_rect_new(struct map *m, struct map_selection *sel)
320     {
321 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
322     dbg(0,"+#+:enter\n");
323     #endif
324 zoff99 2 struct map_rect *mr;
325    
326     #if 0
327     printf("map_rect_new 0x%x,0x%x-0x%x,0x%x\n", r->lu.x, r->lu.y, r->rl.x, r->rl.y);
328     #endif
329     //if (sel!=NULL)
330     //{
331     // dbg(0,"map_rect_new 0x%x,0x%x-0x%x,0x%x\n", sel->u.c_rect.lu.x, sel->u.c_rect.lu.y, sel->u.c_rect.rl.x, sel->u.c_rect.rl.y);
332     //}
333     mr=g_new0(struct map_rect, 1);
334 zoff99 28 mr->m = m;
335     mr->priv = m->meth.map_rect_new(m->priv, sel);
336     if (!mr->priv)
337     {
338 zoff99 2 g_free(mr);
339 zoff99 28 mr = NULL;
340 zoff99 2 }
341    
342     return mr;
343     }
344    
345     /**
346     * @brief Gets the next item from a map rect
347     *
348     * Returns an item from a map rect and advances the "item pointer" one step further,
349     * so that at the next call the next item is returned. Returns NULL if there are no more items.
350     *
351     * @param mr The map rect to return an item from
352     * @return An item from the map rect
353     */
354     struct item *
355     map_rect_get_item(struct map_rect *mr)
356     {
357 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
358     dbg(0,"+#+:enter\n");
359     #endif
360 zoff99 2 struct item *ret;
361     dbg_assert(mr != NULL);
362     dbg_assert(mr->m != NULL);
363     dbg_assert(mr->m->meth.map_rect_get_item != NULL);
364 zoff99 28 ret = mr->m->meth.map_rect_get_item(mr->priv);
365 zoff99 2 if (ret)
366 zoff99 28 ret->map = mr->m;
367 zoff99 2 return ret;
368     }
369    
370     /**
371     * @brief Returns the item specified by the ID
372     *
373     * @param mr The map rect to search for the item
374     * @param id_hi High part of the ID to be found
375     * @param id_lo Low part of the ID to be found
376     * @return The item with the specified ID or NULL if not found
377     */
378     struct item *
379     map_rect_get_item_byid(struct map_rect *mr, int id_hi, int id_lo)
380     {
381 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
382     dbg(0,"+#+:enter\n");
383     #endif
384     struct item *ret = NULL;
385 zoff99 2 dbg_assert(mr != NULL);
386     dbg_assert(mr->m != NULL);
387     if (mr->m->meth.map_rect_get_item_byid)
388 zoff99 28 ret = mr->m->meth.map_rect_get_item_byid(mr->priv, id_hi, id_lo);
389 zoff99 2 if (ret)
390 zoff99 28 ret->map = mr->m;
391 zoff99 2 return ret;
392     }
393    
394     /**
395     * @brief Destroys a map rect
396     *
397     * @param mr The map rect to be destroyed
398     */
399 zoff99 28 void map_rect_destroy(struct map_rect *mr)
400 zoff99 2 {
401 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
402     dbg(0,"+#+:enter\n");
403     #endif
404     if (mr)
405     {
406 zoff99 2 mr->m->meth.map_rect_destroy(mr->priv);
407     g_free(mr);
408     }
409     }
410    
411     /**
412     * @brief Holds information about a search on a map
413     *
414     * This structure holds information about a search performed on a map. This can be
415     * used as "handle" to retrieve items from a search.
416     */
417 zoff99 28 struct map_search
418     {
419     struct map *m;
420     struct attr search_attr;
421     void *priv;
422 zoff99 2 };
423    
424     /**
425     * @brief Starts a search on a map
426     *
427     * This function starts a search on a map. What attributes one can search for depends on the
428     * map plugin.
429     *
430     * The OSM/binfile plugin currently supports: attr_town_name, attr_street_name
431 zoff99 28 * The MG plugin currently supports: attr_town_postal, attr_town_name, attr_street_name
432 zoff99 2 *
433     * If you enable partial matches bear in mind that the search matches only the begin of the
434     * strings - a search for a street named "street" would match to "streetfoo", but not to
435     * "somestreet". Search is case insensitive.
436     *
437     * The item passed to this function specifies a "superior item" to "search within" - e.g. a town
438     * in which we want to search for a street, or a country in which to search for a town.
439     *
440     * Please also note that the search for countries is not handled by map plugins but by navit internally -
441     * have a look into country.c for details. Because of that every map plugin has to accept a country item
442     * to be passed as "superior item".
443     *
444     * Note: If you change something here, please make sure to also update the documentation of mapset_search_new()
445     * in mapset.c!
446     *
447     * @param m The map that should be searched
448     * @param item Specifies a superior item to "search within" (see description)
449     * @param search_attr Attribute specifying what to search for. See description.
450     * @param partial Set this to true to also have partial matches. See description.
451     * @return A new map search struct for this search
452     */
453     struct map_search *
454     map_search_new(struct map *m, struct item *item, struct attr *search_attr, int partial)
455     {
456 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
457     dbg(0,"+#+:enter\n");
458     #endif
459 zoff99 2 struct map_search *this_;
460 zoff99 28 dbg(1, "enter(%p,%p,%p,%d)\n", m, item, search_attr, partial);
461     dbg(1, "0x%x 0x%x 0x%x\n", attr_country_all, search_attr->type, attr_country_name);
462 zoff99 2 this_=g_new0(struct map_search,1);
463 zoff99 28 this_->m = m;
464     this_->search_attr = *search_attr;
465 zoff99 2 if ((search_attr->type >= attr_country_all && search_attr->type <= attr_country_name) || search_attr->type == attr_country_id)
466 zoff99 28 {
467     this_->priv = country_search_new(&this_->search_attr, partial);
468     }
469     else
470     {
471     if (m->meth.map_search_new)
472     {
473 zoff99 2 if (m->meth.charset)
474 zoff99 28 {
475     this_->search_attr.u.str = g_convert(this_->search_attr.u.str, -1, m->meth.charset, "utf-8", NULL, NULL, NULL);
476     }
477     this_->priv = m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
478     if (!this_->priv)
479     {
480 zoff99 2 g_free(this_);
481 zoff99 28 this_ = NULL;
482 zoff99 2 }
483 zoff99 28 }
484     else
485     {
486 zoff99 2 g_free(this_);
487 zoff99 28 this_ = NULL;
488 zoff99 2 }
489     }
490     return this_;
491     }
492    
493     /**
494     * @brief Returns an item from a map search
495     *
496     * This returns an item of the result of a search on a map and advances the "item pointer" one step,
497     * so that at the next call the next item will be returned. If there are no more items in the result
498     * NULL is returned.
499     *
500     * @param this_ Map search struct of the search
501     * @return One item of the result
502     */
503     struct item *
504     map_search_get_item(struct map_search *this_)
505     {
506 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
507     dbg(0,"+#+:enter\n");
508     #endif
509 zoff99 2 struct item *ret;
510    
511 zoff99 28 if (!this_)
512 zoff99 2 return NULL;
513     if ((this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name) || this_->search_attr.type == attr_country_id)
514     return country_search_get_item(this_->priv);
515 zoff99 28 ret = this_->m->meth.map_search_get_item(this_->priv);
516 zoff99 2 if (ret)
517 zoff99 28 ret->map = this_->m;
518 zoff99 2 return ret;
519     }
520    
521     /**
522     * @brief Destroys a map search struct
523     *
524     * @param this_ The map search struct to be destroyed
525     */
526 zoff99 28 void map_search_destroy(struct map_search *this_)
527 zoff99 2 {
528 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
529     dbg(0,"+#+:enter\n");
530     #endif
531     if (!this_)
532 zoff99 2 return;
533     if (this_->search_attr.type >= attr_country_all && this_->search_attr.type <= attr_country_name)
534     country_search_destroy(this_->priv);
535 zoff99 28 else
536     {
537 zoff99 2 if (this_->m->meth.charset)
538 zoff99 28 g_free(this_->search_attr.u.str);
539 zoff99 2 this_->m->meth.map_search_destroy(this_->priv);
540     }
541     g_free(this_);
542     }
543    
544     /**
545     * @brief Creates a new rectangular map selection
546     *
547     * @param center Coordinates of the center of the new rectangle
548     * @param distance Distance of the rectangle's borders from the center
549     * @param order Desired order of the new selection
550     * @return The new map selection
551     */
552     struct map_selection *
553     map_selection_rect_new(struct pcoord *center, int distance, int order)
554     {
555 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
556     dbg(0,"+#+:enter\n");
557     #endif
558 zoff99 2 struct map_selection *ret=g_new0(struct map_selection, 1);
559 zoff99 28 ret->order = order;
560     ret->range = item_range_all;
561     ret->u.c_rect.lu.x = center->x - distance;
562     ret->u.c_rect.lu.y = center->y + distance;
563     ret->u.c_rect.rl.x = center->x + distance;
564     ret->u.c_rect.rl.y = center->y - distance;
565 zoff99 2 return ret;
566     }
567    
568     /**
569     * @brief Duplicates a map selection, transforming coordinates
570     *
571     * This duplicates a map selection and at the same time transforms the internal
572     * coordinates of the selection from one projection to another.
573     *
574     * @param sel The map selection to be duplicated
575     * @param from The projection used for the selection at the moment
576     * @param to The projection that should be used for the duplicated selection
577     * @return A duplicated, transformed map selection
578     */
579     struct map_selection *
580     map_selection_dup_pro(struct map_selection *sel, enum projection from, enum projection to)
581     {
582 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
583     dbg(0,"+#+:enter\n");
584     #endif
585     struct map_selection *next, **last;
586     struct map_selection *ret = NULL;
587     last = &ret;
588     while (sel)
589     {
590 zoff99 2 next = g_new(struct map_selection, 1);
591 zoff99 28 *next = *sel;
592     if (from != projection_none || to != projection_none)
593     {
594 zoff99 2 transform_from_to(&sel->u.c_rect.lu, from, &next->u.c_rect.lu, to);
595     transform_from_to(&sel->u.c_rect.rl, from, &next->u.c_rect.rl, to);
596     }
597 zoff99 28 *last = next;
598     last = &next->next;
599 zoff99 2 sel = sel->next;
600     }
601     return ret;
602     }
603    
604     /**
605     * @brief Duplicates a map selection
606     *
607     * @param sel The map selection to duplicate
608     * @return The duplicated map selection
609     */
610     struct map_selection *
611     map_selection_dup(struct map_selection *sel)
612     {
613 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
614     dbg(0,"+#+:enter\n");
615     #endif
616 zoff99 2 return map_selection_dup_pro(sel, projection_none, projection_none);
617     }
618    
619     /**
620     * @brief Destroys a map selection
621     *
622     * @param sel The map selection to be destroyed
623     */
624 zoff99 28 void map_selection_destroy(struct map_selection *sel)
625 zoff99 2 {
626 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
627     dbg(0,"+#+:enter\n");
628     #endif
629 zoff99 2 struct map_selection *next;
630 zoff99 28 while (sel)
631     {
632 zoff99 2 next = sel->next;
633     g_free(sel);
634     sel = next;
635     }
636     }
637    
638     /**
639     * @brief Checks if a selection contains a rectangle containing an item
640     *
641     * This function checks if a selection contains a rectangle which exactly contains
642     * an item. The rectangle is automatically built around the given item.
643     *
644     * @param sel The selection to be checked
645     * @param item The item that the rectangle should be built around
646     * @return True if the rectangle is within the selection, false otherwise
647     */
648 zoff99 28 int map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
649 zoff99 2 {
650 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
651     dbg(0,"+#+:enter\n");
652     #endif
653 zoff99 2 struct coord c;
654     struct coord_rect r;
655 zoff99 28 int count = 0;
656     while (item_coord_get(item, &c, 1))
657     {
658     if (!count)
659     {
660     r.lu = c;
661     r.rl = c;
662     }
663     else
664 zoff99 2 coord_rect_extend(&r, &c);
665     count++;
666     }
667 zoff99 28 if (!count)
668 zoff99 2 return 0;
669     return map_selection_contains_rect(sel, &r);
670    
671     }
672    
673     /**
674     * @brief Checks if a selection contains a item range
675     *
676     * This function checks if a selection contains at least one of the items in range
677     *
678     * @param sel The selection to be checked
679     * @param follow Whether the next pointer of the selection should be followed
680     * @param ranges The item ranges to be checked
681     * @count the number of elements in ranges
682     * @return True if there is a match, false otherwise
683     */
684    
685 zoff99 28 int map_selection_contains_item_range(struct map_selection *sel, int follow, struct item_range *range, int count)
686 zoff99 2 {
687 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
688     dbg(0,"+#+:enter\n");
689     #endif
690 zoff99 2 int i;
691 zoff99 28 if (!sel)
692 zoff99 2 return 1;
693 zoff99 28 while (sel)
694     {
695     for (i = 0; i < count; i++)
696     {
697 zoff99 2 if (item_range_intersects_range(&sel->range, &range[i]))
698     return 1;
699     }
700 zoff99 28 if (!follow)
701 zoff99 2 break;
702 zoff99 28 sel = sel->next;
703 zoff99 2 }
704     return 0;
705     }
706     /**
707     * @brief Checks if a selection contains a item
708     *
709     * This function checks if a selection contains a item type
710     *
711     * @param sel The selection to be checked
712     * @param follow Whether the next pointer of the selection should be followed
713     * @param item The item type to be checked
714     * @return True if there is a match, false otherwise
715     */
716    
717 zoff99 28 int map_selection_contains_item(struct map_selection *sel, int follow, enum item_type type)
718 zoff99 2 {
719 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
720     dbg(0,"+#+:enter\n");
721     #endif
722     if (!sel)
723 zoff99 2 return 1;
724 zoff99 28 while (sel)
725     {
726 zoff99 2 if (item_range_contains_item(&sel->range, type))
727     return 1;
728 zoff99 28 if (!follow)
729 zoff99 2 break;
730 zoff99 28 sel = sel->next;
731 zoff99 2 }
732     return 0;
733     }
734    
735     /**
736     * @brief Checks if a pointer points to the private data of a map
737     *
738     * @param map The map whose private data should be checked.
739     * @param priv The private data that should be checked.
740     * @return True if priv is the private data of map
741     */
742 zoff99 28 int map_priv_is(struct map *map, struct map_priv *priv)
743 zoff99 2 {
744 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
745     dbg(0,"+#+:enter\n");
746     #endif
747 zoff99 2 return (map->priv == priv);
748     }
749    
750 zoff99 28 void map_dump_filedesc(struct map *map, FILE *out)
751 zoff99 2 {
752 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
753     dbg(0,"+#+:enter\n");
754     #endif
755     struct map_rect *mr = map_rect_new(map, NULL);
756 zoff99 2 struct item *item;
757    
758 zoff99 28 while ((item = map_rect_get_item(mr)))
759 zoff99 2 item_dump_filedesc(item, map, out);
760     map_rect_destroy(mr);
761     }
762    
763 zoff99 28 void map_dump_file(struct map *map, const char *file)
764 zoff99 2 {
765 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
766     dbg(0,"+#+:enter\n");
767     #endif
768 zoff99 2 FILE *f;
769 zoff99 28 f = fopen(file, "w");
770     if (f)
771     {
772 zoff99 2 map_dump_filedesc(map, f);
773     fclose(f);
774 zoff99 28 }
775     else
776     dbg(0, "failed to open file '%s'\n", file);
777 zoff99 2 }
778    
779 zoff99 28 void map_dump(struct map *map)
780 zoff99 2 {
781 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
782     dbg(0,"+#+:enter\n");
783     #endif
784 zoff99 2 map_dump_filedesc(map, stdout);
785     }
786    
787 zoff99 28 struct item *
788 zoff99 2 map_rect_create_item(struct map_rect *mr, enum item_type type_)
789     {
790 zoff99 28 #ifdef NAVIT_FUNC_CALLS_DEBUG_PRINT
791     dbg(0,"+#+:enter\n");
792     #endif
793     if (mr && mr->priv && mr->m)
794     {
795     return mr->m->meth.map_rect_create_item(mr->priv, type_);
796 zoff99 2 }
797 zoff99 28 else
798     {
799 zoff99 2 return NULL;
800     }
801     }
802    

   
Visit the ZANavi Wiki