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"
40 #define _(STRING) gettext(STRING)
58 struct item_hash *hash;
59 struct navigation_itm *first;
60 struct navigation_itm *last;
61 struct navigation_command *cmd_first;
62 struct navigation_command *cmd_last;
63 struct callback_list *callback_speech;
64 struct callback_list *callback;
66 struct item item_last;
68 int turn_around_limit;
71 int announce[route_item_last-route_item_first+1][3];
75 struct navigation_command {
76 struct navigation_itm *itm;
77 struct navigation_command *next;
82 navigation_new(struct attr **attrs)
85 struct navigation *ret=g_new0(struct navigation, 1);
86 ret->hash=item_hash_new();
87 ret->callback=callback_list_new();
88 ret->callback_speech=callback_list_new();
90 ret->distance_last=-2;
91 ret->distance_turn=50;
92 ret->turn_around_limit=3;
94 for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
95 for (i = 0 ; i < 3 ; i++) {
96 ret->announce[j][i]=-1;
104 navigation_set_announce(struct navigation *this_, enum item_type type, int *level)
107 if (type < route_item_first || type > route_item_last) {
108 dbg(0,"street type %d out of range [%d,%d]", type, route_item_first, route_item_last);
111 for (i = 0 ; i < 3 ; i++)
112 this_->announce[type-route_item_first][i]=level[i];
117 navigation_get_announce_level(struct navigation *this_, enum item_type type, int dist)
121 if (type < route_item_first || type > route_item_last)
123 for (i = 0 ; i < 3 ; i++) {
124 if (dist <= this_->announce[type-route_item_first][i])
130 struct navigation_itm {
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;
252 if (! item_attr_get(ritem, attr_length, &length)) {
253 dbg(0,"no length\n");
256 if (! item_attr_get(ritem, attr_time, &time)) {
260 dbg(1,"length=%d time=%d\n", length.u.num, time.u.num);
261 itm->length=length.u.num;
262 itm->time=time.u.num;
265 static struct navigation_itm *
266 navigation_itm_new(struct navigation *this_, struct item *ritem)
268 struct navigation_itm *ret=g_new0(struct navigation_itm, 1);
271 struct attr street_item;
278 if (! item_attr_get(ritem, attr_street_item, &street_item)) {
279 dbg(0,"no street item\n");
282 sitem=street_item.u.item;
284 item_hash_insert(this_->hash, sitem, ret);
285 mr=map_rect_new(sitem->map, NULL);
286 sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
287 if (item_attr_get(sitem, attr_street_name, &attr))
288 ret->name1=map_convert_string(sitem->map,attr.u.str);
289 if (item_attr_get(sitem, attr_street_name_systematic, &attr))
290 ret->name2=map_convert_string(sitem->map,attr.u.str);
291 navigation_itm_update(ret, ritem);
293 while (item_coord_get(ritem, &c[i], 1)) {
294 dbg(1, "coord %d 0x%x 0x%x\n", i, c[i].x ,c[i].y);
303 dbg(1,"count=%d\n", l);
306 ret->angle_start=road_angle(&c[0], &c[1], 0);
307 ret->angle_end=road_angle(&c[l-1], &c[l], 0);
309 dbg(1,"i=%d start %d end %d '%s' '%s'\n", i, ret->angle_start, ret->angle_end, ret->name1, ret->name2);
310 map_rect_destroy(mr);
315 this_->last->next=ret;
316 ret->prev=this_->last;
318 dbg(1,"ret=%p\n", ret);
324 calculate_dest_distance(struct navigation *this_, int incr)
326 int len=0, time=0, count=0;
327 struct navigation_itm *next,*itm=this_->last;
328 dbg(1, "enter this_=%p, incr=%d\n", this_, incr);
331 dbg(2, "old values: (%p) time=%d lenght=%d\n", itm, itm->dest_length, itm->dest_time);
333 dbg(2, "old values: itm is null\n");
336 dbg(2, "itm values: time=%d lenght=%d\n", itm->length, itm->time);
337 dbg(2, "next values: (%p) time=%d lenght=%d\n", next, next->dest_length, next->dest_time);
338 itm->dest_length=next->dest_length+itm->length;
339 itm->dest_count=next->dest_count+1;
340 itm->dest_time=next->dest_time+itm->time;
341 dbg(2, "new values: time=%d lenght=%d\n", itm->dest_length, itm->dest_time);
347 itm->dest_length=len;
349 itm->dest_count=count++;
352 dbg(1,"len %d time %d\n", len, time);
356 is_same_street2(struct navigation_itm *old, struct navigation_itm *new)
358 if (old->name1 && new->name1 && !strcmp(old->name1, new->name1)) {
359 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (1.)\n", old->name2, new->name2, old->name1, new->name1);
362 if (old->name2 && new->name2 && !strcmp(old->name2, new->name2)) {
363 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' yes (2.)\n", old->name2, new->name2, old->name1, new->name1);
366 dbg(1,"is_same_street: '%s' '%s' vs '%s' '%s' no\n", old->name2, new->name2, old->name1, new->name1);
371 maneuver_required2(struct navigation_itm *old, struct navigation_itm *new, int *delta)
373 dbg(1,"enter %p %p %p\n",old, new, delta);
374 if (new->item.type == old->item.type || (new->item.type != type_ramp && old->item.type != type_ramp)) {
375 if (is_same_street2(old, new)) {
379 dbg(1, "maneuver_required: old or new is ramp\n");
381 if (old->crossings_end == 2) {
382 dbg(1, "maneuver_required: only 2 connections: no\n");
386 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) {
387 dbg(1, "maneuver_required: highway changed name\n");
390 *delta=new->angle_start-old->angle_end;
395 dbg(1,"delta=%d-%d=%d\n", new->angle_start, old->angle_end, *delta);
396 if (*delta < 20 && *delta >-20) {
397 dbg(1, "maneuver_required: delta(%d) < 20: no\n", *delta);
400 dbg(1, "maneuver_required: delta=%d: yes\n", *delta);
404 static struct navigation_command *
405 command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
407 struct navigation_command *ret=g_new0(struct navigation_command, 1);
408 dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
412 this_->cmd_last->next=ret;
415 if (!this_->cmd_first)
416 this_->cmd_first=ret;
421 make_maneuvers(struct navigation *this_)
423 struct navigation_itm *itm, *last=NULL, *last_itm=NULL;
426 this_->cmd_last=NULL;
427 this_->cmd_first=NULL;
430 if (maneuver_required2(last_itm, itm, &delta)) {
431 command_new(this_, itm, delta);
441 contains_suffix(char *name, char *suffix)
445 if (strlen(name) < strlen(suffix))
447 return !strcasecmp(name+strlen(name)-strlen(suffix), suffix);
451 replace_suffix(char *name, char *search, char *replace)
453 int len=strlen(name)-strlen(search);
454 char *ret=g_malloc(len+strlen(replace)+1);
455 strncpy(ret, name, len);
456 strcpy(ret+len, replace);
462 navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *next, char *prefix)
464 char *ret=NULL,*name1,*sep,*name2;
468 if(!itm->name1 && !itm->name2 && itm->item.type == type_ramp) {
469 dbg(1,">> Next is ramp %lx current is %lx \n", itm->item.type, next->item.type);
471 if(next->item.type == type_ramp)
473 if(itm->item.type == type_highway_city || itm->item.type == type_highway_land )
474 return g_strdup_printf("%s%s",prefix,_("exit"));
476 return g_strdup_printf("%s%s",prefix,_("ramp"));
479 if (!itm->name1 && !itm->name2)
484 for (i = 0 ; i < sizeof(suffixes)/sizeof(suffixes[0]) ; i++) {
485 if (contains_suffix(itm->name1,suffixes[i].fullname)) {
487 name1=g_strdup(itm->name1);
490 if (contains_suffix(itm->name1,suffixes[i].abbrev)) {
492 name1=replace_suffix(itm->name1, suffixes[i].abbrev, suffixes[i].fullname);
505 /* TRANSLATORS: Arguments: 1: Prefix (Space if required) 2: Street Name 3: Separator (Space if required), 4: Systematic Street Name */
506 ret=g_strdup_printf(_("%sinto the street %s%s%s"),prefix,itm->name1, sep, name2);
509 /* 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 */
510 ret=g_strdup_printf(_("%sinto the %s%s%s|male form"),prefix,name1, sep, name2);
513 /* 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 */
514 ret=g_strdup_printf(_("%sinto the %s%s%s|female form"),prefix,name1, sep, name2);
517 /* 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 */
518 ret=g_strdup_printf(_("%sinto the %s%s%s|neutral form"),prefix,name1, sep, name2);
524 /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
525 ret=g_strdup_printf(_("into the %s"),itm->name2);
544 show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigation_command *cmd, enum attr_type type)
546 /* TRANSLATORS: right, as in 'Turn right' */
547 char *dir=_("right"),*strength="";
548 int distance=itm->dest_length-cmd->itm->dest_length;
550 int delta=cmd->delta;
554 /* TRANSLATORS: left, as in 'Turn left' */
559 /* TRANSLATORS: Don't forget the ending space */
560 strength=_("easily ");
561 } else if (delta < 105) {
563 } else if (delta < 165) {
564 /* TRANSLATORS: Don't forget the ending space */
565 strength=_("strongly ");
567 dbg(1,"delta=%d\n", delta);
568 /* TRANSLATORS: Don't forget the ending space */
569 strength=_("unknown ");
571 if (type != attr_navigation_long_exact)
572 distance=round_distance(distance);
573 if (type == attr_navigation_speech) {
574 if (nav->turn_around && nav->turn_around == nav->turn_around_limit)
575 return g_strdup(_("When possible, please turn around"));
576 level=navigation_get_announce_level(nav, itm->item.type, distance);
577 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, itm->item.type);
581 d=get_distance(distance, type, 1);
582 ret=g_strdup_printf(_("Follow the road for the next %s"), d);
586 d=g_strdup(_("soon"));
589 d=get_distance(distance, type, 0);
592 d=g_strdup(_("now"));
595 d=g_strdup(_("error"));
597 if (cmd->itm->next) {
598 int tellstreetname = 0;
599 char *destination = NULL;
601 if(type == attr_navigation_speech) { // In voice mode
602 // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
605 if (level == 1) { // we are close to the intersection
606 cmd->itm->told = 1; // remeber to be checked when we turn
607 tellstreetname = 1; // Ok so we tell the name of the street
611 if(cmd->itm->told == 0) // we are write at the intersection
614 cmd->itm->told = 0; // reset just in case we come to the same street again
622 destination=navigation_item_destination(cmd->itm, itm, " ");
623 /* 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' */
624 ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
627 ret=g_strdup_printf(_("You have reached your destination %s"), d);
633 navigation_call_callbacks(struct navigation *this_, int force_speech)
635 int distance, level = 0;
637 if (!this_->cmd_first)
639 callback_list_call(this_->callback, 1, &p);
640 dbg(1,"force_speech=%d turn_around=%d turn_around_limit=%d\n", force_speech, this_->turn_around, this_->turn_around_limit);
641 distance=round_distance(this_->first->dest_length-this_->cmd_first->itm->dest_length);
642 if (this_->turn_around_limit && this_->turn_around == this_->turn_around_limit) {
643 dbg(1,"distance=%d distance_turn=%d\n", distance, this_->distance_turn);
644 while (distance > this_->distance_turn) {
648 if (this_->distance_turn >= 500)
649 this_->distance_turn*=2;
651 this_->distance_turn=500;
653 } else if (!this_->turn_around_limit || this_->turn_around == -this_->turn_around_limit+1) {
654 this_->distance_turn=50;
655 level=navigation_get_announce_level(this_, this_->first->item.type, distance);
656 if (level < this_->level_last) {
657 dbg(1,"level %d < %d\n", level, this_->level_last);
658 this_->level_last=level;
661 if (!item_is_equal(this_->cmd_first->itm->item, this_->item_last)) {
662 dbg(1,"item different\n");
663 this_->item_last=this_->cmd_first->itm->item;
668 this_->level_last=level;
669 dbg(1,"distance=%d level=%d type=0x%x\n", distance, level, this_->first->item.type);
670 callback_list_call(this_->callback_speech, 1, &p);
675 navigation_update(struct navigation *this_, struct route *route)
679 struct item *ritem,*sitem;
680 struct attr street_item;
681 struct navigation_itm *itm;
686 map=route_get_map(route);
689 mr=map_rect_new(map, NULL);
693 ritem=map_rect_get_item(mr);
695 if (!item_attr_get(ritem, attr_street_item, &street_item)) {
696 ritem=map_rect_get_item(mr);
700 if (!item_attr_get(ritem, attr_street_item, &street_item)) {
701 dbg(0,"no street item\n");
704 sitem=street_item.u.item;
705 dbg(1,"sitem=%p\n", sitem);
706 itm=item_hash_lookup(this_->hash, sitem);
707 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sitem->id_hi, sitem->id_lo, itm);
708 navigation_destroy_itms_cmds(this_, itm);
711 navigation_itm_update(itm, ritem);
713 dbg(1,"not on track\n");
716 navigation_itm_new(this_, ritem);
717 ritem=map_rect_get_item(mr);
719 itm=navigation_itm_new(this_, NULL);
720 make_maneuvers(this_);
722 calculate_dest_distance(this_, incr);
723 dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
724 if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0)
725 this_->turn_around++;
727 this_->turn_around--;
728 if (this_->turn_around > this_->turn_around_limit)
729 this_->turn_around=this_->turn_around_limit;
730 else if (this_->turn_around < -this_->turn_around_limit+1)
731 this_->turn_around=-this_->turn_around_limit+1;
732 dbg(2,"turn_around=%d\n", this_->turn_around);
733 this_->distance_last=this_->first->dest_length;
735 navigation_call_callbacks(this_, FALSE);
737 navigation_destroy_itms_cmds(this_, NULL);
738 map_rect_destroy(mr);
741 struct route_path_handle *rph;
742 struct route_path_segment *s;
743 struct navigation_itm *itm;
744 struct route_info *pos,*dst;
745 struct street_data *sd;
751 pos=route_get_pos(route);
752 dst=route_get_dst(route);
755 speedlist=route_get_speedlist(route);
756 len=route_info_length(pos, dst, 0);
757 dbg(2,"len pos,dst = %d\n", len);
759 len=route_info_length(pos, NULL, 0);
760 dbg(2,"len pos = %d\n", len);
763 sd=route_info_street(pos);
764 itm=item_hash_lookup(this_->hash, &sd->item);
765 dbg(2,"itm for item with id (0x%x,0x%x) is %p\n", sd->item.id_hi, sd->item.id_lo, itm);
766 navigation_destroy_itms_cmds(this_, itm);
770 itm=navigation_itm_new(this_, &sd->item, route_info_point(pos, -1));
774 itm->time=route_time(speedlist, &sd->item, len);
775 dbg(2,"%p time = %d\n", itm, itm->time);
777 printf("not on track\n");
778 rph=route_path_open(route);
780 while((s=route_path_get_segment(rph))) {
781 itm=navigation_itm_new(this_, route_path_segment_get_item(s),route_path_segment_get_start(s));
782 itm->time=route_path_segment_get_time(s);
783 itm->length=route_path_segment_get_length(s);
785 route_path_close(rph);
788 len=route_info_length(NULL, dst, 0);
789 dbg(1, "end %d\n", len);
790 sd=route_info_street(dst);
791 itm=navigation_itm_new(this_, &sd->item, route_info_point(pos, 2));
793 itm->time=route_time(speedlist, &sd->item, len);
795 itm=navigation_itm_new(this_, NULL, NULL);
796 make_maneuvers(this_);
798 calculate_dest_distance(this_, incr);
799 dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
800 if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0)
801 this_->turn_around=1;
803 this_->turn_around=0;
804 dbg(2,"turn_around=%d\n", this_->turn_around);
805 this_->distance_last=this_->first->dest_length;
807 navigation_call_callbacks(this_, FALSE);
812 navigation_flush(struct navigation *this_)
814 navigation_destroy_itms_cmds(this_, NULL);
819 navigation_destroy(struct navigation *this_)
821 navigation_flush(this_);
822 item_hash_destroy(this_->hash);
823 callback_list_destroy(this_->callback);
824 callback_list_destroy(this_->callback_speech);
829 navigation_register_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
831 if (type == attr_navigation_speech)
832 callback_list_add(this_->callback_speech, cb);
834 callback_list_add(this_->callback, cb);
839 navigation_unregister_callback(struct navigation *this_, enum attr_type type, struct callback *cb)
841 if (type == attr_navigation_speech)
842 callback_list_remove_destroy(this_->callback_speech, cb);
844 callback_list_remove_destroy(this_->callback, cb);
848 navigation_get_map(struct navigation *this_)
851 this_->map=map_new((struct attr*[]){
852 &(struct attr){attr_type,{"navigation"}},
853 &(struct attr){attr_navigation,.u.navigation=this_},
854 &(struct attr){attr_data,{""}},
855 &(struct attr){attr_description,{"Navigation"}},
861 struct navigation *navigation;
864 struct map_rect_priv {
865 struct navigation *nav;
866 struct navigation_command *cmd;
867 struct navigation_command *cmd_next;
868 struct navigation_itm *itm;
869 struct navigation_itm *itm_next;
870 struct navigation_itm *cmd_itm;
871 struct navigation_itm *cmd_itm_next;
873 enum attr_type attr_next;
880 navigation_map_item_coord_get(void *priv_data, struct coord *c, int count)
882 struct map_rect_priv *this=priv_data;
883 if (this->ccount || ! count)
891 navigation_map_item_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
893 struct map_rect_priv *this_=priv_data;
894 attr->type=attr_type;
895 struct navigation_command *cmd=this_->cmd;
897 if (cmd->itm != this_->itm)
901 case attr_navigation_short:
902 this_->attr_next=attr_navigation_long;
904 attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
908 case attr_navigation_long:
909 this_->attr_next=attr_navigation_long_exact;
911 attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
915 case attr_navigation_long_exact:
916 this_->attr_next=attr_navigation_speech;
918 attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, cmd, attr_type);
922 case attr_navigation_speech:
923 this_->attr_next=attr_length;
925 attr->u.str=show_maneuver(this_->nav, this_->cmd_itm, this_->cmd, attr_type);
930 this_->attr_next=attr_time;
932 attr->u.num=this_->cmd_itm->dest_length-cmd->itm->dest_length;
937 this_->attr_next=attr_destination_length;
939 attr->u.num=this_->cmd_itm->dest_time-cmd->itm->dest_time;
943 case attr_destination_length:
944 attr->u.num=this_->itm->dest_length;
945 this_->attr_next=attr_destination_time;
947 case attr_destination_time:
948 attr->u.num=this_->itm->dest_time;
949 this_->attr_next=attr_street_name;
951 case attr_street_name:
952 attr->u.str=this_->itm->name1;
953 this_->attr_next=attr_street_name_systematic;
955 case attr_street_name_systematic:
956 attr->u.str=this_->itm->name2;
957 this_->attr_next=attr_debug;
960 switch(this_->debug_idx) {
962 attr->u.str=g_strdup_printf("%p vs %p\n", this_->itm,this_->cmd->itm);
963 this_->attr_next=attr_none;
966 this_->attr_next=attr_none;
972 while (this_->attr_next != attr_none) {
973 if (navigation_map_item_attr_get(priv_data, this_->attr_next, attr))
978 attr->type=attr_none;
983 static struct item_methods navigation_map_item_methods = {
985 navigation_map_item_coord_get,
987 navigation_map_item_attr_get,
992 navigation_map_destroy(struct map_priv *priv)
998 navigation_map_rect_init(struct map_rect_priv *priv)
1000 priv->cmd_next=priv->nav->cmd_first;
1001 priv->cmd_itm_next=priv->itm_next=priv->nav->first;
1004 static struct map_rect_priv *
1005 navigation_map_rect_new(struct map_priv *priv, struct map_selection *sel)
1007 struct navigation *nav=priv->navigation;
1008 struct map_rect_priv *ret=g_new0(struct map_rect_priv, 1);
1010 navigation_map_rect_init(ret);
1011 ret->item.meth=&navigation_map_item_methods;
1012 ret->item.priv_data=ret;
1017 navigation_map_rect_destroy(struct map_rect_priv *priv)
1022 static struct item *
1023 navigation_map_get_item(struct map_rect_priv *priv)
1025 struct item *ret=&priv->item;
1027 if (!priv->itm_next)
1029 priv->itm=priv->itm_next;
1030 priv->cmd=priv->cmd_next;
1031 priv->cmd_itm=priv->cmd_itm_next;
1032 if (!priv->show_all) {
1035 priv->itm=priv->cmd->itm;
1037 priv->itm_next=priv->itm->next;
1038 ret->type=type_nav_none;
1039 if (priv->cmd->itm == priv->itm) {
1040 priv->cmd_itm_next=priv->cmd->itm;
1041 priv->cmd_next=priv->cmd->next;
1042 delta=priv->cmd->delta;
1046 ret->type=type_nav_left_1;
1047 else if (delta < 105)
1048 ret->type=type_nav_left_2;
1049 else if (delta < 165)
1050 ret->type=type_nav_left_3;
1052 ret->type=type_none;
1055 ret->type=type_nav_right_1;
1056 else if (delta < 105)
1057 ret->type=type_nav_right_2;
1058 else if (delta < 165)
1059 ret->type=type_nav_right_3;
1061 ret->type=type_none;
1066 priv->attr_next=attr_navigation_short;
1068 ret->id_lo=priv->itm->dest_count;
1069 dbg(1,"type=%d\n", ret->type);
1073 static struct item *
1074 navigation_map_get_item_byid(struct map_rect_priv *priv, int id_hi, int id_lo)
1077 navigation_map_rect_init(priv);
1078 while ((ret=navigation_map_get_item(priv))) {
1079 if (ret->id_hi == id_hi && ret->id_lo == id_lo)
1085 static struct map_methods navigation_map_meth = {
1088 navigation_map_destroy,
1089 navigation_map_rect_new,
1090 navigation_map_rect_destroy,
1091 navigation_map_get_item,
1092 navigation_map_get_item_byid,
1098 static struct map_priv *
1099 navigation_map_new(struct map_methods *meth, struct attr **attrs)
1101 struct map_priv *ret;
1102 struct attr *navigation_attr;
1104 navigation_attr=attr_search(attrs, NULL, attr_navigation);
1105 if (! navigation_attr)
1107 ret=g_new0(struct map_priv, 1);
1108 *meth=navigation_map_meth;
1109 ret->navigation=navigation_attr->u.navigation;
1116 navigation_init(void)
1118 plugin_register_map_type("navigation", navigation_map_new);