summaryrefslogtreecommitdiff
path: root/navit/navit.c
diff options
context:
space:
mode:
Diffstat (limited to 'navit/navit.c')
-rw-r--r--navit/navit.c131
1 files changed, 119 insertions, 12 deletions
diff --git a/navit/navit.c b/navit/navit.c
index 6c22ebadb..671e5d9c0 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -180,6 +180,9 @@ struct navit {
int waypoints_flag;
struct coord_geo center;
int auto_switch; /*auto switching between day/night layout enabled ?*/
+ int tunnel_nightlayout; /* switch to nightlayout if we are in a tunnel? */
+ char* layout_before_tunnel;
+ int sunrise_degrees;
};
struct gui *main_loop_gui;
@@ -1484,6 +1487,9 @@ navit_new(struct attr *parent, struct attr **attrs) {
this_->radius = 30;
this_->border = 16;
this_->auto_switch = TRUE;
+ this_->tunnel_nightlayout = FALSE;
+ this_->layout_before_tunnel = "";
+ this_->sunrise_degrees = -5;
transform_from_geo(pro, &g, &co);
center.x=co.x;
@@ -1613,8 +1619,6 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de
}
g_free(destination_file);
- callback_list_call_attr_0(this_->attr_cbl, attr_destination);
-
if (this_->route) {
struct attr attr;
int dstcount;
@@ -1637,10 +1641,12 @@ void navit_set_destination(struct navit *this_, struct pcoord *c, const char *de
g_free(pc);
g_free(destination_file);
}
-
- if (this_->ready == 3 && !(this_->flags & 4))
- navit_draw(this_);
}
+
+ callback_list_call_attr_0(this_->attr_cbl, attr_destination);
+
+ if (this_->route && this_->ready == 3 && !(this_->flags & 4))
+ navit_draw(this_);
}
/**
@@ -1683,15 +1689,30 @@ void navit_set_destinations(struct navit *this_, struct pcoord *c, int count, co
g_free(destination_file);
} else
this_->destination_valid=0;
- callback_list_call_attr_0(this_->attr_cbl, attr_destination);
- if (this_->route) {
+ if (this_->route)
route_set_destinations(this_->route, c, count, async);
- if (this_->ready == 3)
- navit_draw(this_);
- }
+ callback_list_call_attr_0(this_->attr_cbl, attr_destination);
+ if (this_->route && this_->ready == 3)
+ navit_draw(this_);
}
+/**
+ * @brief Retrieves destinations from the route
+ *
+ * Prior to calling this method, you may want to retrieve the number of destinations by calling
+ * {@link navit_get_destination_count(struct navit *)} and assigning a buffer of sufficient capacity.
+ *
+ * If the return value equals `count`, the buffer was either just large enough or too small to hold the
+ * entire list of destinations; there is no way to tell from the result which is the case.
+ *
+ * If the Navit instance does not have a route, the result is 0.
+ *
+ * @param this_ The Navit instance
+ * @param pc Pointer to an array of projected coordinates which will receive the destination coordinates
+ * @param count Capacity of `pc`
+ * @return The number of destinations stored in `pc`, never greater than `count`
+ */
int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) {
if(!this_->route)
return 0;
@@ -1699,6 +1720,12 @@ int navit_get_destinations(struct navit *this_, struct pcoord *pc, int count) {
}
+/**
+ * @brief Get the destinations count for the route
+ *
+ * @param this The Navit instance
+ * @return destination count for the route, or 0 if the Navit instance has no route
+ */
int navit_get_destination_count(struct navit *this_) {
if(!this_->route)
return 0;
@@ -2733,6 +2760,18 @@ static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init) {
attr_updated=(this_->waypoints_flag != !!attr->u.num);
this_->waypoints_flag=!!attr->u.num;
break;
+ case attr_tunnel_nightlayout:
+ attr_updated = (this_->tunnel_nightlayout != !!attr->u.num);
+ this_->tunnel_nightlayout = !!attr->u.num;
+ break;
+ case attr_layout_daynightauto:
+ attr_updated = (this_->auto_switch != !!attr->u.num);
+ this_->auto_switch = !!attr->u.num;
+ break;
+ case attr_sunrise_degrees:
+ attr_updated = (this_->sunrise_degrees != attr->u.num);
+ this_->sunrise_degrees = attr->u.num;
+ break;
default:
dbg(lvl_debug, "calling generic setter method for attribute type %s", attr_to_name(attr->type))
return navit_object_set_attr((struct navit_object *) this_, attr);
@@ -2948,6 +2987,15 @@ int navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr,
case attr_waypoints_flag:
attr->u.num=this_->waypoints_flag;
break;
+ case attr_tunnel_nightlayout:
+ attr->u.num=this_->tunnel_nightlayout;
+ break;
+ case attr_layout_daynightauto:
+ attr->u.num=this_->auto_switch;
+ break;
+ case attr_sunrise_degrees:
+ attr->u.num=this_->sunrise_degrees;
+ break;
default:
dbg(lvl_debug, "calling generic getter method for attribute type %s", attr_to_name(type))
return navit_object_get_attr((struct navit_object *) this_, type, attr, iter);
@@ -3464,7 +3512,6 @@ navit_get_displaylist(struct navit *this_) {
return this_->displaylist;
}
-/*todo : make it switch to nightlayout when we are in a tunnel */
void navit_layout_switch(struct navit *n) {
int currTs=0;
@@ -3474,6 +3521,7 @@ void navit_layout_switch(struct navit *n) {
int year, month, day;
int after_sunrise = FALSE;
int after_sunset = FALSE;
+ int tunnel = tracking_get_current_tunnel(n->tracking);
if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
return; //No layout - nothing to switch
@@ -3495,6 +3543,33 @@ void navit_layout_switch(struct navit *n) {
if (n->auto_switch == FALSE)
return;
+ if (n->tunnel_nightlayout) {
+ if (tunnel) {
+ // store the current layout name
+ if(!strcmp(n->layout_before_tunnel, ""))
+ n->layout_before_tunnel = n->layout_current->name;
+
+ // We are in a tunnel and if we have a nightlayout -> switch to nightlayout
+ if (l->nightname) {
+ navit_set_layout_by_name(n, l->nightname);
+ dbg(lvl_debug, "tunnel -> nightlayout");
+ }
+ return;
+
+ } else {
+ if (l->dayname) {
+ if (!strcmp(l->dayname, n->layout_before_tunnel)) {
+ // restore previous layout
+ navit_set_layout_by_name(n, l->dayname);
+ dbg(lvl_debug, "tunnel end -> daylayout");
+ }
+
+ // We were in nightlayout before the tunnel, keep it
+ n->layout_before_tunnel="";
+ }
+ }
+ }
+
if (currTs-(n->prevTs)<60) {
//We've have to wait a little
return;
@@ -3506,12 +3581,15 @@ void navit_layout_switch(struct navit *n) {
&& valid_attr.u.num==attr_position_valid_invalid) {
return; //No valid fix yet
}
+
if (vehicle_get_attr(n->vehicle->vehicle, attr_position_coord_geo,&geo_attr,NULL)!=1) {
//No position - no sun
return;
}
+
//We calculate sunrise anyway, cause it is needed both for day and for night
- if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,-5,1,&trise,&tset)!=0) {
+ if (__sunriset__(year,month,day,geo_attr.u.coord_geo->lng,geo_attr.u.coord_geo->lat,n->sunrise_degrees,1,&trise,
+ &tset)!=0) {
dbg(lvl_debug,"near the pole sun never rises/sets, so we should never switch profiles");
dbg(lvl_debug,"trise: %u:%u",HOURS(trise),MINUTES(trise));
dbg(lvl_debug,"tset: %u:%u",HOURS(tset),MINUTES(tset));
@@ -3708,7 +3786,36 @@ int navit_get_blocked(struct navit *this_) {
void navit_destroy(struct navit *this_) {
dbg(lvl_debug,"enter %p",this_);
+ GList *mapsets;
+ struct map * map;
+ struct attr attr;
graphics_draw_cancel(this_->gra, this_->displaylist);
+
+ mapsets = this_->mapsets;
+ while (mapsets) {
+ GList *maps = NULL;
+ struct mapset_handle *msh;
+ msh = mapset_open(mapsets->data);
+ while (msh && (map = mapset_next(msh, 0))) {
+ /* Add traffic map (identified by the `attr_traffic` attribute) to list of maps to remove */
+ if (map_get_attr(map, attr_traffic, &attr, NULL))
+ maps = g_list_append(maps, map);
+ }
+ mapset_close(msh);
+
+ /* Remove traffic maps, if any */
+ while (maps) {
+ attr.type = attr_map;
+ attr.u.map = maps->data;
+ mapset_remove_attr(mapsets->data, &attr);
+ attr_free_content(&attr);
+ maps = g_list_next(maps);
+ }
+ if (maps)
+ g_list_free(maps);
+ mapsets = g_list_next(mapsets);
+ }
+
callback_list_call_attr_1(this_->attr_cbl, attr_destroy, this_);
attr_list_free(this_->attrs);