summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre GRANDIN <pgrandin@users.noreply.github.com>2016-09-01 12:45:24 -0700
committerGitHub <noreply@github.com>2016-09-01 12:45:24 -0700
commiteb92b88149349b31a365aa947396c1aa07cc1af7 (patch)
tree44f84687e0b18d9d4d37cfbdeae4ee06257319ca
parent911c72ebe23451d6a7a4e43cb9a8d0fbcec78c52 (diff)
parent03fe14e970bbe4e7dcd05381397f083c8eecfca2 (diff)
downloadnavit-eb92b88149349b31a365aa947396c1aa07cc1af7.tar.gz
Merge pull request #111 from navit-gps/gui_internal_heightprofileR6759
Gui internal heightprofile
-rw-r--r--navit/gui/internal/gui_internal_command.c87
1 files changed, 57 insertions, 30 deletions
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index 12de558fb..182671b35 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -446,6 +446,22 @@ gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct a
navit_attr_iter_destroy(iter);
gui_internal_menu_render(this);
}
+
+/*
+ * @brief Displays Route Height Profile
+ *
+ * displays a heightprofile if a route is active and
+ * some heightinfo is provided by means of a map
+ *
+ * the drawing is simplified by assuming straight
+ * roads between the crossings of the route and the
+ * heightlines.
+ *
+ * the name of the file providing the heightlines must
+ * comply with *.heightlines.bin
+ *
+ * todo : make it show a flat segment when using a tunnel
+ */
static void
gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
{
@@ -460,17 +476,18 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
struct mapset *ms;
struct mapset_handle *msh;
int x,i,first=1,dist=0;
+ int diagram_points_count = 0;
struct coord c,last,res;
struct coord_rect rbbox,dbbox;
struct map_selection sel;
struct heightline *heightline,*heightlines=NULL;
struct diagram_point *min,*diagram_point,*diagram_points=NULL;
+ struct point p[2];
sel.next=NULL;
sel.order=18;
sel.range.min=type_height_line_1;
sel.range.max=type_height_line_3;
-
menu=gui_internal_menu(this,_("Height Profile"));
box = gui_internal_box_new(this, gravity_left_top| orientation_vertical | flags_fill | flags_expand);
gui_internal_widget_append(menu, box);
@@ -491,11 +508,22 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
}
}
map_rect_destroy(mr);
+ mr = NULL;
ms=navit_get_mapset(this->nav);
if (!first && ms) {
msh=mapset_open(ms);
while ((map=mapset_next(msh, 1))) {
- mr=map_rect_new(map, &sel);
+ struct attr name_attr;
+ if (map_get_attr(map, attr_name, &name_attr, NULL)){
+ dbg(lvl_debug,"map name = %s\n",name_attr.u.str);
+ if (strstr(name_attr.u.str,".heightlines.bin")){
+ dbg(lvl_info,"reading heightlines from map %s\n",name_attr.u.str);
+ mr=map_rect_new(map, &sel);
+ }
+ else {
+ dbg(lvl_debug,"ignoring map %s\n",name_attr.u.str);
+ }
+ }
if (mr) {
while((item = map_rect_get_item(mr))) {
if (item->type >= sel.range.min && item->type <= sel.range.max) {
@@ -507,6 +535,7 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
}
}
map_rect_destroy(mr);
+ mr = NULL;
}
}
mapset_close(msh);
@@ -539,7 +568,8 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
diagram_point->c.y=heightline->height;
diagram_point->next=diagram_points;
diagram_points=diagram_point;
- dbg(lvl_info,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
+ diagram_points_count ++;
+ dbg(lvl_debug,"%d %d\n", diagram_point->c.x, diagram_point->c.y);
}
}
}
@@ -553,13 +583,12 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
}
}
-
if(mr)
map_rect_destroy(mr);
gui_internal_menu_render(this);
- if(!diagram_points)
+ if(diagram_points_count < 2) /*fixme: maybe show a flatline in such cases*/
return;
first=1;
@@ -573,38 +602,37 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
coord_rect_extend(&dbbox, &diagram_point->c);
diagram_point=diagram_point->next;
}
- dbg(lvl_info,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
+ dbg(lvl_debug,"%d %d %d %d\n", dbbox.lu.x, dbbox.lu.y, dbbox.rl.x, dbbox.rl.y);
if (dbbox.rl.x > dbbox.lu.x && dbbox.lu.x*100/(dbbox.rl.x-dbbox.lu.x) <= 25)
dbbox.lu.x=0;
if (dbbox.lu.y > dbbox.rl.y && dbbox.rl.y*100/(dbbox.lu.y-dbbox.rl.y) <= 25)
dbbox.rl.y=0;
- dbg(lvl_info,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
+ dbg(lvl_debug,"%d,%d %dx%d\n", box->p.x, box->p.y, box->w, box->h);
x=dbbox.lu.x;
first=1;
- for (;;) {
- struct point p[2];
- min=NULL;
- diagram_point=diagram_points;
- while (diagram_point) {
- if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
- min=diagram_point;
- diagram_point=diagram_point->next;
+ if (diagram_points_count > 1 && dbbox.rl.x != dbbox.lu.x && dbbox.lu.y != dbbox.rl.y){
+ for (;;) {
+ min=NULL;
+ diagram_point=diagram_points;
+ while (diagram_point) {
+ if (diagram_point->c.x >= x && (!min || min->c.x > diagram_point->c.x))
+ min=diagram_point;
+ diagram_point=diagram_point->next;
+ }
+ if (! min)
+ break;
+ p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
+ p[1].y=(box->h)-5-(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y;
+ dbg(lvl_debug,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
+ graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
+ if (first)
+ first=0;
+ else
+ graphics_draw_lines(this->gra, this->foreground, p, 2);
+ p[0]=p[1];
+ x=min->c.x+1;
}
- if (! min)
- break;
- p[1].x=(min->c.x-dbbox.lu.x)*(box->w-10)/(dbbox.rl.x-dbbox.lu.x)+box->p.x+5;
- p[1].y=(min->c.y-dbbox.rl.y)*(box->h-10)/(dbbox.lu.y-dbbox.rl.y)+box->p.y+5;
- dbg(lvl_info,"%d,%d=%d,%d\n",min->c.x, min->c.y, p[1].x,p[1].y);
- graphics_draw_circle(this->gra, this->foreground, &p[1], 2);
- if (first)
- first=0;
- else
- graphics_draw_lines(this->gra, this->foreground, p, 2);
- p[0]=p[1];
- x=min->c.x+1;
}
-
-
}
static void
@@ -1079,7 +1107,6 @@ error:
return;
}
-
static void
gui_internal_cmd_img(struct gui_priv * this, char *function, struct attr **in, struct attr ***out, int *valid)
{