diff --git a/Gui/DataView/GeoOnMeshMapping.ui b/Gui/DataView/GeoOnMeshMapping.ui index 8784c35cf4b18cb21b6bc0196160d89b850f6280..ba162b0a472bfdf9bcc0be6c10061afcb4b85988 100644 --- a/Gui/DataView/GeoOnMeshMapping.ui +++ b/Gui/DataView/GeoOnMeshMapping.ui @@ -11,7 +11,7 @@ </rect> </property> <property name="windowTitle"> - <string>Mapping Options</string> + <string>Geometry Mapping Options</string> </property> <layout class="QGridLayout" name="gridLayout"> <item row="1" column="0" colspan="2"> @@ -23,7 +23,7 @@ </sizepolicy> </property> <property name="text"> - <string>Map original geometry points</string> + <string>Map original geometry points (geometry will be updated)</string> </property> <property name="checked"> <bool>true</bool> @@ -59,29 +59,6 @@ </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"> @@ -91,7 +68,7 @@ </sizepolicy> </property> <property name="text"> - <string>Copy geometry and insert additional points</string> + <string>Copy geometry and insert additional points (geometry will be duplicated)</string> </property> </widget> </item> @@ -105,6 +82,27 @@ </property> </widget> </item> + <item row="0" column="0"> + <widget class="QLabel" name="meshNameLabel"> + <property name="text"> + <string>Map on data set:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QComboBox" name="meshNameComboBox"> + <item> + <property name="text"> + <string><Load mesh from file></string> + </property> + </item> + <item> + <property name="text"> + <string><Load DEM from file></string> + </property> + </item> + </widget> + </item> </layout> </widget> <resources/> diff --git a/Gui/DataView/GeoOnMeshMappingDialog.cpp b/Gui/DataView/GeoOnMeshMappingDialog.cpp index 2d1cb5e73a093df2baeb9caae3688b30eb62c793..c9bff482d59960ebba5f538b783ebcb8434c96cf 100644 --- a/Gui/DataView/GeoOnMeshMappingDialog.cpp +++ b/Gui/DataView/GeoOnMeshMappingDialog.cpp @@ -13,6 +13,7 @@ */ #include "GeoOnMeshMappingDialog.h" +#include "Mesh.h" // ThirdParty/logog #include "logog/include/logog.hpp" @@ -20,16 +21,32 @@ #include "OGSError.h" -GeoOnMeshMappingDialog::GeoOnMeshMappingDialog(QDialog* parent) +GeoOnMeshMappingDialog::GeoOnMeshMappingDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent) : _new_geo_name(""), QDialog(parent) { setupUi(this); + + for (std::size_t i=0; i<mesh_vec.size(); ++i) + this->meshNameComboBox->addItem(QString::fromStdString(mesh_vec[i]->getName())); } GeoOnMeshMappingDialog::~GeoOnMeshMappingDialog() { } +int GeoOnMeshMappingDialog::getDataSetChoice() const +{ + return this->meshNameComboBox->currentIndex(); +} + +void GeoOnMeshMappingDialog::on_meshNameComboBox_currentIndexChanged(int idx) +{ + bool is_enabled(idx != 1); + this->normalMappingButton->setEnabled(is_enabled); + this->advancedMappingButton->setEnabled(is_enabled); + this->geoNameEdit->setEnabled(is_enabled && this->advancedMappingButton->isChecked()); +} + void GeoOnMeshMappingDialog::accept() { if (this->advancedMappingButton->isChecked()) diff --git a/Gui/DataView/GeoOnMeshMappingDialog.h b/Gui/DataView/GeoOnMeshMappingDialog.h index d2b301b54c7a3f2601182fc75be388579ade8496..e0616b83ff619b440bde139d0b550d523613d7c1 100644 --- a/Gui/DataView/GeoOnMeshMappingDialog.h +++ b/Gui/DataView/GeoOnMeshMappingDialog.h @@ -20,6 +20,10 @@ #include "GeoMapper.h" +namespace MeshLib { + class Mesh; +} + /** * \brief A dialog window for creating DIRECT boundary conditions from raster files */ @@ -28,10 +32,11 @@ class GeoOnMeshMappingDialog : public QDialog, private Ui_GeoOnMeshMapping Q_OBJECT public: - GeoOnMeshMappingDialog(QDialog* parent = 0); + GeoOnMeshMappingDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent = 0); ~GeoOnMeshMappingDialog(void); std::string getNewGeoName() const { return _new_geo_name; }; + int getDataSetChoice() const; private: std::string _new_geo_name; @@ -39,6 +44,8 @@ private: private slots: void on_advancedMappingButton_toggled(bool isSelected) { this->geoNameEdit->setEnabled(isSelected); }; + void on_meshNameComboBox_currentIndexChanged(int idx); + /// Instructions if the OK-Button has been pressed. void accept(); diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index cdce5f9b99ccbbafdb58013d3ef4fd4d2febf953..c91b9988c7a0489eaac90aa9c6742c0083147e27 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -956,45 +956,63 @@ void MainWindow::writeStationListToFile(QString listName, QString fileName) 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(), - "OpenGeoSys mesh files (*.vtu *.msh);;Raster files(*.asc *.grd)"); - GeoMapper geo_mapper(*_project.getGEOObjects(), geo_name); - - if (file_name.compare("") != 0) + GeoOnMeshMappingDialog dlg(this->_project.getMeshObjects()); + if (dlg.exec() == QDialog::Accepted) { - QFileInfo fi(file_name); - if (fi.suffix().toLower() == "asc" || fi.suffix().toLower() == "grd") + int choice (dlg.getDataSetChoice()); + + QString file_name(""); + if (choice<2) // load something from a file { - geo_mapper.mapOnDEM(file_name.toStdString()); - dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(geo_name); + QString file_type[2] = {"OpenGeoSys mesh files (*.vtu *.msh)", "Raster files(*.asc *.grd)" }; + QSettings settings("UFZ", "OpenGeoSys-5"); + file_name = QFileDialog::getOpenFileName( this, "Select file for mapping", + settings.value("lastOpenedFileDirectory").toString(), + file_type[choice]); + if (file_name.isEmpty()) return; + QDir dir = QDir(file_name); + settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } - else if (fi.suffix().toLower() == "vtu" || fi.suffix().toLower() == "msh") + + GeoMapper geo_mapper(*_project.getGEOObjects(), geo_name); + QFileInfo fi(file_name); + if (choice == 1) // load raster from file { - GeoOnMeshMappingDialog dlg; - if (dlg.exec() == QDialog::Accepted) + if (fi.suffix().toLower() == "asc" || fi.suffix().toLower() == "grd") { - // just get mesh if already in memory - const MeshLib::Mesh* msh (this->_project.getMesh(fi.completeBaseName().toStdString())); + geo_mapper.mapOnDEM(file_name.toStdString()); + dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(geo_name); + } + else + OGSError::box("The selected file is no supported raster file."); + return; + } - // read mesh otherwise - if (!msh) - msh = FileIO::readMeshFromFile(file_name.toStdString()); + MeshLib::Mesh* mesh (nullptr); + if (choice == 0) // load mesh from file + { + if (fi.suffix().toLower() == "vtu" || fi.suffix().toLower() == "msh") + mesh = FileIO::readMeshFromFile(file_name.toStdString()); + else + { + OGSError::box("The selected file is no supported mesh file."); + return; + } + } + else // use mesh from ProjectData + mesh = this->_project.getMeshObjects()[choice-2]; - std::string new_geo_name = dlg.getNewGeoName(); + std::string new_geo_name = dlg.getNewGeoName(); - if (new_geo_name.empty()) - { - geo_mapper.mapOnMesh(msh); - dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(geo_name); - } - else - { - geo_mapper.advancedMapOnMesh(msh, new_geo_name); - dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(new_geo_name); - } - } + if (new_geo_name.empty()) + { + geo_mapper.mapOnMesh(mesh); + dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(geo_name); + } + else + { + geo_mapper.advancedMapOnMesh(mesh, new_geo_name); + dynamic_cast<GEOModels*>(_project.getGEOObjects())->updateGeometry(new_geo_name); } } }