Dear friends,

Am 03.10.2016 um 18:06 schrieb Robert C. Helling <rob...@euve10195.vserver.de>:

I have three patches on my laptop, one of which is a bugfix.  Will send tonight with proper internet connection. Hold the horses.

back home, so here we go:

From 546d752a4379050eaa8d9056bf1b3b0de88d91e4 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <hell...@atdotde.de>
Date: Mon, 3 Oct 2016 16:25:48 +0200
Subject: [PATCH 2/5] Add preference to change deco model
To: subsurface@subsurface-divelog.org

Signed-off-by: Robert C. Helling <hell...@atdotde.de>
---
 core/subsurface-qt/SettingsObjectWrapper.cpp      |  21 ++++
 core/subsurface-qt/SettingsObjectWrapper.h        |   4 +
 desktop-widgets/preferences/preferences_graph.cpp |  17 +++
 desktop-widgets/preferences/preferences_graph.h   |   3 +-
 desktop-widgets/preferences/preferences_graph.ui  | 123 ++++++++++++----------
 5 files changed, 114 insertions(+), 54 deletions(-)

diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp 
b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 437bf7f..8303afa 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -299,6 +299,11 @@ bool TechnicalDetailsSettings::calcndltts() const
        return prefs.calcndltts;
 }
 
+bool TechnicalDetailsSettings::buehlmann() const
+{
+       return (prefs.deco_mode == BUEHLMANN);
+}
+
 int TechnicalDetailsSettings::gflow() const
 {
        return prefs.gflow;
@@ -499,6 +504,17 @@ void TechnicalDetailsSettings::setCalcndltts(bool value)
        emit calcndlttsChanged(value);
 }
 
+void TechnicalDetailsSettings::setBuehlmann(bool value)
+{
+       if (value == (prefs.deco_mode == BUEHLMANN))
+               return;
+       QSettings s;
+       s.beginGroup(group);
+       s.setValue("buehlmann", value);
+       prefs.deco_mode = value ? BUEHLMANN : VPMB;
+       emit buehlmannChanged(value);
+}
+
 void TechnicalDetailsSettings::setGflow(int value)
 {
        if (value == prefs.gflow)
@@ -2105,6 +2121,11 @@ void SettingsObjectWrapper::load()
        GET_BOOL("tankbar", tankbar);
        GET_BOOL("RulerBar", rulergraph);
        GET_BOOL("percentagegraph", percentagegraph);
+       v = s.value("buehlmann");
+       if (v.isValid())
+               prefs.deco_mode = v.toBool() ? BUEHLMANN : VPMB;
+       else
+               prefs.deco_mode = BUEHLMANN;
        GET_INT("gflow", gflow);
        GET_INT("gfhigh", gfhigh);
        GET_INT("vpmb_conservatism", vpmb_conservatism);
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h 
b/core/subsurface-qt/SettingsObjectWrapper.h
index 1ab3208..8097fc3 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -116,6 +116,7 @@ class TechnicalDetailsSettings : public QObject {
        Q_PROPERTY(bool calcceiling3m    READ calcceiling3m   WRITE 
setCalcceiling3m   NOTIFY calcceiling3mChanged)
        Q_PROPERTY(bool calcalltissues   READ calcalltissues  WRITE 
setCalcalltissues  NOTIFY calcalltissuesChanged)
        Q_PROPERTY(bool calcndltts       READ calcndltts      WRITE 
setCalcndltts      NOTIFY calcndlttsChanged)
+       Q_PROPERTY(bool buehlmann        READ buehlmann       WRITE 
setBuehlmann       NOTIFY buehlmannChanged)
        Q_PROPERTY(int gflow            READ gflow           WRITE setGflow     
      NOTIFY gflowChanged)
        Q_PROPERTY(int gfhigh           READ gfhigh          WRITE setGfhigh    
      NOTIFY gfhighChanged)
        Q_PROPERTY(short vpmb_conservatism READ vpmbConservatism WRITE 
setVpmbConservatism NOTIFY vpmbConservatismChanged)
@@ -143,6 +144,7 @@ public:
        bool calcceiling3m() const;
        bool calcalltissues() const;
        bool calcndltts() const;
+       bool buehlmann() const;
        int gflow() const;
        int gfhigh() const;
        short vpmbConservatism() const;
@@ -169,6 +171,7 @@ public slots:
        void setCalcceiling3m(bool value);
        void setCalcalltissues(bool value);
        void setCalcndltts(bool value);
+       void setBuehlmann(bool value);
        void setGflow(int value);
        void setGfhigh(int value);
        void setVpmbConservatism(short);
@@ -195,6 +198,7 @@ signals:
        void calcceiling3mChanged(bool value);
        void calcalltissuesChanged(bool value);
        void calcndlttsChanged(bool value);
+       void buehlmannChanged(bool value);
        void gflowChanged(int value);
        void gfhighChanged(int value);
        void vpmbConservatismChanged(short value);
diff --git a/desktop-widgets/preferences/preferences_graph.cpp 
b/desktop-widgets/preferences/preferences_graph.cpp
index c13915e..8f3e5e7 100644
--- a/desktop-widgets/preferences/preferences_graph.cpp
+++ b/desktop-widgets/preferences/preferences_graph.cpp
@@ -25,6 +25,13 @@ void PreferencesGraph::refreshSettings()
        ui->maxpo2->setValue(prefs.modpO2);
        ui->red_ceiling->setChecked(prefs.redceiling);
 
+       if (prefs.deco_mode == BUEHLMANN) {
+               ui->buehlmann->setChecked(true);
+               ui->vpmb->setChecked(false);
+       } else {
+               ui->buehlmann->setChecked(false);
+               ui->vpmb->setChecked(false);
+       }
        ui->gflow->setValue(prefs.gflow);
        ui->gfhigh->setValue(prefs.gfhigh);
        ui->vpmb_conservatism->setValue(prefs.vpmb_conservatism);
@@ -54,6 +61,7 @@ void PreferencesGraph::syncSettings()
        auto tech = SettingsObjectWrapper::instance()->techDetails;
        tech->setModp02(ui->maxpo2->value());
        tech->setRedceiling(ui->red_ceiling->isChecked());
+       tech->setBuehlmann(ui->buehlmann->isChecked());
        tech->setGflow(ui->gflow->value());
        tech->setGfhigh(ui->gfhigh->value());
        tech->setVpmbConservatism(ui->vpmb_conservatism->value());
@@ -73,4 +81,13 @@ void PreferencesGraph::on_gfhigh_valueChanged(int gf)
 {
        ui->gfhigh->setStyleSheet(DANGER_GF);
 }
+
+void PreferencesGraph::on_buehlmann_toggled(bool buehlmann)
+{
+       ui->gfhigh->setEnabled(buehlmann);
+       ui->gflow->setEnabled(buehlmann);
+       ui->gf_low_at_maxdepth->setEnabled(buehlmann);
+       ui->vpmb_conservatism->setEnabled(!buehlmann);
+}
+
 #undef DANGER_GF
diff --git a/desktop-widgets/preferences/preferences_graph.h 
b/desktop-widgets/preferences/preferences_graph.h
index ca40c0a..328f348 100644
--- a/desktop-widgets/preferences/preferences_graph.h
+++ b/desktop-widgets/preferences/preferences_graph.h
@@ -18,10 +18,11 @@ public:
 private slots:
        void on_gflow_valueChanged(int gf);
        void on_gfhigh_valueChanged(int gf);
+       void on_buehlmann_toggled(bool buelmann);
 
 private:
        Ui::PreferencesGraph *ui;
 
 };
 
-#endif
\ No newline at end of file
+#endif
diff --git a/desktop-widgets/preferences/preferences_graph.ui 
b/desktop-widgets/preferences/preferences_graph.ui
index b8d6a46..ab5c191 100644
--- a/desktop-widgets/preferences/preferences_graph.ui
+++ b/desktop-widgets/preferences/preferences_graph.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>505</width>
-    <height>555</height>
+    <height>575</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -133,15 +133,15 @@
       <string>Misc</string>
      </property>
      <layout class="QGridLayout" name="gridLayout_2">
-      <item row="0" column="0">
+      <item row="1" column="0">
        <widget class="QLabel" name="label_19">
         <property name="text">
          <string>GFLow</string>
         </property>
        </widget>
       </item>
-      <item row="0" column="1">
-       <widget class="QSpinBox" name="gflow">
+      <item row="2" column="1">
+       <widget class="QSpinBox" name="gfhigh">
         <property name="minimum">
          <number>1</number>
         </property>
@@ -150,15 +150,22 @@
         </property>
        </widget>
       </item>
-      <item row="1" column="0">
-       <widget class="QLabel" name="label_20">
+      <item row="8" column="0" colspan="2">
+       <widget class="QCheckBox" name="show_ccr_setpoint">
         <property name="text">
-         <string>GFHigh</string>
+         <string>CCR: show setpoints when viewing pO₂</string>
+        </property>
+       </widget>
+      </item>
+      <item row="7" column="0" colspan="2">
+       <widget class="QCheckBox" name="gf_low_at_maxdepth">
+        <property name="text">
+         <string>GFLow at max depth</string>
         </property>
        </widget>
       </item>
       <item row="1" column="1">
-       <widget class="QSpinBox" name="gfhigh">
+       <widget class="QSpinBox" name="gflow">
         <property name="minimum">
          <number>1</number>
         </property>
@@ -168,33 +175,61 @@
        </widget>
       </item>
       <item row="2" column="0">
+       <widget class="QLabel" name="label_20">
+        <property name="text">
+         <string>GFHigh</string>
+        </property>
+       </widget>
+      </item>
+      <item row="6" column="1">
+       <widget class="QSpinBox" name="pscrfactor">
+        <property name="suffix">
+         <string/>
+        </property>
+        <property name="prefix">
+         <string>1:</string>
+        </property>
+       </widget>
+      </item>
+      <item row="6" column="0">
+       <widget class="QLabel" name="label_28">
+        <property name="text">
+         <string>pSCR ratio</string>
+        </property>
+       </widget>
+      </item>
+      <item row="3" column="0">
        <widget class="QLabel" name="label_21">
         <property name="text">
          <string>VPM-B Conservatism</string>
         </property>
        </widget>
       </item>
-      <item row="2" column="1">
-       <widget class="QSpinBox" name="vpmb_conservatism">
-        <property name="prefix">
-         <string>+</string>
+      <item row="9" column="0" colspan="2">
+       <widget class="QCheckBox" name="show_ccr_sensors">
+        <property name="text">
+         <string>CCR: show individual O₂ sensor values when viewing 
pO₂</string>
         </property>
-        <property name="minimum">
-         <number>0</number>
+       </widget>
+      </item>
+      <item row="5" column="1">
+       <widget class="QDoubleSpinBox" name="psro2rate">
+        <property name="suffix">
+         <string>ℓ/min</string>
         </property>
-        <property name="maximum">
-         <number>4</number>
+        <property name="decimals">
+         <number>3</number>
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
+      <item row="4" column="0">
        <widget class="QLabel" name="label_26">
         <property name="text">
          <string>Default CCR set-point for dive planning</string>
         </property>
        </widget>
       </item>
-      <item row="3" column="1">
+      <item row="4" column="1">
        <widget class="QDoubleSpinBox" name="defaultSetpoint">
         <property name="suffix">
          <string>bar</string>
@@ -210,58 +245,40 @@
         </property>
        </widget>
       </item>
-      <item row="4" column="0">
+      <item row="5" column="0">
        <widget class="QLabel" name="pSCR">
         <property name="text">
          <string>pSCR O₂ metabolism rate</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="1">
-       <widget class="QDoubleSpinBox" name="psro2rate">
-        <property name="suffix">
-         <string>ℓ/min</string>
-        </property>
-        <property name="decimals">
-         <number>3</number>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="0">
-       <widget class="QLabel" name="label_28">
-        <property name="text">
-         <string>pSCR ratio</string>
+      <item row="3" column="1">
+       <widget class="QSpinBox" name="vpmb_conservatism">
+        <property name="prefix">
+         <string>+</string>
         </property>
-       </widget>
-      </item>
-      <item row="5" column="1">
-       <widget class="QSpinBox" name="pscrfactor">
-        <property name="suffix">
-         <string/>
+        <property name="minimum">
+         <number>0</number>
         </property>
-        <property name="prefix">
-         <string>1:</string>
+        <property name="maximum">
+         <number>4</number>
         </property>
        </widget>
       </item>
-      <item row="6" column="0" colspan="2">
-       <widget class="QCheckBox" name="gf_low_at_maxdepth">
+      <item row="0" column="0">
+       <widget class="QRadioButton" name="buehlmann">
         <property name="text">
-         <string>GFLow at max depth</string>
+         <string>Bühlmann</string>
         </property>
-       </widget>
-      </item>
-      <item row="7" column="0" colspan="2">
-       <widget class="QCheckBox" name="show_ccr_setpoint">
-        <property name="text">
-         <string>CCR: show setpoints when viewing pO₂</string>
+        <property name="checked">
+         <bool>true</bool>
         </property>
        </widget>
       </item>
-      <item row="8" column="0" colspan="2">
-       <widget class="QCheckBox" name="show_ccr_sensors">
+      <item row="0" column="1">
+       <widget class="QRadioButton" name="vpmb">
         <property name="text">
-         <string>CCR: show individual O₂ sensor values when viewing 
pO₂</string>
+         <string>VPM-B</string>
         </property>
        </widget>
       </item>
-- 
2.8.4 (Apple Git-73)

From 4222449c6e6ff51481d531727e87af99bfee9c36 Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <hell...@atdotde.de>
Date: Mon, 3 Oct 2016 16:38:37 +0200
Subject: [PATCH 3/4] Compute weighted Buehlmann coefficients for all deco
 models
To: subsurface@subsurface-divelog.org

... as those are needed for the heatmap and not only
for Buehlmann ceilings.

Signed-off-by: Robert C. Helling <hell...@atdotde.de>
---
 core/deco.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/core/deco.c b/core/deco.c
index 5d4a18c..09426bd 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -248,11 +248,13 @@ double tissue_tolerance_calc(const struct dive *dive, 
double pressure)
        double lowest_ceiling = 0.0;
        double tissue_lowest_ceiling[16];
 
+       for (ci = 0; ci < 16; ci++) {
+               buehlmann_inertgas_a[ci] = ((buehlmann_N2_a[ci] * 
tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * tissue_he_sat[ci])) / 
tissue_inertgas_saturation[ci];
+               buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * 
tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / 
tissue_inertgas_saturation[ci];
+       }
+
        if (prefs.deco_mode != VPMB) {
                for (ci = 0; ci < 16; ci++) {
-                       buehlmann_inertgas_a[ci] = ((buehlmann_N2_a[ci] * 
tissue_n2_sat[ci]) + (buehlmann_He_a[ci] * tissue_he_sat[ci])) / 
tissue_inertgas_saturation[ci];
-                       buehlmann_inertgas_b[ci] = ((buehlmann_N2_b[ci] * 
tissue_n2_sat[ci]) + (buehlmann_He_b[ci] * tissue_he_sat[ci])) / 
tissue_inertgas_saturation[ci];
-
 
                        /* tolerated = (tissue_inertgas_saturation - 
buehlmann_inertgas_a) * buehlmann_inertgas_b; */
 
-- 
2.8.4 (Apple Git-73)

From 16917fc0be42cdafa455e2aa63c7428c337d1bbe Mon Sep 17 00:00:00 2001
From: "Robert C. Helling" <hell...@atdotde.de>
Date: Mon, 3 Oct 2016 17:08:02 +0200
Subject: [PATCH 4/4] Export to TeX file initialized
To: subsurface@subsurface-divelog.org

Signed-off-by: Robert C. Helling <hell...@atdotde.de>
---
 desktop-widgets/divelogexportdialog.cpp | 33 +++++++++++++++++++++++++++++++++
 desktop-widgets/divelogexportdialog.h   |  1 +
 desktop-widgets/divelogexportdialog.ui  | 12 +++++++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/desktop-widgets/divelogexportdialog.cpp 
b/desktop-widgets/divelogexportdialog.cpp
index 5b58d0c..395c494 100644
--- a/desktop-widgets/divelogexportdialog.cpp
+++ b/desktop-widgets/divelogexportdialog.cpp
@@ -86,6 +86,8 @@ void DiveLogExportDialog::showExplanation()
                ui->description->setText(tr("Subsurface native XML format."));
        } else if (ui->exportImageDepths->isChecked()) {
                ui->description->setText(tr("Write depths of images to file."));
+       } else if (ui->exportTeX->isChecked()) {
+               ui->description->setText(tr("Write dive as TeX macros to 
file."));
        }
 }
 
@@ -162,6 +164,10 @@ void DiveLogExportDialog::on_buttonBox_accepted()
                        filename = QFileDialog::getSaveFileName(this, tr("Save 
image depths"), lastDir);
                        if (!filename.isNull() && !filename.isEmpty())
                                export_depths(filename.toUtf8().data(), 
ui->exportSelected->isChecked());
+               } else if (ui->exportTeX->isChecked()) {
+                       filename = QFileDialog::getSaveFileName(this, 
tr("Export to TeX file"), lastDir, tr("TeX files(*.tex)"));
+                       if (!filename.isNull() && !filename.isEmpty())
+                               export_TeX(filename.toUtf8().data(), 
ui->exportSelected->isChecked());
                }
                break;
        case 1:
@@ -223,3 +229,30 @@ void DiveLogExportDialog::export_depths(const char 
*filename, const bool selecte
        }
        free_buffer(&buf);
 }
+
+void DiveLogExportDialog::export_TeX(const char *filename, const bool 
selected_only)
+{
+       FILE *f;
+       struct dive *dive;
+       depth_t depth;
+       int i;
+       const char *unit = NULL;
+
+       struct membuffer buf = {};
+
+       for_each_dive (i, dive) {
+               if (selected_only && !dive->selected)
+                       continue;
+
+               put_format(&buf, "\\number{%d}\n", dive->number);
+       }
+
+       f = subsurface_fopen(filename, "w+");
+       if (!f) {
+               report_error(tr("Can't open file %s").toUtf8().data(), 
filename);
+       } else {
+               flush_buffer(&buf, f); /*check for writing errors? */
+               fclose(f);
+       }
+       free_buffer(&buf);
+}
diff --git a/desktop-widgets/divelogexportdialog.h 
b/desktop-widgets/divelogexportdialog.h
index e7cde31..5d5ad14 100644
--- a/desktop-widgets/divelogexportdialog.h
+++ b/desktop-widgets/divelogexportdialog.h
@@ -33,6 +33,7 @@ private:
        void showExplanation();
        void exportHtmlInit(const QString &filename);
        void export_depths(const char *filename, const bool selected_only);
+       void export_TeX(const char *filename, const bool selected_only);
 };
 
 #endif // DIVELOGEXPORTDIALOG_H
diff --git a/desktop-widgets/divelogexportdialog.ui 
b/desktop-widgets/divelogexportdialog.ui
index 4713bf0..d01f817 100644
--- a/desktop-widgets/divelogexportdialog.ui
+++ b/desktop-widgets/divelogexportdialog.ui
@@ -192,6 +192,16 @@
            </widget>
           </item>
           <item>
+           <widget class="QRadioButton" name="exportTeX">
+            <property name="text">
+             <string>TeX</string>
+            </property>
+            <attribute name="buttonGroup">
+             <string notr="true">exportGroup</string>
+            </attribute>
+           </widget>
+          </item>
+          <item>
            <widget class="QRadioButton" name="exportImageDepths">
             <property name="text">
              <string>I&amp;mage depths</string>
@@ -600,7 +610,7 @@
   </connection>
  </connections>
  <buttongroups>
-  <buttongroup name="buttonGroup"/>
   <buttongroup name="exportGroup"/>
+  <buttongroup name="buttonGroup"/>
  </buttongroups>
 </ui>
-- 
2.8.4 (Apple Git-73)


These three patches are of different character:

There is no 0001.

0002 is something I hacked so I can switch between Buehlmann and VPM-B from the preferences (rather than just from the planner). It is a bit rough (and should also grey out those preferences which do not apply to the active model, to be added later). We should have something like this, but this patch might need a bit more work and Tomaz promised something along these lines anyway.

0003 fixes a bug with the heat map when using VPM-B. The scale for the colors is set by the Buehlmann m-value, so we need to compute that even when not using Buehlmann. Yesterday, his bug was found by Willem. 

0004 is a stub for a CFD: Sometime ago, before starting with our template based printing, I had submitted some patches to print via TeX. Those were turned down because we don’t want to add TeX as a dependency, which I can understand. For my own use to print paper logbook pages, I kept rebasing this branch and use it for my own build. Now, I realized I presented this in the wrong way: This is not about printing. This should be presented as another file format we export to. There is no dependency to anything, this just writes a text file with data from the dive in the form of TeX macros. This can then be used to print out the dive, but only if the user wants to. So, philosophically, this is like many of the other exports: Those make only sense to use if the user has the other thing to reimport the data. This patch is only a stub with no real functionality (it exports only the dive number). The actual code to write TeX, I did not have with me when I wrote this earlier today on a train, but I will add this tomorrow if I don’t hear strong opinions to the opposite.

Best
Robert

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to