From ae421b08063109c5047f20064df392b628e93c75 Mon Sep 17 00:00:00 2001
From: Karsten Rink <karsten.rink@ufz.de>
Date: Mon, 7 Oct 2013 15:08:50 +0200
Subject: [PATCH] linked functionality to GUI

---
 Gui/DataView/CMakeLists.txt             |   3 +
 Gui/DataView/GeoMapper.cpp              |   2 +-
 Gui/DataView/GeoOnMeshMapping.ui        | 145 ++++++++++++++++++++++++
 Gui/DataView/GeoOnMeshMappingDialog.cpp |  40 +++++++
 Gui/DataView/GeoOnMeshMappingDialog.h   |  50 ++++++++
 Gui/mainwindow.cpp                      |  33 +++++-
 6 files changed, 269 insertions(+), 4 deletions(-)
 create mode 100644 Gui/DataView/GeoOnMeshMapping.ui
 create mode 100644 Gui/DataView/GeoOnMeshMappingDialog.cpp
 create mode 100644 Gui/DataView/GeoOnMeshMappingDialog.h

diff --git a/Gui/DataView/CMakeLists.txt b/Gui/DataView/CMakeLists.txt
index 7dd895ea377..fac037a8b20 100644
--- a/Gui/DataView/CMakeLists.txt
+++ b/Gui/DataView/CMakeLists.txt
@@ -10,6 +10,7 @@ set( SOURCES
 	FEMConditionSetupDialog.cpp
 	GeoMapper.cpp
 	GEOModels.cpp
+	GeoOnMeshMappingDialog.cpp
 	GeoTabWidget.cpp
 	GeoTreeModel.cpp
 	GeoTreeView.cpp
@@ -50,6 +51,7 @@ set( MOC_HEADERS
 	ElementTreeView.h
 	FEMConditionSetupDialog.h
 	GEOModels.h
+	GeoOnMeshMappingDialog.h
 	GeoTabWidget.h
 	GeoTreeModel.h
 	GeoTreeView.h
@@ -97,6 +99,7 @@ set( UIS
 	CondFromRaster.ui
 	ConditionWriter.ui
 	FEMConditionSetup.ui
+	GeoOnMeshMapping.ui
 	GeoTabWidgetBase.ui
 	GMSHPrefs.ui
 	License.ui
diff --git a/Gui/DataView/GeoMapper.cpp b/Gui/DataView/GeoMapper.cpp
index 028ede1d50d..3336daf2283 100644
--- a/Gui/DataView/GeoMapper.cpp
+++ b/Gui/DataView/GeoMapper.cpp
@@ -39,7 +39,6 @@ GeoMapper::GeoMapper(GeoLib::GEOObjects &geo_objects, const std::string &geo_nam
 GeoMapper::~GeoMapper()
 {
 	delete _raster;
-	delete _mesh;
 }
 
 void GeoMapper::mapOnDEM(const std::string &file_name)
@@ -56,6 +55,7 @@ void GeoMapper::mapOnMesh(const std::string &file_name)
 {
 	MeshLib::Mesh *mesh (FileIO::readMeshFromFile(file_name));
 	mapOnMesh(mesh);
+	delete mesh;
 }
 
 void GeoMapper::mapOnMesh(const MeshLib::Mesh* mesh)
diff --git a/Gui/DataView/GeoOnMeshMapping.ui b/Gui/DataView/GeoOnMeshMapping.ui
new file mode 100644
index 00000000000..8784c35cf4b
--- /dev/null
+++ b/Gui/DataView/GeoOnMeshMapping.ui
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>GeoOnMeshMapping</class>
+ <widget class="QDialog" name="GeoOnMeshMapping">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>199</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Mapping Options</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="1" column="0" colspan="2">
+    <widget class="QRadioButton" name="normalMappingButton">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>10</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Map original geometry points</string>
+     </property>
+     <property name="checked">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0">
+    <widget class="QLabel" name="geoNameLabel">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Name of new geometry:</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <widget class="QLineEdit" name="geoNameEdit">
+     <property name="enabled">
+      <bool>false</bool>
+     </property>
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>10</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="readOnly">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0" colspan="2">
+    <widget class="QLabel" name="headerLabel">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="font">
+      <font>
+       <pointsize>10</pointsize>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Geometry mapping on mesh</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="2">
+    <widget class="QRadioButton" name="advancedMappingButton">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>10</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="text">
+      <string>Copy geometry and insert additional points</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
+    <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>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>GeoOnMeshMapping</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>GeoOnMeshMapping</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/Gui/DataView/GeoOnMeshMappingDialog.cpp b/Gui/DataView/GeoOnMeshMappingDialog.cpp
new file mode 100644
index 00000000000..382f62dd9a2
--- /dev/null
+++ b/Gui/DataView/GeoOnMeshMappingDialog.cpp
@@ -0,0 +1,40 @@
+/**
+ * \file
+ * \author Karsten Rink
+ * \date   2013-10-07
+ * \brief  Implementation of the GeoOnMeshMappingDialog class.
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#include "GeoOnMeshMappingDialog.h"
+
+// ThirdParty/logog
+#include "logog/include/logog.hpp"
+
+#include "OGSError.h"
+
+
+GeoOnMeshMappingDialog::GeoOnMeshMappingDialog(QDialog* parent)
+	: _new_geo_name(""), QDialog(parent)
+{
+	setupUi(this);
+}
+
+GeoOnMeshMappingDialog::~GeoOnMeshMappingDialog()
+{
+}
+
+void GeoOnMeshMappingDialog::accept()
+{
+	if (this->advancedMappingButton->isEnabled())
+		_new_geo_name = this->geoNameEdit->text().toStdString();
+	this->done(QDialog::Accepted);
+}
+
+
diff --git a/Gui/DataView/GeoOnMeshMappingDialog.h b/Gui/DataView/GeoOnMeshMappingDialog.h
new file mode 100644
index 00000000000..d2b301b54c7
--- /dev/null
+++ b/Gui/DataView/GeoOnMeshMappingDialog.h
@@ -0,0 +1,50 @@
+/**
+ * \file
+ * \author Karsten Rink
+ * \date   2013-10-07
+ * \brief  Definition of the GeoOnMeshMappingDialog class.
+ *
+ * \copyright
+ * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org)
+ *            Distributed under a Modified BSD License.
+ *              See accompanying file LICENSE.txt or
+ *              http://www.opengeosys.org/project/license
+ *
+ */
+
+#ifndef GEOTOMESHMAPPINGDIALOG_H
+#define GEOTOMESHMAPPINGDIALOG_H
+
+#include "ui_GeoOnMeshMapping.h"
+#include <QDialog>
+
+#include "GeoMapper.h"
+
+/**
+ * \brief A dialog window for creating DIRECT boundary conditions from raster files
+ */
+class GeoOnMeshMappingDialog : public QDialog, private Ui_GeoOnMeshMapping
+{
+	Q_OBJECT
+
+public:
+	GeoOnMeshMappingDialog(QDialog* parent = 0);
+	~GeoOnMeshMappingDialog(void);
+
+	std::string getNewGeoName() const { return _new_geo_name; };
+
+private:
+	std::string _new_geo_name;
+
+private slots:
+	void on_advancedMappingButton_toggled(bool isSelected) { this->geoNameEdit->setEnabled(isSelected); };
+
+	/// Instructions if the OK-Button has been pressed.
+	void accept();
+
+	/// Instructions if the Cancel-Button has been pressed.
+	void reject() { this->done(QDialog::Rejected); };
+
+};
+
+#endif //GEOTOMESHMAPPINGDIALOG_H
diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp
index c4430619aa4..c8767361367 100644
--- a/Gui/mainwindow.cpp
+++ b/Gui/mainwindow.cpp
@@ -34,6 +34,7 @@
 #include "DiagramPrefsDialog.h"
 #include "FEMConditionSetupDialog.h"
 //TODO6 #include "OGSFileConverter.h"
+#include "GeoOnMeshMappingDialog.h"
 #include "GMSHPrefsDialog.h"
 #include "LicenseDialog.h"
 #include "LineEditDialog.h"
@@ -949,17 +950,43 @@ void MainWindow::mapGeometry(const std::string &geo_name)
 	QSettings settings("UFZ", "OpenGeoSys-5");
 	QString file_name = QFileDialog::getOpenFileName( this, "Select file for mapping",
 													  settings.value("lastOpenedFileDirectory").toString(),
-													  "Raster files(*.asc *.grd);;OpenGeoSys mesh files (*.vtu *.msh)");
+													  "OpenGeoSys mesh files (*.vtu *.msh);;Raster files(*.asc *.grd)");
 	GeoMapper geo_mapper(*_geoModels, geo_name);
 
 	if (file_name.compare("") != 0)
 	{
 		QFileInfo fi(file_name);
 		if (fi.suffix().toLower() == "asc" || fi.suffix().toLower() == "grd")
+		{
 			geo_mapper.mapOnDEM(file_name.toStdString());
+			this->_geoModels->updateGeometry(geo_name);
+		}
 		else if (fi.suffix().toLower() == "vtu" || fi.suffix().toLower() == "msh")
-			geo_mapper.mapOnMesh(file_name.toStdString());
-		this->_geoModels->updateGeometry(geo_name);
+		{
+			GeoOnMeshMappingDialog dlg;
+			if (dlg.exec() == QDialog::Accepted)
+			{
+				// just get mesh if already in memory
+				const MeshLib::Mesh* msh (this->_project.getMesh(fi.completeBaseName().toStdString()));
+
+				// read mesh otherwise
+				if (!msh)
+					msh = FileIO::readMeshFromFile(file_name.toStdString());
+
+				std::string new_geo_name = dlg.getNewGeoName();
+		
+				if (new_geo_name.empty())
+				{
+					geo_mapper.mapOnMesh(msh);
+					this->_geoModels->updateGeometry(geo_name);
+				}
+				else
+				{
+					geo_mapper.advancedMapOnMesh(msh, new_geo_name);
+					this->_geoModels->updateGeometry(new_geo_name);
+				}
+			}
+		}		
 	}
 }
 
-- 
GitLab