2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
27 #include "navigation.h"
31 #include "transform.h"
33 #include "projection.h"
38 #include "navit_nls.h"
56 struct item_hash *hash;
57 struct navigation_itm *first;
58 struct navigation_itm *last;
59 struct navigation_command *cmd_first;
60 struct navigation_command *cmd_last;
61 struct callback_list *callback_speech;
62 struct callback_list *callback;
64 struct item item_last;
66 int turn_around_limit;
69 int announce[route_item_last-route_item_first+1][3];
73 struct navigation_command {
74 struct navigation_itm *itm;
75 struct navigation_command *next;
80 navigation_new(struct attr **attrs)
83 struct navigation *ret=g_new0(struct navigation, 1);
84 ret->hash=item_hash_new();
85 ret->callback=callback_list_new();
86 ret->callback_speech=callback_list_new();
88 ret->distance_last=-2;
89 ret->distance_turn=50;
90 ret->turn_around_limit=3;
92 for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
93 for (i = 0 ; i < 3 ; i++) {
94 ret->announce[j][i]=-1;
102 navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
105 if (type < route_item_first || type > route_item_last) {
106 dbg(0,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
109 for (i = 0 ; i < 3 ; i++)
110 this_->announce[type-route_item_first][i]=level[i];
115 navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
119 if (type < route_item_first || type > route_item_last)
121 for (i = 0 ; i < 3 ; i++) {
122 if (dist <= this_->announce[type-route_item_first][i])
128 struct navigation_itm {
136 struct coord start,end;
143 struct navigation_itm *next;
144 struct navigation_itm *prev;
149 road_angle(struct coord *c1, struct coord *c2, int dir)
151 int ret=transform_get_angle_delta(c1, c2, dir);
152 dbg(1, "road_angle(0x%x,0x%x - 0x%x,0x%x)=%d\n", c1->x, c1->y, c2->x, c2->y, ret);
157 round_distance(int dist)
180 dist=(dist+500)/1000;
183 dist=(dist+5000)/10000;
188 get_distance(int dist, enum attr_type type, int is_length)
190 if (type == attr_navigation_long) {
192 return g_strdup_printf(_("%d m"), dist);
194 return g_strdup_printf(_("in %d m"), dist);
198 return g_strdup_printf(_("%d meters"), dist);
200 return g_strdup_printf(_("in %d meters"), dist);
203 int rem=(dist/100)%10;
206 return g_strdup_printf(_("%d.%d kilometer"), dist/1000, rem);
208 return g_strdup_printf(_("in %d.%d kilometers"), dist/1000, rem);
212 return g_strdup_printf(ngettext("one kilometer","%d kilometers", dist/1000), dist/1000);
214 return g_strdup_printf(ngettext("in one kilometer","in %d kilometers", dist/1000), dist/1000);
218 navigation_destroy_itms_cmds(struct navigation *this_, struct navigation_itm *end)
220 struct navigation_itm *itm;
221 struct navigation_command *cmd;
222 dbg(2,"enter this_=%p this_->first=%p this_->cmd_first=%p end=%p\n", this_, this_->first, this_->cmd_first, end);
223 if (this_->cmd_first)
224 dbg(2,"this_->cmd_first->itm=%p\n", this_->cmd_first->itm);
225 while (this_->first && this_->first != end) {
227 dbg(3,"destroying %p\n", itm);
228 item_hash_remove(this_->hash, &itm->item);
229 this_->first=itm->next;
231 this_->first->prev=NULL;
232 if (this_->cmd_first && this_->cmd_first->itm == itm->next) {
233 cmd=this_->cmd_first;
234 this_->cmd_first=cmd->next;
237 map_convert_free(itm->name1);
238 map_convert_free(itm->name2);
243 if (! this_->first && end)
244 dbg(0,"end wrong\n");
245 dbg(2,"ret this_->first=%p this_->cmd_first=%p\n",this_->first, this_->cmd_first);
249 navigation_itm_update(struct navigation_itm *itm, struct item *ritem)
251 struct attr length, time, straight;
252 if (! item_attr_get(ritem, attr_length, &length)) {
253 dbg(0,"no length\n");
256 if (! item_attr_get(ritem, attr_time, &time)) {
261 if (item_attr_get(ritem, attr_route_follow_straight, &straight)) {
262 itm->straight = straight.u.num;
267 dbg(1,"length=%d time=%d\n", length.u.num, time.u.num);
268 itm->length=length.u.num;
269 itm->time=time.u.num;
272 static struct navigation_itm *
273 navigation_itm_new(struct navigation *this_, struct item *ritem)
275 struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
278 struct attr street_item,direction;
285 if (! item_attr_get(ritem, attr_street_item, &street_item)) {
286 dbg(0,"no street item\n");
289 if (item_attr_get(ritem, attr_direction, &direction))
290 ret->direction=direction.u.num;
293 sitem=street_item.u.item;
295 item_hash_insert(this_->hash, sitem, ret);
296 mr=map_rect_new(sitem->map, NULL);
297 sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
298 if (item_attr_get(sitem, attr_street_name, &attr))
299 ret->name1=map_convert_string(sitem->map,attr.u.str);
300 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
301 ret->name2=map_convert_string(sitem->map,attr.u.str);
302 navigation_itm_update(ret, ritem);
304 while (item_coord_get(ritem, &c[i], 1)) {
305 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
314 dbg(1,"count=%d\n", i);
317 ret->angle_start=road_angle(&c[0], &c[1], 0);
318 ret->angle_end=road_angle(&c[i-1], &c[i], 0);
322 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
323 map_rect_destroy(mr);
326 ret->start=ret->end=this_->last->end;
331 this_->last->next=ret;
332 ret->prev=this_->last;
334 dbg(1,"ret=%p\n", ret);
340 * @brief Calculates distance and time to the destination
342 * This function calculates the distance and the time to the destination of a
343 * navigation. If incr is set, this is only calculated for the first navigation
344 * item, which is a lot faster than re-calculation the whole destination, but works
345 * only if the rest of the navigation already has been calculated.
347 * @param this_ The navigation whose destination / time should be calculated
348 * @param incr Set this to true to only calculate the first item. See description.
351 calculate_dest_distance(struct navigation *this_, int incr)
353 int len=0, time=0, count=0;
354 struct navigation_itm *next,*itm=this_->last;
355 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
358 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
360 dbg(2, "old values: itm is null\n");
363 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
364 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
365 itm->dest_length=next->dest_length+itm->length;
366 itm->dest_count=next->dest_count+1;
367 itm->dest_time=next->dest_time+itm->time;
368 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
374 itm->dest_length=len;
376 itm->dest_count=count++;
379 dbg(1,"len %d time %d\n", len, time);
383 * @brief Checks if two navigation items are on the same street
385 * This function checks if two navigation items are on the same street. It returns
386 * true if either their name or their "systematic name" (e.g. "A6" or "B256") are the
389 * @param old The first item to be checked
390 * @param new The second item to be checked
391 * @return True if both old and new are on the same street
394 is_same_street2(struct navigation_itm *old, struct navigation_itm *new)
396 if (old->name1 && new->name1 && !strcmp(old->name1, new->name1)) {
397 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old->name2, new->name2, old->name1, new->name1);
400 if (old->name2 && new->name2 && !strcmp(old->name2, new->name2)) {
401 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old->name2, new->name2, old->name1, new->name1);
404 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old->name2, new->name2, old->name1, new->name1);
409 * @brief Checks if two navigation items are on the same street
411 * This function checks if two navigation items are on the same street. It returns
412 * true if the first part of their "systematic name" is equal. If the "systematic name" is
413 * for example "A352/E3" (a german highway which at the same time is part of the international
414 * E-road network), it would only search for "A352" in the second item's systematic name.
416 * @param old The first item to be checked
417 * @param new The second item to be checked
418 * @return True if the "systematic name" of both items matches. See description.
421 is_same_street_systematic(struct navigation_itm *old, struct navigation_itm *new)
423 int slashold,slashnew;
424 if (!old->name2 || !new->name2)
426 slashold=strcspn(old->name2, "/");
427 slashnew=strcspn(new->name2, "/");
428 if (slashold != slashnew || strncmp(old->name2, new->name2, slashold))
434 * @brief Checks if navit has to create a maneuver to drive from old to new
436 * This function checks if it has to create a "maneuver" - i.e. guide the user - to drive
437 * from "old" to "new".
439 * @param old The old navigation item, where we're coming from
440 * @param new The new navigation item, where we're going to
441 * @param delta The angle the user has to steer to navigate from old to new
442 * @return True if navit should guide the user, false otherwise
445 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta)
447 dbg(1,"enter %p %p %p\n",old, new, delta);
448 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
449 if (is_same_street2(old, new)) {
453 dbg(1, "maneuver_required: old or new is ramp\n");
454 if (old->item.type == type_ramp && (new->item.type == type_highway_city || new->item.type == type_highway_land)) {
455 dbg(1, "no_maneuver_required: old is ramp new is highway\n");
459 if (old->crossings_end == 2) {
460 dbg(1, "maneuver_required: only 2 connections: no\n");
464 *delta=new->angle_start-old->angle_end;
469 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
470 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))) {
471 dbg(1, "maneuver_required: highway changed name\n");
474 if (*delta < 20 && *delta >-20) {
475 if (! new->straight) { /* We're not entering this item straight, so have a maneuver */
479 dbg(1, "maneuver_required: delta(%d) < 20: no\n", *delta);
482 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
486 static struct navigation_command *
487 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
489 struct navigation_command *ret=g_new0(struct navigation_command, 1);
490 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
494 this_->cmd_last->next=ret;
497 if (!this_->cmd_first)
498 this_->cmd_first=ret;
503 make_maneuvers(struct navigation *this_)
505 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
508 this_->cmd_last=NULL;
509 this_->cmd_first=NULL;
512 if (maneuver_required2(last_itm, itm, &delta)) {
513 command_new(this_, itm, delta);
523 contains_suffix(char *name, char *suffix)
527 if (strlen(name) < strlen(suffix))
529 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
533 replace_suffix(char *name, char *search, char *replace)
535 int len=strlen(name)-strlen(search);
536 char *ret=g_malloc(len+strlen(replace)+1);
537 strncpy(ret, name, len);
538 strcpy(ret+len, replace);
544 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
546 char *ret=NULL,*name1,*sep,*name2;
550 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
551 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
553 if(next->item.type == type_ramp)
555 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
556 return g_strdup_printf("%s%s",prefix,_("exit")); /* %FIXME Can this even be reached? */
558 return g_strdup_printf("%s%s",prefix,_("ramp"));
561 if (!itm->name1 && !itm->name2)
566 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
567 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
569 name1=g_strdup(itm->name1);
572 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
574 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
587 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
588 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
591 /* 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 */
592 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
595 /* 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 */
596 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
599 /* 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 */
600 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
606 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
607 ret=g_strdup_printf(_("into the %s"),itm->name2);
626 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
628 /* TRANSLATORS: right, as in 'Turn right' */
629 char *dir=_("right"),*strength="";
630 int distance=itm->dest_length-cmd->itm->dest_length;
632 int delta=cmd->delta;
636 /* TRANSLATORS: left, as in 'Turn left' */
641 /* TRANSLATORS: Don't forget the ending space */
642 strength=_("easily ");
643 } else if (delta < 105) {
645 } else if (delta < 165) {
646 /* TRANSLATORS: Don't forget the ending space */
647 strength=_("strongly ");
649 dbg(1,"delta=%d\n", delta);
650 /* TRANSLATORS: Don't forget the ending space */
651 strength=_("unknown ");
653 if (type != attr_navigation_long_exact)
654 distance=round_distance(distance);
655 if (type == attr_navigation_speech) {
656 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
657 return g_strdup(_("When possible, please turn around"));
658 level=navigation_get_announce_level(nav, itm->item.type, distance);
659 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
663 d=get_distance(distance, type, 1);
664 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
668 d=g_strdup(_("soon"));
671 d=get_distance(distance, type, 0);
674 d=g_strdup(_("now"));
677 d=g_strdup(_("error"));
679 if (cmd->itm->next) {
680 int tellstreetname = 0;
681 char *destination = NULL;
683 if(type == attr_navigation_speech) { // In voice mode
684 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
687 if (level == 1) { // we are close to the intersection
688 cmd->itm->told = 1; // remeber to be checked when we turn
689 tellstreetname = 1; // Ok so we tell the name of the street
693 if(cmd->itm->told == 0) // we are write at the intersection
696 cmd->itm->told = 0; // reset just in case we come to the same street again
704 destination=navigation_item_destination(cmd->itm, itm, " ");
705 /* 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' */
706 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
709 ret=g_strdup_printf(_("You have reached your destination %s"), d);
715 navigation_call_callbacks(struct navigation *this_, int force_speech)
717 int distance, level = 0;
719 if (!this_->cmd_first)
721 callback_list_call(this_->callback, 1, &p);
722 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
723 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
724 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
725 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
726 while (distance > this_->distance_turn) {
730 if (this_->distance_turn >= 500)
731 this_->distance_turn*=2;
733 this_->distance_turn=500;
735 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
736 this_->distance_turn=50;
737 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
738 if (level < this_->level_last) {
739 dbg(1,"level %d < %d\n", level, this_->level_last);
740 this_->level_last=level;
743 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
744 dbg(1,"item different\n");
745 this_->item_last=this_->cmd_first->itm->item;
750 this_->level_last=level;
751 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
752 callback_list_call(this_->callback_speech, 1, &p);
757 navigation_update(struct navigation *this_, struct route *route)
761 struct item *ritem; /* Holds an item from the route map */
762 struct item *sitem; /* Holds the corresponding item from the actual map */
763 struct attr street_item,street_direction;
764 struct navigation_itm *itm;
769 map=route_get_map(route);
772 mr=map_rect_new(map, NULL);
776 while ((ritem=map_rect_get_item(mr))) {
777 if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
779 if (!item_attr_get(ritem, attr_direction, &street_direction))
780 street_direction.u.num=0;
781 sitem=street_item.u.item;
782 dbg(1,"sitem=%p\n", sitem);
783 itm=item_hash_lookup(this_->hash, sitem);
784 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
785 if (itm && itm->direction != street_direction.u.num) {
786 dbg(2,"wrong direction\n");
789 navigation_destroy_itms_cmds(this_, itm);
791 navigation_itm_update(itm, ritem);
794 dbg(1,"not on track\n");
796 navigation_itm_new(this_, ritem);
799 navigation_destroy_itms_cmds(this_, NULL);
802 navigation_itm_new(this_, NULL);
803 make_maneuvers(this_);
805 calculate_dest_distance(this_, incr);
806 dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
807 if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0)
808 this_->turn_around++;
810 this_->turn_around--;
811 if (this_->turn_around > this_->turn_around_limit)
812 this_->turn_around=this_->turn_around_limit;
813 else if (this_->turn_around < -this_->turn_around_limit+1)
814 this_->turn_around=-this_->turn_around_limit+1;
815 dbg(2,"turn_around=%d\n", this_->turn_around);
816 this_->distance_last=this_->first->dest_length;
818 navigation_call_callbacks(this_, FALSE);
820 map_rect_destroy(mr);
824 navigation_flush(struct navigation *this_)
826 navigation_destroy_itms_cmds(this_, NULL);
831 navigation_destroy(struct navigation *this_)
833 navigation_flush(this_);
834 item_hash_destroy(this_->hash);
835 callback_list_destroy(this_->callback);
836 callback_list_destroy(this_->callback_speech);
841 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
843 if (type == attr_navigation_speech)
844 callback_list_add(this_->callback_speech, cb);
846 callback_list_add(this_->callback, cb);
851 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
853 if (type == attr_navigation_speech)
854 callback_list_remove_destroy(this_->callback_speech, cb);
856 callback_list_remove_destroy(this_->callback, cb);
860 navigation_get_map(struct navigation *this_)
863 this_->map=map_new(NULL, (struct attr*[]){
864 &(struct attr){attr_type,{"navigation"}},
865 &(struct attr){attr_navigation,.u.navigation=this_},
866 &(struct attr){attr_data,{""}},
867 &(struct attr){attr_description,{"Navigation"}},
873 struct navigation *navigation;
876 struct map_rect_priv {
877 struct navigation *nav;
878 struct navigation_command *cmd;
879 struct navigation_command *cmd_next;
880 struct navigation_itm *itm;
881 struct navigation_itm *itm_next;
882 struct navigation_itm *cmd_itm;
883 struct navigation_itm *cmd_itm_next;
885 enum attr_type attr_next;
893 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
895 struct map_rect_priv *this=priv_data;
896 if (this->ccount || ! count)
904 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
906 struct map_rect_priv *this_=priv_data;
907 attr->type=attr_type;
908 struct navigation_command *cmd=this_->cmd;
909 struct navigation_itm *itm=this_->itm;
910 struct navigation_itm *prev=itm->prev;
922 case attr_navigation_short:
923 this_->attr_next=attr_navigation_long;
925 this_->str=attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
929 case attr_navigation_long:
930 this_->attr_next=attr_navigation_long_exact;
932 this_->str=attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
936 case attr_navigation_long_exact:
937 this_->attr_next=attr_navigation_speech;
939 this_->str=attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
943 case attr_navigation_speech:
944 this_->attr_next=attr_length;
946 this_->str=attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
951 this_->attr_next=attr_time;
953 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
958 this_->attr_next=attr_destination_length;
960 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
964 case attr_destination_length:
965 attr->u.num=itm->dest_length;
966 this_->attr_next=attr_destination_time;
968 case attr_destination_time:
969 attr->u.num=itm->dest_time;
970 this_->attr_next=attr_street_name;
972 case attr_street_name:
973 attr->u.str=itm->name1;
974 this_->attr_next=attr_street_name_systematic;
977 case attr_street_name_systematic:
978 attr->u.str=itm->name2;
979 this_->attr_next=attr_debug;
983 switch(this_->debug_idx) {
986 this_->str=attr->u.str=g_strdup_printf("angle:%d - %d", itm->angle_start, itm->angle_end);
990 this_->str=attr->u.str=g_strdup_printf("item type:%s", item_to_name(itm->item.type));
995 this_->str=attr->u.str=g_strdup_printf("delta:%d", cmd->delta);
1001 this_->str=attr->u.str=g_strdup_printf("prev street_name:%s", prev->name1);
1007 this_->str=attr->u.str=g_strdup_printf("prev street_name_systematic:%s", prev->name2);
1013 this_->str=attr->u.str=g_strdup_printf("prev angle:%d - %d", prev->angle_start, prev->angle_end);
1019 this_->str=attr->u.str=g_strdup_printf("prev item type:%s", item_to_name(prev->item.type));
1023 this_->attr_next=attr_none;
1027 while (this_->attr_next != attr_none) {
1028 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
1033 attr->type=attr_none;
1038 static struct item_methods navigation_map_item_methods = {
1040 navigation_map_item_coord_get,
1042 navigation_map_item_attr_get,
1047 navigation_map_destroy(struct map_priv *priv)
1053 navigation_map_rect_init(struct map_rect_priv *priv)
1055 priv->cmd_next=priv->nav->cmd_first;
1056 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
1059 static struct map_rect_priv *
1060 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
1062 struct navigation *nav=priv->navigation;
1063 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
1065 navigation_map_rect_init(ret);
1066 ret->item.meth=&navigation_map_item_methods;
1067 ret->item.priv_data=ret;
1072 navigation_map_rect_destroy(struct map_rect_priv *priv)
1077 static struct item *
1078 navigation_map_get_item(struct map_rect_priv *priv)
1080 struct item *ret=&priv->item;
1082 if (!priv->itm_next)
1084 priv->itm=priv->itm_next;
1085 priv->cmd=priv->cmd_next;
1086 priv->cmd_itm=priv->cmd_itm_next;
1087 if (!priv->show_all && priv->itm->prev != NULL) {
1090 priv->itm=priv->cmd->itm;
1092 priv->itm_next=priv->itm->next;
1093 if (priv->itm->prev)
1094 ret->type=type_nav_none;
1096 ret->type=type_nav_position;
1097 if (priv->cmd->itm == priv->itm) {
1098 priv->cmd_itm_next=priv->cmd->itm;
1099 priv->cmd_next=priv->cmd->next;
1100 if (priv->cmd_itm_next && !priv->cmd_itm_next->next)
1101 ret->type=type_nav_destination;
1103 delta=priv->cmd->delta;
1107 ret->type=type_nav_left_1;
1108 else if (delta < 105)
1109 ret->type=type_nav_left_2;
1110 else if (delta < 165)
1111 ret->type=type_nav_left_3;
1113 ret->type=type_none;
1116 ret->type=type_nav_right_1;
1117 else if (delta < 105)
1118 ret->type=type_nav_right_2;
1119 else if (delta < 165)
1120 ret->type=type_nav_right_3;
1122 ret->type=type_none;
1128 priv->attr_next=attr_navigation_short;
1130 ret->id_lo=priv->itm->dest_count;
1131 dbg(1,"type=%d\n", ret->type);
1135 static struct item *
1136 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
1139 navigation_map_rect_init(priv);
1140 while ((ret=navigation_map_get_item(priv))) {
1141 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
1147 static struct map_methods navigation_map_meth = {
1150 navigation_map_destroy,
1151 navigation_map_rect_new,
1152 navigation_map_rect_destroy,
1153 navigation_map_get_item,
1154 navigation_map_get_item_byid,
1160 static struct map_priv *
1161 navigation_map_new(struct map_methods *meth, struct attr **attrs)
1163 struct map_priv *ret;
1164 struct attr *navigation_attr;
1166 navigation_attr=attr_search(attrs, NULL, attr_navigation);
1167 if (! navigation_attr)
1169 ret=g_new0(struct map_priv, 1);
1170 *meth=navigation_map_meth;
1171 ret->navigation=navigation_attr->u.navigation;
1178 navigation_init(void)
1180 plugin_register_map_type("navigation", navigation_map_new);