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;
143 struct gui *main_loop_gui;
148 struct mapset_handle *mapset_handle;
152 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
153 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
154 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
155 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
156 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir);
157 static void navit_cmd_zoom_to_route(struct navit *this);
158 static void navit_cmd_set_center_cursor(struct navit *this_);
159 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
162 navit_add_mapset(struct navit *this_, struct mapset *ms)
164 this_->mapsets = g_list_append(this_->mapsets, ms);
168 navit_get_mapset(struct navit *this_)
171 return this_->mapsets->data;
173 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
179 navit_get_tracking(struct navit *this_)
181 return this_->tracking;
185 navit_draw_async(struct navit *this_, int async)
188 struct navit_vehicle *nv;
190 if (this_->blocked) {
194 transform_setup_source_rect(this_->trans);
198 navit_vehicle_draw(this_, nv, NULL);
201 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL);
205 navit_draw(struct navit *this_)
207 navit_draw_async(this_, 0);
212 navit_draw_displaylist(struct navit *this_)
214 if (this_->ready == 3)
215 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 1);
219 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
222 if (attr->type != attr_route_status)
225 if (this_->ready != 3)
227 if (updated != route_status_path_done_new)
229 if (this_->vehicle) {
230 if (this_->vehicle->follow_curr == 1)
232 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
233 this_->vehicle->follow_curr=this_->vehicle->follow;
239 navit_handle_resize(struct navit *this_, int w, int h)
241 struct map_selection sel;
242 memset(&sel, 0, sizeof(sel));
247 transform_set_screen_selection(this_->trans, &sel);
249 graphics_set_rect(this_->gra, &sel.u.p_rect);
250 if (this_->ready == 3)
255 navit_resize(void *data, int w, int h)
257 struct navit *this=data;
258 if (!this->ignore_graphics_events)
259 navit_handle_resize(this, w, h);
263 navit_get_width(struct navit *this_)
270 navit_get_height(struct navit *this_)
276 navit_popup(void *data)
278 struct navit *this_=data;
279 popup(this_, 1, &this_->pressed);
280 this_->button_timeout=NULL;
286 navit_ignore_button(struct navit *this_)
288 if (this_->ignore_button)
290 this_->ignore_button=1;
295 navit_ignore_graphics_events(struct navit *this_, int ignore)
297 this_->ignore_graphics_events=ignore;
301 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
306 double angleo,anglen;
308 transform_reverse(tr, old, &co);
310 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
311 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
312 yaw=transform_get_yaw(tr)+angleo-anglen;
313 transform_set_yaw(tr, yaw % 360);
315 transform_reverse(tr, new, &cn);
316 cp=transform_get_center(tr);
319 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
320 transform_set_center(tr, &c);
324 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
328 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, (void *)pressed, (void *)button, p);
329 if (this_->ignore_button) {
330 this_->ignore_button=0;
338 this_->button_pressed=1;
342 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
345 navit_set_center_screen(this_, p);
347 popup(this_, button, p);
348 if (button == 4 && this_->use_mousewheel) {
350 navit_zoom_in(this_, 2, p);
352 if (button == 5 && this_->use_mousewheel) {
354 navit_zoom_out(this_, 2, p);
358 follow.type=attr_follow;
359 follow.u.num=this_->center_timeout;
361 this_->button_pressed=0;
362 if (this_->button_timeout) {
363 event_remove_timeout(this_->button_timeout);
364 this_->button_timeout=NULL;
365 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
367 navit_set_attr(this_, &follow);
368 navit_set_center_screen(this_, p);
371 if (this_->motion_timeout) {
372 event_remove_timeout(this_->motion_timeout);
373 this_->motion_timeout=NULL;
380 update_transformation(this_->trans, &this_->pressed, p, &pr);
382 update_transformation(this_->trans, &this_->pressed, p, NULL);
384 graphics_draw_drag(this_->gra, NULL);
385 graphics_overlay_disable(this_->gra, 0);
387 navit_set_attr(this_, &follow);
396 navit_button(void *data, int pressed, int button, struct point *p)
398 struct navit *this=data;
399 if (!this->ignore_graphics_events) {
400 if (! this->popup_callback)
401 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
402 navit_handle_button(this, pressed, button, p, this->popup_callback);
408 navit_motion_timeout(struct navit *this_)
412 if (this_->drag_bitmap) {
414 point.x=(this_->current.x-this_->pressed.x);
415 point.y=(this_->current.y-this_->pressed.y);
416 if (graphics_draw_drag(this_->gra, &point)) {
417 graphics_overlay_disable(this_->gra, 1);
418 graphics_draw_mode(this_->gra, draw_mode_end);
420 this_->motion_timeout=NULL;
424 dx=(this_->current.x-this_->last.x);
425 dy=(this_->current.y-this_->last.y);
427 struct transformation *tr;
429 this_->last=this_->current;
430 graphics_overlay_disable(this_->gra, 1);
431 tr=transform_dup(this_->trans);
435 update_transformation(tr, &this_->pressed, &this_->current, &pr);
437 update_transformation(tr, &this_->pressed, &this_->current, NULL);
440 graphics_displaylist_move(this_->displaylist, dx, dy);
442 graphics_draw_cancel(this_->gra, this_->displaylist);
443 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, 0);
444 transform_destroy(tr);
447 this_->motion_timeout=NULL;
452 navit_handle_motion(struct navit *this_, struct point *p)
456 if (this_->button_pressed && !this_->popped) {
457 dx=(p->x-this_->pressed.x);
458 dy=(p->y-this_->pressed.y);
459 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
460 if (this_->button_timeout) {
461 event_remove_timeout(this_->button_timeout);
462 this_->button_timeout=NULL;
465 if (! this_->motion_timeout_callback)
466 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
467 if (! this_->motion_timeout)
468 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
474 navit_motion(void *data, struct point *p)
476 struct navit *this=data;
477 if (!this->ignore_graphics_events)
478 navit_handle_motion(this, p);
482 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
484 struct coord c1, c2, *center;
486 transform_reverse(this_->trans, p, &c1);
487 transform_set_scale(this_->trans, scale);
489 transform_reverse(this_->trans, p, &c2);
490 center = transform_center(this_->trans);
491 center->x += c1.x - c2.x;
492 center->y += c1.y - c2.y;
499 * @brief Automatically adjusts zoom level
501 * This function automatically adjusts the current
502 * zoom level according to the current speed.
504 * @param this_ The navit struct
505 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
506 * @param speed The vehicles speed in meters per second
507 * @param dir The direction into which the vehicle moves
510 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
517 if (! this_->autozoom_active) {
521 distance = speed * this_->autozoom_secs;
523 transform_get_size(this_->trans, &w, &h);
524 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
525 scale = transform_get_scale(this_->trans);
527 /* We make shure that the point we want to see is within a certain range
528 * around the vehicle. The radius of this circle is the size of the
529 * screen. This doesn't necessarily mean the point is visible because of
530 * perspective etc. Quite rough, but should be enough. */
533 new_scale = (double)distance / h * 16;
535 new_scale = (double)distance / w * 16;
538 if (abs(new_scale - scale) < 2) {
542 if (new_scale >= this_->autozoom_min) {
543 navit_scale(this_, (long)new_scale, &pc, 0);
545 if (scale != this_->autozoom_min) {
546 navit_scale(this_, this_->autozoom_min, &pc, 0);
552 * Change the current zoom level, zooming closer to the ground
554 * @param navit The navit instance
555 * @param factor The zoom factor, usually 2
556 * @param p The invariant point (if set to NULL, default to center)
560 navit_zoom_in(struct navit *this_, int factor, struct point *p)
562 long scale=transform_get_scale(this_->trans)/factor;
565 navit_scale(this_, scale, p, 1);
569 * Change the current zoom level
571 * @param navit The navit instance
572 * @param factor The zoom factor, usually 2
573 * @param p The invariant point (if set to NULL, default to center)
577 navit_zoom_out(struct navit *this_, int factor, struct point *p)
579 long scale=transform_get_scale(this_->trans)*factor;
580 navit_scale(this_, scale, p, 1);
584 navit_cmd_zoom_in(struct navit *this_)
587 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
588 navit_zoom_in(this_, 2, &p);
589 this_->vehicle->follow_curr=this_->vehicle->follow;
591 navit_zoom_in(this_, 2, NULL);
596 navit_cmd_zoom_out(struct navit *this_)
599 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
600 navit_zoom_out(this_, 2, &p);
601 this_->vehicle->follow_curr=this_->vehicle->follow;
603 navit_zoom_out(this_, 2, NULL);
607 static struct command_table commands[] = {
608 {"zoom_in",command_cast(navit_cmd_zoom_in)},
609 {"zoom_out",command_cast(navit_cmd_zoom_out)},
610 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
611 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
616 navit_new(struct attr *parent, struct attr **attrs)
618 struct navit *this_=g_new0(struct navit, 1);
619 struct pcoord center;
622 enum projection pro=projection_mg;
627 this_->self.type=attr_navit;
628 this_->self.u.navit=this_;
629 this_->attr_cbl=callback_list_new();
630 main_add_navit(this_);
632 this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
634 this_->orientation=-1;
635 this_->tracking_flag=1;
636 this_->recentdest_count=10;
637 this_->osd_configuration=-1;
639 this_->center_timeout = 10;
640 this_->use_mousewheel = 1;
641 this_->autozoom_secs = 10;
642 this_->autozoom_min = 7;
643 this_->autozoom_active = 0;
645 this_->trans = transform_new();
646 transform_from_geo(pro, &g, &co);
651 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
652 for (;*attrs; attrs++) {
653 navit_set_attr_do(this_, *attrs, 1);
655 this_->displaylist=graphics_displaylist_new();
656 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
658 this_->messages = messagelist_new(attrs);
664 navit_set_gui(struct navit *this_, struct gui *gui)
669 if (gui_has_main_loop(this_->gui)) {
670 if (! main_loop_gui) {
671 main_loop_gui=this_->gui;
673 dbg(0,"gui with main loop already active, ignoring this instance");
681 navit_add_message(struct navit *this_, char *message)
683 message_new(this_->messages, message);
687 *navit_get_messages(struct navit *this_)
689 return message_get(this_->messages);
693 navit_set_graphics(struct navit *this_, struct graphics *gra)
698 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
699 graphics_add_callback(gra, this_->resize_callback);
700 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
701 graphics_add_callback(gra, this_->button_callback);
702 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
703 graphics_add_callback(gra, this_->motion_callback);
708 navit_get_graphics(struct navit *this_)
713 struct vehicleprofile *
714 navit_get_vehicleprofile(struct navit *this_)
716 return this_->vehicleprofile;
720 navit_projection_set(struct navit *this_, enum projection pro)
725 c=transform_center(this_->trans);
726 transform_to_geo(transform_get_projection(this_->trans), c, &g);
727 transform_set_projection(this_->trans, pro);
728 transform_from_geo(pro, &g, c);
733 * @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite"
736 navit_append_coord(struct navit *this_, char *file, struct pcoord *c, const char *type, const char *description, GHashTable *h, int limit)
751 while ((ch = fgetc(f)) != EOF) {
752 if ((ch == '\n') && (prev != '\n')) {
758 if (prev != '\n') { // Last line did not end with a newline
763 f = fopen(file, "r+");
765 while (lines >= limit) { // We have to "scroll up"
767 numc = 0; // Counts how many bytes we have in our line to scroll up
768 while ((ch = fgetc(f)) != EOF) {
775 buffer=g_malloc(numc);
776 offset = numc; // Offset holds where we currently are
779 fseek(f,offset,SEEK_SET);
780 readc = fread(buffer,1,numc,f);
782 fseek(f,-(numc+readc),SEEK_CUR);
783 fwrite(buffer,1,readc,f);
786 } while (readc == numc);
790 ftruncate(fd,(offset-numc));
804 prostr = projection_to_name(c->pro,NULL);
805 fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\"\n",
806 prostr, *prostr ? ":" : "",
807 c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x,
808 c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y,
817 * navit_get_user_data_directory
819 * returns the directory used to store user data files (center.txt,
820 * destination.txt, bookmark.txt, ...)
822 * arg: gboolean create: create the directory if it does not exist
825 navit_get_user_data_directory(gboolean create) {
827 dir = getenv("NAVIT_USER_DATADIR");
828 if (create && !file_exists(dir)) {
829 dbg(0,"creating dir %s\n", dir);
830 if (file_mkdir(dir,0)) {
831 dbg(0,"failed creating dir %s\n", dir);
840 * navit_get_destination_file
842 * returns the name of the file used to store destinations with its
845 * arg: gboolean create: create the directory where the file is stored
846 * if it does not exist
849 navit_get_destination_file(gboolean create)
851 return g_strjoin(NULL, navit_get_user_data_directory(create), "/destination.txt", NULL);
855 * navit_get_bookmark_file
857 * returns the name of the file used to store bookmarks with its
860 * arg: gboolean create: create the directory where the file is stored
861 * if it does not exist
864 navit_get_bookmark_file(gboolean create)
866 return g_strjoin(NULL, navit_get_user_data_directory(create), "/bookmark.txt", NULL);
871 * navit_get_bookmark_file
873 * returns the name of the file used to store the center file with its
876 * arg: gboolean create: create the directory where the file is stored
877 * if it does not exist
880 navit_get_center_file(gboolean create)
882 return g_strjoin(NULL, navit_get_user_data_directory(create), "/center.txt", NULL);
886 navit_set_center_from_file(struct navit *this_, char *file)
891 size_t line_size = 0;
893 struct coord *center;
895 f = fopen(file, "r");
898 getline(&line, &line_size, f);
901 center = transform_center(this_->trans);
902 pro = transform_get_projection(this_->trans);
903 coord_parse(g_strchomp(line), pro, center);
910 navit_write_center_to_file(struct navit *this_, char *file)
914 struct coord *center;
916 f = fopen(file, "w+");
918 center = transform_center(this_->trans);
919 pro = transform_get_projection(this_->trans);
920 coord_print(pro, center, f);
930 * Start the route computing to a given set of coordinates
932 * @param navit The navit instance
933 * @param c The coordinate to start routing to
934 * @param description A label which allows the user to later identify this destination in the former destinations selection
938 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
941 this_->destination=*c;
942 this_->destination_valid=1;
944 this_->destination_valid=0;
945 char *destination_file = navit_get_destination_file(TRUE);
946 navit_append_coord(this_, destination_file, c, "former_destination", description, NULL, this_->recentdest_count);
947 g_free(destination_file);
948 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
950 route_set_destination(this_->route, c, async);
952 if (this_->ready == 3)
958 * @brief Checks if a route is calculated
960 * This function checks if a route is calculated.
962 * @param this_ The navit struct whose route should be checked.
963 * @return True if the route is set, false otherwise.
966 navit_check_route(struct navit *this_)
969 return route_get_path_set(this_->route);
976 * Record the given set of coordinates as a bookmark
978 * @param navit The navit instance
979 * @param c The coordinate to store
980 * @param description A label which allows the user to later identify this bookmark
984 navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description)
986 char *bookmark_file = navit_get_bookmark_file(TRUE);
987 navit_append_coord(this_,bookmark_file, c, "bookmark", description, this_->bookmarks_hash,0);
988 g_free(bookmark_file);
990 callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map);
993 struct navit *global_navit;
996 navit_add_bookmarks_from_file(struct navit *this_)
998 char *bookmark_file = navit_get_bookmark_file(FALSE);
999 struct attr parent={attr_navit, .u.navit=this_};
1000 struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}};
1001 struct attr *attrs[]={&type, &data, NULL};
1003 this_->bookmark=map_new(&parent, attrs);
1004 g_free(bookmark_file);
1008 navit_former_destinations_active(struct navit *this_)
1010 char *destination_file = navit_get_destination_file(FALSE);
1014 f=fopen(destination_file,"r");
1016 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
1020 g_free(destination_file);
1025 navit_add_former_destinations_from_file(struct navit *this_)
1027 char *destination_file = navit_get_destination_file(FALSE);
1028 struct attr parent={attr_navit, .u.navit=this_};
1029 struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}};
1030 struct attr *attrs[]={&type, &data, NULL};
1031 struct map_rect *mr;
1037 this_->former_destination=map_new(&parent, attrs);
1038 g_free(destination_file);
1039 if (!this_->route || !navit_former_destinations_active(this_))
1041 mr=map_rect_new(this_->former_destination, NULL);
1042 while ((item=map_rect_get_item(mr))) {
1043 if (item->type == type_former_destination && item_coord_get(item, &c, 1))
1046 map_rect_destroy(mr);
1047 pc.pro=map_projection(this_->former_destination);
1051 route_set_destination(this_->route, &pc, 1);
1052 this_->destination=pc;
1053 this_->destination_valid=1;
1059 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1064 if (this_->textfile_debug_log && this_->vehicle) {
1065 str1=g_strdup_vprintf(fmt, ap);
1066 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1067 log_write(this_->textfile_debug_log, str2, strlen(str2));
1075 navit_speech_estimate(struct navit *this_, char *str)
1077 return speech_estimate_duration(this_->speech, str);
1081 navit_say(struct navit *this_, char *text)
1083 speech_say(this_->speech, text);
1087 * @brief Toggles the navigation announcer for navit
1088 * @param this_ The navit object
1091 navit_announcer_toggle(struct navit *this_)
1093 struct attr attr, speechattr;
1095 // search for the speech attribute
1096 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1098 // find out if the corresponding attribute attr_active has been set
1099 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1101 attr.u.num = !attr.u.num;
1103 // otherwise disable it because voice is enabled by default
1104 attr.type = attr_active;
1108 // apply the new state
1109 if(!speech_set_attr(speechattr.u.speech, &attr))
1112 // announce that the speech attribute has changed
1113 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1117 navit_speak(struct navit *this_)
1119 struct navigation *nav=this_->navigation;
1120 struct map *map=NULL;
1121 struct map_rect *mr=NULL;
1125 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1127 dbg(1, "this_.speech->active %i\n", attr.u.num);
1132 map=navigation_get_map(nav);
1134 mr=map_rect_new(map, NULL);
1136 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1137 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1138 speech_say(this_->speech, attr.u.str);
1139 navit_add_message(this_, attr.u.str);
1140 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1142 map_rect_destroy(mr);
1147 navit_window_roadbook_update(struct navit *this_)
1149 struct navigation *nav=this_->navigation;
1150 struct map *map=NULL;
1151 struct map_rect *mr=NULL;
1154 struct param_list param[5];
1158 datawindow_mode(this_->roadbook_window, 1);
1160 map=navigation_get_map(nav);
1162 mr=map_rect_new(map, NULL);
1163 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1165 dbg(0,"while loop\n");
1166 while ((item=map_rect_get_item(mr))) {
1167 dbg(0,"item=%p\n", item);
1169 if (item->type != type_nav_position) {
1170 item_attr_get(item, attr_navigation_long, &attr);
1171 dbg(2, "Command='%s'\n", attr.u.str);
1172 param[0].value=g_strdup(attr.u.str);
1174 param[0].value=_("Position");
1175 param[0].name=_("Command");
1177 item_attr_get(item, attr_length, &attr);
1178 dbg(2, "Length=%d\n", attr.u.num);
1179 param[1].name=_("Length");
1181 if ( attr.u.num >= 2000 )
1183 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1187 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1190 item_attr_get(item, attr_time, &attr);
1191 dbg(2, "Time=%d\n", attr.u.num);
1193 param[2].name=_("Time");
1196 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1200 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1203 item_attr_get(item, attr_destination_length, &attr);
1204 dbg(2, "Destlength=%d\n", attr.u.num);
1205 param[3].name=_("Destination Length");
1206 if ( attr.u.num >= 2000 )
1208 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1212 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1215 item_attr_get(item, attr_destination_time, &attr);
1216 dbg(2, "Desttime=%d\n", attr.u.num);
1218 param[4].name=_("Destination Time");
1221 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1225 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1227 datawindow_add(this_->roadbook_window, param, 5);
1229 map_rect_destroy(mr);
1231 datawindow_mode(this_->roadbook_window, 0);
1235 navit_window_roadbook_destroy(struct navit *this_)
1238 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1239 this_->roadbook_window=NULL;
1240 this_->roadbook_callback=NULL;
1243 navit_window_roadbook_new(struct navit *this_)
1245 if (!gui || this_->roadbook_callback || this_->roadbook_window) {
1249 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1250 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1251 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1252 navit_window_roadbook_update(this_);
1256 navit_init(struct navit *this_)
1261 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1264 navit_destroy(this_);
1268 dbg(0,"no graphics\n");
1269 navit_destroy(this_);
1272 dbg(2,"Connecting gui to graphics\n");
1273 if (gui_set_graphics(this_->gui, this_->gra)) {
1274 struct attr attr_type_gui, attr_type_graphics;
1275 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1276 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1277 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1278 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1279 dbg(0," for explanations and solutions\n");
1281 navit_destroy(this_);
1284 dbg(2,"Initializing graphics\n");
1285 graphics_init(this_->gra);
1286 dbg(2,"Setting Vehicle\n");
1287 navit_set_vehicle(this_, this_->vehicle);
1288 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1289 if (this_->mapsets) {
1290 ms=this_->mapsets->data;
1292 if ((map=route_get_map(this_->route)))
1293 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1294 if ((map=route_get_graph_map(this_->route))) {
1295 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1296 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1298 route_set_mapset(this_->route, ms);
1299 route_set_projection(this_->route, transform_get_projection(this_->trans));
1301 if (this_->tracking) {
1302 tracking_set_mapset(this_->tracking, ms);
1304 tracking_set_route(this_->tracking, this_->route);
1306 if (this_->navigation) {
1307 if ((map=navigation_get_map(this_->navigation))) {
1308 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1309 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1312 if (this_->tracking) {
1313 if ((map=tracking_get_map(this_->tracking))) {
1314 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1315 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1318 navit_add_bookmarks_from_file(this_);
1319 navit_add_former_destinations_from_file(this_);
1322 struct attr callback;
1323 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1324 callback.type=attr_callback;
1325 callback.u.callback=this_->route_cb;
1326 route_add_attr(this_->route, &callback);
1328 if (this_->navigation) {
1329 if (this_->speech) {
1330 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1331 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1334 navigation_set_route(this_->navigation, this_->route);
1336 dbg(2,"Setting Center\n");
1337 char *center_file = navit_get_center_file(FALSE);
1338 navit_set_center_from_file(this_, center_file);
1339 g_free(center_file);
1341 if (this_->menubar) {
1342 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1344 navit_add_menu_windows_items(this_, men);
1350 navit_window_roadbook_new(this_);
1351 navit_window_items_new(this_);
1353 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1356 messagelist_init(this_->messages);
1358 dbg(2,"ready=%d\n",this_->ready);
1359 if (this_->ready == 3)
1364 navit_zoom_to_route(struct navit *this_, int orientation)
1367 struct map_rect *mr=NULL;
1370 struct coord_rect r;
1371 int count=0,scale=16;
1375 map=route_get_map(this_->route);
1376 dbg(1,"map=%p\n",map);
1378 mr=map_rect_new(map, NULL);
1379 dbg(1,"mr=%p\n",mr);
1381 while ((item=map_rect_get_item(mr))) {
1382 dbg(1,"item=%s\n", item_to_name(item->type));
1383 while (item_coord_get(item, &c, 1)) {
1388 coord_rect_extend(&r, &c);
1395 c.x=(r.rl.x+r.lu.x)/2;
1396 c.y=(r.rl.y+r.lu.y)/2;
1397 dbg(1,"count=%d\n",count);
1398 if (orientation != -1)
1399 transform_set_yaw(this_->trans, orientation);
1400 transform_set_center(this_->trans, &c);
1401 dbg(1,"%x,%x-%x,%x\n", r.rl.x,r.rl.y,r.lu.x,r.lu.y);
1402 while (scale < 1<<20) {
1404 transform_set_scale(this_->trans, scale);
1405 transform_setup_source_rect(this_->trans);
1406 transform(this_->trans, transform_get_projection(this_->trans), &r.lu, &p1, 1, 0, 0, NULL);
1407 transform(this_->trans, transform_get_projection(this_->trans), &r.rl, &p2, 1, 0, 0, NULL);
1408 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1409 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1410 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1416 if (this_->ready == 3)
1417 navit_draw_async(this_,0);
1421 navit_cmd_zoom_to_route(struct navit *this)
1423 navit_zoom_to_route(this, 0);
1427 * Change the current zoom level
1429 * @param navit The navit instance
1430 * @param center The point where to center the map, including its projection
1434 navit_set_center(struct navit *this_, struct pcoord *center)
1436 struct coord *c=transform_center(this_->trans);
1438 enum projection pro = transform_get_projection(this_->trans);
1439 if (pro != center->pro) {
1442 transform_from_to(&c1, center->pro, &c2, pro);
1448 if (this_->ready == 3)
1453 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p)
1457 transform_set_center(this_->trans, c);
1458 transform_get_size(this_->trans, &width, &height);
1461 update_transformation(this_->trans, &po, p, NULL);
1465 navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir)
1468 struct navit_vehicle *nv=this_->vehicle;
1469 transform_get_size(this_->trans, &width, &height);
1470 if (this_->orientation == -1) {
1477 if (this_->tracking && this_->tracking_flag) {
1478 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
1480 mdir=nv->dir-this_->orientation;
1483 p->x=(50 - 30.*sin(M_PI*mdir/180.))*width/100;
1484 p->y=(50 + 30.*cos(M_PI*mdir/180.))*height/100;
1486 *dir=this_->orientation;
1492 navit_set_center_cursor(struct navit *this_)
1496 struct navit_vehicle *nv=this_->vehicle;
1497 navit_get_cursor_pnt(this_, &pn, &dir);
1498 transform_set_yaw(this_->trans, dir);
1499 navit_set_center_coord_screen(this_, &nv->coord, &pn);
1500 navit_autozoom(this_, &nv->coord, nv->speed, 0);
1501 if (this_->ready == 3)
1502 navit_draw_async(this_, 1);
1506 navit_cmd_set_center_cursor(struct navit *this_)
1508 navit_set_center_cursor(this_);
1512 navit_set_center_screen(struct navit *this_, struct point *p)
1516 transform_reverse(this_->trans, p, &c);
1519 pc.pro = transform_get_projection(this_->trans);
1520 navit_set_center(this_, &pc);
1524 switch((*attrs)->type) {
1526 zoom=(*attrs)->u.num;
1529 g=*((*attrs)->u.coord_geo);
1534 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
1536 int dir=0, orient_old=0, attr_updated=0;
1540 switch (attr->type) {
1542 attr_updated=(this_->autozoom_secs != attr->u.num);
1543 this_->autozoom_secs = attr->u.num;
1545 case attr_autozoom_active:
1546 attr_updated=(this_->autozoom_active != attr->u.num);
1547 this_->autozoom_active = attr->u.num;
1550 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
1551 dbg(1,"0x%x,0x%x\n",co.x,co.y);
1552 transform_set_center(this_->trans, &co);
1554 case attr_drag_bitmap:
1555 attr_updated=(this_->drag_bitmap != !!attr->u.num);
1556 this_->drag_bitmap=!!attr->u.num;
1559 if (!this_->vehicle)
1561 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
1562 this_->vehicle->follow_curr = attr->u.num;
1565 if(this_->layout_current!=attr->u.layout) {
1566 this_->layout_current=attr->u.layout;
1567 graphics_font_destroy_all(this_->gra);
1572 case attr_orientation:
1573 orient_old=this_->orientation;
1574 this_->orientation=attr->u.num;
1576 if (this_->orientation != -1) {
1577 dir = this_->orientation;
1579 if (this_->vehicle) {
1580 dir = this_->vehicle->dir;
1583 transform_set_yaw(this_->trans, dir);
1584 if (orient_old != this_->orientation) {
1585 if (this_->ready == 3)
1591 case attr_osd_configuration:
1592 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
1593 attr_updated=(this_->osd_configuration != attr->u.num);
1594 this_->osd_configuration=attr->u.num;
1597 attr_updated=(this_->pitch != attr->u.num);
1598 this_->pitch=attr->u.num;
1599 transform_set_pitch(this_->trans, this_->pitch);
1600 if (!init && attr_updated && this_->ready == 3)
1603 case attr_projection:
1604 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
1605 navit_projection_set(this_, attr->u.projection);
1609 case attr_recent_dest:
1610 attr_updated=(this_->recentdest_count != attr->u.num);
1611 this_->recentdest_count=attr->u.num;
1614 if(this_->speech && this_->speech != attr->u.speech) {
1616 this_->speech = attr->u.speech;
1620 attr_updated=(this_->center_timeout != attr->u.num);
1621 this_->center_timeout = attr->u.num;
1624 attr_updated=(this_->tracking_flag != !!attr->u.num);
1625 this_->tracking_flag=!!attr->u.num;
1627 case attr_use_mousewheel:
1628 attr_updated=(this_->use_mousewheel != !!attr->u.num);
1629 this_->use_mousewheel=!!attr->u.num;
1632 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
1634 struct navit_vehicle *nv;
1635 struct attr active=(struct attr){attr_active,{(void *)0}};
1639 if (nv->vehicle == attr->u.vehicle) {
1641 vehicle_set_attr(this_->vehicle->vehicle, &active, NULL);
1643 vehicle_set_attr(nv->vehicle, &active, NULL);
1644 navit_set_vehicle(this_, nv);
1652 zoom=transform_get_scale(this_->trans);
1653 attr_updated=(zoom != attr->u.num);
1654 transform_set_scale(this_->trans, attr->u.num);
1655 if (attr_updated && !init)
1659 navit_add_message(this_, attr->u.str);
1664 if (attr_updated && !init) {
1665 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1666 if (attr->type == attr_osd_configuration)
1667 graphics_draw_mode(this_->gra, draw_mode_end);
1673 navit_set_attr(struct navit *this_, struct attr *attr)
1675 return navit_set_attr_do(this_, attr, 0);
1679 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
1681 struct message *msg;
1687 msg = navit_get_messages(this_);
1695 len += strlen(msg->text) + 1;
1698 attr->u.str = g_malloc(len + 1);
1700 msg = navit_get_messages(this_);
1703 g_stpcpy((attr->u.str + offset), msg->text);
1704 offset += strlen(msg->text);
1705 attr->u.str[offset] = '\n';
1711 attr->u.str[len] = '\0';
1713 case attr_bookmark_map:
1714 attr->u.map=this_->bookmark;
1716 case attr_callback_list:
1717 attr->u.callback_list=this_->attr_cbl;
1719 case attr_destination:
1720 if (! this_->destination_valid)
1722 attr->u.pcoord=&this_->destination;
1724 case attr_displaylist:
1725 attr->u.displaylist=this_->displaylist;
1726 return (attr->u.displaylist != NULL);
1727 case attr_former_destination_map:
1728 attr->u.map=this_->former_destination;
1731 attr->u.graphics=this_->gra;
1732 ret=(attr->u.graphics != NULL);
1735 attr->u.gui=this_->gui;
1736 ret=(attr->u.gui != NULL);
1741 iter->u.list=g_list_next(iter->u.list);
1743 iter->u.list=this_->layouts;
1747 attr->u.layout=(struct layout *)iter->u.list->data;
1749 attr->u.layout=this_->layout_current;
1753 if (iter && this_->mapsets) {
1754 if (!iter->u.mapset_handle) {
1755 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
1757 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
1759 mapset_close(iter->u.mapset_handle);
1767 attr->u.mapset=this_->mapsets->data;
1768 return (attr->u.mapset != NULL);
1769 case attr_navigation:
1770 attr->u.navigation=this_->navigation;
1772 case attr_orientation:
1773 attr->u.num=this_->orientation;
1775 case attr_osd_configuration:
1776 attr->u.num=this_->osd_configuration;
1778 case attr_projection:
1780 attr->u.num=transform_get_projection(this_->trans);
1786 attr->u.route=this_->route;
1789 attr->u.speech=this_->speech;
1792 attr->u.num=this_->tracking_flag;
1794 case attr_transformation:
1795 attr->u.transformation=this_->trans;
1800 iter->u.list=g_list_next(iter->u.list);
1802 iter->u.list=this_->vehicles;
1806 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
1808 if(this_->vehicle) {
1809 attr->u.vehicle=this_->vehicle->vehicle;
1816 attr->u.num=transform_get_scale(this_->trans);
1818 case attr_autozoom_active:
1819 attr->u.num=this_->autozoom_active;
1829 navit_add_log(struct navit *this_, struct log *log)
1831 struct attr type_attr;
1832 if (!log_get_attr(log, attr_type, &type_attr, NULL))
1834 if (!strcmp(type_attr.u.str, "textfile_debug")) {
1835 char *header = "type=track_tracked\n";
1836 if (this_->textfile_debug_log)
1838 log_set_header(log, header, strlen(header));
1839 this_->textfile_debug_log=log;
1846 navit_add_attr(struct navit *this_, struct attr *attr)
1849 switch (attr->type) {
1851 navit_add_callback(this_, attr->u.callback);
1854 ret=navit_add_log(this_, attr->u.log);
1857 ret=navit_set_gui(this_, attr->u.gui);
1860 ret=navit_set_graphics(this_, attr->u.graphics);
1863 this_->layouts = g_list_append(this_->layouts, attr->u.layout);
1864 if(!this_->layout_current)
1865 this_->layout_current=attr->u.layout;
1868 this_->route=attr->u.route;
1871 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
1873 case attr_navigation:
1874 this_->navigation=attr->u.navigation;
1876 case attr_recent_dest:
1877 this_->recentdest_count = attr->u.num;
1880 this_->speech=attr->u.speech;
1883 this_->tracking=attr->u.tracking;
1886 ret=navit_add_vehicle(this_, attr->u.vehicle);
1888 case attr_vehicleprofile:
1889 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
1891 case attr_autozoom_min:
1892 this_->autozoom_min = attr->u.num;
1897 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1902 navit_remove_attr(struct navit *this_, struct attr *attr)
1905 switch (attr->type) {
1907 navit_remove_callback(this_, attr->u.callback);
1916 navit_attr_iter_new()
1918 return g_new0(struct attr_iter, 1);
1922 navit_attr_iter_destroy(struct attr_iter *iter)
1928 navit_add_callback(struct navit *this_, struct callback *cb)
1930 callback_list_add(this_->attr_cbl, cb);
1934 navit_remove_callback(struct navit *this_, struct callback *cb)
1936 callback_list_remove(this_->attr_cbl, cb);
1940 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
1942 * @param navit The navit instance
1947 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
1949 struct point cursor_pnt;
1950 enum projection pro;
1955 if (! vehicle_get_attr(nv->vehicle, attr_cursor, &cursor, NULL))
1957 if (! cursor.u.cursor)
1962 pro=transform_get_projection(this_->trans);
1963 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
1965 cursor_draw(cursor.u.cursor, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed);
1970 pro=transform_get_projection(this_->trans);
1971 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
1974 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
1976 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
1982 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
1984 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
1985 struct pcoord cursor_pc;
1986 struct point cursor_pnt, *pnt=&cursor_pnt;
1987 struct tracking *tracking=NULL;
1988 enum projection pro=transform_get_projection(this_->trans);
1990 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
1994 if (this_->ready != 3) {
1995 profile(0,"return 1\n");
1998 if (this_->vehicle == nv && this_->tracking_flag)
1999 tracking=this_->tracking;
2001 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2002 attr_object=tracking;
2003 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2005 attr_object=nv->vehicle;
2006 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2008 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2009 if (!attr_valid.u.num != attr_position_valid_invalid)
2011 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2012 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2013 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2014 profile(0,"return 2\n");
2017 nv->dir=*attr_dir.u.numd;
2018 nv->speed=*attr_speed.u.numd;
2019 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2020 if (nv != this_->vehicle) {
2021 navit_vehicle_draw(this_, nv, NULL);
2022 profile(0,"return 3\n");
2025 cursor_pc.x = nv->coord.x;
2026 cursor_pc.y = nv->coord.y;
2027 cursor_pc.pro = pro;
2030 route_set_position_from_tracking(this_->route, tracking, pro);
2032 route_set_position(this_->route, &cursor_pc);
2034 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2035 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2036 if (this_->gui && nv->speed > 2)
2037 gui_disable_suspend(this_->gui);
2039 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2040 if (this_->button_pressed != 1 && nv->follow_curr <= nv->follow &&
2041 (nv->follow_curr == 1 || !transform_within_border(this_->trans, &cursor_pnt, border)))
2042 navit_set_center_cursor(this_);
2044 navit_vehicle_draw(this_, nv, pnt);
2046 if (nv->follow_curr > 1)
2049 nv->follow_curr=nv->follow;
2050 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2052 /* Finally, if we reached our destination, stop navigation. */
2053 if (this_->route && route_destination_reached(this_->route)) {
2054 navit_set_destination(this_, NULL, NULL, 0);
2056 profile(0,"return 5\n");
2060 * Set the position of the vehicle
2062 * @param navit The navit instance
2063 * @param c The coordinate to set as position
2068 navit_set_position(struct navit *this_, struct pcoord *c)
2071 route_set_position(this_->route, c);
2072 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2074 if (this_->ready == 3)
2079 navit_set_vehicleprofile(struct navit *this_, char *name)
2083 l=this_->vehicleprofiles;
2085 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2086 if (!strcmp(attr.u.str, name)) {
2087 this_->vehicleprofile=l->data;
2089 route_set_profile(this_->route, this_->vehicleprofile);
2099 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2103 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2104 if (navit_set_vehicleprofile(this_, attr.u.str))
2107 navit_set_vehicleprofile(this_,"car");
2111 * Register a new vehicle
2113 * @param navit The navit instance
2114 * @param v The vehicle instance
2115 * @returns 1 for success
2118 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2120 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2121 struct attr follow,color,active, color2, animate;
2126 nv->animate_cursor=0;
2127 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2128 nv->follow=nv->follow=follow.u.num;
2129 if ((vehicle_get_attr(v, attr_color, &color, NULL)))
2130 nv->c=*(color.u.color);
2131 if ((vehicle_get_attr(v, attr_color2, &color2, NULL)))
2132 nv->c2=color2.u.color;
2135 nv->follow_curr=nv->follow;
2136 this_->vehicles=g_list_append(this_->vehicles, nv);
2137 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2138 navit_set_vehicle(this_, nv);
2139 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2140 nv->animate_cursor=animate.u.num;
2141 nv->callback.type=attr_callback;
2142 nv->callback.u.callback=callback_new_2(callback_cast(navit_vehicle_update), this_, nv);
2143 vehicle_add_attr(nv->vehicle, &nv->callback);
2144 vehicle_set_attr(nv->vehicle, &this_->self, NULL);
2152 navit_get_gui(struct navit *this_)
2157 struct transformation *
2158 navit_get_trans(struct navit *this_)
2160 return this_->trans;
2164 navit_get_route(struct navit *this_)
2166 return this_->route;
2170 navit_get_navigation(struct navit *this_)
2172 return this_->navigation;
2175 struct displaylist *
2176 navit_get_displaylist(struct navit *this_)
2178 return this_->displaylist;
2182 navit_block(struct navit *this_, int block)
2185 this_->blocked |= 1;
2186 if (graphics_draw_cancel(this_->gra, this_->displaylist))
2187 this_->blocked |= 2;
2190 if (this_->blocked & 2) {
2200 navit_destroy(struct navit *this_)
2202 /* TODO: destroy objects contained in this_ */
2204 vehicle_destroy(this_->vehicle->vehicle);
2205 main_remove_navit(this_);
2206 char *center_file = navit_get_center_file(TRUE);
2207 navit_write_center_to_file(this_, center_file);
2208 g_free(center_file);
2209 callback_destroy(this_->nav_speech_cb);
2210 callback_destroy(this_->roadbook_callback);
2211 callback_destroy(this_->popup_callback);
2212 callback_destroy(this_->motion_timeout_callback);
2214 graphics_remove_callback(this_->gra, this_->resize_callback);
2215 callback_destroy(this_->resize_callback);
2217 graphics_remove_callback(this_->gra, this_->button_callback);
2218 callback_destroy(this_->button_callback);
2220 graphics_remove_callback(this_->gra, this_->motion_callback);
2221 callback_destroy(this_->motion_callback);