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

Contents of /navit/navit/map.c

Parent Directory Parent Directory | Revision Log Revision Log


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

   
Visit the ZANavi Wiki