summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-03 23:09:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-03 23:09:12 -0700
commit5bc5cae6dcdb6a48bb5077d01e490bebedc624d9 (patch)
tree69323c0f826995c45558937d062e3f0a2d369527
parent88f39912603f9ce3d7c799b65580ee30e5ccb364 (diff)
downloadsubsurface-5bc5cae6dcdb6a48bb5077d01e490bebedc624d9.tar.gz
Planner: only copy cylinders that were used in the template dive
This was only semi-implemented the first time around. Now we really only copy the ones that are indeed used. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c7
-rw-r--r--dive.h2
-rw-r--r--planner.c2
-rw-r--r--qt-ui/diveplanner.cpp10
4 files changed, 12 insertions, 9 deletions
diff --git a/dive.c b/dive.c
index 145a01883..00c08ed2d 100644
--- a/dive.c
+++ b/dive.c
@@ -308,13 +308,16 @@ int nr_weightsystems(struct dive *dive)
return nr;
}
-void copy_cylinders(struct dive *s, struct dive *d)
+void copy_cylinders(struct dive *s, struct dive *d, bool used_only)
{
int i;
if (!s || !d)
return;
for (i = 0; i < MAX_CYLINDERS; i++)
- d->cylinder[i] = s->cylinder[i];
+ if (!used_only || cylinder_is_used(s, &s->cylinder[i]))
+ d->cylinder[i] = s->cylinder[i];
+ else
+ memset(&d->cylinder[i], 0, sizeof(cylinder_t));
}
void copy_samples(struct dive *s, struct dive *d)
diff --git a/dive.h b/dive.h
index f67755b72..be6edfc31 100644
--- a/dive.h
+++ b/dive.h
@@ -605,7 +605,7 @@ extern struct dive *merge_dives(struct dive *a, struct dive *b, int offset, bool
extern struct dive *try_to_merge(struct dive *a, struct dive *b, bool prefer_downloaded);
extern void renumber_dives(int start_nr, bool selected_only);
extern void copy_events(struct dive *s, struct dive *d);
-extern void copy_cylinders(struct dive *s, struct dive *d);
+extern void copy_cylinders(struct dive *s, struct dive *d, bool used_only);
extern void copy_samples(struct dive *s, struct dive *d);
extern bool cylinder_is_used(struct dive *d, cylinder_t *cyl);
extern void fill_default_cylinder(cylinder_t *cyl);
diff --git a/planner.c b/planner.c
index 2c1c66810..2306294b0 100644
--- a/planner.c
+++ b/planner.c
@@ -256,7 +256,7 @@ static struct dive *create_dive_from_plan(struct diveplan *diveplan, struct dive
dc = &dive->dc;
dc->model = "planned dive"; /* do not translate here ! */
dp = diveplan->dp;
- copy_cylinders(master_dive, dive);
+ copy_cylinders(master_dive, dive, false);
/* reset the end pressure values and start with the gas on the first cylinder */
reset_cylinders(master_dive);
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index 1b4427df6..b682aa131 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -83,7 +83,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
memcpy(&backupDive, d, sizeof(struct dive));
copy_samples(d, &backupDive);
copy_events(d, &backupDive);
- copy_cylinders(d, stagingDive); // this way the correct cylinder data is shown
+ copy_cylinders(d, stagingDive, false); // this way the correct cylinder data is shown
CylindersModel::instance()->setDive(stagingDive);
int lasttime = 0;
// we start with the first gas and see if it was changed
@@ -105,7 +105,7 @@ void DivePlannerPointsModel::restoreBackupDive()
void DivePlannerPointsModel::copyCylinders(dive *d)
{
- copy_cylinders(stagingDive, d);
+ copy_cylinders(stagingDive, d, false);
}
// copy the tanks from the current dive, or the default cylinder
@@ -119,9 +119,9 @@ void DivePlannerPointsModel::setupCylinders()
if (stagingDive != current_dive) {
// we are planning a dive
if (current_dive) {
- // take the cylinders from the selected dive as starting point
+ // take the used cylinders from the selected dive as starting point
CylindersModel::instance()->copyFromDive(current_dive);
- copy_cylinders(current_dive, stagingDive);
+ copy_cylinders(current_dive, stagingDive, true);
reset_cylinders(stagingDive);
return;
} else {
@@ -847,7 +847,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
// copy the samples and events, but don't overwrite the cylinders
copy_samples(tempDive, current_dive);
copy_events(tempDive, current_dive);
- copy_cylinders(tempDive, current_dive);
+ copy_cylinders(tempDive, current_dive, false);
}
}
// throw away the cache