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 sure if this exists, neither if it will ever be needed
264 *get_exit_count_str(int n)
268 return _("zeroth exit"); // Not sure 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 kilometers"), 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 if (! (sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo)))
692 if (item_attr_get(sitem, attr_street_name, &attr))
693 ret->name1=map_convert_string(sitem->map,attr.u.str);
694 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
695 ret->name2=map_convert_string(sitem->map,attr.u.str);
696 navigation_itm_update(ret, ritem);
698 while (item_coord_get(ritem, &c[i], 1)) {
699 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
708 dbg(1,"count=%d\n", i);
711 ret->angle_start=road_angle(&c[0], &c[1], 0);
712 ret->angle_end=road_angle(&c[i-1], &c[i], 0);
717 item_attr_get(ritem, attr_route, &route_attr);
718 graph_map = route_get_graph_map(route_attr.u.route);
719 if (check_roundabout(ret, graph_map)) {
720 ret->flags |= AF_ROUNDABOUT;
723 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
724 map_rect_destroy(mr);
727 ret->start=ret->end=this_->last->end;
732 this_->last->next=ret;
733 ret->prev=this_->last;
735 navigation_itm_ways_update(ret,graph_map);
738 dbg(1,"ret=%p\n", ret);
744 * @brief Counts how many times a driver could turn right/left
746 * This function counts how many times the driver theoretically could
747 * turn right/left between two navigation items, not counting the final
750 * @param from The navigation item which should form the start
751 * @param to The navigation item which should form the end
752 * @param direction Set to < 0 to count turns to the left >= 0 for turns to the right
753 * @return The number of possibilities to turn or -1 on error
756 count_possible_turns(struct navigation_itm *from, struct navigation_itm *to, int direction)
759 struct navigation_itm *curr;
760 struct navigation_way *w;
764 while (curr && (curr != to)) {
769 if (angle_delta(curr->prev->angle_end, w->angle2) < 0) {
774 if (angle_delta(curr->prev->angle_end, w->angle2) > 0) {
784 if (!curr) { // from does not lead to to?
792 * @brief Calculates distance and time to the destination
794 * This function calculates the distance and the time to the destination of a
795 * navigation. If incr is set, this is only calculated for the first navigation
796 * item, which is a lot faster than re-calculation the whole destination, but works
797 * only if the rest of the navigation already has been calculated.
799 * @param this_ The navigation whose destination / time should be calculated
800 * @param incr Set this to true to only calculate the first item. See description.
803 calculate_dest_distance(struct navigation *this_, int incr)
805 int len=0, time=0, count=0;
806 struct navigation_itm *next,*itm=this_->last;
807 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
810 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
812 dbg(2, "old values: itm is null\n");
815 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
816 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
817 itm->dest_length=next->dest_length+itm->length;
818 itm->dest_count=next->dest_count+1;
819 itm->dest_time=next->dest_time+itm->time;
820 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
826 itm->dest_length=len;
828 itm->dest_count=count++;
831 dbg(1,"len %d time %d\n", len, time);
835 * @brief Checks if two navigation items are on the same street
837 * This function checks if two navigation items are on the same street. It returns
838 * true if either their name or their "systematic name" (e.g. "A6" or "B256") are the
841 * @param old The first item to be checked
842 * @param new The second item to be checked
843 * @return True if both old and new are on the same street
846 is_same_street2(char *old_name1, char *old_name2, char *new_name1, char *new_name2)
848 if (old_name1 && new_name1 && !strcmp(old_name1, new_name1)) {
849 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old_name2, new_name2, old_name1, new_name1);
852 if (old_name2 && new_name2 && !strcmp(old_name2, new_name2)) {
853 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old_name2, new_name2, old_name1, new_name1);
856 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old_name2, new_name2, old_name1, new_name1);
862 * @brief Checks if two navigation items are on the same street
864 * This function checks if two navigation items are on the same street. It returns
865 * true if the first part of their "systematic name" is equal. If the "systematic name" is
866 * for example "A352/E3" (a german highway which at the same time is part of the international
867 * E-road network), it would only search for "A352" in the second item's systematic name.
869 * @param old The first item to be checked
870 * @param new The second item to be checked
871 * @return True if the "systematic name" of both items matches. See description.
874 is_same_street_systematic(struct navigation_itm *old, struct navigation_itm *new)
876 int slashold,slashnew;
877 if (!old->name2 || !new->name2)
879 slashold=strcspn(old->name2, "/");
880 slashnew=strcspn(new->name2, "/");
881 if (slashold != slashnew || strncmp(old->name2, new->name2, slashold))
888 * @brief Check if there are multiple possibilities to drive from old
890 * This function checks, if there are multiple streets connected to the exit of "old".
891 * Sometimes it happens that an item on a map is just segmented, without any other streets
892 * being connected there, and it is not useful if navit creates a maneuver there.
894 * @param new The navigation item we're driving to
895 * @return True if there are multiple streets
898 maneuver_multiple_streets(struct navigation_itm *new)
909 * @brief Check if the new item is entered "straight"
911 * This function checks if the new item is entered "straight" from the old item, i.e. if there
912 * is no other street one could take from the old item on with less steering.
914 * @param new The navigation item we're driving to
915 * @param diff The absolute angle one needs to steer to drive to this item
916 * @return True if the new item is entered "straight"
919 maneuver_straight(struct navigation_itm *new, int diff)
922 struct navigation_way *w;
925 dbg(1,"diff=%d\n", diff);
927 curr_diff=abs(angle_delta(new->prev->angle_end, w->angle2));
928 dbg(1,"curr_diff=%d\n", curr_diff);
929 if (curr_diff < diff) {
938 static int maneuver_category(enum item_type type)
943 case type_street_1_city:
945 case type_street_2_city:
947 case type_street_3_city:
949 case type_street_4_city:
951 case type_highway_city:
953 case type_street_1_land:
955 case type_street_2_land:
957 case type_street_3_land:
959 case type_street_4_land:
961 case type_street_n_lanes:
963 case type_highway_land:
967 case type_roundabout:
979 is_way_allowed(struct navigation_way *way)
982 if (way->flags & AF_ONEWAYREV)
985 if (way->flags & AF_ONEWAY)
992 * @brief Checks if navit has to create a maneuver to drive from old to new
994 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
995 * from "old" to "new".
997 * @param old The old navigation item, where we're coming from
998 * @param new The new navigation item, where we're going to
999 * @param delta The angle the user has to steer to navigate from old to new
1000 * @param reason A text string explaining how the return value resulted
1001 * @return True if navit should guide the user, false otherwise
1004 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta, char **reason)
1006 int ret=0,d,dw,dlim;
1008 struct navigation_way *w;
1009 int cat,ncat,wcat,maxcat,left=-180,right=180,is_unambigous=0,is_same_street;
1011 dbg(1,"enter %p %p %p\n",old, new, delta);
1012 d=angle_delta(old->angle_end, new->angle_start);
1014 /* No announcement necessary */
1015 r="no: Only one possibility";
1016 } else if (!new->ways->next && new->ways->item.type == type_ramp && !is_way_allowed(new->ways)) {
1017 /* If the other way is only a ramp and it is one-way in the wrong direction, no announcement necessary */
1021 if ((old->flags & AF_ROUNDABOUT) && ! (new->flags & AF_ROUNDABOUT)) {
1022 r="yes: leaving roundabout";
1024 } else if (!(old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1025 r="no: entering roundabout";
1026 else if ((old->flags & AF_ROUNDABOUT) && (new->flags & AF_ROUNDABOUT))
1027 r="no: staying in roundabout";
1029 if (!r && abs(d) > 75) {
1030 /* always make an announcement if you have to make a sharp turn */
1031 r="yes: delta over 75";
1034 cat=maneuver_category(old->item.type);
1035 ncat=maneuver_category(new->item.type);
1037 /* Check whether the street keeps its name */
1038 is_same_street=is_same_street2(old->name1, old->name2, new->name1, new->name2);
1042 dw=angle_delta(old->angle_end, w->angle2);
1050 wcat=maneuver_category(w->item.type);
1051 /* If any other street has the same name but isn't a highway (a highway might split up temporarily), then
1052 we can't use the same name criterium */
1053 if (is_same_street && is_same_street2(old->name1, old->name2, w->name1, w->name2) && (cat != 7 || wcat != 7) && is_way_allowed(w))
1055 /* Mark if the street has a higher or the same category */
1060 /* get the delta limit for checking for other streets. It is lower if the street has no other
1061 streets of the same or higher category */
1066 /* if the street is really straight, the others might be closer to straight */
1069 if ((maxcat == ncat && maxcat == cat) || (ncat == 0 && cat == 0))
1070 dlim=abs(d)*620/256;
1071 else if (maxcat < ncat && maxcat < cat)
1072 dlim=abs(d)*128/256;
1073 if (left < -dlim && right > dlim)
1075 if (!is_same_street && is_unambigous < 1) {
1077 r="yes: not same street or ambigous";
1079 r="no: same street and unambigous";
1081 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);
1091 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
1092 if (is_same_street2(old, new)) {
1093 if (! entering_straight(new, abs(*delta))) {
1094 dbg(1, "maneuver_required: Not driving straight: yes\n");
1096 *reason="yes: Not driving straight";
1100 if (check_multiple_streets(new)) {
1101 if (entering_straight(new,abs(*delta)*2)) {
1103 *reason="no: delta < ext_limit for same name";
1107 *reason="yes: delta > ext_limit for same name";
1110 dbg(1, "maneuver_required: Staying on the same street: no\n");
1112 *reason="no: Staying on same street";
1117 dbg(1, "maneuver_required: old or new is ramp\n");
1119 if (old->item.type == type_ramp && (new->item.type == type_highway_city || new->item.type == type_highway_land)) {
1120 dbg(1, "no_maneuver_required: old is ramp new is highway\n");
1122 *reason="no: old is ramp new is highway";
1127 if (old->crossings_end == 2) {
1128 dbg(1, "maneuver_required: only 2 connections: no\n");
1132 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
1133 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))) {
1134 dbg(1, "maneuver_required: highway changed name\n");
1136 *reason="yes: highway changed name";
1139 if (abs(*delta) < straight_limit) {
1140 if (! entering_straight(new,abs(*delta))) {
1142 *reason="yes: not straight";
1143 dbg(1, "maneuver_required: not driving straight: yes\n");
1147 dbg(1, "maneuver_required: delta(%d) < %d: no\n", *delta, straight_limit);
1149 *reason="no: delta < limit";
1152 if (abs(*delta) < ext_straight_limit) {
1153 if (entering_straight(new,abs(*delta)*2)) {
1155 *reason="no: delta < ext_limit";
1160 if (! check_multiple_streets(new)) {
1161 dbg(1, "maneuver_required: only one possibility: no\n");
1163 *reason="no: only one possibility";
1167 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
1169 *reason="yes: delta >= limit";
1174 static struct navigation_command *
1175 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
1177 struct navigation_command *ret=g_new0(struct navigation_command, 1);
1178 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
1181 if (itm && itm->prev && itm->ways && itm->prev->ways && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
1185 struct navigation_itm *itm2=itm->prev;
1186 int exit_angle=angle_median(itm->prev->angle_end, itm->ways->angle2);
1187 dbg(1,"exit %d median from %d,%d\n", exit_angle,itm->prev->angle_end, itm->ways->angle2);
1188 while (itm2 && (itm2->flags & AF_ROUNDABOUT)) {
1190 angle=itm2->angle_end;
1193 if (itm2 && itm2->next && itm2->next->ways) {
1195 entry_angle=angle_median(angle_opposite(itm2->angle_start), itm2->ways->angle2);
1196 dbg(1,"entry %d median from %d(%d),%d\n", entry_angle,angle_opposite(itm2->angle_start), itm2->angle_start, itm2->ways->angle2);
1198 entry_angle=angle_opposite(angle);
1200 dbg(0,"entry %d exit %d\n", entry_angle, exit_angle);
1201 ret->roundabout_delta=angle_delta(entry_angle, exit_angle);
1205 if (this_->cmd_last) {
1206 this_->cmd_last->next=ret;
1207 ret->prev = this_->cmd_last;
1209 this_->cmd_last=ret;
1211 if (!this_->cmd_first)
1212 this_->cmd_first=ret;
1217 make_maneuvers(struct navigation *this_, struct route *route)
1219 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
1222 this_->cmd_last=NULL;
1223 this_->cmd_first=NULL;
1226 if (maneuver_required2(last_itm, itm,&delta,NULL)) {
1227 command_new(this_, itm, delta);
1234 command_new(this_, last_itm, 0);
1238 contains_suffix(char *name, char *suffix)
1242 if (strlen(name) < strlen(suffix))
1244 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
1248 replace_suffix(char *name, char *search, char *replace)
1250 int len=strlen(name)-strlen(search);
1251 char *ret=g_malloc(len+strlen(replace)+1);
1252 strncpy(ret, name, len);
1253 strcpy(ret+len, replace);
1254 if (isupper(name[len])) {
1255 ret[len]=toupper(ret[len]);
1262 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
1264 char *ret=NULL,*name1,*sep,*name2;
1268 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
1269 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
1271 if(next->item.type == type_ramp)
1273 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
1274 return g_strdup_printf("%s%s",prefix,_("exit")); /* %FIXME Can this even be reached? */
1276 return g_strdup_printf("%s%s",prefix,_("into the ramp"));
1279 if (!itm->name1 && !itm->name2)
1284 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
1285 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
1286 sex=suffixes[i].sex;
1287 name1=g_strdup(itm->name1);
1290 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
1291 sex=suffixes[i].sex;
1292 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
1305 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
1306 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
1309 /* 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 */
1310 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
1313 /* 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 */
1314 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
1317 /* 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 */
1318 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
1324 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
1325 ret=g_strdup_printf(_("%sinto the %s"),prefix,itm->name2);
1327 while (name1 && *name1) {
1343 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type, int connect)
1345 /* TRANSLATORS: right, as in 'Turn right' */
1346 char *dir=_("right"),*strength="";
1347 int distance=itm->dest_length-cmd->itm->dest_length;
1349 int delta=cmd->delta;
1351 int strength_needed;
1353 int count_roundabout;
1354 struct navigation_itm *cur;
1355 struct navigation_way *w;
1358 level = -2; // level = -2 means "connect to another maneuver via 'then ...'"
1363 w = itm->next->ways;
1364 strength_needed = 0;
1365 if (angle_delta(itm->next->angle_start,itm->angle_end) < 0) {
1367 if (angle_delta(w->angle2,itm->angle_end) < 0) {
1368 strength_needed = 1;
1375 if (angle_delta(w->angle2,itm->angle_end) > 0) {
1376 strength_needed = 1;
1384 /* TRANSLATORS: left, as in 'Turn left' */
1389 if (strength_needed) {
1391 /* TRANSLATORS: Don't forget the ending space */
1392 strength=_("easily ");
1393 } else if (delta < 105) {
1395 } else if (delta < 165) {
1396 /* TRANSLATORS: Don't forget the ending space */
1397 strength=_("strongly ");
1398 } else if (delta < 180) {
1399 /* TRANSLATORS: Don't forget the ending space */
1400 strength=_("really strongly ");
1402 dbg(1,"delta=%d\n", delta);
1403 /* TRANSLATORS: Don't forget the ending space */
1404 strength=_("unknown ");
1407 if (type != attr_navigation_long_exact)
1408 distance=round_distance(distance);
1409 if (type == attr_navigation_speech) {
1410 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
1411 return g_strdup(_("When possible, please turn around"));
1413 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1415 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
1418 if (cmd->itm->prev->flags & AF_ROUNDABOUT) {
1421 return g_strdup(_("Enter the roundabout soon"));
1423 d = get_distance(distance, type, 1);
1424 /* TRANSLATORS: %s is the distance to the roundabout */
1425 ret = g_strdup_printf(_("In %s, enter the roundabout"), d);
1430 cur = cmd->itm->prev;
1431 count_roundabout = 0;
1432 while (cur && (cur->flags & AF_ROUNDABOUT)) {
1433 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
1440 ret = g_strdup_printf(_("Leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1443 ret = g_strdup_printf(_("then leave the roundabout at the %s"), get_exit_count_str(count_roundabout));
1452 d=get_distance(distance, type, 1);
1453 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
1457 d=g_strdup(_("soon"));
1460 d=get_distance(distance, type, 0);
1463 skip_roads = count_possible_turns(nav->first,cmd->itm,cmd->delta);
1464 if (skip_roads > 0) {
1465 if (get_count_str(skip_roads+1)) {
1466 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1467 ret = g_strdup_printf(_("Take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1470 d = g_strdup_printf(_("after %i roads"), skip_roads);
1473 d=g_strdup(_("now"));
1477 skip_roads = count_possible_turns(cmd->prev->itm,cmd->itm,cmd->delta);
1478 if (skip_roads > 0) {
1479 /* TRANSLATORS: First argument is the how manieth street to take, second the direction */
1480 if (get_count_str(skip_roads+1)) {
1481 ret = g_strdup_printf(_("then take the %1$s road to the %2$s"), get_count_str(skip_roads+1), dir);
1484 d = g_strdup_printf(_("after %i roads"), skip_roads);
1492 d=g_strdup(_("error"));
1494 if (cmd->itm->next) {
1495 int tellstreetname = 0;
1496 char *destination = NULL;
1498 if(type == attr_navigation_speech) { // In voice mode
1499 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
1502 if (level == 1) { // we are close to the intersection
1503 cmd->itm->streetname_told = 1; // remeber to be checked when we turn
1504 tellstreetname = 1; // Ok so we tell the name of the street
1508 if(cmd->itm->streetname_told == 0) // we are right at the intersection
1511 cmd->itm->streetname_told = 0; // reset just in case we come to the same street again
1518 if(nav->tell_street_name && tellstreetname)
1519 destination=navigation_item_destination(cmd->itm, itm, " ");
1522 /* 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' */
1523 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1525 /* TRANSLATORS: First argument is strength, second direction, third how many roads to skip, fourth destination */
1526 ret=g_strdup_printf(_("then turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
1528 g_free(destination);
1531 ret=g_strdup_printf(_("You have reached your destination %s"), d);
1533 ret=g_strdup_printf(_("then you have reached your destination."));
1541 * @brief Creates announcements for maneuvers, plus maneuvers immediately following the next maneuver
1543 * This function does create an announcement for the current maneuver and for maneuvers
1544 * immediately following that maneuver, if these are too close and we're in speech navigation.
1546 * @return An announcement that should be made
1549 show_next_maneuvers(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
1551 struct navigation_command *cur,*prev;
1552 int distance=itm->dest_length-cmd->itm->dest_length;
1553 int level, dist, i, time;
1554 int speech_time,time2nav;
1555 char *ret,*old,*buf,*next;
1557 if (type != attr_navigation_speech) {
1558 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only in speech navigation
1561 level=navigation_get_announce_level(nav, itm->item.type, distance-cmd->length);
1564 return show_maneuver(nav, itm, cmd, type, 0); // We accumulate maneuvers only if they are close
1567 if (cmd->itm->told) {
1568 return g_strdup("");
1571 ret = show_maneuver(nav, itm, cmd, type, 0);
1572 time2nav = navigation_time(itm,cmd->itm->prev);
1578 while (cur && cur->itm) {
1579 // We don't merge more than 3 announcements...
1580 if (i > 1) { // if you change this, please also change the value below, that is used to terminate the loop
1584 next = show_maneuver(nav,prev->itm, cur, type, 0);
1585 speech_time = navit_speech_estimate(nav->navit,next);
1588 if (speech_time == -1) { // user didn't set cps
1589 speech_time = 30; // assume 3 seconds
1592 dist = prev->itm->dest_length - cur->itm->dest_length;
1593 time = navigation_time(prev->itm,cur->itm->prev);
1595 if (time >= (speech_time + 30)) { // 3 seconds for understanding what has been said
1600 buf = show_maneuver(nav, prev->itm, cur, type, 1);
1601 ret = g_strdup_printf("%s, %s", old, buf);
1603 if (navit_speech_estimate(nav->navit,ret) > time2nav) {
1606 i = 2; // This will terminate the loop
1611 // If the two maneuvers are *really* close, we shouldn't tell the second one again, because TTS won't be fast enough
1612 if (time <= speech_time) {
1625 navigation_call_callbacks(struct navigation *this_, int force_speech)
1627 int distance, level = 0, level2;
1629 if (!this_->cmd_first)
1631 callback_list_call(this_->callback, 1, &p);
1632 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
1633 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
1634 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
1635 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
1636 while (distance > this_->distance_turn) {
1637 this_->level_last=4;
1640 if (this_->distance_turn >= 500)
1641 this_->distance_turn*=2;
1643 this_->distance_turn=500;
1645 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
1646 this_->distance_turn=50;
1647 distance-=this_->cmd_first->length;
1648 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
1649 if (this_->cmd_first->itm->prev) {
1650 level2=navigation_get_announce_level(this_, this_->cmd_first->itm->prev->item.type, distance);
1654 if (level < this_->level_last) {
1655 dbg(1,"level %d < %d\n", level, this_->level_last);
1656 this_->level_last=level;
1659 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
1660 dbg(1,"item different\n");
1661 this_->item_last=this_->cmd_first->itm->item;
1666 this_->level_last=level;
1667 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
1668 callback_list_call(this_->callback_speech, 1, &p);
1673 navigation_update(struct navigation *this_, struct route *route, struct attr *attr)
1676 struct map_rect *mr;
1677 struct item *ritem; /* Holds an item from the route map */
1678 struct item *sitem; /* Holds the corresponding item from the actual map */
1679 struct attr street_item,street_direction;
1680 struct navigation_itm *itm;
1681 int mode=0, incr=0, first=1;
1682 if (attr->type != attr_route_status)
1685 dbg(1,"enter %d\n", mode);
1686 if (attr->u.num == route_status_no_destination || attr->u.num == route_status_not_found || attr->u.num == route_status_path_done_new)
1687 navigation_flush(this_);
1688 if (attr->u.num != route_status_path_done_new && attr->u.num != route_status_path_done_incremental)
1693 map=route_get_map(this_->route);
1696 mr=map_rect_new(map, NULL);
1700 while ((ritem=map_rect_get_item(mr))) {
1701 if (ritem->type == type_route_start && this_->turn_around > -this_->turn_around_limit+1)
1702 this_->turn_around--;
1703 if (ritem->type == type_route_start_reverse && this_->turn_around < this_->turn_around_limit)
1704 this_->turn_around++;
1705 if (ritem->type != type_street_route)
1707 if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
1709 if (!item_attr_get(ritem, attr_direction, &street_direction))
1710 street_direction.u.num=0;
1711 sitem=street_item.u.item;
1712 dbg(1,"sitem=%p\n", sitem);
1713 itm=item_hash_lookup(this_->hash, sitem);
1714 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
1715 if (itm && itm->direction != street_direction.u.num) {
1716 dbg(2,"wrong direction\n");
1719 navigation_destroy_itms_cmds(this_, itm);
1721 navigation_itm_update(itm, ritem);
1724 dbg(1,"not on track\n");
1726 navigation_itm_new(this_, ritem);
1728 dbg(2,"turn_around=%d\n", this_->turn_around);
1730 navigation_destroy_itms_cmds(this_, NULL);
1733 navigation_itm_new(this_, NULL);
1734 make_maneuvers(this_,this_->route);
1736 calculate_dest_distance(this_, incr);
1738 navigation_call_callbacks(this_, FALSE);
1740 map_rect_destroy(mr);
1744 navigation_flush(struct navigation *this_)
1746 navigation_destroy_itms_cmds(this_, NULL);
1751 navigation_destroy(struct navigation *this_)
1753 navigation_flush(this_);
1754 item_hash_destroy(this_->hash);
1755 callback_list_destroy(this_->callback);
1756 callback_list_destroy(this_->callback_speech);
1761 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1763 if (type == attr_navigation_speech)
1764 callback_list_add(this_->callback_speech, cb);
1766 callback_list_add(this_->callback, cb);
1771 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
1773 if (type == attr_navigation_speech)
1774 callback_list_remove_destroy(this_->callback_speech, cb);
1776 callback_list_remove_destroy(this_->callback, cb);
1780 navigation_get_map(struct navigation *this_)
1783 this_->map=map_new(NULL, (struct attr*[]){
1784 &(struct attr){attr_type,{"navigation"}},
1785 &(struct attr){attr_navigation,.u.navigation=this_},
1786 &(struct attr){attr_data,{""}},
1787 &(struct attr){attr_description,{"Navigation"}},
1793 struct navigation *navigation;
1796 struct map_rect_priv {
1797 struct navigation *nav;
1798 struct navigation_command *cmd;
1799 struct navigation_command *cmd_next;
1800 struct navigation_itm *itm;
1801 struct navigation_itm *itm_next;
1802 struct navigation_itm *cmd_itm;
1803 struct navigation_itm *cmd_itm_next;
1805 enum attr_type attr_next;
1808 struct navigation_way *ways;
1814 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
1816 struct map_rect_priv *this=priv_data;
1817 if (this->ccount || ! count)
1819 *c=this->itm->start;
1825 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
1827 struct map_rect_priv *this_=priv_data;
1828 attr->type=attr_type;
1829 struct navigation_command *cmd=this_->cmd;
1830 struct navigation_itm *itm=this_->itm;
1831 struct navigation_itm *prev=itm->prev;
1839 if (cmd->itm != itm)
1843 case attr_navigation_short:
1844 this_->attr_next=attr_navigation_long;
1846 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1850 case attr_navigation_long:
1851 this_->attr_next=attr_navigation_long_exact;
1853 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1857 case attr_navigation_long_exact:
1858 this_->attr_next=attr_navigation_speech;
1860 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, cmd, attr_type);
1864 case attr_navigation_speech:
1865 this_->attr_next=attr_length;
1867 this_->str=attr->u.str=show_next_maneuvers(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
1872 this_->attr_next=attr_time;
1874 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
1879 this_->attr_next=attr_destination_length;
1881 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
1885 case attr_destination_length:
1886 attr->u.num=itm->dest_length;
1887 this_->attr_next=attr_destination_time;
1889 case attr_destination_time:
1890 attr->u.num=itm->dest_time;
1891 this_->attr_next=attr_street_name;
1893 case attr_street_name:
1894 attr->u.str=itm->name1;
1895 this_->attr_next=attr_street_name_systematic;
1899 case attr_street_name_systematic:
1900 attr->u.str=itm->name2;
1901 this_->attr_next=attr_debug;
1906 switch(this_->debug_idx) {
1909 this_->str=attr->u.str=g_strdup_printf("angle:%d (- %d)", itm->angle_start, itm->angle_end);
1913 this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->item.type));
1918 this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
1924 this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->name1);
1930 this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->name2);
1936 this_->str=attr->u.str=g_strdup_printf("prev angle:(%d -) %d", prev->angle_start, prev->angle_end);
1941 this_->ways=itm->ways;
1943 this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->item.type));
1947 if (this_->ways && prev) {
1948 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);
1949 this_->ways=this_->ways->next;
1958 maneuver_required2(prev, itm, &delta, &reason);
1959 this_->str=attr->u.str=g_strdup_printf("reason:%s",reason);
1964 this_->attr_next=attr_none;
1968 while (this_->attr_next != attr_none) {
1969 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
1974 attr->type=attr_none;
1979 static struct item_methods navigation_map_item_methods = {
1981 navigation_map_item_coord_get,
1983 navigation_map_item_attr_get,
1988 navigation_map_destroy(struct map_priv *priv)
1994 navigation_map_rect_init(struct map_rect_priv *priv)
1996 priv->cmd_next=priv->nav->cmd_first;
1997 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
2000 static struct map_rect_priv *
2001 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
2003 struct navigation *nav=priv->navigation;
2004 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
2006 navigation_map_rect_init(ret);
2007 ret->item.meth=&navigation_map_item_methods;
2008 ret->item.priv_data=ret;
2016 navigation_map_rect_destroy(struct map_rect_priv *priv)
2021 static struct item *
2022 navigation_map_get_item(struct map_rect_priv *priv)
2024 struct item *ret=&priv->item;
2026 if (!priv->itm_next)
2028 priv->itm=priv->itm_next;
2029 priv->cmd=priv->cmd_next;
2030 priv->cmd_itm=priv->cmd_itm_next;
2033 if (!priv->show_all && priv->itm->prev != NULL)
2034 priv->itm=priv->cmd->itm;
2035 priv->itm_next=priv->itm->next;
2036 if (priv->itm->prev)
2037 ret->type=type_nav_none;
2039 ret->type=type_nav_position;
2040 if (priv->cmd->itm == priv->itm) {
2041 priv->cmd_itm_next=priv->cmd->itm;
2042 priv->cmd_next=priv->cmd->next;
2043 if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
2044 ret->type=type_nav_destination;
2046 if (priv->itm && priv->itm->prev && !(priv->itm->flags & AF_ROUNDABOUT) && (priv->itm->prev->flags & AF_ROUNDABOUT)) {
2048 switch (((180+22)-priv->cmd->roundabout_delta)/45) {
2051 ret->type=type_nav_roundabout_r1;
2054 ret->type=type_nav_roundabout_r2;
2057 ret->type=type_nav_roundabout_r3;
2060 ret->type=type_nav_roundabout_r4;
2063 ret->type=type_nav_roundabout_r5;
2066 ret->type=type_nav_roundabout_r6;
2069 ret->type=type_nav_roundabout_r7;
2072 ret->type=type_nav_roundabout_r8;
2076 delta=priv->cmd->delta;
2080 ret->type=type_nav_left_1;
2081 else if (delta < 105)
2082 ret->type=type_nav_left_2;
2083 else if (delta < 165)
2084 ret->type=type_nav_left_3;
2086 ret->type=type_none;
2089 ret->type=type_nav_right_1;
2090 else if (delta < 105)
2091 ret->type=type_nav_right_2;
2092 else if (delta < 165)
2093 ret->type=type_nav_right_3;
2095 ret->type=type_none;
2102 priv->attr_next=attr_navigation_short;
2104 ret->id_lo=priv->itm->dest_count;
2105 dbg(1,"type=%d\n", ret->type);
2109 static struct item *
2110 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
2113 navigation_map_rect_init(priv);
2114 while ((ret=navigation_map_get_item(priv))) {
2115 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
2121 static struct map_methods navigation_map_meth = {
2124 navigation_map_destroy,
2125 navigation_map_rect_new,
2126 navigation_map_rect_destroy,
2127 navigation_map_get_item,
2128 navigation_map_get_item_byid,
2134 static struct map_priv *
2135 navigation_map_new(struct map_methods *meth, struct attr **attrs)
2137 struct map_priv *ret;
2138 struct attr *navigation_attr;
2140 navigation_attr=attr_search(attrs, NULL, attr_navigation);
2141 if (! navigation_attr)
2143 ret=g_new0(struct map_priv, 1);
2144 *meth=navigation_map_meth;
2145 ret->navigation=navigation_attr->u.navigation;
2151 navigation_set_route(struct navigation *this_, struct route *route)
2153 struct attr callback;
2155 this_->route_cb=callback_new_attr_1(callback_cast(navigation_update), attr_route_status, this_);
2156 callback.type=attr_callback;
2157 callback.u.callback=this_->route_cb;
2158 route_add_attr(route, &callback);
2162 navigation_init(void)
2164 plugin_register_map_type("navigation", navigation_map_new);