summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjandegr <jandegr@users.noreply.github.com>2016-09-01 19:03:06 +0200
committerGitHub <noreply@github.com>2016-09-01 19:03:06 +0200
commit445525bd64c9cffd84f9f0ab3ca5870b73327b25 (patch)
tree46ba191b694ff8077afb01d4c1717ce47097670f
parentc89c43a1e34d0f0b5215a7849226b732976efb2a (diff)
downloadnavit-445525bd64c9cffd84f9f0ab3ca5870b73327b25.tar.gz
gui internal : some more heightprofile fixes
-rw-r--r--navit/gui/internal/gui_internal_command.c70
1 files changed, 45 insertions, 25 deletions
diff --git a/navit/gui/internal/gui_internal_command.c b/navit/gui/internal/gui_internal_command.c
index ab17e1f97..6b2dd7252 100644
--- a/navit/gui/internal/gui_internal_command.c
+++ b/navit/gui/internal/gui_internal_command.c
@@ -453,8 +453,13 @@ gui_internal_cmd2_setting_layout(struct gui_priv *this, char *function, struct a
* displays a heightprofile if a route is active and
* some heightinfo is provided by means of a map
*
- * todo: fix a division by zero bug, provide a scale,
- * improve the representation
+ * 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
+ *
*/
static void
gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, struct attr **in, struct attr ***out, int *valid)
@@ -470,6 +475,7 @@ 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;
@@ -501,11 +507,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) {
@@ -517,6 +534,7 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
}
}
map_rect_destroy(mr);
+ mr = NULL;
}
}
mapset_close(msh);
@@ -549,7 +567,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);
}
}
}
@@ -568,7 +587,7 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
gui_internal_menu_render(this);
- if(!diagram_points)
+ if(diagram_points_count < 2) /*fixme: maybe show a flatline in such cases*/
return;
first=1;
@@ -590,27 +609,28 @@ gui_internal_cmd2_route_height_profile(struct gui_priv *this, char *function, st
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 (;;) {
- 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;
- /*fixme: sometimes division by zero below*/
- 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;
}
}