/**
* Navit, a modular navigation system.
- * Copyright (C) 2005-2008 Navit Team
+ * Copyright (C) 2005-2009 Navit Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
#include "param.h"
#include "menu.h"
#include "graphics.h"
-#include "cursor.h"
#include "popup.h"
#include "data_window.h"
#include "route.h"
#include "speech.h"
#include "track.h"
#include "vehicle.h"
-#include "color.h"
#include "layout.h"
#include "log.h"
#include "attr.h"
#include "navit_nls.h"
#include "util.h"
#include "messages.h"
+#include "vehicleprofile.h"
+#include "sunriset.h"
/**
* @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
int dir;
int speed;
struct coord last; /*< Position of the last update of this vehicle */
- struct color c;
- struct color *c2;
- struct cursor *cursor;
struct vehicle *vehicle;
struct attr callback;
int animate_cursor;
struct vehicleprofile *vehicleprofile;
GList *vehicleprofiles;
int pitch;
+ int follow_cursor;
+ int prevTs;
+ int graphics_flags;
+ int zoom_min, zoom_max;
};
struct gui *main_loop_gui;
static int navit_add_vehicle(struct navit *this_, struct vehicle *v);
static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init);
static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir);
+static void navit_set_cursors(struct navit *this_);
static void navit_cmd_zoom_to_route(struct navit *this);
static void navit_cmd_set_center_cursor(struct navit *this_);
+static void navit_cmd_announcer_toggle(struct navit *this_);
static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv);
void
return this_->tracking;
}
-void
+static void
navit_draw_async(struct navit *this_, int async)
{
GList *l;
navit_vehicle_draw(this_, nv, NULL);
l=g_list_next(l);
}
- graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL);
+ graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
}
void
navit_draw_async(this_, 0);
}
+int
+navit_get_ready(struct navit *this_)
+{
+ return this_->ready;
+}
+
+
void
navit_draw_displaylist(struct navit *this_)
{
if (this_->ready == 3)
- graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 1);
+ graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
}
static void
navit_handle_resize(struct navit *this_, int w, int h)
{
struct map_selection sel;
- memset(&sel, 0, sizeof(sel));
- this_->w=w;
- this_->h=h;
- sel.u.p_rect.rl.x=w;
- sel.u.p_rect.rl.y=h;
- transform_set_screen_selection(this_->trans, &sel);
+ int callback=(this_->ready == 1);
this_->ready |= 2;
- graphics_set_rect(this_->gra, &sel.u.p_rect);
+ if (this_->w != w || this_->h != h) {
+ memset(&sel, 0, sizeof(sel));
+ this_->w=w;
+ this_->h=h;
+ sel.u.p_rect.rl.x=w;
+ sel.u.p_rect.rl.y=h;
+ transform_set_screen_selection(this_->trans, &sel);
+ graphics_init(this_->gra);
+ graphics_set_rect(this_->gra, &sel.u.p_rect);
+ }
if (this_->ready == 3)
navit_draw(this_);
+ if (callback)
+ callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
}
static void
int yaw;
double angleo,anglen;
- transform_reverse(tr, old, &co);
+ if (!transform_reverse(tr, old, &co))
+ return;
if (rot) {
angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
yaw=transform_get_yaw(tr)+angleo-anglen;
transform_set_yaw(tr, yaw % 360);
}
- transform_reverse(tr, new, &cn);
+ if (!transform_reverse(tr, new, &cn))
+ return;
cp=transform_get_center(tr);
c.x=cp->x+co.x-cn.x;
c.y=cp->y+co.y-cn.y;
transform_set_center(tr, &c);
}
+static void
+navit_set_timeout(struct navit *this_)
+{
+ struct attr follow;
+ follow.type=attr_follow;
+ follow.u.num=this_->center_timeout;
+ navit_set_attr(this_, &follow);
+}
+
int
navit_handle_button(struct navit *this_, int pressed, int button, struct point *p, struct callback *popup_callback)
{
int border=16;
- callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, (void *)pressed, (void *)button, p);
+ dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
+ callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
if (this_->ignore_button) {
this_->ignore_button=0;
return 0;
this_->button_timeout=event_add_timeout(500, 0, popup_callback);
}
if (button == 2)
- navit_set_center_screen(this_, p);
+ navit_set_center_screen(this_, p, 1);
if (button == 3)
popup(this_, button, p);
if (button == 4 && this_->use_mousewheel) {
navit_zoom_out(this_, 2, p);
}
} else {
- struct attr follow;
- follow.type=attr_follow;
- follow.u.num=this_->center_timeout;
this_->button_pressed=0;
if (this_->button_timeout) {
event_remove_timeout(this_->button_timeout);
this_->button_timeout=NULL;
if (! this_->moved && ! transform_within_border(this_->trans, p, border)) {
- if (!this_->zoomed)
- navit_set_attr(this_, &follow);
- navit_set_center_screen(this_, p);
+ navit_set_center_screen(this_, p, !this_->zoomed);
}
}
if (this_->motion_timeout) {
graphics_draw_drag(this_->gra, NULL);
graphics_overlay_disable(this_->gra, 0);
if (!this_->zoomed)
- navit_set_attr(this_, &follow);
+ navit_set_timeout(this_);
navit_draw(this_);
} else
return 1;
navit_button(void *data, int pressed, int button, struct point *p)
{
struct navit *this=data;
+ dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
if (!this->ignore_graphics_events) {
if (! this->popup_callback)
this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
#if 0
graphics_displaylist_move(this_->displaylist, dx, dy);
#endif
- graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, 0);
+ graphics_draw_cancel(this_->gra, this_->displaylist);
+ graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
transform_destroy(tr);
this_->moved=1;
}
dx=(p->x-this_->pressed.x);
dy=(p->y-this_->pressed.y);
if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
+ this_->moved=1;
if (this_->button_timeout) {
event_remove_timeout(this_->button_timeout);
this_->button_timeout=NULL;
navit_scale(struct navit *this_, long scale, struct point *p, int draw)
{
struct coord c1, c2, *center;
+ if (scale < this_->zoom_min)
+ scale=this_->zoom_min;
+ if (scale > this_->zoom_max)
+ scale=this_->zoom_max;
if (p)
transform_reverse(this_->trans, p, &c1);
transform_set_scale(this_->trans, scale);
static void
navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
{
- struct coord c;
struct point pc;
int distance,w,h;
double new_scale;
transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
scale = transform_get_scale(this_->trans);
- /* We make shure that the point we want to see is within a certain range
+ /* We make sure that the point we want to see is within a certain range
* around the vehicle. The radius of this circle is the size of the
* screen. This doesn't necessarily mean the point is visible because of
* perspective etc. Quite rough, but should be enough. */
}
static struct command_table commands[] = {
- {"zoom_in",navit_cmd_zoom_in},
- {"zoom_out",navit_cmd_zoom_out},
- {"zoom_to_route",navit_cmd_zoom_to_route},
- {"set_center_cursor",navit_cmd_set_center_cursor},
+ {"zoom_in",command_cast(navit_cmd_zoom_in)},
+ {"zoom_out",command_cast(navit_cmd_zoom_out)},
+ {"zoom_to_route",command_cast(navit_cmd_zoom_to_route)},
+ {"set_center_cursor",command_cast(navit_cmd_set_center_cursor)},
+ {"announcer_toggle",command_cast(navit_cmd_announcer_toggle)},
};
this_->self.type=attr_navit;
this_->self.u.navit=this_;
this_->attr_cbl=callback_list_new();
- main_add_navit(this_);
this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
this_->autozoom_secs = 10;
this_->autozoom_min = 7;
this_->autozoom_active = 0;
+ this_->zoom_min = 1;
+ this_->zoom_max = 2097152;
+ this_->follow_cursor = 1;
this_->trans = transform_new();
transform_from_geo(pro, &g, &co);
center.x=co.x;
center.y=co.y;
center.pro = pro;
+
+ this_->prevTs=0;
transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0);
for (;*attrs; attrs++) {
return this_->gra;
}
+struct vehicleprofile *
+navit_get_vehicleprofile(struct navit *this_)
+{
+ return this_->vehicleprofile;
+}
+
+GList *
+navit_get_vehicleprofiles(struct navit *this_)
+{
+ return this_->vehicleprofiles;
+}
+
static void
navit_projection_set(struct navit *this_, enum projection pro)
{
f=fopen(file, "a");
if (f) {
if (c) {
- prostr = projection_to_name(c->pro);
+ prostr = projection_to_name(c->pro,NULL);
fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\"\n",
prostr, *prostr ? ":" : "",
c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x,
type, description);
} else
fprintf(f,"\n");
- fclose(f);
}
+ fclose(f);
}
/*
static void
navit_set_center_from_file(struct navit *this_, char *file)
{
+#ifndef HAVE_API_ANDROID
FILE *f;
char *line = NULL;
free(line);
}
return;
+#endif
}
static void
* @returns nothing
*/
void
-navit_set_destination(struct navit *this_, struct pcoord *c, const char *description)
+navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async)
{
if (c) {
this_->destination=*c;
g_free(destination_file);
callback_list_call_attr_0(this_->attr_cbl, attr_destination);
if (this_->route) {
- route_set_destination(this_->route, c);
+ route_set_destination(this_->route, c, async);
if (this_->ready == 3)
navit_draw(this_);
pc.x=c.x;
pc.y=c.y;
if (valid) {
- route_set_destination(this_->route, &pc);
+ route_set_destination(this_->route, &pc, 1);
this_->destination=pc;
this_->destination_valid=1;
}
}
-static void
+void
navit_textfile_debug_log(struct navit *this_, const char *fmt, ...)
{
va_list ap;
if (this_->textfile_debug_log && this_->vehicle) {
str1=g_strdup_vprintf(fmt, ap);
str2=g_strdup_printf("0x%x 0x%x%s%s\n", this_->vehicle->coord.x, this_->vehicle->coord.y, strlen(str1) ? " " : "", str1);
- log_write(this_->textfile_debug_log, str2, strlen(str2));
+ log_write(this_->textfile_debug_log, str2, strlen(str2), 0);
g_free(str2);
g_free(str1);
}
* @brief Toggles the navigation announcer for navit
* @param this_ The navit object
*/
-void
-navit_announcer_toggle(struct navit *this_)
+static void
+navit_cmd_announcer_toggle(struct navit *this_)
{
struct attr attr, speechattr;
attr.u.str=NULL;
if (item->type != type_nav_position) {
item_attr_get(item, attr_navigation_long, &attr);
+ if (attr.u.str == NULL) {
+ continue;
+ }
dbg(2, "Command='%s'\n", attr.u.str);
param[0].value=g_strdup(attr.u.str);
} else
void
navit_window_roadbook_new(struct navit *this_)
{
- if (this_->roadbook_callback || this_->roadbook_window) {
+ if (!this_->gui || this_->roadbook_callback || this_->roadbook_window) {
return;
}
{
struct mapset *ms;
struct map *map;
+ int callback;
+ dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
if (!this_->gui) {
dbg(0,"no gui\n");
navit_destroy(this_);
navit_destroy(this_);
return;
}
+ dbg(2,"Connecting gui to graphics\n");
if (gui_set_graphics(this_->gui, this_->gra)) {
struct attr attr_type_gui, attr_type_graphics;
gui_get_attr(this_->gui, attr_type, &attr_type_gui, NULL);
navit_destroy(this_);
return;
}
- graphics_init(this_->gra);
- if (this_->vehicle)
- navit_set_vehicle(this_, this_->vehicle);
+ dbg(2,"Initializing graphics\n");
+ dbg(2,"Setting Vehicle\n");
+ navit_set_vehicle(this_, this_->vehicle);
+ dbg(2,"Adding dynamic maps to mapset %p\n",this_->mapsets);
if (this_->mapsets) {
ms=this_->mapsets->data;
if (this_->route) {
if (this_->route)
navigation_set_route(this_->navigation, this_->route);
}
+ dbg(2,"Setting Center\n");
char *center_file = navit_get_center_file(FALSE);
navit_set_center_from_file(this_, center_file);
g_free(center_file);
navit_window_roadbook_new(this_);
navit_window_items_new(this_);
#endif
- callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
- this_->ready|=1;
messagelist_init(this_->messages);
+ navit_set_cursors(this_);
+
+ callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
+ callback=(this_->ready == 2);
+ this_->ready|=1;
+ dbg(2,"ready=%d\n",this_->ready);
if (this_->ready == 3)
navit_draw(this_);
+ if (callback)
+ callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
+#if 0
+ routech_test(this_);
+#endif
}
void
navit_zoom_to_route(this, 0);
}
+
/**
* Change the current zoom level
*
* @returns nothing
*/
void
-navit_set_center(struct navit *this_, struct pcoord *center)
+navit_set_center(struct navit *this_, struct pcoord *center, int set_timeout)
{
struct coord *c=transform_center(this_->trans);
struct coord c1,c2;
c2.y = center->y;
}
*c=c2;
+ if (set_timeout)
+ navit_set_timeout(this_);
if (this_->ready == 3)
navit_draw(this_);
}
static void
-navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p)
+navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point *p, int set_timeout)
{
int width, height;
struct point po;
po.x=width/2;
po.y=height/2;
update_transformation(this_->trans, &po, p, NULL);
+ if (set_timeout)
+ navit_set_timeout(this_);
+}
+
+/**
+ * Links all vehicles to a cursor depending on the current profile.
+ *
+ * @param this_ A navit instance
+ * @author Ralph Sennhauser (10/2009)
+ */
+static void
+navit_set_cursors(struct navit *this_)
+{
+ struct attr name;
+ struct navit_vehicle *nv;
+ struct cursor *c;
+ GList *v;
+
+ v=g_list_first(this_->vehicles); // GList of navit_vehicles
+ while (v) {
+ nv=v->data;
+ if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL))
+ c=layout_get_cursor(this_->layout_current, name.u.str);
+ else
+ c=layout_get_cursor(this_->layout_current, "default");
+ vehicle_set_cursor(nv->vehicle, c);
+ v=g_list_next(v);
+ }
+ return;
}
static int
{
int width, height;
struct navit_vehicle *nv=this_->vehicle;
+
+ float offset=30; // Cursor offset from the center of the screen (percent).
+#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 */
+ float min_offset = 0.; // Percent offset at min_offset_speed.
+ float max_offset = 30.; // Percent offset at max_offset_speed.
+ int min_offset_speed = 2; // Speed in km/h
+ int max_offset_speed = 50; // Speed ini km/h
+ // Calculate cursor offset from the center of the screen, upon speed.
+ if (nv->speed <= min_offset_speed) {
+ offset = min_offset;
+ } else if (nv->speed > max_offset_speed) {
+ offset = max_offset;
+ } else {
+ offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
+ }
+#endif
+
transform_get_size(this_->trans, &width, &height);
if (this_->orientation == -1) {
p->x=50*width/100;
- p->y=80*height/100;
+ p->y=(50 + offset)*height/100;
if (dir)
*dir=nv->dir;
} else {
mdir=nv->dir-this_->orientation;
}
- p->x=(50 - 30.*sin(M_PI*mdir/180.))*width/100;
- p->y=(50 + 30.*cos(M_PI*mdir/180.))*height/100;
+ p->x=(50 - offset*sin(M_PI*mdir/180.))*width/100;
+ p->y=(50 + offset*cos(M_PI*mdir/180.))*height/100;
if (dir)
*dir=this_->orientation;
}
struct navit_vehicle *nv=this_->vehicle;
navit_get_cursor_pnt(this_, &pn, &dir);
transform_set_yaw(this_->trans, dir);
- navit_set_center_coord_screen(this_, &nv->coord, &pn);
+ navit_set_center_coord_screen(this_, &nv->coord, &pn, 0);
navit_autozoom(this_, &nv->coord, nv->speed, 0);
if (this_->ready == 3)
navit_draw_async(this_, 1);
}
void
-navit_set_center_screen(struct navit *this_, struct point *p)
+navit_set_center_screen(struct navit *this_, struct point *p, int set_timeout)
{
struct coord c;
struct pcoord pc;
pc.x = c.x;
pc.y = c.y;
pc.pro = transform_get_projection(this_->trans);
- navit_set_center(this_, &pc);
+ navit_set_center(this_, &pc, set_timeout);
}
#if 0
int dir=0, orient_old=0, attr_updated=0;
struct coord co;
long zoom;
+ GList *l;
+ struct navit_vehicle *nv;
+ struct attr active=(struct attr){attr_active,{(void *)0}};
+ struct layout *lay;
switch (attr->type) {
case attr_autozoom:
attr_updated=(this_->drag_bitmap != !!attr->u.num);
this_->drag_bitmap=!!attr->u.num;
break;
+ case attr_flags_graphics:
+ attr_updated=(this_->graphics_flags != attr->u.num);
+ this_->graphics_flags=attr->u.num;
+ break;
case attr_follow:
if (!this_->vehicle)
return 0;
if(this_->layout_current!=attr->u.layout) {
this_->layout_current=attr->u.layout;
graphics_font_destroy_all(this_->gra);
- navit_draw(this_);
+ navit_set_cursors(this_);
+ if (this_->ready == 3)
+ navit_draw(this_);
attr_updated=1;
}
break;
+ case attr_layout_name:
+ l=this_->layouts;
+ while (l) {
+ lay=l->data;
+ if (!strcmp(lay->name,attr->u.str)) {
+ struct attr attr;
+ attr.type=attr_layout;
+ attr.u.layout=lay;
+ return navit_set_attr_do(this_, &attr, init);
+ }
+ l=g_list_next(l);
+ }
+ return 0;
case attr_orientation:
orient_old=this_->orientation;
this_->orientation=attr->u.num;
}
transform_set_yaw(this_->trans, dir);
if (orient_old != this_->orientation) {
+#if 0
if (this_->ready == 3)
navit_draw(this_);
+#endif
attr_updated=1;
}
}
this_->use_mousewheel=!!attr->u.num;
break;
case attr_vehicle:
- if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
- GList *l;
- struct navit_vehicle *nv;
- struct attr active=(struct attr){attr_active,{(void *)0}};
- l=this_->vehicles;
- while(l) {
- nv=l->data;
- if (nv->vehicle == attr->u.vehicle) {
+ l=this_->vehicles;
+ while(l) {
+ nv=l->data;
+ if (nv->vehicle == attr->u.vehicle) {
+ if (!this_->vehicle || this_->vehicle->vehicle != attr->u.vehicle) {
if (this_->vehicle)
- vehicle_set_attr(this_->vehicle->vehicle, &active, NULL);
+ vehicle_set_attr(this_->vehicle->vehicle, &active);
active.u.num=1;
- vehicle_set_attr(nv->vehicle, &active, NULL);
- navit_set_vehicle(this_, nv);
+ vehicle_set_attr(nv->vehicle, &active);
attr_updated=1;
}
- l=g_list_next(l);
+ navit_set_vehicle(this_, nv);
}
+ l=g_list_next(l);
}
break;
case attr_zoom:
if (attr_updated && !init)
navit_draw(this_);
break;
+ case attr_zoom_min:
+ attr_updated=(attr->u.num != this_->zoom_min);
+ this_->zoom_min=attr->u.num;
+ break;
+ case attr_zoom_max:
+ attr_updated=(attr->u.num != this_->zoom_max);
+ this_->zoom_max=attr->u.num;
+ break;
case attr_message:
navit_add_message(this_, attr->u.str);
break;
+ case attr_follow_cursor:
+ attr_updated=(this_->follow_cursor != !!attr->u.num);
+ this_->follow_cursor=!!attr->u.num;
+ break;
default:
return 0;
}
case attr_displaylist:
attr->u.displaylist=this_->displaylist;
return (attr->u.displaylist != NULL);
+ case attr_follow:
+ if (!this_->vehicle)
+ return 0;
+ attr->u.num=this_->vehicle->follow_curr;
+ break;
case attr_former_destination_map:
attr->u.map=this_->former_destination;
break;
case attr_osd_configuration:
attr->u.num=this_->osd_configuration;
break;
+ case attr_pitch:
+ attr->u.num=transform_get_pitch(this_->trans);
+ break;
case attr_projection:
if(this_->trans) {
attr->u.num=transform_get_projection(this_->trans);
case attr_autozoom_active:
attr->u.num=this_->autozoom_active;
break;
+ case attr_follow_cursor:
+ attr->u.num=this_->follow_cursor;
+ break;
default:
return 0;
}
}
struct attr_iter *
-navit_attr_iter_new()
+navit_attr_iter_new(void)
{
return g_new0(struct attr_iter, 1);
}
{
struct point cursor_pnt;
enum projection pro;
- struct attr cursor;
if (this_->blocked)
return;
- if (! vehicle_get_attr(nv->vehicle, attr_cursor, &cursor, NULL))
- return;
- if (! cursor.u.cursor)
- return;
if (pnt)
cursor_pnt=*pnt;
else {
pro=transform_get_projection(this_->trans);
transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
}
- cursor_draw(cursor.u.cursor, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed);
+ vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed);
#if 0
if (pnt)
pnt2=*pnt;
static void
navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
{
- struct attr attr_dir, attr_speed, attr_pos, attr_hdop, attr_time;
+ struct attr attr_valid, attr_dir, attr_speed, attr_pos;
struct pcoord cursor_pc;
struct point cursor_pnt, *pnt=&cursor_pnt;
- enum projection pro;
+ struct tracking *tracking=NULL;
+ enum projection pro=transform_get_projection(this_->trans);
int border=16;
- time_t fixtime;
- int recenter = 1; // indicates if we should recenter the map
+ int (*get_attr)(void *, enum attr_type, struct attr *, struct attr_iter *);
+ void *attr_object;
profile(0,NULL);
if (this_->ready != 3) {
profile(0,"return 1\n");
return;
}
-
- if (! vehicle_get_attr(nv->vehicle, attr_position_direction, &attr_dir, NULL) ||
- ! vehicle_get_attr(nv->vehicle, attr_position_speed, &attr_speed, NULL) ||
- ! vehicle_get_attr(nv->vehicle, attr_position_coord_geo, &attr_pos, NULL)) {
+ navit_layout_switch(this_);
+ if (this_->vehicle == nv && this_->tracking_flag)
+ tracking=this_->tracking;
+ if (tracking) {
+ tracking_update(tracking, nv->vehicle, this_->vehicleprofile, pro);
+ attr_object=tracking;
+ get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))tracking_get_attr;
+ } else {
+ attr_object=nv->vehicle;
+ get_attr=(int (*)(void *, enum attr_type, struct attr *, struct attr_iter *))vehicle_get_attr;
+ }
+ if (get_attr(attr_object, attr_position_valid, &attr_valid, NULL))
+ if (!attr_valid.u.num != attr_position_valid_invalid)
+ return;
+ if (! get_attr(attr_object, attr_position_direction, &attr_dir, NULL) ||
+ ! get_attr(attr_object, attr_position_speed, &attr_speed, NULL) ||
+ ! get_attr(attr_object, attr_position_coord_geo, &attr_pos, NULL)) {
profile(0,"return 2\n");
return;
}
nv->dir=*attr_dir.u.numd;
nv->speed=*attr_speed.u.numd;
- pro=transform_get_projection(this_->trans);
transform_from_geo(pro, attr_pos.u.coord_geo, &nv->coord);
if (nv != this_->vehicle) {
navit_vehicle_draw(this_, nv, NULL);
profile(0,"return 3\n");
return;
}
-
- if (nv->speed < 10) {
- long long diff,diff_x,diff_y;
-
- diff_x = abs(nv->coord.x - nv->last.x);
- diff_y = abs(nv->coord.y - nv->last.y);
- diff = (diff_x * diff_x) + (diff_y * diff_y);
-
- if ((diff < 20) && (diff > 0)) { // if our long is only 32 bit wide, we could run into an overflow here
- recenter = 0;
- }
- }
- if (recenter) {
- nv->last = nv->coord;
- }
-
cursor_pc.x = nv->coord.x;
cursor_pc.y = nv->coord.y;
cursor_pc.pro = pro;
- if (this_->tracking && this_->tracking_flag) {
- double zero;
- if (! vehicle_get_attr(nv->vehicle, attr_position_hdop, &attr_hdop, NULL)) {
- zero = 0.f;
- attr_hdop.u.numd = &zero;
- }
-
- if (! vehicle_get_attr(nv->vehicle, attr_position_time_iso8601, &attr_time, NULL)) {
- fixtime = time(NULL);
- } else {
- fixtime = iso8601_to_secs(attr_time.u.str);
- }
-
- if (tracking_update(this_->tracking, &cursor_pc, nv->dir, attr_hdop.u.numd, nv->speed, fixtime)) {
- nv->coord.x=cursor_pc.x;
- nv->coord.y=cursor_pc.y;
- }
- }
if (this_->route) {
- if (this_->tracking && this_->tracking_flag)
- route_set_position_from_tracking(this_->route, this_->tracking);
+ if (tracking)
+ route_set_position_from_tracking(this_->route, tracking, pro);
else
route_set_position(this_->route, &cursor_pc);
}
gui_disable_suspend(this_->gui);
transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL);
- if (this_->button_pressed != 1 && nv->follow_curr <= nv->follow &&
+ if (this_->button_pressed != 1 && this_->follow_cursor && nv->follow_curr <= nv->follow &&
(nv->follow_curr == 1 || !transform_within_border(this_->trans, &cursor_pnt, border)))
navit_set_center_cursor(this_);
else
/* Finally, if we reached our destination, stop navigation. */
if (this_->route && route_destination_reached(this_->route)) {
- navit_set_destination(this_, NULL, NULL);
+ navit_set_destination(this_, NULL, NULL, 0);
}
profile(0,"return 5\n");
}
{
struct attr attr;
this_->vehicle=nv;
- if (vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
+ if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
if (navit_set_vehicleprofile(this_, attr.u.str))
return;
}
navit_add_vehicle(struct navit *this_, struct vehicle *v)
{
struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
- struct attr follow,color,active, color2, animate;
+ struct attr follow, active, animate;
nv->vehicle=v;
nv->follow=0;
nv->last.x = 0;
nv->animate_cursor=0;
if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
nv->follow=nv->follow=follow.u.num;
- if ((vehicle_get_attr(v, attr_color, &color, NULL)))
- nv->c=*(color.u.color);
- if ((vehicle_get_attr(v, attr_color2, &color2, NULL)))
- nv->c2=color2.u.color;
- else
- nv->c2=NULL;
nv->follow_curr=nv->follow;
this_->vehicles=g_list_append(this_->vehicles, nv);
if ((vehicle_get_attr(v, attr_active, &active, NULL)) && active.u.num)
if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
nv->animate_cursor=animate.u.num;
nv->callback.type=attr_callback;
- nv->callback.u.callback=callback_new_2(callback_cast(navit_vehicle_update), this_, nv);
+ nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
vehicle_add_attr(nv->vehicle, &nv->callback);
- vehicle_set_attr(nv->vehicle, &this_->self, NULL);
+ vehicle_set_attr(nv->vehicle, &this_->self);
return 1;
}
return this_->displaylist;
}
+void
+navit_layout_switch(struct navit *n)
+{
+
+ int currTs=0;
+ struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
+ double trise,tset,trise_actual;
+ struct layout *l;
+ int year, month, day;
+
+ if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
+ return; //No layout - nothing to switch
+ }
+ if (!n->vehicle)
+ return;
+ l=layout_attr.u.layout;
+
+ if (l->dayname || l->nightname) {
+ //Ok, we know that we have profile to switch
+
+ //Check that we aren't calculating too fast
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_time_iso8601,&iso8601_attr,NULL)==1) {
+ currTs=iso8601_to_secs(iso8601_attr.u.str);
+ dbg(1,"currTs: %u:%u\n",currTs%86400/3600,((currTs%86400)%3600)/60);
+ }
+ if (currTs-(n->prevTs)<60) {
+ //We've have to wait a little
+ return;
+ }
+ if (sscanf(iso8601_attr.u.str,"%d-%02d-%02dT",&year,&month,&day) != 3)
+ return;
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
+ //No position - no sun
+ return;
+ }
+ if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
+ return; //No valid fix yet
+ }
+
+ //We calculate sunrise anyway, cause it is needed both for day and for night
+ if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,35,1,&trise,&tset)!=0) {
+ //near the pole sun never rises/sets, so we should never switch profiles
+ n->prevTs=currTs;
+ return;
+ }
+
+ trise_actual=trise;
+ dbg(1,"trise: %u:%u\n",HOURS(trise),MINUTES(trise));
+ if (l->dayname) {
+
+ if ((HOURS(trise)*60+MINUTES(trise)==(currTs%86400)/60) ||
+ (n->prevTs==0 && ((HOURS(trise)*60+MINUTES(trise)<(currTs%86400)/60)))) {
+ //The sun is rising now!
+ if (strcmp(l->name,l->dayname)) {
+ navit_set_layout_by_name(n,l->dayname);
+ }
+ }
+ }
+ if (l->nightname) {
+ if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lat,geo_attr.u.coord_geo->lng,-24,0,&trise,&tset)!=0) {
+ //near the pole sun never rises/sets, so we should never switch profiles
+ n->prevTs=currTs;
+ return;
+ }
+ dbg(1,"tset: %u:%u\n",HOURS(tset),MINUTES(tset));
+ if (HOURS(tset)*60+MINUTES(tset)==((currTs%86400)/60)
+ || (n->prevTs==0 && (((HOURS(tset)*60+MINUTES(tset)<(currTs%86400)/60)) ||
+ ((HOURS(trise_actual)*60+MINUTES(trise_actual)>(currTs%86400)/60))))) {
+ //Time to sleep
+ if (strcmp(l->name,l->nightname)) {
+ navit_set_layout_by_name(n,l->nightname);
+ }
+ }
+ }
+
+ n->prevTs=currTs;
+ }
+}
+
+int
+navit_set_layout_by_name(struct navit *n,char *name)
+{
+ struct layout *l;
+ struct attr_iter iter;
+ struct attr layout_attr;
+
+ iter.u.list=0x00;
+
+ if (navit_get_attr(n,attr_layout,&layout_attr,&iter)!=1) {
+ return 0; //No layouts - nothing to do
+ }
+ if (iter.u.list==NULL) {
+ return 0;
+ }
+
+ iter.u.list=g_list_first(iter.u.list);
+
+ while(iter.u.list) {
+ l=(struct layout*)iter.u.list->data;
+ if (!strcmp(name,l->name)) {
+ layout_attr.u.layout=l;
+ layout_attr.type=attr_layout;
+ navit_set_attr(n,&layout_attr);
+ iter.u.list=g_list_first(iter.u.list);
+ return 1;
+ }
+ iter.u.list=g_list_next(iter.u.list);
+ }
+
+ iter.u.list=g_list_first(iter.u.list);
+ return 0;
+}
+
int
navit_block(struct navit *this_, int block)
{
/* TODO: destroy objects contained in this_ */
if (this_->vehicle)
vehicle_destroy(this_->vehicle->vehicle);
- main_remove_navit(this_);
char *center_file = navit_get_center_file(TRUE);
navit_write_center_to_file(this_, center_file);
g_free(center_file);