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.
35 #include "projection.h"
41 #include "transform.h"
47 #include "data_window.h"
49 #include "navigation.h"
61 #include "navit_nls.h"
64 #include "vehicleprofile.h"
67 * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object
71 //! The navit_vehicule
72 struct navit_vehicle {
74 /*! Limit of the follow counter. See navit_add_vehicle */
76 /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
80 struct coord last; /*< Position of the last update of this vehicle */
83 struct cursor *cursor;
84 struct vehicle *vehicle;
94 struct layout *layout_current;
96 struct action *action;
97 struct transformation *trans;
98 struct compass *compass;
100 struct navigation *navigation;
101 struct speech *speech;
102 struct tracking *tracking;
105 struct displaylist *displaylist;
108 int recentdest_count;
109 int osd_configuration;
111 GList *windows_items;
112 struct navit_vehicle *vehicle;
113 struct callback_list *attr_cbl;
114 struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb;
115 struct datawindow *roadbook_window;
116 struct map *bookmark;
117 struct map *former_destination;
118 GHashTable *bookmarks_hash;
119 struct point pressed, last, current;
120 int button_pressed,moved,popped,zoomed;
125 struct event_timeout *button_timeout, *motion_timeout;
126 struct callback *motion_timeout_callback;
128 int ignore_graphics_events;
129 struct log *textfile_debug_log;
130 struct pcoord destination;
131 int destination_valid;
136 struct messagelist *messages;
137 struct callback *resize_callback,*button_callback,*motion_callback;
138 struct vehicleprofile *vehicleprofile;
139 GList *vehicleprofiles;
144 struct gui *main_loop_gui;
149 struct mapset_handle *mapset_handle;
153 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
154 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
155 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
156 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
157 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir);
158 static void navit_cmd_zoom_to_route(struct navit *this);
159 static void navit_cmd_set_center_cursor(struct navit *this_);
160 static void navit_cmd_announcer_toggle(struct navit *this_);
161 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
164 navit_add_mapset(struct navit *this_, struct mapset *ms)
166 this_->mapsets = g_list_append(this_->mapsets, ms);
170 navit_get_mapset(struct navit *this_)
173 return this_->mapsets->data;
175 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
181 navit_get_tracking(struct navit *this_)
183 return this_->tracking;
187 navit_draw_async(struct navit *this_, int async)
190 struct navit_vehicle *nv;
192 if (this_->blocked) {
196 transform_setup_source_rect(this_->trans);
200 navit_vehicle_draw(this_, nv, NULL);
203 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL);
207 navit_draw(struct navit *this_)
209 navit_draw_async(this_, 0);
214 navit_draw_displaylist(struct navit *this_)
216 if (this_->ready == 3)
217 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 1);
221 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
224 if (attr->type != attr_route_status)
227 if (this_->ready != 3)
229 if (updated != route_status_path_done_new)
231 if (this_->vehicle) {
232 if (this_->vehicle->follow_curr == 1)
234 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
235 this_->vehicle->follow_curr=this_->vehicle->follow;
241 navit_handle_resize(struct navit *this_, int w, int h)
243 struct map_selection sel;
244 memset(&sel, 0, sizeof(sel));
249 transform_set_screen_selection(this_->trans, &sel);
251 graphics_set_rect(this_->gra, &sel.u.p_rect);
252 if (this_->ready == 3)
257 navit_resize(void *data, int w, int h)
259 struct navit *this=data;
260 if (!this->ignore_graphics_events)
261 navit_handle_resize(this, w, h);
265 navit_get_width(struct navit *this_)
272 navit_get_height(struct navit *this_)
278 navit_popup(void *data)
280 struct navit *this_=data;
281 popup(this_, 1, &this_->pressed);
282 this_->button_timeout=NULL;
288 navit_ignore_button(struct navit *this_)
290 if (this_->ignore_button)
292 this_->ignore_button=1;
297 navit_ignore_graphics_events(struct navit *this_, int ignore)
299 this_->ignore_graphics_events=ignore;
303 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
308 double angleo,anglen;
310 transform_reverse(tr, old, &co);
312 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
313 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
314 yaw=transform_get_yaw(tr)+angleo-anglen;
315 transform_set_yaw(tr, yaw % 360);
317 transform_reverse(tr, new, &cn);
318 cp=transform_get_center(tr);
321 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
322 transform_set_center(tr, &c);
326 navit_set_timeout(struct navit *this_)
329 follow.type=attr_follow;
330 follow.u.num=this_->center_timeout;
331 navit_set_attr(this_, &follow);
335 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
339 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, (void *)pressed, (void *)button, p);
340 if (this_->ignore_button) {
341 this_->ignore_button=0;
349 this_->button_pressed=1;
353 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
356 navit_set_center_screen(this_, p, 1);
358 popup(this_, button, p);
359 if (button == 4 && this_->use_mousewheel) {
361 navit_zoom_in(this_, 2, p);
363 if (button == 5 && this_->use_mousewheel) {
365 navit_zoom_out(this_, 2, p);
369 this_->button_pressed=0;
370 if (this_->button_timeout) {
371 event_remove_timeout(this_->button_timeout);
372 this_->button_timeout=NULL;
373 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
374 navit_set_center_screen(this_, p, !this_->zoomed);
377 if (this_->motion_timeout) {
378 event_remove_timeout(this_->motion_timeout);
379 this_->motion_timeout=NULL;
386 update_transformation(this_->trans, &this_->pressed, p, &pr);
388 update_transformation(this_->trans, &this_->pressed, p, NULL);
390 graphics_draw_drag(this_->gra, NULL);
391 graphics_overlay_disable(this_->gra, 0);
393 navit_set_timeout(this_);
402 navit_button(void *data, int pressed, int button, struct point *p)
404 struct navit *this=data;
405 if (!this->ignore_graphics_events) {
406 if (! this->popup_callback)
407 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
408 navit_handle_button(this, pressed, button, p, this->popup_callback);
414 navit_motion_timeout(struct navit *this_)
418 if (this_->drag_bitmap) {
420 point.x=(this_->current.x-this_->pressed.x);
421 point.y=(this_->current.y-this_->pressed.y);
422 if (graphics_draw_drag(this_->gra, &point)) {
423 graphics_overlay_disable(this_->gra, 1);
424 graphics_draw_mode(this_->gra, draw_mode_end);
426 this_->motion_timeout=NULL;
430 dx=(this_->current.x-this_->last.x);
431 dy=(this_->current.y-this_->last.y);
433 struct transformation *tr;
435 this_->last=this_->current;
436 graphics_overlay_disable(this_->gra, 1);
437 tr=transform_dup(this_->trans);
441 update_transformation(tr, &this_->pressed, &this_->current, &pr);
443 update_transformation(tr, &this_->pressed, &this_->current, NULL);
446 graphics_displaylist_move(this_->displaylist, dx, dy);
448 graphics_draw_cancel(this_->gra, this_->displaylist);
449 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, 0);
450 transform_destroy(tr);
453 this_->motion_timeout=NULL;
458 navit_handle_motion(struct navit *this_, struct point *p)
462 if (this_->button_pressed && !this_->popped) {
463 dx=(p->x-this_->pressed.x);
464 dy=(p->y-this_->pressed.y);
465 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
466 if (this_->button_timeout) {
467 event_remove_timeout(this_->button_timeout);
468 this_->button_timeout=NULL;
471 if (! this_->motion_timeout_callback)
472 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
473 if (! this_->motion_timeout)
474 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
480 navit_motion(void *data, struct point *p)
482 struct navit *this=data;
483 if (!this->ignore_graphics_events)
484 navit_handle_motion(this, p);
488 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
490 struct coord c1, c2, *center;
492 transform_reverse(this_->trans, p, &c1);
493 transform_set_scale(this_->trans, scale);
495 transform_reverse(this_->trans, p, &c2);
496 center = transform_center(this_->trans);
497 center->x += c1.x - c2.x;
498 center->y += c1.y - c2.y;
505 * @brief Automatically adjusts zoom level
507 * This function automatically adjusts the current
508 * zoom level according to the current speed.
510 * @param this_ The navit struct
511 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
512 * @param speed The vehicles speed in meters per second
513 * @param dir The direction into which the vehicle moves
516 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
523 if (! this_->autozoom_active) {
527 distance = speed * this_->autozoom_secs;
529 transform_get_size(this_->trans, &w, &h);
530 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
531 scale = transform_get_scale(this_->trans);
533 /* We make shure that the point we want to see is within a certain range
534 * around the vehicle. The radius of this circle is the size of the
535 * screen. This doesn't necessarily mean the point is visible because of
536 * perspective etc. Quite rough, but should be enough. */
539 new_scale = (double)distance / h * 16;
541 new_scale = (double)distance / w * 16;
544 if (abs(new_scale - scale) < 2) {
548 if (new_scale >= this_->autozoom_min) {
549 navit_scale(this_, (long)new_scale, &pc, 0);
551 if (scale != this_->autozoom_min) {
552 navit_scale(this_, this_->autozoom_min, &pc, 0);
558 * Change the current zoom level, zooming closer to the ground
560 * @param navit The navit instance
561 * @param factor The zoom factor, usually 2
562 * @param p The invariant point (if set to NULL, default to center)
566 navit_zoom_in(struct navit *this_, int factor, struct point *p)
568 long scale=transform_get_scale(this_->trans)/factor;
571 navit_scale(this_, scale, p, 1);
575 * Change the current zoom level
577 * @param navit The navit instance
578 * @param factor The zoom factor, usually 2
579 * @param p The invariant point (if set to NULL, default to center)
583 navit_zoom_out(struct navit *this_, int factor, struct point *p)
585 long scale=transform_get_scale(this_->trans)*factor;
586 navit_scale(this_, scale, p, 1);
590 navit_cmd_zoom_in(struct navit *this_)
593 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
594 navit_zoom_in(this_, 2, &p);
595 this_->vehicle->follow_curr=this_->vehicle->follow;
597 navit_zoom_in(this_, 2, NULL);
602 navit_cmd_zoom_out(struct navit *this_)
605 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
606 navit_zoom_out(this_, 2, &p);
607 this_->vehicle->follow_curr=this_->vehicle->follow;
609 navit_zoom_out(this_, 2, NULL);
613 static struct command_table commands[] = {
614 {"zoom_in",command_cast(navit_cmd_zoom_in)},
615 {"zoom_out",command_cast(navit_cmd_zoom_out)},
616 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
617 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
618 {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
623 navit_new(struct attr *parent, struct attr **attrs)
625 struct navit *this_=g_new0(struct navit, 1);
626 struct pcoord center;
629 enum projection pro=projection_mg;
634 this_->self.type=attr_navit;
635 this_->self.u.navit=this_;
636 this_->attr_cbl=callback_list_new();
637 main_add_navit(this_);
639 this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
641 this_->orientation=-1;
642 this_->tracking_flag=1;
643 this_->recentdest_count=10;
644 this_->osd_configuration=-1;
646 this_->center_timeout = 10;
647 this_->use_mousewheel = 1;
648 this_->autozoom_secs = 10;
649 this_->autozoom_min = 7;
650 this_->autozoom_active = 0;
651 this_->follow_cursor = 1;
653 this_->trans = transform_new();
654 transform_from_geo(pro, &g, &co);
659 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
660 for (;*attrs; attrs++) {
661 navit_set_attr_do(this_, *attrs, 1);
663 this_->displaylist=graphics_displaylist_new();
664 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
666 this_->messages = messagelist_new(attrs);
672 navit_set_gui(struct navit *this_, struct gui *gui)
677 if (gui_has_main_loop(this_->gui)) {
678 if (! main_loop_gui) {
679 main_loop_gui=this_->gui;
681 dbg(0,"gui with main loop already active, ignoring this instance");
689 navit_add_message(struct navit *this_, char *message)
691 message_new(this_->messages, message);
695 *navit_get_messages(struct navit *this_)
697 return message_get(this_->messages);
701 navit_set_graphics(struct navit *this_, struct graphics *gra)
706 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
707 graphics_add_callback(gra, this_->resize_callback);
708 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
709 graphics_add_callback(gra, this_->button_callback);
710 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
711 graphics_add_callback(gra, this_->motion_callback);
716 navit_get_graphics(struct navit *this_)
721 struct vehicleprofile *
722 navit_get_vehicleprofile(struct navit *this_)
724 return this_->vehicleprofile;
728 navit_get_vehicleprofiles(struct navit *this_)
730 return this_->vehicleprofiles;
734 navit_projection_set(struct navit *this_, enum projection pro)
739 c=transform_center(this_->trans);
740 transform_to_geo(transform_get_projection(this_->trans), c, &g);
741 transform_set_projection(this_->trans, pro);
742 transform_from_geo(pro, &g, c);
747 * @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite"
750 navit_append_coord(struct navit *this_, char *file, struct pcoord *c, const char *type, const char *description, GHashTable *h, int limit)
765 while ((ch = fgetc(f)) != EOF) {
766 if ((ch == '\n') && (prev != '\n')) {
772 if (prev != '\n') { // Last line did not end with a newline
777 f = fopen(file, "r+");
779 while (lines >= limit) { // We have to "scroll up"
781 numc = 0; // Counts how many bytes we have in our line to scroll up
782 while ((ch = fgetc(f)) != EOF) {
789 buffer=g_malloc(numc);
790 offset = numc; // Offset holds where we currently are
793 fseek(f,offset,SEEK_SET);
794 readc = fread(buffer,1,numc,f);
796 fseek(f,-(numc+readc),SEEK_CUR);
797 fwrite(buffer,1,readc,f);
800 } while (readc == numc);
804 ftruncate(fd,(offset-numc));
818 prostr = projection_to_name(c->pro,NULL);
819 fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\"\n",
820 prostr, *prostr ? ":" : "",
821 c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x,
822 c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y,
831 * navit_get_user_data_directory
833 * returns the directory used to store user data files (center.txt,
834 * destination.txt, bookmark.txt, ...)
836 * arg: gboolean create: create the directory if it does not exist
839 navit_get_user_data_directory(gboolean create) {
841 dir = getenv("NAVIT_USER_DATADIR");
842 if (create && !file_exists(dir)) {
843 dbg(0,"creating dir %s\n", dir);
844 if (file_mkdir(dir,0)) {
845 dbg(0,"failed creating dir %s\n", dir);
854 * navit_get_destination_file
856 * returns the name of the file used to store destinations with its
859 * arg: gboolean create: create the directory where the file is stored
860 * if it does not exist
863 navit_get_destination_file(gboolean create)
865 return g_strjoin(NULL, navit_get_user_data_directory(create), "/destination.txt", NULL);
869 * navit_get_bookmark_file
871 * returns the name of the file used to store bookmarks with its
874 * arg: gboolean create: create the directory where the file is stored
875 * if it does not exist
878 navit_get_bookmark_file(gboolean create)
880 return g_strjoin(NULL, navit_get_user_data_directory(create), "/bookmark.txt", NULL);
885 * navit_get_bookmark_file
887 * returns the name of the file used to store the center file with its
890 * arg: gboolean create: create the directory where the file is stored
891 * if it does not exist
894 navit_get_center_file(gboolean create)
896 return g_strjoin(NULL, navit_get_user_data_directory(create), "/center.txt", NULL);
900 navit_set_center_from_file(struct navit *this_, char *file)
902 #ifndef HAVE_API_ANDROID
906 size_t line_size = 0;
908 struct coord *center;
910 f = fopen(file, "r");
913 getline(&line, &line_size, f);
916 center = transform_center(this_->trans);
917 pro = transform_get_projection(this_->trans);
918 coord_parse(g_strchomp(line), pro, center);
926 navit_write_center_to_file(struct navit *this_, char *file)
930 struct coord *center;
932 f = fopen(file, "w+");
934 center = transform_center(this_->trans);
935 pro = transform_get_projection(this_->trans);
936 coord_print(pro, center, f);
946 * Start the route computing to a given set of coordinates
948 * @param navit The navit instance
949 * @param c The coordinate to start routing to
950 * @param description A label which allows the user to later identify this destination in the former destinations selection
954 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
957 this_->destination=*c;
958 this_->destination_valid=1;
960 this_->destination_valid=0;
961 char *destination_file = navit_get_destination_file(TRUE);
962 navit_append_coord(this_, destination_file, c, "former_destination", description, NULL, this_->recentdest_count);
963 g_free(destination_file);
964 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
966 route_set_destination(this_->route, c, async);
968 if (this_->ready == 3)
974 * @brief Checks if a route is calculated
976 * This function checks if a route is calculated.
978 * @param this_ The navit struct whose route should be checked.
979 * @return True if the route is set, false otherwise.
982 navit_check_route(struct navit *this_)
985 return route_get_path_set(this_->route);
992 * Record the given set of coordinates as a bookmark
994 * @param navit The navit instance
995 * @param c The coordinate to store
996 * @param description A label which allows the user to later identify this bookmark
1000 navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description)
1002 char *bookmark_file = navit_get_bookmark_file(TRUE);
1003 navit_append_coord(this_,bookmark_file, c, "bookmark", description, this_->bookmarks_hash,0);
1004 g_free(bookmark_file);
1006 callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
1009 struct navit *global_navit;
1012 navit_add_bookmarks_from_file(struct navit *this_)
1014 char *bookmark_file = navit_get_bookmark_file(FALSE);
1015 struct attr parent={attr_navit, .u.navit=this_};
1016 struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}};
1017 struct attr *attrs[]={&type, &data, NULL};
1019 this_->bookmark=map_new(&parent, attrs);
1020 g_free(bookmark_file);
1024 navit_former_destinations_active(struct navit *this_)
1026 char *destination_file = navit_get_destination_file(FALSE);
1030 f=fopen(destination_file,"r");
1032 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
1036 g_free(destination_file);
1041 navit_add_former_destinations_from_file(struct navit *this_)
1043 char *destination_file = navit_get_destination_file(FALSE);
1044 struct attr parent={attr_navit, .u.navit=this_};
1045 struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}};
1046 struct attr *attrs[]={&type, &data, NULL};
1047 struct map_rect *mr;
1053 this_->former_destination=map_new(&parent, attrs);
1054 g_free(destination_file);
1055 if (!this_->route || !navit_former_destinations_active(this_))
1057 mr=map_rect_new(this_->former_destination, NULL);
1058 while ((item=map_rect_get_item(mr))) {
1059 if (item->type == type_former_destination && item_coord_get(item, &c, 1))
1062 map_rect_destroy(mr);
1063 pc.pro=map_projection(this_->former_destination);
1067 route_set_destination(this_->route, &pc, 1);
1068 this_->destination=pc;
1069 this_->destination_valid=1;
1075 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1080 if (this_->textfile_debug_log && this_->vehicle) {
1081 str1=g_strdup_vprintf(fmt, ap);
1082 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1083 log_write(this_->textfile_debug_log, str2, strlen(str2));
1091 navit_speech_estimate(struct navit *this_, char *str)
1093 return speech_estimate_duration(this_->speech, str);
1097 navit_say(struct navit *this_, char *text)
1099 speech_say(this_->speech, text);
1103 * @brief Toggles the navigation announcer for navit
1104 * @param this_ The navit object
1107 navit_cmd_announcer_toggle(struct navit *this_)
1109 struct attr attr, speechattr;
1111 // search for the speech attribute
1112 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1114 // find out if the corresponding attribute attr_active has been set
1115 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1117 attr.u.num = !attr.u.num;
1119 // otherwise disable it because voice is enabled by default
1120 attr.type = attr_active;
1124 // apply the new state
1125 if(!speech_set_attr(speechattr.u.speech, &attr))
1128 // announce that the speech attribute has changed
1129 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1133 navit_speak(struct navit *this_)
1135 struct navigation *nav=this_->navigation;
1136 struct map *map=NULL;
1137 struct map_rect *mr=NULL;
1141 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1143 dbg(1, "this_.speech->active %i\n", attr.u.num);
1148 map=navigation_get_map(nav);
1150 mr=map_rect_new(map, NULL);
1152 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1153 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1154 speech_say(this_->speech, attr.u.str);
1155 navit_add_message(this_, attr.u.str);
1156 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1158 map_rect_destroy(mr);
1163 navit_window_roadbook_update(struct navit *this_)
1165 struct navigation *nav=this_->navigation;
1166 struct map *map=NULL;
1167 struct map_rect *mr=NULL;
1170 struct param_list param[5];
1174 datawindow_mode(this_->roadbook_window, 1);
1176 map=navigation_get_map(nav);
1178 mr=map_rect_new(map, NULL);
1179 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1181 dbg(0,"while loop\n");
1182 while ((item=map_rect_get_item(mr))) {
1183 dbg(0,"item=%p\n", item);
1185 if (item->type != type_nav_position) {
1186 item_attr_get(item, attr_navigation_long, &attr);
1187 if (attr.u.str == NULL) {
1190 dbg(2, "Command='%s'\n", attr.u.str);
1191 param[0].value=g_strdup(attr.u.str);
1193 param[0].value=_("Position");
1194 param[0].name=_("Command");
1196 item_attr_get(item, attr_length, &attr);
1197 dbg(2, "Length=%d\n", attr.u.num);
1198 param[1].name=_("Length");
1200 if ( attr.u.num >= 2000 )
1202 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1206 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1209 item_attr_get(item, attr_time, &attr);
1210 dbg(2, "Time=%d\n", attr.u.num);
1212 param[2].name=_("Time");
1215 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1219 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1222 item_attr_get(item, attr_destination_length, &attr);
1223 dbg(2, "Destlength=%d\n", attr.u.num);
1224 param[3].name=_("Destination Length");
1225 if ( attr.u.num >= 2000 )
1227 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1231 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1234 item_attr_get(item, attr_destination_time, &attr);
1235 dbg(2, "Desttime=%d\n", attr.u.num);
1237 param[4].name=_("Destination Time");
1240 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1244 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1246 datawindow_add(this_->roadbook_window, param, 5);
1248 map_rect_destroy(mr);
1250 datawindow_mode(this_->roadbook_window, 0);
1254 navit_window_roadbook_destroy(struct navit *this_)
1257 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1258 this_->roadbook_window=NULL;
1259 this_->roadbook_callback=NULL;
1262 navit_window_roadbook_new(struct navit *this_)
1264 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1268 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1269 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1270 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1271 navit_window_roadbook_update(this_);
1275 navit_init(struct navit *this_)
1280 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1283 navit_destroy(this_);
1287 dbg(0,"no graphics\n");
1288 navit_destroy(this_);
1291 dbg(2,"Connecting gui to graphics\n");
1292 if (gui_set_graphics(this_->gui, this_->gra)) {
1293 struct attr attr_type_gui, attr_type_graphics;
1294 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1295 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1296 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1297 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1298 dbg(0," for explanations and solutions\n");
1300 navit_destroy(this_);
1303 dbg(2,"Initializing graphics\n");
1304 graphics_init(this_->gra);
1305 dbg(2,"Setting Vehicle\n");
1306 navit_set_vehicle(this_, this_->vehicle);
1307 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1308 if (this_->mapsets) {
1309 ms=this_->mapsets->data;
1311 if ((map=route_get_map(this_->route)))
1312 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1313 if ((map=route_get_graph_map(this_->route))) {
1314 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1315 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1317 route_set_mapset(this_->route, ms);
1318 route_set_projection(this_->route, transform_get_projection(this_->trans));
1320 if (this_->tracking) {
1321 tracking_set_mapset(this_->tracking, ms);
1323 tracking_set_route(this_->tracking, this_->route);
1325 if (this_->navigation) {
1326 if ((map=navigation_get_map(this_->navigation))) {
1327 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1328 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1331 if (this_->tracking) {
1332 if ((map=tracking_get_map(this_->tracking))) {
1333 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1334 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1337 navit_add_bookmarks_from_file(this_);
1338 navit_add_former_destinations_from_file(this_);
1341 struct attr callback;
1342 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1343 callback.type=attr_callback;
1344 callback.u.callback=this_->route_cb;
1345 route_add_attr(this_->route, &callback);
1347 if (this_->navigation) {
1348 if (this_->speech) {
1349 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1350 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1353 navigation_set_route(this_->navigation, this_->route);
1355 dbg(2,"Setting Center\n");
1356 char *center_file = navit_get_center_file(FALSE);
1357 navit_set_center_from_file(this_, center_file);
1358 g_free(center_file);
1360 if (this_->menubar) {
1361 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1363 navit_add_menu_windows_items(this_, men);
1369 navit_window_roadbook_new(this_);
1370 navit_window_items_new(this_);
1372 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1375 messagelist_init(this_->messages);
1377 dbg(2,"ready=%d\n",this_->ready);
1378 if (this_->ready == 3)
1383 navit_zoom_to_route(struct navit *this_, int orientation)
1386 struct map_rect *mr=NULL;
1389 struct coord_rect r;
1390 int count=0,scale=16;
1394 map=route_get_map(this_->route);
1395 dbg(1,"map=%p\n",map);
1397 mr=map_rect_new(map, NULL);
1398 dbg(1,"mr=%p\n",mr);
1400 while ((item=map_rect_get_item(mr))) {
1401 dbg(1,"item=%s\n", item_to_name(item->type));
1402 while (item_coord_get(item, &c, 1)) {
1407 coord_rect_extend(&r, &c);
1414 c.x=(r.rl.x+r.lu.x)/2;
1415 c.y=(r.rl.y+r.lu.y)/2;
1416 dbg(1,"count=%d\n",count);
1417 if (orientation != -1)
1418 transform_set_yaw(this_->trans, orientation);
1419 transform_set_center(this_->trans, &c);
1420 dbg(1,"%x,%x-%x,%x\n", r.rl.x,r.rl.y,r.lu.x,r.lu.y);
1421 while (scale < 1<<20) {
1423 transform_set_scale(this_->trans, scale);
1424 transform_setup_source_rect(this_->trans);
1425 transform(this_->trans, transform_get_projection(this_->trans), &r.lu, &p1, 1, 0, 0, NULL);
1426 transform(this_->trans, transform_get_projection(this_->trans), &r.rl, &p2, 1, 0, 0, NULL);
1427 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1428 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1429 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1435 if (this_->ready == 3)
1436 navit_draw_async(this_,0);
1440 navit_cmd_zoom_to_route(struct navit *this)
1442 navit_zoom_to_route(this, 0);
1447 * Change the current zoom level
1449 * @param navit The navit instance
1450 * @param center The point where to center the map, including its projection
1454 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
1456 struct coord *c=transform_center(this_->trans);
1458 enum projection pro = transform_get_projection(this_->trans);
1459 if (pro != center->pro) {
1462 transform_from_to(&c1, center->pro, &c2, pro);
1469 navit_set_timeout(this_);
1470 if (this_->ready == 3)
1475 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
1479 transform_set_center(this_->trans, c);
1480 transform_get_size(this_->trans, &width, &height);
1483 update_transformation(this_->trans, &po, p, NULL);
1485 navit_set_timeout(this_);
1489 navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir)
1492 struct navit_vehicle *nv=this_->vehicle;
1494 float offset; // Cursor offset from the center of the screen (percent).
1495 float min_offset = 0.; // Percent offset at min_offset_speed.
1496 float max_offset = 30.; // Percent offset at max_offset_speed.
1497 int min_offset_speed = 2; // Speed in km/h
1498 int max_offset_speed = 50; // Speed ini km/h
1499 // Calculate cursor offset from the center of the screen, upon speed.
1500 if (nv->speed <= min_offset_speed) {
1501 offset = min_offset;
1502 } else if (nv->speed > max_offset_speed) {
1503 offset = max_offset;
1505 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
1508 transform_get_size(this_->trans, &width, &height);
1509 if (this_->orientation == -1) {
1511 p->y=(50 + offset)*height/100;
1516 if (this_->tracking && this_->tracking_flag) {
1517 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
1519 mdir=nv->dir-this_->orientation;
1522 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
1523 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
1525 *dir=this_->orientation;
1531 navit_set_center_cursor(struct navit *this_)
1535 struct navit_vehicle *nv=this_->vehicle;
1536 navit_get_cursor_pnt(this_, &pn, &dir);
1537 transform_set_yaw(this_->trans, dir);
1538 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
1539 navit_autozoom(this_, &nv->coord, nv->speed, 0);
1540 if (this_->ready == 3)
1541 navit_draw_async(this_, 1);
1545 navit_cmd_set_center_cursor(struct navit *this_)
1547 navit_set_center_cursor(this_);
1551 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
1555 transform_reverse(this_->trans, p, &c);
1558 pc.pro = transform_get_projection(this_->trans);
1559 navit_set_center(this_, &pc, set_timeout);
1563 switch((*attrs)->type) {
1565 zoom=(*attrs)->u.num;
1568 g=*((*attrs)->u.coord_geo);
1573 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
1575 int dir=0, orient_old=0, attr_updated=0;
1579 struct navit_vehicle *nv;
1580 struct attr active=(struct attr){attr_active,{(void *)0}};
1582 switch (attr->type) {
1584 attr_updated=(this_->autozoom_secs != attr->u.num);
1585 this_->autozoom_secs = attr->u.num;
1587 case attr_autozoom_active:
1588 attr_updated=(this_->autozoom_active != attr->u.num);
1589 this_->autozoom_active = attr->u.num;
1592 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
1593 dbg(1,"0x%x,0x%x\n",co.x,co.y);
1594 transform_set_center(this_->trans, &co);
1596 case attr_drag_bitmap:
1597 attr_updated=(this_->drag_bitmap != !!attr->u.num);
1598 this_->drag_bitmap=!!attr->u.num;
1601 if (!this_->vehicle)
1603 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
1604 this_->vehicle->follow_curr = attr->u.num;
1607 if(this_->layout_current!=attr->u.layout) {
1608 this_->layout_current=attr->u.layout;
1609 graphics_font_destroy_all(this_->gra);
1614 case attr_orientation:
1615 orient_old=this_->orientation;
1616 this_->orientation=attr->u.num;
1618 if (this_->orientation != -1) {
1619 dir = this_->orientation;
1621 if (this_->vehicle) {
1622 dir = this_->vehicle->dir;
1625 transform_set_yaw(this_->trans, dir);
1626 if (orient_old != this_->orientation) {
1627 if (this_->ready == 3)
1633 case attr_osd_configuration:
1634 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
1635 attr_updated=(this_->osd_configuration != attr->u.num);
1636 this_->osd_configuration=attr->u.num;
1639 attr_updated=(this_->pitch != attr->u.num);
1640 this_->pitch=attr->u.num;
1641 transform_set_pitch(this_->trans, this_->pitch);
1642 if (!init && attr_updated && this_->ready == 3)
1645 case attr_projection:
1646 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
1647 navit_projection_set(this_, attr->u.projection);
1651 case attr_recent_dest:
1652 attr_updated=(this_->recentdest_count != attr->u.num);
1653 this_->recentdest_count=attr->u.num;
1656 if(this_->speech && this_->speech != attr->u.speech) {
1658 this_->speech = attr->u.speech;
1662 attr_updated=(this_->center_timeout != attr->u.num);
1663 this_->center_timeout = attr->u.num;
1666 attr_updated=(this_->tracking_flag != !!attr->u.num);
1667 this_->tracking_flag=!!attr->u.num;
1669 case attr_use_mousewheel:
1670 attr_updated=(this_->use_mousewheel != !!attr->u.num);
1671 this_->use_mousewheel=!!attr->u.num;
1677 if (nv->vehicle == attr->u.vehicle) {
1678 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
1680 vehicle_set_attr(this_->vehicle->vehicle, &active, NULL);
1682 vehicle_set_attr(nv->vehicle, &active, NULL);
1685 navit_set_vehicle(this_, nv);
1691 zoom=transform_get_scale(this_->trans);
1692 attr_updated=(zoom != attr->u.num);
1693 transform_set_scale(this_->trans, attr->u.num);
1694 if (attr_updated && !init)
1698 navit_add_message(this_, attr->u.str);
1700 case attr_follow_cursor:
1701 attr_updated=(this_->follow_cursor != !!attr->u.num);
1702 this_->follow_cursor=!!attr->u.num;
1707 if (attr_updated && !init) {
1708 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1709 if (attr->type == attr_osd_configuration)
1710 graphics_draw_mode(this_->gra, draw_mode_end);
1716 navit_set_attr(struct navit *this_, struct attr *attr)
1718 return navit_set_attr_do(this_, attr, 0);
1722 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
1724 struct message *msg;
1730 msg = navit_get_messages(this_);
1738 len += strlen(msg->text) + 1;
1741 attr->u.str = g_malloc(len + 1);
1743 msg = navit_get_messages(this_);
1746 g_stpcpy((attr->u.str + offset), msg->text);
1747 offset += strlen(msg->text);
1748 attr->u.str[offset] = '\n';
1754 attr->u.str[len] = '\0';
1756 case attr_bookmark_map:
1757 attr->u.map=this_->bookmark;
1759 case attr_callback_list:
1760 attr->u.callback_list=this_->attr_cbl;
1762 case attr_destination:
1763 if (! this_->destination_valid)
1765 attr->u.pcoord=&this_->destination;
1767 case attr_displaylist:
1768 attr->u.displaylist=this_->displaylist;
1769 return (attr->u.displaylist != NULL);
1770 case attr_former_destination_map:
1771 attr->u.map=this_->former_destination;
1774 attr->u.graphics=this_->gra;
1775 ret=(attr->u.graphics != NULL);
1778 attr->u.gui=this_->gui;
1779 ret=(attr->u.gui != NULL);
1784 iter->u.list=g_list_next(iter->u.list);
1786 iter->u.list=this_->layouts;
1790 attr->u.layout=(struct layout *)iter->u.list->data;
1792 attr->u.layout=this_->layout_current;
1796 if (iter && this_->mapsets) {
1797 if (!iter->u.mapset_handle) {
1798 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
1800 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
1802 mapset_close(iter->u.mapset_handle);
1810 attr->u.mapset=this_->mapsets->data;
1811 return (attr->u.mapset != NULL);
1812 case attr_navigation:
1813 attr->u.navigation=this_->navigation;
1815 case attr_orientation:
1816 attr->u.num=this_->orientation;
1818 case attr_osd_configuration:
1819 attr->u.num=this_->osd_configuration;
1821 case attr_projection:
1823 attr->u.num=transform_get_projection(this_->trans);
1829 attr->u.route=this_->route;
1832 attr->u.speech=this_->speech;
1835 attr->u.num=this_->tracking_flag;
1837 case attr_transformation:
1838 attr->u.transformation=this_->trans;
1843 iter->u.list=g_list_next(iter->u.list);
1845 iter->u.list=this_->vehicles;
1849 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
1851 if(this_->vehicle) {
1852 attr->u.vehicle=this_->vehicle->vehicle;
1859 attr->u.num=transform_get_scale(this_->trans);
1861 case attr_autozoom_active:
1862 attr->u.num=this_->autozoom_active;
1864 case attr_follow_cursor:
1865 attr->u.num=this_->follow_cursor;
1875 navit_add_log(struct navit *this_, struct log *log)
1877 struct attr type_attr;
1878 if (!log_get_attr(log, attr_type, &type_attr, NULL))
1880 if (!strcmp(type_attr.u.str, "textfile_debug")) {
1881 char *header = "type=track_tracked\n";
1882 if (this_->textfile_debug_log)
1884 log_set_header(log, header, strlen(header));
1885 this_->textfile_debug_log=log;
1892 navit_add_attr(struct navit *this_, struct attr *attr)
1895 switch (attr->type) {
1897 navit_add_callback(this_, attr->u.callback);
1900 ret=navit_add_log(this_, attr->u.log);
1903 ret=navit_set_gui(this_, attr->u.gui);
1906 ret=navit_set_graphics(this_, attr->u.graphics);
1909 this_->layouts = g_list_append(this_->layouts, attr->u.layout);
1910 if(!this_->layout_current)
1911 this_->layout_current=attr->u.layout;
1914 this_->route=attr->u.route;
1917 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
1919 case attr_navigation:
1920 this_->navigation=attr->u.navigation;
1922 case attr_recent_dest:
1923 this_->recentdest_count = attr->u.num;
1926 this_->speech=attr->u.speech;
1929 this_->tracking=attr->u.tracking;
1932 ret=navit_add_vehicle(this_, attr->u.vehicle);
1934 case attr_vehicleprofile:
1935 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
1937 case attr_autozoom_min:
1938 this_->autozoom_min = attr->u.num;
1943 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1948 navit_remove_attr(struct navit *this_, struct attr *attr)
1951 switch (attr->type) {
1953 navit_remove_callback(this_, attr->u.callback);
1962 navit_attr_iter_new()
1964 return g_new0(struct attr_iter, 1);
1968 navit_attr_iter_destroy(struct attr_iter *iter)
1974 navit_add_callback(struct navit *this_, struct callback *cb)
1976 callback_list_add(this_->attr_cbl, cb);
1980 navit_remove_callback(struct navit *this_, struct callback *cb)
1982 callback_list_remove(this_->attr_cbl, cb);
1986 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
1988 * @param navit The navit instance
1993 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
1995 struct point cursor_pnt;
1996 enum projection pro;
2001 if (! vehicle_get_attr(nv->vehicle, attr_cursor, &cursor, NULL))
2003 if (! cursor.u.cursor)
2008 pro=transform_get_projection(this_->trans);
2009 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2011 cursor_draw(cursor.u.cursor, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed);
2016 pro=transform_get_projection(this_->trans);
2017 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2020 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2022 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2028 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2030 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2031 struct pcoord cursor_pc;
2032 struct point cursor_pnt, *pnt=&cursor_pnt;
2033 struct tracking *tracking=NULL;
2034 enum projection pro=transform_get_projection(this_->trans);
2036 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2040 if (this_->ready != 3) {
2041 profile(0,"return 1\n");
2044 if (this_->vehicle == nv && this_->tracking_flag)
2045 tracking=this_->tracking;
2047 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2048 attr_object=tracking;
2049 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2051 attr_object=nv->vehicle;
2052 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2054 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2055 if (!attr_valid.u.num != attr_position_valid_invalid)
2057 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2058 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2059 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2060 profile(0,"return 2\n");
2063 nv->dir=*attr_dir.u.numd;
2064 nv->speed=*attr_speed.u.numd;
2065 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2066 if (nv != this_->vehicle) {
2067 navit_vehicle_draw(this_, nv, NULL);
2068 profile(0,"return 3\n");
2071 cursor_pc.x = nv->coord.x;
2072 cursor_pc.y = nv->coord.y;
2073 cursor_pc.pro = pro;
2076 route_set_position_from_tracking(this_->route, tracking, pro);
2078 route_set_position(this_->route, &cursor_pc);
2080 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2081 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2082 if (this_->gui && nv->speed > 2)
2083 gui_disable_suspend(this_->gui);
2085 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2086 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
2087 (nv->follow_curr == 1 || !transform_within_border(this_->trans, &cursor_pnt, border)))
2088 navit_set_center_cursor(this_);
2090 navit_vehicle_draw(this_, nv, pnt);
2092 if (nv->follow_curr > 1)
2095 nv->follow_curr=nv->follow;
2096 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2098 /* Finally, if we reached our destination, stop navigation. */
2099 if (this_->route && route_destination_reached(this_->route)) {
2100 navit_set_destination(this_, NULL, NULL, 0);
2102 profile(0,"return 5\n");
2106 * Set the position of the vehicle
2108 * @param navit The navit instance
2109 * @param c The coordinate to set as position
2114 navit_set_position(struct navit *this_, struct pcoord *c)
2117 route_set_position(this_->route, c);
2118 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2120 if (this_->ready == 3)
2125 navit_set_vehicleprofile(struct navit *this_, char *name)
2129 l=this_->vehicleprofiles;
2131 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2132 if (!strcmp(attr.u.str, name)) {
2133 this_->vehicleprofile=l->data;
2135 route_set_profile(this_->route, this_->vehicleprofile);
2145 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2149 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2150 if (navit_set_vehicleprofile(this_, attr.u.str))
2153 navit_set_vehicleprofile(this_,"car");
2157 * Register a new vehicle
2159 * @param navit The navit instance
2160 * @param v The vehicle instance
2161 * @returns 1 for success
2164 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2166 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2167 struct attr follow,color,active, color2, animate;
2172 nv->animate_cursor=0;
2173 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2174 nv->follow=nv->follow=follow.u.num;
2175 if ((vehicle_get_attr(v, attr_color, &color, NULL)))
2176 nv->c=*(color.u.color);
2177 if ((vehicle_get_attr(v, attr_color2, &color2, NULL)))
2178 nv->c2=color2.u.color;
2181 nv->follow_curr=nv->follow;
2182 this_->vehicles=g_list_append(this_->vehicles, nv);
2183 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2184 navit_set_vehicle(this_, nv);
2185 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2186 nv->animate_cursor=animate.u.num;
2187 nv->callback.type=attr_callback;
2188 nv->callback.u.callback=callback_new_2(callback_cast(navit_vehicle_update), this_, nv);
2189 vehicle_add_attr(nv->vehicle, &nv->callback);
2190 vehicle_set_attr(nv->vehicle, &this_->self, NULL);
2198 navit_get_gui(struct navit *this_)
2203 struct transformation *
2204 navit_get_trans(struct navit *this_)
2206 return this_->trans;
2210 navit_get_route(struct navit *this_)
2212 return this_->route;
2216 navit_get_navigation(struct navit *this_)
2218 return this_->navigation;
2221 struct displaylist *
2222 navit_get_displaylist(struct navit *this_)
2224 return this_->displaylist;
2228 navit_block(struct navit *this_, int block)
2231 this_->blocked |= 1;
2232 if (graphics_draw_cancel(this_->gra, this_->displaylist))
2233 this_->blocked |= 2;
2236 if (this_->blocked & 2) {
2246 navit_destroy(struct navit *this_)
2248 /* TODO: destroy objects contained in this_ */
2250 vehicle_destroy(this_->vehicle->vehicle);
2251 main_remove_navit(this_);
2252 char *center_file = navit_get_center_file(TRUE);
2253 navit_write_center_to_file(this_, center_file);
2254 g_free(center_file);
2255 callback_destroy(this_->nav_speech_cb);
2256 callback_destroy(this_->roadbook_callback);
2257 callback_destroy(this_->popup_callback);
2258 callback_destroy(this_->motion_timeout_callback);
2260 graphics_remove_callback(this_->gra, this_->resize_callback);
2261 callback_destroy(this_->resize_callback);
2263 graphics_remove_callback(this_->gra, this_->button_callback);
2264 callback_destroy(this_->button_callback);
2266 graphics_remove_callback(this_->gra, this_->motion_callback);
2267 callback_destroy(this_->motion_callback);