Improve profile display in planner

This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:

1) In dive.h, create a new dc attribute dc->last_manual_time
   with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
   dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
   element, named last-manual-time. For dive plans, the element would
   now look like:
   <divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
   XML attribute, reads the time value and assigns this time to
   dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
   insert code that sets the appropriate boolean value to dp->entered
   by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
   the dive log, whether hand-entered or loaded from dive computer. It
   looks like the reduction of dive points for dives with >100 points
   continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.

Improvements: Improve code for profile display in dive planner

This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.

Several stylistic changes in text for consistent C source code.

Improvement of dive planner profile display:

Do some simplification of my alterations to diveplannermodel.cpp

Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This commit is contained in:
Willem Ferguson 2018-01-15 14:51:47 +02:00 committed by Dirk Hohndel
parent 7594e7ca7f
commit 9a8bab21c9
7 changed files with 20 additions and 5 deletions

View file

@ -295,7 +295,7 @@ struct extra_data {
*/
struct divecomputer {
timestamp_t when;
duration_t duration, surfacetime;
duration_t duration, surfacetime, last_manual_time;
depth_t maxdepth, meandepth;
temperature_t airtemp, watertemp;
pressure_t surface_pressure;

View file

@ -692,6 +692,9 @@ static void parse_dc_duration(char *line, struct membuffer *str, void *_dc)
static void parse_dc_dctype(char *line, struct membuffer *str, void *_dc)
{ (void) str; struct divecomputer *dc = _dc; dc->divemode = get_dctype(line); }
static void parse_dc_lastmanualtime(char *line, struct membuffer *str, void *_dc)
{ (void) str; struct divecomputer *dc = _dc; dc->last_manual_time = get_duration(line); }
static void parse_dc_maxdepth(char *line, struct membuffer *str, void *_dc)
{ (void) str; struct divecomputer *dc = _dc; dc->maxdepth = get_depth(line); }
@ -979,7 +982,7 @@ struct keyword_action dc_action[] = {
#undef D
#define D(x) { #x, parse_dc_ ## x }
D(airtemp), D(date), D(dctype), D(deviceid), D(diveid), D(duration),
D(event), D(keyvalue), D(maxdepth), D(meandepth), D(model), D(numberofoxygensensors),
D(event), D(keyvalue), D(lastmanualtime), D(maxdepth), D(meandepth), D(model), D(numberofoxygensensors),
D(salinity), D(surfacepressure), D(surfacetime), D(time), D(watertemp)
};

View file

@ -734,6 +734,8 @@ static int match_dc_data_fields(struct divecomputer *dc, const char *name, char
return 1;
if (MATCH("divetimesec", duration, &dc->duration))
return 1;
if (MATCH("last-manual-time", duration, &dc->last_manual_time))
return 1;
if (MATCH("surfacetime", duration, &dc->surfacetime))
return 1;
if (MATCH("airtemp", temperature, &dc->airtemp))

View file

@ -259,7 +259,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
struct event *ev;
cylinder_t *cyl;
int oldpo2 = 0;
int lasttime = 0;
int lasttime = 0, last_manual_point = 0;
depth_t lastdepth = {.mm = 0};
int lastcylid;
enum dive_comp_type type = dive->dc.divemode;
@ -342,6 +342,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
sample[-1].setpoint.mbar = po2;
sample->setpoint.mbar = po2;
sample->time.seconds = lasttime = time;
if (dp->entered) last_manual_point = dp->time;
sample->depth = lastdepth = depth;
sample->manually_entered = dp->entered;
sample->sac.mliter = dp->entered ? prefs.bottomsac : prefs.decosac;
@ -354,6 +355,8 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
finish_sample(dc);
dp = dp->next;
}
dive->dc.last_manual_time.seconds = last_manual_point;
dc->divemode = type;
#if DEBUG_PLAN & 32
save_dive(stdout, &displayed_dive);

View file

@ -395,6 +395,8 @@ static void save_events(struct membuffer *b, struct dive *dive, struct event *ev
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc)
{
show_utf8(b, "model ", dc->model, "\n");
if (dc->last_manual_time.seconds)
put_duration(b, dc->last_manual_time, "lastmanualtime ", "min\n");
if (dc->deviceid)
put_format(b, "deviceid %08x\n", dc->deviceid);
if (dc->diveid)

View file

@ -387,6 +387,8 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer
{
put_format(b, " <divecomputer");
show_utf8(b, dc->model, " model='", "'", 1);
if (dc->last_manual_time.seconds)
put_duration(b, dc->last_manual_time, " last-manual-time='", " min'");
if (dc->deviceid)
put_format(b, " deviceid='%08x'", dc->deviceid);
if (dc->diveid)

View file

@ -82,7 +82,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
struct divecomputer *dc = &(d->dc);
recalc = false;
CylindersModel::instance()->updateDive();
duration_t lasttime = {};
duration_t lasttime = { 0 };
duration_t lastrecordedtime = {};
duration_t newtime = {};
free_dps(&diveplan);
@ -108,6 +108,8 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
int cylinderid = 0;
last_sp.mbar = 0;
for (int i = 0; i < plansamples - 1; i++) {
if (dc->last_manual_time.seconds && lasttime.seconds >= dc->last_manual_time.seconds)
break;
while (j * plansamples <= i * dc->samples) {
const sample &s = dc->sample[j];
if (s.time.seconds != 0 && (!hasMarkedSamples || s.manually_entered)) {
@ -130,7 +132,8 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
}
}
// make sure we get the last point right so the duration is correct
if (!hasMarkedSamples) addStop(0, d->dc.duration.seconds,cylinderid, last_sp.mbar, true);
if (!hasMarkedSamples && !dc->last_manual_time.seconds)
addStop(0, d->dc.duration.seconds,cylinderid, last_sp.mbar, true);
recalc = oldRec;
emitDataChanged();
}