mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Next step to using gasmix instead of o2/he
This changes the divedatapoints and functions that deal with them. It changes plan_add_segment(), create_dp(), gasToStr(), and tankInUse() to consume gasmix instead of o2/he. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
2bf46381a8
commit
fe773241ee
5 changed files with 58 additions and 61 deletions
13
dive.h
13
dive.h
|
@ -113,6 +113,11 @@ static inline bool is_air(int o2, int he)
|
||||||
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
return (he == 0) && (o2 == 0 || ((o2 >= O2_IN_AIR - 1) && (o2 <= O2_IN_AIR + 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool gasmix_is_air(const struct gasmix *gasmix)
|
||||||
|
{
|
||||||
|
return is_air(gasmix->o2.permille, gasmix->he.permille);
|
||||||
|
}
|
||||||
|
|
||||||
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
|
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
|
||||||
static inline int interpolate(int a, int b, int part, int whole)
|
static inline int interpolate(int a, int b, int part, int whole)
|
||||||
{
|
{
|
||||||
|
@ -626,11 +631,11 @@ extern void set_gf(short gflow, short gfhigh, bool gf_low_at_maxdepth);
|
||||||
extern void cache_deco_state(double, char **datap);
|
extern void cache_deco_state(double, char **datap);
|
||||||
extern double restore_deco_state(char *data);
|
extern double restore_deco_state(char *data);
|
||||||
|
|
||||||
|
/* this should be converted to use our types */
|
||||||
struct divedatapoint {
|
struct divedatapoint {
|
||||||
int time;
|
int time;
|
||||||
unsigned int depth;
|
unsigned int depth;
|
||||||
int o2;
|
struct gasmix gasmix;
|
||||||
int he;
|
|
||||||
int po2;
|
int po2;
|
||||||
bool entered;
|
bool entered;
|
||||||
struct divedatapoint *next;
|
struct divedatapoint *next;
|
||||||
|
@ -646,9 +651,9 @@ struct diveplan {
|
||||||
struct divedatapoint *dp;
|
struct divedatapoint *dp;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered);
|
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, struct gasmix gasmix, int po2, bool entered);
|
||||||
void get_gas_string(int o2, int he, char *buf, int len);
|
void get_gas_string(int o2, int he, char *buf, int len);
|
||||||
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
|
struct divedatapoint *create_dp(int time_incr, int depth, struct gasmix gasmix, int po2);
|
||||||
#if DEBUG_PLAN
|
#if DEBUG_PLAN
|
||||||
void dump_plan(struct diveplan *diveplan);
|
void dump_plan(struct diveplan *diveplan);
|
||||||
#endif
|
#endif
|
||||||
|
|
47
planner.c
47
planner.c
|
@ -121,7 +121,6 @@ double tissue_at_end(struct dive *dive, char **cached_datap)
|
||||||
struct divecomputer *dc;
|
struct divecomputer *dc;
|
||||||
struct sample *sample, *psample;
|
struct sample *sample, *psample;
|
||||||
int i, t0, t1, gasidx, lastdepth;
|
int i, t0, t1, gasidx, lastdepth;
|
||||||
int o2, he;
|
|
||||||
double tissue_tolerance;
|
double tissue_tolerance;
|
||||||
struct gasmix gas;
|
struct gasmix gas;
|
||||||
|
|
||||||
|
@ -264,7 +263,8 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
|
||||||
sample->po2 = dp->po2;
|
sample->po2 = dp->po2;
|
||||||
finish_sample(dc);
|
finish_sample(dc);
|
||||||
while (dp) {
|
while (dp) {
|
||||||
int o2 = dp->o2, he = dp->he;
|
int o2 = get_o2(&dp->gasmix);
|
||||||
|
int he = get_he(&dp->gasmix);
|
||||||
int po2 = dp->po2;
|
int po2 = dp->po2;
|
||||||
int time = dp->time;
|
int time = dp->time;
|
||||||
int depth = dp->depth;
|
int depth = dp->depth;
|
||||||
|
@ -352,15 +352,14 @@ void free_dps(struct divedatapoint *dp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2)
|
struct divedatapoint *create_dp(int time_incr, int depth, struct gasmix gasmix, int po2)
|
||||||
{
|
{
|
||||||
struct divedatapoint *dp;
|
struct divedatapoint *dp;
|
||||||
|
|
||||||
dp = malloc(sizeof(struct divedatapoint));
|
dp = malloc(sizeof(struct divedatapoint));
|
||||||
dp->time = time_incr;
|
dp->time = time_incr;
|
||||||
dp->depth = depth;
|
dp->depth = depth;
|
||||||
dp->o2 = o2;
|
dp->gasmix = gasmix;
|
||||||
dp->he = he;
|
|
||||||
dp->po2 = po2;
|
dp->po2 = po2;
|
||||||
dp->entered = false;
|
dp->entered = false;
|
||||||
dp->next = NULL;
|
dp->next = NULL;
|
||||||
|
@ -371,6 +370,7 @@ struct divedatapoint *get_nth_dp(struct diveplan *diveplan, int idx)
|
||||||
{
|
{
|
||||||
struct divedatapoint **ldpp, *dp = diveplan->dp;
|
struct divedatapoint **ldpp, *dp = diveplan->dp;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
struct gasmix air = { 0 };
|
||||||
ldpp = &diveplan->dp;
|
ldpp = &diveplan->dp;
|
||||||
|
|
||||||
while (dp && i++ < idx) {
|
while (dp && i++ < idx) {
|
||||||
|
@ -378,7 +378,7 @@ struct divedatapoint *get_nth_dp(struct diveplan *diveplan, int idx)
|
||||||
dp = dp->next;
|
dp = dp->next;
|
||||||
}
|
}
|
||||||
while (i++ <= idx) {
|
while (i++ <= idx) {
|
||||||
*ldpp = dp = create_dp(0, 0, 0, 0, 0);
|
*ldpp = dp = create_dp(0, 0, air, 0);
|
||||||
ldpp = &((*ldpp)->next);
|
ldpp = &((*ldpp)->next);
|
||||||
}
|
}
|
||||||
return dp;
|
return dp;
|
||||||
|
@ -400,9 +400,9 @@ void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoint *dp)
|
||||||
dp->time += lasttime;
|
dp->time += lasttime;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered)
|
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, struct gasmix gasmix, int po2, bool entered)
|
||||||
{
|
{
|
||||||
struct divedatapoint *dp = create_dp(duration, depth, o2, he, po2);
|
struct divedatapoint *dp = create_dp(duration, depth, gasmix, po2);
|
||||||
dp->entered = entered;
|
dp->entered = entered;
|
||||||
add_to_end_of_diveplan(diveplan, dp);
|
add_to_end_of_diveplan(diveplan, dp);
|
||||||
return (dp);
|
return (dp);
|
||||||
|
@ -424,8 +424,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
|
||||||
int best_depth = dive->cylinder[*asc_cylinder].depth.mm;
|
int best_depth = dive->cylinder[*asc_cylinder].depth.mm;
|
||||||
while (dp) {
|
while (dp) {
|
||||||
if (dp->time == 0) {
|
if (dp->time == 0) {
|
||||||
gas.o2.permille = dp->o2;
|
gas = dp->gasmix;
|
||||||
gas.he.permille = dp->he;
|
|
||||||
if (dp->depth <= depth) {
|
if (dp->depth <= depth) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
nr++;
|
nr++;
|
||||||
|
@ -516,7 +515,6 @@ 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)
|
static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer)
|
||||||
{
|
{
|
||||||
char buffer[20000];
|
char buffer[20000];
|
||||||
int consumption[MAX_CYLINDERS] = { 0, };
|
|
||||||
int len, gasidx, lastdepth = 0, lasttime = 0;
|
int len, gasidx, lastdepth = 0, lasttime = 0;
|
||||||
struct divedatapoint *dp = diveplan->dp;
|
struct divedatapoint *dp = diveplan->dp;
|
||||||
int o2, he;
|
int o2, he;
|
||||||
|
@ -539,22 +537,21 @@ static void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool
|
||||||
char gas[64];
|
char gas[64];
|
||||||
double depthvalue;
|
double depthvalue;
|
||||||
int decimals;
|
int decimals;
|
||||||
double used;
|
|
||||||
int newo2 = -1, newhe = -1;
|
int newo2 = -1, newhe = -1;
|
||||||
struct divedatapoint *nextdp;
|
struct divedatapoint *nextdp;
|
||||||
|
|
||||||
if (dp->time == 0)
|
if (dp->time == 0)
|
||||||
continue;
|
continue;
|
||||||
o2 = dp->o2;
|
o2 = get_o2(&dp->gasmix);
|
||||||
he = dp->he;
|
he = get_he(&dp->gasmix);
|
||||||
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
depthvalue = get_depth_units(dp->depth, &decimals, &depth_unit);
|
||||||
/* analyze the dive points ahead */
|
/* analyze the dive points ahead */
|
||||||
nextdp = dp->next;
|
nextdp = dp->next;
|
||||||
while (nextdp && nextdp->time == 0)
|
while (nextdp && nextdp->time == 0)
|
||||||
nextdp = nextdp->next;
|
nextdp = nextdp->next;
|
||||||
if (nextdp) {
|
if (nextdp) {
|
||||||
newo2 = nextdp->o2;
|
newo2 = get_o2(&nextdp->gasmix);
|
||||||
newhe = nextdp->he;
|
newhe = get_he(&nextdp->gasmix);
|
||||||
if (newhe == 0 && newo2 == 0) {
|
if (newhe == 0 && newo2 == 0) {
|
||||||
/* same as last segment */
|
/* same as last segment */
|
||||||
newo2 = o2;
|
newo2 = o2;
|
||||||
|
@ -686,7 +683,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
/* if all we wanted was the dive just get us back to the surface */
|
/* if all we wanted was the dive just get us back to the surface */
|
||||||
if (!add_deco) {
|
if (!add_deco) {
|
||||||
transitiontime = depth / 75; /* this still needs to be made configurable */
|
transitiontime = depth / 75; /* this still needs to be made configurable */
|
||||||
plan_add_segment(diveplan, transitiontime, 0, o2, he, po2, false);
|
plan_add_segment(diveplan, transitiontime, 0, gas, po2, false);
|
||||||
/* re-create the dive */
|
/* re-create the dive */
|
||||||
delete_single_dive(dive_table.nr - 1);
|
delete_single_dive(dive_table.nr - 1);
|
||||||
*divep = dive = create_dive_from_plan(diveplan, master_dive);
|
*divep = dive = create_dive_from_plan(diveplan, master_dive);
|
||||||
|
@ -723,8 +720,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
stopping = true;
|
stopping = true;
|
||||||
|
|
||||||
current_cylinder = best_first_ascend_cylinder;
|
current_cylinder = best_first_ascend_cylinder;
|
||||||
o2 = get_o2(&dive->cylinder[current_cylinder].gasmix);
|
gas = dive->cylinder[current_cylinder].gasmix;
|
||||||
he = get_he(&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,
|
||||||
(o2 + 5) / 10, (he + 5) / 10, gaschanges[best_first_ascend_cylinder].depth / 1000.0);
|
(o2 + 5) / 10, (he + 5) / 10, gaschanges[best_first_ascend_cylinder].depth / 1000.0);
|
||||||
|
@ -737,7 +733,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
/* Ascend to next stop depth */
|
/* Ascend to next stop depth */
|
||||||
int deltad = ascend_velocity(depth, avg_depth, bottom_time) * TIMESTEP;
|
int deltad = ascend_velocity(depth, avg_depth, bottom_time) * TIMESTEP;
|
||||||
if (ascend_velocity(depth, avg_depth, bottom_time) != last_ascend_rate) {
|
if (ascend_velocity(depth, avg_depth, bottom_time) != last_ascend_rate) {
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, depth, o2, he, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
||||||
previous_point_time = clock;
|
previous_point_time = clock;
|
||||||
stopping = false;
|
stopping = false;
|
||||||
last_ascend_rate = ascend_velocity(depth, avg_depth, bottom_time);
|
last_ascend_rate = ascend_velocity(depth, avg_depth, bottom_time);
|
||||||
|
@ -757,13 +753,12 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) {
|
if (gi >= 0 && stoplevels[stopidx] == gaschanges[gi].depth) {
|
||||||
/* We have reached a gas change.
|
/* We have reached a gas change.
|
||||||
* Record this in the dive plan */
|
* Record this in the dive plan */
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, depth, o2, he, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
||||||
previous_point_time = clock;
|
previous_point_time = clock;
|
||||||
stopping = true;
|
stopping = true;
|
||||||
|
|
||||||
current_cylinder = gaschanges[gi].gasidx;
|
current_cylinder = gaschanges[gi].gasidx;
|
||||||
o2 = get_o2(&dive->cylinder[current_cylinder].gasmix);
|
gas = dive->cylinder[current_cylinder].gasmix;
|
||||||
he = get_he(&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,
|
||||||
(o2 + 5) / 10, (he + 5) / 10, gaschanges[gi].depth / 1000.0);
|
(o2 + 5) / 10, (he + 5) / 10, gaschanges[gi].depth / 1000.0);
|
||||||
|
@ -798,7 +793,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
if (!stopping) {
|
if (!stopping) {
|
||||||
/* The last segment was an ascend segment.
|
/* The last segment was an ascend segment.
|
||||||
* Add a waypoint for start of this deco stop */
|
* Add a waypoint for start of this deco stop */
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, depth, o2, he, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
||||||
previous_point_time = clock;
|
previous_point_time = clock;
|
||||||
stopping = true;
|
stopping = true;
|
||||||
}
|
}
|
||||||
|
@ -809,7 +804,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
}
|
}
|
||||||
if (stopping) {
|
if (stopping) {
|
||||||
/* Next we will ascend again. Add a waypoint if we have spend deco time */
|
/* Next we will ascend again. Add a waypoint if we have spend deco time */
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, depth, o2, he, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, depth, gas, po2, false);
|
||||||
previous_point_time = clock;
|
previous_point_time = clock;
|
||||||
stopping = false;
|
stopping = false;
|
||||||
}
|
}
|
||||||
|
@ -817,7 +812,7 @@ void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, s
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We made it to the surface */
|
/* We made it to the surface */
|
||||||
plan_add_segment(diveplan, clock - previous_point_time, 0, o2, he, po2, false);
|
plan_add_segment(diveplan, clock - previous_point_time, 0, gas, po2, false);
|
||||||
delete_single_dive(dive_table.nr - 1);
|
delete_single_dive(dive_table.nr - 1);
|
||||||
*divep = dive = create_dive_from_plan(diveplan, master_dive);
|
*divep = dive = create_dive_from_plan(diveplan, master_dive);
|
||||||
if (!dive)
|
if (!dive)
|
||||||
|
|
|
@ -30,16 +30,16 @@
|
||||||
#define MAX_DEPTH M_OR_FT(150, 450)
|
#define MAX_DEPTH M_OR_FT(150, 450)
|
||||||
#define MIN_DEPTH M_OR_FT(20, 60)
|
#define MIN_DEPTH M_OR_FT(20, 60)
|
||||||
|
|
||||||
QString gasToStr(const int o2Permille, const int hePermille)
|
QString gasToStr(struct gasmix gas)
|
||||||
{
|
{
|
||||||
uint o2 = (o2Permille + 5) / 10, he = (hePermille + 5) / 10;
|
uint o2 = (gas.o2.permille + 5) / 10, he = (gas.he.permille + 5) / 10;
|
||||||
QString result = is_air(o2Permille, hePermille) ? QObject::tr("AIR") : he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0')) : QString("%1/%2").arg(o2).arg(he);
|
QString result = gasmix_is_air(&gas) ? QObject::tr("AIR") : he == 0 ? QString("EAN%1").arg(o2, 2, 10, QChar('0')) : QString("%1/%2").arg(o2).arg(he);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString dpGasToStr(const divedatapoint &p)
|
QString dpGasToStr(const divedatapoint &p)
|
||||||
{
|
{
|
||||||
return gasToStr(p.o2, p.he);
|
return gasToStr(p.gasmix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
|
||||||
|
@ -153,7 +153,7 @@ QStringList &DivePlannerPointsModel::getGasList()
|
||||||
cylinder_t *cyl = &activeDive->cylinder[i];
|
cylinder_t *cyl = &activeDive->cylinder[i];
|
||||||
if (cylinder_nodata(cyl))
|
if (cylinder_nodata(cyl))
|
||||||
break;
|
break;
|
||||||
list.push_back(gasToStr(get_o2(&cyl->gasmix), get_he(&cyl->gasmix)));
|
list.push_back(gasToStr(cyl->gasmix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
|
@ -417,10 +417,8 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
|
||||||
} break;
|
} break;
|
||||||
case GAS:
|
case GAS:
|
||||||
QByteArray gasv = value.toByteArray();
|
QByteArray gasv = value.toByteArray();
|
||||||
if (validate_gas(gasv.data(), &gas)) {
|
if (validate_gas(gasv.data(), &gas))
|
||||||
p.o2 = get_o2(&gas);
|
p.gasmix = gas;
|
||||||
p.he = get_he(&gas);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
editStop(index.row(), p);
|
editStop(index.row(), p);
|
||||||
|
@ -573,8 +571,8 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
|
||||||
const divedatapoint t = divepoints.at(lastEnteredPoint());
|
const divedatapoint t = divepoints.at(lastEnteredPoint());
|
||||||
milimeters = t.depth;
|
milimeters = t.depth;
|
||||||
seconds = t.time + 600; // 10 minutes.
|
seconds = t.time + 600; // 10 minutes.
|
||||||
o2 = t.o2;
|
o2 = get_o2(&t.gasmix);
|
||||||
he = t.he;
|
he = get_he(&t.gasmix);
|
||||||
ccpoint = t.po2;
|
ccpoint = t.po2;
|
||||||
} else if (seconds == 0 && milimeters == 0 && row == 0) {
|
} else if (seconds == 0 && milimeters == 0 && row == 0) {
|
||||||
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
||||||
|
@ -607,16 +605,16 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
|
||||||
}
|
}
|
||||||
if (o2 == -1) {
|
if (o2 == -1) {
|
||||||
if (row > 0) {
|
if (row > 0) {
|
||||||
o2 = divepoints.at(row - 1).o2;
|
o2 = get_o2(&divepoints.at(row - 1).gasmix);
|
||||||
he = divepoints.at(row - 1).he;
|
he = get_he(&divepoints.at(row - 1).gasmix);
|
||||||
} else {
|
} else {
|
||||||
// when we add a first data point we need to make sure that there is a
|
// when we add a first data point we need to make sure that there is a
|
||||||
// tank for it to use;
|
// tank for it to use;
|
||||||
// first check to the right, then to the left, but if there's nothing,
|
// first check to the right, then to the left, but if there's nothing,
|
||||||
// we simply default to AIR
|
// we simply default to AIR
|
||||||
if (row < divepoints.count()) {
|
if (row < divepoints.count()) {
|
||||||
o2 = divepoints.at(row).o2;
|
o2 = get_o2(&divepoints.at(row).gasmix);
|
||||||
he = divepoints.at(row).he;
|
he = get_he(&divepoints.at(row).gasmix);
|
||||||
} else {
|
} else {
|
||||||
o2 = O2_IN_AIR;
|
o2 = O2_IN_AIR;
|
||||||
if (!addGas(o2, 0))
|
if (!addGas(o2, 0))
|
||||||
|
@ -630,8 +628,8 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int o2, int he,
|
||||||
divedatapoint point;
|
divedatapoint point;
|
||||||
point.depth = milimeters;
|
point.depth = milimeters;
|
||||||
point.time = seconds;
|
point.time = seconds;
|
||||||
point.o2 = o2;
|
point.gasmix.o2.permille = o2;
|
||||||
point.he = he;
|
point.gasmix.he.permille = he;
|
||||||
point.po2 = ccpoint;
|
point.po2 = ccpoint;
|
||||||
point.entered = entered;
|
point.entered = entered;
|
||||||
divepoints.append(point);
|
divepoints.append(point);
|
||||||
|
@ -714,7 +712,7 @@ void DivePlannerPointsModel::rememberTanks()
|
||||||
oldGases = collectGases(stagingDive);
|
oldGases = collectGases(stagingDive);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DivePlannerPointsModel::tankInUse(int o2, int he)
|
bool DivePlannerPointsModel::tankInUse(struct gasmix gasmix)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < rowCount(); j++) {
|
for (int j = 0; j < rowCount(); j++) {
|
||||||
divedatapoint &p = divepoints[j];
|
divedatapoint &p = divepoints[j];
|
||||||
|
@ -722,8 +720,7 @@ bool DivePlannerPointsModel::tankInUse(int o2, int he)
|
||||||
continue;
|
continue;
|
||||||
if (!p.entered) // removing deco gases is ok
|
if (!p.entered) // removing deco gases is ok
|
||||||
continue;
|
continue;
|
||||||
if ((p.o2 == o2 && p.he == he) ||
|
if (gasmix_distance(&p.gasmix, &gasmix) < 200)
|
||||||
(is_air(p.o2, p.he) && is_air(o2, he)))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -747,12 +744,12 @@ void DivePlannerPointsModel::tanksUpdated()
|
||||||
}
|
}
|
||||||
for (int j = 0; j < rowCount(); j++) {
|
for (int j = 0; j < rowCount(); j++) {
|
||||||
divedatapoint &p = divepoints[j];
|
divedatapoint &p = divepoints[j];
|
||||||
int o2 = oldGases.at(i).first;
|
struct gasmix gas;
|
||||||
int he = oldGases.at(i).second;
|
gas.o2.permille = oldGases.at(i).first;
|
||||||
if ((p.o2 == o2 && p.he == he) ||
|
gas.he.permille = oldGases.at(i).second;
|
||||||
(is_air(p.o2, p.he) && (is_air(o2, he) || (o2 == 0 && he == 0)))) {
|
if (gasmix_distance(&gas, &p.gasmix) < 200) {
|
||||||
p.o2 = gases.at(i).first;
|
p.gasmix.o2.permille = gases.at(i).first;
|
||||||
p.he = gases.at(i).second;
|
p.gasmix.he.permille = gases.at(i).second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -797,7 +794,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
||||||
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
|
int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
|
||||||
lastIndex = i;
|
lastIndex = i;
|
||||||
if (p.entered)
|
if (p.entered)
|
||||||
plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2, true);
|
plan_add_segment(&diveplan, deltaT, p.depth, p.gasmix, p.po2, true);
|
||||||
}
|
}
|
||||||
char *cache = NULL;
|
char *cache = NULL;
|
||||||
tempDive = NULL;
|
tempDive = NULL;
|
||||||
|
@ -805,7 +802,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
||||||
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
cylinder_t *cyl = &stagingDive->cylinder[i];
|
cylinder_t *cyl = &stagingDive->cylinder[i];
|
||||||
if (cyl->depth.mm) {
|
if (cyl->depth.mm) {
|
||||||
dp = create_dp(0, cyl->depth.mm, get_o2(&cyl->gasmix), get_he(&cyl->gasmix), 0);
|
dp = create_dp(0, cyl->depth.mm, cyl->gasmix, 0);
|
||||||
if (diveplan.dp) {
|
if (diveplan.dp) {
|
||||||
dp->next = diveplan.dp->next;
|
dp->next = diveplan.dp->next;
|
||||||
diveplan.dp->next = dp;
|
diveplan.dp->next = dp;
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
bool recalcQ();
|
bool recalcQ();
|
||||||
void tanksUpdated();
|
void tanksUpdated();
|
||||||
void rememberTanks();
|
void rememberTanks();
|
||||||
bool tankInUse(int o2, int he);
|
bool tankInUse(struct gasmix gasmix);
|
||||||
void copyCylinders(struct dive *d);
|
void copyCylinders(struct dive *d);
|
||||||
void setupCylinders();
|
void setupCylinders();
|
||||||
/**
|
/**
|
||||||
|
@ -137,7 +137,7 @@ private:
|
||||||
Ui::DivePlanner ui;
|
Ui::DivePlanner ui;
|
||||||
};
|
};
|
||||||
|
|
||||||
QString gasToStr(const int o2Permille, const int hePermille);
|
QString gasToStr(gasmix gas);
|
||||||
QString dpGasToStr(const divedatapoint &p);
|
QString dpGasToStr(const divedatapoint &p);
|
||||||
|
|
||||||
#endif // DIVEPLANNER_H
|
#endif // DIVEPLANNER_H
|
||||||
|
|
|
@ -356,7 +356,7 @@ void CylindersModel::remove(const QModelIndex &index)
|
||||||
}
|
}
|
||||||
cylinder_t *cyl = ¤t->cylinder[index.row()];
|
cylinder_t *cyl = ¤t->cylinder[index.row()];
|
||||||
if ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
|
if ((DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING &&
|
||||||
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) ||
|
DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix)) ||
|
||||||
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
|
(DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING &&
|
||||||
(cyl->manually_added || (current_dive && cylinder_is_used(current_dive, cyl))))) {
|
(cyl->manually_added || (current_dive && cylinder_is_used(current_dive, cyl))))) {
|
||||||
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
|
QMessageBox::warning(MainWindow::instance(), TITLE_OR_TEXT(
|
||||||
|
|
Loading…
Add table
Reference in a new issue