mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
Fix missing save of (almost empty) cylinder information
If we have no explicit cylinder info at all (it's normal air, no size or
working pressure information, and no beginning/end pressure information),
we don't save the cylinders in question because that would be redundant.
Such non-saved cylinders may still show up in the equipment list because
there may be implicit mention of them elsewhere, notably due to sample
data, so not saving them is the right thing to do - there is nothing to
save.
However, we missed one case: if there were other cylinders that *did* have
explicit information in it following such an uninteresting cylinder, we do
need to save the cylinder information for the useless case - if only in
order to be able to save the non-useless information for subsequent
cylinders.
This patch does that. Now, if you had an air-filled cylinder with no
information as your first cylinder, and a 51% nitrox as your second one,
it will save that information as
<cylinder />
<cylinder o2='51.0%' />
rather than dropping the cylinder information entirely.
This bug has been there for a long time, and was hidden by the fact that
normally you'd fill in cylinder descriptions etc after importing new
dives. It also used to be that we saved the cylinder beginning/end
pressure even if that was generated from the sample data, so if you
imported from a air-integrated computer and had samples for that cylinder,
we used to save it even though it was technically redundant.
We stopped saving redundant air sample information in commit 0089dd8819
("Don't save cylinder start/end pressures unless set by hand").
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Removed start and end in save_cylinder_info(). These two variables are no
longer used.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
26f550403d
commit
c4c636fb4f
3 changed files with 31 additions and 11 deletions
2
dive.h
2
dive.h
|
@ -93,6 +93,8 @@ typedef struct {
|
|||
const char *description; /* "integrated", "belt", "ankle" */
|
||||
} weightsystem_t;
|
||||
|
||||
extern gboolean cylinder_nodata(cylinder_t *cyl);
|
||||
extern gboolean cylinder_nosamples(cylinder_t *cyl);
|
||||
extern gboolean cylinder_none(void *_data);
|
||||
extern gboolean no_cylinders(cylinder_t *cyl);
|
||||
extern gboolean cylinders_equal(cylinder_t *cyl1, cylinder_t *cyl2);
|
||||
|
|
17
equipment.c
17
equipment.c
|
@ -444,20 +444,29 @@ static void show_weightsystem(weightsystem_t *ws, struct ws_widget *weightsystem
|
|||
set_weight_weight_spinbutton(weightsystem_widget, ws->weight.grams);
|
||||
}
|
||||
|
||||
gboolean cylinder_none(void *_data)
|
||||
gboolean cylinder_nodata(cylinder_t *cyl)
|
||||
{
|
||||
cylinder_t *cyl = _data;
|
||||
return !cyl->type.size.mliter &&
|
||||
!cyl->type.workingpressure.mbar &&
|
||||
!cyl->type.description &&
|
||||
!cyl->gasmix.o2.permille &&
|
||||
!cyl->gasmix.he.permille &&
|
||||
!cyl->sample_start.mbar &&
|
||||
!cyl->sample_end.mbar &&
|
||||
!cyl->start.mbar &&
|
||||
!cyl->end.mbar;
|
||||
}
|
||||
|
||||
gboolean cylinder_nosamples(cylinder_t *cyl)
|
||||
{
|
||||
return !cyl->sample_start.mbar &&
|
||||
!cyl->sample_end.mbar;
|
||||
}
|
||||
|
||||
gboolean cylinder_none(void *_data)
|
||||
{
|
||||
cylinder_t *cyl = _data;
|
||||
return cylinder_nodata(cyl) && cylinder_nosamples(cyl);
|
||||
}
|
||||
|
||||
gboolean no_cylinders(cylinder_t *cyl)
|
||||
{
|
||||
int i;
|
||||
|
|
23
save-xml.c
23
save-xml.c
|
@ -193,22 +193,31 @@ static void save_overview(FILE *f, struct dive *dive)
|
|||
show_utf8(f, dive->suit, " <suit>","</suit>\n", 0);
|
||||
}
|
||||
|
||||
static int nr_cylinders(struct dive *dive)
|
||||
{
|
||||
int nr;
|
||||
|
||||
for (nr = MAX_CYLINDERS; nr; --nr) {
|
||||
cylinder_t *cylinder = dive->cylinder+nr-1;
|
||||
if (!cylinder_nodata(cylinder))
|
||||
break;
|
||||
}
|
||||
return nr;
|
||||
}
|
||||
|
||||
static void save_cylinder_info(FILE *f, struct dive *dive)
|
||||
{
|
||||
int i;
|
||||
int i, nr;
|
||||
|
||||
for (i = 0; i < MAX_CYLINDERS; i++) {
|
||||
nr = nr_cylinders(dive);
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
cylinder_t *cylinder = dive->cylinder+i;
|
||||
int volume = cylinder->type.size.mliter;
|
||||
const char *description = cylinder->type.description;
|
||||
int o2 = cylinder->gasmix.o2.permille;
|
||||
int he = cylinder->gasmix.he.permille;
|
||||
int start = cylinder->start.mbar;
|
||||
int end = cylinder->end.mbar;
|
||||
|
||||
/* No cylinder information at all? */
|
||||
if (!o2 && !volume && !start && !end)
|
||||
return;
|
||||
fprintf(f, " <cylinder");
|
||||
if (volume)
|
||||
show_milli(f, " size='", volume, " l", "'");
|
||||
|
|
Loading…
Reference in a new issue