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"
69 #ifdef HAVE_API_WIN32_BASE
73 #ifdef HAVE_API_WIN32_CE
78 * @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
82 //! The navit_vehicule
83 struct navit_vehicle {
85 /*! Limit of the follow counter. See navit_add_vehicle */
87 /*! Deprecated : follow counter itself. When it reaches 'update' counts, map is recentered*/
91 struct coord last; /*< Position of the last update of this vehicle */
92 struct vehicle *vehicle;
102 struct layout *layout_current;
103 struct graphics *gra;
104 struct action *action;
105 struct transformation *trans, *trans_cursor;
106 struct compass *compass;
108 struct navigation *navigation;
109 struct speech *speech;
110 struct tracking *tracking;
113 struct displaylist *displaylist;
116 int recentdest_count;
117 int osd_configuration;
119 GList *windows_items;
120 struct navit_vehicle *vehicle;
121 struct callback_list *attr_cbl;
122 struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb, *progress_cb;
123 struct datawindow *roadbook_window;
124 struct map *former_destination;
125 struct point pressed, last, current;
126 int button_pressed,moved,popped,zoomed;
131 struct event_timeout *button_timeout, *motion_timeout;
132 struct callback *motion_timeout_callback;
134 int ignore_graphics_events;
135 struct log *textfile_debug_log;
136 struct pcoord destination;
137 int destination_valid;
142 struct messagelist *messages;
143 struct callback *resize_callback,*button_callback,*motion_callback,*predraw_callback;
144 struct vehicleprofile *vehicleprofile;
145 GList *vehicleprofiles;
150 int zoom_min, zoom_max;
152 struct bookmarks *bookmarks;
154 /* 1=No graphics ok */
158 struct attr **attr_list;
161 struct gui *main_loop_gui;
167 struct mapset_handle *mapset_handle;
171 static void navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv);
172 static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt);
173 static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
174 static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
175 static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir);
176 static void navit_set_cursors(struct navit *this_);
177 static void navit_cmd_zoom_to_route(struct navit *this);
178 static void navit_cmd_set_center_cursor(struct navit *this_);
179 static void navit_cmd_announcer_toggle(struct navit *this_);
180 static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
182 struct navit *global_navit;
185 navit_add_mapset(struct navit *this_, struct mapset *ms)
187 this_->mapsets = g_list_append(this_->mapsets, ms);
191 navit_get_mapset(struct navit *this_)
194 return this_->mapsets->data;
196 dbg(0,"No mapsets enabled! Is it on purpose? Navit can't draw a map. Please check your navit.xml\n");
202 navit_get_tracking(struct navit *this_)
204 return this_->tracking;
208 * @brief Get the user data directory.
209 * @param[in] create - create the directory if it does not exist
211 * @return char * to the data directory string.
213 * returns the directory used to store user data files (center.txt,
214 * destination.txt, bookmark.txt, ...)
218 navit_get_user_data_directory(int create) {
220 dir = getenv("NAVIT_USER_DATADIR");
221 if (create && !file_exists(dir)) {
222 dbg(0,"creating dir %s\n", dir);
223 if (file_mkdir(dir,0)) {
224 dbg(0,"failed creating dir %s\n", dir);
229 } /* end: navit_get_user_data_directory(gboolean create) */
233 navit_draw_async(struct navit *this_, int async)
236 if (this_->blocked) {
240 transform_setup_source_rect(this_->trans);
241 graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
245 navit_draw(struct navit *this_)
247 if (this_->ready == 3)
248 navit_draw_async(this_, 0);
252 navit_get_ready(struct navit *this_)
260 navit_draw_displaylist(struct navit *this_)
262 if (this_->ready == 3)
263 graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
267 navit_map_progress(struct navit *this_)
271 struct mapset_handle *msh;
274 if (this_->ready != 3)
279 ms=this_->mapsets->data;
281 while (msh && (map=mapset_next(msh, 0))) {
282 if (map_get_attr(map, attr_progress, &attr, NULL)) {
283 char *str=g_strdup_printf("%s ",attr.u.str);
284 graphics_draw_mode(this_->gra, draw_mode_begin);
285 graphics_draw_text_std(this_->gra, 16, str, &p);
288 graphics_draw_mode(this_->gra, draw_mode_end);
295 navit_redraw_route(struct navit *this_, struct route *route, struct attr *attr)
298 if (attr->type != attr_route_status)
301 if (this_->ready != 3)
303 if (updated != route_status_path_done_new)
305 if (this_->vehicle) {
306 if (this_->vehicle->follow_curr == 1)
308 if (this_->vehicle->follow_curr <= this_->vehicle->follow)
309 this_->vehicle->follow_curr=this_->vehicle->follow;
315 navit_handle_resize(struct navit *this_, int w, int h)
317 struct map_selection sel;
318 int callback=(this_->ready == 1);
320 memset(&sel, 0, sizeof(sel));
325 transform_set_screen_selection(this_->trans, &sel);
326 graphics_init(this_->gra);
327 graphics_set_rect(this_->gra, &sel.u.p_rect);
329 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
330 if (this_->ready == 3)
331 navit_draw_async(this_, 1);
335 navit_resize(void *data, int w, int h)
337 struct navit *this=data;
338 if (!this->ignore_graphics_events)
339 navit_handle_resize(this, w, h);
343 navit_get_width(struct navit *this_)
350 navit_get_height(struct navit *this_)
356 navit_popup(void *data)
358 struct navit *this_=data;
359 popup(this_, 1, &this_->pressed);
360 this_->button_timeout=NULL;
366 navit_ignore_button(struct navit *this_)
368 if (this_->ignore_button)
370 this_->ignore_button=1;
375 navit_ignore_graphics_events(struct navit *this_, int ignore)
377 this_->ignore_graphics_events=ignore;
381 update_transformation(struct transformation *tr, struct point *old, struct point *new, struct point *rot)
386 double angleo,anglen;
388 if (!transform_reverse(tr, old, &co))
391 angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
392 anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
393 yaw=transform_get_yaw(tr)+angleo-anglen;
394 transform_set_yaw(tr, yaw % 360);
396 if (!transform_reverse(tr, new, &cn))
398 cp=transform_get_center(tr);
401 dbg(1,"from 0x%x,0x%x to 0x%x,0x%x\n", cp->x, cp->y, c.x, c.y);
402 transform_set_center(tr, &c);
406 navit_set_timeout(struct navit *this_)
409 follow.type=attr_follow;
410 follow.u.num=this_->center_timeout;
411 navit_set_attr(this_, &follow);
415 navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
419 dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
420 callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
421 if (this_->ignore_button) {
422 this_->ignore_button=0;
430 this_->button_pressed=1;
434 this_->button_timeout=event_add_timeout(500, 0, popup_callback);
437 navit_set_center_screen(this_, p, 1);
439 popup(this_, button, p);
440 if (button == 4 && this_->use_mousewheel) {
442 navit_zoom_in(this_, 2, p);
444 if (button == 5 && this_->use_mousewheel) {
446 navit_zoom_out(this_, 2, p);
450 this_->button_pressed=0;
451 if (this_->button_timeout) {
452 event_remove_timeout(this_->button_timeout);
453 this_->button_timeout=NULL;
454 if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
455 navit_set_center_screen(this_, p, !this_->zoomed);
458 if (this_->motion_timeout) {
459 event_remove_timeout(this_->motion_timeout);
460 this_->motion_timeout=NULL;
467 update_transformation(this_->trans, &this_->pressed, p, &pr);
469 update_transformation(this_->trans, &this_->pressed, p, NULL);
471 graphics_draw_drag(this_->gra, NULL);
472 transform_copy(this_->trans, this_->trans_cursor);
473 graphics_overlay_disable(this_->gra, 0);
475 navit_set_timeout(this_);
484 navit_button(void *data, int pressed, int button, struct point *p)
486 struct navit *this=data;
487 dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
488 if (!this->ignore_graphics_events) {
489 if (! this->popup_callback)
490 this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
491 navit_handle_button(this, pressed, button, p, this->popup_callback);
497 navit_motion_timeout(struct navit *this_)
501 if (this_->drag_bitmap) {
503 point.x=(this_->current.x-this_->pressed.x);
504 point.y=(this_->current.y-this_->pressed.y);
505 if (graphics_draw_drag(this_->gra, &point)) {
506 graphics_overlay_disable(this_->gra, 1);
507 graphics_draw_mode(this_->gra, draw_mode_end);
509 this_->motion_timeout=NULL;
513 dx=(this_->current.x-this_->last.x);
514 dy=(this_->current.y-this_->last.y);
516 struct transformation *tr;
518 this_->last=this_->current;
519 graphics_overlay_disable(this_->gra, 1);
520 tr=transform_dup(this_->trans);
524 update_transformation(tr, &this_->pressed, &this_->current, &pr);
526 update_transformation(tr, &this_->pressed, &this_->current, NULL);
529 graphics_displaylist_move(this_->displaylist, dx, dy);
531 graphics_draw_cancel(this_->gra, this_->displaylist);
532 graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
533 transform_destroy(tr);
536 this_->motion_timeout=NULL;
541 navit_handle_motion(struct navit *this_, struct point *p)
545 if (this_->button_pressed && !this_->popped) {
546 dx=(p->x-this_->pressed.x);
547 dy=(p->y-this_->pressed.y);
548 if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
550 if (this_->button_timeout) {
551 event_remove_timeout(this_->button_timeout);
552 this_->button_timeout=NULL;
555 if (! this_->motion_timeout_callback)
556 this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
557 if (! this_->motion_timeout)
558 this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
564 navit_motion(void *data, struct point *p)
566 struct navit *this=data;
567 if (!this->ignore_graphics_events)
568 navit_handle_motion(this, p);
572 navit_predraw(struct navit *this_)
575 struct navit_vehicle *nv;
576 transform_copy(this_->trans, this_->trans_cursor);
580 navit_vehicle_draw(this_, nv, NULL);
586 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
588 struct coord c1, c2, *center;
589 if (scale < this_->zoom_min)
590 scale=this_->zoom_min;
591 if (scale > this_->zoom_max)
592 scale=this_->zoom_max;
594 transform_reverse(this_->trans, p, &c1);
595 transform_set_scale(this_->trans, scale);
597 transform_reverse(this_->trans, p, &c2);
598 center = transform_center(this_->trans);
599 center->x += c1.x - c2.x;
600 center->y += c1.y - c2.y;
607 * @brief Automatically adjusts zoom level
609 * This function automatically adjusts the current
610 * zoom level according to the current speed.
612 * @param this_ The navit struct
613 * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
614 * @param speed The vehicles speed in meters per second
615 * @param dir The direction into which the vehicle moves
618 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
625 if (! this_->autozoom_active) {
629 distance = speed * this_->autozoom_secs;
631 transform_get_size(this_->trans, &w, &h);
632 transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
633 scale = transform_get_scale(this_->trans);
635 /* We make sure that the point we want to see is within a certain range
636 * around the vehicle. The radius of this circle is the size of the
637 * screen. This doesn't necessarily mean the point is visible because of
638 * perspective etc. Quite rough, but should be enough. */
641 new_scale = (double)distance / h * 16;
643 new_scale = (double)distance / w * 16;
646 if (abs(new_scale - scale) < 2) {
650 if (new_scale >= this_->autozoom_min) {
651 navit_scale(this_, (long)new_scale, &pc, 0);
653 if (scale != this_->autozoom_min) {
654 navit_scale(this_, this_->autozoom_min, &pc, 0);
660 * Change the current zoom level, zooming closer to the ground
662 * @param navit The navit instance
663 * @param factor The zoom factor, usually 2
664 * @param p The invariant point (if set to NULL, default to center)
668 navit_zoom_in(struct navit *this_, int factor, struct point *p)
670 long scale=transform_get_scale(this_->trans)/factor;
673 navit_scale(this_, scale, p, 1);
677 * Change the current zoom level
679 * @param navit The navit instance
680 * @param factor The zoom factor, usually 2
681 * @param p The invariant point (if set to NULL, default to center)
685 navit_zoom_out(struct navit *this_, int factor, struct point *p)
687 long scale=transform_get_scale(this_->trans)*factor;
688 navit_scale(this_, scale, p, 1);
692 navit_zoom_in_cursor(struct navit *this_, int factor)
695 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
696 navit_zoom_in(this_, factor, &p);
697 this_->vehicle->follow_curr=this_->vehicle->follow;
699 navit_zoom_in(this_, factor, NULL);
703 navit_zoom_out_cursor(struct navit *this_, int factor)
706 if (this_->vehicle && this_->vehicle->follow_curr <= 1 && navit_get_cursor_pnt(this_, &p, 0, NULL)) {
707 navit_zoom_out(this_, 2, &p);
708 this_->vehicle->follow_curr=this_->vehicle->follow;
710 navit_zoom_out(this_, 2, NULL);
714 navit_cmd_zoom_in(struct navit *this_)
716 navit_zoom_in_cursor(this_, 2);
721 navit_cmd_zoom_out(struct navit *this_)
723 navit_zoom_out_cursor(this_, 2);
729 navit_cmd_say(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
731 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str)
732 navit_say(this, in[0]->u.str);
735 static GHashTable *cmd_int_var_hash = NULL;
736 static GHashTable *cmd_attr_var_hash = NULL;
739 * Store key value pair for the command system (for int typed values)
741 * @param navit The navit instance
742 * @param function unused (needed to match command function signiture)
743 * @param in input attributes in[0] is the key string, in[1] is the integer value to store
744 * @param out output attributes, unused
745 * @param valid unused
749 navit_cmd_set_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
753 if(!cmd_int_var_hash) {
754 cmd_int_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
757 if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
758 (in && in[1] && ATTR_IS_NUMERIC(in[1]->type))) {
759 val = g_new(struct attr,1);
760 attr_dup_content(in[1],val);
761 key = g_strdup(in[0]->u.str);
762 g_hash_table_insert(cmd_int_var_hash, key, val);
768 * Store key value pair for the command system (for attr typed values, can be used as opaque handles)
770 * @param navit The navit instance
771 * @param function unused (needed to match command function signiture)
772 * @param in input attributes in[0] is the key string, in[1] is the attr* value to store
773 * @param out output attributes, unused
774 * @param valid unused
777 //TODO free stored attributes on navit_destroy
779 navit_cmd_set_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
783 if(!cmd_attr_var_hash) {
784 cmd_attr_var_hash = g_hash_table_new(g_str_hash, g_str_equal);
787 if ( (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) &&
789 val = attr_dup(in[1]);
791 key = g_strdup(in[0]->u.str);
792 g_hash_table_insert(cmd_attr_var_hash, key, val);
799 * command to toggle the active state of a named layer of the current layout
801 * @param navit The navit instance
802 * @param function unused (needed to match command function signiture)
803 * @param in input attribute in[0] is the name of the layer
804 * @param out output unused
805 * @param valid unused
809 navit_cmd_toggle_layer(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
811 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
812 if(this->layout_current && this->layout_current->layers) {
813 GList* layers = this->layout_current->layers;
815 struct layer*l=layers->data;
816 if(l && !strcmp(l->name,in[0]->u.str) ) {
821 layers=g_list_next(layers);
828 * adds an item with the current coordinate of the vehicle to a named map
830 * @param navit The navit instance
831 * @param function unused (needed to match command function signiture)
832 * @param in input attribute in[0] is the name of the map
833 * @param out output attribute, 0 on error or the id of the created item on success
834 * @param valid unused
838 navit_cmd_map_add_curr_pos(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
840 struct attr **list = g_new0(struct attr *,2);
841 struct attr*val = g_new0(struct attr,1);
843 struct map_selection sel;
844 const int selection_range = 10;
845 enum item_type item_type;
847 struct map* curr_map = NULL;
848 struct coord curr_coord;
851 //return invalid item on error
852 val->type = attr_none;
858 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str && //map name
859 in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str //item type
862 if(!(ms=navit_get_mapset(this))) {
866 if((item_type = item_from_name(in[1]->u.str))==type_none) {
870 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
872 //no map with the given name found
877 if(this->vehicle && this->vehicle->vehicle ) {
878 struct attr pos_attr;
879 if(vehicle_get_attr(this->vehicle->vehicle,attr_position_coord_geo,&pos_attr,NULL)) {
880 transform_from_geo(projection_mg, pos_attr.u.coord_geo, &curr_coord);
890 sel.range.min=type_none;
891 sel.range.max=type_tec_common;
892 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
893 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
894 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
895 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
897 mr = map_rect_new(curr_map, &sel);
899 it = map_rect_create_item( mr, item_type);
901 val->type = attr_type_item_begin;
902 item_coord_set(it,&curr_coord, 1, change_mode_modify);
906 map_rect_destroy(mr);
911 * sets an attribute (name value pair) of a map item specified by map name and item id
913 * @param navit The navit instance
914 * @param function unused (needed to match command function signiture)
915 * @param in input attribute in[0] - name of the map ; in[1] - item ; in[2] - attr name ; in[3] - attr value
916 * @param out output attribute, 0 on error, 1 on success
917 * @param valid unused
921 navit_cmd_map_item_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
924 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str &&//map name
925 in[1] && ATTR_IS_ITEM(in[1]->type) && //item
926 in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str && //attr_type str
927 in[3] && ATTR_IS_STRING(in[3]->type) && in[3]->u.str //attr_value str
929 struct attr attr_to_set;
930 struct map* curr_map = NULL;
932 struct map_selection sel;
933 const int selection_range = 500;
934 struct coord curr_coord;
937 if(ATTR_IS_STRING(attr_from_name(in[2]->u.str))) {
938 attr_to_set.u.str = in[3]->u.str;
939 attr_to_set.type = attr_from_name(in[2]->u.str);
941 else if(ATTR_IS_INT(attr_from_name(in[2]->u.str))) {
942 attr_to_set.u.num = atoi(in[3]->u.str);
943 attr_to_set.type = attr_from_name(in[2]->u.str);
945 else if(ATTR_IS_DOUBLE(attr_from_name(in[2]->u.str))) {
946 double* val = g_new0(double,1);
947 *val = atof(in[3]->u.str);
948 attr_to_set.u.numd = val;
949 attr_to_set.type = attr_from_name(in[2]->u.str);
952 ms = navit_get_mapset(this);
954 curr_map = mapset_get_map_by_name(ms, in[0]->u.str);
961 sel.range.min=type_none;
962 sel.range.max=type_tec_common;
963 sel.u.c_rect.lu.x=curr_coord.x-selection_range;
964 sel.u.c_rect.lu.y=curr_coord.y+selection_range;
965 sel.u.c_rect.rl.x=curr_coord.x+selection_range;
966 sel.u.c_rect.rl.y=curr_coord.y-selection_range;
970 item_attr_set(it, &attr_to_set, change_mode_modify);
976 * Get attr variable given a key string for the command system (for opaque usage)
978 * @param navit The navit instance
979 * @param function unused (needed to match command function signiture)
980 * @param in input attribute in[0] is the key string
981 * @param out output attribute, the attr for the given key string if exists or NULL
982 * @param valid unused
986 navit_cmd_get_attr_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
988 struct attr **list = g_new0(struct attr *,2);
989 if(!cmd_int_var_hash) {
990 struct attr*val = g_new0(struct attr,1);
991 val->type = attr_type_item_begin;
995 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
996 struct attr*ret = g_hash_table_lookup(cmd_attr_var_hash, in[0]->u.str);
998 list[0] = attr_dup(ret);
1001 struct attr*val = g_new0(struct attr,1);
1002 val->type = attr_type_int_begin;
1013 * Get value given a key string for the command system
1015 * @param navit The navit instance
1016 * @param function unused (needed to match command function signiture)
1017 * @param in input attribute in[0] is the key string
1018 * @param out output attribute, the value for the given key string if exists or 0
1019 * @param valid unused
1023 navit_cmd_get_int_var(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1025 struct attr **list = g_new0(struct attr *,2);
1026 if(!cmd_int_var_hash) {
1027 struct attr*val = g_new0(struct attr,1);
1028 val->type = attr_type_int_begin;
1032 if (in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str) {
1033 struct attr*ret = g_hash_table_lookup(cmd_int_var_hash, in[0]->u.str);
1038 struct attr*val = g_new0(struct attr,1);
1039 val->type = attr_type_int_begin;
1048 GList *cmd_int_var_stack = NULL;
1051 * Push an integer to the stack for the command system
1053 * @param navit The navit instance
1054 * @param function unused (needed to match command function signiture)
1055 * @param in input attribute in[0] is the integer attibute to push
1056 * @param out output attributes, unused
1057 * @param valid unused
1061 navit_cmd_push_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1063 if (in && in[0] && ATTR_IS_NUMERIC(in[0]->type)) {
1064 struct attr*val = g_new(struct attr,1);
1065 attr_dup_content(in[0],val);
1066 cmd_int_var_stack = g_list_prepend(cmd_int_var_stack, val);
1071 * Pop an integer from the command system's integer stack
1073 * @param navit The navit instance
1074 * @param function unused (needed to match command function signiture)
1075 * @param in input attributes unused
1076 * @param out output attribute, the value popped if stack isn't empty or 0
1077 * @param valid unused
1081 navit_cmd_pop_int(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1083 struct attr **list = g_new0(struct attr *,2);
1084 if(!cmd_int_var_stack) {
1085 struct attr*val = g_new0(struct attr,1);
1086 val->type = attr_type_int_begin;
1091 list[0] = cmd_int_var_stack->data;
1092 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1099 * Get current size of command system's integer stack
1101 * @param navit The navit instance
1102 * @param function unused (needed to match command function signiture)
1103 * @param in input attributes unused
1104 * @param out output attribute, the size of stack
1105 * @param valid unused
1109 navit_cmd_int_stack_size(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1112 struct attr *attr = g_new0(struct attr ,1);
1113 attr->type = attr_type_int_begin;
1114 if(!cmd_int_var_stack) {
1118 attr->u.num = g_list_length(cmd_int_var_stack);
1120 list = g_new0(struct attr *,2);
1124 cmd_int_var_stack = g_list_remove_link(cmd_int_var_stack,cmd_int_var_stack);
1127 static struct attr **
1128 navit_get_coord(struct navit *this, struct attr **in, struct pcoord *pc)
1134 pc->pro = transform_get_projection(this->trans);
1135 if (ATTR_IS_STRING(in[0]->type)) {
1137 coord_parse(in[0]->u.str, pc->pro, &c);
1141 } else if (ATTR_IS_COORD(in[0]->type)) {
1142 pc->x=in[0]->u.coord->x;
1143 pc->y=in[0]->u.coord->y;
1145 } else if (ATTR_IS_PCOORD(in[0]->type)) {
1146 *pc=*in[0]->u.pcoord;
1148 } else if (in[1] && in[2] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type) && ATTR_IS_INT(in[2]->type)) {
1149 pc->pro=in[0]->u.num;
1153 } else if (in[1] && ATTR_IS_INT(in[0]->type) && ATTR_IS_INT(in[1]->type)) {
1163 navit_cmd_set_destination(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1166 char *description=NULL;
1167 in=navit_get_coord(this, in, &pc);
1170 if (in[0] && ATTR_IS_STRING(in[0]->type))
1171 description=in[0]->u.str;
1172 navit_set_destination(this, &pc, description, 1);
1177 navit_cmd_set_center(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1180 in=navit_get_coord(this, in, &pc);
1183 navit_set_center(this, &pc, 0);
1187 navit_cmd_fmt_coordinates(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1190 attr.type=attr_type_string_begin;
1191 attr.u.str="Fix me";
1193 *out=attr_generic_add_attr(*out, &attr);
1198 * Join several string attributes into one
1200 * @param navit The navit instance
1201 * @param function unused (needed to match command function signiture)
1202 * @param in input attributes in[0] - separator, in[1..] - attributes to join
1203 * @param out output attribute joined attribute as string
1204 * @param valid unused
1208 navit_cmd_strjoin(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1213 attr.type=attr_type_string_begin;
1215 if(in[0] && in[1]) {
1216 sep=attr_to_text(in[0],NULL,1);
1217 ret=attr_to_text(in[1],NULL,1);
1218 for(i=2;in[i];i++) {
1219 gchar *in_i=attr_to_text(in[i],NULL,1);
1220 gchar *r=g_strjoin(sep,ret,in_i,NULL);
1228 *out=attr_generic_add_attr(*out, &attr);
1235 * Call external program
1237 * @param navit The navit instance
1238 * @param function unused (needed to match command function signiture)
1239 * @param in input attributes in[0] - name of executable, in[1..] - parameters
1240 * @param out output attribute unused
1241 * @param valid unused
1245 navit_cmd_spawn(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
1247 int i,j, nparms, nvalid;
1248 const char ** argv=NULL;
1249 struct spawn_process_info *pi;
1255 if (in[nparms]->type!=attr_none)
1262 argv=g_new(char*,nvalid+1);
1263 for(i=0,j=0;in[i];i++) {
1264 if(in[i]->type!=attr_none ) {
1265 argv[j++]=attr_to_text(in[i],NULL,1);
1267 dbg(0,"Parameter #%i is attr_none - skipping\n",i);
1271 pi=spawn_process(argv);
1273 // spawn_process() testing suite - uncomment following code to test.
1275 // example of non-blocking wait
1276 //int st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st);
1277 // example of blocking wait
1278 //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st);
1279 // example of wait after process is finished and status is
1281 //st=spawn_process_check_status(pi,1);dbg(0,"status %i\n",st);
1282 // example of wait after process is finished and status is
1283 // already tested - unblocked
1284 //st=spawn_process_check_status(pi,0);dbg(0,"status %i\n",st);
1286 // End testing suite
1287 spawn_process_info_free(pi);
1288 for(i=0;argv[i];i++)
1295 static struct command_table commands[] = {
1296 {"zoom_in",command_cast(navit_cmd_zoom_in)},
1297 {"zoom_out",command_cast(navit_cmd_zoom_out)},
1298 {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
1299 {"say",command_cast(navit_cmd_say)},
1300 {"set_center",command_cast(navit_cmd_set_center)},
1301 {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
1302 {"set_destination",command_cast(navit_cmd_set_destination)},
1303 {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
1304 {"fmt_coordinates",command_cast(navit_cmd_fmt_coordinates)},
1305 {"set_int_var",command_cast(navit_cmd_set_int_var)},
1306 {"get_int_var",command_cast(navit_cmd_get_int_var)},
1307 {"push_int",command_cast(navit_cmd_push_int)},
1308 {"pop_int",command_cast(navit_cmd_pop_int)},
1309 {"int_stack_size",command_cast(navit_cmd_int_stack_size)},
1310 {"toggle_layer",command_cast(navit_cmd_toggle_layer)},
1311 {"strjoin",command_cast(navit_cmd_strjoin)},
1312 {"spawn",command_cast(navit_cmd_spawn)},
1313 {"map_add_curr_pos",command_cast(navit_cmd_map_add_curr_pos)},
1314 {"map_item_set_attr",command_cast(navit_cmd_map_item_set_attr)},
1315 {"set_attr_var",command_cast(navit_cmd_set_attr_var)},
1316 {"get_attr_var",command_cast(navit_cmd_get_attr_var)},
1320 navit_command_add_table(struct navit*this_, struct command_table *commands, int count)
1322 command_add_table(this_->attr_cbl, commands, count, this_);
1326 navit_new(struct attr *parent, struct attr **attrs)
1328 struct navit *this_=g_new0(struct navit, 1);
1329 struct pcoord center;
1332 enum projection pro=projection_mg;
1337 this_->self.type=attr_navit;
1338 this_->self.u.navit=this_;
1339 this_->attr_cbl=callback_list_new();
1341 this_->orientation=-1;
1342 this_->tracking_flag=1;
1343 this_->recentdest_count=10;
1344 this_->osd_configuration=-1;
1346 this_->center_timeout = 10;
1347 this_->use_mousewheel = 1;
1348 this_->autozoom_secs = 10;
1349 this_->autozoom_min = 7;
1350 this_->autozoom_active = 0;
1351 this_->zoom_min = 1;
1352 this_->zoom_max = 2097152;
1353 this_->follow_cursor = 1;
1357 this_->trans = transform_new();
1358 this_->trans_cursor = transform_new();
1359 transform_from_geo(pro, &g, &co);
1364 transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
1366 this_->bookmarks=bookmarks_new(&this_->self, NULL, this_->trans);
1370 for (;*attrs; attrs++) {
1371 navit_set_attr_do(this_, *attrs, 1);
1373 this_->displaylist=graphics_displaylist_new();
1374 command_add_table(this_->attr_cbl, commands, sizeof(commands)/sizeof(struct command_table), this_);
1376 this_->messages = messagelist_new(attrs);
1382 navit_set_gui(struct navit *this_, struct gui *gui)
1387 if (gui_has_main_loop(this_->gui)) {
1388 if (! main_loop_gui) {
1389 main_loop_gui=this_->gui;
1391 dbg(0,"gui with main loop already active, ignoring this instance");
1399 navit_add_message(struct navit *this_, char *message)
1401 message_new(this_->messages, message);
1405 *navit_get_messages(struct navit *this_)
1407 return message_get(this_->messages);
1411 navit_set_graphics(struct navit *this_, struct graphics *gra)
1416 this_->resize_callback=callback_new_attr_1(callback_cast(navit_resize), attr_resize, this_);
1417 graphics_add_callback(gra, this_->resize_callback);
1418 this_->button_callback=callback_new_attr_1(callback_cast(navit_button), attr_button, this_);
1419 graphics_add_callback(gra, this_->button_callback);
1420 this_->motion_callback=callback_new_attr_1(callback_cast(navit_motion), attr_motion, this_);
1421 graphics_add_callback(gra, this_->motion_callback);
1422 this_->predraw_callback=callback_new_attr_1(callback_cast(navit_predraw), attr_predraw, this_);
1423 graphics_add_callback(gra, this_->predraw_callback);
1428 navit_get_graphics(struct navit *this_)
1433 struct vehicleprofile *
1434 navit_get_vehicleprofile(struct navit *this_)
1436 return this_->vehicleprofile;
1440 navit_get_vehicleprofiles(struct navit *this_)
1442 return this_->vehicleprofiles;
1446 navit_projection_set(struct navit *this_, enum projection pro, int draw)
1451 c=transform_center(this_->trans);
1452 transform_to_geo(transform_get_projection(this_->trans), c, &g);
1453 transform_set_projection(this_->trans, pro);
1454 transform_from_geo(pro, &g, c);
1460 * Start the route computing to a given set of coordinates
1462 * @param navit The navit instance
1463 * @param c The coordinate to start routing to
1464 * @param description A label which allows the user to later identify this destination in the former destinations selection
1468 navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
1470 char *destination_file;
1472 this_->destination=*c;
1473 this_->destination_valid=1;
1475 dbg(1, "navit->navit_set_destination %i\n", c->x);
1476 dbg(1, "navit->navit_set_destination %i\n", c->y);
1479 this_->destination_valid=0;
1480 destination_file = bookmarks_get_destination_file(TRUE);
1481 bookmarks_append_coord(this_->bookmarks, destination_file, c, 1, "former_destination", description, NULL, this_->recentdest_count);
1482 g_free(destination_file);
1483 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1485 route_set_destination(this_->route, c, async);
1487 if (this_->ready == 3)
1493 * Start the route computing to a given set of coordinates including waypoints
1495 * @param navit The navit instance
1496 * @param c The coordinate to start routing to
1497 * @param description A label which allows the user to later identify this destination in the former destinations selection
1501 navit_set_destinations(struct navit *this_, struct pcoord *c, int count, const char *description, int async)
1503 char *destination_file;
1505 this_->destination=c[count-1];
1506 this_->destination_valid=1;
1508 this_->destination_valid=0;
1509 destination_file = bookmarks_get_destination_file(TRUE);
1510 bookmarks_append_coord(this_->bookmarks, destination_file, c, count, "former_itinerary", description, NULL, this_->recentdest_count);
1511 g_free(destination_file);
1512 callback_list_call_attr_0(this_->attr_cbl, attr_destination);
1514 route_set_destinations(this_->route, c, count, async);
1516 if (this_->ready == 3)
1522 * @brief Checks if a route is calculated
1524 * This function checks if a route is calculated.
1526 * @param this_ The navit struct whose route should be checked.
1527 * @return True if the route is set, false otherwise.
1530 navit_check_route(struct navit *this_)
1533 return route_get_path_set(this_->route);
1540 navit_former_destinations_active(struct navit *this_)
1542 char *destination_file = bookmarks_get_destination_file(FALSE);
1546 f=fopen(destination_file,"r");
1548 if(!fseek(f, -2, SEEK_END) && fread(buffer, 2, 1, f) == 1 && (buffer[0]!='\n' || buffer[1]!='\n'))
1552 g_free(destination_file);
1556 struct map* read_former_destinations_from_file(){
1557 struct attr type, data, flags, *attrs[4];
1558 char *destination_file = bookmarks_get_destination_file(FALSE);
1561 type.type=attr_type;
1562 type.u.str="textfile";
1564 data.type=attr_data;
1565 data.u.str=destination_file;
1567 flags.type=attr_flags;
1570 attrs[0]=&type; attrs[1]=&data; attrs[2]=&flags; attrs[3]=NULL;
1572 m=map_new(NULL, attrs);
1573 g_free(destination_file);
1578 navit_add_former_destinations_from_file(struct navit *this_)
1581 int i,valid=0,count=0;
1583 struct pcoord pc[16];
1584 struct map_rect *mr;
1586 this_->former_destination=read_former_destinations_from_file();
1587 if (!this_->route || !navit_former_destinations_active(this_))
1589 mr=map_rect_new(this_->former_destination, NULL);
1590 while ((item=map_rect_get_item(mr))) {
1591 if ((item->type == type_former_destination || item->type == type_former_itinerary || item->type == type_former_itinerary_part) && (count=item_coord_get(item, c, 16)))
1594 map_rect_destroy(mr);
1595 if (valid && count > 0) {
1596 for (i = 0 ; i < count ; i++) {
1597 pc[i].pro=map_projection(this_->former_destination);
1602 route_set_destination(this_->route, &pc[0], 1);
1604 route_set_destinations(this_->route, pc, count, 1);
1605 this_->destination=pc[count-1];
1606 this_->destination_valid=1;
1612 navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
1617 if (this_->textfile_debug_log && this_->vehicle) {
1618 str1=g_strdup_vprintf(fmt, ap);
1619 str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
1620 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1628 navit_textfile_debug_log_at(struct navit *this_, struct pcoord *pc, const char *fmt, ...)
1633 if (this_->textfile_debug_log && this_->vehicle) {
1634 str1=g_strdup_vprintf(fmt, ap);
1635 str2=g_strdup_printf("0x%x 0x%x%s%s\n", pc->x, pc->y, strlen(str1) ? " " : "", str1);
1636 log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
1644 navit_say(struct navit *this_, char *text)
1647 speech_say(this_->speech, text);
1652 * @brief Toggles the navigation announcer for navit
1653 * @param this_ The navit object
1656 navit_cmd_announcer_toggle(struct navit *this_)
1658 struct attr attr, speechattr;
1660 // search for the speech attribute
1661 if(!navit_get_attr(this_, attr_speech, &speechattr, NULL))
1663 // find out if the corresponding attribute attr_active has been set
1664 if(speech_get_attr(speechattr.u.speech, attr_active, &attr, NULL)) {
1666 attr.u.num = !attr.u.num;
1668 // otherwise disable it because voice is enabled by default
1669 attr.type = attr_active;
1673 // apply the new state
1674 if(!speech_set_attr(speechattr.u.speech, &attr))
1677 // announce that the speech attribute has changed
1678 callback_list_call_attr_0(this_->attr_cbl, attr_speech);
1682 navit_speak(struct navit *this_)
1684 struct navigation *nav=this_->navigation;
1685 struct map *map=NULL;
1686 struct map_rect *mr=NULL;
1690 if (!speech_get_attr(this_->speech, attr_active, &attr, NULL))
1692 dbg(1, "this_.speech->active %i\n", attr.u.num);
1697 map=navigation_get_map(nav);
1699 mr=map_rect_new(map, NULL);
1701 while ((item=map_rect_get_item(mr)) && (item->type == type_nav_position || item->type == type_nav_none));
1702 if (item && item_attr_get(item, attr_navigation_speech, &attr)) {
1703 speech_say(this_->speech, attr.u.str);
1704 navit_add_message(this_, attr.u.str);
1705 navit_textfile_debug_log(this_, "type=announcement label=\"%s\"", attr.u.str);
1707 map_rect_destroy(mr);
1712 navit_window_roadbook_update(struct navit *this_)
1714 struct navigation *nav=this_->navigation;
1715 struct map *map=NULL;
1716 struct map_rect *mr=NULL;
1719 struct param_list param[5];
1723 datawindow_mode(this_->roadbook_window, 1);
1725 map=navigation_get_map(nav);
1727 mr=map_rect_new(map, NULL);
1728 dbg(0,"nav=%p map=%p mr=%p\n", nav, map, mr);
1730 dbg(0,"while loop\n");
1731 while ((item=map_rect_get_item(mr))) {
1732 dbg(0,"item=%p\n", item);
1734 if (item->type != type_nav_position) {
1735 item_attr_get(item, attr_navigation_long, &attr);
1736 if (attr.u.str == NULL) {
1739 dbg(2, "Command='%s'\n", attr.u.str);
1740 param[0].value=g_strdup(attr.u.str);
1742 param[0].value=_("Position");
1743 param[0].name=_("Command");
1745 item_attr_get(item, attr_length, &attr);
1746 dbg(2, "Length=%d\n", attr.u.num);
1747 param[1].name=_("Length");
1749 if ( attr.u.num >= 2000 )
1751 param[1].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1755 param[1].value=g_strdup_printf("%7d %s",attr.u.num, _("m"));
1758 item_attr_get(item, attr_time, &attr);
1759 dbg(2, "Time=%d\n", attr.u.num);
1761 param[2].name=_("Time");
1764 param[2].value=g_strdup_printf("%d:%02d:%02d",secs / 60, ( secs / 60 ) % 60 , secs % 60);
1768 param[2].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1771 item_attr_get(item, attr_destination_length, &attr);
1772 dbg(2, "Destlength=%d\n", attr.u.num);
1773 param[3].name=_("Destination Length");
1774 if ( attr.u.num >= 2000 )
1776 param[3].value=g_strdup_printf("%5.1f %s",(float)attr.u.num / 1000, _("km") );
1780 param[3].value=g_strdup_printf("%d %s",attr.u.num, _("m"));
1783 item_attr_get(item, attr_destination_time, &attr);
1784 dbg(2, "Desttime=%d\n", attr.u.num);
1786 param[4].name=_("Destination Time");
1789 param[4].value=g_strdup_printf("%d:%02d:%02d",secs / 3600, (secs / 60 ) % 60 , secs % 60);
1793 param[4].value=g_strdup_printf("%d:%02d",secs / 60, secs % 60);
1795 datawindow_add(this_->roadbook_window, param, 5);
1797 map_rect_destroy(mr);
1799 datawindow_mode(this_->roadbook_window, 0);
1803 navit_window_roadbook_destroy(struct navit *this_)
1806 navigation_unregister_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1807 this_->roadbook_window=NULL;
1808 this_->roadbook_callback=NULL;
1811 navit_window_roadbook_new(struct navit *this_)
1813 if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
1817 this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
1818 navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
1819 this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));
1820 navit_window_roadbook_update(this_);
1824 navit_init(struct navit *this_)
1831 dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
1833 if (!this_->gui && !(this_->flags & 2)) {
1835 navit_destroy(this_);
1838 if (!this_->gra && !(this_->flags & 1)) {
1839 dbg(0,"no graphics\n");
1840 navit_destroy(this_);
1843 dbg(2,"Connecting gui to graphics\n");
1844 if (this_->gui && this_->gra && gui_set_graphics(this_->gui, this_->gra)) {
1845 struct attr attr_type_gui, attr_type_graphics;
1846 gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
1847 graphics_get_attr(this_->gra, attr_type, &attr_type_graphics, NULL);
1848 dbg(0,"failed to connect graphics '%s' to gui '%s'\n", attr_type_graphics.u.str, attr_type_gui.u.str);
1849 dbg(0," Please see http://wiki.navit-project.org/index.php/Failed_to_connect_graphics_to_gui\n");
1850 dbg(0," for explanations and solutions\n");
1852 navit_destroy(this_);
1855 if (this_->speech && this_->navigation) {
1857 speech.type=attr_speech;
1858 speech.u.speech=this_->speech;
1859 navigation_set_attr(this_->navigation, &speech);
1861 dbg(2,"Initializing graphics\n");
1862 dbg(2,"Setting Vehicle\n");
1863 navit_set_vehicle(this_, this_->vehicle);
1864 dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
1865 if (this_->mapsets) {
1866 struct mapset_handle *msh;
1867 ms=this_->mapsets->data;
1868 this_->progress_cb=callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
1869 msh=mapset_open(ms);
1870 while (msh && (map=mapset_next(msh, 0))) {
1871 //pass new callback instance for each map in the mapset to make map callback list destruction work correctly
1872 struct callback *pcb = callback_new_attr_1(callback_cast(navit_map_progress), attr_progress, this_);
1873 map_add_callback(map, pcb);
1878 if ((map=route_get_map(this_->route))) {
1880 map_a.type=attr_map;
1882 mapset_add_attr(ms, &map_a);
1884 if ((map=route_get_graph_map(this_->route))) {
1885 struct attr map_a,active;
1886 map_a.type=attr_map;
1888 active.type=attr_active;
1890 mapset_add_attr(ms, &map_a);
1891 map_set_attr(map, &active);
1893 route_set_mapset(this_->route, ms);
1894 route_set_projection(this_->route, transform_get_projection(this_->trans));
1896 if (this_->tracking) {
1897 tracking_set_mapset(this_->tracking, ms);
1899 tracking_set_route(this_->tracking, this_->route);
1901 if (this_->navigation) {
1902 if ((map=navigation_get_map(this_->navigation))) {
1903 struct attr map_a,active;
1904 map_a.type=attr_map;
1906 active.type=attr_active;
1908 mapset_add_attr(ms, &map_a);
1909 map_set_attr(map, &active);
1912 if (this_->tracking) {
1913 if ((map=tracking_get_map(this_->tracking))) {
1914 struct attr map_a,active;
1915 map_a.type=attr_map;
1917 active.type=attr_active;
1919 mapset_add_attr(ms, &map_a);
1920 map_set_attr(map, &active);
1923 navit_add_former_destinations_from_file(this_);
1926 struct attr callback;
1927 this_->route_cb=callback_new_attr_1(callback_cast(navit_redraw_route), attr_route_status, this_);
1928 callback.type=attr_callback;
1929 callback.u.callback=this_->route_cb;
1930 route_add_attr(this_->route, &callback);
1932 if (this_->navigation) {
1933 if (this_->speech) {
1934 this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_);
1935 navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb);
1938 navigation_set_route(this_->navigation, this_->route);
1940 dbg(2,"Setting Center\n");
1941 center_file = bookmarks_get_center_file(FALSE);
1942 bookmarks_set_center_from_file(this_->bookmarks, center_file);
1943 g_free(center_file);
1945 if (this_->menubar) {
1946 men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL);
1948 navit_add_menu_windows_items(this_, men);
1954 navit_window_roadbook_new(this_);
1955 navit_window_items_new(this_);
1958 messagelist_init(this_->messages);
1960 navit_set_cursors(this_);
1962 callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
1963 callback=(this_->ready == 2);
1965 dbg(2,"ready=%d\n",this_->ready);
1966 if (this_->ready == 3)
1967 navit_draw_async(this_, 1);
1969 callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
1971 routech_test(this_);
1976 navit_zoom_to_rect(struct navit *this_, struct coord_rect *r)
1981 c.x=(r->rl.x+r->lu.x)/2;
1982 c.y=(r->rl.y+r->lu.y)/2;
1983 transform_set_center(this_->trans, &c);
1984 dbg(1,"%x,%x-%x,%x\n", r->rl.x,r->rl.y,r->lu.x,r->lu.y);
1985 while (scale < 1<<20) {
1987 transform_set_scale(this_->trans, scale);
1988 transform_setup_source_rect(this_->trans);
1989 transform(this_->trans, transform_get_projection(this_->trans), &r->lu, &p1, 1, 0, 0, NULL);
1990 transform(this_->trans, transform_get_projection(this_->trans), &r->rl, &p2, 1, 0, 0, NULL);
1991 dbg(1,"%d,%d-%d,%d\n",p1.x,p1.y,p2.x,p2.y);
1992 if (p1.x < 0 || p2.x < 0 || p1.x > this_->w || p2.x > this_->w ||
1993 p1.y < 0 || p2.y < 0 || p1.y > this_->h || p2.y > this_->h)
1999 if (this_->ready == 3)
2000 navit_draw_async(this_,0);
2004 navit_zoom_to_route(struct navit *this_, int orientation)
2007 struct map_rect *mr=NULL;
2010 struct coord_rect r;
2015 map=route_get_map(this_->route);
2016 dbg(1,"map=%p\n",map);
2018 mr=map_rect_new(map, NULL);
2019 dbg(1,"mr=%p\n",mr);
2021 while ((item=map_rect_get_item(mr))) {
2022 dbg(1,"item=%s\n", item_to_name(item->type));
2023 while (item_coord_get(item, &c, 1)) {
2028 coord_rect_extend(&r, &c);
2032 map_rect_destroy(mr);
2036 if (orientation != -1)
2037 transform_set_yaw(this_->trans, orientation);
2038 navit_zoom_to_rect(this_, &r);
2042 navit_cmd_zoom_to_route(struct navit *this)
2044 navit_zoom_to_route(this, 0);
2049 * Change the current zoom level
2051 * @param navit The navit instance
2052 * @param center The point where to center the map, including its projection
2056 navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
2058 struct coord *c=transform_center(this_->trans);
2060 enum projection pro = transform_get_projection(this_->trans);
2061 if (pro != center->pro) {
2064 transform_from_to(&c1, center->pro, &c2, pro);
2071 navit_set_timeout(this_);
2072 if (this_->ready == 3)
2077 navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
2081 transform_set_center(this_->trans, c);
2082 transform_get_size(this_->trans, &width, &height);
2085 update_transformation(this_->trans, &po, p, NULL);
2087 navit_set_timeout(this_);
2091 * Links all vehicles to a cursor depending on the current profile.
2093 * @param this_ A navit instance
2094 * @author Ralph Sennhauser (10/2009)
2097 navit_set_cursors(struct navit *this_)
2100 struct navit_vehicle *nv;
2104 v=g_list_first(this_->vehicles); // GList of navit_vehicles
2107 if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) {
2108 if (!strcmp(name.u.str,"none"))
2111 c=layout_get_cursor(this_->layout_current, name.u.str);
2113 c=layout_get_cursor(this_->layout_current, "default");
2114 vehicle_set_cursor(nv->vehicle, c, 0);
2121 navit_get_cursor_pnt(struct navit *this_, struct point *p, int keep_orientation, int *dir)
2124 struct navit_vehicle *nv=this_->vehicle;
2126 float offset=this_->radius; // Cursor offset from the center of the screen (percent).
2127 #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 */
2128 float min_offset = 0.; // Percent offset at min_offset_speed.
2129 float max_offset = 30.; // Percent offset at max_offset_speed.
2130 int min_offset_speed = 2; // Speed in km/h
2131 int max_offset_speed = 50; // Speed ini km/h
2132 // Calculate cursor offset from the center of the screen, upon speed.
2133 if (nv->speed <= min_offset_speed) {
2134 offset = min_offset;
2135 } else if (nv->speed > max_offset_speed) {
2136 offset = max_offset;
2138 offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
2142 transform_get_size(this_->trans, &width, &height);
2143 if (this_->orientation == -1 || keep_orientation) {
2145 p->y=(50 + offset)*height/100;
2147 *dir=keep_orientation?this_->orientation:nv->dir;
2150 if (this_->tracking && this_->tracking_flag) {
2151 mdir = tracking_get_angle(this_->tracking) - this_->orientation;
2153 mdir=nv->dir-this_->orientation;
2156 p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
2157 p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
2159 *dir=this_->orientation;
2165 navit_set_center_cursor(struct navit *this_, int autozoom, int keep_orientation)
2169 struct navit_vehicle *nv=this_->vehicle;
2170 navit_get_cursor_pnt(this_, &pn, keep_orientation, &dir);
2171 transform_set_yaw(this_->trans, dir);
2172 navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
2174 navit_autozoom(this_, &nv->coord, nv->speed, 0);
2178 navit_set_center_cursor_draw(struct navit *this_)
2180 navit_set_center_cursor(this_,1,0);
2181 if (this_->ready == 3)
2182 navit_draw_async(this_, 1);
2186 navit_cmd_set_center_cursor(struct navit *this_)
2188 navit_set_center_cursor_draw(this_);
2192 navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
2196 transform_reverse(this_->trans, p, &c);
2199 pc.pro = transform_get_projection(this_->trans);
2200 navit_set_center(this_, &pc, set_timeout);
2204 switch((*attrs)->type) {
2206 zoom=(*attrs)->u.num;
2209 g=*((*attrs)->u.coord_geo);
2214 navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
2216 int dir=0, orient_old=0, attr_updated=0;
2220 struct navit_vehicle *nv;
2223 active.type=attr_active;
2226 switch (attr->type) {
2228 attr_updated=(this_->autozoom_secs != attr->u.num);
2229 this_->autozoom_secs = attr->u.num;
2231 case attr_autozoom_active:
2232 attr_updated=(this_->autozoom_active != attr->u.num);
2233 this_->autozoom_active = attr->u.num;
2236 transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
2237 dbg(1,"0x%x,0x%x\n",co.x,co.y);
2238 transform_set_center(this_->trans, &co);
2240 case attr_drag_bitmap:
2241 attr_updated=(this_->drag_bitmap != !!attr->u.num);
2242 this_->drag_bitmap=!!attr->u.num;
2245 attr_updated=(this_->flags != attr->u.num);
2246 this_->flags=attr->u.num;
2248 case attr_flags_graphics:
2249 attr_updated=(this_->graphics_flags != attr->u.num);
2250 this_->graphics_flags=attr->u.num;
2253 if (!this_->vehicle)
2255 attr_updated=(this_->vehicle->follow_curr != attr->u.num);
2256 this_->vehicle->follow_curr = attr->u.num;
2259 if(this_->layout_current!=attr->u.layout) {
2260 this_->layout_current=attr->u.layout;
2261 graphics_font_destroy_all(this_->gra);
2262 navit_set_cursors(this_);
2263 if (this_->ready == 3)
2268 case attr_layout_name:
2272 if (!strcmp(lay->name,attr->u.str)) {
2274 attr.type=attr_layout;
2276 return navit_set_attr_do(this_, &attr, init);
2281 case attr_map_border:
2282 if (this_->border != attr->u.num) {
2283 this_->border=attr->u.num;
2287 case attr_orientation:
2288 orient_old=this_->orientation;
2289 this_->orientation=attr->u.num;
2291 if (this_->orientation != -1) {
2292 dir = this_->orientation;
2294 if (this_->vehicle) {
2295 dir = this_->vehicle->dir;
2298 transform_set_yaw(this_->trans, dir);
2299 if (orient_old != this_->orientation) {
2301 if (this_->ready == 3)
2308 case attr_osd_configuration:
2309 dbg(0,"setting osd_configuration to %d (was %d)\n", attr->u.num, this_->osd_configuration);
2310 attr_updated=(this_->osd_configuration != attr->u.num);
2311 this_->osd_configuration=attr->u.num;
2314 attr_updated=(this_->pitch != attr->u.num);
2315 this_->pitch=attr->u.num;
2316 transform_set_pitch(this_->trans, this_->pitch);
2317 if (!init && attr_updated && this_->ready == 3)
2320 case attr_projection:
2321 if(this_->trans && transform_get_projection(this_->trans) != attr->u.projection) {
2322 navit_projection_set(this_, attr->u.projection, !init);
2327 attr_updated=(this_->radius != attr->u.num);
2328 this_->radius=attr->u.num;
2330 case attr_recent_dest:
2331 attr_updated=(this_->recentdest_count != attr->u.num);
2332 this_->recentdest_count=attr->u.num;
2335 if(this_->speech && this_->speech != attr->u.speech) {
2337 this_->speech = attr->u.speech;
2341 attr_updated=(this_->center_timeout != attr->u.num);
2342 this_->center_timeout = attr->u.num;
2345 attr_updated=(this_->tracking_flag != !!attr->u.num);
2346 this_->tracking_flag=!!attr->u.num;
2348 case attr_transformation:
2349 this_->trans=attr->u.transformation;
2351 case attr_use_mousewheel:
2352 attr_updated=(this_->use_mousewheel != !!attr->u.num);
2353 this_->use_mousewheel=!!attr->u.num;
2359 if (nv->vehicle == attr->u.vehicle) {
2360 if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
2362 vehicle_set_attr(this_->vehicle->vehicle, &active);
2364 vehicle_set_attr(nv->vehicle, &active);
2367 navit_set_vehicle(this_, nv);
2373 zoom=transform_get_scale(this_->trans);
2374 attr_updated=(zoom != attr->u.num);
2375 transform_set_scale(this_->trans, attr->u.num);
2376 if (attr_updated && !init)
2380 attr_updated=(attr->u.num != this_->zoom_min);
2381 this_->zoom_min=attr->u.num;
2384 attr_updated=(attr->u.num != this_->zoom_max);
2385 this_->zoom_max=attr->u.num;
2388 navit_add_message(this_, attr->u.str);
2390 case attr_follow_cursor:
2391 attr_updated=(this_->follow_cursor != !!attr->u.num);
2392 this_->follow_cursor=!!attr->u.num;
2395 attr_updated=(this_->imperial != attr->u.num);
2396 this_->imperial=attr->u.num;
2401 if (attr_updated && !init) {
2402 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2403 if (attr->type == attr_osd_configuration)
2404 graphics_draw_mode(this_->gra, draw_mode_end);
2410 navit_set_attr(struct navit *this_, struct attr *attr)
2412 return navit_set_attr_do(this_, attr, 0);
2416 navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
2418 struct message *msg;
2424 msg = navit_get_messages(this_);
2432 len += strlen(msg->text) + 1;
2435 attr->u.str = g_malloc(len + 1);
2437 msg = navit_get_messages(this_);
2440 g_stpcpy((attr->u.str + offset), msg->text);
2441 offset += strlen(msg->text);
2442 attr->u.str[offset] = '\n';
2448 attr->u.str[len] = '\0';
2451 attr->u.num=this_->imperial;
2453 case attr_bookmark_map:
2454 attr->u.map=bookmarks_get_map(this_->bookmarks);
2456 case attr_bookmarks:
2457 attr->u.bookmarks=this_->bookmarks;
2459 case attr_callback_list:
2460 attr->u.callback_list=this_->attr_cbl;
2462 case attr_destination:
2463 if (! this_->destination_valid)
2465 attr->u.pcoord=&this_->destination;
2467 case attr_displaylist:
2468 attr->u.displaylist=this_->displaylist;
2469 return (attr->u.displaylist != NULL);
2471 if (!this_->vehicle)
2473 attr->u.num=this_->vehicle->follow_curr;
2475 case attr_former_destination_map:
2476 attr->u.map=this_->former_destination;
2479 attr->u.graphics=this_->gra;
2480 ret=(attr->u.graphics != NULL);
2483 attr->u.gui=this_->gui;
2484 ret=(attr->u.gui != NULL);
2489 iter->u.list=g_list_next(iter->u.list);
2491 iter->u.list=this_->layouts;
2495 attr->u.layout=(struct layout *)iter->u.list->data;
2497 attr->u.layout=this_->layout_current;
2501 if (iter && this_->mapsets) {
2502 if (!iter->u.mapset_handle) {
2503 iter->u.mapset_handle=mapset_open((struct mapset *)this_->mapsets->data);
2505 attr->u.map=mapset_next(iter->u.mapset_handle, 0);
2507 mapset_close(iter->u.mapset_handle);
2515 attr->u.mapset=this_->mapsets->data;
2516 ret=(attr->u.mapset != NULL);
2518 case attr_navigation:
2519 attr->u.navigation=this_->navigation;
2521 case attr_orientation:
2522 attr->u.num=this_->orientation;
2525 ret=attr_generic_get_attr(this_->attr_list, NULL, type, attr, iter?(struct attr_iter *)&iter->iter:NULL);
2527 case attr_osd_configuration:
2528 attr->u.num=this_->osd_configuration;
2531 attr->u.num=transform_get_pitch(this_->trans);
2533 case attr_projection:
2535 attr->u.num=transform_get_projection(this_->trans);
2541 attr->u.route=this_->route;
2544 attr->u.speech=this_->speech;
2547 attr->u.num=this_->tracking_flag;
2549 case attr_trackingo:
2550 attr->u.tracking=this_->tracking;
2552 case attr_transformation:
2553 attr->u.transformation=this_->trans;
2558 iter->u.list=g_list_next(iter->u.list);
2560 iter->u.list=this_->vehicles;
2564 attr->u.vehicle=((struct navit_vehicle*)iter->u.list->data)->vehicle;
2566 if(this_->vehicle) {
2567 attr->u.vehicle=this_->vehicle->vehicle;
2573 case attr_vehicleprofile:
2574 attr->u.vehicleprofile=this_->vehicleprofile;
2577 attr->u.num=transform_get_scale(this_->trans);
2579 case attr_autozoom_active:
2580 attr->u.num=this_->autozoom_active;
2582 case attr_follow_cursor:
2583 attr->u.num=this_->follow_cursor;
2593 navit_add_log(struct navit *this_, struct log *log)
2595 struct attr type_attr;
2596 if (!log_get_attr(log, attr_type, &type_attr, NULL))
2598 if (!strcmp(type_attr.u.str, "textfile_debug")) {
2599 char *header = "type=track_tracked\n";
2600 if (this_->textfile_debug_log)
2602 log_set_header(log, header, strlen(header));
2603 this_->textfile_debug_log=log;
2610 navit_add_layout(struct navit *this_, struct layout *layout)
2613 this_->layouts = g_list_append(this_->layouts, layout);
2614 layout_get_attr(layout, attr_active, &active, NULL);
2615 if(active.u.num || !this_->layout_current) {
2616 this_->layout_current=layout;
2623 navit_add_attr(struct navit *this_, struct attr *attr)
2626 switch (attr->type) {
2628 navit_add_callback(this_, attr->u.callback);
2631 ret=navit_add_log(this_, attr->u.log);
2634 ret=navit_set_gui(this_, attr->u.gui);
2637 ret=navit_set_graphics(this_, attr->u.graphics);
2640 ret=navit_add_layout(this_, attr->u.layout);
2643 this_->route=attr->u.route;
2646 this_->mapsets = g_list_append(this_->mapsets, attr->u.mapset);
2648 case attr_navigation:
2649 this_->navigation=attr->u.navigation;
2652 this_->attr_list=attr_generic_add_attr(this_->attr_list, attr);
2654 case attr_recent_dest:
2655 this_->recentdest_count = attr->u.num;
2658 this_->speech=attr->u.speech;
2661 this_->tracking=attr->u.tracking;
2664 ret=navit_add_vehicle(this_, attr->u.vehicle);
2666 case attr_vehicleprofile:
2667 this_->vehicleprofiles=g_list_prepend(this_->vehicleprofiles, attr->u.vehicleprofile);
2669 case attr_autozoom_min:
2670 this_->autozoom_min = attr->u.num;
2675 callback_list_call_attr_2(this_->attr_cbl, attr->type, this_, attr);
2680 navit_remove_attr(struct navit *this_, struct attr *attr)
2683 switch (attr->type) {
2685 navit_remove_callback(this_, attr->u.callback);
2694 navit_attr_iter_new(void)
2696 return g_new0(struct attr_iter, 1);
2700 navit_attr_iter_destroy(struct attr_iter *iter)
2706 navit_add_callback(struct navit *this_, struct callback *cb)
2708 callback_list_add(this_->attr_cbl, cb);
2712 navit_remove_callback(struct navit *this_, struct callback *cb)
2714 callback_list_remove(this_->attr_cbl, cb);
2718 * Toggle the cursor update : refresh the map each time the cursor has moved (instead of only when it reaches a border)
2720 * @param navit The navit instance
2725 navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *pnt)
2727 struct point cursor_pnt;
2728 enum projection pro;
2735 pro=transform_get_projection(this_->trans_cursor);
2738 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2740 vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans_cursor), nv->speed);
2745 pro=transform_get_projection(this_->trans);
2746 transform(this_->trans, pro, &nv->coord, &pnt2, 1);
2749 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
2751 cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, 1);
2757 navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
2759 struct attr attr_valid, attr_dir, attr_speed, attr_pos;
2760 struct pcoord cursor_pc;
2761 struct point cursor_pnt, *pnt=&cursor_pnt;
2762 struct tracking *tracking=NULL;
2763 struct pcoord pc[16];
2764 enum projection pro=transform_get_projection(this_->trans_cursor);
2766 int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
2768 char *destination_file;
2771 if (this_->ready != 3) {
2772 profile(0,"return 1\n");
2775 navit_layout_switch(this_);
2776 if (this_->vehicle == nv && this_->tracking_flag)
2777 tracking=this_->tracking;
2779 tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
2780 attr_object=tracking;
2781 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
2783 attr_object=nv->vehicle;
2784 get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
2786 if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
2787 if (!attr_valid.u.num != attr_position_valid_invalid)
2789 if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
2790 ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
2791 ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
2792 profile(0,"return 2\n");
2795 nv->dir=*attr_dir.u.numd;
2796 nv->speed=*attr_speed.u.numd;
2797 transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
2798 if (nv != this_->vehicle) {
2799 navit_vehicle_draw(this_, nv, NULL);
2800 profile(0,"return 3\n");
2803 cursor_pc.x = nv->coord.x;
2804 cursor_pc.y = nv->coord.y;
2805 cursor_pc.pro = pro;
2808 route_set_position_from_tracking(this_->route, tracking, pro);
2810 route_set_position(this_->route, &cursor_pc);
2812 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2813 navit_textfile_debug_log(this_, "type=trackpoint_tracked");
2814 if (this_->gui && nv->speed > 2)
2815 navit_disable_suspend();
2817 transform(this_->trans_cursor, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
2818 if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
2819 (nv->follow_curr == 1 || !transform_within_border(this_->trans_cursor, &cursor_pnt, this_->border)))
2820 navit_set_center_cursor_draw(this_);
2822 navit_vehicle_draw(this_, nv, pnt);
2824 if (nv->follow_curr > 1)
2827 nv->follow_curr=nv->follow;
2828 callback_list_call_attr_2(this_->attr_cbl, attr_position_coord_geo, this_, nv->vehicle);
2830 /* Finally, if we reached our destination, stop navigation. */
2832 switch(route_destination_reached(this_->route)) {
2834 route_remove_waypoint(this_->route);
2835 count=route_get_destinations(this_->route, pc, 16);
2836 destination_file = bookmarks_get_destination_file(TRUE);
2837 bookmarks_append_coord(this_->bookmarks, destination_file, pc, count, "former_itinerary_part", NULL, NULL, this_->recentdest_count);
2840 navit_set_destination(this_, NULL, NULL, 0);
2844 profile(0,"return 5\n");
2848 * Set the position of the vehicle
2850 * @param navit The navit instance
2851 * @param c The coordinate to set as position
2856 navit_set_position(struct navit *this_, struct pcoord *c)
2859 route_set_position(this_->route, c);
2860 callback_list_call_attr_0(this_->attr_cbl, attr_position);
2862 if (this_->ready == 3)
2867 navit_set_vehicleprofile(struct navit *this_, char *name)
2871 l=this_->vehicleprofiles;
2873 if (vehicleprofile_get_attr(l->data, attr_name, &attr, NULL)) {
2874 if (!strcmp(attr.u.str, name)) {
2875 this_->vehicleprofile=l->data;
2877 route_set_profile(this_->route, this_->vehicleprofile);
2887 navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
2891 if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
2892 if (navit_set_vehicleprofile(this_, attr.u.str))
2895 if (!navit_set_vehicleprofile(this_,"car")) {
2896 /* We do not have a fallback "car" profile
2897 * so lets set any profile */
2899 l=this_->vehicleprofiles;
2901 this_->vehicleprofile=l->data;
2903 route_set_profile(this_->route, this_->vehicleprofile);
2909 * Register a new vehicle
2911 * @param navit The navit instance
2912 * @param v The vehicle instance
2913 * @returns 1 for success
2916 navit_add_vehicle(struct navit *this_, struct vehicle *v)
2918 struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
2919 struct attr follow, active, animate;
2924 nv->animate_cursor=0;
2925 if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
2926 nv->follow=follow.u.num;
2927 nv->follow_curr=nv->follow;
2928 this_->vehicles=g_list_append(this_->vehicles, nv);
2929 if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
2930 navit_set_vehicle(this_, nv);
2931 if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
2932 nv->animate_cursor=animate.u.num;
2933 nv->callback.type=attr_callback;
2934 nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
2935 vehicle_add_attr(nv->vehicle, &nv->callback);
2936 vehicle_set_attr(nv->vehicle, &this_->self);
2944 navit_get_gui(struct navit *this_)
2949 struct transformation *
2950 navit_get_trans(struct navit *this_)
2952 return this_->trans;
2956 navit_get_route(struct navit *this_)
2958 return this_->route;
2962 navit_get_navigation(struct navit *this_)
2964 return this_->navigation;
2967 struct displaylist *
2968 navit_get_displaylist(struct navit *this_)
2970 return this_->displaylist;
2974 navit_layout_switch(struct navit *n)
2978 struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
2979 double trise,tset,trise_actual;
2981 int year, month, day;
2983 if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
2984 return; //No layout - nothing to switch
2988 l=layout_attr.u.layout;
2990 if (l->dayname || l->nightname) {
2991 //Ok, we know that we have profile to switch
2993 //Check that we aren't calculating too fast
2994 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
2995 currTs=iso8601_to_secs(iso8601_attr.u.str);
2996 dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
2998 if (currTs-(n->prevTs)<60) {
2999 //We've have to wait a little
3002 if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
3004 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
3005 return; //No valid fix yet
3007 if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
3008 //No position - no sun
3012 //We calculate sunrise anyway, cause it is needed both for day and for night
3013 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
3014 //near the pole sun never rises/sets, so we should never switch profiles
3015 dbg(1,"trise: %u:%u, sun never visible, never switch profile\n",HOURS(trise),MINUTES(trise));
3021 dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
3024 if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
3025 (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
3026 //The sun is rising now!
3027 if (strcmp(l->name,l->dayname)) {
3028 navit_set_layout_by_name(n,l->dayname);
3033 if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
3034 //near the pole sun never rises/sets, so we should never switch profiles
3035 dbg(1,"tset: %u:%u, sun always visible, never switch profile\n",HOURS(tset),MINUTES(tset));
3039 dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
3040 if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
3041 || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
3042 ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
3044 if (strcmp(l->name,l->nightname)) {
3045 navit_set_layout_by_name(n,l->nightname);
3055 navit_set_vehicle_by_name(struct navit *n,const char *name)
3058 struct attr_iter *iter;
3059 struct attr vehicle_attr, name_attr;
3061 iter=navit_attr_iter_new();
3063 while (navit_get_attr(n,attr_vehicle,&vehicle_attr,iter)) {
3064 v=vehicle_attr.u.vehicle;
3065 vehicle_get_attr(v,attr_name,&name_attr,NULL);
3066 if (name_attr.type==attr_name) {
3067 if (!strcmp(name,name_attr.u.str)) {
3068 navit_set_attr(n,&vehicle_attr);
3069 navit_attr_iter_destroy(iter);
3074 navit_attr_iter_destroy(iter);
3079 navit_set_layout_by_name(struct navit *n,const char *name)
3082 struct attr_iter iter;
3083 struct attr layout_attr;
3087 if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
3088 return 0; //No layouts - nothing to do
3090 if (iter.u.list==NULL) {
3094 iter.u.list=g_list_first(iter.u.list);
3096 while(iter.u.list) {
3097 l=(struct layout*)iter.u.list->data;
3098 if (!strcmp(name,l->name)) {
3099 layout_attr.u.layout=l;
3100 layout_attr.type=attr_layout;
3101 navit_set_attr(n,&layout_attr);
3102 iter.u.list=g_list_first(iter.u.list);
3105 iter.u.list=g_list_next(iter.u.list);
3108 iter.u.list=g_list_first(iter.u.list);
3113 navit_disable_suspend() {
3114 gui_disable_suspend(global_navit->gui);
3115 callback_list_call_attr_0(global_navit->attr_cbl,attr_unsuspend);
3119 navit_block(struct navit *this_, int block)
3122 this_->blocked |= 1;
3123 if (graphics_draw_cancel(this_->gra, this_->displaylist))
3124 this_->blocked |= 2;
3127 if ((this_->blocked & 2) || block < 0) {
3137 navit_destroy(struct navit *this_)
3140 callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
3142 /* TODO: destroy objects contained in this_ */
3144 vehicle_destroy(this_->vehicle->vehicle);
3145 if (this_->bookmarks) {
3146 char *center_file = bookmarks_get_center_file(TRUE);
3147 bookmarks_write_center_to_file(this_->bookmarks, center_file);
3148 g_free(center_file);
3149 bookmarks_destroy(this_->bookmarks);
3151 callback_destroy(this_->nav_speech_cb);
3152 callback_destroy(this_->roadbook_callback);
3153 callback_destroy(this_->popup_callback);
3154 callback_destroy(this_->motion_timeout_callback);
3155 callback_destroy(this_->progress_cb);
3157 graphics_remove_callback(this_->gra, this_->resize_callback);
3158 callback_destroy(this_->resize_callback);
3160 graphics_remove_callback(this_->gra, this_->button_callback);
3161 callback_destroy(this_->button_callback);
3163 graphics_remove_callback(this_->gra, this_->motion_callback);
3164 callback_destroy(this_->motion_callback);
3166 graphics_remove_callback(this_->gra, this_->predraw_callback);
3167 callback_destroy(this_->predraw_callback);
3168 route_destroy(this_->route);
3169 ms = navit_get_mapset(this_);
3172 graphics_free(this_->gra);