2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
27 #include "navigation.h"
31 #include "transform.h"
33 #include "projection.h"
38 #include "navit_nls.h"
58 struct item_hash *hash;
59 struct navigation_itm *first;
60 struct navigation_itm *last;
61 struct navigation_command *cmd_first;
62 struct navigation_command *cmd_last;
63 struct callback_list *callback_speech;
64 struct callback_list *callback;
67 struct item item_last;
69 int turn_around_limit;
72 int announce[route_item_last-route_item_first+1][3];
76 struct navigation_command {
77 struct navigation_itm *itm;
78 struct navigation_command *next;
79 struct navigation_command *prev;
86 * @brief Calculates the delta between two angles
87 * @param angle1 The first angle
88 * @param angle2 The second angle
89 * @return The difference between the angles: -179..-1=angle2 is left of angle1,0=same,1..179=angle2 is right of angle1,180=angle1 is opposite of angle2
93 angle_delta(int angle1, int angle2)
95 int delta=angle2-angle1;
104 navigation_new(struct attr *parent, struct attr **attrs)
107 struct navigation *ret=g_new0(struct navigation, 1);
108 ret->hash=item_hash_new();
109 ret->callback=callback_list_new();
110 ret->callback_speech=callback_list_new();
112 ret->distance_last=-2;
113 ret->distance_turn=50;
114 ret->turn_around_limit=3;
115 ret->navit=parent->u.navit;
117 for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
118 for (i = 0 ; i < 3 ; i++) {
119 ret->announce[j][i]=-1;
127 navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
130 if (type < route_item_first || type > route_item_last) {
131 dbg(0,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
134 for (i = 0 ; i < 3 ; i++)
135 this_->announce[type-route_item_first][i]=level[i];
140 navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
144 if (type < route_item_first || type > route_item_last)
146 for (i = 0 ; i < 3 ; i++) {
147 if (dist <= this_->announce[type-route_item_first][i])
154 * @brief Holds a way that one could possibly drive from a navigation item
156 struct navigation_way {
157 struct navigation_way *next; /**< Pointer to a linked-list of all navigation_ways from this navigation item */
158 short dir; /**< The direction -1 or 1 of the way */
159 short angle2; /**< The angle one has to steer to drive from the old item to this street */
160 int flags; /**< The flags of the way */
161 struct item item; /**< The item of the way */
166 struct navigation_itm {
173 struct coord start,end;
178 int told; /**< Indicates if this item's announcement has been told earlier and should not be told again*/
179 int streetname_told; /**< Indicates if this item's streetname has been told in speech navigation*/
182 struct navigation_itm *next;
183 struct navigation_itm *prev;
184 struct navigation_way *ways; /**< Pointer to all ways one could drive from here */
189 road_angle(struct coord *c1, struct coord *c2, int dir)
191 int ret=transform_get_angle_delta(c1, c2, dir);
192 dbg(1, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d\n", c1->x, c1->y, c2->x, c2->y, ret);
197 *get_count_str(int n)
201 return _("zeroth"); // Not shure if this exists, neither if it will ever be needed
220 round_distance(int dist)
243 dist=(dist+500)/1000;
246 dist=(dist+5000)/10000;
251 get_distance(int dist, enum attr_type type, int is_length)
253 if (type == attr_navigation_long) {
255 return g_strdup_printf(_("%d m"), dist);
257 return g_strdup_printf(_("in %d m"), dist);
261 return g_strdup_printf(_("%d meters"), dist);
263 return g_strdup_printf(_("in %d meters"), dist);
266 int rem=(dist/100)%10;
269 return g_strdup_printf(_("%d.%d kilometer"), dist/1000, rem);
271 return g_strdup_printf(_("in %d.%d kilometers"), dist/1000, rem);
275 return g_strdup_printf(ngettext("one kilometer","%d kilometers", dist/1000), dist/1000);
277 return g_strdup_printf(ngettext("in one kilometer","in %d kilometers", dist/1000), dist/1000);
282 * @brief This calculates the angle with which an item starts or ends
284 * This function can be used to get the angle an item (from a route graph map)
285 * starts or ends with. Note that the angle will point towards the inner of
288 * This is meant to be used with items from a route graph map
289 * With other items this will probably not be optimal...
291 * @param w The way which should be calculated
294 calculate_angle(struct navigation_way *w)
296 struct coord cbuf[2];
297 struct item *ritem; // the "real" item
303 mr = map_rect_new(w->item.map, NULL);
307 ritem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
309 dbg(1,"Item from segment not found on map!\n");
310 map_rect_destroy(mr);
314 if (ritem->type < type_line || ritem->type >= type_area) {
315 map_rect_destroy(mr);
318 if (item_attr_get(ritem, attr_flags, &attr))
322 if (item_attr_get(ritem, attr_street_name, &attr))
323 w->name1=map_convert_string(ritem->map,attr.u.str);
326 if (item_attr_get(ritem, attr_street_name_systematic, &attr))
327 w->name2=map_convert_string(ritem->map,attr.u.str);
332 if (item_coord_get(ritem, cbuf, 2) != 2) {
333 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
334 map_rect_destroy(mr);
338 while (item_coord_get(ritem, &c, 1)) {
344 if (item_coord_get(ritem, cbuf, 2) != 2) {
345 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
346 map_rect_destroy(mr);
354 map_rect_destroy(mr);
356 w->angle2=road_angle(&cbuf[1],&cbuf[0],0);
360 * @brief Returns the time (in seconds) one will drive between two navigation items
362 * This function returns the time needed to drive between two items, including both of them,
365 * @param from The first item
366 * @param to The last item
367 * @return The travel time in seconds, or -1 on error
370 navigation_time(struct navigation_itm *from, struct navigation_itm *to)
372 struct navigation_itm *cur;
394 * @brief Clears the ways one can drive from itm
396 * @param itm The item that should have its ways cleared
399 navigation_itm_ways_clear(struct navigation_itm *itm)
401 struct navigation_way *c,*n;
406 map_convert_free(c->name1);
407 map_convert_free(c->name2);
416 * @brief Updates the ways one can drive from itm
418 * This updates the list of possible ways to drive to from itm. The item "itm" is on
419 * and the next navigation item are excluded.
421 * @param itm The item that should be updated
422 * @param graph_map The route graph's map that these items are on
425 navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map)
427 struct map_selection coord_sel;
428 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
429 struct item *i,*sitem;
430 struct attr sitem_attr,direction_attr;
431 struct navigation_way *w,*l;
433 navigation_itm_ways_clear(itm);
435 // These values cause the code in route.c to get us only the route graph point and connected segments
436 coord_sel.next = NULL;
437 coord_sel.u.c_rect.lu = itm->start;
438 coord_sel.u.c_rect.rl = itm->start;
439 // the selection's order is ignored
441 g_rect = map_rect_new(graph_map, &coord_sel);
443 i = map_rect_get_item(g_rect);
444 if (!i || i->type != type_rg_point) { // probably offroad?
451 i = map_rect_get_item(g_rect);
457 if (i->type != type_rg_segment) {
461 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
462 dbg(1, "Got no street item for route graph item in entering_straight()\n");
466 if (!item_attr_get(i,attr_direction,&direction_attr)) {
470 sitem = sitem_attr.u.item;
471 if (item_is_equal(itm->item,*sitem) || ((itm->prev) && item_is_equal(itm->prev->item,*sitem))) {
476 w = g_new(struct navigation_way, 1);
477 w->dir = direction_attr.u.num;
483 map_rect_destroy(g_rect);
489 navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end)
491 struct navigation_itm *itm;
492 struct navigation_command *cmd;
493 dbg(2,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p\n", this_, this_->first, this_->cmd_first, end);
494 if (this_->cmd_first)
495 dbg(2,"this_->cmd_first->itm=%p\n", this_->cmd_first->itm);
496 while (this_->first && this_->first != end) {
498 dbg(3,"destroying %p\n", itm);
499 item_hash_remove(this_->hash, &itm->item);
500 this_->first=itm->next;
502 this_->first->prev=NULL;
503 if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
504 cmd=this_->cmd_first;
505 this_->cmd_first=cmd->next;
507 cmd->next->prev = NULL;
511 map_convert_free(itm->name1);
512 map_convert_free(itm->name2);
513 navigation_itm_ways_clear(itm);
518 if (! this_->first && end)
519 dbg(0,"end wrong\n");
520 dbg(2,"ret this_->first=%p this_->cmd_first=%p\n",this_->first, this_->cmd_first);
524 navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
526 struct attr length, time;
528 if (! item_attr_get(ritem, attr_length, &length)) {
529 dbg(0,"no length\n");
532 if (! item_attr_get(ritem, attr_time, &time)) {
537 dbg(1,"length=%d time=%d\n", length.u.num, time.u.num);
538 itm->length=length.u.num;
539 itm->time=time.u.num;
543 * @brief This check if an item is part of a roundabout
545 * @param itm The item to be checked
546 * @return True if the item is part of a roundabout
549 check_roundabout(struct navigation_itm *itm, struct map *graph_map)
551 struct map_selection coord_sel;
552 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
553 struct item *i,*sitem;
554 struct attr sitem_attr,flags_attr;
556 // These values cause the code in route.c to get us only the route graph point and connected segments
557 coord_sel.next = NULL;
558 coord_sel.u.c_rect.lu = itm->start;
559 coord_sel.u.c_rect.rl = itm->start;
560 // the selection's order is ignored
562 g_rect = map_rect_new(graph_map, &coord_sel);
564 i = map_rect_get_item(g_rect);
565 if (!i || i->type != type_rg_point) { // probably offroad?
570 i = map_rect_get_item(g_rect);
576 if (i->type != type_rg_segment) {
580 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
584 sitem = sitem_attr.u.item;
585 if (item_is_equal(itm->item,*sitem)) {
586 if (item_attr_get(i,attr_flags,&flags_attr) && (flags_attr.u.num & AF_ROUNDABOUT)) {
587 map_rect_destroy(g_rect);
593 map_rect_destroy(g_rect);
597 static struct navigation_itm *
598 navigation_itm_new(struct navigation *this_, struct item *ritem)
600 struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
603 struct map *graph_map = NULL;
604 struct attr street_item,direction,route_attr;
610 ret->streetname_told=0;
611 if (! item_attr_get(ritem, attr_street_item, &street_item)) {
612 dbg(0,"no street item\n");
615 if (item_attr_get(ritem, attr_direction, &direction))
616 ret->direction=direction.u.num;
620 sitem=street_item.u.item;
622 item_hash_insert(this_->hash, sitem, ret);
623 mr=map_rect_new(sitem->map, NULL);
624 sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
625 if (item_attr_get(sitem, attr_street_name, &attr))
626 ret->name1=map_convert_string(sitem->map,attr.u.str);
627 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
628 ret->name2=map_convert_string(sitem->map,attr.u.str);
629 navigation_itm_update(ret, ritem);
631 while (item_coord_get(ritem, &c[i], 1)) {
632 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
641 dbg(1,"count=%d\n", i);
644 ret->angle_start=road_angle(&c[0], &c[1], 0);
645 ret->angle_end=road_angle(&c[i-1], &c[i], 0);
650 item_attr_get(ritem, attr_route, &route_attr);
651 graph_map = route_get_graph_map(route_attr.u.route);
652 if (check_roundabout(ret, graph_map)) {
653 ret->flags |= AF_ROUNDABOUT;
656 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
657 map_rect_destroy(mr);
660 ret->start=ret->end=this_->last->end;
665 this_->last->next=ret;
666 ret->prev=this_->last;
668 navigation_itm_ways_update(ret,graph_map);
671 dbg(1,"ret=%p\n", ret);
677 * @brief Counts how many times a driver could turn right/left
679 * This function counts how many times the driver theoretically could
680 * turn right/left between two navigation items, not counting the final
683 * @param from The navigation item which should form the start
684 * @param to The navigation item which should form the end
685 * @param direction Set to < 0 to count turns to the left >= 0 for turns to the right
686 * @return The number of possibilities to turn or -1 on error
689 count_possible_turns(struct navigation_itm *from, struct navigation_itm *to, int direction)
692 struct navigation_itm *curr;
693 struct navigation_way *w;
697 while (curr && (curr != to)) {
702 if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
707 if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
717 if (!curr) { // from does not lead to to?
725 * @brief Calculates distance and time to the destination
727 * This function calculates the distance and the time to the destination of a
728 * navigation. If incr is set, this is only calculated for the first navigation
729 * item, which is a lot faster than re-calculation the whole destination, but works
730 * only if the rest of the navigation already has been calculated.
732 * @param this_ The navigation whose destination / time should be calculated
733 * @param incr Set this to true to only calculate the first item. See description.
736 calculate_dest_distance(struct navigation *this_, int incr)
738 int len=0, time=0, count=0;
739 struct navigation_itm *next,*itm=this_->last;
740 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
743 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
745 dbg(2, "old values: itm is null\n");
748 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
749 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
750 itm->dest_length=next->dest_length+itm->length;
751 itm->dest_count=next->dest_count+1;
752 itm->dest_time=next->dest_time+itm->time;
753 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
759 itm->dest_length=len;
761 itm->dest_count=count++;
764 dbg(1,"len %d time %d\n", len, time);
768 * @brief Checks if two navigation items are on the same street
770 * This function checks if two navigation items are on the same street. It returns
771 * true if either their name or their "systematic name" (e.g. "A6" or "B256") are the
774 * @param old The first item to be checked
775 * @param new The second item to be checked
776 * @return True if both old and new are on the same street
779 is_same_street2(char *old_name1, char *old_name2, char *new_name1, char *new_name2)
781 if (old_name1 && new_name1 && !strcmp(old_name1, new_name1)) {
782 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old_name2, new_name2, old_name1, new_name1);
785 if (old_name2 && new_name2 && !strcmp(old_name2, new_name2)) {
786 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old_name2, new_name2, old_name1, new_name1);
789 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old_name2, new_name2, old_name1, new_name1);
795 * @brief Checks if two navigation items are on the same street
797 * This function checks if two navigation items are on the same street. It returns
798 * true if the first part of their "systematic name" is equal. If the "systematic name" is
799 * for example "A352/E3" (a german highway which at the same time is part of the international
800 * E-road network), it would only search for "A352" in the second item's systematic name.
802 * @param old The first item to be checked
803 * @param new The second item to be checked
804 * @return True if the "systematic name" of both items matches. See description.
807 is_same_street_systematic(struct navigation_itm *old, struct navigation_itm *new)
809 int slashold,slashnew;
810 if (!old->name2 || !new->name2)
812 slashold=strcspn(old->name2, "/");
813 slashnew=strcspn(new->name2, "/");
814 if (slashold != slashnew || strncmp(old->name2, new->name2, slashold))
821 * @brief Check if there are multiple possibilities to drive from old
823 * This function checks, if there are multiple streets connected to the exit of "old".
824 * Sometimes it happens that an item on a map is just segmented, without any other streets
825 * being connected there, and it is not useful if navit creates a maneuver there.
827 * @param new The navigation item we're driving to
828 * @return True if there are multiple streets
831 maneuver_multiple_streets(struct navigation_itm *new)
842 * @brief Check if the new item is entered "straight"
844 * This function checks if the new item is entered "straight" from the old item, i.e. if there
845 * is no other street one could take from the old item on with less steering.
847 * @param new The navigation item we're driving to
848 * @param diff The absolute angle one needs to steer to drive to this item
849 * @return True if the new item is entered "straight"
852 maneuver_straight(struct navigation_itm *new, int diff)
855 struct navigation_way *w;
858 dbg(1,"diff=%d\n", diff);
860 curr_diff=abs(angle_delta(new->prev->angle_end, w->angle2));
861 dbg(1,"curr_diff=%d\n", curr_diff);
862 if (curr_diff < diff) {
871 static int maneuver_category(enum item_type type)
876 case type_street_1_city:
878 case type_street_2_city:
880 case type_street_3_city:
882 case type_street_4_city:
884 case type_highway_city:
886 case type_street_1_land:
888 case type_street_2_land:
890 case type_street_3_land:
892 case type_street_4_land:
894 case type_street_n_lanes:
896 case type_highway_land:
900 case type_roundabout:
912 is_way_allowed(struct navigation_way *way)
915 if (way->flags & AF_ONEWAYREV)
918 if (way->flags & AF_ONEWAY)
925 * @brief Checks if navit has to create a maneuver to drive from old to new
927 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
928 * from "old" to "new".
930 * @param old The old navigation item, where we're coming from
931 * @param new The new navigation item, where we're going to
932 * @param delta The angle the user has to steer to navigate from old to new
933 * @param reason A text string explaining how the return value resulted
934 * @return True if navit should guide the user, false otherwise
937 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta, char **reason)
941 struct navigation_way *w;
942 int cat,ncat,wcat,maxcat,left=-180,right=180,is_unambigous=0,is_same_street;
944 dbg(1,"enter %p %p %p\n",old, new, delta);
945 d=angle_delta(old->angle_end, new->angle_start);
947 /* No announcement necessary */
948 r="no: Only one possibility";
949 } else if (!new->ways->next && new->ways->item.type == type_ramp) {
950 /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
951 /* TODO: check for one way in wrong direction */
955 if ((old->flags & AF_ROUNDABOUT) && ! (new->flags & AF_ROUNDABOUT)) {
956 r="yes: leaving roundabout";
958 } else if (!(old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
959 r="no: entering roundabout";
960 else if ((old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
961 r="no: staying in roundabout";
963 if (!r && abs(d) > 75) {
964 /* always make an announcement if you have to make a sharp turn */
965 r="yes: delta over 75";
968 cat=maneuver_category(old->item.type);
969 ncat=maneuver_category(new->item.type);
971 /* Check whether the street keeps its name */
972 is_same_street=is_same_street2(old->name1, old->name2, new->name1, new->name2);
976 dw=angle_delta(old->angle_end, w->angle2);
984 wcat=maneuver_category(w->item.type);
985 /* If any other street has the same name but isn't a highway (a highway might split up temporarily), then
986 we can't use the same name criterium */
987 if (is_same_street && is_same_street2(old->name1, old->name2, w->name1, w->name2) && (cat != 7 || wcat != 7) && is_way_allowed(w))
989 /* Mark if the street has a higher or the same category */
994 /* get the delta limit for checking for other streets. It is lower if the street has no other
995 streets of the same or higher category */
1000 /* if the street is really straight, the others might be closer to straight */
1003 if ((maxcat == ncat && maxcat == cat) || (ncat == 0 && cat == 0))
1004 dlim=abs(d)*620/256;
1005 else if (maxcat < ncat && maxcat < cat)
1006 dlim=abs(d)*128/256;
1007 if (left < -dlim && right > dlim)
1009 if (!is_same_street && is_unambigous < 1) {
1011 r="yes: not same street or ambigous";
1013 r="no: same street and unambigous";
1015 r=g_strdup_printf("yes: d %d left %d right %d dlim=%d cat old:%d new:%d max:%d unambigous=%d same_street=%d", d, left, right, dlim, cat, ncat, maxcat, is_unambigous, is_same_street);
1025 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
1026 if (is_same_street2(old, new)) {
1027 if (! entering_straight(new, abs(*delta))) {
1028 dbg(1, "maneuver_required: Not driving straight: yes\n");
1030 *reason="yes: Not driving straight";
1034 if (check_multiple_streets(new)) {
1035 if (entering_straight(new,abs(*delta)*2)) {
1037 *reason="no: delta < ext_limit for same name";
1041 *reason="yes: delta > ext_limit for same name";
1044 dbg(1, "maneuver_required: Staying on the same street: no\n");
1046 *reason="no: Staying on same street";
1051 dbg(1, "maneuver_required: old or new is ramp\n");
1053 if (old->item.type == type_ramp && (new->item.type == type_highway_city || new->item.type == type_highway_land)) {
1054 dbg(1, "no_maneuver_required: old is ramp new is highway\n");
1056 *reason="no: old is ramp new is highway";
1061 if (old->crossings_end == 2) {
1062 dbg(1, "maneuver_required: only 2 connections: no\n");
1066 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
1067 if ((new->item.type == type_highway_land || new->item.type == type_highway_city || old->item.type == type_highway_land || old->item.type == type_highway_city) && (!is_same_street_systematic(old, new) || (old->name2 != NULL && new->name2 == NULL))) {
1068 dbg(1, "maneuver_required: highway changed name\n");
1070 *reason="yes: highway changed name";
1073 if (abs(*delta) < straight_limit) {
1074 if (! entering_straight(new,abs(*delta))) {
1076 *reason="yes: not straight";
1077 dbg(1, "maneuver_required: not driving straight: yes\n");
1081 dbg(1, "maneuver_required: delta(%d) < %d: no\n", *delta, straight_limit);
1083 *reason="no: delta < limit";
1086 if (abs(*delta) < ext_straight_limit) {
1087 if (entering_straight(new,abs(*delta)*2)) {
1089 *reason="no: delta < ext_limit";
1094 if (! check_multiple_streets(new)) {
1095 dbg(1, "maneuver_required: only one possibility: no\n");
1097 *reason="no: only one possibility";
1101 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
1103 *reason="yes: delta >= limit";
1108 static struct navigation_command *
1109 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
1111 struct navigation_command *ret=g_new0(struct navigation_command, 1);
1112 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
1115 if (itm && itm->prev && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
1118 struct navigation_itm *itm2=itm->prev;
1119 while (itm2 && (itm2->flags & AF_ROUNDABOUT)) {
1121 angle=itm2->angle_end;
1125 ret->roundabout_delta=angle_delta(itm2->angle_end, itm->angle_start);
1131 ret->roundabout_delta=angle_delta(angle % 360, itm->angle_start);
1136 if (this_->cmd_last) {
1137 this_->cmd_last->next=ret;
1138 ret->prev = this_->cmd_last;
1140 this_->cmd_last=ret;
1142 if (!this_->cmd_first)
1143 this_->cmd_first=ret;
1148 make_maneuvers(struct navigation *this_, struct route *route)
1150 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
1153 this_->cmd_last=NULL;
1154 this_->cmd_first=NULL;
1157 if (maneuver_required2(last_itm, itm,&delta,NULL)) {
1158 command_new(this_, itm, delta);
1165 command_new(this_, last_itm, 0);
1169 contains_suffix(char *name, char *suffix)
1173 if (strlen(name) < strlen(suffix))
1175 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
1179 replace_suffix(char *name, char *search, char *replace)
1181 int len=strlen(name)-strlen(search);
1182 char *ret=g_malloc(len+strlen(replace)+1);
1183 strncpy(ret, name, len);
1184 strcpy(ret+len, replace);
1185 if (isupper(name[len])) {
1186 ret[len]=toupper(ret[len]);
1193 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
1195 char *ret=NULL,*name1,*sep,*name2;
1199 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
1200 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
1202 if(next->item.type == type_ramp)
1204 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
1205 return g_strdup_printf("%s%s",prefix,_("exit")); /* %FIXME Can this even be reached? */
1207 return g_strdup_printf("%s%s",prefix,_("into the ramp"));
1210 if (!itm->name1 && !itm->name2)
1215 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
1216 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
1217 sex=suffixes[i].sex;
1218 name1=g_strdup(itm->name1);
1221 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
1222 sex=suffixes[i].sex;
1223 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
1236 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
1237 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
1240 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Male form. The stuff after | doesn't have to be included */
1241 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
1244 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Female form. The stuff after | doesn't have to be included */
1245 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
1248 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name. Neutral form. The stuff after | doesn't have to be included */
1249 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
1255 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
1256 ret=g_strdup_printf(_("%sinto the %s"),prefix,itm->name2);
1274 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type, int connect)
1276 /* TRANSLATORS: right, as in 'Turn right' */
1277 char *dir=_("right"),*strength="";
1278 int distance=itm->dest_length-cmd->itm->dest_length;
1280 int delta=cmd->delta;
1282 int strength_needed;
1284 int count_roundabout;
1285 struct navigation_itm *cur;
1286 struct navigation_way *w;
1289 level = -2; // level = -2 means "connect to another maneuver via 'then ...'"
1294 w = itm->next->ways;
1295 strength_needed = 0;
1296 if (angle_delta(itm->next->angle_start,itm->angle_end) < 0) {
1298 if (angle_delta(w->angle2,itm->angle_end) < 0) {
1299 strength_needed = 1;
1306 if (angle_delta(w->angle2,itm->angle_end) > 0) {
1307 strength_needed = 1;
1315 /* TRANSLATORS: left, as in 'Turn left' */
1320 if (strength_needed) {
1322 /* TRANSLATORS: Don't forget the ending space */
1323 strength=_("easily ");
1324 } else if (delta < 105) {
1326 } else if (delta < 165) {
1327 /* TRANSLATORS: Don't forget the ending space */
1328 strength=_("strongly ");
1330 dbg(1,"delta=%d\n", delta);
1331 /* TRANSLATORS: Don't forget the ending space */
1332 strength=_("unknown ");
1335 if (type != attr_navigation_long_exact)
1336 distance=round_distance(distance);
1337 if (type == attr_navigation_speech) {
1338 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
1339 return g_strdup(_("When possible, please turn around"));
1341 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1343 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
1346 if (cmd->itm->prev->flags & AF_ROUNDABOUT) {
1349 return g_strdup(_("Enter the roundabout soon"));
1351 d = get_distance(distance, type, 1);
1352 /* TRANSLATORS: %s is the distance to the roundabout */
1353 ret = g_strdup_printf(_("In %s, enter the roundabout"), d);
1358 cur = cmd->itm->prev;
1359 count_roundabout = 0;
1360 while (cur && (cur->flags & AF_ROUNDABOUT)) {
1361 if (cur->next->ways && is_way_allowed(cur->next->ways)) { // If the next segment has no exit or the exit isn't allowed, don't count it
1368 ret = g_strdup_printf(_("Leave the roundabout at the %s exit"), get_count_str(count_roundabout));
1371 ret = g_strdup_printf(_("then leave the roundabout at the %s exit"), get_count_str(count_roundabout));
1380 d=get_distance(distance, type, 1);
1381 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
1385 d=g_strdup(_("soon"));
1388 d=get_distance(distance, type, 0);
1391 skip_roads = count_possible_turns(nav->first,cmd->itm,cmd->delta);
1392 if (skip_roads > 0) {
1393 if (get_count_str(skip_roads+1)) {
1394 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1395 ret = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1398 d = g_strdup_printf(_("after %i roads"), skip_roads);
1401 d=g_strdup(_("now"));
1405 skip_roads = count_possible_turns(cmd->prev->itm,cmd->itm,cmd->delta);
1406 if (skip_roads > 0) {
1407 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1408 if (get_count_str(skip_roads+1)) {
1409 ret = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1412 d = g_strdup_printf(_("after %i roads"), skip_roads);
1416 d = g_strdup_printf("");
1420 d=g_strdup(_("error"));
1422 if (cmd->itm->next) {
1423 int tellstreetname = 0;
1424 char *destination = NULL;
1426 if(type == attr_navigation_speech) { // In voice mode
1427 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
1430 if (level == 1) { // we are close to the intersection
1431 cmd->itm->streetname_told = 1; // remeber to be checked when we turn
1432 tellstreetname = 1; // Ok so we tell the name of the street
1436 if(cmd->itm->streetname_told == 0) // we are right at the intersection
1439 cmd->itm->streetname_told = 0; // reset just in case we come to the same street again
1447 destination=navigation_item_destination(cmd->itm, itm, " ");
1449 /* TRANSLATORS: The first argument is strength, the second direction, the third distance and the fourth destination Example: 'Turn 'slightly' 'left' in '100 m' 'onto baker street' */
1450 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1452 /* TRANSLATORS: First argument is strength, second direction, third how many roads to skip, fourth destination */
1453 ret=g_strdup_printf(_("then turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1455 g_free(destination);
1458 ret=g_strdup_printf(_("You have reached your destination %s"), d);
1460 ret=g_strdup_printf(_("then you have reached your destination."));
1468 * @brief Creates announcements for maneuvers, plus maneuvers immediately following the next maneuver
1470 * This function does create an announcement for the current maneuver and for maneuvers
1471 * immediately following that maneuver, if these are too close and we're in speech navigation.
1473 * @return An announcement that should be made
1476 show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
1478 struct navigation_command *cur,*prev;
1479 int distance=itm->dest_length-cmd->itm->dest_length;
1480 int l0_dist,level,dist,i,time;
1481 int speech_time,time2nav;
1482 char *ret,*old,*buf,*next;
1484 if (type != attr_navigation_speech) {
1485 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only in speech navigation
1488 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1491 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only if they are close
1494 if (cmd->itm->told) {
1498 ret = show_maneuver(nav, itm, cmd, type, 0);
1499 time2nav = navigation_time(itm,cmd->itm->prev);
1505 while (cur && cur->itm) {
1506 // We don't merge more than 3 announcements...
1507 if (i > 1) { // if you change this, please also change the value below, that is used to terminate the loop
1511 next = show_maneuver(nav,prev->itm, cur, type, 0);
1512 speech_time = navit_speech_estimate(nav->navit,next);
1515 if (speech_time == -1) { // user didn't set cps
1516 speech_time = 30; // assume 3 seconds
1519 dist = prev->itm->dest_length - cur->itm->dest_length;
1520 time = navigation_time(prev->itm,cur->itm->prev);
1522 if (time >= (speech_time + 30)) { // 3 seconds for understanding what has been said
1523 printf("Time: %i, speech_time: %i\n", time, speech_time);
1528 buf = show_maneuver(nav, prev->itm, cur, type, 1);
1529 ret = g_strdup_printf("%s, %s", old, buf);
1531 if (navit_speech_estimate(nav->navit,ret) > time2nav) {
1534 i = 2; // This will terminate the loop
1539 // If the two maneuvers are *really* close, we shouldn't tell the second one again, because TTS won't be fast enough
1540 if (time <= speech_time) {
1553 navigation_call_callbacks(struct navigation *this_, int force_speech)
1555 int distance, level = 0, level2;
1557 if (!this_->cmd_first)
1559 callback_list_call(this_->callback, 1, &p);
1560 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
1561 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
1562 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
1563 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
1564 while (distance > this_->distance_turn) {
1565 this_->level_last=4;
1568 if (this_->distance_turn >= 500)
1569 this_->distance_turn*=2;
1571 this_->distance_turn=500;
1573 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
1574 this_->distance_turn=50;
1575 distance-=this_->cmd_first->length;
1576 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
1577 if (this_->cmd_first->itm->prev) {
1578 level2=navigation_get_announce_level(this_, this_->cmd_first->itm->prev->item.type, distance);
1582 if (level < this_->level_last) {
1583 dbg(1,"level %d < %d\n", level, this_->level_last);
1584 this_->level_last=level;
1587 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
1588 dbg(1,"item different\n");
1589 this_->item_last=this_->cmd_first->itm->item;
1594 this_->level_last=level;
1595 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
1596 callback_list_call(this_->callback_speech, 1, &p);
1601 navigation_update(struct navigation *this_, struct route *route)
1604 struct map_rect *mr;
1605 struct item *ritem; /* Holds an item from the route map */
1606 struct item *sitem; /* Holds the corresponding item from the actual map */
1607 struct attr street_item,street_direction;
1608 struct navigation_itm *itm;
1613 map=route_get_map(route);
1616 mr=map_rect_new(map, NULL);
1620 while ((ritem=map_rect_get_item(mr))) {
1621 if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
1623 if (!item_attr_get(ritem, attr_direction, &street_direction))
1624 street_direction.u.num=0;
1625 sitem=street_item.u.item;
1626 dbg(1,"sitem=%p\n", sitem);
1627 itm=item_hash_lookup(this_->hash, sitem);
1628 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
1629 if (itm && itm->direction != street_direction.u.num) {
1630 dbg(2,"wrong direction\n");
1633 navigation_destroy_itms_cmds(this_, itm);
1635 navigation_itm_update(itm, ritem);
1638 dbg(1,"not on track\n");
1640 navigation_itm_new(this_, ritem);
1643 navigation_destroy_itms_cmds(this_, NULL);
1646 navigation_itm_new(this_, NULL);
1647 make_maneuvers(this_,route);
1649 calculate_dest_distance(this_, incr);
1650 dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
1651 if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0)
1652 this_->turn_around++;
1654 this_->turn_around--;
1655 if (this_->turn_around > this_->turn_around_limit)
1656 this_->turn_around=this_->turn_around_limit;
1657 else if (this_->turn_around < -this_->turn_around_limit+1)
1658 this_->turn_around=-this_->turn_around_limit+1;
1659 dbg(2,"turn_around=%d\n", this_->turn_around);
1660 this_->distance_last=this_->first->dest_length;
1662 navigation_call_callbacks(this_, FALSE);
1664 map_rect_destroy(mr);
1668 navigation_flush(struct navigation *this_)
1670 navigation_destroy_itms_cmds(this_, NULL);
1675 navigation_destroy(struct navigation *this_)
1677 navigation_flush(this_);
1678 item_hash_destroy(this_->hash);
1679 callback_list_destroy(this_->callback);
1680 callback_list_destroy(this_->callback_speech);
1685 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1687 if (type == attr_navigation_speech)
1688 callback_list_add(this_->callback_speech, cb);
1690 callback_list_add(this_->callback, cb);
1695 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1697 if (type == attr_navigation_speech)
1698 callback_list_remove_destroy(this_->callback_speech, cb);
1700 callback_list_remove_destroy(this_->callback, cb);
1704 navigation_get_map(struct navigation *this_)
1707 this_->map=map_new(NULL, (struct attr*[]){
1708 &(struct attr){attr_type,{"navigation"}},
1709 &(struct attr){attr_navigation,.u.navigation=this_},
1710 &(struct attr){attr_data,{""}},
1711 &(struct attr){attr_description,{"Navigation"}},
1717 struct navigation *navigation;
1720 struct map_rect_priv {
1721 struct navigation *nav;
1722 struct navigation_command *cmd;
1723 struct navigation_command *cmd_next;
1724 struct navigation_itm *itm;
1725 struct navigation_itm *itm_next;
1726 struct navigation_itm *cmd_itm;
1727 struct navigation_itm *cmd_itm_next;
1729 enum attr_type attr_next;
1732 struct navigation_way *ways;
1738 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
1740 struct map_rect_priv *this=priv_data;
1741 if (this->ccount || ! count)
1743 *c=this->itm->start;
1749 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
1751 struct map_rect_priv *this_=priv_data;
1752 attr->type=attr_type;
1753 struct navigation_command *cmd=this_->cmd;
1754 struct navigation_itm *itm=this_->itm;
1755 struct navigation_itm *prev=itm->prev;
1763 if (cmd->itm != itm)
1767 case attr_navigation_short:
1768 this_->attr_next=attr_navigation_long;
1770 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1774 case attr_navigation_long:
1775 this_->attr_next=attr_navigation_long_exact;
1777 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1781 case attr_navigation_long_exact:
1782 this_->attr_next=attr_navigation_speech;
1784 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1788 case attr_navigation_speech:
1789 this_->attr_next=attr_length;
1791 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
1796 this_->attr_next=attr_time;
1798 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
1803 this_->attr_next=attr_destination_length;
1805 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
1809 case attr_destination_length:
1810 attr->u.num=itm->dest_length;
1811 this_->attr_next=attr_destination_time;
1813 case attr_destination_time:
1814 attr->u.num=itm->dest_time;
1815 this_->attr_next=attr_street_name;
1817 case attr_street_name:
1818 attr->u.str=itm->name1;
1819 this_->attr_next=attr_street_name_systematic;
1823 case attr_street_name_systematic:
1824 attr->u.str=itm->name2;
1825 this_->attr_next=attr_debug;
1830 switch(this_->debug_idx) {
1833 this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->angle_start, itm->angle_end);
1837 this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->item.type));
1842 this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
1848 this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->name1);
1854 this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->name2);
1860 this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->angle_start, prev->angle_end);
1865 this_->ways=itm->ways;
1867 this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->item.type));
1871 if (this_->ways && prev) {
1872 this_->str=attr->u.str=g_strdup_printf("other item angle:%d delta:%d flags:%d dir:%d type:%s id:(0x%x,0x%x)", this_->ways->angle2, angle_delta(prev->angle_end, this_->ways->angle2), this_->ways->flags, this_->ways->dir, item_to_name(this_->ways->item.type), this_->ways->item.id_hi, this_->ways->item.id_lo);
1873 this_->ways=this_->ways->next;
1882 maneuver_required2(prev, itm, &delta, &reason);
1883 this_->str=attr->u.str=g_strdup_printf("reason:%s",reason);
1888 this_->attr_next=attr_none;
1892 while (this_->attr_next != attr_none) {
1893 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
1898 attr->type=attr_none;
1903 static struct item_methods navigation_map_item_methods = {
1905 navigation_map_item_coord_get,
1907 navigation_map_item_attr_get,
1912 navigation_map_destroy(struct map_priv *priv)
1918 navigation_map_rect_init(struct map_rect_priv *priv)
1920 priv->cmd_next=priv->nav->cmd_first;
1921 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
1924 static struct map_rect_priv *
1925 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
1927 struct navigation *nav=priv->navigation;
1928 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
1930 navigation_map_rect_init(ret);
1931 ret->item.meth=&navigation_map_item_methods;
1932 ret->item.priv_data=ret;
1940 navigation_map_rect_destroy(struct map_rect_priv *priv)
1945 static struct item *
1946 navigation_map_get_item(struct map_rect_priv *priv)
1948 struct item *ret=&priv->item;
1950 if (!priv->itm_next)
1952 priv->itm=priv->itm_next;
1953 priv->cmd=priv->cmd_next;
1954 priv->cmd_itm=priv->cmd_itm_next;
1957 if (!priv->show_all && priv->itm->prev != NULL)
1958 priv->itm=priv->cmd->itm;
1959 priv->itm_next=priv->itm->next;
1960 if (priv->itm->prev)
1961 ret->type=type_nav_none;
1963 ret->type=type_nav_position;
1964 if (priv->cmd->itm == priv->itm) {
1965 priv->cmd_itm_next=priv->cmd->itm;
1966 priv->cmd_next=priv->cmd->next;
1967 if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
1968 ret->type=type_nav_destination;
1970 if (priv->itm && priv->itm->prev && !(priv->itm->flags & AF_ROUNDABOUT) && (priv->itm->prev->flags & AF_ROUNDABOUT)) {
1972 switch (((180+22)-priv->cmd->roundabout_delta)/45) {
1975 ret->type=type_nav_roundabout_r1;
1978 ret->type=type_nav_roundabout_r2;
1981 ret->type=type_nav_roundabout_r3;
1984 ret->type=type_nav_roundabout_r4;
1987 ret->type=type_nav_roundabout_r5;
1990 ret->type=type_nav_roundabout_r6;
1993 ret->type=type_nav_roundabout_r7;
1996 ret->type=type_nav_roundabout_r8;
2000 delta=priv->cmd->delta;
2004 ret->type=type_nav_left_1;
2005 else if (delta < 105)
2006 ret->type=type_nav_left_2;
2007 else if (delta < 165)
2008 ret->type=type_nav_left_3;
2010 ret->type=type_none;
2013 ret->type=type_nav_right_1;
2014 else if (delta < 105)
2015 ret->type=type_nav_right_2;
2016 else if (delta < 165)
2017 ret->type=type_nav_right_3;
2019 ret->type=type_none;
2026 priv->attr_next=attr_navigation_short;
2028 ret->id_lo=priv->itm->dest_count;
2029 dbg(1,"type=%d\n", ret->type);
2033 static struct item *
2034 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
2037 navigation_map_rect_init(priv);
2038 while ((ret=navigation_map_get_item(priv))) {
2039 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
2045 static struct map_methods navigation_map_meth = {
2048 navigation_map_destroy,
2049 navigation_map_rect_new,
2050 navigation_map_rect_destroy,
2051 navigation_map_get_item,
2052 navigation_map_get_item_byid,
2058 static struct map_priv *
2059 navigation_map_new(struct map_methods *meth, struct attr **attrs)
2061 struct map_priv *ret;
2062 struct attr *navigation_attr;
2064 navigation_attr=attr_search(attrs, NULL, attr_navigation);
2065 if (! navigation_attr)
2067 ret=g_new0(struct map_priv, 1);
2068 *meth=navigation_map_meth;
2069 ret->navigation=navigation_attr->u.navigation;
2076 navigation_init(void)
2078 plugin_register_map_type("navigation", navigation_map_new);