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.
28 #include "navigation.h"
32 #include "transform.h"
34 #include "projection.h"
39 #include "navit_nls.h"
60 struct item_hash *hash;
61 struct navigation_itm *first;
62 struct navigation_itm *last;
63 struct navigation_command *cmd_first;
64 struct navigation_command *cmd_last;
65 struct callback_list *callback_speech;
66 struct callback_list *callback;
69 struct item item_last;
71 int turn_around_limit;
74 struct callback *route_cb;
75 int announce[route_item_last-route_item_first+1][3];
79 struct navigation_command {
80 struct navigation_itm *itm;
81 struct navigation_command *next;
82 struct navigation_command *prev;
88 static void navigation_flush(struct navigation *this_);
91 * @brief Calculates the delta between two angles
92 * @param angle1 The first angle
93 * @param angle2 The second angle
94 * @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
98 angle_delta(int angle1, int angle2)
100 int delta=angle2-angle1;
109 angle_median(int angle1, int angle2)
111 int delta=angle_delta(angle1, angle2);
112 int ret=angle1+delta/2;
121 angle_opposite(int angle)
123 return ((angle+180)%360);
127 navigation_get_attr(struct navigation *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
129 dbg(0,"enter %s\n", attr_to_name(type));
132 attr->u.map=this_->map;
143 navigation_new(struct attr *parent, struct attr **attrs)
146 struct navigation *ret=g_new0(struct navigation, 1);
147 ret->hash=item_hash_new();
148 ret->callback=callback_list_new();
149 ret->callback_speech=callback_list_new();
151 ret->distance_last=-2;
152 ret->distance_turn=50;
153 ret->turn_around_limit=3;
154 ret->navit=parent->u.navit;
156 for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
157 for (i = 0 ; i < 3 ; i++) {
158 ret->announce[j][i]=-1;
166 navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
169 if (type < route_item_first || type > route_item_last) {
170 dbg(0,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
173 for (i = 0 ; i < 3 ; i++)
174 this_->announce[type-route_item_first][i]=level[i];
179 navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
183 if (type < route_item_first || type > route_item_last)
185 for (i = 0 ; i < 3 ; i++) {
186 if (dist <= this_->announce[type-route_item_first][i])
193 * @brief Holds a way that one could possibly drive from a navigation item
195 struct navigation_way {
196 struct navigation_way *next; /**< Pointer to a linked-list of all navigation_ways from this navigation item */
197 short dir; /**< The direction -1 or 1 of the way */
198 short angle2; /**< The angle one has to steer to drive from the old item to this street */
199 int flags; /**< The flags of the way */
200 struct item item; /**< The item of the way */
205 struct navigation_itm {
212 struct coord start,end;
217 int told; /**< Indicates if this item's announcement has been told earlier and should not be told again*/
218 int streetname_told; /**< Indicates if this item's streetname has been told in speech navigation*/
221 struct navigation_itm *next;
222 struct navigation_itm *prev;
223 struct navigation_way *ways; /**< Pointer to all ways one could drive from here */
228 road_angle(struct coord *c1, struct coord *c2, int dir)
230 int ret=transform_get_angle_delta(c1, c2, dir);
231 dbg(1, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d\n", c1->x, c1->y, c2->x, c2->y, ret);
236 *get_count_str(int n)
240 return _("zeroth"); // Not shure if this exists, neither if it will ever be needed
259 *get_exit_count_str(int n)
263 return _("zeroth exit"); // Not shure if this exists, neither if it will ever be needed
265 return _("first exit");
267 return _("second exit");
269 return _("third exit");
271 return _("fourth exit");
273 return _("fifth exit");
275 return _("sixth exit");
281 round_distance(int dist)
304 dist=(dist+500)/1000;
307 dist=(dist+5000)/10000;
312 get_distance(int dist, enum attr_type type, int is_length)
314 if (type == attr_navigation_long) {
316 return g_strdup_printf(_("%d m"), dist);
318 return g_strdup_printf(_("in %d m"), dist);
322 return g_strdup_printf(_("%d meters"), dist);
324 return g_strdup_printf(_("in %d meters"), dist);
327 int rem=(dist/100)%10;
330 return g_strdup_printf(_("%d.%d kilometer"), dist/1000, rem);
332 return g_strdup_printf(_("in %d.%d kilometers"), dist/1000, rem);
336 return g_strdup_printf(ngettext("one kilometer","%d kilometers", dist/1000), dist/1000);
338 return g_strdup_printf(ngettext("in one kilometer","in %d kilometers", dist/1000), dist/1000);
343 * @brief This calculates the angle with which an item starts or ends
345 * This function can be used to get the angle an item (from a route graph map)
346 * starts or ends with. Note that the angle will point towards the inner of
349 * This is meant to be used with items from a route graph map
350 * With other items this will probably not be optimal...
352 * @param w The way which should be calculated
355 calculate_angle(struct navigation_way *w)
357 struct coord cbuf[2];
358 struct item *ritem; // the "real" item
364 mr = map_rect_new(w->item.map, NULL);
368 ritem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
370 dbg(1,"Item from segment not found on map!\n");
371 map_rect_destroy(mr);
375 if (ritem->type < type_line || ritem->type >= type_area) {
376 map_rect_destroy(mr);
379 if (item_attr_get(ritem, attr_flags, &attr))
383 if (item_attr_get(ritem, attr_street_name, &attr))
384 w->name1=map_convert_string(ritem->map,attr.u.str);
387 if (item_attr_get(ritem, attr_street_name_systematic, &attr))
388 w->name2=map_convert_string(ritem->map,attr.u.str);
393 if (item_coord_get(ritem, cbuf, 2) != 2) {
394 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
395 map_rect_destroy(mr);
399 while (item_coord_get(ritem, &c, 1)) {
405 if (item_coord_get(ritem, cbuf, 2) != 2) {
406 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
407 map_rect_destroy(mr);
415 map_rect_destroy(mr);
417 w->angle2=road_angle(&cbuf[1],&cbuf[0],0);
421 * @brief Returns the time (in seconds) one will drive between two navigation items
423 * This function returns the time needed to drive between two items, including both of them,
426 * @param from The first item
427 * @param to The last item
428 * @return The travel time in seconds, or -1 on error
431 navigation_time(struct navigation_itm *from, struct navigation_itm *to)
433 struct navigation_itm *cur;
455 * @brief Clears the ways one can drive from itm
457 * @param itm The item that should have its ways cleared
460 navigation_itm_ways_clear(struct navigation_itm *itm)
462 struct navigation_way *c,*n;
467 map_convert_free(c->name1);
468 map_convert_free(c->name2);
477 * @brief Updates the ways one can drive from itm
479 * This updates the list of possible ways to drive to from itm. The item "itm" is on
480 * and the next navigation item are excluded.
482 * @param itm The item that should be updated
483 * @param graph_map The route graph's map that these items are on
486 navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map)
488 struct map_selection coord_sel;
489 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
490 struct item *i,*sitem;
491 struct attr sitem_attr,direction_attr;
492 struct navigation_way *w,*l;
494 navigation_itm_ways_clear(itm);
496 // These values cause the code in route.c to get us only the route graph point and connected segments
497 coord_sel.next = NULL;
498 coord_sel.u.c_rect.lu = itm->start;
499 coord_sel.u.c_rect.rl = itm->start;
500 // the selection's order is ignored
502 g_rect = map_rect_new(graph_map, &coord_sel);
504 i = map_rect_get_item(g_rect);
505 if (!i || i->type != type_rg_point) { // probably offroad?
512 i = map_rect_get_item(g_rect);
518 if (i->type != type_rg_segment) {
522 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
523 dbg(1, "Got no street item for route graph item in entering_straight()\n");
527 if (!item_attr_get(i,attr_direction,&direction_attr)) {
531 sitem = sitem_attr.u.item;
532 if (item_is_equal(itm->item,*sitem) || ((itm->prev) && item_is_equal(itm->prev->item,*sitem))) {
537 w = g_new(struct navigation_way, 1);
538 w->dir = direction_attr.u.num;
544 map_rect_destroy(g_rect);
550 navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end)
552 struct navigation_itm *itm;
553 struct navigation_command *cmd;
554 dbg(2,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p\n", this_, this_->first, this_->cmd_first, end);
555 if (this_->cmd_first)
556 dbg(2,"this_->cmd_first->itm=%p\n", this_->cmd_first->itm);
557 while (this_->first && this_->first != end) {
559 dbg(3,"destroying %p\n", itm);
560 item_hash_remove(this_->hash, &itm->item);
561 this_->first=itm->next;
563 this_->first->prev=NULL;
564 if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
565 cmd=this_->cmd_first;
566 this_->cmd_first=cmd->next;
568 cmd->next->prev = NULL;
572 map_convert_free(itm->name1);
573 map_convert_free(itm->name2);
574 navigation_itm_ways_clear(itm);
579 if (! this_->first && end)
580 dbg(0,"end wrong\n");
581 dbg(2,"ret this_->first=%p this_->cmd_first=%p\n",this_->first, this_->cmd_first);
585 navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
587 struct attr length, time;
589 if (! item_attr_get(ritem, attr_length, &length)) {
590 dbg(0,"no length\n");
593 if (! item_attr_get(ritem, attr_time, &time)) {
598 dbg(1,"length=%d time=%d\n", length.u.num, time.u.num);
599 itm->length=length.u.num;
600 itm->time=time.u.num;
604 * @brief This check if an item is part of a roundabout
606 * @param itm The item to be checked
607 * @return True if the item is part of a roundabout
610 check_roundabout(struct navigation_itm *itm, struct map *graph_map)
612 struct map_selection coord_sel;
613 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
614 struct item *i,*sitem;
615 struct attr sitem_attr,flags_attr;
617 // These values cause the code in route.c to get us only the route graph point and connected segments
618 coord_sel.next = NULL;
619 coord_sel.u.c_rect.lu = itm->start;
620 coord_sel.u.c_rect.rl = itm->start;
621 // the selection's order is ignored
623 g_rect = map_rect_new(graph_map, &coord_sel);
625 i = map_rect_get_item(g_rect);
626 if (!i || i->type != type_rg_point) { // probably offroad?
631 i = map_rect_get_item(g_rect);
637 if (i->type != type_rg_segment) {
641 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
645 sitem = sitem_attr.u.item;
646 if (item_is_equal(itm->item,*sitem)) {
647 if (item_attr_get(i,attr_flags,&flags_attr) && (flags_attr.u.num & AF_ROUNDABOUT)) {
648 map_rect_destroy(g_rect);
654 map_rect_destroy(g_rect);
658 static struct navigation_itm *
659 navigation_itm_new(struct navigation *this_, struct item *ritem)
661 struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
664 struct map *graph_map = NULL;
665 struct attr street_item,direction,route_attr;
671 ret->streetname_told=0;
672 if (! item_attr_get(ritem, attr_street_item, &street_item)) {
673 dbg(0,"no street item\n");
676 if (item_attr_get(ritem, attr_direction, &direction))
677 ret->direction=direction.u.num;
681 sitem=street_item.u.item;
683 item_hash_insert(this_->hash, sitem, ret);
684 mr=map_rect_new(sitem->map, NULL);
685 sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
686 if (item_attr_get(sitem, attr_street_name, &attr))
687 ret->name1=map_convert_string(sitem->map,attr.u.str);
688 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
689 ret->name2=map_convert_string(sitem->map,attr.u.str);
690 navigation_itm_update(ret, ritem);
692 while (item_coord_get(ritem, &c[i], 1)) {
693 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
702 dbg(1,"count=%d\n", i);
705 ret->angle_start=road_angle(&c[0], &c[1], 0);
706 ret->angle_end=road_angle(&c[i-1], &c[i], 0);
711 item_attr_get(ritem, attr_route, &route_attr);
712 graph_map = route_get_graph_map(route_attr.u.route);
713 if (check_roundabout(ret, graph_map)) {
714 ret->flags |= AF_ROUNDABOUT;
717 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
718 map_rect_destroy(mr);
721 ret->start=ret->end=this_->last->end;
726 this_->last->next=ret;
727 ret->prev=this_->last;
729 navigation_itm_ways_update(ret,graph_map);
732 dbg(1,"ret=%p\n", ret);
738 * @brief Counts how many times a driver could turn right/left
740 * This function counts how many times the driver theoretically could
741 * turn right/left between two navigation items, not counting the final
744 * @param from The navigation item which should form the start
745 * @param to The navigation item which should form the end
746 * @param direction Set to < 0 to count turns to the left >= 0 for turns to the right
747 * @return The number of possibilities to turn or -1 on error
750 count_possible_turns(struct navigation_itm *from, struct navigation_itm *to, int direction)
753 struct navigation_itm *curr;
754 struct navigation_way *w;
758 while (curr && (curr != to)) {
763 if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
768 if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
778 if (!curr) { // from does not lead to to?
786 * @brief Calculates distance and time to the destination
788 * This function calculates the distance and the time to the destination of a
789 * navigation. If incr is set, this is only calculated for the first navigation
790 * item, which is a lot faster than re-calculation the whole destination, but works
791 * only if the rest of the navigation already has been calculated.
793 * @param this_ The navigation whose destination / time should be calculated
794 * @param incr Set this to true to only calculate the first item. See description.
797 calculate_dest_distance(struct navigation *this_, int incr)
799 int len=0, time=0, count=0;
800 struct navigation_itm *next,*itm=this_->last;
801 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
804 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
806 dbg(2, "old values: itm is null\n");
809 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
810 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
811 itm->dest_length=next->dest_length+itm->length;
812 itm->dest_count=next->dest_count+1;
813 itm->dest_time=next->dest_time+itm->time;
814 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
820 itm->dest_length=len;
822 itm->dest_count=count++;
825 dbg(1,"len %d time %d\n", len, time);
829 * @brief Checks if two navigation items are on the same street
831 * This function checks if two navigation items are on the same street. It returns
832 * true if either their name or their "systematic name" (e.g. "A6" or "B256") are the
835 * @param old The first item to be checked
836 * @param new The second item to be checked
837 * @return True if both old and new are on the same street
840 is_same_street2(char *old_name1, char *old_name2, char *new_name1, char *new_name2)
842 if (old_name1 && new_name1 && !strcmp(old_name1, new_name1)) {
843 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old_name2, new_name2, old_name1, new_name1);
846 if (old_name2 && new_name2 && !strcmp(old_name2, new_name2)) {
847 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old_name2, new_name2, old_name1, new_name1);
850 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old_name2, new_name2, old_name1, new_name1);
856 * @brief Checks if two navigation items are on the same street
858 * This function checks if two navigation items are on the same street. It returns
859 * true if the first part of their "systematic name" is equal. If the "systematic name" is
860 * for example "A352/E3" (a german highway which at the same time is part of the international
861 * E-road network), it would only search for "A352" in the second item's systematic name.
863 * @param old The first item to be checked
864 * @param new The second item to be checked
865 * @return True if the "systematic name" of both items matches. See description.
868 is_same_street_systematic(struct navigation_itm *old, struct navigation_itm *new)
870 int slashold,slashnew;
871 if (!old->name2 || !new->name2)
873 slashold=strcspn(old->name2, "/");
874 slashnew=strcspn(new->name2, "/");
875 if (slashold != slashnew || strncmp(old->name2, new->name2, slashold))
882 * @brief Check if there are multiple possibilities to drive from old
884 * This function checks, if there are multiple streets connected to the exit of "old".
885 * Sometimes it happens that an item on a map is just segmented, without any other streets
886 * being connected there, and it is not useful if navit creates a maneuver there.
888 * @param new The navigation item we're driving to
889 * @return True if there are multiple streets
892 maneuver_multiple_streets(struct navigation_itm *new)
903 * @brief Check if the new item is entered "straight"
905 * This function checks if the new item is entered "straight" from the old item, i.e. if there
906 * is no other street one could take from the old item on with less steering.
908 * @param new The navigation item we're driving to
909 * @param diff The absolute angle one needs to steer to drive to this item
910 * @return True if the new item is entered "straight"
913 maneuver_straight(struct navigation_itm *new, int diff)
916 struct navigation_way *w;
919 dbg(1,"diff=%d\n", diff);
921 curr_diff=abs(angle_delta(new->prev->angle_end, w->angle2));
922 dbg(1,"curr_diff=%d\n", curr_diff);
923 if (curr_diff < diff) {
932 static int maneuver_category(enum item_type type)
937 case type_street_1_city:
939 case type_street_2_city:
941 case type_street_3_city:
943 case type_street_4_city:
945 case type_highway_city:
947 case type_street_1_land:
949 case type_street_2_land:
951 case type_street_3_land:
953 case type_street_4_land:
955 case type_street_n_lanes:
957 case type_highway_land:
961 case type_roundabout:
973 is_way_allowed(struct navigation_way *way)
976 if (way->flags & AF_ONEWAYREV)
979 if (way->flags & AF_ONEWAY)
986 * @brief Checks if navit has to create a maneuver to drive from old to new
988 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
989 * from "old" to "new".
991 * @param old The old navigation item, where we're coming from
992 * @param new The new navigation item, where we're going to
993 * @param delta The angle the user has to steer to navigate from old to new
994 * @param reason A text string explaining how the return value resulted
995 * @return True if navit should guide the user, false otherwise
998 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta, char **reason)
1000 int ret=0,d,dw,dlim;
1002 struct navigation_way *w;
1003 int cat,ncat,wcat,maxcat,left=-180,right=180,is_unambigous=0,is_same_street;
1005 dbg(1,"enter %p %p %p\n",old, new, delta);
1006 d=angle_delta(old->angle_end, new->angle_start);
1008 /* No announcement necessary */
1009 r="no: Only one possibility";
1010 } else if (!new->ways->next && new->ways->item.type == type_ramp && !is_way_allowed(new->ways)) {
1011 /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
1015 if ((old->flags & AF_ROUNDABOUT) && ! (new->flags & AF_ROUNDABOUT)) {
1016 r="yes: leaving roundabout";
1018 } else if (!(old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1019 r="no: entering roundabout";
1020 else if ((old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1021 r="no: staying in roundabout";
1023 if (!r && abs(d) > 75) {
1024 /* always make an announcement if you have to make a sharp turn */
1025 r="yes: delta over 75";
1028 cat=maneuver_category(old->item.type);
1029 ncat=maneuver_category(new->item.type);
1031 /* Check whether the street keeps its name */
1032 is_same_street=is_same_street2(old->name1, old->name2, new->name1, new->name2);
1036 dw=angle_delta(old->angle_end, w->angle2);
1044 wcat=maneuver_category(w->item.type);
1045 /* If any other street has the same name but isn't a highway (a highway might split up temporarily), then
1046 we can't use the same name criterium */
1047 if (is_same_street && is_same_street2(old->name1, old->name2, w->name1, w->name2) && (cat != 7 || wcat != 7) && is_way_allowed(w))
1049 /* Mark if the street has a higher or the same category */
1054 /* get the delta limit for checking for other streets. It is lower if the street has no other
1055 streets of the same or higher category */
1060 /* if the street is really straight, the others might be closer to straight */
1063 if ((maxcat == ncat && maxcat == cat) || (ncat == 0 && cat == 0))
1064 dlim=abs(d)*620/256;
1065 else if (maxcat < ncat && maxcat < cat)
1066 dlim=abs(d)*128/256;
1067 if (left < -dlim && right > dlim)
1069 if (!is_same_street && is_unambigous < 1) {
1071 r="yes: not same street or ambigous";
1073 r="no: same street and unambigous";
1075 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);
1085 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
1086 if (is_same_street2(old, new)) {
1087 if (! entering_straight(new, abs(*delta))) {
1088 dbg(1, "maneuver_required: Not driving straight: yes\n");
1090 *reason="yes: Not driving straight";
1094 if (check_multiple_streets(new)) {
1095 if (entering_straight(new,abs(*delta)*2)) {
1097 *reason="no: delta < ext_limit for same name";
1101 *reason="yes: delta > ext_limit for same name";
1104 dbg(1, "maneuver_required: Staying on the same street: no\n");
1106 *reason="no: Staying on same street";
1111 dbg(1, "maneuver_required: old or new is ramp\n");
1113 if (old->item.type == type_ramp && (new->item.type == type_highway_city || new->item.type == type_highway_land)) {
1114 dbg(1, "no_maneuver_required: old is ramp new is highway\n");
1116 *reason="no: old is ramp new is highway";
1121 if (old->crossings_end == 2) {
1122 dbg(1, "maneuver_required: only 2 connections: no\n");
1126 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
1127 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))) {
1128 dbg(1, "maneuver_required: highway changed name\n");
1130 *reason="yes: highway changed name";
1133 if (abs(*delta) < straight_limit) {
1134 if (! entering_straight(new,abs(*delta))) {
1136 *reason="yes: not straight";
1137 dbg(1, "maneuver_required: not driving straight: yes\n");
1141 dbg(1, "maneuver_required: delta(%d) < %d: no\n", *delta, straight_limit);
1143 *reason="no: delta < limit";
1146 if (abs(*delta) < ext_straight_limit) {
1147 if (entering_straight(new,abs(*delta)*2)) {
1149 *reason="no: delta < ext_limit";
1154 if (! check_multiple_streets(new)) {
1155 dbg(1, "maneuver_required: only one possibility: no\n");
1157 *reason="no: only one possibility";
1161 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
1163 *reason="yes: delta >= limit";
1168 static struct navigation_command *
1169 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
1171 struct navigation_command *ret=g_new0(struct navigation_command, 1);
1172 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
1175 if (itm && itm->prev && itm->prev->ways && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
1179 struct navigation_itm *itm2=itm->prev;
1180 int exit_angle=angle_median(itm->prev->angle_end, itm->ways->angle2);
1181 dbg(1,"exit %d median from %d,%d\n", exit_angle,itm->prev->angle_end, itm->ways->angle2);
1182 while (itm2 && (itm2->flags & AF_ROUNDABOUT)) {
1184 angle=itm2->angle_end;
1187 if (itm2 && itm2->next && itm2->next->ways) {
1189 entry_angle=angle_median(angle_opposite(itm2->angle_start), itm2->ways->angle2);
1190 dbg(1,"entry %d median from %d(%d),%d\n", entry_angle,angle_opposite(itm2->angle_start), itm2->angle_start, itm2->ways->angle2);
1192 entry_angle=angle_opposite(angle);
1194 dbg(0,"entry %d exit %d\n", entry_angle, exit_angle);
1195 ret->roundabout_delta=angle_delta(entry_angle, exit_angle);
1199 if (this_->cmd_last) {
1200 this_->cmd_last->next=ret;
1201 ret->prev = this_->cmd_last;
1203 this_->cmd_last=ret;
1205 if (!this_->cmd_first)
1206 this_->cmd_first=ret;
1211 make_maneuvers(struct navigation *this_, struct route *route)
1213 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
1216 this_->cmd_last=NULL;
1217 this_->cmd_first=NULL;
1220 if (maneuver_required2(last_itm, itm,&delta,NULL)) {
1221 command_new(this_, itm, delta);
1228 command_new(this_, last_itm, 0);
1232 contains_suffix(char *name, char *suffix)
1236 if (strlen(name) < strlen(suffix))
1238 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
1242 replace_suffix(char *name, char *search, char *replace)
1244 int len=strlen(name)-strlen(search);
1245 char *ret=g_malloc(len+strlen(replace)+1);
1246 strncpy(ret, name, len);
1247 strcpy(ret+len, replace);
1248 if (isupper(name[len])) {
1249 ret[len]=toupper(ret[len]);
1256 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
1258 char *ret=NULL,*name1,*sep,*name2;
1262 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
1263 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
1265 if(next->item.type == type_ramp)
1267 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
1268 return g_strdup_printf("%s%s",prefix,_("exit")); /* %FIXME Can this even be reached? */
1270 return g_strdup_printf("%s%s",prefix,_("into the ramp"));
1273 if (!itm->name1 && !itm->name2)
1278 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
1279 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
1280 sex=suffixes[i].sex;
1281 name1=g_strdup(itm->name1);
1284 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
1285 sex=suffixes[i].sex;
1286 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
1299 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
1300 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
1303 /* 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 */
1304 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
1307 /* 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 */
1308 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
1311 /* 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 */
1312 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
1318 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
1319 ret=g_strdup_printf(_("%sinto the %s"),prefix,itm->name2);
1337 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type, int connect)
1339 /* TRANSLATORS: right, as in 'Turn right' */
1340 char *dir=_("right"),*strength="";
1341 int distance=itm->dest_length-cmd->itm->dest_length;
1343 int delta=cmd->delta;
1345 int strength_needed;
1347 int count_roundabout;
1348 struct navigation_itm *cur;
1349 struct navigation_way *w;
1352 level = -2; // level = -2 means "connect to another maneuver via 'then ...'"
1357 w = itm->next->ways;
1358 strength_needed = 0;
1359 if (angle_delta(itm->next->angle_start,itm->angle_end) < 0) {
1361 if (angle_delta(w->angle2,itm->angle_end) < 0) {
1362 strength_needed = 1;
1369 if (angle_delta(w->angle2,itm->angle_end) > 0) {
1370 strength_needed = 1;
1378 /* TRANSLATORS: left, as in 'Turn left' */
1383 if (strength_needed) {
1385 /* TRANSLATORS: Don't forget the ending space */
1386 strength=_("easily ");
1387 } else if (delta < 105) {
1389 } else if (delta < 165) {
1390 /* TRANSLATORS: Don't forget the ending space */
1391 strength=_("strongly ");
1393 dbg(1,"delta=%d\n", delta);
1394 /* TRANSLATORS: Don't forget the ending space */
1395 strength=_("unknown ");
1398 if (type != attr_navigation_long_exact)
1399 distance=round_distance(distance);
1400 if (type == attr_navigation_speech) {
1401 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
1402 return g_strdup(_("When possible, please turn around"));
1404 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1406 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
1409 if (cmd->itm->prev->flags & AF_ROUNDABOUT) {
1412 return g_strdup(_("Enter the roundabout soon"));
1414 d = get_distance(distance, type, 1);
1415 /* TRANSLATORS: %s is the distance to the roundabout */
1416 ret = g_strdup_printf(_("In %s, enter the roundabout"), d);
1421 cur = cmd->itm->prev;
1422 count_roundabout = 0;
1423 while (cur && (cur->flags & AF_ROUNDABOUT)) {
1424 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
1431 ret = g_strdup_printf(_("Leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1434 ret = g_strdup_printf(_("then leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1443 d=get_distance(distance, type, 1);
1444 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
1448 d=g_strdup(_("soon"));
1451 d=get_distance(distance, type, 0);
1454 skip_roads = count_possible_turns(nav->first,cmd->itm,cmd->delta);
1455 if (skip_roads > 0) {
1456 if (get_count_str(skip_roads+1)) {
1457 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1458 ret = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1461 d = g_strdup_printf(_("after %i roads"), skip_roads);
1464 d=g_strdup(_("now"));
1468 skip_roads = count_possible_turns(cmd->prev->itm,cmd->itm,cmd->delta);
1469 if (skip_roads > 0) {
1470 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1471 if (get_count_str(skip_roads+1)) {
1472 ret = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1475 d = g_strdup_printf(_("after %i roads"), skip_roads);
1483 d=g_strdup(_("error"));
1485 if (cmd->itm->next) {
1486 int tellstreetname = 0;
1487 char *destination = NULL;
1489 if(type == attr_navigation_speech) { // In voice mode
1490 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
1493 if (level == 1) { // we are close to the intersection
1494 cmd->itm->streetname_told = 1; // remeber to be checked when we turn
1495 tellstreetname = 1; // Ok so we tell the name of the street
1499 if(cmd->itm->streetname_told == 0) // we are right at the intersection
1502 cmd->itm->streetname_told = 0; // reset just in case we come to the same street again
1510 destination=navigation_item_destination(cmd->itm, itm, " ");
1512 /* 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' */
1513 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1515 /* TRANSLATORS: First argument is strength, second direction, third how many roads to skip, fourth destination */
1516 ret=g_strdup_printf(_("then turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1518 g_free(destination);
1521 ret=g_strdup_printf(_("You have reached your destination %s"), d);
1523 ret=g_strdup_printf(_("then you have reached your destination."));
1531 * @brief Creates announcements for maneuvers, plus maneuvers immediately following the next maneuver
1533 * This function does create an announcement for the current maneuver and for maneuvers
1534 * immediately following that maneuver, if these are too close and we're in speech navigation.
1536 * @return An announcement that should be made
1539 show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
1541 struct navigation_command *cur,*prev;
1542 int distance=itm->dest_length-cmd->itm->dest_length;
1543 int level, dist, i, time;
1544 int speech_time,time2nav;
1545 char *ret,*old,*buf,*next;
1547 if (type != attr_navigation_speech) {
1548 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only in speech navigation
1551 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1554 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only if they are close
1557 if (cmd->itm->told) {
1561 ret = show_maneuver(nav, itm, cmd, type, 0);
1562 time2nav = navigation_time(itm,cmd->itm->prev);
1568 while (cur && cur->itm) {
1569 // We don't merge more than 3 announcements...
1570 if (i > 1) { // if you change this, please also change the value below, that is used to terminate the loop
1574 next = show_maneuver(nav,prev->itm, cur, type, 0);
1575 speech_time = navit_speech_estimate(nav->navit,next);
1578 if (speech_time == -1) { // user didn't set cps
1579 speech_time = 30; // assume 3 seconds
1582 dist = prev->itm->dest_length - cur->itm->dest_length;
1583 time = navigation_time(prev->itm,cur->itm->prev);
1585 if (time >= (speech_time + 30)) { // 3 seconds for understanding what has been said
1590 buf = show_maneuver(nav, prev->itm, cur, type, 1);
1591 ret = g_strdup_printf("%s, %s", old, buf);
1593 if (navit_speech_estimate(nav->navit,ret) > time2nav) {
1596 i = 2; // This will terminate the loop
1601 // If the two maneuvers are *really* close, we shouldn't tell the second one again, because TTS won't be fast enough
1602 if (time <= speech_time) {
1615 navigation_call_callbacks(struct navigation *this_, int force_speech)
1617 int distance, level = 0, level2;
1619 if (!this_->cmd_first)
1621 callback_list_call(this_->callback, 1, &p);
1622 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
1623 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
1624 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
1625 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
1626 while (distance > this_->distance_turn) {
1627 this_->level_last=4;
1630 if (this_->distance_turn >= 500)
1631 this_->distance_turn*=2;
1633 this_->distance_turn=500;
1635 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
1636 this_->distance_turn=50;
1637 distance-=this_->cmd_first->length;
1638 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
1639 if (this_->cmd_first->itm->prev) {
1640 level2=navigation_get_announce_level(this_, this_->cmd_first->itm->prev->item.type, distance);
1644 if (level < this_->level_last) {
1645 dbg(1,"level %d < %d\n", level, this_->level_last);
1646 this_->level_last=level;
1649 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
1650 dbg(1,"item different\n");
1651 this_->item_last=this_->cmd_first->itm->item;
1656 this_->level_last=level;
1657 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
1658 callback_list_call(this_->callback_speech, 1, &p);
1663 navigation_update(struct navigation *this_, struct route *route, struct attr *attr)
1666 struct map_rect *mr;
1667 struct item *ritem; /* Holds an item from the route map */
1668 struct item *sitem; /* Holds the corresponding item from the actual map */
1669 struct attr street_item,street_direction;
1670 struct navigation_itm *itm;
1671 int mode=0, incr=0, first=1;
1672 if (attr->type != attr_route_status)
1675 dbg(1,"enter %d\n", mode);
1676 if (attr->u.num == route_status_no_destination || attr->u.num == route_status_not_found || attr->u.num == route_status_path_done_new)
1677 navigation_flush(this_);
1678 if (attr->u.num != route_status_path_done_new && attr->u.num != route_status_path_done_incremental)
1683 map=route_get_map(this_->route);
1686 mr=map_rect_new(map, NULL);
1690 while ((ritem=map_rect_get_item(mr))) {
1691 if (ritem->type != type_street_route)
1693 if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
1695 if (!item_attr_get(ritem, attr_direction, &street_direction))
1696 street_direction.u.num=0;
1697 sitem=street_item.u.item;
1698 dbg(1,"sitem=%p\n", sitem);
1699 itm=item_hash_lookup(this_->hash, sitem);
1700 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
1701 if (itm && itm->direction != street_direction.u.num) {
1702 dbg(2,"wrong direction\n");
1705 navigation_destroy_itms_cmds(this_, itm);
1707 navigation_itm_update(itm, ritem);
1710 dbg(1,"not on track\n");
1712 navigation_itm_new(this_, ritem);
1715 navigation_destroy_itms_cmds(this_, NULL);
1718 navigation_itm_new(this_, NULL);
1719 make_maneuvers(this_,this_->route);
1721 calculate_dest_distance(this_, incr);
1722 dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
1723 if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0)
1724 this_->turn_around++;
1726 this_->turn_around--;
1727 if (this_->turn_around > this_->turn_around_limit)
1728 this_->turn_around=this_->turn_around_limit;
1729 else if (this_->turn_around < -this_->turn_around_limit+1)
1730 this_->turn_around=-this_->turn_around_limit+1;
1731 dbg(2,"turn_around=%d\n", this_->turn_around);
1732 this_->distance_last=this_->first->dest_length;
1734 navigation_call_callbacks(this_, FALSE);
1736 map_rect_destroy(mr);
1740 navigation_flush(struct navigation *this_)
1742 navigation_destroy_itms_cmds(this_, NULL);
1747 navigation_destroy(struct navigation *this_)
1749 navigation_flush(this_);
1750 item_hash_destroy(this_->hash);
1751 callback_list_destroy(this_->callback);
1752 callback_list_destroy(this_->callback_speech);
1757 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1759 if (type == attr_navigation_speech)
1760 callback_list_add(this_->callback_speech, cb);
1762 callback_list_add(this_->callback, cb);
1767 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1769 if (type == attr_navigation_speech)
1770 callback_list_remove_destroy(this_->callback_speech, cb);
1772 callback_list_remove_destroy(this_->callback, cb);
1776 navigation_get_map(struct navigation *this_)
1779 this_->map=map_new(NULL, (struct attr*[]){
1780 &(struct attr){attr_type,{"navigation"}},
1781 &(struct attr){attr_navigation,.u.navigation=this_},
1782 &(struct attr){attr_data,{""}},
1783 &(struct attr){attr_description,{"Navigation"}},
1789 struct navigation *navigation;
1792 struct map_rect_priv {
1793 struct navigation *nav;
1794 struct navigation_command *cmd;
1795 struct navigation_command *cmd_next;
1796 struct navigation_itm *itm;
1797 struct navigation_itm *itm_next;
1798 struct navigation_itm *cmd_itm;
1799 struct navigation_itm *cmd_itm_next;
1801 enum attr_type attr_next;
1804 struct navigation_way *ways;
1810 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
1812 struct map_rect_priv *this=priv_data;
1813 if (this->ccount || ! count)
1815 *c=this->itm->start;
1821 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
1823 struct map_rect_priv *this_=priv_data;
1824 attr->type=attr_type;
1825 struct navigation_command *cmd=this_->cmd;
1826 struct navigation_itm *itm=this_->itm;
1827 struct navigation_itm *prev=itm->prev;
1835 if (cmd->itm != itm)
1839 case attr_navigation_short:
1840 this_->attr_next=attr_navigation_long;
1842 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1846 case attr_navigation_long:
1847 this_->attr_next=attr_navigation_long_exact;
1849 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1853 case attr_navigation_long_exact:
1854 this_->attr_next=attr_navigation_speech;
1856 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1860 case attr_navigation_speech:
1861 this_->attr_next=attr_length;
1863 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
1868 this_->attr_next=attr_time;
1870 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
1875 this_->attr_next=attr_destination_length;
1877 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
1881 case attr_destination_length:
1882 attr->u.num=itm->dest_length;
1883 this_->attr_next=attr_destination_time;
1885 case attr_destination_time:
1886 attr->u.num=itm->dest_time;
1887 this_->attr_next=attr_street_name;
1889 case attr_street_name:
1890 attr->u.str=itm->name1;
1891 this_->attr_next=attr_street_name_systematic;
1895 case attr_street_name_systematic:
1896 attr->u.str=itm->name2;
1897 this_->attr_next=attr_debug;
1902 switch(this_->debug_idx) {
1905 this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->angle_start, itm->angle_end);
1909 this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->item.type));
1914 this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
1920 this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->name1);
1926 this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->name2);
1932 this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->angle_start, prev->angle_end);
1937 this_->ways=itm->ways;
1939 this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->item.type));
1943 if (this_->ways && prev) {
1944 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);
1945 this_->ways=this_->ways->next;
1954 maneuver_required2(prev, itm, &delta, &reason);
1955 this_->str=attr->u.str=g_strdup_printf("reason:%s",reason);
1960 this_->attr_next=attr_none;
1964 while (this_->attr_next != attr_none) {
1965 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
1970 attr->type=attr_none;
1975 static struct item_methods navigation_map_item_methods = {
1977 navigation_map_item_coord_get,
1979 navigation_map_item_attr_get,
1984 navigation_map_destroy(struct map_priv *priv)
1990 navigation_map_rect_init(struct map_rect_priv *priv)
1992 priv->cmd_next=priv->nav->cmd_first;
1993 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
1996 static struct map_rect_priv *
1997 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
1999 struct navigation *nav=priv->navigation;
2000 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
2002 navigation_map_rect_init(ret);
2003 ret->item.meth=&navigation_map_item_methods;
2004 ret->item.priv_data=ret;
2012 navigation_map_rect_destroy(struct map_rect_priv *priv)
2017 static struct item *
2018 navigation_map_get_item(struct map_rect_priv *priv)
2020 struct item *ret=&priv->item;
2022 if (!priv->itm_next)
2024 priv->itm=priv->itm_next;
2025 priv->cmd=priv->cmd_next;
2026 priv->cmd_itm=priv->cmd_itm_next;
2029 if (!priv->show_all && priv->itm->prev != NULL)
2030 priv->itm=priv->cmd->itm;
2031 priv->itm_next=priv->itm->next;
2032 if (priv->itm->prev)
2033 ret->type=type_nav_none;
2035 ret->type=type_nav_position;
2036 if (priv->cmd->itm == priv->itm) {
2037 priv->cmd_itm_next=priv->cmd->itm;
2038 priv->cmd_next=priv->cmd->next;
2039 if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
2040 ret->type=type_nav_destination;
2042 if (priv->itm && priv->itm->prev && !(priv->itm->flags & AF_ROUNDABOUT) && (priv->itm->prev->flags & AF_ROUNDABOUT)) {
2044 switch (((180+22)-priv->cmd->roundabout_delta)/45) {
2047 ret->type=type_nav_roundabout_r1;
2050 ret->type=type_nav_roundabout_r2;
2053 ret->type=type_nav_roundabout_r3;
2056 ret->type=type_nav_roundabout_r4;
2059 ret->type=type_nav_roundabout_r5;
2062 ret->type=type_nav_roundabout_r6;
2065 ret->type=type_nav_roundabout_r7;
2068 ret->type=type_nav_roundabout_r8;
2072 delta=priv->cmd->delta;
2076 ret->type=type_nav_left_1;
2077 else if (delta < 105)
2078 ret->type=type_nav_left_2;
2079 else if (delta < 165)
2080 ret->type=type_nav_left_3;
2082 ret->type=type_none;
2085 ret->type=type_nav_right_1;
2086 else if (delta < 105)
2087 ret->type=type_nav_right_2;
2088 else if (delta < 165)
2089 ret->type=type_nav_right_3;
2091 ret->type=type_none;
2098 priv->attr_next=attr_navigation_short;
2100 ret->id_lo=priv->itm->dest_count;
2101 dbg(1,"type=%d\n", ret->type);
2105 static struct item *
2106 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
2109 navigation_map_rect_init(priv);
2110 while ((ret=navigation_map_get_item(priv))) {
2111 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
2117 static struct map_methods navigation_map_meth = {
2120 navigation_map_destroy,
2121 navigation_map_rect_new,
2122 navigation_map_rect_destroy,
2123 navigation_map_get_item,
2124 navigation_map_get_item_byid,
2130 static struct map_priv *
2131 navigation_map_new(struct map_methods *meth, struct attr **attrs)
2133 struct map_priv *ret;
2134 struct attr *navigation_attr;
2136 navigation_attr=attr_search(attrs, NULL, attr_navigation);
2137 if (! navigation_attr)
2139 ret=g_new0(struct map_priv, 1);
2140 *meth=navigation_map_meth;
2141 ret->navigation=navigation_attr->u.navigation;
2147 navigation_set_route(struct navigation *this_, struct route *route)
2149 struct attr callback;
2151 this_->route_cb=callback_new_attr_1(callback_cast(navigation_update), attr_route_status, this_);
2152 callback.type=attr_callback;
2153 callback.u.callback=this_->route_cb;
2154 route_add_attr(route, &callback);
2158 navigation_init(void)
2160 plugin_register_map_type("navigation", navigation_map_new);