[PATCH 3/4] Add support for importing TTS from CSV files

Anton Lundin glance at acc.umu.se
Wed Jul 9 13:13:38 PDT 2014


Signed-off-by: Anton Lundin <glance at acc.umu.se>
---
 dive.h                        |  2 +-
 file.c                        |  8 ++++++--
 qt-ui/divelogimportdialog.cpp | 14 +++++++++-----
 qt-ui/divelogimportdialog.h   |  1 +
 qt-ui/divelogimportdialog.ui  | 22 ++++++++++++++++++++++
 xslt/csv2xml.xslt             | 10 ++++++++++
 6 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/dive.h b/dive.h
index fc9e676..60693f2 100644
--- a/dive.h
+++ b/dive.h
@@ -553,7 +553,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char *url, const char *buf, i
 extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const char *buf, int size, struct dive_table *table);
 
 extern int parse_file(const char *filename);
-extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int stopdepthf, int sepidx, const char *csvtemplate, int units);
+extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int sepidx, const char *csvtemplate, int units);
 extern int parse_manual_file(const char *filename, int separator_index, int units, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int buddy, int notes, int weight, int tags);
 
 extern int save_dives(const char *filename);
diff --git a/file.c b/file.c
index cb2c4f2..9d8dafe 100644
--- a/file.c
+++ b/file.c
@@ -384,17 +384,18 @@ int parse_file(const char *filename)
 
 #define MAXCOLDIGITS 3
 #define MAXCOLS 100
-int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int ndlf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx)
+int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int sepidx, const char *csvtemplate, int unitidx)
 {
 	struct memblock mem;
 	int pnr = 0;
-	char *params[23];
+	char *params[25];
 	char timebuf[MAXCOLDIGITS];
 	char depthbuf[MAXCOLDIGITS];
 	char tempbuf[MAXCOLDIGITS];
 	char po2buf[MAXCOLDIGITS];
 	char cnsbuf[MAXCOLDIGITS];
 	char ndlbuf[MAXCOLDIGITS];
+	char ttsbuf[MAXCOLDIGITS];
 	char stopdepthbuf[MAXCOLDIGITS];
 	char unitbuf[MAXCOLDIGITS];
 	char separator_index[MAXCOLDIGITS];
@@ -412,6 +413,7 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
 	snprintf(po2buf, MAXCOLDIGITS, "%d", po2f);
 	snprintf(cnsbuf, MAXCOLDIGITS, "%d", cnsf);
 	snprintf(ndlbuf, MAXCOLDIGITS, "%d", ndlf);
+	snprintf(ttsbuf, MAXCOLDIGITS, "%d", ttsf);
 	snprintf(stopdepthbuf, MAXCOLDIGITS, "%d", stopdepthf);
 	snprintf(separator_index, MAXCOLDIGITS, "%d", sepidx);
 	snprintf(unitbuf, MAXCOLDIGITS, "%d", unitidx);
@@ -435,6 +437,8 @@ int parse_csv_file(const char *filename, int timef, int depthf, int tempf, int p
 	params[pnr++] = cnsbuf;
 	params[pnr++] = "ndlField";
 	params[pnr++] = ndlbuf;
+	params[pnr++] = "ttsField";
+	params[pnr++] = ttsbuf;
 	params[pnr++] = "stopdepthField";
 	params[pnr++] = stopdepthbuf;
 	params[pnr++] = "date";
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 8e53a99..98dbefd 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -6,12 +6,12 @@
 #include "ui_divelogimportdialog.h"
 
 const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] = {
-	// time, depth, temperature, po2, cns, ndl, stopdepth
+	// time, depth, temperature, po2, cns, ndl, tts, stopdepth
 	{ "", },
-	{ "APD Log Viewer", 1, 2, 16, 7, 18, -1, 19, "Tab" },
-	{ "XP5", 1, 2, 10, -1, -1, -1, -1, "Tab" },
-	{ "SensusCSV", 10, 11, -1, -1, -1, -1, -1, "," },
-	{ "Seabear CSV", 1, 2, 6, -1, -1, -1, 5, ";" },
+	{ "APD Log Viewer", 1, 2, 16, 7, 18, -1, -1, 19, "Tab" },
+	{ "XP5", 1, 2, 10, -1, -1, -1, -1, -1, "Tab" },
+	{ "SensusCSV", 10, 11, -1, -1, -1, -1, -1, -1, "," },
+	{ "Seabear CSV", 1, 2, 6, -1, -1, -1, -1, 5, ";" },
 	{ NULL, }
 };
 
@@ -47,6 +47,8 @@ DiveLogImportDialog::DiveLogImportDialog(QStringList *fn, QWidget *parent) : QDi
 	connect(ui->cnsCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
 	connect(ui->CSVndl, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
 	connect(ui->ndlCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
+	connect(ui->CSVtts, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
+	connect(ui->ttsCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
 	connect(ui->CSVstopdepth, SIGNAL(valueChanged(int)), this, SLOT(unknownImports()));
 	connect(ui->stopdepthCheckBox, SIGNAL(clicked(bool)), this, SLOT(unknownImports()));
 	QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
@@ -70,6 +72,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
 				       VALUE_IF_CHECKED(CSVpo2),
 				       VALUE_IF_CHECKED(CSVcns),
 				       VALUE_IF_CHECKED(CSVndl),
+				       VALUE_IF_CHECKED(CSVtts),
 				       VALUE_IF_CHECKED(CSVstopdepth),
 				       ui->CSVSeparator->currentIndex(),
 				       specialCSV.contains(ui->knownImports->currentIndex()) ? CSVApps[ui->knownImports->currentIndex()].name.toUtf8().data() : "csv",
@@ -120,6 +123,7 @@ void DiveLogImportDialog::on_knownImports_currentIndexChanged(int index)
 	SET_VALUE_AND_CHECKBOX(CSVpo2, po2CheckBox, CSVApps[index].po2);
 	SET_VALUE_AND_CHECKBOX(CSVcns, cnsCheckBox, CSVApps[index].cns);
 	SET_VALUE_AND_CHECKBOX(CSVndl, ndlCheckBox, CSVApps[index].ndl);
+	SET_VALUE_AND_CHECKBOX(CSVtts, ttsCheckBox, CSVApps[index].tts);
 	SET_VALUE_AND_CHECKBOX(CSVstopdepth, stopdepthCheckBox, CSVApps[index].stopdepth);
 	ui->CSVSeparator->blockSignals(true);
 	int separator_index = ui->CSVSeparator->findText(CSVApps[index].separator);
diff --git a/qt-ui/divelogimportdialog.h b/qt-ui/divelogimportdialog.h
index ff81fe6..637d85a 100644
--- a/qt-ui/divelogimportdialog.h
+++ b/qt-ui/divelogimportdialog.h
@@ -37,6 +37,7 @@ private:
 		int po2;
 		int cns;
 		int ndl;
+		int tts;
 		int stopdepth;
 		QString separator;
 	};
diff --git a/qt-ui/divelogimportdialog.ui b/qt-ui/divelogimportdialog.ui
index 0fbb96b..987768d 100644
--- a/qt-ui/divelogimportdialog.ui
+++ b/qt-ui/divelogimportdialog.ui
@@ -159,6 +159,26 @@
             </property>
            </widget>
           </item>
+          <item row="6" column="0">
+           <widget class="QCheckBox" name="ttsCheckBox">
+            <property name="text">
+             <string>TTS</string>
+            </property>
+           </widget>
+          </item>
+          <item row="6" column="1">
+           <widget class="QSpinBox" name="CSVtts">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="minimum">
+             <number>1</number>
+            </property>
+            <property name="value">
+             <number>1</number>
+            </property>
+           </widget>
+          </item>
           <item row="4" column="0">
            <widget class="QCheckBox" name="cnsCheckBox">
             <property name="text">
@@ -169,6 +189,8 @@
          </layout>
          <zorder>ndlCheckBox</zorder>
          <zorder>CSVndl</zorder>
+         <zorder>ttsCheckBox</zorder>
+         <zorder>CSVtts</zorder>
          <zorder>label</zorder>
          <zorder>label_2</zorder>
          <zorder>CSVTime</zorder>
diff --git a/xslt/csv2xml.xslt b/xslt/csv2xml.xslt
index 034eb93..74770f4 100644
--- a/xslt/csv2xml.xslt
+++ b/xslt/csv2xml.xslt
@@ -9,6 +9,7 @@
   <xsl:param name="cnsField" select="cnsField"/>
   <xsl:param name="otuField" select="otuField"/>
   <xsl:param name="ndlField" select="ndlField"/>
+  <xsl:param name="ttsField" select="ttsField"/>
   <xsl:param name="stopdepthField" select="stopdepthField"/>
   <xsl:param name="date" select="date"/>
   <xsl:param name="time" select="time"/>
@@ -187,6 +188,15 @@
           </xsl:attribute>
         </xsl:if>
 
+        <xsl:if test="$ttsField >= 0">
+          <xsl:attribute name="tts">
+            <xsl:call-template name="getFieldByIndex">
+              <xsl:with-param name="index" select="$ttsField"/>
+              <xsl:with-param name="line" select="$line"/>
+            </xsl:call-template>
+          </xsl:attribute>
+        </xsl:if>
+
         <xsl:if test="$stopdepthField >= 0">
           <xsl:variable name="stopdepth">
             <xsl:call-template name="getFieldByIndex">
-- 
1.9.1



More information about the subsurface mailing list