aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2018-04-07 14:56:37 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-05-14 23:47:00 +0300
commitb9174332d562b8b9c436a94880c51acf2c5ab761 (patch)
treec6c08d8bc89c602e5f7c75be4fcf1b21777187f9
parent5f95c226ef4d0def6aafc60a9f4880a3a3374167 (diff)
downloadsubsurface-b9174332d562b8b9c436a94880c51acf2c5ab761.tar.gz
Read and write divemode changes (xml and git)
This provides for reading of divemode change events from dive logs and for writing them to dive logs. This applies to xml and git divelogs. Divemode change events have the following structure: event->name = "modechange" event->value = integer corresponding to enum dive_comp_type (dive.c), reflecting the type of divemode change (OC, CCR, PSCR, etc). In the dive log file, the event value is written as a string that corresponds to each of the enum values, e.g. <event name='modechange' divemode='OC' /> This xml is also read from the dive log file and translated to an appropriate value of event->value. The file diveeventitem.cpp was udated to reflect this new way of dealing with divemode change events. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
-rw-r--r--core/dive.h2
-rw-r--r--core/load-git.c11
-rw-r--r--core/parse-xml.c22
-rw-r--r--core/save-git.c6
-rw-r--r--core/save-xml.c5
-rw-r--r--profile-widget/diveeventitem.cpp9
6 files changed, 48 insertions, 7 deletions
diff --git a/core/dive.h b/core/dive.h
index 6fb1509b4..d336318d5 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -27,7 +27,7 @@ extern "C" {
extern int last_xml_version;
-enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
+enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE, UNDEF_COMP_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type
enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NOT_USED, NUM_GAS_USE}; // The different uses for cylinders
extern const char *cylinderuse_text[];
diff --git a/core/load-git.c b/core/load-git.c
index 4af7221c3..67a2dfa29 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -723,6 +723,15 @@ static void parse_dc_time(char *line, struct membuffer *str, void *_dc)
static void parse_dc_watertemp(char *line, struct membuffer *str, void *_dc)
{ (void) str; struct divecomputer *dc = _dc; dc->watertemp = get_temperature(line); }
+
+int get_divemode(const char *divemodestring) {
+ for (int i = 0; i < NUM_DC_TYPE; i++) {
+ if (!strcmp(divemodestring, divemode_text[i]))
+ return i;
+ }
+ return 0;
+}
+
static void parse_event_keyvalue(void *_event, const char *key, const char *value)
{
struct event *event = _event;
@@ -736,6 +745,8 @@ static void parse_event_keyvalue(void *_event, const char *key, const char *valu
event->value = val;
} else if (!strcmp(key, "name")) {
/* We get the name from the string handling */
+ } else if (!strcmp(key,"divemode")) {
+ event->value = get_divemode(value);
} else if (!strcmp(key, "cylinder")) {
/* NOTE! We add one here as a marker that "yes, we got a cylinder index" */
event->gas.index = 1+get_index(value);
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 47358865b..fa7572ac9 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -428,7 +428,7 @@ static void event_name(char *buffer, char *name)
{
int size = trimspace(buffer);
if (size >= MAX_EVENT_NAME)
- size = MAX_EVENT_NAME-1;
+ size = MAX_EVENT_NAME - 1;
memcpy(name, buffer, size);
name[size] = 0;
}
@@ -449,6 +449,24 @@ static void get_dc_type(char *buffer, enum dive_comp_type *dct)
}
}
+/* For divemode_text[] (defined in dive.h) determine the index of
+ * the string contained in the xml divemode attribute and passed
+ * in buffer, below. Typical xml input would be:
+ * <event name='modechange' divemode='OC' /> */
+static void event_divemode(char *buffer, int *value)
+{
+ int size = trimspace(buffer);
+ if (size >= MAX_EVENT_NAME)
+ size = MAX_EVENT_NAME - 1;
+ buffer[size] = 0x0;
+ for (int i = 0; i < NUM_DC_TYPE; i++) {
+ if (!strcmp(buffer,divemode_text[i])) {
+ *value = i;
+ break;
+ }
+ }
+}
+
#define MATCH(pattern, fn, dest) ({ \
/* Silly type compatibility test */ \
if (0) (fn)("test", dest); \
@@ -708,6 +726,8 @@ static void try_to_fill_event(const char *name, char *buf)
return;
if (MATCH("value", get_index, &cur_event.value))
return;
+ if (MATCH("divemode", event_divemode, &cur_event.value))
+ return;
if (MATCH("cylinder", get_index, &cur_event.gas.index)) {
/* We add one to indicate that we got an actual cylinder index value */
cur_event.gas.index++;
diff --git a/core/save-git.c b/core/save-git.c
index 395490d83..c0f098d44 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -374,7 +374,11 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event
put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type=", "");
show_index(b, ev->flags, "flags=", "");
- show_index(b, ev->value, "value=", "");
+
+ if (!strcmp(ev->name,"modechange"))
+ show_utf8(b, "divemode=", divemode_text[ev->value], "");
+ else
+ show_index(b, ev->value, "value=", "");
show_utf8(b, " name=", ev->name, "");
if (event_is_gaschange(ev)) {
struct gasmix *mix = get_gasmix_from_event(dive, ev);
diff --git a/core/save-xml.c b/core/save-xml.c
index adf9ec2f1..90587163d 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -301,7 +301,10 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event
put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60));
show_index(b, ev->type, "type='", "'");
show_index(b, ev->flags, "flags='", "'");
- show_index(b, ev->value, "value='", "'");
+ if (!strcmp(ev->name,"modechange"))
+ show_utf8(b, divemode_text[ev->value], "divemode='", "'",1);
+ else
+ show_index(b, ev->value, "value='", "'");
show_utf8(b, ev->name, " name='", "'", 1);
if (event_is_gaschange(ev)) {
struct gasmix *mix = get_gasmix_from_event(dive, ev);
diff --git a/profile-widget/diveeventitem.cpp b/profile-widget/diveeventitem.cpp
index 7e7c602a1..b734f5b5e 100644
--- a/profile-widget/diveeventitem.cpp
+++ b/profile-widget/diveeventitem.cpp
@@ -84,9 +84,10 @@ void DiveEventItem::setupPixmap(struct gasmix *lastgasmix)
#define EVENT_PIXMAP_BIGGER(PIX) QPixmap(QString(PIX)).scaled(sz_bigger, sz_bigger, Qt::KeepAspectRatio, Qt::SmoothTransformation)
if (empty_string(internalEvent->name)) {
setPixmap(EVENT_PIXMAP(":status-warning-icon"));
- } else if (same_string_caseinsensitive(internalEvent->name, "OC")) {
- setPixmap(EVENT_PIXMAP(":bailout-icon"));
- } else if (same_string_caseinsensitive(internalEvent->name, "CCR") || same_string_caseinsensitive(internalEvent->name, "PSCR")) {
+ } else if (same_string_caseinsensitive(internalEvent->name, "modechange")) {
+ if (internalEvent->value == 0)
+ setPixmap(EVENT_PIXMAP(":bailout-icon"));
+ else
setPixmap(EVENT_PIXMAP(":onCCRLoop-icon"));
} else if (internalEvent->type == SAMPLE_EVENT_BOOKMARK) {
setPixmap(EVENT_PIXMAP(":dive-bookmark-icon"));
@@ -192,6 +193,8 @@ void DiveEventItem::setupToolTipString(struct gasmix *lastgasmix)
free_buffer(&mb);
}
*lastgasmix = *mix;
+ } else if (same_string(internalEvent->name, "modechange")) {
+ name += tr(": %1").arg(divemode_text[internalEvent->value]);
} else if (value) {
if (type == SAMPLE_EVENT_PO2 && same_string(internalEvent->name, "SP change")) {
name += QString(": %1bar").arg((double)value / 1000, 0, 'f', 1);