diff options
Diffstat (limited to 'profile.c')
-rw-r--r-- | profile.c | 159 |
1 files changed, 99 insertions, 60 deletions
@@ -243,7 +243,7 @@ static int get_maxdepth(struct plot_info *pi) /* Minimum 30m, rounded up to 10m, with at least 3m to spare */ md = MAX(30000, ROUND_UP(mm+3000, 10000)); } - if (GRAPHS_ENABLED) { + if (PP_GRAPHS_ENABLED) { if (md <= 20000) md += 10000; else @@ -512,7 +512,7 @@ static void plot_depth_scale(struct graphics_context *gc, struct plot_info *pi) maxdepth = get_maxdepth(pi); gc->topy = 0; gc->bottomy = maxdepth; - switch (output_units.length) { + switch (prefs.output_units.length) { case METERS: marker = 10000; break; case FEET: marker = 9144; break; /* 30 ft */ } @@ -545,7 +545,6 @@ static void plot_pp_text(struct graphics_context *gc, struct plot_info *pi) static const text_render_options_t tro = {11, PP_LINES, LEFT, MIDDLE}; setup_pp_limits(gc, pi); - pp = floor(pi->maxpp * 10.0) / 10.0 + 0.2; dpp = floor(2.0 * pp) / 10.0; hpos = pi->entry[pi->nr - 1].sec; @@ -565,13 +564,13 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p setup_pp_limits(gc, pi); - if (partial_pressure_graphs.pn2) { + if (prefs.pp_graphs.pn2) { set_source_rgba(gc, PN2); entry = pi->entry; move_to(gc, entry->sec, entry->pn2); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->pn2 < partial_pressure_graphs.pn2_threshold) + if (entry->pn2 < prefs.pp_graphs.pn2_threshold) line_to(gc, entry->sec, entry->pn2); else move_to(gc, entry->sec, entry->pn2); @@ -583,20 +582,20 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p move_to(gc, entry->sec, entry->pn2); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->pn2 >= partial_pressure_graphs.pn2_threshold) + if (entry->pn2 >= prefs.pp_graphs.pn2_threshold) line_to(gc, entry->sec, entry->pn2); else move_to(gc, entry->sec, entry->pn2); } cairo_stroke(gc->cr); } - if (partial_pressure_graphs.phe) { + if (prefs.pp_graphs.phe) { set_source_rgba(gc, PHE); entry = pi->entry; move_to(gc, entry->sec, entry->phe); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->phe < partial_pressure_graphs.phe_threshold) + if (entry->phe < prefs.pp_graphs.phe_threshold) line_to(gc, entry->sec, entry->phe); else move_to(gc, entry->sec, entry->phe); @@ -608,20 +607,20 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p move_to(gc, entry->sec, entry->phe); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->phe >= partial_pressure_graphs.phe_threshold) + if (entry->phe >= prefs.pp_graphs.phe_threshold) line_to(gc, entry->sec, entry->phe); else move_to(gc, entry->sec, entry->phe); } cairo_stroke(gc->cr); } - if (partial_pressure_graphs.po2) { + if (prefs.pp_graphs.po2) { set_source_rgba(gc, PO2); entry = pi->entry; move_to(gc, entry->sec, entry->po2); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->po2 < partial_pressure_graphs.po2_threshold) + if (entry->po2 < prefs.pp_graphs.po2_threshold) line_to(gc, entry->sec, entry->po2); else move_to(gc, entry->sec, entry->po2); @@ -633,7 +632,7 @@ static void plot_pp_gas_profile(struct graphics_context *gc, struct plot_info *p move_to(gc, entry->sec, entry->po2); for (i = 1; i < pi->nr; i++) { entry++; - if (entry->po2 >= partial_pressure_graphs.po2_threshold) + if (entry->po2 >= prefs.pp_graphs.po2_threshold) line_to(gc, entry->sec, entry->po2); else move_to(gc, entry->sec, entry->po2); @@ -696,7 +695,7 @@ static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi /* Depth markers: every 30 ft or 10 m*/ gc->leftx = 0; gc->rightx = 1.0; gc->topy = 0; gc->bottomy = maxdepth; - switch (output_units.length) { + switch (prefs.output_units.length) { case METERS: marker = 10000; break; case FEET: marker = 9144; break; /* 30 ft */ } @@ -761,7 +760,7 @@ static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi /* if the user wants the deco ceiling more visible, do that here (this * basically draws over the background that we had allowed to shine * through so far) */ - if (profile_red_ceiling) { + if (prefs.profile_red_ceiling) { pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0 * plot_scale); pattern_add_color_stop_rgba (gc, pat, 0, CEILING_SHALLOW); pattern_add_color_stop_rgba (gc, pat, 1, CEILING_DEEP); @@ -837,12 +836,12 @@ static int setup_temperature_limits(struct graphics_context *gc, struct plot_inf delta = 3000; gc->topy = maxtemp + delta*2; - if (GRAPHS_ENABLED) + if (PP_GRAPHS_ENABLED) gc->bottomy = mintemp - delta * 2; else gc->bottomy = mintemp - delta / 3; - pi->endtempcoord = SCALEY(gc, pi->endtemp); + pi->endtempcoord = SCALEY(gc, pi->mintemp); return maxtemp > mintemp; } @@ -929,7 +928,7 @@ static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_ gc->leftx = 0; gc->rightx = get_maxtime(pi); - if (GRAPHS_ENABLED) + if (PP_GRAPHS_ENABLED) gc->bottomy = -pi->maxpressure * 0.75; else gc->bottomy = 0; @@ -937,7 +936,7 @@ static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_ if (!pi->maxpressure) return FALSE; - while (pi->endtempcoord <= SCALEY(gc, pi->endpressure - (gc->topy) * 0.1)) + while (pi->endtempcoord <= SCALEY(gc, pi->minpressure - (gc->topy) * 0.1)) gc->bottomy -= gc->topy * 0.1; return TRUE; @@ -1175,27 +1174,6 @@ static struct plot_info *analyze_plot_info(struct plot_info *pi) int i; int nr = pi->nr; - /* Do pressure min/max based on the non-surface data */ - for (i = 0; i < nr; i++) { - struct plot_data *entry = pi->entry+i; - int pressure = GET_PRESSURE(entry); - int temperature = entry->temperature; - - if (pressure) { - if (pressure > pi->maxpressure) - pi->maxpressure = pressure; - pi->endpressure = pressure; - } - - if (temperature) { - if (!pi->mintemp || temperature < pi->mintemp) - pi->mintemp = temperature; - if (temperature > pi->maxtemp) - pi->maxtemp = temperature; - pi->endtemp = temperature; - } - } - /* Smoothing function: 5-point triangular smooth */ for (i = 2; i < nr; i++) { struct plot_data *entry = pi->entry+i; @@ -1450,6 +1428,73 @@ static int count_gas_change_events(struct divecomputer *dc) return count; } +static void calculate_max_limits(struct dive *dive, struct graphics_context *gc) +{ + struct divecomputer *dc; + struct plot_info *pi; + int maxdepth = 0; + int maxtime = 0; + int maxpressure = 0, minpressure = INT_MAX; + int mintemp = 0, maxtemp = 0; + int cyl; + + /* The plot-info is embedded in the graphics context */ + pi = &gc->pi; + memset(pi, 0, sizeof(*pi)); + + /* This should probably have been per-dive-computer */ + maxdepth = dive->maxdepth.mm; + mintemp = maxtemp = dive->watertemp.mkelvin; + + /* Get the per-cylinder maximum pressure if they are manual */ + for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { + unsigned int mbar = dive->cylinder[cyl].start.mbar; + if (mbar > maxpressure) + maxpressure = mbar; + } + + /* Then do all the samples from all the dive computers */ + dc = &dive->dc; + do { + int i = dc->samples; + int lastdepth = 0; + struct sample *s = dc->sample; + + while (--i >= 0) { + int depth = s->depth.mm; + int pressure = s->cylinderpressure.mbar; + int temperature = s->temperature.mkelvin; + + if (!mintemp && temperature < mintemp) + mintemp = temperature; + if (temperature > maxtemp) + maxtemp = temperature; + + if (pressure && pressure < minpressure) + minpressure = pressure; + if (pressure > maxpressure) + maxpressure = pressure; + + if (depth > maxdepth) + maxdepth = s->depth.mm; + if ((depth || lastdepth) && s->time.seconds > maxtime) + maxtime = s->time.seconds; + lastdepth = depth; + s++; + } + } while ((dc = dc->next) != NULL); + + if (minpressure > maxpressure) + minpressure = 0; + + pi->maxdepth = maxdepth; + pi->maxtime = maxtime; + pi->maxpressure = maxpressure; + pi->minpressure = minpressure; + pi->mintemp = mintemp; + pi->maxtemp = maxtemp; +} + /* * Create a plot-info with smoothing and ranged min/max * @@ -1472,7 +1517,6 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer /* The plot-info is embedded in the graphics context */ pi = &gc->pi; - memset(pi, 0, sizeof(*pi)); /* we want to potentially add synthetic plot_info elements for the gas changes */ nr = dc->samples + 4 + 2 * count_gas_change_events(dc); @@ -1576,8 +1620,6 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer lastindex = i + pi_idx; lastdepth = depth; - if (depth > pi->maxdepth) - pi->maxdepth = depth; } entry = pi->entry + i + pi_idx; /* are there still unprocessed gas changes? that would be very strange */ @@ -1699,17 +1741,6 @@ static struct plot_info *create_plot_info(struct dive *dive, struct divecomputer pi->nr = lastindex+1; while (pi->nr <= i+2 && pi->entry[pi->nr-1].depth > 0) pi->nr++; - pi->maxtime = pi->entry[lastindex].sec; - - /* Analyze_plot_info() will do the sample max pressures, - * this handles the manual pressures - */ - pi->maxpressure = 0; - for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) { - unsigned int mbar = dive->cylinder[cyl].start.mbar; - if (mbar > pi->maxpressure) - pi->maxpressure = mbar; - } pi->meandepth = dive->meandepth.mm; @@ -1767,7 +1798,11 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) dc = &fakedc; } - pi = create_plot_info(dive, dc, gc); + /* + * Set up limits that are independent of + * the dive computer + */ + calculate_max_limits(dive, gc); /* shift the drawing area so we have a nice margin around it */ cairo_translate(gc->cr, drawing_area->x, drawing_area->y); @@ -1785,6 +1820,9 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) gc->maxx = (drawing_area->width - 2*drawing_area->x); gc->maxy = (drawing_area->height - 2*drawing_area->y); + /* This is per-dive-computer. Right now we just do the first one */ + pi = create_plot_info(dive, dc, gc); + /* Depth profile */ plot_depth_profile(gc, pi); plot_events(gc, pi, dc); @@ -1819,7 +1857,7 @@ void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale) plot_text(gc, &computer, 0, 1, "%s", dc->model); } - if (GRAPHS_ENABLED) { + if (PP_GRAPHS_ENABLED) { plot_pp_gas_profile(gc, pi); plot_pp_text(gc, pi); } @@ -1884,15 +1922,15 @@ static void plot_string(struct plot_data *entry, char *buf, size_t bufsize, memcpy(buf2, buf, bufsize); snprintf(buf, bufsize, "%s\nNDL:%umin", buf2, entry->ndl / 60); } - if (partial_pressure_graphs.po2) { + if (prefs.pp_graphs.po2) { memcpy(buf2, buf, bufsize); snprintf(buf, bufsize, "%s\npO" UTF8_SUBSCRIPT_2 ":%.2f", buf2, entry->po2); } - if (partial_pressure_graphs.pn2) { + if (prefs.pp_graphs.pn2) { memcpy(buf2, buf, bufsize); snprintf(buf, bufsize, "%s\npN" UTF8_SUBSCRIPT_2 ":%.2f", buf2, entry->pn2); } - if (partial_pressure_graphs.phe) { + if (prefs.pp_graphs.phe) { memcpy(buf2, buf, bufsize); snprintf(buf, bufsize, "%s\npHe:%.2f", buf2, entry->phe); } @@ -1903,7 +1941,7 @@ void get_plot_details(struct graphics_context *gc, int time, char *buf, size_t b { struct plot_info *pi = &gc->pi; int pressure = 0, temp = 0; - struct plot_data *entry; + struct plot_data *entry = NULL; int i; for (i = 0; i < pi->nr; i++) { @@ -1915,5 +1953,6 @@ void get_plot_details(struct graphics_context *gc, int time, char *buf, size_t b if (entry->sec >= time) break; } - plot_string(entry, buf, bufsize, entry->depth, pressure, temp, pi->has_ndl); + if (entry) + plot_string(entry, buf, bufsize, entry->depth, pressure, temp, pi->has_ndl); } |