From e63a898364394c818460d77f36e13dc724580887 Mon Sep 17 00:00:00 2001
From: rinkk <karsten.rink@ufz.de>
Date: Wed, 17 Jun 2020 11:36:56 +0200
Subject: [PATCH] [gui] adding widget and access for ignoring nodata

---
 .../DataExplorer/DataView/MeshMapping2D.ui    | 65 ++++++++++---------
 .../DataView/MeshMapping2DDialog.cpp          | 17 ++++-
 .../DataView/MeshMapping2DDialog.h            |  2 +
 .../DataExplorer/DataView/MeshView.cpp        |  3 +-
 4 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/Applications/DataExplorer/DataView/MeshMapping2D.ui b/Applications/DataExplorer/DataView/MeshMapping2D.ui
index 5a2a1e6ab34..c508556503a 100644
--- a/Applications/DataExplorer/DataView/MeshMapping2D.ui
+++ b/Applications/DataExplorer/DataView/MeshMapping2D.ui
@@ -26,6 +26,20 @@
    <string>2D Mesh Mapping</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
+   <item row="6" column="2">
+    <widget class="QLineEdit" name="newNameEdit">
+     <property name="text">
+      <string>MappedMesh</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0" colspan="2">
+    <widget class="QLabel" name="newNameLabel">
+     <property name="text">
+      <string>Name of new mesh:</string>
+     </property>
+    </widget>
+   </item>
    <item row="1" column="3">
     <widget class="QPushButton" name="rasterSelectButton">
      <property name="maximumSize">
@@ -39,20 +53,6 @@
      </property>
     </widget>
    </item>
-   <item row="2" column="0" colspan="2">
-    <widget class="QLabel" name="noDataValueLabel">
-     <property name="text">
-      <string>     Set NoData values to:</string>
-     </property>
-    </widget>
-   </item>
-   <item row="3" column="0" colspan="2">
-    <widget class="QRadioButton" name="staticValueButton">
-     <property name="text">
-      <string>Map to static value:</string>
-     </property>
-    </widget>
-   </item>
    <item row="1" column="2">
     <widget class="QLineEdit" name="rasterPathEdit"/>
    </item>
@@ -66,7 +66,7 @@
      </property>
     </widget>
    </item>
-   <item row="2" column="2">
+   <item row="4" column="2">
     <widget class="QLineEdit" name="noDataValueEdit">
      <property name="text">
       <string>0.0</string>
@@ -76,7 +76,7 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="2">
+   <item row="5" column="2">
     <widget class="QLineEdit" name="staticValueEdit">
      <property name="enabled">
       <bool>false</bool>
@@ -89,13 +89,10 @@
      </property>
     </widget>
    </item>
-   <item row="5" column="1" colspan="3">
-    <widget class="QDialogButtonBox" name="buttonBox">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="standardButtons">
-      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+   <item row="5" column="0" colspan="2">
+    <widget class="QRadioButton" name="staticValueButton">
+     <property name="text">
+      <string>Map to static value:</string>
      </property>
     </widget>
    </item>
@@ -109,17 +106,27 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="2">
-    <widget class="QLineEdit" name="newNameEdit">
-     <property name="text">
-      <string>MappedMesh</string>
+   <item row="7" column="1" colspan="3">
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
      </property>
     </widget>
    </item>
    <item row="4" column="0" colspan="2">
-    <widget class="QLabel" name="newNameLabel">
+    <widget class="QLabel" name="noDataValueLabel">
      <property name="text">
-      <string>Name of new mesh:</string>
+      <string>     Set NoData values to:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="3">
+    <widget class="QCheckBox" name="ignoreNoDataCheckbox">
+     <property name="text">
+      <string>Ignore</string>
      </property>
     </widget>
    </item>
diff --git a/Applications/DataExplorer/DataView/MeshMapping2DDialog.cpp b/Applications/DataExplorer/DataView/MeshMapping2DDialog.cpp
index b61d1eccc18..7092597051c 100644
--- a/Applications/DataExplorer/DataView/MeshMapping2DDialog.cpp
+++ b/Applications/DataExplorer/DataView/MeshMapping2DDialog.cpp
@@ -25,10 +25,17 @@ MeshMapping2DDialog::MeshMapping2DDialog(QDialog* parent)
     this->staticValueEdit->setValidator (static_value_validator);
 }
 
+void MeshMapping2DDialog::on_ignoreNoDataCheckbox_toggled(bool isChecked)
+{
+    this->noDataValueEdit->setEnabled(!isChecked);
+}
+
 void MeshMapping2DDialog::on_rasterValueButton_toggled(bool isChecked)
 {
     this->rasterPathEdit->setEnabled(isChecked);
-    this->noDataValueEdit->setEnabled(isChecked);
+    this->ignoreNoDataCheckbox->setEnabled(isChecked);
+    this->noDataValueEdit->setEnabled(isChecked &&
+                                      !this->ignoreNoDataCheckbox->isChecked());
     this->rasterSelectButton->setEnabled(isChecked);
     this->staticValueEdit->setEnabled(!isChecked);
 }
@@ -52,7 +59,9 @@ void MeshMapping2DDialog::accept()
         OGSError::box("Please specify path to raster file.");
         return;
     }
-    if (this->rasterValueButton->isChecked() && this->noDataValueEdit->text().isEmpty())
+    if (this->rasterValueButton->isChecked() &&
+        !this->ignoreNoDataCheckbox->isChecked() &&
+        this->noDataValueEdit->text().isEmpty())
     {
         OGSError::box("Please specify No Data value.");
         return;
@@ -67,6 +76,10 @@ void MeshMapping2DDialog::accept()
         OGSError::box("Please specify a name for the resulting mesh.");
         return;
     }
+    if (this->noDataValueEdit->text().isEmpty())
+    {
+        this->noDataValueEdit->setText("0.0");
+    }
 
     this->done(QDialog::Accepted);
 }
diff --git a/Applications/DataExplorer/DataView/MeshMapping2DDialog.h b/Applications/DataExplorer/DataView/MeshMapping2DDialog.h
index 4a4b015ac85..e99b1a86d97 100644
--- a/Applications/DataExplorer/DataView/MeshMapping2DDialog.h
+++ b/Applications/DataExplorer/DataView/MeshMapping2DDialog.h
@@ -29,10 +29,12 @@ public:
     bool useStaticMapping() const { return this->staticValueButton->isChecked(); }
     std::string getRasterPath() const { return this->rasterPathEdit->text().toStdString(); }
     double getNoDataReplacement() const { return this->noDataValueEdit->text().toDouble(); }
+    bool getIgnoreNoData() const { return this->ignoreNoDataCheckbox->isChecked(); }
     double getStaticValue() const { return this->staticValueEdit->text().toDouble(); }
     std::string getNewMeshName() const { return this->newNameEdit->text().toStdString(); }
 
 private slots:
+    void on_ignoreNoDataCheckbox_toggled(bool isChecked);
     void on_rasterValueButton_toggled(bool isChecked);
     void on_rasterSelectButton_pressed();
 
diff --git a/Applications/DataExplorer/DataView/MeshView.cpp b/Applications/DataExplorer/DataView/MeshView.cpp
index 8515b5656ee..746c9a99099 100644
--- a/Applications/DataExplorer/DataView/MeshView.cpp
+++ b/Applications/DataExplorer/DataView/MeshView.cpp
@@ -189,7 +189,8 @@ void MeshView::openMap2dMeshDialog()
             return;
         }
         if (!MeshLib::MeshLayerMapper::layerMapping(*result, *raster,
-                                                    dlg.getNoDataReplacement()))
+                                                    dlg.getNoDataReplacement(),
+                                                    dlg.getIgnoreNoData()))
         {
             OGSError::box("Error mapping mesh.");
             return;
-- 
GitLab