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 {
52 struct cursor *cursor;
53 struct vehicle *vehicle;
63 struct layout *layout_current;
66 struct action *action;
67 struct transformation *trans;
68 struct compass *compass;
71 struct statusbar *statusbar;
74 struct navigation *navigation;
75 struct speech *speech;
76 struct tracking *tracking;
79 struct displaylist *displaylist;
82 int orient_north_flag;
85 struct navit_vehicle *vehicle;
86 struct callback_list *vehicle_cbl;
87 struct callback_list *init_cbl;
89 struct callback *nav_speech_cb;
90 struct callback *roadbook_callback;
91 struct datawindow *roadbook_window;
92 struct menu *bookmarks;
93 GHashTable *bookmarks_hash;
94 struct menu *destinations;
95 struct point pressed, last, current;
96 int button_pressed,moved,popped;
97 guint button_timeout, motion_timeout;
100 struct gui *main_loop_gui;
102 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
103 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
106 navit_add_mapset(struct navit *this_, struct mapset *ms)
108 this_->mapsets = g_list_append(this_->mapsets, ms);
112 navit_get_mapset(struct navit *this_)
114 return this_->mapsets->data;
118 navit_get_tracking(struct navit *this_)
120 return this_->tracking;
124 navit_add_layout(struct navit *this_, struct layout *lay)
126 this_->layouts = g_list_append(this_->layouts, lay);
130 navit_draw(struct navit *this_)
133 struct navit_vehicle *nv;
135 transform_setup_source_rect(this_->trans);
136 graphics_draw(this_->gra, this_->displaylist, this_->mapsets, this_->trans, this_->layouts, this_->route);
140 navit_vehicle_draw(this_, nv, NULL);
147 navit_draw_displaylist(struct navit *this_)
150 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layouts, this_->route);
155 navit_resize(void *data, int w, int h)
157 struct navit *this_=data;
158 transform_set_size(this_->trans, w, h);
163 navit_popup(void *data)
165 struct navit *this_=data;
166 popup(this_, 1, &this_->pressed);
167 this_->button_timeout=0;
173 navit_button(void *data, int pressed, int button, struct point *p)
175 struct navit *this_=data;
182 this_->button_pressed=1;
185 this_->button_timeout=g_timeout_add(500, navit_popup, data);
188 navit_set_center_screen(this_, p);
190 popup(this_, button, p);
192 navit_zoom_in(this_, 2, p);
194 navit_zoom_out(this_, 2, p);
196 this_->button_pressed=0;
197 if (this_->button_timeout) {
198 g_source_remove(this_->button_timeout);
199 this_->button_timeout=0;
200 if (! this_->moved && ! transform_within_border(this_->trans, p, border))
201 navit_set_center_screen(this_, p);
204 if (this_->motion_timeout) {
205 g_source_remove(this_->motion_timeout);
206 this_->motion_timeout=0;
210 transform_get_size(this_->trans, &p.x, &p.y);
213 p.x-=this_->last.x-this_->pressed.x;
214 p.y-=this_->last.y-this_->pressed.y;
215 navit_set_center_screen(this_, &p);
222 navit_motion_timeout(void *data)
224 struct navit *this_=data;
227 dx=(this_->current.x-this_->last.x);
228 dy=(this_->current.y-this_->last.y);
230 this_->last=this_->current;
231 graphics_displaylist_move(this_->displaylist, dx, dy);
232 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layouts, this_->route);
235 this_->motion_timeout=0;
240 navit_motion(void *data, struct point *p)
242 struct navit *this_=data;
245 if (this_->button_pressed && !this_->popped) {
246 dx=(p->x-this_->pressed.x);
247 dy=(p->y-this_->pressed.y);
248 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
249 if (this_->button_timeout) {
250 g_source_remove(this_->button_timeout);
251 this_->button_timeout=0;
254 if (! this_->motion_timeout)
255 this_->motion_timeout=g_timeout_add(100, navit_motion_timeout, data);
261 navit_scale(struct navit *this_, long scale, struct point *p)
263 struct coord c1, c2, *center;
265 transform_reverse(this_->trans, p, &c1);
266 transform_set_scale(this_->trans, scale);
268 transform_reverse(this_->trans, p, &c2);
269 center = transform_center(this_->trans);
270 center->x += c1.x - c2.x;
271 center->y += c1.y - c2.y;
277 * Change the current zoom level, zooming closer to the ground
279 * @param navit The navit instance
280 * @param factor The zoom factor, usually 2
281 * @param p The invariant point (if set to NULL, default to center)
285 navit_zoom_in(struct navit *this_, int factor, struct point *p)
287 long scale=transform_get_scale(this_->trans)/factor;
290 navit_scale(this_, scale, p);
294 * Change the current zoom level
296 * @param navit The navit instance
297 * @param factor The zoom factor, usually 2
298 * @param p The invariant point (if set to NULL, default to center)
302 navit_zoom_out(struct navit *this_, int factor, struct point *p)
304 long scale=transform_get_scale(this_->trans)*factor;
305 navit_scale(this_, scale, p);
309 navit_new(struct pcoord *center, int zoom)
311 struct navit *this_=g_new0(struct navit, 1);
314 main_add_navit(this_);
315 this_->self.type=attr_navit;
316 this_->self.u.navit=this_;
317 this_->vehicle_cbl=callback_list_new();
318 this_->init_cbl=callback_list_new();
320 f=popen("pidof /usr/bin/ipaq-sleep","r");
322 fscanf(f,"%d",&this_->pid);
323 dbg(1,"ipaq_sleep pid=%d\n", this_->pid);
327 this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
328 this_->cursor_flag=1;
329 this_->tracking_flag=1;
330 this_->trans=transform_new();
331 transform_setup(this_->trans, center, zoom, 0);
332 this_->displaylist=graphics_displaylist_new();
337 navit_set_gui(struct navit *this_, struct gui *gui, char *type)
340 this_->gui_type=g_strdup(type);
341 if (gui_has_main_loop(this_->gui)) {
342 if (! main_loop_gui) {
343 main_loop_gui=this_->gui;
345 g_warning("gui with main loop already active, ignoring this instance");
349 this_->menubar=gui_menubar_new(this_->gui);
350 this_->toolbar=gui_toolbar_new(this_->gui);
351 this_->statusbar=gui_statusbar_new(this_->gui);
355 navit_set_graphics(struct navit *this_, struct graphics *gra, char *type)
358 this_->gra_type=g_strdup(type);
359 graphics_register_resize_callback(this_->gra, navit_resize, this_);
360 graphics_register_button_callback(this_->gra, navit_button, this_);
361 graphics_register_motion_callback(this_->gra, navit_motion, this_);
365 navit_get_graphics(struct navit *this_)
371 navit_map_toggle(struct menu *menu, struct navit *this_, struct map *map)
373 if ((menu_get_toggle(menu) != 0) != (map_get_active(map) != 0)) {
374 map_set_active(map, (menu_get_toggle(menu) != 0));
380 navit_projection_set(struct navit *this_, enum projection pro)
385 c=transform_center(this_->trans);
386 transform_to_geo(transform_get_projection(this_->trans), c, &g);
387 transform_set_projection(this_->trans, pro);
388 transform_from_geo(pro, &g, c);
393 navit_add_menu_destinations(struct navit *this_, char *name, struct menu *rmen, GHashTable *h, struct callback *cb)
397 struct menu *men,*nmen;
403 while (h && (i=index(n, '/'))) {
404 strcpy(buffer2, name);
405 buffer2[i-name]='\0';
406 if (!(nmen=g_hash_table_lookup(h, buffer2))) {
407 nmen=menu_add(men, buffer2+(n-name), menu_type_submenu, NULL);
408 g_hash_table_insert(h, g_strdup(buffer2), nmen);
413 menu_add(men, n, menu_type_menu, cb);
418 navit_proj2str(enum projection pro)
423 case projection_garmin:
430 navit_append_coord(struct navit *this_, char *file, struct pcoord *c, char *type, char *description, struct menu *rmen, GHashTable *h, void (*cb_func)(void))
442 prostr = navit_proj2str(c->pro);
443 fprintf(f,"%s%s0x%x 0x%x type=%s label=\"%s\"\n",
444 prostr, *prostr ? ":" : "", c->x, c->y, type, description);
450 buffer=g_strdup(description);
451 cb=callback_new_2(cb_func, this_, (void *)offset);
452 navit_add_menu_destinations(this_, buffer, rmen, h, cb);
458 parse_line(FILE *f, char *buffer, char **name, struct pcoord *c)
464 enum projection pro = projection_mg;
466 if (! fgets(buffer, 2048, f))
469 pos=coord_parse(cp, pro, &co);
472 if (!cp[pos] || cp[pos] == '\n')
474 cp[strlen(cp)-1]='\0';
476 if (!strncmp(s,"type=", 5)) {
494 navit_set_destination_from_file(struct navit *this_, char *file, int bookmark, int offset)
497 char *name, *description, buffer[2048];
503 fseek(f, offset, SEEK_SET);
504 if (parse_line(f, buffer, &name, &c) <= 0)
507 description=g_strdup_printf("Bookmark %s", name);
508 navit_set_destination(this_, &c, description);
511 navit_set_destination(this_, &c, name);
515 navit_set_destination_from_destination(struct navit *this_, void *offset_p)
517 navit_set_destination_from_file(this_, "destination.txt", 0, (int)offset_p);
521 navit_set_destination_from_bookmark(struct navit *this_, void *offset_p)
523 navit_set_destination_from_file(this_, "bookmark.txt", 1, (int)offset_p);
527 * Start the route computing to a given set of coordinates
529 * @param navit The navit instance
530 * @param c The coordinate to start routing to
531 * @param description A label which allows the user to later identify this destination in the former destinations selection
535 navit_set_destination(struct navit *this_, struct pcoord *c, char *description)
537 navit_append_coord(this_, "destination.txt", c, "former_destination", description, this_->destinations, NULL, callback_cast(navit_set_destination_from_destination));
539 route_set_destination(this_->route, c);
545 * Record the given set of coordinates as a bookmark
547 * @param navit The navit instance
548 * @param c The coordinate to store
549 * @param description A label which allows the user to later identify this bookmark
553 navit_add_bookmark(struct navit *this_, struct pcoord *c, char *description)
555 navit_append_coord(this_,"bookmark.txt", c, "bookmark", description, this_->bookmarks, this_->bookmarks_hash, callback_cast(navit_set_destination_from_bookmark));
558 struct navit *global_navit;
565 navit_debug(struct navit *this_)
570 struct search_list *sl;
571 struct search_list_result *res;
573 debug_level_set("data_mg:town_search_get_item",9);
574 debug_level_set("data_mg:town_search_compare",9);
575 debug_level_set("data_mg:tree_search_next",9);
576 debug_level_set("data_mg:map_search_new_mg",9);
577 sl=search_list_new(this_->mapsets->data);
578 attr.type=attr_country_all;
580 search_list_search(sl, &attr, 1);
581 while ((res=search_list_get_result(sl))) {
582 printf("country result\n");
584 attr.type=attr_town_name;
586 search_list_search(sl, &attr, 1);
587 while ((res=search_list_get_result(sl))) {
588 printf("town result\n");
590 attr.type=attr_street_name;
592 search_list_search(sl, &attr, 1);
593 while ((res=search_list_get_result(sl))) {
594 printf("street result\n");
596 search_list_destroy(sl);
602 navit_add_menu_layouts(struct navit *this_, struct menu *men)
604 menu_add(men, "Test", menu_type_menu, NULL);
608 navit_add_menu_layout(struct navit *this_, struct menu *men)
610 navit_add_menu_layouts(this_, menu_add(men, _("Layout"), menu_type_submenu, NULL));
614 navit_add_menu_projections(struct navit *this_, struct menu *men)
617 cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_mg);
618 menu_add(men, "M&G", menu_type_menu, cb);
619 cb=callback_new_2(callback_cast(navit_projection_set), this_, (void *)projection_garmin);
620 menu_add(men, "Garmin", menu_type_menu, cb);
624 navit_add_menu_projection(struct navit *this_, struct menu *men)
626 navit_add_menu_projections(this_, menu_add(men, _("Projection"), menu_type_submenu, NULL));
630 navit_add_menu_maps(struct navit *this_, struct mapset *ms, struct menu *men)
632 struct mapset_handle *handle;
637 handle=mapset_open(ms);
638 while ((map=mapset_next(handle,0))) {
639 char *s=g_strdup_printf("%s:%s", map_get_type(map), map_get_filename(map));
640 cb=callback_new_3(callback_cast(navit_map_toggle), NULL, this_, map);
641 mmen=menu_add(men, s, menu_type_toggle, cb);
642 callback_set_arg(cb, 0, mmen);
643 menu_set_toggle(mmen, map_get_active(map));
646 mapset_close(handle);
650 navit_add_menu_destinations_from_file(struct navit *this_, char *file, struct menu *rmen, GHashTable *h, struct route *route, void (*cb_func)(void))
662 while (! feof(f) && (pos=parse_line(f, buffer, &name, &c)) > -3) {
664 cb=callback_new_2(cb_func, this_, (void *)offset);
665 navit_add_menu_destinations(this_, name, rmen, h, cb);
673 route_set_destination(route, &c);
678 navit_add_menu_former_destinations(struct navit *this_, struct menu *men, struct route *route)
681 this_->destinations=menu_add(men, _("Former Destinations"), menu_type_submenu, NULL);
683 this_->destinations=NULL;
684 navit_add_menu_destinations_from_file(this_, "destination.txt", this_->destinations, NULL, route, callback_cast(navit_set_destination_from_destination));
688 navit_add_menu_bookmarks(struct navit *this_, struct menu *men)
691 this_->bookmarks=menu_add(men, _("Bookmarks"), menu_type_submenu, NULL);
693 this_->bookmarks=NULL;
694 navit_add_menu_destinations_from_file(this_, "bookmark.txt", this_->bookmarks, this_->bookmarks_hash, NULL, callback_cast(navit_set_destination_from_bookmark));
698 navit_vehicle_toggle(struct navit *this_, struct navit_vehicle *nv)
700 if (menu_get_toggle(nv->menu)) {
701 if (this_->vehicle && this_->vehicle != nv)
702 menu_set_toggle(this_->vehicle->menu, 0);
705 if (this_->vehicle == nv)
711 navit_add_menu_vehicles(struct navit *this_, struct menu *men)
713 struct navit_vehicle *nv;
719 cb=callback_new_2(callback_cast(navit_vehicle_toggle), this_, nv);
720 nv->menu=menu_add(men, nv->name, menu_type_toggle, cb);
721 menu_set_toggle(nv->menu, this_->vehicle == nv);
727 navit_add_menu_vehicle(struct navit *this_, struct menu *men)
729 men=menu_add(men, _("Vehicle"), menu_type_submenu, NULL);
730 navit_add_menu_vehicles(this_, men);
734 navit_speak(struct navit *this_)
736 struct navigation *nav=this_->navigation;
737 struct navigation_list *list;
741 list=navigation_list_new(nav);
742 item=navigation_list_get_item(list);
743 if (item_attr_get(item, attr_navigation_speech, &attr))
744 speech_say(this_->speech, attr.u.str);
745 navigation_list_destroy(list);
749 navit_window_roadbook_update(struct navit *this_)
751 struct navigation *nav=this_->navigation;
752 struct navigation_list *list;
755 struct param_list param[1];
758 datawindow_mode(this_->roadbook_window, 1);
759 list=navigation_list_new(nav);
760 while ((item=navigation_list_get_item(list))) {
762 item_attr_get(item, attr_navigation_long, &attr);
763 dbg(2, "Command='%s'\n", attr.u.str);
764 param[0].name="Command";
765 param[0].value=attr.u.str;
766 datawindow_add(this_->roadbook_window, param, 1);
768 navigation_list_destroy(list);
769 datawindow_mode(this_->roadbook_window, 0);
773 navit_window_roadbook_destroy(struct navit *this_)
776 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
777 this_->roadbook_window=NULL;
778 this_->roadbook_callback=NULL;
781 navit_window_roadbook_new(struct navit *this_)
783 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
784 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
785 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
786 navit_window_roadbook_update(this_);
790 get_direction(char *buffer, int angle, int mode)
795 sprintf(buffer,"%d",angle);
798 if (angle < 69 || angle > 291)
800 if (angle > 111 && angle < 249)
802 if (angle > 22 && angle < 158)
804 if (angle > 202 && angle < 338)
812 sprintf(buffer,"%d H", angle);
817 struct navit_window_items {
818 struct datawindow *win;
819 struct callback *click;
827 navit_window_items_click(struct navit *this_, struct navit_window_items *nwi, char **col)
833 dbg(0,"enter col=%s,%s,%s,%s,%s\n", col[0], col[1], col[2], col[3], col[4]);
834 sscanf(col[4], "0x%x,0x%x", &c.x, &c.y);
835 c.pro = projection_mg;
836 dbg(0,"0x%x,0x%x\n", c.x, c.y);
837 description=g_strdup_printf("%s %s", nwi->name, col[3]);
838 navit_set_destination(this_, &c, description);
843 navit_window_items_open(struct navit *this_, struct navit_window_items *nwi)
845 struct map_selection sel;
846 struct coord c,*center;
847 struct mapset_handle *h;
853 struct param_list param[5];
858 dbg(0, "distance=%d\n", nwi->distance);
859 if (nwi->distance == -1)
862 dist=nwi->distance*1000;
863 param[0].name="Distance";
864 param[1].name="Direction";
865 param[2].name="Type";
866 param[3].name="Name";
870 sel.order[layer_town]=18;
871 sel.order[layer_street]=18;
872 sel.order[layer_poly]=18;
874 sel.order[layer_town]=0;
875 sel.order[layer_street]=0;
876 sel.order[layer_poly]=0;
878 center=transform_center(this_->trans);
879 sel.u.c_rect.lu.x=center->x-dist;
880 sel.u.c_rect.lu.y=center->y+dist;
881 sel.u.c_rect.rl.x=center->x+dist;
882 sel.u.c_rect.rl.y=center->y-dist;
883 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);
884 nwi->click=callback_new_2(callback_cast(navit_window_items_click), this_, nwi);
885 nwi->win=gui_datawindow_new(this_->gui, nwi->name, nwi->click, NULL);
886 h=mapset_open(navit_get_mapset(this_));
887 while ((m=mapset_next(h, 1))) {
888 dbg(2,"m=%p %s\n", m, map_get_filename(m));
889 mr=map_rect_new(m, &sel);
890 dbg(2,"mr=%p\n", mr);
891 while ((item=map_rect_get_item(mr))) {
892 if (item_coord_get(item, &c, 1)) {
893 if (coord_rect_contains(&sel.u.c_rect, &c) && g_hash_table_lookup(nwi->hash, &item->type)) {
894 if (! item_attr_get(item, attr_label, &attr))
896 idist=transform_distance(map_projection(item->map), center, &c);
898 get_direction(dirbuf, transform_get_angle_delta(center, &c, 0), 1);
899 param[0].value=distbuf;
900 param[1].value=dirbuf;
901 param[2].value=item_to_name(item->type);
902 sprintf(distbuf,"%d", idist/1000);
903 param[3].value=attr.u.str;
904 sprintf(coordbuf, "0x%x,0x%x", c.x, c.y);
905 param[4].value=coordbuf;
906 datawindow_add(nwi->win, param, 5);
908 /* printf("gefunden %s %s %d\n",item_to_name(item->type), attr.u.str, idist/1000); */
910 if (item->type >= type_line)
911 while (item_coord_get(item, &c, 1));
914 map_rect_destroy(mr);
919 struct navit_window_items *
920 navit_window_items_new(const char *name, int distance)
922 struct navit_window_items *nwi=g_new0(struct navit_window_items, 1);
923 nwi->name=g_strdup(name);
924 nwi->distance=distance;
925 nwi->hash=g_hash_table_new(g_int_hash, g_int_equal);
931 navit_window_items_add_item(struct navit_window_items *nwi, enum item_type type)
933 nwi->list=g_list_prepend(nwi->list, (void *)type);
934 g_hash_table_insert(nwi->hash, &nwi->list->data, (void *)1);
938 navit_add_window_items(struct navit *this_, struct navit_window_items *nwi)
940 this_->windows_items=g_list_append(this_->windows_items, nwi);
944 navit_add_menu_windows_items(struct navit *this_, struct menu *men)
946 struct navit_window_items *nwi;
949 l=this_->windows_items;
952 cb=callback_new_2(callback_cast(navit_window_items_open), this_, nwi);
953 menu_add(men, nwi->name, menu_type_menu, cb);
959 navit_init(struct navit *this_)
964 struct navit_vehicle *nv;
967 g_warning("failed to instantiate gui '%s'\n",this_->gui_type);
968 navit_destroy(this_);
972 g_warning("failed to instantiate gui '%s'\n",this_->gra_type);
973 navit_destroy(this_);
976 if (gui_set_graphics(this_->gui, this_->gra)) {
977 g_warning("failed to connect graphics '%s' to gui '%s'\n", this_->gra_type, this_->gui_type);
978 g_warning(" Please see http://navit.sourceforge.net/wiki/index.php/Failed_to_connect_graphics_to_gui\n");
979 g_warning(" for explanations and solutions\n");
981 navit_destroy(this_);
984 graphics_init(this_->gra);
987 dbg(1,"parsed one vehicle\n");
989 nv->cursor=cursor_new(this_->gra, &nv->c);
990 nv->callback.type=attr_callback;
991 nv->callback.u.callback=callback_new_2(callback_cast(navit_vehicle_update), this_, nv);
992 vehicle_add_attr(nv->vehicle, &nv->callback, NULL);
993 vehicle_set_attr(nv->vehicle, &this_->self, NULL);
996 if (this_->mapsets) {
997 ms=this_->mapsets->data;
999 route_set_mapset(this_->route, ms);
1000 if (this_->tracking)
1001 tracking_set_mapset(this_->tracking, ms);
1002 if (this_->navigation)
1003 navigation_set_mapset(this_->navigation, ms);
1004 if (this_->menubar) {
1005 men=menu_add(this_->menubar, _("Map"), menu_type_submenu, NULL);
1007 navit_add_menu_layout(this_, men);
1008 navit_add_menu_projection(this_, men);
1009 navit_add_menu_vehicle(this_, men);
1010 navit_add_menu_maps(this_, ms, men);
1012 men=menu_add(this_->menubar, _("Route"), menu_type_submenu, NULL);
1014 navit_add_menu_former_destinations(this_, men, this_->route);
1015 navit_add_menu_bookmarks(this_, men);
1018 navit_add_menu_former_destinations(this_, NULL, this_->route);
1020 if (this_->navigation && this_->speech) {
1021 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1022 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1026 if (this_->menubar) {
1027 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1029 navit_add_menu_windows_items(this_, men);
1034 navit_window_roadbook_new(this_);
1035 navit_window_items_new(this_);
1038 callback_list_call_1(this_->init_cbl, this_);
1042 navit_set_center(struct navit *this_, struct coord *center)
1044 struct coord *c=transform_center(this_->trans);
1051 navit_set_center_cursor(struct navit *this_, struct coord *cursor, int dir, int xpercent, int ypercent)
1053 struct coord *c=transform_center(this_->trans);
1058 transform_get_size(this_->trans, &width, &height);
1060 transform_set_angle(this_->trans, dir);
1061 p.x=(100-xpercent)*width/100;
1062 p.y=(100-ypercent)*height/100;
1063 transform_reverse(this_->trans, &p, &cnew);
1072 navit_set_center_screen(struct navit *this_, struct point *p)
1075 transform_reverse(this_->trans, p, &c);
1076 navit_set_center(this_, &c);
1080 navit_toggle_cursor(struct navit *this_)
1082 this_->cursor_flag=1-this_->cursor_flag;
1086 * Toggle the tracking : automatic centering of the map on the main vehicle
1088 * @param navit The navit instance
1092 navit_toggle_tracking(struct navit *this_)
1094 this_->tracking_flag=1-this_->tracking_flag;
1098 * Toggle the north orientation : forces the map to be aimed at north
1100 * @param navit The navit instance
1104 navit_toggle_orient_north(struct navit *this_)
1106 this_->orient_north_flag=1-this_->orient_north_flag;
1110 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
1112 * @param navit The navit instance
1117 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
1120 enum projection pro;
1124 pro=transform_get_projection(this_->trans);
1125 transform(this_->trans, pro, &nv->coord, &pnt2);
1128 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
1130 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
1135 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
1137 struct attr attr_dir, attr_speed, attr_pos;
1138 struct pcoord cursor_pc;
1139 struct point cursor_pnt, *pnt=&cursor_pnt;
1140 enum projection pro;
1143 if (! vehicle_position_attr_get(nv->vehicle, attr_position_direction, &attr_dir) ||
1144 ! vehicle_position_attr_get(nv->vehicle, attr_position_speed, &attr_speed) ||
1145 ! vehicle_position_attr_get(nv->vehicle, attr_position_coord_geo, &attr_pos))
1147 nv->dir=*attr_dir.u.numd;
1148 nv->speed=*attr_speed.u.numd;
1149 pro=transform_get_projection(this_->trans);
1150 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
1151 if (nv != this_->vehicle) {
1152 navit_vehicle_draw(this_, nv, NULL);
1156 if (this_->tracking && this_->tracking_flag) {
1157 if (tracking_update(this_->tracking, &nv->coord, nv->dir)) {
1158 if (this_->route && nv->update_curr == 1)
1159 route_set_position_from_tracking(this_->route, this_->tracking);
1162 if (this_->route && nv->update_curr == 1) {
1163 cursor_pc.pro = pro;
1164 cursor_pc.x = nv->coord.x;
1165 cursor_pc.y = nv->coord.y;
1166 route_set_position(this_->route, &cursor_pc);
1170 if ((!transform(this_->trans, pro, &nv->coord, &cursor_pnt) || !transform_within_border(this_->trans, &cursor_pnt, border))) {
1171 if (!this_->cursor_flag)
1173 if (nv->follow_curr != 1) {
1174 if (this_->orient_north_flag)
1175 navit_set_center_cursor(this_, &nv->coord, 0, 50 - 30.*sin(M_PI*nv->dir/180.), 50 + 30.*cos(M_PI*nv->dir/180.));
1177 navit_set_center_cursor(this_, &nv->coord, nv->dir, 50, 80);
1182 if (this_->pid && nv->speed > 2)
1183 kill(this_->pid, SIGWINCH);
1184 if (this_->route && nv->update_curr == 1)
1185 navigation_update(this_->navigation, this_->route);
1186 if (this_->cursor_flag && nv->follow_curr == 1) {
1187 navit_set_center_cursor(this_, &nv->coord, nv->dir, 50, 80);
1190 if (nv->follow_curr > 1)
1193 nv->follow_curr=nv->follow;
1194 if (nv->update_curr > 1)
1197 nv->update_curr=nv->update;
1198 callback_list_call_2(this_->vehicle_cbl, this_, nv->vehicle);
1200 navit_vehicle_draw(this_, nv, pnt);
1204 * Set the position of the vehicle
1206 * @param navit The navit instance
1207 * @param c The coordinate to set as position
1212 navit_set_position(struct navit *this_, struct pcoord *c)
1215 route_set_position(this_->route, c);
1216 if (this_->navigation) {
1217 navigation_update(this_->navigation, this_->route);
1224 * Register a new vehicle
1226 * @param navit The navit instance
1227 * @param v The vehicle instance
1228 * @param name Guess? :)
1229 * @param c The color to use for the cursor, currently only used in GTK
1230 * @param update Wether to refresh the map each time this vehicle position changes (instead of only when it reaches a border)
1231 * @param follow Wether to center the map on this vehicle position
1232 * @returns a vehicle instance
1234 struct navit_vehicle *
1235 navit_add_vehicle(struct navit *this_, struct vehicle *v, struct attr **attrs)
1237 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
1238 struct attr *name,*update,*follow,*color,*active;
1240 if ((name=attr_search(attrs, NULL, attr_name)))
1241 nv->name=g_strdup(name->u.str);
1242 if ((update=attr_search(attrs, NULL, attr_update)))
1243 nv->update_curr=nv->update=update->u.num;
1244 if ((follow=attr_search(attrs, NULL, attr_follow)))
1245 nv->follow_curr=nv->follow=follow->u.num;
1246 if ((color=attr_search(attrs, NULL, attr_color))) {
1247 nv->c=*(color->u.color);
1249 this_->vehicles=g_list_append(this_->vehicles, nv);
1250 if ((active=attr_search(attrs, NULL, attr_active)) && active->u.num)
1251 navit_set_vehicle(this_, nv);
1257 navit_add_vehicle_cb(struct navit *this_, struct callback *cb)
1259 callback_list_add(this_->vehicle_cbl, cb);
1263 navit_remove_vehicle_cb(struct navit *this_, struct callback *cb)
1265 callback_list_remove(this_->vehicle_cbl, cb);
1269 navit_add_init_cb(struct navit *this_, struct callback *cb)
1271 callback_list_add(this_->init_cbl, cb);
1275 navit_remove_init_cb(struct navit *this_, struct callback *cb)
1277 callback_list_remove(this_->init_cbl, cb);
1281 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
1287 navit_tracking_add(struct navit *this_, struct tracking *tracking)
1289 this_->tracking=tracking;
1293 navit_route_add(struct navit *this_, struct route *route)
1299 navit_navigation_add(struct navit *this_, struct navigation *navigation)
1301 this_->navigation=navigation;
1305 navit_set_speech(struct navit *this_, struct speech *speech)
1307 this_->speech=speech;
1312 navit_get_gui(struct navit *this_)
1317 struct transformation *
1318 navit_get_trans(struct navit *this_)
1320 return this_->trans;
1324 navit_get_route(struct navit *this_)
1326 return this_->route;
1330 navit_get_navigation(struct navit *this_)
1332 return this_->navigation;
1335 struct displaylist *
1336 navit_get_displaylist(struct navit *this_)
1338 return this_->displaylist;
1342 navit_destroy(struct navit *this_)
1344 /* TODO: destroy objects contained in this_ */
1345 main_remove_navit(this_);
1350 navit_toggle_routegraph_display(struct navit *nav)
1354 route_toggle_routegraph_display(nav->route);