15 #include "projection.h"
21 #include "transform.h"
27 #include "data_window.h"
29 #include "navigation.h"
35 #define _(STRING) gettext(STRING)
37 * @defgroup navit the navit core instance
41 struct navit_vehicle {
49 struct cursor *cursor;
50 struct vehicle *vehicle;
51 struct callback *update_cb;
59 struct layout *layout_current;
62 struct action *action;
63 struct transformation *trans;
64 struct compass *compass;
67 struct statusbar *statusbar;
70 struct navigation *navigation;
71 struct speech *speech;
72 struct tracking *tracking;
75 struct displaylist *displaylist;
78 int orient_north_flag;
81 struct navit_vehicle *vehicle;
82 struct callback_list *vehicle_cbl;
83 struct callback_list *init_cbl;
85 struct callback *nav_speech_cb;
86 struct callback *roadbook_callback;
87 struct datawindow *roadbook_window;
88 struct menu *bookmarks;
89 GHashTable *bookmarks_hash;
90 struct menu *destinations;
91 struct point pressed, last, current;
92 int button_pressed,moved,popped;
93 guint button_timeout, motion_timeout;
96 struct gui *main_loop_gui;
98 static void navit_cursor_update(struct navit *this_, struct cursor *cursor);
101 navit_add_mapset(struct navit *this_, struct mapset *ms)
103 this_->mapsets = g_list_append(this_->mapsets, ms);
107 navit_get_mapset(struct navit *this_)
109 return this_->mapsets->data;
113 navit_get_tracking(struct navit *this_)
115 return this_->tracking;
119 navit_add_layout(struct navit *this_, struct layout *lay)
121 this_->layouts = g_list_append(this_->layouts, lay);
125 navit_draw(struct navit *this_)
128 struct navit_vehicle *nv;
130 transform_setup_source_rect(this_->trans);
131 graphics_draw(this_->gra, this_->displaylist, this_->mapsets, this_->trans, this_->layouts, this_->route);
135 cursor_redraw(nv->cursor);
142 navit_draw_displaylist(struct navit *this_)
145 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layouts, this_->route);
150 navit_resize(void *data, int w, int h)
152 struct navit *this_=data;
153 transform_set_size(this_->trans, w, h);
158 navit_popup(void *data)
160 struct navit *this_=data;
161 popup(this_, 1, &this_->pressed);
162 this_->button_timeout=0;
168 navit_button(void *data, int pressed, int button, struct point *p)
170 struct navit *this_=data;
177 this_->button_pressed=1;
180 this_->button_timeout=g_timeout_add(500, navit_popup, data);
183 navit_set_center_screen(this_, p);
185 popup(this_, button, p);
187 navit_zoom_in(this_, 2, p);
189 navit_zoom_out(this_, 2, p);
191 this_->button_pressed=0;
192 if (this_->button_timeout) {
193 g_source_remove(this_->button_timeout);
194 this_->button_timeout=0;
195 if (! this_->moved && ! transform_within_border(this_->trans, p, border))
196 navit_set_center_screen(this_, p);
199 if (this_->motion_timeout) {
200 g_source_remove(this_->motion_timeout);
201 this_->motion_timeout=0;
205 transform_get_size(this_->trans, &p.x, &p.y);
208 p.x-=this_->last.x-this_->pressed.x;
209 p.y-=this_->last.y-this_->pressed.y;
210 navit_set_center_screen(this_, &p);
217 navit_motion_timeout(void *data)
219 struct navit *this_=data;
222 dx=(this_->current.x-this_->last.x);
223 dy=(this_->current.y-this_->last.y);
225 this_->last=this_->current;
226 graphics_displaylist_move(this_->displaylist, dx, dy);
227 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layouts, this_->route);
230 this_->motion_timeout=0;
235 navit_motion(void *data, struct point *p)
237 struct navit *this_=data;
240 if (this_->button_pressed && !this_->popped) {
241 dx=(p->x-this_->pressed.x);
242 dy=(p->y-this_->pressed.y);
243 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
244 if (this_->button_timeout) {
245 g_source_remove(this_->button_timeout);
246 this_->button_timeout=0;
249 if (! this_->motion_timeout)
250 this_->motion_timeout=g_timeout_add(100, navit_motion_timeout, data);
256 navit_scale(struct navit *this_, long scale, struct point *p)
258 struct coord c1, c2, *center;
260 transform_reverse(this_->trans, p, &c1);
261 transform_set_scale(this_->trans, scale);
263 transform_reverse(this_->trans, p, &c2);
264 center = transform_center(this_->trans);
265 center->x += c1.x - c2.x;
266 center->y += c1.y - c2.y;
272 * Change the current zoom level, zooming closer to the ground
274 * @param navit The navit instance
275 * @param factor The zoom factor, usually 2
276 * @param p The invariant point (if set to NULL, default to center)
280 navit_zoom_in(struct navit *this_, int factor, struct point *p)
282 long scale=transform_get_scale(this_->trans)/factor;
285 navit_scale(this_, scale, p);
289 * Change the current zoom level
291 * @param navit The navit instance
292 * @param factor The zoom factor, usually 2
293 * @param p The invariant point (if set to NULL, default to center)
297 navit_zoom_out(struct navit *this_, int factor, struct point *p)
299 long scale=transform_get_scale(this_->trans)*factor;
300 navit_scale(this_, scale, p);
304 navit_new(struct pcoord *center, int zoom)
306 struct navit *this_=g_new0(struct navit, 1);
309 main_add_navit(this_);
310 this_->vehicle_cbl=callback_list_new();
311 this_->init_cbl=callback_list_new();
313 f=popen("pidof /usr/bin/ipaq-sleep","r");
315 fscanf(f,"%d",&this_->pid);
316 dbg(1,"ipaq_sleep pid=%d\n", this_->pid);
320 this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
321 this_->cursor_flag=1;
322 this_->tracking_flag=1;
323 this_->trans=transform_new();
324 transform_setup(this_->trans, center, zoom, 0);
325 this_->displaylist=graphics_displaylist_new();
330 navit_set_gui(struct navit *this_, struct gui *gui, char *type)
333 this_->gui_type=g_strdup(type);
334 if (gui_has_main_loop(this_->gui)) {
335 if (! main_loop_gui) {
336 main_loop_gui=this_->gui;
338 g_warning("gui with main loop already active, ignoring this instance");
342 this_->menubar=gui_menubar_new(this_->gui);
343 this_->toolbar=gui_toolbar_new(this_->gui);
344 this_->statusbar=gui_statusbar_new(this_->gui);
348 navit_set_graphics(struct navit *this_, struct graphics *gra, char *type)
351 this_->gra_type=g_strdup(type);
352 graphics_register_resize_callback(this_->gra, navit_resize, this_);
353 graphics_register_button_callback(this_->gra, navit_button, this_);
354 graphics_register_motion_callback(this_->gra, navit_motion, this_);
358 navit_get_graphics(struct navit *this_)
364 navit_map_toggle(struct menu *menu, struct navit *this_, struct map *map)
366 if ((menu_get_toggle(menu) != 0) != (map_get_active(map) != 0)) {
367 map_set_active(map, (menu_get_toggle(menu) != 0));
373 navit_projection_set(struct navit *this_, enum projection pro)
378 c=transform_center(this_->trans);
379 transform_to_geo(transform_get_projection(this_->trans), c, &g);
380 transform_set_projection(this_->trans, pro);
381 transform_from_geo(pro, &g, c);
386 navit_add_menu_destinations(struct navit *this_, char *name, struct menu *rmen, GHashTable *h, struct callback *cb)
390 struct menu *men,*nmen;
396 while (h && (i=index(n, '/'))) {
397 strcpy(buffer2, name);
398 buffer2[i-name]='\0';
399 if (!(nmen=g_hash_table_lookup(h, buffer2))) {
400 nmen=menu_add(men, buffer2+(n-name), menu_type_submenu, NULL);
401 g_hash_table_insert(h, g_strdup(buffer2), nmen);
406 menu_add(men, n, menu_type_menu, cb);
411 navit_proj2str(enum projection pro)
416 case projection_garmin:
423 navit_append_coord(struct navit *this_, char *file, struct pcoord *c, char *type, char *description, struct menu *rmen, GHashTable *h, void (*cb_func)(void))
435 prostr = navit_proj2str(c->pro);
436 fprintf(f,"%s%s0x%x 0x%x type=%s label=\"%s\"\n",
437 prostr, *prostr ? ":" : "", c->x, c->y, type, description);
443 buffer=g_strdup(description);
444 cb=callback_new_2(cb_func, this_, (void *)offset);
445 navit_add_menu_destinations(this_, buffer, rmen, h, cb);
451 parse_line(FILE *f, char *buffer, char **name, struct pcoord *c)
457 enum projection pro = projection_mg;
459 if (! fgets(buffer, 2048, f))
462 pos=coord_parse(cp, pro, &co);
465 if (!cp[pos] || cp[pos] == '\n')
467 cp[strlen(cp)-1]='\0';
469 if (!strncmp(s,"type=", 5)) {
487 navit_set_destination_from_file(struct navit *this_, char *file, int bookmark, int offset)
490 char *name, *description, buffer[2048];
496 fseek(f, offset, SEEK_SET);
497 if (parse_line(f, buffer, &name, &c) <= 0)
500 description=g_strdup_printf("Bookmark %s", name);
501 navit_set_destination(this_, &c, description);
504 navit_set_destination(this_, &c, name);
508 navit_set_destination_from_destination(struct navit *this_, void *offset_p)
510 navit_set_destination_from_file(this_, "destination.txt", 0, (int)offset_p);
514 navit_set_destination_from_bookmark(struct navit *this_, void *offset_p)
516 navit_set_destination_from_file(this_, "bookmark.txt", 1, (int)offset_p);
520 * Start the route computing to a given set of coordinates
522 * @param navit The navit instance
523 * @param c The coordinate to start routing to
524 * @param description A label which allows the user to later identify this destination in the former destinations selection
528 navit_set_destination(struct navit *this_, struct pcoord *c, char *description)
530 navit_append_coord(this_, "destination.txt", c, "former_destination", description, this_->destinations, NULL, callback_cast(navit_set_destination_from_destination));
532 route_set_destination(this_->route, c);
538 * Record the given set of coordinates as a bookmark
540 * @param navit The navit instance
541 * @param c The coordinate to store
542 * @param description A label which allows the user to later identify this bookmark
546 navit_add_bookmark(struct navit *this_, struct pcoord *c, char *description)
548 navit_append_coord(this_,"bookmark.txt", c, "bookmark", description, this_->bookmarks, this_->bookmarks_hash, callback_cast(navit_set_destination_from_bookmark));
551 struct navit *global_navit;
558 navit_debug(struct navit *this_)
563 struct search_list *sl;
564 struct search_list_result *res;
566 debug_level_set("data_mg:town_search_get_item",9);
567 debug_level_set("data_mg:town_search_compare",9);
568 debug_level_set("data_mg:tree_search_next",9);
569 debug_level_set("data_mg:map_search_new_mg",9);
570 sl=search_list_new(this_->mapsets->data);
571 attr.type=attr_country_all;
573 search_list_search(sl, &attr, 1);
574 while ((res=search_list_get_result(sl))) {
575 printf("country result\n");
577 attr.type=attr_town_name;
579 search_list_search(sl, &attr, 1);
580 while ((res=search_list_get_result(sl))) {
581 printf("town result\n");
583 attr.type=attr_street_name;
585 search_list_search(sl, &attr, 1);
586 while ((res=search_list_get_result(sl))) {
587 printf("street result\n");
589 search_list_destroy(sl);
595 navit_add_menu_layouts(struct navit *this_, struct menu *men)
597 menu_add(men, "Test", menu_type_menu, NULL);
601 navit_add_menu_layout(struct navit *this_, struct menu *men)
603 navit_add_menu_layouts(this_, menu_add(men, _("Layout"), menu_type_submenu, NULL));
607 navit_add_menu_projections(struct navit *this_, struct menu *men)
610 cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_mg);
611 menu_add(men, "M&G", menu_type_menu, cb);
612 cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_garmin);
613 menu_add(men, "Garmin", menu_type_menu, cb);
617 navit_add_menu_projection(struct navit *this_, struct menu *men)
619 navit_add_menu_projections(this_, menu_add(men, _("Projection"), menu_type_submenu, NULL));
623 navit_add_menu_maps(struct navit *this_, struct mapset *ms, struct menu *men)
625 struct mapset_handle *handle;
630 handle=mapset_open(ms);
631 while ((map=mapset_next(handle,0))) {
632 char *s=g_strdup_printf("%s:%s", map_get_type(map), map_get_filename(map));
633 cb=callback_new_3(callback_cast(navit_map_toggle), NULL, this_, map);
634 mmen=menu_add(men, s, menu_type_toggle, cb);
635 callback_set_arg(cb, 0, mmen);
636 menu_set_toggle(mmen, map_get_active(map));
639 mapset_close(handle);
643 navit_add_menu_destinations_from_file(struct navit *this_, char *file, struct menu *rmen, GHashTable *h, struct route *route, void (*cb_func)(void))
655 while (! feof(f) && (pos=parse_line(f, buffer, &name, &c)) > -3) {
657 cb=callback_new_2(cb_func, this_, (void *)offset);
658 navit_add_menu_destinations(this_, name, rmen, h, cb);
666 route_set_destination(route, &c);
671 navit_add_menu_former_destinations(struct navit *this_, struct menu *men, struct route *route)
674 this_->destinations=menu_add(men, _("Former Destinations"), menu_type_submenu, NULL);
676 this_->destinations=NULL;
677 navit_add_menu_destinations_from_file(this_, "destination.txt", this_->destinations, NULL, route, callback_cast(navit_set_destination_from_destination));
681 navit_add_menu_bookmarks(struct navit *this_, struct menu *men)
684 this_->bookmarks=menu_add(men, _("Bookmarks"), menu_type_submenu, NULL);
686 this_->bookmarks=NULL;
687 navit_add_menu_destinations_from_file(this_, "bookmark.txt", this_->bookmarks, this_->bookmarks_hash, NULL, callback_cast(navit_set_destination_from_bookmark));
691 navit_vehicle_toggle(struct navit *this_, struct navit_vehicle *nv)
693 if (menu_get_toggle(nv->menu)) {
694 if (this_->vehicle && this_->vehicle != nv)
695 menu_set_toggle(this_->vehicle->menu, 0);
698 if (this_->vehicle == nv)
704 navit_add_menu_vehicles(struct navit *this_, struct menu *men)
706 struct navit_vehicle *nv;
712 cb=callback_new_2(callback_cast(navit_vehicle_toggle), this_, nv);
713 nv->menu=menu_add(men, nv->name, menu_type_toggle, cb);
714 menu_set_toggle(nv->menu, this_->vehicle == nv);
720 navit_add_menu_vehicle(struct navit *this_, struct menu *men)
722 men=menu_add(men, _("Vehicle"), menu_type_submenu, NULL);
723 navit_add_menu_vehicles(this_, men);
727 navit_speak(struct navit *this_)
729 struct navigation *nav=this_->navigation;
730 struct navigation_list *list;
734 list=navigation_list_new(nav);
735 item=navigation_list_get_item(list);
736 if (item_attr_get(item, attr_navigation_speech, &attr))
737 speech_say(this_->speech, attr.u.str);
738 navigation_list_destroy(list);
742 navit_window_roadbook_update(struct navit *this_)
744 struct navigation *nav=this_->navigation;
745 struct navigation_list *list;
748 struct param_list param[1];
751 datawindow_mode(this_->roadbook_window, 1);
752 list=navigation_list_new(nav);
753 while ((item=navigation_list_get_item(list))) {
755 item_attr_get(item, attr_navigation_long, &attr);
756 dbg(2, "Command='%s'\n", attr.u.str);
757 param[0].name="Command";
758 param[0].value=attr.u.str;
759 datawindow_add(this_->roadbook_window, param, 1);
761 navigation_list_destroy(list);
762 datawindow_mode(this_->roadbook_window, 0);
766 navit_window_roadbook_destroy(struct navit *this_)
769 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
770 this_->roadbook_window=NULL;
771 this_->roadbook_callback=NULL;
774 navit_window_roadbook_new(struct navit *this_)
776 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
777 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
778 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
779 navit_window_roadbook_update(this_);
783 get_direction(char *buffer, int angle, int mode)
788 sprintf(buffer,"%d",angle);
791 if (angle < 69 || angle > 291)
793 if (angle > 111 && angle < 249)
795 if (angle > 22 && angle < 158)
797 if (angle > 202 && angle < 338)
805 sprintf(buffer,"%d H", angle);
810 struct navit_window_items {
811 struct datawindow *win;
812 struct callback *click;
820 navit_window_items_click(struct navit *this_, struct navit_window_items *nwi, char **col)
826 dbg(0,"enter col=%s,%s,%s,%s,%s\n", col[0], col[1], col[2], col[3], col[4]);
827 sscanf(col[4], "0x%x,0x%x", &c.x, &c.y);
828 c.pro = projection_mg;
829 dbg(0,"0x%x,0x%x\n", c.x, c.y);
830 description=g_strdup_printf("%s %s", nwi->name, col[3]);
831 navit_set_destination(this_, &c, description);
836 navit_window_items_open(struct navit *this_, struct navit_window_items *nwi)
838 struct map_selection sel;
839 struct coord c,*center;
840 struct mapset_handle *h;
846 struct param_list param[5];
851 dbg(0, "distance=%d\n", nwi->distance);
852 if (nwi->distance == -1)
855 dist=nwi->distance*1000;
856 param[0].name="Distance";
857 param[1].name="Direction";
858 param[2].name="Type";
859 param[3].name="Name";
863 sel.order[layer_town]=18;
864 sel.order[layer_street]=18;
865 sel.order[layer_poly]=18;
867 sel.order[layer_town]=0;
868 sel.order[layer_street]=0;
869 sel.order[layer_poly]=0;
871 center=transform_center(this_->trans);
872 sel.u.c_rect.lu.x=center->x-dist;
873 sel.u.c_rect.lu.y=center->y+dist;
874 sel.u.c_rect.rl.x=center->x+dist;
875 sel.u.c_rect.rl.y=center->y-dist;
876 dbg(2,"0x%x,0x%x - 0x%x,0x%x\n", sel.u.c_rect.lu.x, sel.u.c_rect.lu.y, sel.u.c_rect.rl.x, sel.u.c_rect.rl.y);
877 nwi->click=callback_new_2(callback_cast(navit_window_items_click), this_, nwi);
878 nwi->win=gui_datawindow_new(this_->gui, nwi->name, nwi->click, NULL);
879 h=mapset_open(navit_get_mapset(this_));
880 while ((m=mapset_next(h, 1))) {
881 dbg(2,"m=%p %s\n", m, map_get_filename(m));
882 mr=map_rect_new(m, &sel);
883 dbg(2,"mr=%p\n", mr);
884 while ((item=map_rect_get_item(mr))) {
885 if (item_coord_get(item, &c, 1)) {
886 if (coord_rect_contains(&sel.u.c_rect, &c) && g_hash_table_lookup(nwi->hash, &item->type)) {
887 if (! item_attr_get(item, attr_label, &attr))
889 idist=transform_distance(map_projection(item->map), center, &c);
891 get_direction(dirbuf, transform_get_angle_delta(center, &c, 0), 1);
892 param[0].value=distbuf;
893 param[1].value=dirbuf;
894 param[2].value=item_to_name(item->type);
895 sprintf(distbuf,"%d", idist/1000);
896 param[3].value=attr.u.str;
897 sprintf(coordbuf, "0x%x,0x%x", c.x, c.y);
898 param[4].value=coordbuf;
899 datawindow_add(nwi->win, param, 5);
901 /* printf("gefunden %s %s %d\n",item_to_name(item->type), attr.u.str, idist/1000); */
903 if (item->type >= type_line)
904 while (item_coord_get(item, &c, 1));
907 map_rect_destroy(mr);
912 struct navit_window_items *
913 navit_window_items_new(const char *name, int distance)
915 struct navit_window_items *nwi=g_new0(struct navit_window_items, 1);
916 nwi->name=g_strdup(name);
917 nwi->distance=distance;
918 nwi->hash=g_hash_table_new(g_int_hash, g_int_equal);
924 navit_window_items_add_item(struct navit_window_items *nwi, enum item_type type)
926 nwi->list=g_list_prepend(nwi->list, (void *)type);
927 g_hash_table_insert(nwi->hash, &nwi->list->data, (void *)1);
931 navit_add_window_items(struct navit *this_, struct navit_window_items *nwi)
933 this_->windows_items=g_list_append(this_->windows_items, nwi);
937 navit_add_menu_windows_items(struct navit *this_, struct menu *men)
939 struct navit_window_items *nwi;
942 l=this_->windows_items;
945 cb=callback_new_2(callback_cast(navit_window_items_open), this_, nwi);
946 menu_add(men, nwi->name, menu_type_menu, cb);
952 navit_init(struct navit *this_)
957 struct navit_vehicle *nv;
960 g_warning("failed to instantiate gui '%s'\n",this_->gui_type);
961 navit_destroy(this_);
965 g_warning("failed to instantiate gui '%s'\n",this_->gra_type);
966 navit_destroy(this_);
969 if (gui_set_graphics(this_->gui, this_->gra)) {
970 g_warning("failed to connect graphics '%s' to gui '%s'\n", this_->gra_type, this_->gui_type);
971 g_warning(" Please see http://navit.sourceforge.net/wiki/index.php/Failed_to_connect_graphics_to_gui\n");
972 g_warning(" for explanations and solutions\n");
974 navit_destroy(this_);
977 graphics_init(this_->gra);
980 dbg(0,"parsed one vehicle\n");
982 nv->cursor=cursor_new(this_->gra, nv->vehicle, &nv->c, this_->trans);
983 nv->update_cb=callback_new_1(callback_cast(navit_cursor_update), this_);
984 cursor_add_callback(nv->cursor, nv->update_cb);
985 vehicle_set_navit(nv->vehicle, this_);
988 if (this_->mapsets) {
989 ms=this_->mapsets->data;
991 route_set_mapset(this_->route, ms);
993 tracking_set_mapset(this_->tracking, ms);
994 if (this_->navigation)
995 navigation_set_mapset(this_->navigation, ms);
996 if (this_->menubar) {
997 men=menu_add(this_->menubar, _("Map"), menu_type_submenu, NULL);
999 navit_add_menu_layout(this_, men);
1000 navit_add_menu_projection(this_, men);
1001 navit_add_menu_vehicle(this_, men);
1002 navit_add_menu_maps(this_, ms, men);
1004 men=menu_add(this_->menubar, _("Route"), menu_type_submenu, NULL);
1006 navit_add_menu_former_destinations(this_, men, this_->route);
1007 navit_add_menu_bookmarks(this_, men);
1010 navit_add_menu_former_destinations(this_, NULL, this_->route);
1012 if (this_->navigation && this_->speech) {
1013 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1014 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1018 if (this_->menubar) {
1019 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1021 navit_add_menu_windows_items(this_, men);
1026 navit_window_roadbook_new(this_);
1027 navit_window_items_new(this_);
1030 callback_list_call_1(this_->init_cbl, this_);
1034 navit_set_center(struct navit *this_, struct coord *center)
1036 struct coord *c=transform_center(this_->trans);
1043 navit_set_center_cursor(struct navit *this_, struct coord *cursor, int dir, int xpercent, int ypercent)
1045 struct coord *c=transform_center(this_->trans);
1050 transform_get_size(this_->trans, &width, &height);
1052 transform_set_angle(this_->trans, dir);
1053 p.x=(100-xpercent)*width/100;
1054 p.y=(100-ypercent)*height/100;
1055 transform_reverse(this_->trans, &p, &cnew);
1064 navit_set_center_screen(struct navit *this_, struct point *p)
1067 transform_reverse(this_->trans, p, &c);
1068 navit_set_center(this_, &c);
1072 navit_toggle_cursor(struct navit *this_)
1074 this_->cursor_flag=1-this_->cursor_flag;
1078 * Toggle the tracking : automatic centering of the map on the main vehicle
1080 * @param navit The navit instance
1084 navit_toggle_tracking(struct navit *this_)
1086 this_->tracking_flag=1-this_->tracking_flag;
1090 * Toggle the north orientation : forces the map to be aimed at north
1092 * @param navit The navit instance
1096 navit_toggle_orient_north(struct navit *this_)
1098 this_->orient_north_flag=1-this_->orient_north_flag;
1102 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
1104 * @param navit The navit instance
1109 navit_cursor_update(struct navit *this_, struct cursor *cursor)
1112 struct coord *cursor_c=cursor_pos_get(cursor);
1114 int dir=cursor_get_dir(cursor);
1115 int speed=cursor_get_speed(cursor);
1116 enum projection pro;
1119 if (!this_->vehicle || this_->vehicle->cursor != cursor)
1122 cursor_c=cursor_pos_get(cursor);
1123 dir=cursor_get_dir(cursor);
1124 speed=cursor_get_speed(cursor);
1125 pro=vehicle_projection(this_->vehicle->vehicle);
1127 /* This transform is useless cursor and vehicle are in the same projection */
1128 if (!transform(this_->trans, pro, cursor_c, &pnt) || !transform_within_border(this_->trans, &pnt, border)) {
1129 if (!this_->cursor_flag)
1131 if (this_->orient_north_flag)
1132 navit_set_center_cursor(this_, cursor_c, 0, 50 - 30.*sin(M_PI*dir/180.), 50 + 30.*cos(M_PI*dir/180.));
1134 navit_set_center_cursor(this_, cursor_c, dir, 50, 80);
1135 transform(this_->trans, pro, cursor_c, &pnt);
1138 if (this_->pid && speed > 2)
1139 kill(this_->pid, SIGWINCH);
1140 if (this_->tracking && this_->tracking_flag) {
1141 struct coord c=*cursor_c;
1142 if (tracking_update(this_->tracking, &c, dir)) {
1144 cursor_pos_set(cursor, cursor_c);
1145 if (this_->route && this_->vehicle->update_curr == 1)
1146 route_set_position_from_tracking(this_->route, this_->tracking);
1149 if (this_->route && this_->vehicle->update_curr == 1) {
1153 route_set_position(this_->route, &pc);
1156 if (this_->route && this_->vehicle->update_curr == 1)
1157 navigation_update(this_->navigation, this_->route);
1158 if (this_->cursor_flag) {
1159 if (this_->vehicle->follow_curr == 1)
1160 navit_set_center_cursor(this_, cursor_c, dir, 50, 80);
1162 if (this_->vehicle->follow_curr > 1)
1163 this_->vehicle->follow_curr--;
1165 this_->vehicle->follow_curr=this_->vehicle->follow;
1166 if (this_->vehicle->update_curr > 1)
1167 this_->vehicle->update_curr--;
1169 this_->vehicle->update_curr=this_->vehicle->update;
1170 callback_list_call_2(this_->vehicle_cbl, this_, this_->vehicle->vehicle);
1174 * Set the position of the vehicle
1176 * @param navit The navit instance
1177 * @param c The coordinate to set as position
1182 navit_set_position(struct navit *this_, struct pcoord *c)
1185 route_set_position(this_->route, c);
1186 if (this_->navigation) {
1187 navigation_update(this_->navigation, this_->route);
1194 * Register a new vehicle
1196 * @param navit The navit instance
1197 * @param v The vehicle instance
1198 * @param name Guess? :)
1199 * @param c The color to use for the cursor, currently only used in GTK
1200 * @param update Wether to refresh the map each time this vehicle position changes (instead of only when it reaches a border)
1201 * @param follow Wether to center the map on this vehicle position
1202 * @returns a vehicle instance
1204 struct navit_vehicle *
1205 navit_add_vehicle(struct navit *this_, struct vehicle *v, const char *name, struct color *c, int update, int follow)
1207 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
1209 nv->name=g_strdup(name);
1210 nv->update_curr=nv->update=update;
1211 nv->follow_curr=nv->follow=follow;
1214 this_->vehicles=g_list_append(this_->vehicles, nv);
1219 navit_add_vehicle_cb(struct navit *this_, struct callback *cb)
1221 callback_list_add(this_->vehicle_cbl, cb);
1225 navit_remove_vehicle_cb(struct navit *this_, struct callback *cb)
1227 callback_list_remove(this_->vehicle_cbl, cb);
1231 navit_add_init_cb(struct navit *this_, struct callback *cb)
1233 callback_list_add(this_->init_cbl, cb);
1237 navit_remove_init_cb(struct navit *this_, struct callback *cb)
1239 callback_list_remove(this_->init_cbl, cb);
1243 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
1249 navit_tracking_add(struct navit *this_, struct tracking *tracking)
1251 this_->tracking=tracking;
1255 navit_route_add(struct navit *this_, struct route *route)
1261 navit_navigation_add(struct navit *this_, struct navigation *navigation)
1263 this_->navigation=navigation;
1267 navit_set_speech(struct navit *this_, struct speech *speech)
1269 this_->speech=speech;
1274 navit_get_gui(struct navit *this_)
1279 struct transformation *
1280 navit_get_trans(struct navit *this_)
1282 return this_->trans;
1286 navit_get_route(struct navit *this_)
1288 return this_->route;
1292 navit_get_navigation(struct navit *this_)
1294 return this_->navigation;
1297 struct displaylist *
1298 navit_get_displaylist(struct navit *this_)
1300 return this_->displaylist;
1304 navit_destroy(struct navit *this_)
1306 /* TODO: destroy objects contained in this_ */
1307 main_remove_navit(this_);
1312 navit_toggle_routegraph_display(struct navit *nav)
1316 route_toggle_routegraph_display(nav->route);