diff --git a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp index 4585112a4add7e74d5f13ace1e6aedd593ad52b5..78f8aa9523fca86ff9154d84c969b4facf9bdab3 100644 --- a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp +++ b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp @@ -21,9 +21,9 @@ #include "OGSError.h" GeoOnMeshMappingDialog::GeoOnMeshMappingDialog( - std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, - QDialog* parent) - : QDialog(parent), _new_geo_name("") + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent) +: QDialog(parent), _new_geo_name("") { setupUi(this); diff --git a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h index 480446b983ec967221c33209caecc8f8b029716e..6124bb2f9081e911d84420ec86503ebdd7e67362 100644 --- a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h +++ b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h @@ -33,8 +33,8 @@ class GeoOnMeshMappingDialog : public QDialog, private Ui_GeoOnMeshMapping public: GeoOnMeshMappingDialog( - std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, - QDialog* parent = 0); + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent = 0); ~GeoOnMeshMappingDialog(void); std::string const& getNewGeoName() const { return _new_geo_name; }; diff --git a/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp b/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp index 29c695365142c30377d34d4acb0be2ca91f3b628..4e624077af50f50f18a5906771571b32f55e4ee6 100644 --- a/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp @@ -24,9 +24,9 @@ #include "logog/include/logog.hpp" MeshAnalysisDialog::MeshAnalysisDialog( - std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, - QDialog* parent) - : QDialog(parent), _mesh_vec(mesh_vec) + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent) +: QDialog(parent), _mesh_vec(mesh_vec) { setupUi(this); @@ -49,23 +49,23 @@ MeshAnalysisDialog::~MeshAnalysisDialog() void MeshAnalysisDialog::on_startButton_pressed() { - const MeshLib::Mesh* mesh (_mesh_vec[this->meshListBox->currentIndex()].get()); + MeshLib::Mesh const& mesh (*_mesh_vec[this->meshListBox->currentIndex()].get()); - MeshLib::NodeSearch ns(*mesh); + MeshLib::NodeSearch ns(mesh); ns.searchUnused(); const std::vector<std::size_t> unusedNodesIdx (ns.getSearchedNodeIDs()); - MeshLib::MeshRevision rev(const_cast<MeshLib::Mesh&>(*mesh)); + MeshLib::MeshRevision rev(const_cast<MeshLib::Mesh&>(mesh)); std::vector<std::size_t> const& collapsibleNodeIds (rev.collapseNodeIndices( this->collapsibleNodesThreshold->text().toDouble() + std::numeric_limits<double>::epsilon())); - this->nodesGroupBox->setTitle("Nodes (out of " + QString::number(mesh->getNNodes()) + ")"); + this->nodesGroupBox->setTitle("Nodes (out of " + QString::number(mesh.getNNodes()) + ")"); this->nodesMsgOutput(unusedNodesIdx, collapsibleNodeIds); const std::vector<ElementErrorCode> element_error_codes (MeshLib::MeshValidation::testElementGeometry( - *mesh, this->zeroVolumeThreshold->text().toDouble() + std::numeric_limits<double>::epsilon())); - this->elementsGroupBox->setTitle("Elements (out of " + QString::number(mesh->getNElements()) + ")"); + mesh, this->zeroVolumeThreshold->text().toDouble() + std::numeric_limits<double>::epsilon())); + this->elementsGroupBox->setTitle("Elements (out of " + QString::number(mesh.getNElements()) + ")"); this->elementsMsgOutput(element_error_codes); - unsigned const n_holes (MeshLib::MeshValidation::detectHoles(*mesh)); + unsigned const n_holes (MeshLib::MeshValidation::detectHoles(mesh)); if (n_holes>0) this->meshHoleOutputLabel->setText("<strong>" + QString::number(n_holes) + " hole(s) found within the mesh</strong>"); } diff --git a/Applications/DataExplorer/DataView/MeshAnalysisDialog.h b/Applications/DataExplorer/DataView/MeshAnalysisDialog.h index 1e02224a733a23c848c8552066f20a4fc544515f..d183463cd4980b7ac26031a34f160700c111b8a6 100644 --- a/Applications/DataExplorer/DataView/MeshAnalysisDialog.h +++ b/Applications/DataExplorer/DataView/MeshAnalysisDialog.h @@ -35,8 +35,8 @@ class MeshAnalysisDialog : public QDialog, private Ui_MeshAnalysis public: MeshAnalysisDialog( - std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, - QDialog* parent = nullptr); + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent = nullptr); ~MeshAnalysisDialog(void); private: diff --git a/Applications/DataExplorer/DataView/MshModel.cpp b/Applications/DataExplorer/DataView/MshModel.cpp index 0f53aff658ffe74ba493de658f8a312f845efe73..68a1df3fb90efdaf68f8cbf20e2fe34325a5d8ce 100644 --- a/Applications/DataExplorer/DataView/MshModel.cpp +++ b/Applications/DataExplorer/DataView/MshModel.cpp @@ -50,6 +50,13 @@ int MshModel::columnCount( const QModelIndex &parent /*= QModelIndex()*/ ) const return 3; } +void MshModel::addMesh(std::unique_ptr<MeshLib::Mesh> mesh) +{ + _project.addMesh(std::move(mesh)); + auto const& meshes(_project.getMeshObjects()); + this->addMeshObject(meshes.back().get()); +} + void MshModel::addMesh(MeshLib::Mesh* mesh) { _project.addMesh(std::unique_ptr<MeshLib::Mesh>(mesh)); @@ -154,10 +161,10 @@ void MshModel::updateMesh(MeshLib::Mesh* mesh) void MshModel::updateModel() { - auto const & msh_vec = _project.getMeshObjects(); - for (auto it(msh_vec.begin()); it != msh_vec.end(); ++it) - if (!this->getMesh((*it)->getName())) // if Mesh is not yet added to GUI, do it now - addMeshObject(it->get()); + auto const& mesh_vec = _project.getMeshObjects(); + for (auto const& mesh : mesh_vec) + if (!getMesh(mesh->getName())) // if Mesh is not yet added to GUI, do it now + addMeshObject(mesh.get()); } std::map<MeshLib::MeshElemType, QVariant> MshModel::createMeshElemTypeMap() diff --git a/Applications/DataExplorer/DataView/MshModel.h b/Applications/DataExplorer/DataView/MshModel.h index 69c71452703a21dadb14dc417b2c36539e01b234..c4352d470400180431d2456ae5c2fb644b71ab13 100644 --- a/Applications/DataExplorer/DataView/MshModel.h +++ b/Applications/DataExplorer/DataView/MshModel.h @@ -40,12 +40,15 @@ class MshModel : public TreeModel public: MshModel(DataHolderLib::Project &project, QObject* parent = 0); + /// Adds a new mesh + void addMesh(std::unique_ptr<MeshLib::Mesh> mesh); + /// Returns the number of columns used for the data list int columnCount(const QModelIndex& parent = QModelIndex()) const; public slots: - /// Adds a new mesh - void addMesh(MeshLib::Mesh* mesh); // needs only to be a slot for MshLayerMapper. Otherwise normal function would be okay. + /// Adds a new mesh (using no unique_ptr as this interferes with Qt's signal/slot policy) + void addMesh(MeshLib::Mesh* mesh); /// Returns the mesh with the given index. const MeshLib::Mesh* getMesh(const QModelIndex &idx) const; /// Returns the mesh with the given name. diff --git a/Applications/DataExplorer/DataView/MshView.cpp b/Applications/DataExplorer/DataView/MshView.cpp index 8ad64ec25ff0f8997a3d83f180b256c404fef88c..077ae0cf16222f2b951b5ed4cd63c5f75a4276f7 100644 --- a/Applications/DataExplorer/DataView/MshView.cpp +++ b/Applications/DataExplorer/DataView/MshView.cpp @@ -183,7 +183,7 @@ void MshView::openMap2dMeshDialog() } else MeshLib::MeshLayerMapper::mapToStaticValue(*result, dlg.getStaticValue()); - static_cast<MshModel*>(this->model())->addMesh(result.release()); + static_cast<MshModel*>(this->model())->addMesh(std::move(result)); } @@ -227,10 +227,10 @@ void MshView::openAddLayerDialog() double const thickness (dlg.getThickness()); std::unique_ptr<MeshLib::Mesh> result(MeshLib::addLayerToMesh( - *mesh, thickness, dlg.getName(), dlg.isTopLayer())); + *mesh, thickness, dlg.getName(), dlg.isTopLayer())); if (result) - static_cast<MshModel*>(model())->addMesh(result.release()); + static_cast<MshModel*>(model())->addMesh(std::move(result)); else OGSError::box("Error adding layer to mesh."); } @@ -251,7 +251,7 @@ void MshView::extractSurfaceMesh() std::unique_ptr<MeshLib::Mesh> sfc_mesh( MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir, tolerance)); if (sfc_mesh) - static_cast<MshModel*>(model())->addMesh(sfc_mesh.release()); + static_cast<MshModel*>(model())->addMesh(std::move(sfc_mesh)); else OGSError::box(" No surfaces found to extract\n using the specified parameters."); } diff --git a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp index e4689bc5a5ce64e10f9dc2e683f7c3364cef9510..f7a4d425079281aba1c98476b9938c0c8ac44a0e 100644 --- a/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp +++ b/Applications/DataExplorer/VtkVis/VtkVisPipelineView.cpp @@ -211,8 +211,8 @@ void VtkVisPipelineView::showImageToMeshConversionDialog() double spacing[3]; imageSource->GetOutput()->GetSpacing(spacing); - MeshLib::Mesh* mesh = MeshLib::RasterToMesh::convert(imageSource->GetOutput(), origin, - spacing[0], dlg.getElementSelection(), dlg.getIntensitySelection(), dlg.getArrayName()); + MeshLib::Mesh* mesh (MeshLib::RasterToMesh::convert(imageSource->GetOutput(), origin, + spacing[0], dlg.getElementSelection(), dlg.getIntensitySelection(), dlg.getArrayName())); if (mesh) { mesh->setName(dlg.getMeshName()); diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 06fe54b66e85baf061bd32795997999264902024..ea124e476706c91ebd13df0e117f0ad77bc822ad 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -262,9 +262,8 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const*const, const unsigned)), this->_vtkVisPipeline.get(), SLOT(removeHighlightedMeshComponent())); - connect(vtkVisTabWidget->vtkVisPipelineView, - SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(), - SLOT(addMesh(MeshLib::Mesh*))); + connect(vtkVisTabWidget->vtkVisPipelineView, SIGNAL(meshAdded(MeshLib::Mesh*)), + _meshModel.get(), SLOT(addMesh(MeshLib::Mesh*))); // Stack the data dock widgets together tabifyDockWidget(geoDock, mshDock); @@ -498,13 +497,13 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) myTimer0.start(); #endif std::unique_ptr<MeshLib::Mesh> mesh( - FileIO::readMeshFromFile(fileName.toStdString())); + FileIO::readMeshFromFile(fileName.toStdString())); #ifndef NDEBUG INFO("Mesh loading time: %d ms.", myTimer0.elapsed()); myTimer1.start(); #endif if (mesh) - _meshModel->addMesh(mesh.release()); + _meshModel->addMesh(std::move(mesh)); else OGSError::box("Failed to load mesh file."); #ifndef NDEBUG @@ -520,10 +519,10 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) if (fi.suffix().toLower() == "fem") // FEFLOW model files { FileIO::FEFLOWInterface feflowIO(&_project.getGEOObjects()); - std::unique_ptr<MeshLib::Mesh> msh( - feflowIO.readFEFLOWFile(fileName.toStdString())); - if (msh) - _meshModel->addMesh(msh.release()); + std::unique_ptr<MeshLib::Mesh> mesh( + feflowIO.readFEFLOWFile(fileName.toStdString())); + if (mesh) + _meshModel->addMesh(std::move(mesh)); else OGSError::box("Failed to load a FEFLOW mesh."); } @@ -538,10 +537,8 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) new std::vector<GeoLib::Point*>()); std::string name = fi.baseName().toStdString(); - if (GMSInterface::readBoreholesFromGMS(boreholes.get(), - fileName.toStdString())) - _project.getGEOObjects().addStationVec(std::move(boreholes), - name); + if (GMSInterface::readBoreholesFromGMS(boreholes.get(), fileName.toStdString())) + _project.getGEOObjects().addStationVec(std::move(boreholes), name); else OGSError::box("Error reading GMS file."); } @@ -550,7 +547,9 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) std::string name = fileName.toStdString(); std::unique_ptr<MeshLib::Mesh> mesh(GMSInterface::readGMS3DMMesh(name)); if (mesh) - _meshModel->addMesh(mesh.release()); + _meshModel->addMesh(std::move(mesh)); + else + OGSError::box("Failed to load a GMS mesh."); } settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } @@ -561,7 +560,9 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) { std::unique_ptr<MeshLib::Mesh> mesh(FileIO::GMSHInterface::readGMSHMesh(msh_name)); if (mesh) - _meshModel->addMesh(mesh.release()); + _meshModel->addMesh(std::move(mesh)); + else + OGSError::box("Failed to load a GMSH mesh."); } settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } @@ -574,7 +575,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) { std::unique_ptr<MeshLib::Mesh> mesh(dlg.getMesh()); mesh->setName(dlg.getName()); - _meshModel->addMesh(mesh.release()); + _meshModel->addMesh(std::move(mesh)); } if (dlg.getRaster()) _vtkVisPipeline->addPipelineItem(dlg.getRaster()); @@ -629,7 +630,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) std::unique_ptr<MeshLib::Mesh> mesh(tetgen.readTetGenMesh( fileName.toStdString(), element_fname.toStdString())); if (mesh) - _meshModel->addMesh(mesh.release()); + _meshModel->addMesh(std::move(mesh)); else OGSError::box("Failed to load a TetGen mesh."); } @@ -837,7 +838,7 @@ void MainWindow::mapGeometry(const std::string &geo_name) mesh = FileIO::readMeshFromFile(file_name.toStdString()); else { - OGSError::box("The selected file isn't a supported mesh file."); + OGSError::box("The selected file is no supported mesh file."); return; } } @@ -998,16 +999,16 @@ void MainWindow::showGeoNameDialog(const std::string &geometry_name, const GeoLi void MainWindow::showCreateStructuredGridDialog() { CreateStructuredGridDialog dlg; - connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(), - SLOT(addMesh(MeshLib::Mesh*))); + connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), + _meshModel.get(), SLOT(addMesh(MeshLib::Mesh*))); dlg.exec(); } void MainWindow::showMeshElementRemovalDialog() { MeshElementRemovalDialog dlg(this->_project); - connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModel.get(), - SLOT(addMesh(MeshLib::Mesh*))); + connect(&dlg, SIGNAL(meshAdded(MeshLib::Mesh*)), + _meshModel.get(), SLOT(addMesh(MeshLib::Mesh*))); dlg.exec(); } diff --git a/DataHolderLib/Project.cpp b/DataHolderLib/Project.cpp index 9e89b74941da987c2f032cfd76e4be375ca5b90b..8df157f4e39306fcb939af993ec8e512aa8d6320 100644 --- a/DataHolderLib/Project.cpp +++ b/DataHolderLib/Project.cpp @@ -40,10 +40,8 @@ std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator Project::findMeshByName(std::string const& name) { return std::find_if(_mesh_vec.begin(), _mesh_vec.end(), - [&name](std::unique_ptr<MeshLib::Mesh> & mesh) - { - return mesh && (name == mesh->getName()); - }); + [&name](std::unique_ptr<MeshLib::Mesh> & mesh) + { return mesh && (name == mesh->getName()); }); } const MeshLib::Mesh* Project::getMesh(const std::string &name) const diff --git a/FileIO/CMakeLists.txt b/FileIO/CMakeLists.txt index e4428a07a1fe7c2d5366860f65f96e88dad15200..761268d714da9df66ad2d76795906a450e7629f6 100644 --- a/FileIO/CMakeLists.txt +++ b/FileIO/CMakeLists.txt @@ -60,7 +60,6 @@ target_link_libraries(FileIO INTERFACE InSituLib MeshLib logog - shp ) if(QT4_FOUND) target_link_libraries(FileIO PUBLIC Qt4::QtXml Qt4::QtXmlPatterns)