Planner note logic and layout improved

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Robert C. Helling 2014-06-03 11:38:24 +02:00 committed by Dirk Hohndel
parent 6699e3ab3e
commit 575a092e7e
3 changed files with 73 additions and 64 deletions

115
planner.c
View file

@ -56,7 +56,7 @@ bool diveplan_empty(struct diveplan *diveplan)
if (!diveplan || !diveplan->dp) if (!diveplan || !diveplan->dp)
return true; return true;
dp = diveplan->dp; dp = diveplan->dp;
while(dp) { while (dp) {
if (dp->time) if (dp->time)
return false; return false;
dp = dp->next; dp = dp->next;
@ -316,7 +316,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
sample->time.seconds = lasttime = time; sample->time.seconds = lasttime = time;
sample->depth.mm = lastdepth = depth; sample->depth.mm = lastdepth = depth;
update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds, update_cylinder_pressure(dive, sample[-1].depth.mm, depth, time - sample[-1].time.seconds,
dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl); dp->entered ? diveplan->bottomsac : diveplan->decosac, cyl);
sample->cylinderpressure.mbar = cyl->end.mbar; sample->cylinderpressure.mbar = cyl->end.mbar;
finish_sample(dc); finish_sample(dc);
dp = dp->next; dp = dp->next;
@ -409,7 +409,6 @@ struct gaschanges {
}; };
static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder) static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder)
{ {
struct gasmix gas; struct gasmix gas;
@ -514,24 +513,27 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
int len, gasidx, lastdepth = 0, lasttime = 0; int len, gasidx, lastdepth = 0, lasttime = 0;
struct divedatapoint *dp = diveplan->dp; struct divedatapoint *dp = diveplan->dp;
const char *disclaimer = ""; const char *disclaimer = "";
bool gaschange = true; bool gaschange = !plan_verbatim;
if (!dp) if (!dp)
return; return;
if (show_disclaimer) if (show_disclaimer)
disclaimer = translate("gettextFromC", "<b>DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN " disclaimer = translate("gettextFromC", "<b>DISCLAIMER / WARNING: THIS IS A NEW IMPLEMENTATION OF THE BUHLMANN "
"ALGORITHM AND A DIVE PLANNER IMPLEMENTION BASED ON THAT WHICH HAS " "ALGORITHM AND A DIVE PLANNER IMPLEMENTION BASED ON THAT WHICH HAS "
"RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO " "RECEIVED ONLY A LIMITED AMOUNT OF TESTING. WE STRONGLY RECOMMEND NOT TO "
"PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE.</b>"); "PLAN DIVES SIMPLY BASED ON THE RESULTS GIVEN HERE.</b>");
len = snprintf(buffer, sizeof(buffer), len = snprintf(buffer, sizeof(buffer),
translate("gettextFromC", "%s<br>Subsurface dive plan\nbased on GFlow = %d and GFhigh = %d<br><br>depth"), translate("gettextFromC", "%s<br>Subsurface dive plan\nbased on GFlow = %d and GFhigh = %d<br><br>"),
disclaimer, diveplan->gflow, diveplan->gfhigh); disclaimer, diveplan->gflow, diveplan->gfhigh);
if (plan_display_runtime) if (!plan_verbatim) {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " runtime")); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "<table cellspacing=5%><thead><tr><th>depth</th>"));
if (plan_display_duration) if (plan_display_runtime)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " duration")); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <th>runtime</th>"));
len += snprintf(buffer + len, sizeof(buffer) - len, " gas<br>"); if (plan_display_duration)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <th>duration</th>"));
len += snprintf(buffer + len, sizeof(buffer) - len, " <th align=left>gas</th></tr><tbody align=right>");
}
do { do {
struct gasmix gasmix, newgasmix; struct gasmix gasmix, newgasmix;
const char *depth_unit; const char *depth_unit;
@ -561,59 +563,52 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
continue; continue;
gasidx = get_gasidx(dive, &gasmix); gasidx = get_gasidx(dive, &gasmix);
len = strlen(buffer); len = strlen(buffer);
if (dp->depth != lastdepth) { if (nextdp && gasmix_distance(&gasmix, &newgasmix))
if (plan_display_transitions && plan_verbatim) gaschange = true;
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n"), if (plan_verbatim) {
decimals, depthvalue, depth_unit, if (dp->depth != lastdepth) {
FRACTION(dp->time - lasttime, 60), if (plan_display_transitions || dp->entered || !dp->next)
FRACTION(dp->time, 60), len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s<br>"),
gasname(&gasmix)); decimals, depthvalue, depth_unit,
else FRACTION(dp->time - lasttime, 60),
if (dp->entered || plan_display_transitions) { FRACTION(dp->time, 60),
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); gasname(&gasmix));
if (plan_display_runtime)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " %3dmin "), (dp->time + 30) / 60);
if (plan_display_duration)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " %3dmin "), (dp->time - lasttime + 30) / 60);
if (gaschange) {
len += snprintf(buffer + len, sizeof(buffer) - len, " <b>%s</b>", gasname(&newgasmix));
gaschange = false;
}
len += snprintf(buffer + len, sizeof(buffer) - len, "<br>");
}
} else {
if (plan_verbatim) {
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s<br>"),
decimals, depthvalue, depth_unit,
FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60),
gasname(&gasmix));
} else { } else {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Stay at %.*f %s for %d:%02d min - runtime %d:%02u on %s<br>"),
decimals, depthvalue, depth_unit,
FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60),
gasname(&gasmix));
}
} else {
if (dp->depth == lastdepth || plan_display_transitions || dp->entered || !dp->next) {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "<tr><td align=right>%3.0f%s</td>"), depthvalue, depth_unit);
if (plan_display_runtime) if (plan_display_runtime)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " %3dmin "), (dp->time + 30) / 60); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <td align=right>%3dmin</td> "), (dp->time + 30) / 60);
if (plan_display_duration) if (plan_display_duration)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " %3dmin "), (dp->time - lasttime + 30) / 60); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <td align=right>%3dmin</td> "), (dp->time - lasttime + 30) / 60);
if (gaschange) { if (gaschange) {
len += snprintf(buffer + len, sizeof(buffer) - len, " <b>%s</b>", gasname(&newgasmix)); len += snprintf(buffer + len, sizeof(buffer) - len, " <td align=left style=color:red><b>%s</b></td>", gasname(&newgasmix));
gaschange = false; gaschange = false;
} else {
len += snprintf(buffer + len, sizeof(buffer) - len, " <td><b>&nbsp;</b><td>");
} }
len += snprintf(buffer + len, sizeof(buffer) - len, "<br>"); len += snprintf(buffer + len, sizeof(buffer) - len, "</tr>");
} }
} }
if (nextdp && gasmix_distance(&gasmix, &newgasmix)) { if (gaschange) {
// gas switch at this waypoint // gas switch at this waypoint
if (plan_verbatim) if (plan_verbatim) {
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s<br>"), gasname(&newgasmix)); snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s<br>"), gasname(&newgasmix));
else gaschange = false;
gaschange = true; }
gasmix = newgasmix; gasmix = newgasmix;
} }
lasttime = dp->time; lasttime = dp->time;
lastdepth = dp->depth; lastdepth = dp->depth;
} while ((dp = dp->next) != NULL); } while ((dp = dp->next) != NULL);
len = strlen(buffer); len = strlen(buffer);
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "\nGas consumption:\n")); snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "</tbody></table><br>Gas consumption:\n"));
for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) { for (gasidx = 0; gasidx < MAX_CYLINDERS; gasidx++) {
double volume; double volume;
const char *unit; const char *unit;
@ -661,7 +656,7 @@ int ascend_velocity(int depth, int avg_depth, int bottom_time)
if (depth <= 6000) if (depth <= 6000)
return 1000 / 60; return 1000 / 60;
if (depth * 4 > avg_depth *3) if (depth * 4 > avg_depth * 3)
return 9000 / 60; return 9000 / 60;
else else
return 6000 / 60; return 6000 / 60;
@ -756,9 +751,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
gas = dive->cylinder[current_cylinder].gasmix; gas = dive->cylinder[current_cylinder].gasmix;
#if DEBUG_PLAN & 16 #if DEBUG_PLAN & 16
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", best_first_ascend_cylinder, printf("switch to gas %d (%d/%d) @ %5.2lfm\n", best_first_ascend_cylinder,
(gas.o2.permille + 5) / 10, (gas.he.permille + 5) / 10, gaschanges[best_first_ascend_cylinder].depth / 1000.0); (gas.o2.permille + 5) / 10, (gas.he.permille + 5) / 10, gaschanges[best_first_ascend_cylinder].depth / 1000.0);
#endif #endif
} }
while (1) { while (1) {
/* We will break out when we hit the surface */ /* We will break out when we hit the surface */
@ -780,7 +774,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
} while (depth > stoplevels[stopidx]); } while (depth > stoplevels[stopidx]);
if (depth <= 0) if (depth <= 0)
break; /* We are at the surface */ break; /* We are at the surface */
if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) { if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) {
@ -794,7 +788,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
gas = dive->cylinder[current_cylinder].gasmix; gas = dive->cylinder[current_cylinder].gasmix;
#if DEBUG_PLAN & 16 #if DEBUG_PLAN & 16
printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx, printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
(gas.o2.permille + 5) / 10, (gas.he.permille + 5) / 10, gaschanges[gi].depth / 1000.0); (gas.o2.permille + 5) / 10, (gas.he.permille + 5) / 10, gaschanges[gi].depth / 1000.0);
#endif #endif
gi--; gi--;
} }
@ -804,13 +798,13 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
/* Save the current state and try to ascend to the next stopdepth */ /* Save the current state and try to ascend to the next stopdepth */
int trial_depth = depth; int trial_depth = depth;
cache_deco_state(tissue_tolerance, &trial_cache); cache_deco_state(tissue_tolerance, &trial_cache);
while(1) { while (1) {
/* Check if ascending to next stop is clear, go back and wait if we hit the ceiling on the way */ /* Check if ascending to next stop is clear, go back and wait if we hit the ceiling on the way */
clear_to_ascend = true; clear_to_ascend = true;
while (trial_depth > stoplevels[stopidx]) { while (trial_depth > stoplevels[stopidx]) {
int deltad = ascend_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP; int deltad = ascend_velocity(trial_depth, avg_depth, bottom_time) * TIMESTEP;
tissue_tolerance = add_segment(depth_to_mbar(trial_depth, dive) / 1000.0, &dive->cylinder[current_cylinder].gasmix, TIMESTEP, po2, dive); tissue_tolerance = add_segment(depth_to_mbar(trial_depth, dive) / 1000.0, &dive->cylinder[current_cylinder].gasmix, TIMESTEP, po2, dive);
if (deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1) > trial_depth - deltad){ if (deco_allowed_depth(tissue_tolerance, diveplan->surface_pressure / 1000.0, dive, 1) > trial_depth - deltad) {
/* We should have stopped */ /* We should have stopped */
clear_to_ascend = false; clear_to_ascend = false;
break; break;
@ -819,8 +813,8 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
} }
restore_deco_state(trial_cache); restore_deco_state(trial_cache);
if(clear_to_ascend) if (clear_to_ascend)
break; /* We did not hit the ceiling */ break; /* We did not hit the ceiling */
/* Add a minute of deco time and then try again */ /* Add a minute of deco time and then try again */
if (!stopping) { if (!stopping) {
@ -841,7 +835,6 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
previous_point_time = clock; previous_point_time = clock;
stopping = false; stopping = false;
} }
} }
/* We made it to the surface */ /* We made it to the surface */

View file

@ -2,6 +2,9 @@
<ui version="4.0"> <ui version="4.0">
<class>DivePlanner</class> <class>DivePlanner</class>
<widget class="QWidget" name="DivePlanner"> <widget class="QWidget" name="DivePlanner">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -195,18 +198,24 @@
<string>In diveplan, list transitions or treat them as implicit</string> <string>In diveplan, list transitions or treat them as implicit</string>
</property> </property>
<property name="text"> <property name="text">
<string>display transitions</string> <string>display transitions in deco</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QCheckBox" name="display_duration"> <widget class="QCheckBox" name="display_duration">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip"> <property name="toolTip">
<string>In dive plan, show duration (relative time) of stops</string> <string>In dive plan, show duration (relative time) of stops</string>
</property> </property>
<property name="text"> <property name="text">
<string>display segment duration</string> <string>display segment duration</string>
</property> </property>
<property name="checked">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="7" column="0">

View file

@ -63,6 +63,9 @@
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="page_2"> <widget class="QWidget" name="page_2">
<property name="enabled">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
@ -80,7 +83,11 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="DivePlannerWidget" name="divePlannerWidget" native="true"/> <widget class="DivePlannerWidget" name="divePlannerWidget" native="true">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -497,7 +504,7 @@
</property> </property>
<widget class="QStackedWidget" name="diveListPane"> <widget class="QStackedWidget" name="diveListPane">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="DiveListView" name="ListWidget"> <widget class="DiveListView" name="ListWidget">
<property name="alternatingRowColors"> <property name="alternatingRowColors">