From 61961b11ad5530f612fd36f08d5b7c75c7abe64d Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Fri, 21 Nov 2014 14:53:51 +0100 Subject: Print gas changes at the correct lines in diveplan This is a pain. We plan with segments but the plan shows waypoints. If after a constant depth segment the gaschange (or setpoint chenge for that matter) appears, the _next_ line should get the info about the new gas (i.e. change _after_ the constant depth segment). If, however, the gas is changed after a transition, the final waypoint of the transition gets the gas printed. And all is different for a verbatim plan, where the gas change is an event rather than part of a segment. Signed-off-by: Robert C. Helling Signed-off-by: Dirk Hohndel --- planner.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/planner.c b/planner.c index c734cc09a..2de66e1b3 100644 --- a/planner.c +++ b/planner.c @@ -514,9 +514,9 @@ static unsigned int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error) { char buffer[20000], temp[1000]; - int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1; + int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0; struct divedatapoint *dp = diveplan->dp; - bool gaschange = !plan_verbatim; + bool gaschange = !plan_verbatim, postponed = plan_verbatim; struct divedatapoint *nextdp = NULL; disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN " @@ -577,13 +577,14 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool nextdp && dp->setpoint == nextdp->setpoint && dp->depth != lastdepth && - nextdp->depth != dp->depth) + nextdp->depth != dp->depth + && !gaschange) continue; if (dp->time - lasttime < 10 && !(gaschange && dp->next && dp->depth != dp->next->depth)) continue; len = strlen(buffer); - if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != lastsetpoint)) + if (nextdp && (gasmix_distance(&gasmix, &newgasmix) || dp->setpoint != nextdp->setpoint)) gaschange = true; if (plan_verbatim) { if (dp->depth != lastdepth) { @@ -604,6 +605,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool gasname(&gasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); + newdepth = dp->depth; lasttime = dp->time; } } else { @@ -623,6 +625,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool gasname(&gasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); + newdepth = dp->depth; lasttime = dp->time; } } @@ -638,38 +641,50 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool snprintf(temp, sizeof(temp), translate("gettextFromC", "%3dmin"), (dp->time - lasttime + 30) / 60); len += snprintf(buffer + len, sizeof(buffer) - len, "%s", temp); } + if (gaschange) { - if (dp->setpoint) { - snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0); - len += snprintf(buffer + len, sizeof(buffer) - len, "%s %s", gasname(&newgasmix), - temp); + if(dp->depth == lastdepth && !postponed) { + postponed = true; } else { - len += snprintf(buffer + len, sizeof(buffer) - len, "%s", gasname(&newgasmix)); + if (dp->setpoint) { + snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0); + len += snprintf(buffer + len, sizeof(buffer) - len, "%s %s", gasname(&newgasmix), + temp); + } else { + len += snprintf(buffer + len, sizeof(buffer) - len, "%s", gasname(&newgasmix)); + } + gaschange = false; + postponed = false; } - gaschange = false; } else { len += snprintf(buffer + len, sizeof(buffer) - len, " "); } len += snprintf(buffer + len, sizeof(buffer) - len, ""); + newdepth = dp->depth; lasttime = dp->time; } } if (gaschange) { + if(dp->depth == lastdepth && !postponed) { + postponed = true; + } else { // gas switch at this waypoint if (plan_verbatim) { if (lastsetpoint >= 0) { - if (dp->setpoint) - snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) dp->setpoint / 1000.0); + if (nextdp && nextdp->setpoint) + snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s (SP = %.1fbar)"), gasname(&newgasmix), (double) nextdp->setpoint / 1000.0); else snprintf(temp, sizeof(temp), translate("gettextFromC", "Switch gas to %s"), gasname(&newgasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, "%s
", temp); } gaschange = false; + postponed = true; } gasmix = newgasmix; + } } - lastdepth = dp->depth; + lastdepth = newdepth; lastsetpoint = dp->setpoint; } while ((dp = nextdp) != NULL); len += snprintf(buffer + len, sizeof(buffer) - len, ""); -- cgit v1.2.3-70-g09d2