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;
73 struct callback *route_cb;
74 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)
147 struct navigation *ret=g_new0(struct navigation, 1);
148 ret->hash=item_hash_new();
149 ret->callback=callback_list_new();
150 ret->callback_speech=callback_list_new();
152 ret->distance_turn=50;
153 ret->turn_around_limit=3;
154 ret->navit=parent->u.navit;
155 ret->tell_street_name=1;
157 for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
158 for (i = 0 ; i < 3 ; i++) {
159 ret->announce[j][i]=-1;
163 if ((attr=attr_search(attrs, NULL, attr_tell_street_name))) {
164 ret->tell_street_name = attr->u.num;
171 navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
174 if (type < route_item_first || type > route_item_last) {
175 dbg(0,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
178 for (i = 0 ; i < 3 ; i++)
179 this_->announce[type-route_item_first][i]=level[i];
184 navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
188 if (type < route_item_first || type > route_item_last)
190 for (i = 0 ; i < 3 ; i++) {
191 if (dist <= this_->announce[type-route_item_first][i])
198 * @brief Holds a way that one could possibly drive from a navigation item
200 struct navigation_way {
201 struct navigation_way *next; /**< Pointer to a linked-list of all navigation_ways from this navigation item */
202 short dir; /**< The direction -1 or 1 of the way */
203 short angle2; /**< The angle one has to steer to drive from the old item to this street */
204 int flags; /**< The flags of the way */
205 struct item item; /**< The item of the way */
210 struct navigation_itm {
217 struct coord start,end;
222 int told; /**< Indicates if this item's announcement has been told earlier and should not be told again*/
223 int streetname_told; /**< Indicates if this item's streetname has been told in speech navigation*/
226 struct navigation_itm *next;
227 struct navigation_itm *prev;
228 struct navigation_way *ways; /**< Pointer to all ways one could drive from here */
233 road_angle(struct coord *c1, struct coord *c2, int dir)
235 int ret=transform_get_angle_delta(c1, c2, dir);
236 dbg(1, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d\n", c1->x, c1->y, c2->x, c2->y, ret);
241 *get_count_str(int n)
245 return _("zeroth"); // Not shure if this exists, neither if it will ever be needed
264 *get_exit_count_str(int n)
268 return _("zeroth exit"); // Not shure if this exists, neither if it will ever be needed
270 return _("first exit");
272 return _("second exit");
274 return _("third exit");
276 return _("fourth exit");
278 return _("fifth exit");
280 return _("sixth exit");
286 round_distance(int dist)
309 dist=(dist+500)/1000;
312 dist=(dist+5000)/10000;
317 get_distance(int dist, enum attr_type type, int is_length)
319 if (type == attr_navigation_long) {
321 return g_strdup_printf(_("%d m"), dist);
323 return g_strdup_printf(_("in %d m"), dist);
327 return g_strdup_printf(_("%d meters"), dist);
329 return g_strdup_printf(_("in %d meters"), dist);
332 int rem=(dist/100)%10;
335 return g_strdup_printf(_("%d.%d kilometer"), dist/1000, rem);
337 return g_strdup_printf(_("in %d.%d kilometers"), dist/1000, rem);
341 return g_strdup_printf(ngettext("one kilometer","%d kilometers", dist/1000), dist/1000);
343 return g_strdup_printf(ngettext("in one kilometer","in %d kilometers", dist/1000), dist/1000);
348 * @brief This calculates the angle with which an item starts or ends
350 * This function can be used to get the angle an item (from a route graph map)
351 * starts or ends with. Note that the angle will point towards the inner of
354 * This is meant to be used with items from a route graph map
355 * With other items this will probably not be optimal...
357 * @param w The way which should be calculated
360 calculate_angle(struct navigation_way *w)
362 struct coord cbuf[2];
363 struct item *ritem; // the "real" item
369 mr = map_rect_new(w->item.map, NULL);
373 ritem = map_rect_get_item_byid(mr, w->item.id_hi, w->item.id_lo);
375 dbg(1,"Item from segment not found on map!\n");
376 map_rect_destroy(mr);
380 if (ritem->type < type_line || ritem->type >= type_area) {
381 map_rect_destroy(mr);
384 if (item_attr_get(ritem, attr_flags, &attr))
388 if (item_attr_get(ritem, attr_street_name, &attr))
389 w->name1=map_convert_string(ritem->map,attr.u.str);
392 if (item_attr_get(ritem, attr_street_name_systematic, &attr))
393 w->name2=map_convert_string(ritem->map,attr.u.str);
398 if (item_coord_get(ritem, cbuf, 2) != 2) {
399 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
400 map_rect_destroy(mr);
404 while (item_coord_get(ritem, &c, 1)) {
410 if (item_coord_get(ritem, cbuf, 2) != 2) {
411 dbg(1,"Using calculate_angle() with a less-than-two-coords-item?\n");
412 map_rect_destroy(mr);
420 map_rect_destroy(mr);
422 w->angle2=road_angle(&cbuf[1],&cbuf[0],0);
426 * @brief Returns the time (in seconds) one will drive between two navigation items
428 * This function returns the time needed to drive between two items, including both of them,
431 * @param from The first item
432 * @param to The last item
433 * @return The travel time in seconds, or -1 on error
436 navigation_time(struct navigation_itm *from, struct navigation_itm *to)
438 struct navigation_itm *cur;
460 * @brief Clears the ways one can drive from itm
462 * @param itm The item that should have its ways cleared
465 navigation_itm_ways_clear(struct navigation_itm *itm)
467 struct navigation_way *c,*n;
472 map_convert_free(c->name1);
473 map_convert_free(c->name2);
482 * @brief Updates the ways one can drive from itm
484 * This updates the list of possible ways to drive to from itm. The item "itm" is on
485 * and the next navigation item are excluded.
487 * @param itm The item that should be updated
488 * @param graph_map The route graph's map that these items are on
491 navigation_itm_ways_update(struct navigation_itm *itm, struct map *graph_map)
493 struct map_selection coord_sel;
494 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
495 struct item *i,*sitem;
496 struct attr sitem_attr,direction_attr;
497 struct navigation_way *w,*l;
499 navigation_itm_ways_clear(itm);
501 // These values cause the code in route.c to get us only the route graph point and connected segments
502 coord_sel.next = NULL;
503 coord_sel.u.c_rect.lu = itm->start;
504 coord_sel.u.c_rect.rl = itm->start;
505 // the selection's order is ignored
507 g_rect = map_rect_new(graph_map, &coord_sel);
509 i = map_rect_get_item(g_rect);
510 if (!i || i->type != type_rg_point) { // probably offroad?
517 i = map_rect_get_item(g_rect);
523 if (i->type != type_rg_segment) {
527 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
528 dbg(1, "Got no street item for route graph item in entering_straight()\n");
532 if (!item_attr_get(i,attr_direction,&direction_attr)) {
536 sitem = sitem_attr.u.item;
537 if (item_is_equal(itm->item,*sitem) || ((itm->prev) && item_is_equal(itm->prev->item,*sitem))) {
542 w = g_new(struct navigation_way, 1);
543 w->dir = direction_attr.u.num;
549 map_rect_destroy(g_rect);
555 navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end)
557 struct navigation_itm *itm;
558 struct navigation_command *cmd;
559 dbg(2,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p\n", this_, this_->first, this_->cmd_first, end);
560 if (this_->cmd_first)
561 dbg(2,"this_->cmd_first->itm=%p\n", this_->cmd_first->itm);
562 while (this_->first && this_->first != end) {
564 dbg(3,"destroying %p\n", itm);
565 item_hash_remove(this_->hash, &itm->item);
566 this_->first=itm->next;
568 this_->first->prev=NULL;
569 if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
570 cmd=this_->cmd_first;
571 this_->cmd_first=cmd->next;
573 cmd->next->prev = NULL;
577 map_convert_free(itm->name1);
578 map_convert_free(itm->name2);
579 navigation_itm_ways_clear(itm);
584 if (! this_->first && end)
585 dbg(0,"end wrong\n");
586 dbg(2,"ret this_->first=%p this_->cmd_first=%p\n",this_->first, this_->cmd_first);
590 navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
592 struct attr length, time;
594 if (! item_attr_get(ritem, attr_length, &length)) {
595 dbg(0,"no length\n");
598 if (! item_attr_get(ritem, attr_time, &time)) {
603 dbg(1,"length=%d time=%d\n", length.u.num, time.u.num);
604 itm->length=length.u.num;
605 itm->time=time.u.num;
609 * @brief This check if an item is part of a roundabout
611 * @param itm The item to be checked
612 * @return True if the item is part of a roundabout
615 check_roundabout(struct navigation_itm *itm, struct map *graph_map)
617 struct map_selection coord_sel;
618 struct map_rect *g_rect; // Contains a map rectangle from the route graph's map
619 struct item *i,*sitem;
620 struct attr sitem_attr,flags_attr;
622 // These values cause the code in route.c to get us only the route graph point and connected segments
623 coord_sel.next = NULL;
624 coord_sel.u.c_rect.lu = itm->start;
625 coord_sel.u.c_rect.rl = itm->start;
626 // the selection's order is ignored
628 g_rect = map_rect_new(graph_map, &coord_sel);
630 i = map_rect_get_item(g_rect);
631 if (!i || i->type != type_rg_point) { // probably offroad?
636 i = map_rect_get_item(g_rect);
642 if (i->type != type_rg_segment) {
646 if (!item_attr_get(i,attr_street_item,&sitem_attr)) {
650 sitem = sitem_attr.u.item;
651 if (item_is_equal(itm->item,*sitem)) {
652 if (item_attr_get(i,attr_flags,&flags_attr) && (flags_attr.u.num & AF_ROUNDABOUT)) {
653 map_rect_destroy(g_rect);
659 map_rect_destroy(g_rect);
663 static struct navigation_itm *
664 navigation_itm_new(struct navigation *this_, struct item *ritem)
666 struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
669 struct map *graph_map = NULL;
670 struct attr street_item,direction,route_attr;
676 ret->streetname_told=0;
677 if (! item_attr_get(ritem, attr_street_item, &street_item)) {
678 dbg(1, "no street item\n");
681 if (item_attr_get(ritem, attr_direction, &direction))
682 ret->direction=direction.u.num;
686 sitem=street_item.u.item;
688 item_hash_insert(this_->hash, sitem, ret);
689 mr=map_rect_new(sitem->map, NULL);
690 sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
691 if (item_attr_get(sitem, attr_street_name, &attr))
692 ret->name1=map_convert_string(sitem->map,attr.u.str);
693 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
694 ret->name2=map_convert_string(sitem->map,attr.u.str);
695 navigation_itm_update(ret, ritem);
697 while (item_coord_get(ritem, &c[i], 1)) {
698 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
707 dbg(1,"count=%d\n", i);
710 ret->angle_start=road_angle(&c[0], &c[1], 0);
711 ret->angle_end=road_angle(&c[i-1], &c[i], 0);
716 item_attr_get(ritem, attr_route, &route_attr);
717 graph_map = route_get_graph_map(route_attr.u.route);
718 if (check_roundabout(ret, graph_map)) {
719 ret->flags |= AF_ROUNDABOUT;
722 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
723 map_rect_destroy(mr);
726 ret->start=ret->end=this_->last->end;
731 this_->last->next=ret;
732 ret->prev=this_->last;
734 navigation_itm_ways_update(ret,graph_map);
737 dbg(1,"ret=%p\n", ret);
743 * @brief Counts how many times a driver could turn right/left
745 * This function counts how many times the driver theoretically could
746 * turn right/left between two navigation items, not counting the final
749 * @param from The navigation item which should form the start
750 * @param to The navigation item which should form the end
751 * @param direction Set to < 0 to count turns to the left >= 0 for turns to the right
752 * @return The number of possibilities to turn or -1 on error
755 count_possible_turns(struct navigation_itm *from, struct navigation_itm *to, int direction)
758 struct navigation_itm *curr;
759 struct navigation_way *w;
763 while (curr && (curr != to)) {
768 if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
773 if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
783 if (!curr) { // from does not lead to to?
791 * @brief Calculates distance and time to the destination
793 * This function calculates the distance and the time to the destination of a
794 * navigation. If incr is set, this is only calculated for the first navigation
795 * item, which is a lot faster than re-calculation the whole destination, but works
796 * only if the rest of the navigation already has been calculated.
798 * @param this_ The navigation whose destination / time should be calculated
799 * @param incr Set this to true to only calculate the first item. See description.
802 calculate_dest_distance(struct navigation *this_, int incr)
804 int len=0, time=0, count=0;
805 struct navigation_itm *next,*itm=this_->last;
806 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
809 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
811 dbg(2, "old values: itm is null\n");
814 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
815 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
816 itm->dest_length=next->dest_length+itm->length;
817 itm->dest_count=next->dest_count+1;
818 itm->dest_time=next->dest_time+itm->time;
819 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
825 itm->dest_length=len;
827 itm->dest_count=count++;
830 dbg(1,"len %d time %d\n", len, time);
834 * @brief Checks if two navigation items are on the same street
836 * This function checks if two navigation items are on the same street. It returns
837 * true if either their name or their "systematic name" (e.g. "A6" or "B256") are the
840 * @param old The first item to be checked
841 * @param new The second item to be checked
842 * @return True if both old and new are on the same street
845 is_same_street2(char *old_name1, char *old_name2, char *new_name1, char *new_name2)
847 if (old_name1 && new_name1 && !strcmp(old_name1, new_name1)) {
848 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old_name2, new_name2, old_name1, new_name1);
851 if (old_name2 && new_name2 && !strcmp(old_name2, new_name2)) {
852 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old_name2, new_name2, old_name1, new_name1);
855 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old_name2, new_name2, old_name1, new_name1);
861 * @brief Checks if two navigation items are on the same street
863 * This function checks if two navigation items are on the same street. It returns
864 * true if the first part of their "systematic name" is equal. If the "systematic name" is
865 * for example "A352/E3" (a german highway which at the same time is part of the international
866 * E-road network), it would only search for "A352" in the second item's systematic name.
868 * @param old The first item to be checked
869 * @param new The second item to be checked
870 * @return True if the "systematic name" of both items matches. See description.
873 is_same_street_systematic(struct navigation_itm *old, struct navigation_itm *new)
875 int slashold,slashnew;
876 if (!old->name2 || !new->name2)
878 slashold=strcspn(old->name2, "/");
879 slashnew=strcspn(new->name2, "/");
880 if (slashold != slashnew || strncmp(old->name2, new->name2, slashold))
887 * @brief Check if there are multiple possibilities to drive from old
889 * This function checks, if there are multiple streets connected to the exit of "old".
890 * Sometimes it happens that an item on a map is just segmented, without any other streets
891 * being connected there, and it is not useful if navit creates a maneuver there.
893 * @param new The navigation item we're driving to
894 * @return True if there are multiple streets
897 maneuver_multiple_streets(struct navigation_itm *new)
908 * @brief Check if the new item is entered "straight"
910 * This function checks if the new item is entered "straight" from the old item, i.e. if there
911 * is no other street one could take from the old item on with less steering.
913 * @param new The navigation item we're driving to
914 * @param diff The absolute angle one needs to steer to drive to this item
915 * @return True if the new item is entered "straight"
918 maneuver_straight(struct navigation_itm *new, int diff)
921 struct navigation_way *w;
924 dbg(1,"diff=%d\n", diff);
926 curr_diff=abs(angle_delta(new->prev->angle_end, w->angle2));
927 dbg(1,"curr_diff=%d\n", curr_diff);
928 if (curr_diff < diff) {
937 static int maneuver_category(enum item_type type)
942 case type_street_1_city:
944 case type_street_2_city:
946 case type_street_3_city:
948 case type_street_4_city:
950 case type_highway_city:
952 case type_street_1_land:
954 case type_street_2_land:
956 case type_street_3_land:
958 case type_street_4_land:
960 case type_street_n_lanes:
962 case type_highway_land:
966 case type_roundabout:
978 is_way_allowed(struct navigation_way *way)
981 if (way->flags & AF_ONEWAYREV)
984 if (way->flags & AF_ONEWAY)
991 * @brief Checks if navit has to create a maneuver to drive from old to new
993 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
994 * from "old" to "new".
996 * @param old The old navigation item, where we're coming from
997 * @param new The new navigation item, where we're going to
998 * @param delta The angle the user has to steer to navigate from old to new
999 * @param reason A text string explaining how the return value resulted
1000 * @return True if navit should guide the user, false otherwise
1003 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta, char **reason)
1005 int ret=0,d,dw,dlim;
1007 struct navigation_way *w;
1008 int cat,ncat,wcat,maxcat,left=-180,right=180,is_unambigous=0,is_same_street;
1010 dbg(1,"enter %p %p %p\n",old, new, delta);
1011 d=angle_delta(old->angle_end, new->angle_start);
1013 /* No announcement necessary */
1014 r="no: Only one possibility";
1015 } else if (!new->ways->next && new->ways->item.type == type_ramp && !is_way_allowed(new->ways)) {
1016 /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
1020 if ((old->flags & AF_ROUNDABOUT) && ! (new->flags & AF_ROUNDABOUT)) {
1021 r="yes: leaving roundabout";
1023 } else if (!(old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1024 r="no: entering roundabout";
1025 else if ((old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1026 r="no: staying in roundabout";
1028 if (!r && abs(d) > 75) {
1029 /* always make an announcement if you have to make a sharp turn */
1030 r="yes: delta over 75";
1033 cat=maneuver_category(old->item.type);
1034 ncat=maneuver_category(new->item.type);
1036 /* Check whether the street keeps its name */
1037 is_same_street=is_same_street2(old->name1, old->name2, new->name1, new->name2);
1041 dw=angle_delta(old->angle_end, w->angle2);
1049 wcat=maneuver_category(w->item.type);
1050 /* If any other street has the same name but isn't a highway (a highway might split up temporarily), then
1051 we can't use the same name criterium */
1052 if (is_same_street && is_same_street2(old->name1, old->name2, w->name1, w->name2) && (cat != 7 || wcat != 7) && is_way_allowed(w))
1054 /* Mark if the street has a higher or the same category */
1059 /* get the delta limit for checking for other streets. It is lower if the street has no other
1060 streets of the same or higher category */
1065 /* if the street is really straight, the others might be closer to straight */
1068 if ((maxcat == ncat && maxcat == cat) || (ncat == 0 && cat == 0))
1069 dlim=abs(d)*620/256;
1070 else if (maxcat < ncat && maxcat < cat)
1071 dlim=abs(d)*128/256;
1072 if (left < -dlim && right > dlim)
1074 if (!is_same_street && is_unambigous < 1) {
1076 r="yes: not same street or ambigous";
1078 r="no: same street and unambigous";
1080 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);
1090 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
1091 if (is_same_street2(old, new)) {
1092 if (! entering_straight(new, abs(*delta))) {
1093 dbg(1, "maneuver_required: Not driving straight: yes\n");
1095 *reason="yes: Not driving straight";
1099 if (check_multiple_streets(new)) {
1100 if (entering_straight(new,abs(*delta)*2)) {
1102 *reason="no: delta < ext_limit for same name";
1106 *reason="yes: delta > ext_limit for same name";
1109 dbg(1, "maneuver_required: Staying on the same street: no\n");
1111 *reason="no: Staying on same street";
1116 dbg(1, "maneuver_required: old or new is ramp\n");
1118 if (old->item.type == type_ramp && (new->item.type == type_highway_city || new->item.type == type_highway_land)) {
1119 dbg(1, "no_maneuver_required: old is ramp new is highway\n");
1121 *reason="no: old is ramp new is highway";
1126 if (old->crossings_end == 2) {
1127 dbg(1, "maneuver_required: only 2 connections: no\n");
1131 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
1132 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))) {
1133 dbg(1, "maneuver_required: highway changed name\n");
1135 *reason="yes: highway changed name";
1138 if (abs(*delta) < straight_limit) {
1139 if (! entering_straight(new,abs(*delta))) {
1141 *reason="yes: not straight";
1142 dbg(1, "maneuver_required: not driving straight: yes\n");
1146 dbg(1, "maneuver_required: delta(%d) < %d: no\n", *delta, straight_limit);
1148 *reason="no: delta < limit";
1151 if (abs(*delta) < ext_straight_limit) {
1152 if (entering_straight(new,abs(*delta)*2)) {
1154 *reason="no: delta < ext_limit";
1159 if (! check_multiple_streets(new)) {
1160 dbg(1, "maneuver_required: only one possibility: no\n");
1162 *reason="no: only one possibility";
1166 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
1168 *reason="yes: delta >= limit";
1173 static struct navigation_command *
1174 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
1176 struct navigation_command *ret=g_new0(struct navigation_command, 1);
1177 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
1180 if (itm && itm->prev && itm->ways && itm->prev->ways && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
1184 struct navigation_itm *itm2=itm->prev;
1185 int exit_angle=angle_median(itm->prev->angle_end, itm->ways->angle2);
1186 dbg(1,"exit %d median from %d,%d\n", exit_angle,itm->prev->angle_end, itm->ways->angle2);
1187 while (itm2 && (itm2->flags & AF_ROUNDABOUT)) {
1189 angle=itm2->angle_end;
1192 if (itm2 && itm2->next && itm2->next->ways) {
1194 entry_angle=angle_median(angle_opposite(itm2->angle_start), itm2->ways->angle2);
1195 dbg(1,"entry %d median from %d(%d),%d\n", entry_angle,angle_opposite(itm2->angle_start), itm2->angle_start, itm2->ways->angle2);
1197 entry_angle=angle_opposite(angle);
1199 dbg(0,"entry %d exit %d\n", entry_angle, exit_angle);
1200 ret->roundabout_delta=angle_delta(entry_angle, exit_angle);
1204 if (this_->cmd_last) {
1205 this_->cmd_last->next=ret;
1206 ret->prev = this_->cmd_last;
1208 this_->cmd_last=ret;
1210 if (!this_->cmd_first)
1211 this_->cmd_first=ret;
1216 make_maneuvers(struct navigation *this_, struct route *route)
1218 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
1221 this_->cmd_last=NULL;
1222 this_->cmd_first=NULL;
1225 if (maneuver_required2(last_itm, itm,&delta,NULL)) {
1226 command_new(this_, itm, delta);
1233 command_new(this_, last_itm, 0);
1237 contains_suffix(char *name, char *suffix)
1241 if (strlen(name) < strlen(suffix))
1243 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
1247 replace_suffix(char *name, char *search, char *replace)
1249 int len=strlen(name)-strlen(search);
1250 char *ret=g_malloc(len+strlen(replace)+1);
1251 strncpy(ret, name, len);
1252 strcpy(ret+len, replace);
1253 if (isupper(name[len])) {
1254 ret[len]=toupper(ret[len]);
1261 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
1263 char *ret=NULL,*name1,*sep,*name2;
1267 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
1268 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
1270 if(next->item.type == type_ramp)
1272 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
1273 return g_strdup_printf("%s%s",prefix,_("exit")); /* %FIXME Can this even be reached? */
1275 return g_strdup_printf("%s%s",prefix,_("into the ramp"));
1278 if (!itm->name1 && !itm->name2)
1283 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
1284 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
1285 sex=suffixes[i].sex;
1286 name1=g_strdup(itm->name1);
1289 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
1290 sex=suffixes[i].sex;
1291 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
1304 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
1305 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
1308 /* 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 */
1309 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
1312 /* 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 */
1313 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
1316 /* 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 */
1317 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
1323 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
1324 ret=g_strdup_printf(_("%sinto the %s"),prefix,itm->name2);
1326 while (name1 && *name1) {
1342 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type, int connect)
1344 /* TRANSLATORS: right, as in 'Turn right' */
1345 char *dir=_("right"),*strength="";
1346 int distance=itm->dest_length-cmd->itm->dest_length;
1348 int delta=cmd->delta;
1350 int strength_needed;
1352 int count_roundabout;
1353 struct navigation_itm *cur;
1354 struct navigation_way *w;
1357 level = -2; // level = -2 means "connect to another maneuver via 'then ...'"
1362 w = itm->next->ways;
1363 strength_needed = 0;
1364 if (angle_delta(itm->next->angle_start,itm->angle_end) < 0) {
1366 if (angle_delta(w->angle2,itm->angle_end) < 0) {
1367 strength_needed = 1;
1374 if (angle_delta(w->angle2,itm->angle_end) > 0) {
1375 strength_needed = 1;
1383 /* TRANSLATORS: left, as in 'Turn left' */
1388 if (strength_needed) {
1390 /* TRANSLATORS: Don't forget the ending space */
1391 strength=_("easily ");
1392 } else if (delta < 105) {
1394 } else if (delta < 165) {
1395 /* TRANSLATORS: Don't forget the ending space */
1396 strength=_("strongly ");
1397 } else if (delta < 180) {
1398 /* TRANSLATORS: Don't forget the ending space */
1399 strength=_("really strongly ");
1401 dbg(1,"delta=%d\n", delta);
1402 /* TRANSLATORS: Don't forget the ending space */
1403 strength=_("unknown ");
1406 if (type != attr_navigation_long_exact)
1407 distance=round_distance(distance);
1408 if (type == attr_navigation_speech) {
1409 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
1410 return g_strdup(_("When possible, please turn around"));
1412 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1414 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
1417 if (cmd->itm->prev->flags & AF_ROUNDABOUT) {
1420 return g_strdup(_("Enter the roundabout soon"));
1422 d = get_distance(distance, type, 1);
1423 /* TRANSLATORS: %s is the distance to the roundabout */
1424 ret = g_strdup_printf(_("In %s, enter the roundabout"), d);
1429 cur = cmd->itm->prev;
1430 count_roundabout = 0;
1431 while (cur && (cur->flags & AF_ROUNDABOUT)) {
1432 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
1439 ret = g_strdup_printf(_("Leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1442 ret = g_strdup_printf(_("then leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1451 d=get_distance(distance, type, 1);
1452 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
1456 d=g_strdup(_("soon"));
1459 d=get_distance(distance, type, 0);
1462 skip_roads = count_possible_turns(nav->first,cmd->itm,cmd->delta);
1463 if (skip_roads > 0) {
1464 if (get_count_str(skip_roads+1)) {
1465 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1466 ret = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1469 d = g_strdup_printf(_("after %i roads"), skip_roads);
1472 d=g_strdup(_("now"));
1476 skip_roads = count_possible_turns(cmd->prev->itm,cmd->itm,cmd->delta);
1477 if (skip_roads > 0) {
1478 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1479 if (get_count_str(skip_roads+1)) {
1480 ret = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1483 d = g_strdup_printf(_("after %i roads"), skip_roads);
1491 d=g_strdup(_("error"));
1493 if (cmd->itm->next) {
1494 int tellstreetname = 0;
1495 char *destination = NULL;
1497 if(type == attr_navigation_speech) { // In voice mode
1498 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
1501 if (level == 1) { // we are close to the intersection
1502 cmd->itm->streetname_told = 1; // remeber to be checked when we turn
1503 tellstreetname = 1; // Ok so we tell the name of the street
1507 if(cmd->itm->streetname_told == 0) // we are right at the intersection
1510 cmd->itm->streetname_told = 0; // reset just in case we come to the same street again
1517 if(nav->tell_street_name && tellstreetname)
1518 destination=navigation_item_destination(cmd->itm, itm, " ");
1521 /* 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' */
1522 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1524 /* TRANSLATORS: First argument is strength, second direction, third how many roads to skip, fourth destination */
1525 ret=g_strdup_printf(_("then turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1527 g_free(destination);
1530 ret=g_strdup_printf(_("You have reached your destination %s"), d);
1532 ret=g_strdup_printf(_("then you have reached your destination."));
1540 * @brief Creates announcements for maneuvers, plus maneuvers immediately following the next maneuver
1542 * This function does create an announcement for the current maneuver and for maneuvers
1543 * immediately following that maneuver, if these are too close and we're in speech navigation.
1545 * @return An announcement that should be made
1548 show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
1550 struct navigation_command *cur,*prev;
1551 int distance=itm->dest_length-cmd->itm->dest_length;
1552 int level, dist, i, time;
1553 int speech_time,time2nav;
1554 char *ret,*old,*buf,*next;
1556 if (type != attr_navigation_speech) {
1557 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only in speech navigation
1560 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1563 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only if they are close
1566 if (cmd->itm->told) {
1567 return g_strdup("");
1570 ret = show_maneuver(nav, itm, cmd, type, 0);
1571 time2nav = navigation_time(itm,cmd->itm->prev);
1577 while (cur && cur->itm) {
1578 // We don't merge more than 3 announcements...
1579 if (i > 1) { // if you change this, please also change the value below, that is used to terminate the loop
1583 next = show_maneuver(nav,prev->itm, cur, type, 0);
1584 speech_time = navit_speech_estimate(nav->navit,next);
1587 if (speech_time == -1) { // user didn't set cps
1588 speech_time = 30; // assume 3 seconds
1591 dist = prev->itm->dest_length - cur->itm->dest_length;
1592 time = navigation_time(prev->itm,cur->itm->prev);
1594 if (time >= (speech_time + 30)) { // 3 seconds for understanding what has been said
1599 buf = show_maneuver(nav, prev->itm, cur, type, 1);
1600 ret = g_strdup_printf("%s, %s", old, buf);
1602 if (navit_speech_estimate(nav->navit,ret) > time2nav) {
1605 i = 2; // This will terminate the loop
1610 // If the two maneuvers are *really* close, we shouldn't tell the second one again, because TTS won't be fast enough
1611 if (time <= speech_time) {
1624 navigation_call_callbacks(struct navigation *this_, int force_speech)
1626 int distance, level = 0, level2;
1628 if (!this_->cmd_first)
1630 callback_list_call(this_->callback, 1, &p);
1631 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
1632 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
1633 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
1634 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
1635 while (distance > this_->distance_turn) {
1636 this_->level_last=4;
1639 if (this_->distance_turn >= 500)
1640 this_->distance_turn*=2;
1642 this_->distance_turn=500;
1644 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
1645 this_->distance_turn=50;
1646 distance-=this_->cmd_first->length;
1647 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
1648 if (this_->cmd_first->itm->prev) {
1649 level2=navigation_get_announce_level(this_, this_->cmd_first->itm->prev->item.type, distance);
1653 if (level < this_->level_last) {
1654 dbg(1,"level %d < %d\n", level, this_->level_last);
1655 this_->level_last=level;
1658 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
1659 dbg(1,"item different\n");
1660 this_->item_last=this_->cmd_first->itm->item;
1665 this_->level_last=level;
1666 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
1667 callback_list_call(this_->callback_speech, 1, &p);
1672 navigation_update(struct navigation *this_, struct route *route, struct attr *attr)
1675 struct map_rect *mr;
1676 struct item *ritem; /* Holds an item from the route map */
1677 struct item *sitem; /* Holds the corresponding item from the actual map */
1678 struct attr street_item,street_direction;
1679 struct navigation_itm *itm;
1680 int mode=0, incr=0, first=1;
1681 if (attr->type != attr_route_status)
1684 dbg(1,"enter %d\n", mode);
1685 if (attr->u.num == route_status_no_destination || attr->u.num == route_status_not_found || attr->u.num == route_status_path_done_new)
1686 navigation_flush(this_);
1687 if (attr->u.num != route_status_path_done_new && attr->u.num != route_status_path_done_incremental)
1692 map=route_get_map(this_->route);
1695 mr=map_rect_new(map, NULL);
1699 while ((ritem=map_rect_get_item(mr))) {
1700 if (ritem->type == type_route_start && this_->turn_around > -this_->turn_around_limit+1)
1701 this_->turn_around--;
1702 if (ritem->type == type_route_start_reverse && this_->turn_around < this_->turn_around_limit)
1703 this_->turn_around++;
1704 if (ritem->type != type_street_route)
1706 if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
1708 if (!item_attr_get(ritem, attr_direction, &street_direction))
1709 street_direction.u.num=0;
1710 sitem=street_item.u.item;
1711 dbg(1,"sitem=%p\n", sitem);
1712 itm=item_hash_lookup(this_->hash, sitem);
1713 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
1714 if (itm && itm->direction != street_direction.u.num) {
1715 dbg(2,"wrong direction\n");
1718 navigation_destroy_itms_cmds(this_, itm);
1720 navigation_itm_update(itm, ritem);
1723 dbg(1,"not on track\n");
1725 navigation_itm_new(this_, ritem);
1727 dbg(2,"turn_around=%d\n", this_->turn_around);
1729 navigation_destroy_itms_cmds(this_, NULL);
1732 navigation_itm_new(this_, NULL);
1733 make_maneuvers(this_,this_->route);
1735 calculate_dest_distance(this_, incr);
1737 navigation_call_callbacks(this_, FALSE);
1739 map_rect_destroy(mr);
1743 navigation_flush(struct navigation *this_)
1745 navigation_destroy_itms_cmds(this_, NULL);
1750 navigation_destroy(struct navigation *this_)
1752 navigation_flush(this_);
1753 item_hash_destroy(this_->hash);
1754 callback_list_destroy(this_->callback);
1755 callback_list_destroy(this_->callback_speech);
1760 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1762 if (type == attr_navigation_speech)
1763 callback_list_add(this_->callback_speech, cb);
1765 callback_list_add(this_->callback, cb);
1770 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1772 if (type == attr_navigation_speech)
1773 callback_list_remove_destroy(this_->callback_speech, cb);
1775 callback_list_remove_destroy(this_->callback, cb);
1779 navigation_get_map(struct navigation *this_)
1782 this_->map=map_new(NULL, (struct attr*[]){
1783 &(struct attr){attr_type,{"navigation"}},
1784 &(struct attr){attr_navigation,.u.navigation=this_},
1785 &(struct attr){attr_data,{""}},
1786 &(struct attr){attr_description,{"Navigation"}},
1792 struct navigation *navigation;
1795 struct map_rect_priv {
1796 struct navigation *nav;
1797 struct navigation_command *cmd;
1798 struct navigation_command *cmd_next;
1799 struct navigation_itm *itm;
1800 struct navigation_itm *itm_next;
1801 struct navigation_itm *cmd_itm;
1802 struct navigation_itm *cmd_itm_next;
1804 enum attr_type attr_next;
1807 struct navigation_way *ways;
1813 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
1815 struct map_rect_priv *this=priv_data;
1816 if (this->ccount || ! count)
1818 *c=this->itm->start;
1824 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
1826 struct map_rect_priv *this_=priv_data;
1827 attr->type=attr_type;
1828 struct navigation_command *cmd=this_->cmd;
1829 struct navigation_itm *itm=this_->itm;
1830 struct navigation_itm *prev=itm->prev;
1838 if (cmd->itm != itm)
1842 case attr_navigation_short:
1843 this_->attr_next=attr_navigation_long;
1845 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1849 case attr_navigation_long:
1850 this_->attr_next=attr_navigation_long_exact;
1852 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1856 case attr_navigation_long_exact:
1857 this_->attr_next=attr_navigation_speech;
1859 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1863 case attr_navigation_speech:
1864 this_->attr_next=attr_length;
1866 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
1871 this_->attr_next=attr_time;
1873 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
1878 this_->attr_next=attr_destination_length;
1880 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
1884 case attr_destination_length:
1885 attr->u.num=itm->dest_length;
1886 this_->attr_next=attr_destination_time;
1888 case attr_destination_time:
1889 attr->u.num=itm->dest_time;
1890 this_->attr_next=attr_street_name;
1892 case attr_street_name:
1893 attr->u.str=itm->name1;
1894 this_->attr_next=attr_street_name_systematic;
1898 case attr_street_name_systematic:
1899 attr->u.str=itm->name2;
1900 this_->attr_next=attr_debug;
1905 switch(this_->debug_idx) {
1908 this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->angle_start, itm->angle_end);
1912 this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->item.type));
1917 this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
1923 this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->name1);
1929 this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->name2);
1935 this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->angle_start, prev->angle_end);
1940 this_->ways=itm->ways;
1942 this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->item.type));
1946 if (this_->ways && prev) {
1947 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);
1948 this_->ways=this_->ways->next;
1957 maneuver_required2(prev, itm, &delta, &reason);
1958 this_->str=attr->u.str=g_strdup_printf("reason:%s",reason);
1963 this_->attr_next=attr_none;
1967 while (this_->attr_next != attr_none) {
1968 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
1973 attr->type=attr_none;
1978 static struct item_methods navigation_map_item_methods = {
1980 navigation_map_item_coord_get,
1982 navigation_map_item_attr_get,
1987 navigation_map_destroy(struct map_priv *priv)
1993 navigation_map_rect_init(struct map_rect_priv *priv)
1995 priv->cmd_next=priv->nav->cmd_first;
1996 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
1999 static struct map_rect_priv *
2000 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
2002 struct navigation *nav=priv->navigation;
2003 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
2005 navigation_map_rect_init(ret);
2006 ret->item.meth=&navigation_map_item_methods;
2007 ret->item.priv_data=ret;
2015 navigation_map_rect_destroy(struct map_rect_priv *priv)
2020 static struct item *
2021 navigation_map_get_item(struct map_rect_priv *priv)
2023 struct item *ret=&priv->item;
2025 if (!priv->itm_next)
2027 priv->itm=priv->itm_next;
2028 priv->cmd=priv->cmd_next;
2029 priv->cmd_itm=priv->cmd_itm_next;
2032 if (!priv->show_all && priv->itm->prev != NULL)
2033 priv->itm=priv->cmd->itm;
2034 priv->itm_next=priv->itm->next;
2035 if (priv->itm->prev)
2036 ret->type=type_nav_none;
2038 ret->type=type_nav_position;
2039 if (priv->cmd->itm == priv->itm) {
2040 priv->cmd_itm_next=priv->cmd->itm;
2041 priv->cmd_next=priv->cmd->next;
2042 if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
2043 ret->type=type_nav_destination;
2045 if (priv->itm && priv->itm->prev && !(priv->itm->flags & AF_ROUNDABOUT) && (priv->itm->prev->flags & AF_ROUNDABOUT)) {
2047 switch (((180+22)-priv->cmd->roundabout_delta)/45) {
2050 ret->type=type_nav_roundabout_r1;
2053 ret->type=type_nav_roundabout_r2;
2056 ret->type=type_nav_roundabout_r3;
2059 ret->type=type_nav_roundabout_r4;
2062 ret->type=type_nav_roundabout_r5;
2065 ret->type=type_nav_roundabout_r6;
2068 ret->type=type_nav_roundabout_r7;
2071 ret->type=type_nav_roundabout_r8;
2075 delta=priv->cmd->delta;
2079 ret->type=type_nav_left_1;
2080 else if (delta < 105)
2081 ret->type=type_nav_left_2;
2082 else if (delta < 165)
2083 ret->type=type_nav_left_3;
2085 ret->type=type_none;
2088 ret->type=type_nav_right_1;
2089 else if (delta < 105)
2090 ret->type=type_nav_right_2;
2091 else if (delta < 165)
2092 ret->type=type_nav_right_3;
2094 ret->type=type_none;
2101 priv->attr_next=attr_navigation_short;
2103 ret->id_lo=priv->itm->dest_count;
2104 dbg(1,"type=%d\n", ret->type);
2108 static struct item *
2109 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
2112 navigation_map_rect_init(priv);
2113 while ((ret=navigation_map_get_item(priv))) {
2114 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
2120 static struct map_methods navigation_map_meth = {
2123 navigation_map_destroy,
2124 navigation_map_rect_new,
2125 navigation_map_rect_destroy,
2126 navigation_map_get_item,
2127 navigation_map_get_item_byid,
2133 static struct map_priv *
2134 navigation_map_new(struct map_methods *meth, struct attr **attrs)
2136 struct map_priv *ret;
2137 struct attr *navigation_attr;
2139 navigation_attr=attr_search(attrs, NULL, attr_navigation);
2140 if (! navigation_attr)
2142 ret=g_new0(struct map_priv, 1);
2143 *meth=navigation_map_meth;
2144 ret->navigation=navigation_attr->u.navigation;
2150 navigation_set_route(struct navigation *this_, struct route *route)
2152 struct attr callback;
2154 this_->route_cb=callback_new_attr_1(callback_cast(navigation_update), attr_route_status, this_);
2155 callback.type=attr_callback;
2156 callback.u.callback=this_->route_cb;
2157 route_add_attr(route, &callback);
2161 navigation_init(void)
2163 plugin_register_map_type("navigation", navigation_map_new);