aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-28 14:50:40 +0200
committerGravatar Robert C. Helling <helling@atdotde.de>2020-05-01 12:36:28 +0200
commitb949bad026c8bab7611998fb0fcf9f6008dbd7e9 (patch)
treebda7c10206612274a204b31412ae6999b8cc13b0
parent0c28821d2895e246295884891df02e924eb8e359 (diff)
downloadsubsurface-b949bad026c8bab7611998fb0fcf9f6008dbd7e9.tar.gz
core: always keep an empty cylinder at the end of the cylinder array
This will be temporarilly used by the planner to mark consumption of air at the surface. Do this by creating a new function add_cylinder, which replaces add_to_cylinder_table() and takes care of always adding a dummy cylinder at the end of the table. Make the original add_to_cylinder_table() local, so that it cannot be accessed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--commands/command_edit.cpp2
-rw-r--r--core/cochran.c6
-rw-r--r--core/equipment.c18
-rw-r--r--core/equipment.h4
-rw-r--r--core/libdivecomputer.c2
-rw-r--r--core/liquivision.c2
-rw-r--r--core/load-git.c2
-rw-r--r--core/planner.c2
-rw-r--r--qt-models/cylindermodel.cpp2
-rw-r--r--qt-models/diveplannermodel.cpp4
10 files changed, 28 insertions, 16 deletions
diff --git a/commands/command_edit.cpp b/commands/command_edit.cpp
index 0e1159f6d..c763cbffa 100644
--- a/commands/command_edit.cpp
+++ b/commands/command_edit.cpp
@@ -1167,7 +1167,7 @@ void RemoveCylinder::undo()
{
for (size_t i = 0; i < dives.size(); ++i) {
std::vector<int> mapping = get_cylinder_map_for_add(dives[i]->cylinders.nr, indexes[i]);
- add_to_cylinder_table(&dives[i]->cylinders, indexes[i], clone_cylinder(cyl[i]));
+ add_cylinder(&dives[i]->cylinders, indexes[i], clone_cylinder(cyl[i]));
emit diveListNotifier.cylinderAdded(dives[i], indexes[i]);
invalidate_dive_cache(dives[i]); // Ensure that dive is written in git_save()
}
diff --git a/core/cochran.c b/core/cochran.c
index 5955ddb69..55460014a 100644
--- a/core/cochran.c
+++ b/core/cochran.c
@@ -682,7 +682,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT] / 256
+ log[CMD_O2_PERCENT + 1]) * 10;
cyl.gasmix.he.permille = 0;
- add_to_cylinder_table(&dive->cylinders, 0, cyl);
+ add_cylinder(&dive->cylinders, 0, cyl);
} else {
dc->model = "Commander";
dc->deviceid = array_uint32_le(buf + 0x31e); // serial no
@@ -692,7 +692,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.o2.permille = (log[CMD_O2_PERCENT + g * 2] / 256
+ log[CMD_O2_PERCENT + g * 2 + 1]) * 10;
cyl.gasmix.he.permille = 0;
- add_to_cylinder_table(&dive->cylinders, g, cyl);
+ add_cylinder(&dive->cylinders, g, cyl);
}
}
@@ -739,7 +739,7 @@ static void cochran_parse_dive(const unsigned char *decode, unsigned mod,
cyl.gasmix.he.permille =
(log[EMC_HE_PERCENT + g * 2] / 256
+ log[EMC_HE_PERCENT + g * 2 + 1]) * 10;
- add_to_cylinder_table(&dive->cylinders, g, cyl);
+ add_cylinder(&dive->cylinders, g, cyl);
}
tm.tm_year = log[EMC_YEAR];
diff --git a/core/equipment.c b/core/equipment.c
index 4be46ed1e..8d169d8d2 100644
--- a/core/equipment.c
+++ b/core/equipment.c
@@ -56,7 +56,7 @@ MAKE_CLEAR_TABLE(weightsystem_table, weightsystems, weightsystem)
//static MAKE_GET_IDX(cylinder_table, cylinder_t, cylinders)
static MAKE_GROW_TABLE(cylinder_table, cylinder_t, cylinders)
//static MAKE_GET_INSERTION_INDEX(cylinder_table, cylinder_t, cylinders, cylinder_less_than)
-MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders)
+static MAKE_ADD_TO(cylinder_table, cylinder_t, cylinders)
MAKE_REMOVE_FROM(cylinder_table, cylinders)
//MAKE_SORT(cylinder_table, cylinder_t, cylinders, comp_cylinders)
//MAKE_REMOVE(cylinder_table, cylinder_t, cylinder)
@@ -144,11 +144,23 @@ cylinder_t clone_cylinder(cylinder_t cyl)
return res;
}
+void add_cylinder(struct cylinder_table *t, int idx, cylinder_t cyl)
+{
+ add_to_cylinder_table(t, idx, cyl);
+ /* FIXME: This is a horrible hack: we make sure that at the end of
+ * every single cylinder table there is an empty cylinder that can
+ * be used by the planner as "surface air" cylinder. Fix this.
+ */
+ add_to_cylinder_table(t, t->nr, empty_cylinder);
+ t->nr--;
+ t->cylinders[t->nr].cylinder_use = NOT_USED;
+}
+
/* Add a clone of a cylinder to the end of a cylinder table.
* Cloned in means that the description-string is copied. */
void add_cloned_cylinder(struct cylinder_table *t, cylinder_t cyl)
{
- add_to_cylinder_table(t, t->nr, clone_cylinder(cyl));
+ add_cylinder(t, t->nr, clone_cylinder(cyl));
}
bool same_weightsystem(weightsystem_t w1, weightsystem_t w2)
@@ -342,7 +354,7 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t)
{
cylinder_t cyl = empty_cylinder;
cyl.type.description = strdup("");
- add_to_cylinder_table(t, t->nr, cyl);
+ add_cylinder(t, t->nr, cyl);
return &t->cylinders[t->nr - 1];
}
diff --git a/core/equipment.h b/core/equipment.h
index 081a13835..c5a0db6d6 100644
--- a/core/equipment.h
+++ b/core/equipment.h
@@ -39,7 +39,7 @@ static const cylinder_t empty_cylinder = { { { 0 }, { 0 }, (const char *)0}, { {
* *not* pointers to cylinders. This has two crucial consequences:
* 1) Pointers to cylinders are not stable. They may be
* invalidated if the table is reallocated.
- * 2) add_to_cylinder_table(), etc. take ownership of the
+ * 2) add_cylinder(), etc. take ownership of the
* cylinder. Notably of the description string. */
struct cylinder_table {
int nr, allocated;
@@ -102,7 +102,7 @@ extern void add_to_weightsystem_table(struct weightsystem_table *, int idx, weig
/* Cylinder table functions */
extern void clear_cylinder_table(struct cylinder_table *);
-extern void add_to_cylinder_table(struct cylinder_table *, int idx, cylinder_t cyl);
+extern void add_cylinder(struct cylinder_table *, int idx, cylinder_t cyl);
void get_gas_string(struct gasmix gasmix, char *text, int len);
const char *gasname(struct gasmix gasmix);
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index bc0836c3c..f40c55c2e 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -228,7 +228,7 @@ static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t
if (empty_string(cyl.type.description))
cyl.type.description = strdup(translate("gettextFromC", "unknown"));
- add_to_cylinder_table(&dive->cylinders, dive->cylinders.nr, cyl);
+ add_cylinder(&dive->cylinders, dive->cylinders.nr, cyl);
}
return DC_STATUS_SUCCESS;
}
diff --git a/core/liquivision.c b/core/liquivision.c
index 905091dd8..5a9caf603 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -151,7 +151,7 @@ static void parse_dives(int log_version, const unsigned char *buf, unsigned int
for (i = 0; i < 1; i++) {
cylinder_t cyl = empty_cylinder;
fill_default_cylinder(dive, &cyl);
- add_to_cylinder_table(&dive->cylinders, i, cyl);
+ add_cylinder(&dive->cylinders, i, cyl);
}
// Model 0=Xen, 1,2=Xeo, 4=Lynx, other=Liquivision
diff --git a/core/load-git.c b/core/load-git.c
index b7353763f..24f96a794 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -455,7 +455,7 @@ static void parse_dive_cylinder(char *line, struct membuffer *str, struct git_pa
if (cylinder.cylinder_use == OXYGEN)
state->o2pressure_sensor = state->active_dive->cylinders.nr;
- add_to_cylinder_table(&state->active_dive->cylinders, state->active_dive->cylinders.nr, cylinder);
+ add_cylinder(&state->active_dive->cylinders, state->active_dive->cylinders.nr, cylinder);
}
static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char *value)
diff --git a/core/planner.c b/core/planner.c
index a5f0d36bc..8cadaca01 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -1074,7 +1074,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
// If no empty cylinder is found, keep using last deco gas
cylinder_t cyl = empty_cylinder;
cyl.cylinder_use = NOT_USED;
- add_to_cylinder_table(&dive->cylinders, dive->cylinders.nr, cyl);
+ add_cylinder(&dive->cylinders, dive->cylinders.nr, cyl);
current_cylinder = dive->cylinders.nr - 1;
plan_add_segment(diveplan, prefs.surface_segment, 0, current_cylinder, 0, false, OC);
}
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 6759670c6..0055849ff 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -490,7 +490,7 @@ void CylindersModel::add()
int row = d->cylinders.nr;
cylinder_t cyl = create_new_cylinder(d);
beginInsertRows(QModelIndex(), row, row);
- add_to_cylinder_table(&d->cylinders, row, cyl);
+ add_cylinder(&d->cylinders, row, cyl);
endInsertRows();
emit dataChanged(createIndex(row, 0), createIndex(row, COLUMNS - 1));
}
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index f9823c12d..c6821109b 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -174,14 +174,14 @@ void DivePlannerPointsModel::setupCylinders()
cylinder_t cyl = empty_cylinder;
fill_default_cylinder(&displayed_dive, &cyl);
cyl.start = cyl.type.workingpressure;
- add_to_cylinder_table(&displayed_dive.cylinders, 0, cyl);
+ add_cylinder(&displayed_dive.cylinders, 0, cyl);
} else {
cylinder_t cyl = empty_cylinder;
// roughly an AL80
cyl.type.description = copy_qstring(tr("unknown"));
cyl.type.size.mliter = 11100;
cyl.type.workingpressure.mbar = 207000;
- add_to_cylinder_table(&displayed_dive.cylinders, 0, cyl);
+ add_cylinder(&displayed_dive.cylinders, 0, cyl);
}
reset_cylinders(&displayed_dive, false);
cylinders.updateDive(&displayed_dive);