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.
20 #define _USE_MATH_DEFINES 1
38 #include "projection.h"
44 #include "transform.h"
49 #include "data_window.h"
51 #include "navigation.h"
62 #include "navit_nls.h"
66 #include "vehicleprofile.h"
68 #include "bookmarks.h"
71 * @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
75 //! The navit_vehicule
76 struct navit_vehicle {
78 /*! Limit of the follow counter. See navit_add_vehicle */
80 /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
84 struct coord last; /*< Position of the last update of this vehicle */
85 struct vehicle *vehicle;
95 struct layout *layout_current;
97 struct action *action;
98 struct transformation *trans, *trans_cursor;
99 struct compass *compass;
101 struct navigation *navigation;
102 struct speech *speech;
103 struct tracking *tracking;
106 struct displaylist *displaylist;
109 int recentdest_count;
110 int osd_configuration;
112 GList *windows_items;
113 struct navit_vehicle *vehicle;
114 struct callback_list *attr_cbl;
115 struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb, *progress_cb;
116 struct datawindow *roadbook_window;
117 struct map *former_destination;
118 struct point pressed, last, current;
119 int button_pressed,moved,popped,zoomed;
124 struct event_timeout *button_timeout, *motion_timeout;
125 struct callback *motion_timeout_callback;
127 int ignore_graphics_events;
128 struct log *textfile_debug_log;
129 struct pcoord destination;
130 int destination_valid;
135 struct messagelist *messages;
136 struct callback *resize_callback,*button_callback,*motion_callback,*predraw_callback;
137 struct vehicleprofile *vehicleprofile;
138 GList *vehicleprofiles;
143 int zoom_min, zoom_max;
145 struct bookmarks *bookmarks;
147 /* 1=No graphics ok */
153 struct gui *main_loop_gui;
158 struct mapset_handle *mapset_handle;
162 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
163 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
164 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
165 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
166 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
167 static void navit_set_cursors(struct navit *this_);
168 static void navit_cmd_zoom_to_route(struct navit *this);
169 static void navit_cmd_set_center_cursor(struct navit *this_);
170 static void navit_cmd_announcer_toggle(struct navit *this_);
171 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
173 struct navit *global_navit;
176 navit_add_mapset(struct navit *this_, struct mapset *ms)
178 this_->mapsets = g_list_append(this_->mapsets, ms);
182 navit_get_mapset(struct navit *this_)
185 return this_->mapsets->data;
187 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
193 navit_get_tracking(struct navit *this_)
195 return this_->tracking;
199 * @brief Get the user data directory.
200 * @param[in] create - create the directory if it does not exist
202 * @return char * to the data directory string.
204 * returns the directory used to store user data files (center.txt,
205 * destination.txt, bookmark.txt, ...)
209 navit_get_user_data_directory(int create) {
211 dir = getenv("NAVIT_USER_DATADIR");
212 if (create && !file_exists(dir)) {
213 dbg(0,"creating dir %s\n", dir);
214 if (file_mkdir(dir,0)) {
215 dbg(0,"failed creating dir %s\n", dir);
220 } /* end: navit_get_user_data_directory(gboolean create) */
224 navit_draw_async(struct navit *this_, int async)
227 if (this_->blocked) {
231 transform_setup_source_rect(this_->trans);
232 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
236 navit_draw(struct navit *this_)
238 if (this_->ready == 3)
239 navit_draw_async(this_, 0);
243 navit_get_ready(struct navit *this_)
251 navit_draw_displaylist(struct navit *this_)
253 if (this_->ready == 3)
254 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
258 navit_map_progress(struct navit *this_)
262 struct mapset_handle *msh;
265 if (this_->ready != 3)
270 ms=this_->mapsets->data;
272 while (msh && (map=mapset_next(msh, 0))) {
273 if (map_get_attr(map, attr_progress, &attr, NULL)) {
274 char *str=g_strdup_printf("%s ",attr.u.str);
275 graphics_draw_mode(this_->gra, draw_mode_begin);
276 graphics_draw_text_std(this_->gra, 16, str, &p);
279 graphics_draw_mode(this_->gra, draw_mode_end);
286 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
289 if (attr->type != attr_route_status)
292 if (this_->ready != 3)
294 if (updated != route_status_path_done_new)
296 if (this_->vehicle) {
297 if (this_->vehicle->follow_curr == 1)
299 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
300 this_->vehicle->follow_curr=this_->vehicle->follow;
306 navit_handle_resize(struct navit *this_, int w, int h)
308 struct map_selection sel;
309 int callback=(this_->ready == 1);
311 memset(&sel, 0, sizeof(sel));
316 transform_set_screen_selection(this_->trans, &sel);
317 graphics_init(this_->gra);
318 graphics_set_rect(this_->gra, &sel.u.p_rect);
320 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
321 if (this_->ready == 3)
322 navit_draw_async(this_, 1);
326 navit_resize(void *data, int w, int h)
328 struct navit *this=data;
329 if (!this->ignore_graphics_events)
330 navit_handle_resize(this, w, h);
334 navit_get_width(struct navit *this_)
341 navit_get_height(struct navit *this_)
347 navit_popup(void *data)
349 struct navit *this_=data;
350 popup(this_, 1, &this_->pressed);
351 this_->button_timeout=NULL;
357 navit_ignore_button(struct navit *this_)
359 if (this_->ignore_button)
361 this_->ignore_button=1;
366 navit_ignore_graphics_events(struct navit *this_, int ignore)
368 this_->ignore_graphics_events=ignore;
372 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
377 double angleo,anglen;
379 if (!transform_reverse(tr, old, &co))
382 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
383 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
384 yaw=transform_get_yaw(tr)+angleo-anglen;
385 transform_set_yaw(tr, yaw % 360);
387 if (!transform_reverse(tr, new, &cn))
389 cp=transform_get_center(tr);
392 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
393 transform_set_center(tr, &c);
397 navit_set_timeout(struct navit *this_)
400 follow.type=attr_follow;
401 follow.u.num=this_->center_timeout;
402 navit_set_attr(this_, &follow);
406 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
410 dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
411 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
412 if (this_->ignore_button) {
413 this_->ignore_button=0;
421 this_->button_pressed=1;
425 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
428 navit_set_center_screen(this_, p, 1);
430 popup(this_, button, p);
431 if (button == 4 && this_->use_mousewheel) {
433 navit_zoom_in(this_, 2, p);
435 if (button == 5 && this_->use_mousewheel) {
437 navit_zoom_out(this_, 2, p);
441 this_->button_pressed=0;
442 if (this_->button_timeout) {
443 event_remove_timeout(this_->button_timeout);
444 this_->button_timeout=NULL;
445 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
446 navit_set_center_screen(this_, p, !this_->zoomed);
449 if (this_->motion_timeout) {
450 event_remove_timeout(this_->motion_timeout);
451 this_->motion_timeout=NULL;
458 update_transformation(this_->trans, &this_->pressed, p, &pr);
460 update_transformation(this_->trans, &this_->pressed, p, NULL);
462 graphics_draw_drag(this_->gra, NULL);
463 transform_copy(this_->trans, this_->trans_cursor);
464 graphics_overlay_disable(this_->gra, 0);
466 navit_set_timeout(this_);
475 navit_button(void *data, int pressed, int button, struct point *p)
477 struct navit *this=data;
478 dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
479 if (!this->ignore_graphics_events) {
480 if (! this->popup_callback)
481 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
482 navit_handle_button(this, pressed, button, p, this->popup_callback);
488 navit_motion_timeout(struct navit *this_)
492 if (this_->drag_bitmap) {
494 point.x=(this_->current.x-this_->pressed.x);
495 point.y=(this_->current.y-this_->pressed.y);
496 if (graphics_draw_drag(this_->gra, &point)) {
497 graphics_overlay_disable(this_->gra, 1);
498 graphics_draw_mode(this_->gra, draw_mode_end);
500 this_->motion_timeout=NULL;
504 dx=(this_->current.x-this_->last.x);
505 dy=(this_->current.y-this_->last.y);
507 struct transformation *tr;
509 this_->last=this_->current;
510 graphics_overlay_disable(this_->gra, 1);
511 tr=transform_dup(this_->trans);
515 update_transformation(tr, &this_->pressed, &this_->current, &pr);
517 update_transformation(tr, &this_->pressed, &this_->current, NULL);
520 graphics_displaylist_move(this_->displaylist, dx, dy);
522 graphics_draw_cancel(this_->gra, this_->displaylist);
523 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
524 transform_destroy(tr);
527 this_->motion_timeout=NULL;
532 navit_handle_motion(struct navit *this_, struct point *p)
536 if (this_->button_pressed && !this_->popped) {
537 dx=(p->x-this_->pressed.x);
538 dy=(p->y-this_->pressed.y);
539 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
541 if (this_->button_timeout) {
542 event_remove_timeout(this_->button_timeout);
543 this_->button_timeout=NULL;
546 if (! this_->motion_timeout_callback)
547 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
548 if (! this_->motion_timeout)
549 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
555 navit_motion(void *data, struct point *p)
557 struct navit *this=data;
558 if (!this->ignore_graphics_events)
559 navit_handle_motion(this, p);
563 navit_predraw(struct navit *this_)
566 struct navit_vehicle *nv;
567 transform_copy(this_->trans, this_->trans_cursor);
571 navit_vehicle_draw(this_, nv, NULL);
577 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
579 struct coord c1, c2, *center;
580 if (scale < this_->zoom_min)
581 scale=this_->zoom_min;
582 if (scale > this_->zoom_max)
583 scale=this_->zoom_max;
585 transform_reverse(this_->trans, p, &c1);
586 transform_set_scale(this_->trans, scale);
588 transform_reverse(this_->trans, p, &c2);
589 center = transform_center(this_->trans);
590 center->x += c1.x - c2.x;
591 center->y += c1.y - c2.y;
598 * @brief Automatically adjusts zoom level
600 * This function automatically adjusts the current
601 * zoom level according to the current speed.
603 * @param this_ The navit struct
604 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
605 * @param speed The vehicles speed in meters per second
606 * @param dir The direction into which the vehicle moves
609 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
616 if (! this_->autozoom_active) {
620 distance = speed * this_->autozoom_secs;
622 transform_get_size(this_->trans, &w, &h);
623 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
624 scale = transform_get_scale(this_->trans);
626 /* We make sure that the point we want to see is within a certain range
627 * around the vehicle. The radius of this circle is the size of the
628 * screen. This doesn't necessarily mean the point is visible because of
629 * perspective etc. Quite rough, but should be enough. */
632 new_scale = (double)distance / h * 16;
634 new_scale = (double)distance / w * 16;
637 if (abs(new_scale - scale) < 2) {
641 if (new_scale >= this_->autozoom_min) {
642 navit_scale(this_, (long)new_scale, &pc, 0);
644 if (scale != this_->autozoom_min) {
645 navit_scale(this_, this_->autozoom_min, &pc, 0);
651 * Change the current zoom level, zooming closer to the ground
653 * @param navit The navit instance
654 * @param factor The zoom factor, usually 2
655 * @param p The invariant point (if set to NULL, default to center)
659 navit_zoom_in(struct navit *this_, int factor, struct point *p)
661 long scale=transform_get_scale(this_->trans)/factor;
664 navit_scale(this_, scale, p, 1);
668 * Change the current zoom level
670 * @param navit The navit instance
671 * @param factor The zoom factor, usually 2
672 * @param p The invariant point (if set to NULL, default to center)
676 navit_zoom_out(struct navit *this_, int factor, struct point *p)
678 long scale=transform_get_scale(this_->trans)*factor;
679 navit_scale(this_, scale, p, 1);
683 navit_zoom_in_cursor(struct navit *this_, int factor)
686 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
687 navit_zoom_in(this_, factor, &p);
688 this_->vehicle->follow_curr=this_->vehicle->follow;
690 navit_zoom_in(this_, factor, NULL);
694 navit_zoom_out_cursor(struct navit *this_, int factor)
697 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
698 navit_zoom_out(this_, 2, &p);
699 this_->vehicle->follow_curr=this_->vehicle->follow;
701 navit_zoom_out(this_, 2, NULL);
705 navit_cmd_zoom_in(struct navit *this_)
707 navit_zoom_in_cursor(this_, 2);
712 navit_cmd_zoom_out(struct navit *this_)
714 navit_zoom_out_cursor(this_, 2);
720 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
722 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
723 navit_say(this, in[0]->u.str);
726 static GHashTable *cmd_int_var_hash = NULL;
727 static GHashTable *cmd_attr_var_hash = NULL;
730 * Store key value pair for the command system (for int typed values)
732 * @param navit The navit instance
733 * @param function unused (needed to match command function signiture)
734 * @param in input attributes in[0] is the key string, in[1] is the integer value to store
735 * @param out output attributes, unused
736 * @param valid unused
740 navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
744 if(!cmd_int_var_hash) {
745 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
748 if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
749 (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) {
750 val = g_new(struct attr,1);
751 attr_dup_content(in[1],val);
752 key = g_strdup(in[0]->u.str);
753 g_hash_table_insert(cmd_int_var_hash, key, val);
759 * Store key value pair for the command system (for attr typed values, can be used as opaque handles)
761 * @param navit The navit instance
762 * @param function unused (needed to match command function signiture)
763 * @param in input attributes in[0] is the key string, in[1] is the attr* value to store
764 * @param out output attributes, unused
765 * @param valid unused
768 //TODO free stored attributes on navit_destroy
770 navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
774 if(!cmd_attr_var_hash) {
775 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
778 if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
780 val = attr_dup(in[1]);
782 key = g_strdup(in[0]->u.str);
783 g_hash_table_insert(cmd_attr_var_hash, key, val);
790 * command to toggle the active state of a named layer of the current layout
792 * @param navit The navit instance
793 * @param function unused (needed to match command function signiture)
794 * @param in input attribute in[0] is the name of the layer
795 * @param out output unused
796 * @param valid unused
800 navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
802 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
803 if(this->layout_current && this->layout_current->layers) {
804 GList* layers = this->layout_current->layers;
806 struct layer*l=layers->data;
807 if(l && !strcmp(l->name,in[0]->u.str) ) {
812 layers=g_list_next(layers);
819 * adds an item with the current coordinate of the vehicle to a named map
821 * @param navit The navit instance
822 * @param function unused (needed to match command function signiture)
823 * @param in input attribute in[0] is the name of the map
824 * @param out output attribute, 0 on error or the id of the created item on success
825 * @param valid unused
829 navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
831 struct attr **list = g_new0(struct attr *,2);
832 struct attr*val = g_new0(struct attr,1);
834 struct map_selection sel;
835 const int selection_range = 10;
836 enum item_type item_type;
838 struct map* curr_map = NULL;
839 struct coord curr_coord;
842 val->type = attr_type_item_begin;
843 val->u.item = NULL; //return invalid item on error
848 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
849 in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
852 if(!(ms=navit_get_mapset(this))) {
856 if((item_type = item_from_name(in[1]->u.str))==type_none) {
860 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
862 //no map with the given name found
867 if(this->vehicle && this->vehicle->vehicle ) {
868 struct attr pos_attr;
869 if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) {
870 transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
880 sel.range.min=type_none;
881 sel.range.max=type_tec_common;
882 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
883 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
884 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
885 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
887 mr = map_rect_new(curr_map, &sel);
889 it = map_rect_create_item( mr, item_type);
890 item_coord_set(it,&curr_coord, 1, change_mode_modify);
893 map_rect_destroy(mr);
898 * sets an attribute (name value pair) of a map item specified by map name and item id
900 * @param navit The navit instance
901 * @param function unused (needed to match command function signiture)
902 * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
903 * @param out output attribute, 0 on error, 1 on success
904 * @param valid unused
908 navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
911 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str &&//map name
912 in[1] && ATTR_IS_ITEM(in[1]->type) && //item
913 in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
914 in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
916 struct attr attr_to_set;
917 struct map* curr_map = NULL;
919 struct map_selection sel;
920 const int selection_range = 500;
921 struct coord curr_coord;
924 if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) {
925 attr_to_set.u.str = in[3]->u.str;
926 attr_to_set.type = attr_from_name(in[2]->u.str);
928 else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) {
929 attr_to_set.u.num = atoi(in[3]->u.str);
930 attr_to_set.type = attr_from_name(in[2]->u.str);
932 else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) {
933 double* val = g_new0(double,1);
934 *val = atof(in[3]->u.str);
935 attr_to_set.u.numd = val;
936 attr_to_set.type = attr_from_name(in[2]->u.str);
939 ms = navit_get_mapset(this);
941 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
948 sel.range.min=type_none;
949 sel.range.max=type_tec_common;
950 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
951 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
952 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
953 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
957 item_attr_set(it, &attr_to_set, change_mode_modify);
963 * Get attr variable given a key string for the command system (for opaque usage)
965 * @param navit The navit instance
966 * @param function unused (needed to match command function signiture)
967 * @param in input attribute in[0] is the key string
968 * @param out output attribute, the attr for the given key string if exists or NULL
969 * @param valid unused
973 navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
975 struct attr **list = g_new0(struct attr *,2);
976 if(!cmd_int_var_hash) {
977 struct attr*val = g_new0(struct attr,1);
978 val->type = attr_type_item_begin;
982 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
983 struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
988 struct attr*val = g_new0(struct attr,1);
989 val->type = attr_type_int_begin;
1000 * Get value given a key string for the command system
1002 * @param navit The navit instance
1003 * @param function unused (needed to match command function signiture)
1004 * @param in input attribute in[0] is the key string
1005 * @param out output attribute, the value for the given key string if exists or 0
1006 * @param valid unused
1010 navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1012 struct attr **list = g_new0(struct attr *,2);
1013 if(!cmd_int_var_hash) {
1014 struct attr*val = g_new0(struct attr,1);
1015 val->type = attr_type_int_begin;
1019 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
1020 struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
1025 struct attr*val = g_new0(struct attr,1);
1026 val->type = attr_type_int_begin;
1035 GList *cmd_int_var_stack = NULL;
1038 * Push an integer to the stack for the command system
1040 * @param navit The navit instance
1041 * @param function unused (needed to match command function signiture)
1042 * @param in input attribute in[0] is the integer attibute to push
1043 * @param out output attributes, unused
1044 * @param valid unused
1048 navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1050 if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) {
1051 struct attr*val = g_new(struct attr,1);
1052 attr_dup_content(in[0],val);
1053 cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
1058 * Pop an integer from the command system's integer stack
1060 * @param navit The navit instance
1061 * @param function unused (needed to match command function signiture)
1062 * @param in input attributes unused
1063 * @param out output attribute, the value popped if stack isn't empty or 0
1064 * @param valid unused
1068 navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1070 struct attr **list = g_new0(struct attr *,2);
1071 if(!cmd_int_var_stack) {
1072 struct attr*val = g_new0(struct attr,1);
1073 val->type = attr_type_int_begin;
1078 list[0] = cmd_int_var_stack->data;
1079 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1086 * Get current size of command system's integer stack
1088 * @param navit The navit instance
1089 * @param function unused (needed to match command function signiture)
1090 * @param in input attributes unused
1091 * @param out output attribute, the size of stack
1092 * @param valid unused
1096 navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1099 struct attr *attr = g_new0(struct attr ,1);
1100 attr->type = attr_type_int_begin;
1101 if(!cmd_int_var_stack) {
1105 attr->u.num = g_list_length(cmd_int_var_stack);
1107 list = g_new0(struct attr *,2);
1111 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1115 navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1118 char *description=NULL;
1123 pc.pro = transform_get_projection(this->trans);
1124 if (ATTR_IS_COORD(in[0]->type)) {
1125 pc.x=in[0]->u.coord->x;
1126 pc.y=in[0]->u.coord->y;
1128 } else if (ATTR_IS_PCOORD(in[0]->type)) {
1129 pc=*in[0]->u.pcoord;
1131 } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
1132 pc.pro=in[0]->u.num;
1136 } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
1142 if (in[0] && ATTR_IS_STRING(in[0]->type))
1143 description=in[0]->u.str;
1144 navit_set_destination(this, &pc, description, 1);
1148 navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1151 attr.type=attr_type_string_begin;
1152 attr.u.str="Fix me";
1154 *out=attr_generic_add_attr(*out, &attr);
1158 static struct command_table commands[] = {
1159 {"zoom_in",command_cast(navit_cmd_zoom_in)},
1160 {"zoom_out",command_cast(navit_cmd_zoom_out)},
1161 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
1162 {"say",command_cast(navit_cmd_say)},
1163 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
1164 {"set_destination",command_cast(navit_cmd_set_destination)},
1165 {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
1166 {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
1167 {"set_int_var",command_cast(navit_cmd_set_int_var)},
1168 {"get_int_var",command_cast(navit_cmd_get_int_var)},
1169 {"push_int",command_cast(navit_cmd_push_int)},
1170 {"pop_int",command_cast(navit_cmd_pop_int)},
1171 {"int_stack_size",command_cast(navit_cmd_int_stack_size)},
1172 {"toggle_layer",command_cast(navit_cmd_toggle_layer)},
1173 {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)},
1174 {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
1175 {"set_attr_var",command_cast(navit_cmd_set_attr_var)},
1176 {"get_attr_var",command_cast(navit_cmd_get_attr_var)},
1180 navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
1182 command_add_table(this_->attr_cbl, commands, count, this_);
1186 navit_new(struct attr *parent, struct attr **attrs)
1188 struct navit *this_=g_new0(struct navit, 1);
1189 struct pcoord center;
1192 enum projection pro=projection_mg;
1197 this_->self.type=attr_navit;
1198 this_->self.u.navit=this_;
1199 this_->attr_cbl=callback_list_new();
1201 this_->orientation=-1;
1202 this_->tracking_flag=1;
1203 this_->recentdest_count=10;
1204 this_->osd_configuration=-1;
1206 this_->center_timeout = 10;
1207 this_->use_mousewheel = 1;
1208 this_->autozoom_secs = 10;
1209 this_->autozoom_min = 7;
1210 this_->autozoom_active = 0;
1211 this_->zoom_min = 1;
1212 this_->zoom_max = 2097152;
1213 this_->follow_cursor = 1;
1217 this_->trans = transform_new();
1218 this_->trans_cursor = transform_new();
1219 transform_from_geo(pro, &g, &co);
1224 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
1226 this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
1230 for (;*attrs; attrs++) {
1231 navit_set_attr_do(this_, *attrs, 1);
1233 this_->displaylist=graphics_displaylist_new();
1234 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
1236 this_->messages = messagelist_new(attrs);
1242 navit_set_gui(struct navit *this_, struct gui *gui)
1247 if (gui_has_main_loop(this_->gui)) {
1248 if (! main_loop_gui) {
1249 main_loop_gui=this_->gui;
1251 dbg(0,"gui with main loop already active, ignoring this instance");
1259 navit_add_message(struct navit *this_, char *message)
1261 message_new(this_->messages, message);
1265 *navit_get_messages(struct navit *this_)
1267 return message_get(this_->messages);
1271 navit_set_graphics(struct navit *this_, struct graphics *gra)
1276 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
1277 graphics_add_callback(gra, this_->resize_callback);
1278 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
1279 graphics_add_callback(gra, this_->button_callback);
1280 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
1281 graphics_add_callback(gra, this_->motion_callback);
1282 this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
1283 graphics_add_callback(gra, this_->predraw_callback);
1288 navit_get_graphics(struct navit *this_)
1293 struct vehicleprofile *
1294 navit_get_vehicleprofile(struct navit *this_)
1296 return this_->vehicleprofile;
1300 navit_get_vehicleprofiles(struct navit *this_)
1302 return this_->vehicleprofiles;
1306 navit_projection_set(struct navit *this_, enum projection pro, int draw)
1311 c=transform_center(this_->trans);
1312 transform_to_geo(transform_get_projection(this_->trans), c, &g);
1313 transform_set_projection(this_->trans, pro);
1314 transform_from_geo(pro, &g, c);
1320 * Start the route computing to a given set of coordinates
1322 * @param navit The navit instance
1323 * @param c The coordinate to start routing to
1324 * @param description A label which allows the user to later identify this destination in the former destinations selection
1328 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
1330 char *destination_file;
1332 this_->destination=*c;
1333 this_->destination_valid=1;
1335 dbg(1, "navit->navit_set_destination %i\n", c->x);
1336 dbg(1, "navit->navit_set_destination %i\n", c->y);
1339 this_->destination_valid=0;
1340 destination_file = bookmarks_get_destination_file(TRUE);
1341 bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
1342 g_free(destination_file);
1343 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1345 route_set_destination(this_->route, c, async);
1347 if (this_->ready == 3)
1353 * Start the route computing to a given set of coordinates including waypoints
1355 * @param navit The navit instance
1356 * @param c The coordinate to start routing to
1357 * @param description A label which allows the user to later identify this destination in the former destinations selection
1361 navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
1363 char *destination_file;
1365 this_->destination=c[count-1];
1366 this_->destination_valid=1;
1368 this_->destination_valid=0;
1369 destination_file = bookmarks_get_destination_file(TRUE);
1370 bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
1371 g_free(destination_file);
1372 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1374 route_set_destinations(this_->route, c, count, async);
1376 if (this_->ready == 3)
1382 * @brief Checks if a route is calculated
1384 * This function checks if a route is calculated.
1386 * @param this_ The navit struct whose route should be checked.
1387 * @return True if the route is set, false otherwise.
1390 navit_check_route(struct navit *this_)
1393 return route_get_path_set(this_->route);
1400 navit_former_destinations_active(struct navit *this_)
1402 char *destination_file = bookmarks_get_destination_file(FALSE);
1406 f=fopen(destination_file,"r");
1408 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
1412 g_free(destination_file);
1417 navit_add_former_destinations_from_file(struct navit *this_)
1419 char *destination_file = bookmarks_get_destination_file(FALSE);
1420 struct attr *attrs[4];
1421 struct map_rect *mr;
1423 int i,valid=0,count=0;
1425 struct pcoord pc[16];
1431 parent.type=attr_navit;
1432 parent.u.navit=this_;
1434 type.type=attr_type;
1435 type.u.str="textfile";
1437 data.type=attr_data;
1438 data.u.str=destination_file;
1440 flags.type=attr_flags;
1443 attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL;
1445 this_->former_destination=map_new(&parent, attrs);
1446 g_free(destination_file);
1447 if (!this_->route || !navit_former_destinations_active(this_))
1449 mr=map_rect_new(this_->former_destination, NULL);
1450 while ((item=map_rect_get_item(mr))) {
1451 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16)))
1454 map_rect_destroy(mr);
1455 if (valid && count > 0) {
1456 for (i = 0 ; i < count ; i++) {
1457 pc[i].pro=map_projection(this_->former_destination);
1462 route_set_destination(this_->route, &pc[0], 1);
1464 route_set_destinations(this_->route, pc, count, 1);
1465 this_->destination=pc[count-1];
1466 this_->destination_valid=1;
1472 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1477 if (this_->textfile_debug_log && this_->vehicle) {
1478 str1=g_strdup_vprintf(fmt, ap);
1479 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1480 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1488 navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
1493 if (this_->textfile_debug_log && this_->vehicle) {
1494 str1=g_strdup_vprintf(fmt, ap);
1495 str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
1496 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1504 navit_say(struct navit *this_, char *text)
1507 speech_say(this_->speech, text);
1512 * @brief Toggles the navigation announcer for navit
1513 * @param this_ The navit object
1516 navit_cmd_announcer_toggle(struct navit *this_)
1518 struct attr attr, speechattr;
1520 // search for the speech attribute
1521 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1523 // find out if the corresponding attribute attr_active has been set
1524 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1526 attr.u.num = !attr.u.num;
1528 // otherwise disable it because voice is enabled by default
1529 attr.type = attr_active;
1533 // apply the new state
1534 if(!speech_set_attr(speechattr.u.speech, &attr))
1537 // announce that the speech attribute has changed
1538 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1542 navit_speak(struct navit *this_)
1544 struct navigation *nav=this_->navigation;
1545 struct map *map=NULL;
1546 struct map_rect *mr=NULL;
1550 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1552 dbg(1, "this_.speech->active %i\n", attr.u.num);
1557 map=navigation_get_map(nav);
1559 mr=map_rect_new(map, NULL);
1561 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1562 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1563 speech_say(this_->speech, attr.u.str);
1564 navit_add_message(this_, attr.u.str);
1565 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1567 map_rect_destroy(mr);
1572 navit_window_roadbook_update(struct navit *this_)
1574 struct navigation *nav=this_->navigation;
1575 struct map *map=NULL;
1576 struct map_rect *mr=NULL;
1579 struct param_list param[5];
1583 datawindow_mode(this_->roadbook_window, 1);
1585 map=navigation_get_map(nav);
1587 mr=map_rect_new(map, NULL);
1588 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1590 dbg(0,"while loop\n");
1591 while ((item=map_rect_get_item(mr))) {
1592 dbg(0,"item=%p\n", item);
1594 if (item->type != type_nav_position) {
1595 item_attr_get(item, attr_navigation_long, &attr);
1596 if (attr.u.str == NULL) {
1599 dbg(2, "Command='%s'\n", attr.u.str);
1600 param[0].value=g_strdup(attr.u.str);
1602 param[0].value=_("Position");
1603 param[0].name=_("Command");
1605 item_attr_get(item, attr_length, &attr);
1606 dbg(2, "Length=%d\n", attr.u.num);
1607 param[1].name=_("Length");
1609 if ( attr.u.num >= 2000 )
1611 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1615 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1618 item_attr_get(item, attr_time, &attr);
1619 dbg(2, "Time=%d\n", attr.u.num);
1621 param[2].name=_("Time");
1624 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1628 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1631 item_attr_get(item, attr_destination_length, &attr);
1632 dbg(2, "Destlength=%d\n", attr.u.num);
1633 param[3].name=_("Destination Length");
1634 if ( attr.u.num >= 2000 )
1636 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1640 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1643 item_attr_get(item, attr_destination_time, &attr);
1644 dbg(2, "Desttime=%d\n", attr.u.num);
1646 param[4].name=_("Destination Time");
1649 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1653 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1655 datawindow_add(this_->roadbook_window, param, 5);
1657 map_rect_destroy(mr);
1659 datawindow_mode(this_->roadbook_window, 0);
1663 navit_window_roadbook_destroy(struct navit *this_)
1666 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1667 this_->roadbook_window=NULL;
1668 this_->roadbook_callback=NULL;
1671 navit_window_roadbook_new(struct navit *this_)
1673 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1677 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1678 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1679 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1680 navit_window_roadbook_update(this_);
1684 navit_init(struct navit *this_)
1691 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1693 if (!this_->gui && !(this_->flags & 2)) {
1695 navit_destroy(this_);
1698 if (!this_->gra && !(this_->flags & 1)) {
1699 dbg(0,"no graphics\n");
1700 navit_destroy(this_);
1703 dbg(2,"Connecting gui to graphics\n");
1704 if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
1705 struct attr attr_type_gui, attr_type_graphics;
1706 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1707 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1708 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1709 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1710 dbg(0," for explanations and solutions\n");
1712 navit_destroy(this_);
1715 if (this_->speech && this_->navigation) {
1717 speech.type=attr_speech;
1718 speech.u.speech=this_->speech;
1719 navigation_set_attr(this_->navigation, &speech);
1721 dbg(2,"Initializing graphics\n");
1722 dbg(2,"Setting Vehicle\n");
1723 navit_set_vehicle(this_, this_->vehicle);
1724 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1725 if (this_->mapsets) {
1726 struct mapset_handle *msh;
1727 ms=this_->mapsets->data;
1728 this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
1729 msh=mapset_open(ms);
1730 while (msh && (map=mapset_next(msh, 0))) {
1731 map_add_callback(map, this_->progress_cb);
1736 if ((map=route_get_map(this_->route))) {
1738 map_a.type=attr_map;
1740 mapset_add_attr(ms, &map_a);
1742 if ((map=route_get_graph_map(this_->route))) {
1743 struct attr map_a,active;
1744 map_a.type=attr_map;
1746 active.type=attr_active;
1748 mapset_add_attr(ms, &map_a);
1749 map_set_attr(map, &active);
1751 route_set_mapset(this_->route, ms);
1752 route_set_projection(this_->route, transform_get_projection(this_->trans));
1754 if (this_->tracking) {
1755 tracking_set_mapset(this_->tracking, ms);
1757 tracking_set_route(this_->tracking, this_->route);
1759 if (this_->navigation) {
1760 if ((map=navigation_get_map(this_->navigation))) {
1761 struct attr map_a,active;
1762 map_a.type=attr_map;
1764 active.type=attr_active;
1766 mapset_add_attr(ms, &map_a);
1767 map_set_attr(map, &active);
1770 if (this_->tracking) {
1771 if ((map=tracking_get_map(this_->tracking))) {
1772 struct attr map_a,active;
1773 map_a.type=attr_map;
1775 active.type=attr_active;
1777 mapset_add_attr(ms, &map_a);
1778 map_set_attr(map, &active);
1781 navit_add_former_destinations_from_file(this_);
1784 struct attr callback;
1785 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1786 callback.type=attr_callback;
1787 callback.u.callback=this_->route_cb;
1788 route_add_attr(this_->route, &callback);
1790 if (this_->navigation) {
1791 if (this_->speech) {
1792 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1793 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1796 navigation_set_route(this_->navigation, this_->route);
1798 dbg(2,"Setting Center\n");
1799 center_file = bookmarks_get_center_file(FALSE);
1800 bookmarks_set_center_from_file(this_->bookmarks, center_file);
1801 g_free(center_file);
1803 if (this_->menubar) {
1804 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1806 navit_add_menu_windows_items(this_, men);
1812 navit_window_roadbook_new(this_);
1813 navit_window_items_new(this_);
1816 messagelist_init(this_->messages);
1818 navit_set_cursors(this_);
1820 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1821 callback=(this_->ready == 2);
1823 dbg(2,"ready=%d\n",this_->ready);
1824 if (this_->ready == 3)
1825 navit_draw_async(this_, 1);
1827 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
1829 routech_test(this_);
1834 navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
1839 c.x=(r->rl.x+r->lu.x)/2;
1840 c.y=(r->rl.y+r->lu.y)/2;
1841 transform_set_center(this_->trans, &c);
1842 dbg(1,"%x,%x-%x,%x\n", r->rl.x,r->rl.y,r->lu.x,r->lu.y);
1843 while (scale < 1<<20) {
1845 transform_set_scale(this_->trans, scale);
1846 transform_setup_source_rect(this_->trans);
1847 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
1848 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
1849 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1850 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1851 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1857 if (this_->ready == 3)
1858 navit_draw_async(this_,0);
1862 navit_zoom_to_route(struct navit *this_, int orientation)
1865 struct map_rect *mr=NULL;
1868 struct coord_rect r;
1873 map=route_get_map(this_->route);
1874 dbg(1,"map=%p\n",map);
1876 mr=map_rect_new(map, NULL);
1877 dbg(1,"mr=%p\n",mr);
1879 while ((item=map_rect_get_item(mr))) {
1880 dbg(1,"item=%s\n", item_to_name(item->type));
1881 while (item_coord_get(item, &c, 1)) {
1886 coord_rect_extend(&r, &c);
1890 map_rect_destroy(mr);
1894 if (orientation != -1)
1895 transform_set_yaw(this_->trans, orientation);
1896 navit_zoom_to_rect(this_, &r);
1900 navit_cmd_zoom_to_route(struct navit *this)
1902 navit_zoom_to_route(this, 0);
1907 * Change the current zoom level
1909 * @param navit The navit instance
1910 * @param center The point where to center the map, including its projection
1914 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
1916 struct coord *c=transform_center(this_->trans);
1918 enum projection pro = transform_get_projection(this_->trans);
1919 if (pro != center->pro) {
1922 transform_from_to(&c1, center->pro, &c2, pro);
1929 navit_set_timeout(this_);
1930 if (this_->ready == 3)
1935 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
1939 transform_set_center(this_->trans, c);
1940 transform_get_size(this_->trans, &width, &height);
1943 update_transformation(this_->trans, &po, p, NULL);
1945 navit_set_timeout(this_);
1949 * Links all vehicles to a cursor depending on the current profile.
1951 * @param this_ A navit instance
1952 * @author Ralph Sennhauser (10/2009)
1955 navit_set_cursors(struct navit *this_)
1958 struct navit_vehicle *nv;
1962 v=g_list_first(this_->vehicles); // GList of navit_vehicles
1965 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
1966 if (!strcmp(name.u.str,"none"))
1969 c=layout_get_cursor(this_->layout_current, name.u.str);
1971 c=layout_get_cursor(this_->layout_current, "default");
1972 vehicle_set_cursor(nv->vehicle, c, 0);
1979 navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
1982 struct navit_vehicle *nv=this_->vehicle;
1984 float offset=this_->radius; // Cursor offset from the center of the screen (percent).
1985 #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 */
1986 float min_offset = 0.; // Percent offset at min_offset_speed.
1987 float max_offset = 30.; // Percent offset at max_offset_speed.
1988 int min_offset_speed = 2; // Speed in km/h
1989 int max_offset_speed = 50; // Speed ini km/h
1990 // Calculate cursor offset from the center of the screen, upon speed.
1991 if (nv->speed <= min_offset_speed) {
1992 offset = min_offset;
1993 } else if (nv->speed > max_offset_speed) {
1994 offset = max_offset;
1996 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
2000 transform_get_size(this_->trans, &width, &height);
2001 if (this_->orientation == -1 || keep_orientation) {
2003 p->y=(50 + offset)*height/100;
2005 *dir=keep_orientation?this_->orientation:nv->dir;
2008 if (this_->tracking && this_->tracking_flag) {
2009 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
2011 mdir=nv->dir-this_->orientation;
2014 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
2015 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
2017 *dir=this_->orientation;
2023 navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
2027 struct navit_vehicle *nv=this_->vehicle;
2028 navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
2029 transform_set_yaw(this_->trans, dir);
2030 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
2032 navit_autozoom(this_, &nv->coord, nv->speed, 0);
2036 navit_set_center_cursor_draw(struct navit *this_)
2038 navit_set_center_cursor(this_,1,0);
2039 if (this_->ready == 3)
2040 navit_draw_async(this_, 1);
2044 navit_cmd_set_center_cursor(struct navit *this_)
2046 navit_set_center_cursor_draw(this_);
2050 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
2054 transform_reverse(this_->trans, p, &c);
2057 pc.pro = transform_get_projection(this_->trans);
2058 navit_set_center(this_, &pc, set_timeout);
2062 switch((*attrs)->type) {
2064 zoom=(*attrs)->u.num;
2067 g=*((*attrs)->u.coord_geo);
2072 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
2074 int dir=0, orient_old=0, attr_updated=0;
2078 struct navit_vehicle *nv;
2081 active.type=attr_active;
2084 switch (attr->type) {
2086 attr_updated=(this_->autozoom_secs != attr->u.num);
2087 this_->autozoom_secs = attr->u.num;
2089 case attr_autozoom_active:
2090 attr_updated=(this_->autozoom_active != attr->u.num);
2091 this_->autozoom_active = attr->u.num;
2094 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
2095 dbg(1,"0x%x,0x%x\n",co.x,co.y);
2096 transform_set_center(this_->trans, &co);
2098 case attr_drag_bitmap:
2099 attr_updated=(this_->drag_bitmap != !!attr->u.num);
2100 this_->drag_bitmap=!!attr->u.num;
2103 attr_updated=(this_->flags != attr->u.num);
2104 this_->flags=attr->u.num;
2106 case attr_flags_graphics:
2107 attr_updated=(this_->graphics_flags != attr->u.num);
2108 this_->graphics_flags=attr->u.num;
2111 if (!this_->vehicle)
2113 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
2114 this_->vehicle->follow_curr = attr->u.num;
2117 if(this_->layout_current!=attr->u.layout) {
2118 this_->layout_current=attr->u.layout;
2119 graphics_font_destroy_all(this_->gra);
2120 navit_set_cursors(this_);
2121 if (this_->ready == 3)
2126 case attr_layout_name:
2130 if (!strcmp(lay->name,attr->u.str)) {
2132 attr.type=attr_layout;
2134 return navit_set_attr_do(this_, &attr, init);
2139 case attr_map_border:
2140 if (this_->border != attr->u.num) {
2141 this_->border=attr->u.num;
2145 case attr_orientation:
2146 orient_old=this_->orientation;
2147 this_->orientation=attr->u.num;
2149 if (this_->orientation != -1) {
2150 dir = this_->orientation;
2152 if (this_->vehicle) {
2153 dir = this_->vehicle->dir;
2156 transform_set_yaw(this_->trans, dir);
2157 if (orient_old != this_->orientation) {
2159 if (this_->ready == 3)
2166 case attr_osd_configuration:
2167 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
2168 attr_updated=(this_->osd_configuration != attr->u.num);
2169 this_->osd_configuration=attr->u.num;
2172 attr_updated=(this_->pitch != attr->u.num);
2173 this_->pitch=attr->u.num;
2174 transform_set_pitch(this_->trans, this_->pitch);
2175 if (!init && attr_updated && this_->ready == 3)
2178 case attr_projection:
2179 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
2180 navit_projection_set(this_, attr->u.projection, !init);
2185 attr_updated=(this_->radius != attr->u.num);
2186 this_->radius=attr->u.num;
2188 case attr_recent_dest:
2189 attr_updated=(this_->recentdest_count != attr->u.num);
2190 this_->recentdest_count=attr->u.num;
2193 if(this_->speech && this_->speech != attr->u.speech) {
2195 this_->speech = attr->u.speech;
2199 attr_updated=(this_->center_timeout != attr->u.num);
2200 this_->center_timeout = attr->u.num;
2203 attr_updated=(this_->tracking_flag != !!attr->u.num);
2204 this_->tracking_flag=!!attr->u.num;
2206 case attr_transformation:
2207 this_->trans=attr->u.transformation;
2209 case attr_use_mousewheel:
2210 attr_updated=(this_->use_mousewheel != !!attr->u.num);
2211 this_->use_mousewheel=!!attr->u.num;
2217 if (nv->vehicle == attr->u.vehicle) {
2218 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
2220 vehicle_set_attr(this_->vehicle->vehicle, &active);
2222 vehicle_set_attr(nv->vehicle, &active);
2225 navit_set_vehicle(this_, nv);
2231 zoom=transform_get_scale(this_->trans);
2232 attr_updated=(zoom != attr->u.num);
2233 transform_set_scale(this_->trans, attr->u.num);
2234 if (attr_updated && !init)
2238 attr_updated=(attr->u.num != this_->zoom_min);
2239 this_->zoom_min=attr->u.num;
2242 attr_updated=(attr->u.num != this_->zoom_max);
2243 this_->zoom_max=attr->u.num;
2246 navit_add_message(this_, attr->u.str);
2248 case attr_follow_cursor:
2249 attr_updated=(this_->follow_cursor != !!attr->u.num);
2250 this_->follow_cursor=!!attr->u.num;
2253 attr_updated=(this_->imperial != attr->u.num);
2254 this_->imperial=attr->u.num;
2259 if (attr_updated && !init) {
2260 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2261 if (attr->type == attr_osd_configuration)
2262 graphics_draw_mode(this_->gra, draw_mode_end);
2268 navit_set_attr(struct navit *this_, struct attr *attr)
2270 return navit_set_attr_do(this_, attr, 0);
2274 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
2276 struct message *msg;
2282 msg = navit_get_messages(this_);
2290 len += strlen(msg->text) + 1;
2293 attr->u.str = g_malloc(len + 1);
2295 msg = navit_get_messages(this_);
2298 g_stpcpy((attr->u.str + offset), msg->text);
2299 offset += strlen(msg->text);
2300 attr->u.str[offset] = '\n';
2306 attr->u.str[len] = '\0';
2309 attr->u.num=this_->imperial;
2311 case attr_bookmark_map:
2312 attr->u.map=bookmarks_get_map(this_->bookmarks);
2314 case attr_bookmarks:
2315 attr->u.bookmarks=this_->bookmarks;
2317 case attr_callback_list:
2318 attr->u.callback_list=this_->attr_cbl;
2320 case attr_destination:
2321 if (! this_->destination_valid)
2323 attr->u.pcoord=&this_->destination;
2325 case attr_displaylist:
2326 attr->u.displaylist=this_->displaylist;
2327 return (attr->u.displaylist != NULL);
2329 if (!this_->vehicle)
2331 attr->u.num=this_->vehicle->follow_curr;
2333 case attr_former_destination_map:
2334 attr->u.map=this_->former_destination;
2337 attr->u.graphics=this_->gra;
2338 ret=(attr->u.graphics != NULL);
2341 attr->u.gui=this_->gui;
2342 ret=(attr->u.gui != NULL);
2347 iter->u.list=g_list_next(iter->u.list);
2349 iter->u.list=this_->layouts;
2353 attr->u.layout=(struct layout *)iter->u.list->data;
2355 attr->u.layout=this_->layout_current;
2359 if (iter && this_->mapsets) {
2360 if (!iter->u.mapset_handle) {
2361 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
2363 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
2365 mapset_close(iter->u.mapset_handle);
2373 attr->u.mapset=this_->mapsets->data;
2374 ret=(attr->u.mapset != NULL);
2376 case attr_navigation:
2377 attr->u.navigation=this_->navigation;
2379 case attr_orientation:
2380 attr->u.num=this_->orientation;
2382 case attr_osd_configuration:
2383 attr->u.num=this_->osd_configuration;
2386 attr->u.num=transform_get_pitch(this_->trans);
2388 case attr_projection:
2390 attr->u.num=transform_get_projection(this_->trans);
2396 attr->u.route=this_->route;
2399 attr->u.speech=this_->speech;
2402 attr->u.num=this_->tracking_flag;
2404 case attr_trackingo:
2405 attr->u.tracking=this_->tracking;
2407 case attr_transformation:
2408 attr->u.transformation=this_->trans;
2413 iter->u.list=g_list_next(iter->u.list);
2415 iter->u.list=this_->vehicles;
2419 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
2421 if(this_->vehicle) {
2422 attr->u.vehicle=this_->vehicle->vehicle;
2428 case attr_vehicleprofile:
2429 attr->u.vehicleprofile=this_->vehicleprofile;
2432 attr->u.num=transform_get_scale(this_->trans);
2434 case attr_autozoom_active:
2435 attr->u.num=this_->autozoom_active;
2437 case attr_follow_cursor:
2438 attr->u.num=this_->follow_cursor;
2448 navit_add_log(struct navit *this_, struct log *log)
2450 struct attr type_attr;
2451 if (!log_get_attr(log, attr_type, &type_attr, NULL))
2453 if (!strcmp(type_attr.u.str, "textfile_debug")) {
2454 char *header = "type=track_tracked\n";
2455 if (this_->textfile_debug_log)
2457 log_set_header(log, header, strlen(header));
2458 this_->textfile_debug_log=log;
2465 navit_add_layout(struct navit *this_, struct layout *layout)
2468 this_->layouts = g_list_append(this_->layouts, layout);
2469 layout_get_attr(layout, attr_active, &active, NULL);
2470 if(active.u.num || !this_->layout_current) {
2471 this_->layout_current=layout;
2478 navit_add_attr(struct navit *this_, struct attr *attr)
2481 switch (attr->type) {
2483 navit_add_callback(this_, attr->u.callback);
2486 ret=navit_add_log(this_, attr->u.log);
2489 ret=navit_set_gui(this_, attr->u.gui);
2492 ret=navit_set_graphics(this_, attr->u.graphics);
2495 ret=navit_add_layout(this_, attr->u.layout);
2498 this_->route=attr->u.route;
2501 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
2503 case attr_navigation:
2504 this_->navigation=attr->u.navigation;
2506 case attr_recent_dest:
2507 this_->recentdest_count = attr->u.num;
2510 this_->speech=attr->u.speech;
2513 this_->tracking=attr->u.tracking;
2516 ret=navit_add_vehicle(this_, attr->u.vehicle);
2518 case attr_vehicleprofile:
2519 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
2521 case attr_autozoom_min:
2522 this_->autozoom_min = attr->u.num;
2527 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2532 navit_remove_attr(struct navit *this_, struct attr *attr)
2535 switch (attr->type) {
2537 navit_remove_callback(this_, attr->u.callback);
2546 navit_attr_iter_new(void)
2548 return g_new0(struct attr_iter, 1);
2552 navit_attr_iter_destroy(struct attr_iter *iter)
2558 navit_add_callback(struct navit *this_, struct callback *cb)
2560 callback_list_add(this_->attr_cbl, cb);
2564 navit_remove_callback(struct navit *this_, struct callback *cb)
2566 callback_list_remove(this_->attr_cbl, cb);
2570 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
2572 * @param navit The navit instance
2577 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
2579 struct point cursor_pnt;
2580 enum projection pro;
2587 pro=transform_get_projection(this_->trans_cursor);
2590 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2592 vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
2597 pro=transform_get_projection(this_->trans);
2598 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2601 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2603 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2609 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2611 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2612 struct pcoord cursor_pc;
2613 struct point cursor_pnt, *pnt=&cursor_pnt;
2614 struct tracking *tracking=NULL;
2615 struct pcoord pc[16];
2616 enum projection pro=transform_get_projection(this_->trans_cursor);
2618 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2620 char *destination_file;
2623 if (this_->ready != 3) {
2624 profile(0,"return 1\n");
2627 navit_layout_switch(this_);
2628 if (this_->vehicle == nv && this_->tracking_flag)
2629 tracking=this_->tracking;
2631 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2632 attr_object=tracking;
2633 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2635 attr_object=nv->vehicle;
2636 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2638 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2639 if (!attr_valid.u.num != attr_position_valid_invalid)
2641 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2642 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2643 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2644 profile(0,"return 2\n");
2647 nv->dir=*attr_dir.u.numd;
2648 nv->speed=*attr_speed.u.numd;
2649 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2650 if (nv != this_->vehicle) {
2651 navit_vehicle_draw(this_, nv, NULL);
2652 profile(0,"return 3\n");
2655 cursor_pc.x = nv->coord.x;
2656 cursor_pc.y = nv->coord.y;
2657 cursor_pc.pro = pro;
2660 route_set_position_from_tracking(this_->route, tracking, pro);
2662 route_set_position(this_->route, &cursor_pc);
2664 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2665 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2666 if (this_->gui && nv->speed > 2)
2667 navit_disable_suspend();
2669 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2670 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
2671 (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
2672 navit_set_center_cursor_draw(this_);
2674 navit_vehicle_draw(this_, nv, pnt);
2676 if (nv->follow_curr > 1)
2679 nv->follow_curr=nv->follow;
2680 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2682 /* Finally, if we reached our destination, stop navigation. */
2684 switch(route_destination_reached(this_->route)) {
2686 route_remove_waypoint(this_->route);
2687 count=route_get_destinations(this_->route, pc, 16);
2688 destination_file = bookmarks_get_destination_file(TRUE);
2689 bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
2692 navit_set_destination(this_, NULL, NULL, 0);
2696 profile(0,"return 5\n");
2700 * Set the position of the vehicle
2702 * @param navit The navit instance
2703 * @param c The coordinate to set as position
2708 navit_set_position(struct navit *this_, struct pcoord *c)
2711 route_set_position(this_->route, c);
2712 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2714 if (this_->ready == 3)
2719 navit_set_vehicleprofile(struct navit *this_, char *name)
2723 l=this_->vehicleprofiles;
2725 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2726 if (!strcmp(attr.u.str, name)) {
2727 this_->vehicleprofile=l->data;
2729 route_set_profile(this_->route, this_->vehicleprofile);
2739 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2743 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2744 if (navit_set_vehicleprofile(this_, attr.u.str))
2747 if (!navit_set_vehicleprofile(this_,"car")) {
2748 /* We do not have a fallback "car" profile
2749 * so lets set any profile */
2751 l=this_->vehicleprofiles;
2753 this_->vehicleprofile=l->data;
2755 route_set_profile(this_->route, this_->vehicleprofile);
2761 * Register a new vehicle
2763 * @param navit The navit instance
2764 * @param v The vehicle instance
2765 * @returns 1 for success
2768 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2770 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2771 struct attr follow, active, animate;
2776 nv->animate_cursor=0;
2777 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2778 nv->follow=follow.u.num;
2779 nv->follow_curr=nv->follow;
2780 this_->vehicles=g_list_append(this_->vehicles, nv);
2781 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2782 navit_set_vehicle(this_, nv);
2783 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2784 nv->animate_cursor=animate.u.num;
2785 nv->callback.type=attr_callback;
2786 nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
2787 vehicle_add_attr(nv->vehicle, &nv->callback);
2788 vehicle_set_attr(nv->vehicle, &this_->self);
2796 navit_get_gui(struct navit *this_)
2801 struct transformation *
2802 navit_get_trans(struct navit *this_)
2804 return this_->trans;
2808 navit_get_route(struct navit *this_)
2810 return this_->route;
2814 navit_get_navigation(struct navit *this_)
2816 return this_->navigation;
2819 struct displaylist *
2820 navit_get_displaylist(struct navit *this_)
2822 return this_->displaylist;
2826 navit_layout_switch(struct navit *n)
2830 struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
2831 double trise,tset,trise_actual;
2833 int year, month, day;
2835 if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
2836 return; //No layout - nothing to switch
2840 l=layout_attr.u.layout;
2842 if (l->dayname || l->nightname) {
2843 //Ok, we know that we have profile to switch
2845 //Check that we aren't calculating too fast
2846 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
2847 currTs=iso8601_to_secs(iso8601_attr.u.str);
2848 dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
2850 if (currTs-(n->prevTs)<60) {
2851 //We've have to wait a little
2854 if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
2856 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
2857 return; //No valid fix yet
2859 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
2860 //No position - no sun
2864 //We calculate sunrise anyway, cause it is needed both for day and for night
2865 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2866 //near the pole sun never rises/sets, so we should never switch profiles
2867 dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
2873 dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
2876 if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
2877 (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
2878 //The sun is rising now!
2879 if (strcmp(l->name,l->dayname)) {
2880 navit_set_layout_by_name(n,l->dayname);
2885 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
2886 //near the pole sun never rises/sets, so we should never switch profiles
2887 dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
2891 dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
2892 if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
2893 || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
2894 ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
2896 if (strcmp(l->name,l->nightname)) {
2897 navit_set_layout_by_name(n,l->nightname);
2907 navit_set_vehicle_by_name(struct navit *n,const char *name)
2910 struct attr_iter *iter;
2911 struct attr vehicle_attr, name_attr;
2913 iter=navit_attr_iter_new();
2915 while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
2916 v=vehicle_attr.u.vehicle;
2917 vehicle_get_attr(v,attr_name,&name_attr,NULL);
2918 if (name_attr.type==attr_name) {
2919 if (!strcmp(name,name_attr.u.str)) {
2920 navit_set_attr(n,&vehicle_attr);
2921 navit_attr_iter_destroy(iter);
2926 navit_attr_iter_destroy(iter);
2931 navit_set_layout_by_name(struct navit *n,const char *name)
2934 struct attr_iter iter;
2935 struct attr layout_attr;
2939 if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
2940 return 0; //No layouts - nothing to do
2942 if (iter.u.list==NULL) {
2946 iter.u.list=g_list_first(iter.u.list);
2948 while(iter.u.list) {
2949 l=(struct layout*)iter.u.list->data;
2950 if (!strcmp(name,l->name)) {
2951 layout_attr.u.layout=l;
2952 layout_attr.type=attr_layout;
2953 navit_set_attr(n,&layout_attr);
2954 iter.u.list=g_list_first(iter.u.list);
2957 iter.u.list=g_list_next(iter.u.list);
2960 iter.u.list=g_list_first(iter.u.list);
2965 navit_disable_suspend() {
2966 gui_disable_suspend(global_navit->gui);
2967 callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
2971 navit_block(struct navit *this_, int block)
2974 this_->blocked |= 1;
2975 if (graphics_draw_cancel(this_->gra, this_->displaylist))
2976 this_->blocked |= 2;
2979 if ((this_->blocked & 2) || block < 0) {
2989 navit_destroy(struct navit *this_)
2992 callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
2994 /* TODO: destroy objects contained in this_ */
2996 vehicle_destroy(this_->vehicle->vehicle);
2997 if (this_->bookmarks) {
2998 char *center_file = bookmarks_get_center_file(TRUE);
2999 bookmarks_write_center_to_file(this_->bookmarks, center_file);
3000 g_free(center_file);
3001 bookmarks_destroy(this_->bookmarks);
3003 callback_destroy(this_->nav_speech_cb);
3004 callback_destroy(this_->roadbook_callback);
3005 callback_destroy(this_->popup_callback);
3006 callback_destroy(this_->motion_timeout_callback);
3008 graphics_remove_callback(this_->gra, this_->resize_callback);
3009 callback_destroy(this_->resize_callback);
3011 graphics_remove_callback(this_->gra, this_->button_callback);
3012 callback_destroy(this_->button_callback);
3014 graphics_remove_callback(this_->gra, this_->motion_callback);
3015 callback_destroy(this_->motion_callback);
3017 graphics_remove_callback(this_->gra, this_->predraw_callback);
3018 callback_destroy(this_->predraw_callback);
3019 route_destroy(this_->route);
3020 ms = navit_get_mapset(this_);
3023 graphics_free(this_->gra);