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;
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;
133 struct vehicleprofile *vehicleprofile;
134 GList *vehicleprofiles;
139 int zoom_min, zoom_max;
141 struct bookmarks *bookmarks;
143 /* 1=No graphics ok */
147 struct gui *main_loop_gui;
152 struct mapset_handle *mapset_handle;
156 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
157 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
158 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
159 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
160 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir);
161 static void navit_set_cursors(struct navit *this_);
162 static void navit_cmd_zoom_to_route(struct navit *this);
163 static void navit_cmd_set_center_cursor(struct navit *this_);
164 static void navit_cmd_announcer_toggle(struct navit *this_);
165 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
167 struct navit *global_navit;
170 navit_add_mapset(struct navit *this_, struct mapset *ms)
172 this_->mapsets = g_list_append(this_->mapsets, ms);
176 navit_get_mapset(struct navit *this_)
179 return this_->mapsets->data;
181 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
187 navit_get_tracking(struct navit *this_)
189 return this_->tracking;
193 navit_draw_async(struct navit *this_, int async)
196 struct navit_vehicle *nv;
198 if (this_->blocked) {
202 transform_setup_source_rect(this_->trans);
206 navit_vehicle_draw(this_, nv, NULL);
209 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
213 navit_draw(struct navit *this_)
215 if (this_->ready == 3)
216 navit_draw_async(this_, 0);
220 navit_get_ready(struct navit *this_)
228 navit_draw_displaylist(struct navit *this_)
230 if (this_->ready == 3)
231 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
235 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
238 if (attr->type != attr_route_status)
241 if (this_->ready != 3)
243 if (updated != route_status_path_done_new)
245 if (this_->vehicle) {
246 if (this_->vehicle->follow_curr == 1)
248 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
249 this_->vehicle->follow_curr=this_->vehicle->follow;
255 navit_handle_resize(struct navit *this_, int w, int h)
257 struct map_selection sel;
258 int callback=(this_->ready == 1);
260 memset(&sel, 0, sizeof(sel));
265 transform_set_screen_selection(this_->trans, &sel);
266 graphics_init(this_->gra);
267 graphics_set_rect(this_->gra, &sel.u.p_rect);
269 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
270 if (this_->ready == 3)
275 navit_resize(void *data, int w, int h)
277 struct navit *this=data;
278 if (!this->ignore_graphics_events)
279 navit_handle_resize(this, w, h);
283 navit_get_width(struct navit *this_)
290 navit_get_height(struct navit *this_)
296 navit_popup(void *data)
298 struct navit *this_=data;
299 popup(this_, 1, &this_->pressed);
300 this_->button_timeout=NULL;
306 navit_ignore_button(struct navit *this_)
308 if (this_->ignore_button)
310 this_->ignore_button=1;
315 navit_ignore_graphics_events(struct navit *this_, int ignore)
317 this_->ignore_graphics_events=ignore;
321 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
326 double angleo,anglen;
328 if (!transform_reverse(tr, old, &co))
331 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
332 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
333 yaw=transform_get_yaw(tr)+angleo-anglen;
334 transform_set_yaw(tr, yaw % 360);
336 if (!transform_reverse(tr, new, &cn))
338 cp=transform_get_center(tr);
341 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
342 transform_set_center(tr, &c);
346 navit_set_timeout(struct navit *this_)
349 follow.type=attr_follow;
350 follow.u.num=this_->center_timeout;
351 navit_set_attr(this_, &follow);
355 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
359 dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
360 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
361 if (this_->ignore_button) {
362 this_->ignore_button=0;
370 this_->button_pressed=1;
374 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
377 navit_set_center_screen(this_, p, 1);
379 popup(this_, button, p);
380 if (button == 4 && this_->use_mousewheel) {
382 navit_zoom_in(this_, 2, p);
384 if (button == 5 && this_->use_mousewheel) {
386 navit_zoom_out(this_, 2, p);
390 this_->button_pressed=0;
391 if (this_->button_timeout) {
392 event_remove_timeout(this_->button_timeout);
393 this_->button_timeout=NULL;
394 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
395 navit_set_center_screen(this_, p, !this_->zoomed);
398 if (this_->motion_timeout) {
399 event_remove_timeout(this_->motion_timeout);
400 this_->motion_timeout=NULL;
407 update_transformation(this_->trans, &this_->pressed, p, &pr);
409 update_transformation(this_->trans, &this_->pressed, p, NULL);
411 graphics_draw_drag(this_->gra, NULL);
412 graphics_overlay_disable(this_->gra, 0);
414 navit_set_timeout(this_);
423 navit_button(void *data, int pressed, int button, struct point *p)
425 struct navit *this=data;
426 dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
427 if (!this->ignore_graphics_events) {
428 if (! this->popup_callback)
429 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
430 navit_handle_button(this, pressed, button, p, this->popup_callback);
436 navit_motion_timeout(struct navit *this_)
440 if (this_->drag_bitmap) {
442 point.x=(this_->current.x-this_->pressed.x);
443 point.y=(this_->current.y-this_->pressed.y);
444 if (graphics_draw_drag(this_->gra, &point)) {
445 graphics_overlay_disable(this_->gra, 1);
446 graphics_draw_mode(this_->gra, draw_mode_end);
448 this_->motion_timeout=NULL;
452 dx=(this_->current.x-this_->last.x);
453 dy=(this_->current.y-this_->last.y);
455 struct transformation *tr;
457 this_->last=this_->current;
458 graphics_overlay_disable(this_->gra, 1);
459 tr=transform_dup(this_->trans);
463 update_transformation(tr, &this_->pressed, &this_->current, &pr);
465 update_transformation(tr, &this_->pressed, &this_->current, NULL);
468 graphics_displaylist_move(this_->displaylist, dx, dy);
470 graphics_draw_cancel(this_->gra, this_->displaylist);
471 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
472 transform_destroy(tr);
475 this_->motion_timeout=NULL;
480 navit_handle_motion(struct navit *this_, struct point *p)
484 if (this_->button_pressed && !this_->popped) {
485 dx=(p->x-this_->pressed.x);
486 dy=(p->y-this_->pressed.y);
487 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
489 if (this_->button_timeout) {
490 event_remove_timeout(this_->button_timeout);
491 this_->button_timeout=NULL;
494 if (! this_->motion_timeout_callback)
495 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
496 if (! this_->motion_timeout)
497 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
503 navit_motion(void *data, struct point *p)
505 struct navit *this=data;
506 if (!this->ignore_graphics_events)
507 navit_handle_motion(this, p);
511 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
513 struct coord c1, c2, *center;
514 if (scale < this_->zoom_min)
515 scale=this_->zoom_min;
516 if (scale > this_->zoom_max)
517 scale=this_->zoom_max;
519 transform_reverse(this_->trans, p, &c1);
520 transform_set_scale(this_->trans, scale);
522 transform_reverse(this_->trans, p, &c2);
523 center = transform_center(this_->trans);
524 center->x += c1.x - c2.x;
525 center->y += c1.y - c2.y;
532 * @brief Automatically adjusts zoom level
534 * This function automatically adjusts the current
535 * zoom level according to the current speed.
537 * @param this_ The navit struct
538 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
539 * @param speed The vehicles speed in meters per second
540 * @param dir The direction into which the vehicle moves
543 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
550 if (! this_->autozoom_active) {
554 distance = speed * this_->autozoom_secs;
556 transform_get_size(this_->trans, &w, &h);
557 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
558 scale = transform_get_scale(this_->trans);
560 /* We make sure that the point we want to see is within a certain range
561 * around the vehicle. The radius of this circle is the size of the
562 * screen. This doesn't necessarily mean the point is visible because of
563 * perspective etc. Quite rough, but should be enough. */
566 new_scale = (double)distance / h * 16;
568 new_scale = (double)distance / w * 16;
571 if (abs(new_scale - scale) < 2) {
575 if (new_scale >= this_->autozoom_min) {
576 navit_scale(this_, (long)new_scale, &pc, 0);
578 if (scale != this_->autozoom_min) {
579 navit_scale(this_, this_->autozoom_min, &pc, 0);
585 * Change the current zoom level, zooming closer to the ground
587 * @param navit The navit instance
588 * @param factor The zoom factor, usually 2
589 * @param p The invariant point (if set to NULL, default to center)
593 navit_zoom_in(struct navit *this_, int factor, struct point *p)
595 long scale=transform_get_scale(this_->trans)/factor;
598 navit_scale(this_, scale, p, 1);
602 * Change the current zoom level
604 * @param navit The navit instance
605 * @param factor The zoom factor, usually 2
606 * @param p The invariant point (if set to NULL, default to center)
610 navit_zoom_out(struct navit *this_, int factor, struct point *p)
612 long scale=transform_get_scale(this_->trans)*factor;
613 navit_scale(this_, scale, p, 1);
617 navit_cmd_zoom_in(struct navit *this_)
620 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
621 navit_zoom_in(this_, 2, &p);
622 this_->vehicle->follow_curr=this_->vehicle->follow;
624 navit_zoom_in(this_, 2, NULL);
629 navit_cmd_zoom_out(struct navit *this_)
632 if (this_->vehicle && this_->vehicle->follow_curr == 1 && navit_get_cursor_pnt(this_, &p, NULL)) {
633 navit_zoom_out(this_, 2, &p);
634 this_->vehicle->follow_curr=this_->vehicle->follow;
636 navit_zoom_out(this_, 2, NULL);
642 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
644 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
645 navit_say(this, in[0]->u.str);
649 navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
652 char *description=NULL;
657 pc.pro = transform_get_projection(this->trans);
658 if (ATTR_IS_COORD(in[0]->type)) {
659 pc.x=in[0]->u.coord->x;
660 pc.y=in[0]->u.coord->y;
662 } else if (ATTR_IS_PCOORD(in[0]->type)) {
665 } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
670 } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
676 if (in[0] && ATTR_IS_STRING(in[0]->type))
677 description=in[0]->u.str;
678 navit_set_destination(this, &pc, description, 1);
682 navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
685 attr.type=attr_type_string_begin;
688 *out=attr_generic_add_attr(*out, &attr);
692 static struct command_table commands[] = {
693 {"zoom_in",command_cast(navit_cmd_zoom_in)},
694 {"zoom_out",command_cast(navit_cmd_zoom_out)},
695 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
696 {"say",command_cast(navit_cmd_say)},
697 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
698 {"set_destination",command_cast(navit_cmd_set_destination)},
699 {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
700 {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
705 navit_new(struct attr *parent, struct attr **attrs)
707 struct navit *this_=g_new0(struct navit, 1);
708 struct pcoord center;
711 enum projection pro=projection_mg;
716 this_->self.type=attr_navit;
717 this_->self.u.navit=this_;
718 this_->attr_cbl=callback_list_new();
720 this_->orientation=-1;
721 this_->tracking_flag=1;
722 this_->recentdest_count=10;
723 this_->osd_configuration=-1;
725 this_->center_timeout = 10;
726 this_->use_mousewheel = 1;
727 this_->autozoom_secs = 10;
728 this_->autozoom_min = 7;
729 this_->autozoom_active = 0;
731 this_->zoom_max = 2097152;
732 this_->follow_cursor = 1;
735 this_->trans = transform_new();
736 transform_from_geo(pro, &g, &co);
741 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
743 this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
747 for (;*attrs; attrs++) {
748 navit_set_attr_do(this_, *attrs, 1);
750 this_->displaylist=graphics_displaylist_new();
751 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
753 this_->messages = messagelist_new(attrs);
759 navit_set_gui(struct navit *this_, struct gui *gui)
764 if (gui_has_main_loop(this_->gui)) {
765 if (! main_loop_gui) {
766 main_loop_gui=this_->gui;
768 dbg(0,"gui with main loop already active, ignoring this instance");
776 navit_add_message(struct navit *this_, char *message)
778 message_new(this_->messages, message);
782 *navit_get_messages(struct navit *this_)
784 return message_get(this_->messages);
788 navit_set_graphics(struct navit *this_, struct graphics *gra)
793 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
794 graphics_add_callback(gra, this_->resize_callback);
795 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
796 graphics_add_callback(gra, this_->button_callback);
797 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
798 graphics_add_callback(gra, this_->motion_callback);
803 navit_get_graphics(struct navit *this_)
808 struct vehicleprofile *
809 navit_get_vehicleprofile(struct navit *this_)
811 return this_->vehicleprofile;
815 navit_get_vehicleprofiles(struct navit *this_)
817 return this_->vehicleprofiles;
821 navit_projection_set(struct navit *this_, enum projection pro, int draw)
826 c=transform_center(this_->trans);
827 transform_to_geo(transform_get_projection(this_->trans), c, &g);
828 transform_set_projection(this_->trans, pro);
829 transform_from_geo(pro, &g, c);
835 * Start the route computing to a given set of coordinates
837 * @param navit The navit instance
838 * @param c The coordinate to start routing to
839 * @param description A label which allows the user to later identify this destination in the former destinations selection
843 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
846 this_->destination=*c;
847 this_->destination_valid=1;
849 this_->destination_valid=0;
850 char *destination_file = bookmarks_get_destination_file(TRUE);
851 bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
852 g_free(destination_file);
853 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
855 route_set_destination(this_->route, c, async);
857 if (this_->ready == 3)
863 * Start the route computing to a given set of coordinates including waypoints
865 * @param navit The navit instance
866 * @param c The coordinate to start routing to
867 * @param description A label which allows the user to later identify this destination in the former destinations selection
871 navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
874 this_->destination=c[count-1];
875 this_->destination_valid=1;
877 this_->destination_valid=0;
878 char *destination_file = bookmarks_get_destination_file(TRUE);
879 bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
880 g_free(destination_file);
881 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
883 route_set_destinations(this_->route, c, count, async);
885 if (this_->ready == 3)
891 * @brief Checks if a route is calculated
893 * This function checks if a route is calculated.
895 * @param this_ The navit struct whose route should be checked.
896 * @return True if the route is set, false otherwise.
899 navit_check_route(struct navit *this_)
902 return route_get_path_set(this_->route);
909 navit_former_destinations_active(struct navit *this_)
911 char *destination_file = bookmarks_get_destination_file(FALSE);
915 f=fopen(destination_file,"r");
917 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
921 g_free(destination_file);
926 navit_add_former_destinations_from_file(struct navit *this_)
928 char *destination_file = bookmarks_get_destination_file(FALSE);
929 struct attr parent={attr_navit, .u.navit=this_};
930 struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}}, flags={attr_flags, {(void *)1}};
931 struct attr *attrs[]={&type, &data, &flags, NULL};
934 int i,valid=0,count=0;
936 struct pcoord pc[16];
938 this_->former_destination=map_new(&parent, attrs);
939 g_free(destination_file);
940 if (!this_->route || !navit_former_destinations_active(this_))
942 mr=map_rect_new(this_->former_destination, NULL);
943 while ((item=map_rect_get_item(mr))) {
944 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16)))
947 map_rect_destroy(mr);
948 if (valid && count > 0) {
949 for (i = 0 ; i < count ; i++) {
950 pc[i].pro=map_projection(this_->former_destination);
955 route_set_destination(this_->route, &pc[0], 1);
957 route_set_destinations(this_->route, pc, count, 1);
958 this_->destination=pc[count-1];
959 this_->destination_valid=1;
965 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
970 if (this_->textfile_debug_log && this_->vehicle) {
971 str1=g_strdup_vprintf(fmt, ap);
972 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
973 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
981 navit_speech_estimate(struct navit *this_, char *str)
983 return speech_estimate_duration(this_->speech, str);
987 navit_say(struct navit *this_, char *text)
989 speech_say(this_->speech, text);
993 * @brief Toggles the navigation announcer for navit
994 * @param this_ The navit object
997 navit_cmd_announcer_toggle(struct navit *this_)
999 struct attr attr, speechattr;
1001 // search for the speech attribute
1002 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1004 // find out if the corresponding attribute attr_active has been set
1005 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1007 attr.u.num = !attr.u.num;
1009 // otherwise disable it because voice is enabled by default
1010 attr.type = attr_active;
1014 // apply the new state
1015 if(!speech_set_attr(speechattr.u.speech, &attr))
1018 // announce that the speech attribute has changed
1019 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1023 navit_speak(struct navit *this_)
1025 struct navigation *nav=this_->navigation;
1026 struct map *map=NULL;
1027 struct map_rect *mr=NULL;
1031 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1033 dbg(1, "this_.speech->active %i\n", attr.u.num);
1038 map=navigation_get_map(nav);
1040 mr=map_rect_new(map, NULL);
1042 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1043 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1044 speech_say(this_->speech, attr.u.str);
1045 navit_add_message(this_, attr.u.str);
1046 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1048 map_rect_destroy(mr);
1053 navit_window_roadbook_update(struct navit *this_)
1055 struct navigation *nav=this_->navigation;
1056 struct map *map=NULL;
1057 struct map_rect *mr=NULL;
1060 struct param_list param[5];
1064 datawindow_mode(this_->roadbook_window, 1);
1066 map=navigation_get_map(nav);
1068 mr=map_rect_new(map, NULL);
1069 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1071 dbg(0,"while loop\n");
1072 while ((item=map_rect_get_item(mr))) {
1073 dbg(0,"item=%p\n", item);
1075 if (item->type != type_nav_position) {
1076 item_attr_get(item, attr_navigation_long, &attr);
1077 if (attr.u.str == NULL) {
1080 dbg(2, "Command='%s'\n", attr.u.str);
1081 param[0].value=g_strdup(attr.u.str);
1083 param[0].value=_("Position");
1084 param[0].name=_("Command");
1086 item_attr_get(item, attr_length, &attr);
1087 dbg(2, "Length=%d\n", attr.u.num);
1088 param[1].name=_("Length");
1090 if ( attr.u.num >= 2000 )
1092 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1096 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1099 item_attr_get(item, attr_time, &attr);
1100 dbg(2, "Time=%d\n", attr.u.num);
1102 param[2].name=_("Time");
1105 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1109 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1112 item_attr_get(item, attr_destination_length, &attr);
1113 dbg(2, "Destlength=%d\n", attr.u.num);
1114 param[3].name=_("Destination Length");
1115 if ( attr.u.num >= 2000 )
1117 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1121 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1124 item_attr_get(item, attr_destination_time, &attr);
1125 dbg(2, "Desttime=%d\n", attr.u.num);
1127 param[4].name=_("Destination Time");
1130 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1134 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1136 datawindow_add(this_->roadbook_window, param, 5);
1138 map_rect_destroy(mr);
1140 datawindow_mode(this_->roadbook_window, 0);
1144 navit_window_roadbook_destroy(struct navit *this_)
1147 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1148 this_->roadbook_window=NULL;
1149 this_->roadbook_callback=NULL;
1152 navit_window_roadbook_new(struct navit *this_)
1154 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1158 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1159 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1160 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1161 navit_window_roadbook_update(this_);
1165 navit_init(struct navit *this_)
1171 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1173 if (!this_->gui && !(this_->flags & 2)) {
1175 navit_destroy(this_);
1178 if (!this_->gra && !(this_->flags & 1)) {
1179 dbg(0,"no graphics\n");
1180 navit_destroy(this_);
1183 dbg(2,"Connecting gui to graphics\n");
1184 if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
1185 struct attr attr_type_gui, attr_type_graphics;
1186 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1187 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1188 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1189 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1190 dbg(0," for explanations and solutions\n");
1192 navit_destroy(this_);
1195 dbg(2,"Initializing graphics\n");
1196 dbg(2,"Setting Vehicle\n");
1197 navit_set_vehicle(this_, this_->vehicle);
1198 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1199 if (this_->mapsets) {
1200 ms=this_->mapsets->data;
1202 if ((map=route_get_map(this_->route)))
1203 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1204 if ((map=route_get_graph_map(this_->route))) {
1205 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1206 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1208 route_set_mapset(this_->route, ms);
1209 route_set_projection(this_->route, transform_get_projection(this_->trans));
1211 if (this_->tracking) {
1212 tracking_set_mapset(this_->tracking, ms);
1214 tracking_set_route(this_->tracking, this_->route);
1216 if (this_->navigation) {
1217 if ((map=navigation_get_map(this_->navigation))) {
1218 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1219 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1222 if (this_->tracking) {
1223 if ((map=tracking_get_map(this_->tracking))) {
1224 mapset_add_attr(ms, &(struct attr){attr_map,.u.map=map});
1225 map_set_attr(map, &(struct attr ){attr_active,.u.num=0});
1228 navit_add_former_destinations_from_file(this_);
1231 struct attr callback;
1232 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1233 callback.type=attr_callback;
1234 callback.u.callback=this_->route_cb;
1235 route_add_attr(this_->route, &callback);
1237 if (this_->navigation) {
1238 if (this_->speech) {
1239 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1240 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1243 navigation_set_route(this_->navigation, this_->route);
1245 dbg(2,"Setting Center\n");
1246 char *center_file = bookmarks_get_center_file(FALSE);
1247 bookmarks_set_center_from_file(this_->bookmarks, center_file);
1248 g_free(center_file);
1250 if (this_->menubar) {
1251 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1253 navit_add_menu_windows_items(this_, men);
1259 navit_window_roadbook_new(this_);
1260 navit_window_items_new(this_);
1263 messagelist_init(this_->messages);
1265 navit_set_cursors(this_);
1267 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1268 callback=(this_->ready == 2);
1270 dbg(2,"ready=%d\n",this_->ready);
1271 if (this_->ready == 3)
1274 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
1276 routech_test(this_);
1281 navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
1286 c.x=(r->rl.x+r->lu.x)/2;
1287 c.y=(r->rl.y+r->lu.y)/2;
1288 transform_set_center(this_->trans, &c);
1289 dbg(1,"%x,%x-%x,%x\n", r->rl.x,r->rl.y,r->lu.x,r->lu.y);
1290 while (scale < 1<<20) {
1292 transform_set_scale(this_->trans, scale);
1293 transform_setup_source_rect(this_->trans);
1294 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
1295 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
1296 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1297 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1298 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1304 if (this_->ready == 3)
1305 navit_draw_async(this_,0);
1309 navit_zoom_to_route(struct navit *this_, int orientation)
1312 struct map_rect *mr=NULL;
1315 struct coord_rect r;
1320 map=route_get_map(this_->route);
1321 dbg(1,"map=%p\n",map);
1323 mr=map_rect_new(map, NULL);
1324 dbg(1,"mr=%p\n",mr);
1326 while ((item=map_rect_get_item(mr))) {
1327 dbg(1,"item=%s\n", item_to_name(item->type));
1328 while (item_coord_get(item, &c, 1)) {
1333 coord_rect_extend(&r, &c);
1340 if (orientation != -1)
1341 transform_set_yaw(this_->trans, orientation);
1342 navit_zoom_to_rect(this_, &r);
1346 navit_cmd_zoom_to_route(struct navit *this)
1348 navit_zoom_to_route(this, 0);
1353 * Change the current zoom level
1355 * @param navit The navit instance
1356 * @param center The point where to center the map, including its projection
1360 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
1362 struct coord *c=transform_center(this_->trans);
1364 enum projection pro = transform_get_projection(this_->trans);
1365 if (pro != center->pro) {
1368 transform_from_to(&c1, center->pro, &c2, pro);
1375 navit_set_timeout(this_);
1376 if (this_->ready == 3)
1381 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
1385 transform_set_center(this_->trans, c);
1386 transform_get_size(this_->trans, &width, &height);
1389 update_transformation(this_->trans, &po, p, NULL);
1391 navit_set_timeout(this_);
1395 * Links all vehicles to a cursor depending on the current profile.
1397 * @param this_ A navit instance
1398 * @author Ralph Sennhauser (10/2009)
1401 navit_set_cursors(struct navit *this_)
1404 struct navit_vehicle *nv;
1408 v=g_list_first(this_->vehicles); // GList of navit_vehicles
1411 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
1412 if (!strcmp(name.u.str,"none"))
1415 c=layout_get_cursor(this_->layout_current, name.u.str);
1417 c=layout_get_cursor(this_->layout_current, "default");
1418 vehicle_set_cursor(nv->vehicle, c);
1425 navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir)
1428 struct navit_vehicle *nv=this_->vehicle;
1430 float offset=this_->radius; // Cursor offset from the center of the screen (percent).
1431 #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 */
1432 float min_offset = 0.; // Percent offset at min_offset_speed.
1433 float max_offset = 30.; // Percent offset at max_offset_speed.
1434 int min_offset_speed = 2; // Speed in km/h
1435 int max_offset_speed = 50; // Speed ini km/h
1436 // Calculate cursor offset from the center of the screen, upon speed.
1437 if (nv->speed <= min_offset_speed) {
1438 offset = min_offset;
1439 } else if (nv->speed > max_offset_speed) {
1440 offset = max_offset;
1442 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
1446 transform_get_size(this_->trans, &width, &height);
1447 if (this_->orientation == -1) {
1449 p->y=(50 + offset)*height/100;
1454 if (this_->tracking && this_->tracking_flag) {
1455 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
1457 mdir=nv->dir-this_->orientation;
1460 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
1461 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
1463 *dir=this_->orientation;
1469 navit_set_center_cursor(struct navit *this_)
1473 struct navit_vehicle *nv=this_->vehicle;
1474 navit_get_cursor_pnt(this_, &pn, &dir);
1475 transform_set_yaw(this_->trans, dir);
1476 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
1477 navit_autozoom(this_, &nv->coord, nv->speed, 0);
1478 if (this_->ready == 3)
1479 navit_draw_async(this_, 1);
1483 navit_cmd_set_center_cursor(struct navit *this_)
1485 navit_set_center_cursor(this_);
1489 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
1493 transform_reverse(this_->trans, p, &c);
1496 pc.pro = transform_get_projection(this_->trans);
1497 navit_set_center(this_, &pc, set_timeout);
1501 switch((*attrs)->type) {
1503 zoom=(*attrs)->u.num;
1506 g=*((*attrs)->u.coord_geo);
1511 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
1513 int dir=0, orient_old=0, attr_updated=0;
1517 struct navit_vehicle *nv;
1518 struct attr active=(struct attr){attr_active,{(void *)0}};
1521 switch (attr->type) {
1523 attr_updated=(this_->autozoom_secs != attr->u.num);
1524 this_->autozoom_secs = attr->u.num;
1526 case attr_autozoom_active:
1527 attr_updated=(this_->autozoom_active != attr->u.num);
1528 this_->autozoom_active = attr->u.num;
1531 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
1532 dbg(1,"0x%x,0x%x\n",co.x,co.y);
1533 transform_set_center(this_->trans, &co);
1535 case attr_drag_bitmap:
1536 attr_updated=(this_->drag_bitmap != !!attr->u.num);
1537 this_->drag_bitmap=!!attr->u.num;
1540 attr_updated=(this_->flags != attr->u.num);
1541 this_->flags=attr->u.num;
1543 case attr_flags_graphics:
1544 attr_updated=(this_->graphics_flags != attr->u.num);
1545 this_->graphics_flags=attr->u.num;
1548 if (!this_->vehicle)
1550 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
1551 this_->vehicle->follow_curr = attr->u.num;
1554 if(this_->layout_current!=attr->u.layout) {
1555 this_->layout_current=attr->u.layout;
1556 graphics_font_destroy_all(this_->gra);
1557 navit_set_cursors(this_);
1558 if (this_->ready == 3)
1563 case attr_layout_name:
1567 if (!strcmp(lay->name,attr->u.str)) {
1569 attr.type=attr_layout;
1571 return navit_set_attr_do(this_, &attr, init);
1576 case attr_orientation:
1577 orient_old=this_->orientation;
1578 this_->orientation=attr->u.num;
1580 if (this_->orientation != -1) {
1581 dir = this_->orientation;
1583 if (this_->vehicle) {
1584 dir = this_->vehicle->dir;
1587 transform_set_yaw(this_->trans, dir);
1588 if (orient_old != this_->orientation) {
1590 if (this_->ready == 3)
1597 case attr_osd_configuration:
1598 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
1599 attr_updated=(this_->osd_configuration != attr->u.num);
1600 this_->osd_configuration=attr->u.num;
1603 attr_updated=(this_->pitch != attr->u.num);
1604 this_->pitch=attr->u.num;
1605 transform_set_pitch(this_->trans, this_->pitch);
1606 if (!init && attr_updated && this_->ready == 3)
1609 case attr_projection:
1610 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
1611 navit_projection_set(this_, attr->u.projection, !init);
1616 attr_updated=(this_->radius != attr->u.num);
1617 this_->radius=attr->u.num;
1619 case attr_recent_dest:
1620 attr_updated=(this_->recentdest_count != attr->u.num);
1621 this_->recentdest_count=attr->u.num;
1624 if(this_->speech && this_->speech != attr->u.speech) {
1626 this_->speech = attr->u.speech;
1630 attr_updated=(this_->center_timeout != attr->u.num);
1631 this_->center_timeout = attr->u.num;
1634 attr_updated=(this_->tracking_flag != !!attr->u.num);
1635 this_->tracking_flag=!!attr->u.num;
1637 case attr_transformation:
1638 this_->trans=attr->u.transformation;
1640 case attr_use_mousewheel:
1641 attr_updated=(this_->use_mousewheel != !!attr->u.num);
1642 this_->use_mousewheel=!!attr->u.num;
1648 if (nv->vehicle == attr->u.vehicle) {
1649 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
1651 vehicle_set_attr(this_->vehicle->vehicle, &active);
1653 vehicle_set_attr(nv->vehicle, &active);
1656 navit_set_vehicle(this_, nv);
1662 zoom=transform_get_scale(this_->trans);
1663 attr_updated=(zoom != attr->u.num);
1664 transform_set_scale(this_->trans, attr->u.num);
1665 if (attr_updated && !init)
1669 attr_updated=(attr->u.num != this_->zoom_min);
1670 this_->zoom_min=attr->u.num;
1673 attr_updated=(attr->u.num != this_->zoom_max);
1674 this_->zoom_max=attr->u.num;
1677 navit_add_message(this_, attr->u.str);
1679 case attr_follow_cursor:
1680 attr_updated=(this_->follow_cursor != !!attr->u.num);
1681 this_->follow_cursor=!!attr->u.num;
1686 if (attr_updated && !init) {
1687 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1688 if (attr->type == attr_osd_configuration)
1689 graphics_draw_mode(this_->gra, draw_mode_end);
1695 navit_set_attr(struct navit *this_, struct attr *attr)
1697 return navit_set_attr_do(this_, attr, 0);
1701 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
1703 struct message *msg;
1709 msg = navit_get_messages(this_);
1717 len += strlen(msg->text) + 1;
1720 attr->u.str = g_malloc(len + 1);
1722 msg = navit_get_messages(this_);
1725 g_stpcpy((attr->u.str + offset), msg->text);
1726 offset += strlen(msg->text);
1727 attr->u.str[offset] = '\n';
1733 attr->u.str[len] = '\0';
1735 case attr_bookmark_map:
1736 attr->u.map=bookmarks_get_map(this_->bookmarks);
1738 case attr_bookmarks:
1739 attr->u.bookmarks=this_->bookmarks;
1741 case attr_callback_list:
1742 attr->u.callback_list=this_->attr_cbl;
1744 case attr_destination:
1745 if (! this_->destination_valid)
1747 attr->u.pcoord=&this_->destination;
1749 case attr_displaylist:
1750 attr->u.displaylist=this_->displaylist;
1751 return (attr->u.displaylist != NULL);
1753 if (!this_->vehicle)
1755 attr->u.num=this_->vehicle->follow_curr;
1757 case attr_former_destination_map:
1758 attr->u.map=this_->former_destination;
1761 attr->u.graphics=this_->gra;
1762 ret=(attr->u.graphics != NULL);
1765 attr->u.gui=this_->gui;
1766 ret=(attr->u.gui != NULL);
1771 iter->u.list=g_list_next(iter->u.list);
1773 iter->u.list=this_->layouts;
1777 attr->u.layout=(struct layout *)iter->u.list->data;
1779 attr->u.layout=this_->layout_current;
1783 if (iter && this_->mapsets) {
1784 if (!iter->u.mapset_handle) {
1785 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
1787 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
1789 mapset_close(iter->u.mapset_handle);
1797 attr->u.mapset=this_->mapsets->data;
1798 ret=(attr->u.mapset != NULL);
1800 case attr_navigation:
1801 attr->u.navigation=this_->navigation;
1803 case attr_orientation:
1804 attr->u.num=this_->orientation;
1806 case attr_osd_configuration:
1807 attr->u.num=this_->osd_configuration;
1810 attr->u.num=transform_get_pitch(this_->trans);
1812 case attr_projection:
1814 attr->u.num=transform_get_projection(this_->trans);
1820 attr->u.route=this_->route;
1823 attr->u.speech=this_->speech;
1826 attr->u.num=this_->tracking_flag;
1828 case attr_trackingo:
1829 attr->u.tracking=this_->tracking;
1831 case attr_transformation:
1832 attr->u.transformation=this_->trans;
1837 iter->u.list=g_list_next(iter->u.list);
1839 iter->u.list=this_->vehicles;
1843 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
1845 if(this_->vehicle) {
1846 attr->u.vehicle=this_->vehicle->vehicle;
1852 case attr_vehicleprofile:
1853 attr->u.vehicleprofile=this_->vehicleprofile;
1856 attr->u.num=transform_get_scale(this_->trans);
1858 case attr_autozoom_active:
1859 attr->u.num=this_->autozoom_active;
1861 case attr_follow_cursor:
1862 attr->u.num=this_->follow_cursor;
1872 navit_add_log(struct navit *this_, struct log *log)
1874 struct attr type_attr;
1875 if (!log_get_attr(log, attr_type, &type_attr, NULL))
1877 if (!strcmp(type_attr.u.str, "textfile_debug")) {
1878 char *header = "type=track_tracked\n";
1879 if (this_->textfile_debug_log)
1881 log_set_header(log, header, strlen(header));
1882 this_->textfile_debug_log=log;
1889 navit_add_attr(struct navit *this_, struct attr *attr)
1892 switch (attr->type) {
1894 navit_add_callback(this_, attr->u.callback);
1897 ret=navit_add_log(this_, attr->u.log);
1900 ret=navit_set_gui(this_, attr->u.gui);
1903 ret=navit_set_graphics(this_, attr->u.graphics);
1906 this_->layouts = g_list_append(this_->layouts, attr->u.layout);
1907 if(!this_->layout_current)
1908 this_->layout_current=attr->u.layout;
1911 this_->route=attr->u.route;
1914 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
1916 case attr_navigation:
1917 this_->navigation=attr->u.navigation;
1919 case attr_recent_dest:
1920 this_->recentdest_count = attr->u.num;
1923 this_->speech=attr->u.speech;
1926 this_->tracking=attr->u.tracking;
1929 ret=navit_add_vehicle(this_, attr->u.vehicle);
1931 case attr_vehicleprofile:
1932 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
1934 case attr_autozoom_min:
1935 this_->autozoom_min = attr->u.num;
1940 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
1945 navit_remove_attr(struct navit *this_, struct attr *attr)
1948 switch (attr->type) {
1950 navit_remove_callback(this_, attr->u.callback);
1959 navit_attr_iter_new(void)
1961 return g_new0(struct attr_iter, 1);
1965 navit_attr_iter_destroy(struct attr_iter *iter)
1971 navit_add_callback(struct navit *this_, struct callback *cb)
1973 callback_list_add(this_->attr_cbl, cb);
1977 navit_remove_callback(struct navit *this_, struct callback *cb)
1979 callback_list_remove(this_->attr_cbl, cb);
1983 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
1985 * @param navit The navit instance
1990 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
1992 struct point cursor_pnt;
1993 enum projection pro;
2000 pro=transform_get_projection(this_->trans);
2001 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2003 vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed);
2008 pro=transform_get_projection(this_->trans);
2009 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2012 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2014 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2020 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2022 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2023 struct pcoord cursor_pc;
2024 struct point cursor_pnt, *pnt=&cursor_pnt;
2025 struct tracking *tracking=NULL;
2026 struct pcoord pc[16];
2027 enum projection pro=transform_get_projection(this_->trans);
2028 int count,border=16;
2029 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2031 char *destination_file;
2034 if (this_->ready != 3) {
2035 profile(0,"return 1\n");
2038 navit_layout_switch(this_);
2039 if (this_->vehicle == nv && this_->tracking_flag)
2040 tracking=this_->tracking;
2042 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2043 attr_object=tracking;
2044 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2046 attr_object=nv->vehicle;
2047 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2049 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2050 if (!attr_valid.u.num != attr_position_valid_invalid)
2052 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2053 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2054 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2055 profile(0,"return 2\n");
2058 nv->dir=*attr_dir.u.numd;
2059 nv->speed=*attr_speed.u.numd;
2060 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2061 if (nv != this_->vehicle) {
2062 navit_vehicle_draw(this_, nv, NULL);
2063 profile(0,"return 3\n");
2066 cursor_pc.x = nv->coord.x;
2067 cursor_pc.y = nv->coord.y;
2068 cursor_pc.pro = pro;
2071 route_set_position_from_tracking(this_->route, tracking, pro);
2073 route_set_position(this_->route, &cursor_pc);
2075 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2076 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2077 if (this_->gui && nv->speed > 2)
2078 navit_disable_suspend();
2080 transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2081 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
2082 (nv->follow_curr == 1 || !transform_within_border(this_->trans, &cursor_pnt, border)))
2083 navit_set_center_cursor(this_);
2085 navit_vehicle_draw(this_, nv, pnt);
2087 if (nv->follow_curr > 1)
2090 nv->follow_curr=nv->follow;
2091 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2093 /* Finally, if we reached our destination, stop navigation. */
2095 switch(route_destination_reached(this_->route)) {
2097 route_remove_waypoint(this_->route);
2098 count=route_get_destinations(this_->route, pc, 16);
2099 destination_file = bookmarks_get_destination_file(TRUE);
2100 bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
2103 navit_set_destination(this_, NULL, NULL, 0);
2107 profile(0,"return 5\n");
2111 * Set the position of the vehicle
2113 * @param navit The navit instance
2114 * @param c The coordinate to set as position
2119 navit_set_position(struct navit *this_, struct pcoord *c)
2122 route_set_position(this_->route, c);
2123 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2125 if (this_->ready == 3)
2130 navit_set_vehicleprofile(struct navit *this_, char *name)
2134 l=this_->vehicleprofiles;
2136 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2137 if (!strcmp(attr.u.str, name)) {
2138 this_->vehicleprofile=l->data;
2140 route_set_profile(this_->route, this_->vehicleprofile);
2150 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2154 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2155 if (navit_set_vehicleprofile(this_, attr.u.str))
2158 if (!navit_set_vehicleprofile(this_,"car")) {
2159 /* We do not have a fallback "car" profile
2160 * so lets set any profile */
2162 l=this_->vehicleprofiles;
2164 this_->vehicleprofile=l->data;
2166 route_set_profile(this_->route, this_->vehicleprofile);
2172 * Register a new vehicle
2174 * @param navit The navit instance
2175 * @param v The vehicle instance
2176 * @returns 1 for success
2179 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2181 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2182 struct attr follow, active, animate;
2187 nv->animate_cursor=0;
2188 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2189 nv->follow=nv->follow=follow.u.num;
2190 nv->follow_curr=nv->follow;
2191 this_->vehicles=g_list_append(this_->vehicles, nv);
2192 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2193 navit_set_vehicle(this_, nv);
2194 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2195 nv->animate_cursor=animate.u.num;
2196 nv->callback.type=attr_callback;
2197 nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
2198 vehicle_add_attr(nv->vehicle, &nv->callback);
2199 vehicle_set_attr(nv->vehicle, &this_->self);
2207 navit_get_gui(struct navit *this_)
2212 struct transformation *
2213 navit_get_trans(struct navit *this_)
2215 return this_->trans;
2219 navit_get_route(struct navit *this_)
2221 return this_->route;
2225 navit_get_navigation(struct navit *this_)
2227 return this_->navigation;
2230 struct displaylist *
2231 navit_get_displaylist(struct navit *this_)
2233 return this_->displaylist;
2237 navit_layout_switch(struct navit *n)
2241 struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
2242 double trise,tset,trise_actual;
2244 int year, month, day;
2246 if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
2247 return; //No layout - nothing to switch
2251 l=layout_attr.u.layout;
2253 if (l->dayname || l->nightname) {
2254 //Ok, we know that we have profile to switch
2256 //Check that we aren't calculating too fast
2257 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
2258 currTs=iso8601_to_secs(iso8601_attr.u.str);
2259 dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
2261 if (currTs-(n->prevTs)<60) {
2262 //We've have to wait a little
2265 if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
2267 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
2268 //No position - no sun
2271 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
2272 return; //No valid fix yet
2275 //We calculate sunrise anyway, cause it is needed both for day and for night
2276 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2277 //near the pole sun never rises/sets, so we should never switch profiles
2278 dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
2284 dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
2287 if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
2288 (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
2289 //The sun is rising now!
2290 if (strcmp(l->name,l->dayname)) {
2291 navit_set_layout_by_name(n,l->dayname);
2296 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2297 //near the pole sun never rises/sets, so we should never switch profiles
2298 dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
2302 dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
2303 if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
2304 || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
2305 ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
2307 if (strcmp(l->name,l->nightname)) {
2308 navit_set_layout_by_name(n,l->nightname);
2318 navit_set_vehicle_by_name(struct navit *n,const char *name)
2321 struct attr_iter *iter;
2322 struct attr vehicle_attr, name_attr;
2324 iter=navit_attr_iter_new();
2326 while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
2327 v=vehicle_attr.u.vehicle;
2328 vehicle_get_attr(v,attr_name,&name_attr,NULL);
2329 if (name_attr.type==attr_name) {
2330 if (!strcmp(name,name_attr.u.str)) {
2331 navit_set_attr(n,&vehicle_attr);
2332 navit_attr_iter_destroy(iter);
2337 navit_attr_iter_destroy(iter);
2342 navit_set_layout_by_name(struct navit *n,const char *name)
2345 struct attr_iter iter;
2346 struct attr layout_attr;
2350 if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
2351 return 0; //No layouts - nothing to do
2353 if (iter.u.list==NULL) {
2357 iter.u.list=g_list_first(iter.u.list);
2359 while(iter.u.list) {
2360 l=(struct layout*)iter.u.list->data;
2361 if (!strcmp(name,l->name)) {
2362 layout_attr.u.layout=l;
2363 layout_attr.type=attr_layout;
2364 navit_set_attr(n,&layout_attr);
2365 iter.u.list=g_list_first(iter.u.list);
2368 iter.u.list=g_list_next(iter.u.list);
2371 iter.u.list=g_list_first(iter.u.list);
2376 navit_disable_suspend() {
2377 gui_disable_suspend(global_navit->gui);
2378 callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
2382 navit_block(struct navit *this_, int block)
2385 this_->blocked |= 1;
2386 if (graphics_draw_cancel(this_->gra, this_->displaylist))
2387 this_->blocked |= 2;
2390 if ((this_->blocked & 2) || block < 0) {
2400 navit_destroy(struct navit *this_)
2402 /* TODO: destroy objects contained in this_ */
2404 vehicle_destroy(this_->vehicle->vehicle);
2405 if (this_->bookmarks) {
2406 char *center_file = bookmarks_get_center_file(TRUE);
2407 bookmarks_write_center_to_file(this_->bookmarks, center_file);
2408 g_free(center_file);
2409 bookmarks_destroy(this_->bookmarks);
2411 callback_destroy(this_->nav_speech_cb);
2412 callback_destroy(this_->roadbook_callback);
2413 callback_destroy(this_->popup_callback);
2414 callback_destroy(this_->motion_timeout_callback);
2416 graphics_remove_callback(this_->gra, this_->resize_callback);
2417 callback_destroy(this_->resize_callback);
2419 graphics_remove_callback(this_->gra, this_->button_callback);
2420 callback_destroy(this_->button_callback);
2422 graphics_remove_callback(this_->gra, this_->motion_callback);
2423 callback_destroy(this_->motion_callback);
2424 route_destroy(this_->route);