2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2009 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"
46 #include "data_window.h"
48 #include "navigation.h"
59 #include "navit_nls.h"
62 #include "vehicleprofile.h"
64 #include "bookmarks.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 */
81 struct vehicle *vehicle;
91 struct layout *layout_current;
93 struct action *action;
94 struct transformation *trans, *trans_cursor;
95 struct compass *compass;
97 struct navigation *navigation;
98 struct speech *speech;
99 struct tracking *tracking;
102 struct displaylist *displaylist;
105 int recentdest_count;
106 int osd_configuration;
108 GList *windows_items;
109 struct navit_vehicle *vehicle;
110 struct callback_list *attr_cbl;
111 struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb;
112 struct datawindow *roadbook_window;
113 struct map *former_destination;
114 struct point pressed, last, current;
115 int button_pressed,moved,popped,zoomed;
120 struct event_timeout *button_timeout, *motion_timeout;
121 struct callback *motion_timeout_callback;
123 int ignore_graphics_events;
124 struct log *textfile_debug_log;
125 struct pcoord destination;
126 int destination_valid;
131 struct messagelist *messages;
132 struct callback *resize_callback,*button_callback,*motion_callback,*postdraw_callback;
133 struct vehicleprofile *vehicleprofile;
134 GList *vehicleprofiles;
139 int zoom_min, zoom_max;
141 struct bookmarks *bookmarks;
143 /* 1=No graphics ok */
148 struct gui *main_loop_gui;
153 struct mapset_handle *mapset_handle;
157 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
158 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
159 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
160 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
161 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
162 static void navit_set_cursors(struct navit *this_);
163 static void navit_cmd_zoom_to_route(struct navit *this);
164 static void navit_cmd_set_center_cursor(struct navit *this_);
165 static void navit_cmd_announcer_toggle(struct navit *this_);
166 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
168 struct navit *global_navit;
171 navit_add_mapset(struct navit *this_, struct mapset *ms)
173 this_->mapsets = g_list_append(this_->mapsets, ms);
177 navit_get_mapset(struct navit *this_)
180 return this_->mapsets->data;
182 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
188 navit_get_tracking(struct navit *this_)
190 return this_->tracking;
194 * @brief Get the user data directory.
195 * @param[in] create - create the directory if it does not exist
197 * @return char * to the data directory string.
199 * returns the directory used to store user data files (center.txt,
200 * destination.txt, bookmark.txt, ...)
204 navit_get_user_data_directory(int create) {
206 dir = getenv("NAVIT_USER_DATADIR");
207 if (create && !file_exists(dir)) {
208 dbg(0,"creating dir %s\n", dir);
209 if (file_mkdir(dir,0)) {
210 dbg(0,"failed creating dir %s\n", dir);
215 } /* end: navit_get_user_data_directory(gboolean create) */
219 navit_draw_async(struct navit *this_, int async)
222 if (this_->blocked) {
226 transform_setup_source_rect(this_->trans);
227 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
231 navit_draw(struct navit *this_)
233 if (this_->ready == 3)
234 navit_draw_async(this_, 0);
238 navit_get_ready(struct navit *this_)
246 navit_draw_displaylist(struct navit *this_)
248 if (this_->ready == 3)
249 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
253 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
256 if (attr->type != attr_route_status)
259 if (this_->ready != 3)
261 if (updated != route_status_path_done_new)
263 if (this_->vehicle) {
264 if (this_->vehicle->follow_curr == 1)
266 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
267 this_->vehicle->follow_curr=this_->vehicle->follow;
273 navit_handle_resize(struct navit *this_, int w, int h)
275 struct map_selection sel;
276 int callback=(this_->ready == 1);
278 memset(&sel, 0, sizeof(sel));
283 transform_set_screen_selection(this_->trans, &sel);
284 graphics_init(this_->gra);
285 graphics_set_rect(this_->gra, &sel.u.p_rect);
287 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
288 if (this_->ready == 3)
293 navit_resize(void *data, int w, int h)
295 struct navit *this=data;
296 if (!this->ignore_graphics_events)
297 navit_handle_resize(this, w, h);
301 navit_get_width(struct navit *this_)
308 navit_get_height(struct navit *this_)
314 navit_popup(void *data)
316 struct navit *this_=data;
317 popup(this_, 1, &this_->pressed);
318 this_->button_timeout=NULL;
324 navit_ignore_button(struct navit *this_)
326 if (this_->ignore_button)
328 this_->ignore_button=1;
333 navit_ignore_graphics_events(struct navit *this_, int ignore)
335 this_->ignore_graphics_events=ignore;
339 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
344 double angleo,anglen;
346 if (!transform_reverse(tr, old, &co))
349 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
350 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
351 yaw=transform_get_yaw(tr)+angleo-anglen;
352 transform_set_yaw(tr, yaw % 360);
354 if (!transform_reverse(tr, new, &cn))
356 cp=transform_get_center(tr);
359 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
360 transform_set_center(tr, &c);
364 navit_set_timeout(struct navit *this_)
367 follow.type=attr_follow;
368 follow.u.num=this_->center_timeout;
369 navit_set_attr(this_, &follow);
373 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
377 dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
378 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
379 if (this_->ignore_button) {
380 this_->ignore_button=0;
388 this_->button_pressed=1;
392 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
395 navit_set_center_screen(this_, p, 1);
397 popup(this_, button, p);
398 if (button == 4 && this_->use_mousewheel) {
400 navit_zoom_in(this_, 2, p);
402 if (button == 5 && this_->use_mousewheel) {
404 navit_zoom_out(this_, 2, p);
408 this_->button_pressed=0;
409 if (this_->button_timeout) {
410 event_remove_timeout(this_->button_timeout);
411 this_->button_timeout=NULL;
412 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
413 navit_set_center_screen(this_, p, !this_->zoomed);
416 if (this_->motion_timeout) {
417 event_remove_timeout(this_->motion_timeout);
418 this_->motion_timeout=NULL;
425 update_transformation(this_->trans, &this_->pressed, p, &pr);
427 update_transformation(this_->trans, &this_->pressed, p, NULL);
429 graphics_draw_drag(this_->gra, NULL);
430 transform_copy(this_->trans, this_->trans_cursor);
431 graphics_overlay_disable(this_->gra, 0);
433 navit_set_timeout(this_);
442 navit_button(void *data, int pressed, int button, struct point *p)
444 struct navit *this=data;
445 dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
446 if (!this->ignore_graphics_events) {
447 if (! this->popup_callback)
448 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
449 navit_handle_button(this, pressed, button, p, this->popup_callback);
455 navit_motion_timeout(struct navit *this_)
459 if (this_->drag_bitmap) {
461 point.x=(this_->current.x-this_->pressed.x);
462 point.y=(this_->current.y-this_->pressed.y);
463 if (graphics_draw_drag(this_->gra, &point)) {
464 graphics_overlay_disable(this_->gra, 1);
465 graphics_draw_mode(this_->gra, draw_mode_end);
467 this_->motion_timeout=NULL;
471 dx=(this_->current.x-this_->last.x);
472 dy=(this_->current.y-this_->last.y);
474 struct transformation *tr;
476 this_->last=this_->current;
477 graphics_overlay_disable(this_->gra, 1);
478 tr=transform_dup(this_->trans);
482 update_transformation(tr, &this_->pressed, &this_->current, &pr);
484 update_transformation(tr, &this_->pressed, &this_->current, NULL);
487 graphics_displaylist_move(this_->displaylist, dx, dy);
489 graphics_draw_cancel(this_->gra, this_->displaylist);
490 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
491 transform_destroy(tr);
494 this_->motion_timeout=NULL;
499 navit_handle_motion(struct navit *this_, struct point *p)
503 if (this_->button_pressed && !this_->popped) {
504 dx=(p->x-this_->pressed.x);
505 dy=(p->y-this_->pressed.y);
506 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
508 if (this_->button_timeout) {
509 event_remove_timeout(this_->button_timeout);
510 this_->button_timeout=NULL;
513 if (! this_->motion_timeout_callback)
514 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
515 if (! this_->motion_timeout)
516 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
522 navit_motion(void *data, struct point *p)
524 struct navit *this=data;
525 if (!this->ignore_graphics_events)
526 navit_handle_motion(this, p);
530 navit_postdraw(struct navit *this_)
533 struct navit_vehicle *nv;
534 transform_copy(this_->trans, this_->trans_cursor);
538 navit_vehicle_draw(this_, nv, NULL);
544 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
546 struct coord c1, c2, *center;
547 if (scale < this_->zoom_min)
548 scale=this_->zoom_min;
549 if (scale > this_->zoom_max)
550 scale=this_->zoom_max;
552 transform_reverse(this_->trans, p, &c1);
553 transform_set_scale(this_->trans, scale);
555 transform_reverse(this_->trans, p, &c2);
556 center = transform_center(this_->trans);
557 center->x += c1.x - c2.x;
558 center->y += c1.y - c2.y;
565 * @brief Automatically adjusts zoom level
567 * This function automatically adjusts the current
568 * zoom level according to the current speed.
570 * @param this_ The navit struct
571 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
572 * @param speed The vehicles speed in meters per second
573 * @param dir The direction into which the vehicle moves
576 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
583 if (! this_->autozoom_active) {
587 distance = speed * this_->autozoom_secs;
589 transform_get_size(this_->trans, &w, &h);
590 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
591 scale = transform_get_scale(this_->trans);
593 /* We make sure that the point we want to see is within a certain range
594 * around the vehicle. The radius of this circle is the size of the
595 * screen. This doesn't necessarily mean the point is visible because of
596 * perspective etc. Quite rough, but should be enough. */
599 new_scale = (double)distance / h * 16;
601 new_scale = (double)distance / w * 16;
604 if (abs(new_scale - scale) < 2) {
608 if (new_scale >= this_->autozoom_min) {
609 navit_scale(this_, (long)new_scale, &pc, 0);
611 if (scale != this_->autozoom_min) {
612 navit_scale(this_, this_->autozoom_min, &pc, 0);
618 * Change the current zoom level, zooming closer to the ground
620 * @param navit The navit instance
621 * @param factor The zoom factor, usually 2
622 * @param p The invariant point (if set to NULL, default to center)
626 navit_zoom_in(struct navit *this_, int factor, struct point *p)
628 long scale=transform_get_scale(this_->trans)/factor;
631 navit_scale(this_, scale, p, 1);
635 * Change the current zoom level
637 * @param navit The navit instance
638 * @param factor The zoom factor, usually 2
639 * @param p The invariant point (if set to NULL, default to center)
643 navit_zoom_out(struct navit *this_, int factor, struct point *p)
645 long scale=transform_get_scale(this_->trans)*factor;
646 navit_scale(this_, scale, p, 1);
650 navit_cmd_zoom_in(struct navit *this_)
653 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
654 navit_zoom_in(this_, 2, &p);
655 this_->vehicle->follow_curr=this_->vehicle->follow;
657 navit_zoom_in(this_, 2, NULL);
662 navit_cmd_zoom_out(struct navit *this_)
665 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
666 navit_zoom_out(this_, 2, &p);
667 this_->vehicle->follow_curr=this_->vehicle->follow;
669 navit_zoom_out(this_, 2, NULL);
675 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
677 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
678 navit_say(this, in[0]->u.str);
682 navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
685 char *description=NULL;
690 pc.pro = transform_get_projection(this->trans);
691 if (ATTR_IS_COORD(in[0]->type)) {
692 pc.x=in[0]->u.coord->x;
693 pc.y=in[0]->u.coord->y;
695 } else if (ATTR_IS_PCOORD(in[0]->type)) {
698 } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
703 } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
709 if (in[0] && ATTR_IS_STRING(in[0]->type))
710 description=in[0]->u.str;
711 navit_set_destination(this, &pc, description, 1);
715 navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
718 attr.type=attr_type_string_begin;
721 *out=attr_generic_add_attr(*out, &attr);
725 static struct command_table commands[] = {
726 {"zoom_in",command_cast(navit_cmd_zoom_in)},
727 {"zoom_out",command_cast(navit_cmd_zoom_out)},
728 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
729 {"say",command_cast(navit_cmd_say)},
730 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
731 {"set_destination",command_cast(navit_cmd_set_destination)},
732 {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
733 {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
738 navit_new(struct attr *parent, struct attr **attrs)
740 struct navit *this_=g_new0(struct navit, 1);
741 struct pcoord center;
744 enum projection pro=projection_mg;
749 this_->self.type=attr_navit;
750 this_->self.u.navit=this_;
751 this_->attr_cbl=callback_list_new();
753 this_->orientation=-1;
754 this_->tracking_flag=1;
755 this_->recentdest_count=10;
756 this_->osd_configuration=-1;
758 this_->center_timeout = 10;
759 this_->use_mousewheel = 1;
760 this_->autozoom_secs = 10;
761 this_->autozoom_min = 7;
762 this_->autozoom_active = 0;
764 this_->zoom_max = 2097152;
765 this_->follow_cursor = 1;
769 this_->trans = transform_new();
770 this_->trans_cursor = transform_new();
771 transform_from_geo(pro, &g, &co);
776 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
778 this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
782 for (;*attrs; attrs++) {
783 navit_set_attr_do(this_, *attrs, 1);
785 this_->displaylist=graphics_displaylist_new();
786 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
788 this_->messages = messagelist_new(attrs);
794 navit_set_gui(struct navit *this_, struct gui *gui)
799 if (gui_has_main_loop(this_->gui)) {
800 if (! main_loop_gui) {
801 main_loop_gui=this_->gui;
803 dbg(0,"gui with main loop already active, ignoring this instance");
811 navit_add_message(struct navit *this_, char *message)
813 message_new(this_->messages, message);
817 *navit_get_messages(struct navit *this_)
819 return message_get(this_->messages);
823 navit_set_graphics(struct navit *this_, struct graphics *gra)
828 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
829 graphics_add_callback(gra, this_->resize_callback);
830 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
831 graphics_add_callback(gra, this_->button_callback);
832 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
833 graphics_add_callback(gra, this_->motion_callback);
834 this_->postdraw_callback=callback_new_attr_1(callback_cast(navit_postdraw), attr_postdraw, this_);
835 graphics_add_callback(gra, this_->postdraw_callback);
840 navit_get_graphics(struct navit *this_)
845 struct vehicleprofile *
846 navit_get_vehicleprofile(struct navit *this_)
848 return this_->vehicleprofile;
852 navit_get_vehicleprofiles(struct navit *this_)
854 return this_->vehicleprofiles;
858 navit_projection_set(struct navit *this_, enum projection pro, int draw)
863 c=transform_center(this_->trans);
864 transform_to_geo(transform_get_projection(this_->trans), c, &g);
865 transform_set_projection(this_->trans, pro);
866 transform_from_geo(pro, &g, c);
872 * Start the route computing to a given set of coordinates
874 * @param navit The navit instance
875 * @param c The coordinate to start routing to
876 * @param description A label which allows the user to later identify this destination in the former destinations selection
880 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
883 this_->destination=*c;
884 this_->destination_valid=1;
886 this_->destination_valid=0;
887 char *destination_file = bookmarks_get_destination_file(TRUE);
888 bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
889 g_free(destination_file);
890 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
892 route_set_destination(this_->route, c, async);
894 if (this_->ready == 3)
900 * Start the route computing to a given set of coordinates including waypoints
902 * @param navit The navit instance
903 * @param c The coordinate to start routing to
904 * @param description A label which allows the user to later identify this destination in the former destinations selection
908 navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
911 this_->destination=c[count-1];
912 this_->destination_valid=1;
914 this_->destination_valid=0;
915 char *destination_file = bookmarks_get_destination_file(TRUE);
916 bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
917 g_free(destination_file);
918 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
920 route_set_destinations(this_->route, c, count, async);
922 if (this_->ready == 3)
928 * @brief Checks if a route is calculated
930 * This function checks if a route is calculated.
932 * @param this_ The navit struct whose route should be checked.
933 * @return True if the route is set, false otherwise.
936 navit_check_route(struct navit *this_)
939 return route_get_path_set(this_->route);
946 navit_former_destinations_active(struct navit *this_)
948 char *destination_file = bookmarks_get_destination_file(FALSE);
952 f=fopen(destination_file,"r");
954 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
958 g_free(destination_file);
963 navit_add_former_destinations_from_file(struct navit *this_)
965 char *destination_file = bookmarks_get_destination_file(FALSE);
966 struct attr parent={attr_navit, .u.navit=this_};
967 struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}}, flags={attr_flags, {(void *)1}};
968 struct attr *attrs[]={&type, &data, &flags, NULL};
971 int i,valid=0,count=0;
973 struct pcoord pc[16];
975 this_->former_destination=map_new(&parent, attrs);
976 g_free(destination_file);
977 if (!this_->route || !navit_former_destinations_active(this_))
979 mr=map_rect_new(this_->former_destination, NULL);
980 while ((item=map_rect_get_item(mr))) {
981 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16)))
984 map_rect_destroy(mr);
985 if (valid && count > 0) {
986 for (i = 0 ; i < count ; i++) {
987 pc[i].pro=map_projection(this_->former_destination);
992 route_set_destination(this_->route, &pc[0], 1);
994 route_set_destinations(this_->route, pc, count, 1);
995 this_->destination=pc[count-1];
996 this_->destination_valid=1;
1002 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1007 if (this_->textfile_debug_log && this_->vehicle) {
1008 str1=g_strdup_vprintf(fmt, ap);
1009 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1010 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1018 navit_speech_estimate(struct navit *this_, char *str)
1020 return speech_estimate_duration(this_->speech, str);
1024 navit_say(struct navit *this_, char *text)
1026 speech_say(this_->speech, text);
1030 * @brief Toggles the navigation announcer for navit
1031 * @param this_ The navit object
1034 navit_cmd_announcer_toggle(struct navit *this_)
1036 struct attr attr, speechattr;
1038 // search for the speech attribute
1039 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1041 // find out if the corresponding attribute attr_active has been set
1042 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1044 attr.u.num = !attr.u.num;
1046 // otherwise disable it because voice is enabled by default
1047 attr.type = attr_active;
1051 // apply the new state
1052 if(!speech_set_attr(speechattr.u.speech, &attr))
1055 // announce that the speech attribute has changed
1056 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1060 navit_speak(struct navit *this_)
1062 struct navigation *nav=this_->navigation;
1063 struct map *map=NULL;
1064 struct map_rect *mr=NULL;
1068 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1070 dbg(1, "this_.speech->active %i\n", attr.u.num);
1075 map=navigation_get_map(nav);
1077 mr=map_rect_new(map, NULL);
1079 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1080 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1081 speech_say(this_->speech, attr.u.str);
1082 navit_add_message(this_, attr.u.str);
1083 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1085 map_rect_destroy(mr);
1090 navit_window_roadbook_update(struct navit *this_)
1092 struct navigation *nav=this_->navigation;
1093 struct map *map=NULL;
1094 struct map_rect *mr=NULL;
1097 struct param_list param[5];
1101 datawindow_mode(this_->roadbook_window, 1);
1103 map=navigation_get_map(nav);
1105 mr=map_rect_new(map, NULL);
1106 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1108 dbg(0,"while loop\n");
1109 while ((item=map_rect_get_item(mr))) {
1110 dbg(0,"item=%p\n", item);
1112 if (item->type != type_nav_position) {
1113 item_attr_get(item, attr_navigation_long, &attr);
1114 if (attr.u.str == NULL) {
1117 dbg(2, "Command='%s'\n", attr.u.str);
1118 param[0].value=g_strdup(attr.u.str);
1120 param[0].value=_("Position");
1121 param[0].name=_("Command");
1123 item_attr_get(item, attr_length, &attr);
1124 dbg(2, "Length=%d\n", attr.u.num);
1125 param[1].name=_("Length");
1127 if ( attr.u.num >= 2000 )
1129 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1133 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1136 item_attr_get(item, attr_time, &attr);
1137 dbg(2, "Time=%d\n", attr.u.num);
1139 param[2].name=_("Time");
1142 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1146 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1149 item_attr_get(item, attr_destination_length, &attr);
1150 dbg(2, "Destlength=%d\n", attr.u.num);
1151 param[3].name=_("Destination Length");
1152 if ( attr.u.num >= 2000 )
1154 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1158 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1161 item_attr_get(item, attr_destination_time, &attr);
1162 dbg(2, "Desttime=%d\n", attr.u.num);
1164 param[4].name=_("Destination Time");
1167 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1171 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1173 datawindow_add(this_->roadbook_window, param, 5);
1175 map_rect_destroy(mr);
1177 datawindow_mode(this_->roadbook_window, 0);
1181 navit_window_roadbook_destroy(struct navit *this_)
1184 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1185 this_->roadbook_window=NULL;
1186 this_->roadbook_callback=NULL;
1189 navit_window_roadbook_new(struct navit *this_)
1191 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1195 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1196 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1197 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1198 navit_window_roadbook_update(this_);
1202 navit_init(struct navit *this_)
1208 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1210 if (!this_->gui && !(this_->flags & 2)) {
1212 navit_destroy(this_);
1215 if (!this_->gra && !(this_->flags & 1)) {
1216 dbg(0,"no graphics\n");
1217 navit_destroy(this_);
1220 dbg(2,"Connecting gui to graphics\n");
1221 if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
1222 struct attr attr_type_gui, attr_type_graphics;
1223 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1224 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1225 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1226 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1227 dbg(0," for explanations and solutions\n");
1229 navit_destroy(this_);
1232 dbg(2,"Initializing graphics\n");
1233 dbg(2,"Setting Vehicle\n");
1234 navit_set_vehicle(this_, this_->vehicle);
1235 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1236 if (this_->mapsets) {
1237 ms=this_->mapsets->data;
1239 if ((map=route_get_map(this_->route)))
1240 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1241 if ((map=route_get_graph_map(this_->route))) {
1242 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1243 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1245 route_set_mapset(this_->route, ms);
1246 route_set_projection(this_->route, transform_get_projection(this_->trans));
1248 if (this_->tracking) {
1249 tracking_set_mapset(this_->tracking, ms);
1251 tracking_set_route(this_->tracking, this_->route);
1253 if (this_->navigation) {
1254 if ((map=navigation_get_map(this_->navigation))) {
1255 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1256 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1259 if (this_->tracking) {
1260 if ((map=tracking_get_map(this_->tracking))) {
1261 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1262 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1265 navit_add_former_destinations_from_file(this_);
1268 struct attr callback;
1269 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1270 callback.type=attr_callback;
1271 callback.u.callback=this_->route_cb;
1272 route_add_attr(this_->route, &callback);
1274 if (this_->navigation) {
1275 if (this_->speech) {
1276 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1277 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1280 navigation_set_route(this_->navigation, this_->route);
1282 dbg(2,"Setting Center\n");
1283 char *center_file = bookmarks_get_center_file(FALSE);
1284 bookmarks_set_center_from_file(this_->bookmarks, center_file);
1285 g_free(center_file);
1287 if (this_->menubar) {
1288 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1290 navit_add_menu_windows_items(this_, men);
1296 navit_window_roadbook_new(this_);
1297 navit_window_items_new(this_);
1300 messagelist_init(this_->messages);
1302 navit_set_cursors(this_);
1304 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1305 callback=(this_->ready == 2);
1307 dbg(2,"ready=%d\n",this_->ready);
1308 if (this_->ready == 3)
1311 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
1313 routech_test(this_);
1318 navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
1323 c.x=(r->rl.x+r->lu.x)/2;
1324 c.y=(r->rl.y+r->lu.y)/2;
1325 transform_set_center(this_->trans, &c);
1326 dbg(1,"%x,%x-%x,%x\n", r->rl.x,r->rl.y,r->lu.x,r->lu.y);
1327 while (scale < 1<<20) {
1329 transform_set_scale(this_->trans, scale);
1330 transform_setup_source_rect(this_->trans);
1331 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
1332 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
1333 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1334 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1335 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1341 if (this_->ready == 3)
1342 navit_draw_async(this_,0);
1346 navit_zoom_to_route(struct navit *this_, int orientation)
1349 struct map_rect *mr=NULL;
1352 struct coord_rect r;
1357 map=route_get_map(this_->route);
1358 dbg(1,"map=%p\n",map);
1360 mr=map_rect_new(map, NULL);
1361 dbg(1,"mr=%p\n",mr);
1363 while ((item=map_rect_get_item(mr))) {
1364 dbg(1,"item=%s\n", item_to_name(item->type));
1365 while (item_coord_get(item, &c, 1)) {
1370 coord_rect_extend(&r, &c);
1377 if (orientation != -1)
1378 transform_set_yaw(this_->trans, orientation);
1379 navit_zoom_to_rect(this_, &r);
1383 navit_cmd_zoom_to_route(struct navit *this)
1385 navit_zoom_to_route(this, 0);
1390 * Change the current zoom level
1392 * @param navit The navit instance
1393 * @param center The point where to center the map, including its projection
1397 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
1399 struct coord *c=transform_center(this_->trans);
1401 enum projection pro = transform_get_projection(this_->trans);
1402 if (pro != center->pro) {
1405 transform_from_to(&c1, center->pro, &c2, pro);
1412 navit_set_timeout(this_);
1413 if (this_->ready == 3)
1418 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
1422 transform_set_center(this_->trans, c);
1423 transform_get_size(this_->trans, &width, &height);
1426 update_transformation(this_->trans, &po, p, NULL);
1428 navit_set_timeout(this_);
1432 * Links all vehicles to a cursor depending on the current profile.
1434 * @param this_ A navit instance
1435 * @author Ralph Sennhauser (10/2009)
1438 navit_set_cursors(struct navit *this_)
1441 struct navit_vehicle *nv;
1445 v=g_list_first(this_->vehicles); // GList of navit_vehicles
1448 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
1449 if (!strcmp(name.u.str,"none"))
1452 c=layout_get_cursor(this_->layout_current, name.u.str);
1454 c=layout_get_cursor(this_->layout_current, "default");
1455 vehicle_set_cursor(nv->vehicle, c);
1462 navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
1465 struct navit_vehicle *nv=this_->vehicle;
1467 float offset=this_->radius; // Cursor offset from the center of the screen (percent).
1468 #if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */
1469 float min_offset = 0.; // Percent offset at min_offset_speed.
1470 float max_offset = 30.; // Percent offset at max_offset_speed.
1471 int min_offset_speed = 2; // Speed in km/h
1472 int max_offset_speed = 50; // Speed ini km/h
1473 // Calculate cursor offset from the center of the screen, upon speed.
1474 if (nv->speed <= min_offset_speed) {
1475 offset = min_offset;
1476 } else if (nv->speed > max_offset_speed) {
1477 offset = max_offset;
1479 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
1483 transform_get_size(this_->trans, &width, &height);
1484 if (this_->orientation == -1 || keep_orientation) {
1486 p->y=(50 + offset)*height/100;
1488 *dir=keep_orientation?this_->orientation:nv->dir;
1491 if (this_->tracking && this_->tracking_flag) {
1492 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
1494 mdir=nv->dir-this_->orientation;
1497 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
1498 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
1500 *dir=this_->orientation;
1506 navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
1510 struct navit_vehicle *nv=this_->vehicle;
1511 navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
1512 transform_set_yaw(this_->trans, dir);
1513 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
1515 navit_autozoom(this_, &nv->coord, nv->speed, 0);
1519 navit_set_center_cursor_draw(struct navit *this_)
1521 navit_set_center_cursor(this_,1,0);
1522 if (this_->ready == 3)
1523 navit_draw_async(this_, 1);
1527 navit_cmd_set_center_cursor(struct navit *this_)
1529 navit_set_center_cursor_draw(this_);
1533 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
1537 transform_reverse(this_->trans, p, &c);
1540 pc.pro = transform_get_projection(this_->trans);
1541 navit_set_center(this_, &pc, set_timeout);
1545 switch((*attrs)->type) {
1547 zoom=(*attrs)->u.num;
1550 g=*((*attrs)->u.coord_geo);
1555 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
1557 int dir=0, orient_old=0, attr_updated=0;
1561 struct navit_vehicle *nv;
1562 struct attr active=(struct attr){attr_active,{(void *)0}};
1565 switch (attr->type) {
1567 attr_updated=(this_->autozoom_secs != attr->u.num);
1568 this_->autozoom_secs = attr->u.num;
1570 case attr_autozoom_active:
1571 attr_updated=(this_->autozoom_active != attr->u.num);
1572 this_->autozoom_active = attr->u.num;
1575 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
1576 dbg(1,"0x%x,0x%x\n",co.x,co.y);
1577 transform_set_center(this_->trans, &co);
1579 case attr_drag_bitmap:
1580 attr_updated=(this_->drag_bitmap != !!attr->u.num);
1581 this_->drag_bitmap=!!attr->u.num;
1584 attr_updated=(this_->flags != attr->u.num);
1585 this_->flags=attr->u.num;
1587 case attr_flags_graphics:
1588 attr_updated=(this_->graphics_flags != attr->u.num);
1589 this_->graphics_flags=attr->u.num;
1592 if (!this_->vehicle)
1594 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
1595 this_->vehicle->follow_curr = attr->u.num;
1598 if(this_->layout_current!=attr->u.layout) {
1599 this_->layout_current=attr->u.layout;
1600 graphics_font_destroy_all(this_->gra);
1601 navit_set_cursors(this_);
1602 if (this_->ready == 3)
1607 case attr_layout_name:
1611 if (!strcmp(lay->name,attr->u.str)) {
1613 attr.type=attr_layout;
1615 return navit_set_attr_do(this_, &attr, init);
1620 case attr_map_border:
1621 if (this_->border != attr->u.num) {
1622 this_->border=attr->u.num;
1626 case attr_orientation:
1627 orient_old=this_->orientation;
1628 this_->orientation=attr->u.num;
1630 if (this_->orientation != -1) {
1631 dir = this_->orientation;
1633 if (this_->vehicle) {
1634 dir = this_->vehicle->dir;
1637 transform_set_yaw(this_->trans, dir);
1638 if (orient_old != this_->orientation) {
1640 if (this_->ready == 3)
1647 case attr_osd_configuration:
1648 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
1649 attr_updated=(this_->osd_configuration != attr->u.num);
1650 this_->osd_configuration=attr->u.num;
1653 attr_updated=(this_->pitch != attr->u.num);
1654 this_->pitch=attr->u.num;
1655 transform_set_pitch(this_->trans, this_->pitch);
1656 if (!init && attr_updated && this_->ready == 3)
1659 case attr_projection:
1660 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
1661 navit_projection_set(this_, attr->u.projection, !init);
1666 attr_updated=(this_->radius != attr->u.num);
1667 this_->radius=attr->u.num;
1669 case attr_recent_dest:
1670 attr_updated=(this_->recentdest_count != attr->u.num);
1671 this_->recentdest_count=attr->u.num;
1674 if(this_->speech && this_->speech != attr->u.speech) {
1676 this_->speech = attr->u.speech;
1680 attr_updated=(this_->center_timeout != attr->u.num);
1681 this_->center_timeout = attr->u.num;
1684 attr_updated=(this_->tracking_flag != !!attr->u.num);
1685 this_->tracking_flag=!!attr->u.num;
1687 case attr_transformation:
1688 this_->trans=attr->u.transformation;
1690 case attr_use_mousewheel:
1691 attr_updated=(this_->use_mousewheel != !!attr->u.num);
1692 this_->use_mousewheel=!!attr->u.num;
1698 if (nv->vehicle == attr->u.vehicle) {
1699 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
1701 vehicle_set_attr(this_->vehicle->vehicle, &active);
1703 vehicle_set_attr(nv->vehicle, &active);
1706 navit_set_vehicle(this_, nv);
1712 zoom=transform_get_scale(this_->trans);
1713 attr_updated=(zoom != attr->u.num);
1714 transform_set_scale(this_->trans, attr->u.num);
1715 if (attr_updated && !init)
1719 attr_updated=(attr->u.num != this_->zoom_min);
1720 this_->zoom_min=attr->u.num;
1723 attr_updated=(attr->u.num != this_->zoom_max);
1724 this_->zoom_max=attr->u.num;
1727 navit_add_message(this_, attr->u.str);
1729 case attr_follow_cursor:
1730 attr_updated=(this_->follow_cursor != !!attr->u.num);
1731 this_->follow_cursor=!!attr->u.num;
1736 if (attr_updated && !init) {
1737 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1738 if (attr->type == attr_osd_configuration)
1739 graphics_draw_mode(this_->gra, draw_mode_end);
1745 navit_set_attr(struct navit *this_, struct attr *attr)
1747 return navit_set_attr_do(this_, attr, 0);
1751 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
1753 struct message *msg;
1759 msg = navit_get_messages(this_);
1767 len += strlen(msg->text) + 1;
1770 attr->u.str = g_malloc(len + 1);
1772 msg = navit_get_messages(this_);
1775 g_stpcpy((attr->u.str + offset), msg->text);
1776 offset += strlen(msg->text);
1777 attr->u.str[offset] = '\n';
1783 attr->u.str[len] = '\0';
1785 case attr_bookmark_map:
1786 attr->u.map=bookmarks_get_map(this_->bookmarks);
1788 case attr_bookmarks:
1789 attr->u.bookmarks=this_->bookmarks;
1791 case attr_callback_list:
1792 attr->u.callback_list=this_->attr_cbl;
1794 case attr_destination:
1795 if (! this_->destination_valid)
1797 attr->u.pcoord=&this_->destination;
1799 case attr_displaylist:
1800 attr->u.displaylist=this_->displaylist;
1801 return (attr->u.displaylist != NULL);
1803 if (!this_->vehicle)
1805 attr->u.num=this_->vehicle->follow_curr;
1807 case attr_former_destination_map:
1808 attr->u.map=this_->former_destination;
1811 attr->u.graphics=this_->gra;
1812 ret=(attr->u.graphics != NULL);
1815 attr->u.gui=this_->gui;
1816 ret=(attr->u.gui != NULL);
1821 iter->u.list=g_list_next(iter->u.list);
1823 iter->u.list=this_->layouts;
1827 attr->u.layout=(struct layout *)iter->u.list->data;
1829 attr->u.layout=this_->layout_current;
1833 if (iter && this_->mapsets) {
1834 if (!iter->u.mapset_handle) {
1835 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
1837 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
1839 mapset_close(iter->u.mapset_handle);
1847 attr->u.mapset=this_->mapsets->data;
1848 ret=(attr->u.mapset != NULL);
1850 case attr_navigation:
1851 attr->u.navigation=this_->navigation;
1853 case attr_orientation:
1854 attr->u.num=this_->orientation;
1856 case attr_osd_configuration:
1857 attr->u.num=this_->osd_configuration;
1860 attr->u.num=transform_get_pitch(this_->trans);
1862 case attr_projection:
1864 attr->u.num=transform_get_projection(this_->trans);
1870 attr->u.route=this_->route;
1873 attr->u.speech=this_->speech;
1876 attr->u.num=this_->tracking_flag;
1878 case attr_trackingo:
1879 attr->u.tracking=this_->tracking;
1881 case attr_transformation:
1882 attr->u.transformation=this_->trans;
1887 iter->u.list=g_list_next(iter->u.list);
1889 iter->u.list=this_->vehicles;
1893 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
1895 if(this_->vehicle) {
1896 attr->u.vehicle=this_->vehicle->vehicle;
1902 case attr_vehicleprofile:
1903 attr->u.vehicleprofile=this_->vehicleprofile;
1906 attr->u.num=transform_get_scale(this_->trans);
1908 case attr_autozoom_active:
1909 attr->u.num=this_->autozoom_active;
1911 case attr_follow_cursor:
1912 attr->u.num=this_->follow_cursor;
1922 navit_add_log(struct navit *this_, struct log *log)
1924 struct attr type_attr;
1925 if (!log_get_attr(log, attr_type, &type_attr, NULL))
1927 if (!strcmp(type_attr.u.str, "textfile_debug")) {
1928 char *header = "type=track_tracked\n";
1929 if (this_->textfile_debug_log)
1931 log_set_header(log, header, strlen(header));
1932 this_->textfile_debug_log=log;
1939 navit_add_attr(struct navit *this_, struct attr *attr)
1942 switch (attr->type) {
1944 navit_add_callback(this_, attr->u.callback);
1947 ret=navit_add_log(this_, attr->u.log);
1950 ret=navit_set_gui(this_, attr->u.gui);
1953 ret=navit_set_graphics(this_, attr->u.graphics);
1956 this_->layouts = g_list_append(this_->layouts, attr->u.layout);
1957 if(!this_->layout_current)
1958 this_->layout_current=attr->u.layout;
1961 this_->route=attr->u.route;
1964 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
1966 case attr_navigation:
1967 this_->navigation=attr->u.navigation;
1969 case attr_recent_dest:
1970 this_->recentdest_count = attr->u.num;
1973 this_->speech=attr->u.speech;
1976 this_->tracking=attr->u.tracking;
1979 ret=navit_add_vehicle(this_, attr->u.vehicle);
1981 case attr_vehicleprofile:
1982 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
1984 case attr_autozoom_min:
1985 this_->autozoom_min = attr->u.num;
1990 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1995 navit_remove_attr(struct navit *this_, struct attr *attr)
1998 switch (attr->type) {
2000 navit_remove_callback(this_, attr->u.callback);
2009 navit_attr_iter_new(void)
2011 return g_new0(struct attr_iter, 1);
2015 navit_attr_iter_destroy(struct attr_iter *iter)
2021 navit_add_callback(struct navit *this_, struct callback *cb)
2023 callback_list_add(this_->attr_cbl, cb);
2027 navit_remove_callback(struct navit *this_, struct callback *cb)
2029 callback_list_remove(this_->attr_cbl, cb);
2033 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
2035 * @param navit The navit instance
2040 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
2042 struct point cursor_pnt;
2043 enum projection pro;
2050 pro=transform_get_projection(this_->trans_cursor);
2053 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2055 vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
2060 pro=transform_get_projection(this_->trans);
2061 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2064 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2066 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2072 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2074 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2075 struct pcoord cursor_pc;
2076 struct point cursor_pnt, *pnt=&cursor_pnt;
2077 struct tracking *tracking=NULL;
2078 struct pcoord pc[16];
2079 enum projection pro=transform_get_projection(this_->trans_cursor);
2081 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2083 char *destination_file;
2086 if (this_->ready != 3) {
2087 profile(0,"return 1\n");
2090 navit_layout_switch(this_);
2091 if (this_->vehicle == nv && this_->tracking_flag)
2092 tracking=this_->tracking;
2094 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2095 attr_object=tracking;
2096 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2098 attr_object=nv->vehicle;
2099 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2101 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2102 if (!attr_valid.u.num != attr_position_valid_invalid)
2104 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2105 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2106 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2107 profile(0,"return 2\n");
2110 nv->dir=*attr_dir.u.numd;
2111 nv->speed=*attr_speed.u.numd;
2112 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2113 if (nv != this_->vehicle) {
2114 navit_vehicle_draw(this_, nv, NULL);
2115 profile(0,"return 3\n");
2118 cursor_pc.x = nv->coord.x;
2119 cursor_pc.y = nv->coord.y;
2120 cursor_pc.pro = pro;
2123 route_set_position_from_tracking(this_->route, tracking, pro);
2125 route_set_position(this_->route, &cursor_pc);
2127 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2128 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2129 if (this_->gui && nv->speed > 2)
2130 navit_disable_suspend();
2132 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2133 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
2134 (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
2135 navit_set_center_cursor_draw(this_);
2137 navit_vehicle_draw(this_, nv, pnt);
2139 if (nv->follow_curr > 1)
2142 nv->follow_curr=nv->follow;
2143 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2145 /* Finally, if we reached our destination, stop navigation. */
2147 switch(route_destination_reached(this_->route)) {
2149 route_remove_waypoint(this_->route);
2150 count=route_get_destinations(this_->route, pc, 16);
2151 destination_file = bookmarks_get_destination_file(TRUE);
2152 bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
2155 navit_set_destination(this_, NULL, NULL, 0);
2159 profile(0,"return 5\n");
2163 * Set the position of the vehicle
2165 * @param navit The navit instance
2166 * @param c The coordinate to set as position
2171 navit_set_position(struct navit *this_, struct pcoord *c)
2174 route_set_position(this_->route, c);
2175 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2177 if (this_->ready == 3)
2182 navit_set_vehicleprofile(struct navit *this_, char *name)
2186 l=this_->vehicleprofiles;
2188 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2189 if (!strcmp(attr.u.str, name)) {
2190 this_->vehicleprofile=l->data;
2192 route_set_profile(this_->route, this_->vehicleprofile);
2202 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2206 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2207 if (navit_set_vehicleprofile(this_, attr.u.str))
2210 if (!navit_set_vehicleprofile(this_,"car")) {
2211 /* We do not have a fallback "car" profile
2212 * so lets set any profile */
2214 l=this_->vehicleprofiles;
2216 this_->vehicleprofile=l->data;
2218 route_set_profile(this_->route, this_->vehicleprofile);
2224 * Register a new vehicle
2226 * @param navit The navit instance
2227 * @param v The vehicle instance
2228 * @returns 1 for success
2231 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2233 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2234 struct attr follow, active, animate;
2239 nv->animate_cursor=0;
2240 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2241 nv->follow=follow.u.num;
2242 nv->follow_curr=nv->follow;
2243 this_->vehicles=g_list_append(this_->vehicles, nv);
2244 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2245 navit_set_vehicle(this_, nv);
2246 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2247 nv->animate_cursor=animate.u.num;
2248 nv->callback.type=attr_callback;
2249 nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
2250 vehicle_add_attr(nv->vehicle, &nv->callback);
2251 vehicle_set_attr(nv->vehicle, &this_->self);
2259 navit_get_gui(struct navit *this_)
2264 struct transformation *
2265 navit_get_trans(struct navit *this_)
2267 return this_->trans;
2271 navit_get_route(struct navit *this_)
2273 return this_->route;
2277 navit_get_navigation(struct navit *this_)
2279 return this_->navigation;
2282 struct displaylist *
2283 navit_get_displaylist(struct navit *this_)
2285 return this_->displaylist;
2289 navit_layout_switch(struct navit *n)
2293 struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
2294 double trise,tset,trise_actual;
2296 int year, month, day;
2298 if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
2299 return; //No layout - nothing to switch
2303 l=layout_attr.u.layout;
2305 if (l->dayname || l->nightname) {
2306 //Ok, we know that we have profile to switch
2308 //Check that we aren't calculating too fast
2309 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
2310 currTs=iso8601_to_secs(iso8601_attr.u.str);
2311 dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
2313 if (currTs-(n->prevTs)<60) {
2314 //We've have to wait a little
2317 if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
2319 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
2320 return; //No valid fix yet
2322 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
2323 //No position - no sun
2327 //We calculate sunrise anyway, cause it is needed both for day and for night
2328 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2329 //near the pole sun never rises/sets, so we should never switch profiles
2330 dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
2336 dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
2339 if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
2340 (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
2341 //The sun is rising now!
2342 if (strcmp(l->name,l->dayname)) {
2343 navit_set_layout_by_name(n,l->dayname);
2348 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2349 //near the pole sun never rises/sets, so we should never switch profiles
2350 dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
2354 dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
2355 if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
2356 || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
2357 ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
2359 if (strcmp(l->name,l->nightname)) {
2360 navit_set_layout_by_name(n,l->nightname);
2370 navit_set_vehicle_by_name(struct navit *n,const char *name)
2373 struct attr_iter *iter;
2374 struct attr vehicle_attr, name_attr;
2376 iter=navit_attr_iter_new();
2378 while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
2379 v=vehicle_attr.u.vehicle;
2380 vehicle_get_attr(v,attr_name,&name_attr,NULL);
2381 if (name_attr.type==attr_name) {
2382 if (!strcmp(name,name_attr.u.str)) {
2383 navit_set_attr(n,&vehicle_attr);
2384 navit_attr_iter_destroy(iter);
2389 navit_attr_iter_destroy(iter);
2394 navit_set_layout_by_name(struct navit *n,const char *name)
2397 struct attr_iter iter;
2398 struct attr layout_attr;
2402 if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
2403 return 0; //No layouts - nothing to do
2405 if (iter.u.list==NULL) {
2409 iter.u.list=g_list_first(iter.u.list);
2411 while(iter.u.list) {
2412 l=(struct layout*)iter.u.list->data;
2413 if (!strcmp(name,l->name)) {
2414 layout_attr.u.layout=l;
2415 layout_attr.type=attr_layout;
2416 navit_set_attr(n,&layout_attr);
2417 iter.u.list=g_list_first(iter.u.list);
2420 iter.u.list=g_list_next(iter.u.list);
2423 iter.u.list=g_list_first(iter.u.list);
2428 navit_disable_suspend() {
2429 gui_disable_suspend(global_navit->gui);
2430 callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
2434 navit_block(struct navit *this_, int block)
2437 this_->blocked |= 1;
2438 if (graphics_draw_cancel(this_->gra, this_->displaylist))
2439 this_->blocked |= 2;
2442 if ((this_->blocked & 2) || block < 0) {
2452 navit_destroy(struct navit *this_)
2454 callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
2456 /* TODO: destroy objects contained in this_ */
2458 vehicle_destroy(this_->vehicle->vehicle);
2459 if (this_->bookmarks) {
2460 char *center_file = bookmarks_get_center_file(TRUE);
2461 bookmarks_write_center_to_file(this_->bookmarks, center_file);
2462 g_free(center_file);
2463 bookmarks_destroy(this_->bookmarks);
2465 callback_destroy(this_->nav_speech_cb);
2466 callback_destroy(this_->roadbook_callback);
2467 callback_destroy(this_->popup_callback);
2468 callback_destroy(this_->motion_timeout_callback);
2470 graphics_remove_callback(this_->gra, this_->resize_callback);
2471 callback_destroy(this_->resize_callback);
2473 graphics_remove_callback(this_->gra, this_->button_callback);
2474 callback_destroy(this_->button_callback);
2476 graphics_remove_callback(this_->gra, this_->motion_callback);
2477 callback_destroy(this_->motion_callback);
2479 graphics_remove_callback(this_->gra, this_->postdraw_callback);
2480 callback_destroy(this_->postdraw_callback);
2481 route_destroy(this_->route);