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

101
planner.c
View file

@ -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,7 +513,7 @@ 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;
@ -525,13 +524,16 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
"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_verbatim) {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "<table cellspacing=5%><thead><tr><th>depth</th>"));
if (plan_display_runtime) if (plan_display_runtime)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " runtime")); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <th>runtime</th>"));
if (plan_display_duration) if (plan_display_duration)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " duration")); len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <th>duration</th>"));
len += snprintf(buffer + len, sizeof(buffer) - len, " gas<br>"); 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)
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %d:%02d min - runtime %d:%02u on %s\n"),
decimals, depthvalue, depth_unit,
FRACTION(dp->time - lasttime, 60),
FRACTION(dp->time, 60),
gasname(&gasmix));
else
if (dp->entered || plan_display_transitions) {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
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 {
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "%3.0f%s"), depthvalue, depth_unit);
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>");
}
}
if (nextdp && gasmix_distance(&gasmix, &newgasmix)) {
// gas switch at this waypoint
if (plan_verbatim)
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s<br>"), gasname(&newgasmix));
else
gaschange = true; gaschange = true;
if (plan_verbatim) {
if (dp->depth != lastdepth) {
if (plan_display_transitions || dp->entered || !dp->next)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Transition to %.*f %s in %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 {
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)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <td align=right>%3dmin</td> "), (dp->time + 30) / 60);
if (plan_display_duration)
len += snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", " <td align=right>%3dmin</td> "), (dp->time - lasttime + 30) / 60);
if (gaschange) {
len += snprintf(buffer + len, sizeof(buffer) - len, " <td align=left style=color:red><b>%s</b></td>", gasname(&newgasmix));
gaschange = false;
} else {
len += snprintf(buffer + len, sizeof(buffer) - len, " <td><b>&nbsp;</b><td>");
}
len += snprintf(buffer + len, sizeof(buffer) - len, "</tr>");
}
}
if (gaschange) {
// gas switch at this waypoint
if (plan_verbatim) {
snprintf(buffer + len, sizeof(buffer) - len, translate("gettextFromC", "Switch gas to %s<br>"), gasname(&newgasmix));
gaschange = false;
}
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;
@ -758,7 +753,6 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
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 */
@ -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">