summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Rick Walsh <rickmwalsh@gmail.com>2015-06-20 15:04:05 +1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-22 17:24:56 -0700
commit26622e7e048caa952b697abee706a7936f94c39c (patch)
treef84fa4b5a200e6cf420464f3d328fee11c6a49ad /planner.c
parent21c46b8c2d17fa03596d9334710d75d8cba44d8c (diff)
downloadsubsurface-26622e7e048caa952b697abee706a7936f94c39c.tar.gz
Planner notes - revise logic for gasmix output
The logic for when to output a gasmix in the notes table is more complicated than it seems at first. - On a descent leg, the gas is the gas used for descent - At a stop (calculated or user defined), the gas is the gas used for that stop - But on an ascent leg (if displayed), the gas is the gas that is ABOUT TO BE USED - The gas should not be repeated if it's the same gas as used on the last row of the table - Ascent legs should only be displayed if the display transitions option is selected, OR if there is a gas change without a stop (the user can now set a minimum duration for a gaschange, but zero is still allowed). The existing code tries to track what gas is being used/switched to at each waypoint, and whether the gas should be printed or postponed to the next leg. It works sometimes but not always. This patch replaces the postponed gas logic with: - Is this an ascent leg? (determines whether the applicable gas is the preceding or following leg, and whether the leg should be displayed at all if the transitions option isn't selected) - Is it an ascent with a gaschange without a stop? - Has the gas actually changed from the last output? - Will the next leg be at the same level and same gas (in which case merge them)? Signed-off-by: Rick Walsh <rickmwalsh@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/planner.c b/planner.c
index aee380b7e..6fc0ac29e 100644
--- a/planner.c
+++ b/planner.c
@@ -521,9 +521,10 @@ 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[2000000], temp[100000];
- int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0;
+ int len, lastdepth = 0, lasttime = 0, lastsetpoint = -1, newdepth = 0, lastprintdepth = 0, lastprintsetpoint = -1;
+ struct gasmix lastprintgasmix = { -1, -1 };
struct divedatapoint *dp = diveplan->dp;
- bool gaschange = !plan_verbatim, postponed = plan_verbatim;
+ bool gaschange = !plan_verbatim;
struct divedatapoint *nextdp = NULL;
disclaimer = translate("gettextFromC", "DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
@@ -567,6 +568,7 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
const char *depth_unit;
double depthvalue;
int decimals;
+ bool isascent = (dp->depth < lastdepth);
nextdp = dp->next;
if (dp->time == 0)
@@ -639,6 +641,10 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
} else {
if ((dp->depth == lastdepth && nextdp && dp->depth != nextdp->depth) ||
plan_display_transitions || dp->entered || !dp->next || (gaschange && dp->next && dp->depth != nextdp->depth)) {
+ if (plan_display_transitions || dp->entered || !dp->next || dp->depth != nextdp->depth ||
+ !isascent && (gasmix_distance(&lastprintgasmix, &gasmix) || lastprintsetpoint != dp->setpoint) &&
+ ((nextdp && dp->depth != nextdp->depth) || gasmix_distance(&gasmix, &newgasmix) || (nextdp && dp->setpoint != nextdp->setpoint)) ||
+ (isascent && gaschange && nextdp && dp->depth != nextdp->depth )) {
snprintf(temp, sizeof(temp), translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
len += snprintf(buffer + len, sizeof(buffer) - len, "<tr><td style='padding-left: 10px; float: right;'>%s</td>", temp);
if (plan_display_duration) {
@@ -650,20 +656,28 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; float: right;'>%s</td>", temp);
}
- if (gaschange) {
- if(dp->depth == lastdepth && !postponed) {
- postponed = true;
- } else {
- if (dp->setpoint) {
- snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
- len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
+ if (isascent && gaschange) {
+ if (dp->setpoint) {
+ snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) nextdp->setpoint / 1000.0);
+ len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&newgasmix),
temp);
- } else {
+ } else {
len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&newgasmix));
- }
- gaschange = false;
- postponed = false;
}
+ lastprintsetpoint = nextdp->setpoint;
+ lastprintgasmix = newgasmix;
+ gaschange = false;
+ } else if (gasmix_distance(&lastprintgasmix, &gasmix) != 0 || lastprintsetpoint != dp->setpoint) {
+ if (dp->setpoint) {
+ snprintf(temp, sizeof(temp), translate("gettextFromC", "(SP = %.1fbar)"), (double) dp->setpoint / 1000.0);
+ len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s %s</b></td>", gasname(&gasmix),
+ temp);
+ } else {
+ len += snprintf(buffer + len, sizeof(buffer) - len, "<td style='padding-left: 10px; color: red; float: left;'><b>%s</b></td>", gasname(&gasmix));
+ }
+ lastprintsetpoint = dp->setpoint;
+ lastprintgasmix = gasmix;
+ gaschange = false;
} else {
len += snprintf(buffer + len, sizeof(buffer) - len, "<td>&nbsp;</td>");
}
@@ -673,9 +687,6 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
}
}
if (gaschange) {
- if(dp->depth == lastdepth && !postponed) {
- postponed = true;
- } else {
// gas switch at this waypoint
if (plan_verbatim) {
if (lastsetpoint >= 0) {
@@ -687,8 +698,6 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
len += snprintf(buffer + len, sizeof(buffer) - len, "%s<br>", temp);
}
gaschange = false;
- postponed = true;
- }
gasmix = newgasmix;
}
}