diff --git a/Applications/DataExplorer/DataExplorer.cmake b/Applications/DataExplorer/DataExplorer.cmake index d6fd25590c0853074358ea8d587c07dd824bd835..5bfac32991b6d16679ce6953cf463078cf327661 100644 --- a/Applications/DataExplorer/DataExplorer.cmake +++ b/Applications/DataExplorer/DataExplorer.cmake @@ -53,6 +53,7 @@ target_link_libraries(DataExplorer Qt4::QtXml Qt4::QtNetwork ApplicationsLib + DataHolderLib FileIO QtDataView QtDiagramView diff --git a/Applications/DataExplorer/DataView/CMakeLists.txt b/Applications/DataExplorer/DataView/CMakeLists.txt index c66ee3216dd4f67bcdedaf61dc8b675e96b0c55a..18c2a0e1fd817ffc58b0958d812b11ae59b63a5c 100644 --- a/Applications/DataExplorer/DataView/CMakeLists.txt +++ b/Applications/DataExplorer/DataView/CMakeLists.txt @@ -133,6 +133,7 @@ add_library(QtDataView STATIC target_link_libraries(QtDataView PUBLIC Qt4::QtCore Qt4::QtGui) target_link_libraries(QtDataView INTERFACE FileIO + DataHolderLib QtBase ) add_dependencies(QtDataView QtDiagramView QtStratView) diff --git a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp index 5530c41421463ded0e95846cefa0c5e60606260f..90a61a627e6abdd870eb8918368ef07b3346418a 100644 --- a/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp +++ b/Applications/DataExplorer/DataView/GMSHPrefsDialog.cpp @@ -26,7 +26,7 @@ #include "OGSError.h" -GMSHPrefsDialog::GMSHPrefsDialog(const GeoLib::GEOObjects* geoObjects, QDialog* parent) +GMSHPrefsDialog::GMSHPrefsDialog(GeoLib::GEOObjects const& geoObjects, QDialog* parent) : QDialog(parent), _allGeo(new QStringListModel), _selGeo(new QStringListModel) { setupUi(this); @@ -60,11 +60,11 @@ GMSHPrefsDialog::GMSHPrefsDialog(const GeoLib::GEOObjects* geoObjects, QDialog* param3->setValidator (mesh_density_scaling_stations_validator); std::vector<std::string> geoNames; - geoObjects->getGeometryNames(geoNames); + geoObjects.getGeometryNames(geoNames); // get station names std::vector<std::string> geo_station_names; - geoObjects->getStationVectorNames(geo_station_names); + geoObjects.getStationVectorNames(geo_station_names); for (unsigned k(0); k < geo_station_names.size(); ++k) geoNames.push_back (geo_station_names[k]); diff --git a/Applications/DataExplorer/DataView/GMSHPrefsDialog.h b/Applications/DataExplorer/DataView/GMSHPrefsDialog.h index e3f623b6ccbc3b39a0613b31660e4f22d1f89c31..8183db336412499ad8189b3cc944700a8f3f125f 100644 --- a/Applications/DataExplorer/DataView/GMSHPrefsDialog.h +++ b/Applications/DataExplorer/DataView/GMSHPrefsDialog.h @@ -33,7 +33,7 @@ class GMSHPrefsDialog : public QDialog, private Ui_GMSHPrefs Q_OBJECT public: - GMSHPrefsDialog(const GeoLib::GEOObjects* geoObjects, QDialog* parent = 0); + GMSHPrefsDialog(GeoLib::GEOObjects const& geoObjects, QDialog* parent = nullptr); ~GMSHPrefsDialog(void); private: diff --git a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp index 223bd4f43e2cfa0a2fc1fda595ef7a9b2a133ff0..78f8aa9523fca86ff9154d84c969b4facf9bdab3 100644 --- a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp +++ b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.cpp @@ -20,9 +20,10 @@ #include "OGSError.h" - -GeoOnMeshMappingDialog::GeoOnMeshMappingDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent) - : QDialog(parent), _new_geo_name("") +GeoOnMeshMappingDialog::GeoOnMeshMappingDialog( + 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 f5301d08dfbfe3f2a8b8e8dce15cb94dae510408..6124bb2f9081e911d84420ec86503ebdd7e67362 100644 --- a/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h +++ b/Applications/DataExplorer/DataView/GeoOnMeshMappingDialog.h @@ -32,7 +32,9 @@ class GeoOnMeshMappingDialog : public QDialog, private Ui_GeoOnMeshMapping Q_OBJECT public: - GeoOnMeshMappingDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent = 0); + GeoOnMeshMappingDialog( + 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/MergeGeometriesDialog.cpp b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp index 04d23b1b9cff54b3b70f9d219a5a79c1c16286ad..3b8bb9f0b4b1b6d3b1e186f3f892504d064980b6 100644 --- a/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp +++ b/Applications/DataExplorer/DataView/MergeGeometriesDialog.cpp @@ -20,17 +20,17 @@ #include "OGSError.h" -MergeGeometriesDialog::MergeGeometriesDialog(GeoLib::GEOObjects* geoObjects, QDialog* parent) +MergeGeometriesDialog::MergeGeometriesDialog(GeoLib::GEOObjects& geoObjects, QDialog* parent) : QDialog(parent), _geo_objects(geoObjects), _allGeo(new QStringListModel), _selGeo(new QStringListModel) { setupUi(this); std::vector<std::string> geoNames; - _geo_objects->getGeometryNames(geoNames); + _geo_objects.getGeometryNames(geoNames); // get station names std::vector<std::string> geo_station_names; - _geo_objects->getStationVectorNames(geo_station_names); + _geo_objects.getStationVectorNames(geo_station_names); // merge method does currently not merge stations, converter function needed first //geoNames.reserve(geo_station_names.size()); @@ -53,7 +53,7 @@ MergeGeometriesDialog::MergeGeometriesDialog(GeoLib::GEOObjects* geoObjects, QDi this->selectedGeoView->setModel(_selGeo); std::string new_geo_name("MergedGeometry"); - _geo_objects->isUniquePointVecName(new_geo_name); + _geo_objects.isUniquePointVecName(new_geo_name); this->newGeoNameEdit->setText(QString::fromStdString(new_geo_name)); } diff --git a/Applications/DataExplorer/DataView/MergeGeometriesDialog.h b/Applications/DataExplorer/DataView/MergeGeometriesDialog.h index 61cc7b7b377ccb39d71c4e4d14bdf03da96ab949..3ce828e6c01e8f878aaa0c762d0810661b8c10dd 100644 --- a/Applications/DataExplorer/DataView/MergeGeometriesDialog.h +++ b/Applications/DataExplorer/DataView/MergeGeometriesDialog.h @@ -33,7 +33,7 @@ class MergeGeometriesDialog : public QDialog, private Ui_MergeGeometries Q_OBJECT public: - MergeGeometriesDialog(GeoLib::GEOObjects* geoObjects, QDialog* parent = 0); + MergeGeometriesDialog(GeoLib::GEOObjects& geoObjects, QDialog* parent = 0); ~MergeGeometriesDialog(void); /// Returns a vector of selected geometries @@ -43,7 +43,7 @@ public: std::string getGeometryName() const; private: - GeoLib::GEOObjects* _geo_objects; + GeoLib::GEOObjects& _geo_objects; QStringListModel* _allGeo; QStringListModel* _selGeo; diff --git a/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp b/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp index cfed63d7e26c3200da953d6589cb0776030507ee..4e624077af50f50f18a5906771571b32f55e4ee6 100644 --- a/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshAnalysisDialog.cpp @@ -23,9 +23,10 @@ // ThirdParty/logog #include "logog/include/logog.hpp" - -MeshAnalysisDialog::MeshAnalysisDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent) - : QDialog(parent), _mesh_vec (mesh_vec) +MeshAnalysisDialog::MeshAnalysisDialog( + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent) +: QDialog(parent), _mesh_vec(mesh_vec) { setupUi(this); @@ -48,23 +49,23 @@ MeshAnalysisDialog::~MeshAnalysisDialog() void MeshAnalysisDialog::on_startButton_pressed() { - const MeshLib::Mesh* mesh (_mesh_vec[this->meshListBox->currentIndex()]); + 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 e0ac90dff579c5c6927fbdb43b49d167d376564f..d183463cd4980b7ac26031a34f160700c111b8a6 100644 --- a/Applications/DataExplorer/DataView/MeshAnalysisDialog.h +++ b/Applications/DataExplorer/DataView/MeshAnalysisDialog.h @@ -15,6 +15,8 @@ #ifndef MESHANALYSISDIALOG_H #define MESHANALYSISDIALOG_H +#include <memory> + #include "ui_MeshAnalysis.h" #include <QDialog> @@ -32,7 +34,9 @@ class MeshAnalysisDialog : public QDialog, private Ui_MeshAnalysis Q_OBJECT public: - MeshAnalysisDialog(const std::vector<MeshLib::Mesh*> &mesh_vec, QDialog* parent = nullptr); + MeshAnalysisDialog( + std::vector<std::unique_ptr<MeshLib::Mesh>> const& mesh_vec, + QDialog* parent = nullptr); ~MeshAnalysisDialog(void); private: @@ -42,7 +46,7 @@ private: /// Prepares the output for the node message window void elementsMsgOutput(const std::vector<ElementErrorCode> &error_codes); - const std::vector<MeshLib::Mesh*>& _mesh_vec; + std::vector<std::unique_ptr<MeshLib::Mesh>> const& _mesh_vec; private slots: /// Starts the analysis diff --git a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp index 688b50882266f3dd1b2a5f198130230d06db762e..b4b2e24796a525100c3c107378c8e42031da8169 100644 --- a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp +++ b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp @@ -26,12 +26,12 @@ #include <QListWidgetItem> /// Constructor -MeshElementRemovalDialog::MeshElementRemovalDialog(const ProjectData &project, QDialog* parent) +MeshElementRemovalDialog::MeshElementRemovalDialog(DataHolderLib::Project const& project, QDialog* parent) : QDialog(parent), _project(project), _currentIndex(0), _aabbIndex(std::numeric_limits<unsigned>::max()), _matIDIndex(std::numeric_limits<unsigned>::max()) { setupUi(this); - const std::vector<MeshLib::Mesh*> mesh_vec (_project.getMeshObjects()); + auto const& mesh_vec(_project.getMeshObjects()); const std::size_t nMeshes (mesh_vec.size()); for (std::size_t i=0; i<nMeshes; ++i) diff --git a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.h b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.h index 6589ddef53ee24d355f631a9a3ee41250f631a6b..f05fab72c6ed9854b0b3c9265ba19d5a676c3222 100644 --- a/Applications/DataExplorer/DataView/MeshElementRemovalDialog.h +++ b/Applications/DataExplorer/DataView/MeshElementRemovalDialog.h @@ -19,7 +19,7 @@ #include <QDialog> #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 -#include "Applications/ApplicationsLib/ProjectData.h" +#include "DataHolderLib/Project.h" #endif class Node; @@ -32,7 +32,7 @@ class MeshElementRemovalDialog : public QDialog, private Ui_MeshElementRemoval Q_OBJECT public: - MeshElementRemovalDialog(const ProjectData &project, QDialog* parent = 0); + MeshElementRemovalDialog(DataHolderLib::Project const& project, QDialog* parent = 0); ~MeshElementRemovalDialog(void); private slots: @@ -50,7 +50,7 @@ private slots: void reject(); private: - const ProjectData& _project; + DataHolderLib::Project const& _project; unsigned _currentIndex, _aabbIndex, _matIDIndex; std::array<bool, 6> aabb_edits; diff --git a/Applications/DataExplorer/DataView/MshModel.cpp b/Applications/DataExplorer/DataView/MshModel.cpp index 41f3cb371fb1d1c8725758dec398d6a6350e9db0..68a1df3fb90efdaf68f8cbf20e2fe34325a5d8ce 100644 --- a/Applications/DataExplorer/DataView/MshModel.cpp +++ b/Applications/DataExplorer/DataView/MshModel.cpp @@ -30,12 +30,11 @@ // MeshLib #include "MeshLib/Node.h" #include "Elements/Element.h" -#include "MeshEnums.h" const QVariant MshModel::element_str = "Element"; const std::map<MeshLib::MeshElemType, QVariant> MshModel::elem_type_map = MshModel::createMeshElemTypeMap(); -MshModel::MshModel(ProjectData &project, QObject* parent /*= 0*/ ) +MshModel::MshModel(DataHolderLib::Project &project, QObject* parent /*= 0*/ ) : TreeModel(parent), _project(project) { delete _rootItem; @@ -51,10 +50,18 @@ 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(mesh); - this->addMeshObject(mesh); + _project.addMesh(std::unique_ptr<MeshLib::Mesh>(mesh)); + auto const& meshes(_project.getMeshObjects()); + this->addMeshObject(meshes.back().get()); } void MshModel::addMeshObject(const MeshLib::Mesh* mesh) @@ -154,10 +161,10 @@ void MshModel::updateMesh(MeshLib::Mesh* mesh) void MshModel::updateModel() { - const std::vector<MeshLib::Mesh*> msh_vec = _project.getMeshObjects(); - for (std::vector<MeshLib::Mesh*>::const_iterator 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); + 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 fd2fd4a4d98d4d879beec556359100daf6636203..c4352d470400180431d2456ae5c2fb644b71ab13 100644 --- a/Applications/DataExplorer/DataView/MshModel.h +++ b/Applications/DataExplorer/DataView/MshModel.h @@ -17,9 +17,11 @@ // ** INCLUDES ** #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 -#include "Applications/ApplicationsLib/ProjectData.h" +#include "DataHolderLib/Project.h" #endif +#include "MeshLib/MeshEnums.h" + #include "TreeModel.h" namespace MeshLib { @@ -36,14 +38,17 @@ class MshModel : public TreeModel Q_OBJECT public: - MshModel(ProjectData &project, QObject* parent = 0); + 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. @@ -67,7 +72,7 @@ private: /// Checks if the name of the mesh is already exists, if so it generates a unique name. //bool isUniqueMeshName(std::string &name); - ProjectData& _project; + DataHolderLib::Project& _project; /// Creates a static map of all element type name-strings in QVariant format static std::map<MeshLib::MeshElemType, QVariant> createMeshElemTypeMap(); diff --git a/Applications/DataExplorer/DataView/MshView.cpp b/Applications/DataExplorer/DataView/MshView.cpp index 8bb3ad669fe4e168aa39e8039671e9ea8f6144b2..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)); } @@ -226,11 +226,11 @@ void MshView::openAddLayerDialog() return; double const thickness (dlg.getThickness()); - MeshLib::Mesh* result = - MeshLib::addLayerToMesh(*mesh, thickness, dlg.getName(), dlg.isTopLayer()); + std::unique_ptr<MeshLib::Mesh> result(MeshLib::addLayerToMesh( + *mesh, thickness, dlg.getName(), dlg.isTopLayer())); - if (result != nullptr) - static_cast<MshModel*>(this->model())->addMesh(result); + if (result) + static_cast<MshModel*>(model())->addMesh(std::move(result)); else OGSError::box("Error adding layer to mesh."); } @@ -248,9 +248,10 @@ void MshView::extractSurfaceMesh() MathLib::Vector3 const& dir (dlg.getNormal()); int const tolerance (dlg.getTolerance()); - MeshLib::Mesh* sfc_mesh (MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir, tolerance)); - if (sfc_mesh != nullptr) - static_cast<MshModel*>(this->model())->addMesh(sfc_mesh); + std::unique_ptr<MeshLib::Mesh> sfc_mesh( + MeshLib::MeshSurfaceExtraction::getMeshSurface(*mesh, dir, tolerance)); + if (sfc_mesh) + static_cast<MshModel*>(model())->addMesh(std::move(sfc_mesh)); else OGSError::box(" No surfaces found to extract\n using the specified parameters."); } @@ -323,8 +324,8 @@ void MshView::writeToFile() const void MshView::addDIRECTSourceTerms() { - QModelIndex const index = this->selectionModel()->currentIndex(); - MeshLib::Mesh const*const grid = static_cast<MshModel*>(this->model())->getMesh(index); + //QModelIndex const index = this->selectionModel()->currentIndex(); + //MeshLib::Mesh const*const grid = static_cast<MshModel*>(this->model())->getMesh(index); } void MshView::loadDIRECTSourceTerms() diff --git a/Applications/DataExplorer/DataView/SHPImportDialog.cpp b/Applications/DataExplorer/DataView/SHPImportDialog.cpp index 2c9766bbe36fa78a0cbbd9c02336c7eae642f398..115585c39c6b513664b91be8ff0c5aebf6948c31 100644 --- a/Applications/DataExplorer/DataView/SHPImportDialog.cpp +++ b/Applications/DataExplorer/DataView/SHPImportDialog.cpp @@ -25,7 +25,7 @@ #include <QVBoxLayout> SHPImportDialog::SHPImportDialog(std::string filename, - GeoLib::GEOObjects* geo_objects, + GeoLib::GEOObjects& geo_objects, QDialog* parent) : QDialog(parent), _buttonBox(nullptr), diff --git a/Applications/DataExplorer/DataView/SHPImportDialog.h b/Applications/DataExplorer/DataView/SHPImportDialog.h index ad4700929e34f1080a1c4bbb22ae85df4b032b94..afee77faa26099ae6d9124d4ef2665c7018167e8 100644 --- a/Applications/DataExplorer/DataView/SHPImportDialog.h +++ b/Applications/DataExplorer/DataView/SHPImportDialog.h @@ -42,7 +42,7 @@ class SHPImportDialog : public QDialog public: /// Constructor - SHPImportDialog(std::string filename, GeoLib::GEOObjects* geo_objects, + SHPImportDialog(std::string filename, GeoLib::GEOObjects& geo_objects, QDialog* parent = nullptr); ~SHPImportDialog(); 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/main.cpp b/Applications/DataExplorer/main.cpp index 46e186f1eb8ff7de163c048b01867349d0596f6a..089c4279f970f357ddd6984ed2f8851fc8f6b2dd 100644 --- a/Applications/DataExplorer/main.cpp +++ b/Applications/DataExplorer/main.cpp @@ -14,6 +14,8 @@ FbxManager* lSdkManager = NULL; FbxScene* lScene = NULL; #endif +#include <vtkSmartPointer.h> + #include "BaseLib/BuildInfo.h" #include "VtkVis/VtkConsoleOutputWindow.h" diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 7adef2343e9d611dfdf98495b987e24fbc177604..ea124e476706c91ebd13df0e117f0ad77bc822ad 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -115,7 +115,7 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) _elementModel.reset(new ElementTreeModel()); _processModel.reset(new TreeModel()); - _geo_model.reset(new GEOModels{*_project.getGEOObjects()}); + _geo_model.reset(new GEOModels{_project.getGEOObjects()}); geoTabWidget->treeView->setModel(_geo_model->getGeoModel()); stationTabWidget->treeView->setModel(_geo_model->getStationModel()); mshTabWidget->treeView->setModel(_meshModel.get()); @@ -420,18 +420,13 @@ void MainWindow::save() if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(*_project.getGEOObjects(), - _project.getMeshObjects(), - [this](MeshLib::Mesh* const mesh) - { - _project.addMesh(mesh); - }); + XmlGspInterface xml(_project); xml.writeToFile(fileName.toStdString()); } else if (fi.suffix().toLower() == "geo") { int const return_val = - FileIO::GMSHInterface::writeGeoFile(*_project.getGEOObjects(), fileName.toStdString()); + FileIO::GMSHInterface::writeGeoFile(_project.getGEOObjects(), fileName.toStdString()); if (return_val == 1) OGSError::box(" No geometry available\n to write to geo-file"); @@ -472,12 +467,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(*_project.getGEOObjects(), - _project.getMeshObjects(), - [this](MeshLib::Mesh* const mesh) - { - _project.addMesh(mesh); - }); + XmlGspInterface xml(_project); if (xml.readFile(fileName)) { _meshModel->updateModel(); @@ -487,14 +477,14 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (fi.suffix().toLower() == "gml") { - XmlGmlInterface xml(*(_project.getGEOObjects())); + XmlGmlInterface xml(_project.getGEOObjects()); if (!xml.readFile(fileName)) OGSError::box("Failed to load geometry.\n Please see console for details."); } // OpenGeoSys observation station files (incl. boreholes) else if (fi.suffix().toLower() == "stn") { - XmlStnInterface xml(*(_project.getGEOObjects())); + XmlStnInterface xml(_project.getGEOObjects()); if (!xml.readFile(fileName)) OGSError::box("Failed to load station data.\n Please see console for details."); @@ -506,13 +496,14 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) QTime myTimer0, myTimer1; myTimer0.start(); #endif - MeshLib::Mesh* mesh (FileIO::readMeshFromFile(fileName.toStdString())); + std::unique_ptr<MeshLib::Mesh> mesh( + FileIO::readMeshFromFile(fileName.toStdString())); #ifndef NDEBUG INFO("Mesh loading time: %d ms.", myTimer0.elapsed()); myTimer1.start(); #endif if (mesh) - _meshModel->addMesh(mesh); + _meshModel->addMesh(std::move(mesh)); else OGSError::box("Failed to load mesh file."); #ifndef NDEBUG @@ -527,10 +518,11 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) { if (fi.suffix().toLower() == "fem") // FEFLOW model files { - FEFLOWInterface feflowIO(_project.getGEOObjects()); - MeshLib::Mesh* msh = feflowIO.readFEFLOWFile(fileName.toStdString()); - if (msh) - _meshModel->addMesh(msh); + FileIO::FEFLOWInterface feflowIO(&_project.getGEOObjects()); + 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."); } @@ -545,19 +537,19 @@ 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."); } else if (fi.suffix().toLower() == "3dm") // GMS mesh files { std::string name = fileName.toStdString(); - MeshLib::Mesh* mesh = GMSInterface::readGMS3DMMesh(name); + std::unique_ptr<MeshLib::Mesh> mesh(GMSInterface::readGMS3DMMesh(name)); if (mesh) - _meshModel->addMesh(mesh); + _meshModel->addMesh(std::move(mesh)); + else + OGSError::box("Failed to load a GMS mesh."); } settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } @@ -566,23 +558,24 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) std::string msh_name (fileName.toStdString()); if (FileIO::GMSHInterface::isGMSHMeshFile (msh_name)) { - MeshLib::Mesh* mesh = FileIO::GMSHInterface::readGMSHMesh(msh_name); + std::unique_ptr<MeshLib::Mesh> mesh(FileIO::GMSHInterface::readGMSHMesh(msh_name)); if (mesh) - _meshModel->addMesh(mesh); + _meshModel->addMesh(std::move(mesh)); + else + OGSError::box("Failed to load a GMSH mesh."); } settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } else if (t == ImportFileType::NETCDF) // CH 01.2012 { - MeshLib::Mesh* mesh (nullptr); NetCdfConfigureDialog dlg(fileName.toStdString()); dlg.exec(); if (dlg.getMesh()) { - mesh = dlg.getMesh(); + std::unique_ptr<MeshLib::Mesh> mesh(dlg.getMesh()); mesh->setName(dlg.getName()); - _meshModel->addMesh(mesh); + _meshModel->addMesh(std::move(mesh)); } if (dlg.getRaster()) _vtkVisPipeline->addPipelineItem(dlg.getRaster()); @@ -625,7 +618,7 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) if (fi.suffix().toLower().compare("poly") == 0 || fi.suffix().toLower().compare("smesh") == 0) { FileIO::TetGenInterface tetgen; - tetgen.readTetGenGeometry(fileName.toStdString(), *(_project.getGEOObjects())); + tetgen.readTetGenGeometry(fileName.toStdString(), _project.getGEOObjects()); } else { settings.setValue("lastOpenedTetgenFileDirectory", QFileInfo(fileName).absolutePath()); @@ -634,9 +627,10 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) if (!fileName.isEmpty()) { FileIO::TetGenInterface tetgen; - MeshLib::Mesh* mesh (tetgen.readTetGenMesh(fileName.toStdString(), element_fname.toStdString())); + std::unique_ptr<MeshLib::Mesh> mesh(tetgen.readTetGenMesh( + fileName.toStdString(), element_fname.toStdString())); if (mesh) - _meshModel->addMesh(mesh); + _meshModel->addMesh(std::move(mesh)); else OGSError::box("Failed to load a TetGen mesh."); } @@ -765,7 +759,7 @@ void MainWindow::loadPetrelFiles() std::string unique_str(*(sfc_files.begin())); - PetrelInterface(sfc_files, well_path_files, unique_str, _project.getGEOObjects()); + PetrelInterface(sfc_files, well_path_files, unique_str, &_project.getGEOObjects()); QDir dir = QDir(sfc_file_names.at(0)); @@ -785,18 +779,18 @@ void MainWindow::writeGeometryToFile(QString gliName, QString fileName) QFileInfo fi(fileName); if (fi.suffix().toLower() == "gli") { - FileIO::Legacy::writeAllDataToGLIFileV4(fileName.toStdString(), *this->_project.getGEOObjects()); + FileIO::Legacy::writeAllDataToGLIFileV4(fileName.toStdString(), this->_project.getGEOObjects()); return; } #endif - XmlGmlInterface xml(*(_project.getGEOObjects())); + XmlGmlInterface xml(_project.getGEOObjects()); xml.setNameForExport(gliName.toStdString()); xml.writeToFile(fileName.toStdString()); } void MainWindow::writeStationListToFile(QString listName, QString fileName) { - XmlStnInterface xml(*(_project.getGEOObjects())); + XmlStnInterface xml(_project.getGEOObjects()); xml.setNameForExport(listName.toStdString()); xml.writeToFile(fileName.toStdString()); } @@ -823,7 +817,7 @@ void MainWindow::mapGeometry(const std::string &geo_name) settings.setValue("lastOpenedFileDirectory", dir.absolutePath()); } - MeshGeoToolsLib::GeoMapper geo_mapper(*_project.getGEOObjects(), geo_name); + MeshGeoToolsLib::GeoMapper geo_mapper(_project.getGEOObjects(), geo_name); QFileInfo fi(file_name); if (choice == 1) // load raster from file { @@ -849,7 +843,7 @@ void MainWindow::mapGeometry(const std::string &geo_name) } } else // use mesh from ProjectData - mesh = this->_project.getMeshObjects()[choice-2]; + mesh = _project.getMeshObjects()[choice-2].get(); std::string const& new_geo_name = dlg.getNewGeoName(); @@ -867,12 +861,12 @@ void MainWindow::mapGeometry(const std::string &geo_name) void MainWindow::convertMeshToGeometry(const MeshLib::Mesh* mesh) { - MeshLib::convertMeshToGeo(*mesh, *this->_project.getGEOObjects()); + MeshLib::convertMeshToGeo(*mesh, _project.getGEOObjects()); } void MainWindow::exportBoreholesToGMS(std::string listName, std::string fileName) { - const std::vector<GeoLib::Point*>* stations(_project.getGEOObjects()->getStationVec(listName)); + const std::vector<GeoLib::Point*>* stations(_project.getGEOObjects().getStationVec(listName)); GMSInterface::writeBoreholesToGMS(stations, fileName); } @@ -897,13 +891,13 @@ void MainWindow::callGMSH(std::vector<std::string> & selectedGeometries, if (!fileName.isEmpty()) { if (param4 == -1) { // adaptive meshing selected - GMSHInterface gmsh_io(*(static_cast<GeoLib::GEOObjects*> (_project.getGEOObjects())), true, + GMSHInterface gmsh_io(*(static_cast<GeoLib::GEOObjects*> (&_project.getGEOObjects())), true, FileIO::GMSH::MeshDensityAlgorithm::AdaptiveMeshDensity, param2, param3, param1, selectedGeometries); gmsh_io.setPrecision(20); gmsh_io.writeToFile(fileName.toStdString()); } else { // homogeneous meshing selected - GMSHInterface gmsh_io(*(static_cast<GeoLib::GEOObjects*> (_project.getGEOObjects())), true, + GMSHInterface gmsh_io(*(static_cast<GeoLib::GEOObjects*> (&_project.getGEOObjects())), true, FileIO::GMSH::MeshDensityAlgorithm::FixedMeshDensity, param4, param3, param1, selectedGeometries); gmsh_io.setPrecision(20); @@ -992,27 +986,29 @@ void MainWindow::showDiagramPrefsDialog() void MainWindow::showGeoNameDialog(const std::string &geometry_name, const GeoLib::GEOTYPE object_type, std::size_t id) { - std::string old_name = this->_project.getGEOObjects()->getElementNameByID(geometry_name, object_type, id); + std::string old_name = _project.getGEOObjects().getElementNameByID(geometry_name, object_type, id); SetNameDialog dlg(GeoLib::convertGeoTypeToString(object_type), id, old_name); if (dlg.exec() != QDialog::Accepted) return; _geo_model->addNameForElement(geometry_name, object_type, id, dlg.getNewName()); static_cast<GeoTreeModel*>(this->geoTabWidget->treeView->model())->setNameForItem(geometry_name, object_type, - id, this->_project.getGEOObjects()->getElementNameByID(geometry_name, object_type, id)); + id, _project.getGEOObjects().getElementNameByID(geometry_name, object_type, id)); } 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(); } @@ -1025,7 +1021,7 @@ void MainWindow::showMeshAnalysisDialog() void MainWindow::showLineEditDialog(const std::string &geoName) { LineEditDialog lineEdit( - *(_project.getGEOObjects()->getPolylineVecObj(geoName))); + *(_project.getGEOObjects().getPolylineVecObj(geoName))); connect(&lineEdit, SIGNAL(connectPolylines(const std::string&, std::vector<std::size_t>, double, std::string, bool, bool)), @@ -1049,7 +1045,7 @@ void MainWindow::showMergeGeometriesDialog() if (dlg.exec() != QDialog::Accepted) return; std::string name (dlg.getGeometryName()); - if (_project.getGEOObjects()->mergeGeometries(dlg.getSelectedGeometries(), name) < 0) + if (_project.getGEOObjects().mergeGeometries(dlg.getSelectedGeometries(), name) < 0) OGSError::box("Points are missing for\n at least one geometry."); } diff --git a/Applications/DataExplorer/mainwindow.h b/Applications/DataExplorer/mainwindow.h index 3babcd65049e6d23e80cad6c7c17e6c1555e1ded..d9f86dd575a9904c1cce332f28f6f873b0cebf54 100644 --- a/Applications/DataExplorer/mainwindow.h +++ b/Applications/DataExplorer/mainwindow.h @@ -18,7 +18,7 @@ #include <memory> #ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829 -#include "Applications/ApplicationsLib/ProjectData.h" +#include "DataHolderLib/Project.h" #endif #include "ImportFileTypes.h" @@ -126,8 +126,8 @@ private: void readSettings(); void writeSettings(); QString getLastUsedDir(); - - ProjectData _project; + + DataHolderLib::Project _project; std::unique_ptr<MshModel> _meshModel; std::unique_ptr<ElementTreeModel> _elementModel; std::unique_ptr<TreeModel> _processModel; diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index 173900c76f679af396d9da0ded6bb9cf5fa385e0..5033281e63e1355e2caf7719c390c5ebcf63151d 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -94,7 +94,7 @@ void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &o std::string unique_name; std::vector<std::string> errors; - FileIO::Legacy::readGLIFileV4(it->toStdString(), &geo_objects, unique_name, errors); + FileIO::Legacy::readGLIFileV4(it->toStdString(), geo_objects, unique_name, errors); if (errors.empty() || (errors.size()==1 && errors[0].compare("[readSurface] polyline for surface not found!")==0)) { std::string const geo_name = BaseLib::extractBaseName(it->toStdString()); diff --git a/CMakeLists.txt b/CMakeLists.txt index 95168f728d4352b9e03ec544365d071dbf08347d..7fcb8a3eef77358b89815b9239c18f7ab1152ea2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,7 @@ add_subdirectory( BaseLib ) if(TARGET Boost) add_dependencies(BaseLib Boost) endif() +add_subdirectory( DataHolderLib ) add_subdirectory( FileIO ) add_subdirectory( GeoLib ) add_subdirectory( InSituLib ) diff --git a/DataHolderLib/CMakeLists.txt b/DataHolderLib/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..3983aa59b14d1c0eacac4ba6d3a3355ebfaf5dfa --- /dev/null +++ b/DataHolderLib/CMakeLists.txt @@ -0,0 +1,11 @@ +# Source files +GET_SOURCE_FILES(SOURCES_DataHolderLib) + +# Library +add_library(DataHolderLib ${SOURCES_DataHolderLib}) + +target_link_libraries(DataHolderLib + GeoLib + MeshLib + logog +) \ No newline at end of file diff --git a/DataHolderLib/Project.cpp b/DataHolderLib/Project.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8df157f4e39306fcb939af993ec8e512aa8d6320 --- /dev/null +++ b/DataHolderLib/Project.cpp @@ -0,0 +1,103 @@ +/** + * \copyright + * Copyright (c) 2012-2016, 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 "Project.h" + +#include <algorithm> + +// ThirdParty/logog +#include <logog/include/logog.hpp> + +#include "BaseLib/FileTools.h" +#include "BaseLib/uniqueInsert.h" + +#include "MeshLib/Mesh.h" + +namespace DataHolderLib +{ + +void Project::addMesh(std::unique_ptr<MeshLib::Mesh> mesh) +{ + std::string name = mesh->getName(); + getUniqueName(name); + mesh->setName(name); + _mesh_vec.push_back(std::move(mesh)); +} + +std::vector<std::unique_ptr<MeshLib::Mesh>>::const_iterator +Project::findMeshByName(std::string const& name) const +{ + return const_cast<Project&>(*this).findMeshByName(name); +} + +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()); }); +} + +const MeshLib::Mesh* Project::getMesh(const std::string &name) const +{ + auto it = findMeshByName(name); + return (it == _mesh_vec.end() ? nullptr : it->get()); +} + +bool Project::removeMesh(const std::string &name) +{ + auto it = findMeshByName(name); + if (it != _mesh_vec.end()) + { + delete it->release(); + _mesh_vec.erase(it); + return true; + } + return false; +} + +bool Project::meshExists(const std::string &name) const +{ + return findMeshByName(name) != _mesh_vec.end(); +} + +bool Project::getUniqueName(std::string &name) const +{ + int count(0); + bool isUnique(false); + std::string cpName; + + while (!isUnique) + { + isUnique = true; + cpName = name; + + count++; + // If the original name already exists we start to add numbers to name for + // as long as it takes to make the name unique. + if (count > 1) + cpName = cpName + "-" + std::to_string(count); + + for (auto & mesh : _mesh_vec) + if ( cpName == mesh->getName()) + isUnique = false; + } + + // At this point cpName is a unique name and isUnique is true. + // If cpName is not the original name, "name" is changed and isUnique is set to false, + // indicating that a vector with the original name already exists. + if (count > 1) + { + isUnique = false; + name = cpName; + } + return isUnique; +} + +} //namespace diff --git a/DataHolderLib/Project.h b/DataHolderLib/Project.h new file mode 100644 index 0000000000000000000000000000000000000000..670e66f7f58f4c83feb14d084c22ea98efc9f05f --- /dev/null +++ b/DataHolderLib/Project.h @@ -0,0 +1,85 @@ +/** + * \copyright + * Copyright (c) 2012-2016, 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 DATAEXPLORERPROJECT_H_ +#define DATAEXPLORERPROJECT_H_ + +#include <memory> + +#include "GeoLib/GEOObjects.h" + +#include "MeshLib/Mesh.h" + +//namespace MeshLib { +// class Mesh; +//} + +namespace DataHolderLib +{ + +/** + * The ProjectData Object contains all the data needed for a certain project, i.e. all + * geometric data (stored in a GEOObjects-object), all the meshes, processes, + * and process variables. + */ +class Project final +{ +public: + /// Constructor + Project() = default; + + Project(Project&) = delete; + + ~Project() = default; + + /// Returns the GEOObjects containing all points, polylines and surfaces. + GeoLib::GEOObjects& getGEOObjects() { return _geoObjects; } + + /// Adds a new mesh under a (possibly new) unique name. + /// \attention This might change the given mesh's name. + void addMesh(std::unique_ptr<MeshLib::Mesh> mesh); + + /// Returns the mesh with the given name or a \c nullptr if the mesh was not + /// found. + const MeshLib::Mesh* getMesh(const std::string &name) const; + + /// Returns all the meshes with their respective names + const std::vector<std::unique_ptr<MeshLib::Mesh>>& getMeshObjects() const + { + return _mesh_vec; + } + + /// Deletes all meshes with the given name and removes them from the list of + /// saved meshes. If any mesh was found for removal, true is returned and + /// false otherwise. + bool removeMesh(const std::string &name); + +private: + /// Checks if a mesh with the same name exists and provides a unique name in + /// case of already existing mesh. Returns true if the mesh name is unique. + /// Returns false and changes the provided name to a unique name otherwise. + bool getUniqueName(std::string &name) const; + + /// Returns true if a mesh with the same name exists and false otherwise. + bool meshExists(const std::string &name) const; + + + /// Returns an iterator to the first found mesh with the given name. + std::vector<std::unique_ptr<MeshLib::Mesh>>::const_iterator findMeshByName( + std::string const& name) const; + std::vector<std::unique_ptr<MeshLib::Mesh>>::iterator findMeshByName( + std::string const& name); + + GeoLib::GEOObjects _geoObjects; + std::vector<std::unique_ptr<MeshLib::Mesh>> _mesh_vec; +}; + +} // namespace + +#endif //DATAEXPLORERPROJECT_H_ diff --git a/FileIO/Legacy/OGSIOVer4.cpp b/FileIO/Legacy/OGSIOVer4.cpp index 9bd002e6adeec4ded7dda44812809efa91fa405b..927b4c00adbf994f35f0285973e51ee8c5627d75 100644 --- a/FileIO/Legacy/OGSIOVer4.cpp +++ b/FileIO/Legacy/OGSIOVer4.cpp @@ -430,7 +430,7 @@ std::string readSurfaces(std::istream &in, } bool readGLIFileV4(const std::string& fname, - GeoLib::GEOObjects* geo, + GeoLib::GEOObjects& geo, std::string& unique_name, std::vector<std::string>& errors) { @@ -458,8 +458,7 @@ bool readGLIFileV4(const std::string& fname, unique_name = BaseLib::extractBaseName(fname); if (!pnt_vec->empty()) - // KR: insert into GEOObjects if not empty - geo->addPointVec(std::move(pnt_vec), unique_name, pnt_id_names_map, 1e-6); + geo.addPointVec(std::move(pnt_vec), unique_name, pnt_id_names_map, 1e-6); // extract path for reading external files const std::string path = BaseLib::extractPath(fname); @@ -469,7 +468,7 @@ bool readGLIFileV4(const std::string& fname, auto ply_vec = std::unique_ptr<std::vector<GeoLib::Polyline*>>( new std::vector<GeoLib::Polyline*>); GeoLib::PointVec & point_vec( - *const_cast<GeoLib::PointVec*>(geo->getPointVecObj(unique_name))); + *const_cast<GeoLib::PointVec*>(geo.getPointVecObj(unique_name))); std::vector<GeoLib::Point*>* geo_pnt_vec(const_cast<std::vector<GeoLib::Point*>*>( point_vec.getVector())); if (tag.find("#POLYLINE") != std::string::npos && in) @@ -477,7 +476,7 @@ bool readGLIFileV4(const std::string& fname, INFO("GeoLib::readGLIFile(): read polylines from stream."); tag = readPolylines(in, ply_vec.get(), *ply_names, *geo_pnt_vec, zero_based_idx, - geo->getPointVecObj(unique_name)->getIDMap(), path, errors); + geo.getPointVecObj(unique_name)->getIDMap(), path, errors); INFO("GeoLib::readGLIFile(): \t ok, %d polylines read.", ply_vec->size()); } else @@ -505,13 +504,13 @@ bool readGLIFileV4(const std::string& fname, in.close(); if (!ply_vec->empty()) - geo->addPolylineVec(std::move(ply_vec), unique_name, ply_names); // KR: insert into GEOObjects if not empty + geo.addPolylineVec(std::move(ply_vec), unique_name, ply_names); // KR: insert into GEOObjects if not empty else { delete ply_names; } if (!sfc_vec->empty()) - geo->addSurfaceVec(std::move(sfc_vec), unique_name, sfc_names); // KR: insert into GEOObjects if not empty + geo.addSurfaceVec(std::move(sfc_vec), unique_name, sfc_names); // KR: insert into GEOObjects if not empty else { delete sfc_names; } diff --git a/FileIO/Legacy/OGSIOVer4.h b/FileIO/Legacy/OGSIOVer4.h index 81ea756839c08c11f1e062bb83b4e17eb31927d9..21dc3b8b082c996e14bba9188032be724513417d 100644 --- a/FileIO/Legacy/OGSIOVer4.h +++ b/FileIO/Legacy/OGSIOVer4.h @@ -30,7 +30,10 @@ namespace Legacy { /** Interface for handling geometry from OGS-5 and below (*.gli files) */ /** Reads geometric objects from file in gli format */ -bool readGLIFileV4 (const std::string& fname, GeoLib::GEOObjects* geo, std::string& unique_name, std::vector<std::string>& errors); +bool readGLIFileV4 (const std::string& fname, + GeoLib::GEOObjects& geo, + std::string& unique_name, + std::vector<std::string>& errors); /** Writes geometric objects from a specific geometry to a gli-file */ void writeGLIFileV4 (const std::string& fname, diff --git a/FileIO/SHPInterface.cpp b/FileIO/SHPInterface.cpp index d0c74cbbf04e9d50aad8bdee5417e10200937460..6075c0b81d9bf467d36fc60d0cb9e21cd517ccdd 100644 --- a/FileIO/SHPInterface.cpp +++ b/FileIO/SHPInterface.cpp @@ -85,7 +85,7 @@ void SHPInterface::readPoints(const SHPHandle &hSHP, int numberOfElements, std:: points->push_back(pnt); } - _geoObjects->addPointVec(std::move(points), listName); + _geoObjects.addPointVec(std::move(points), listName); SHPDestroyObject(hSHPObject); // de-allocate SHPObject } } @@ -107,7 +107,7 @@ void SHPInterface::readStations(const SHPHandle &hSHP, int numberOfElements, std stations->push_back(stn); } - _geoObjects->addStationVec(std::move(stations), listName); + _geoObjects.addStationVec(std::move(stations), listName); SHPDestroyObject(hSHPObject); // de-allocate SHPObject } } @@ -143,8 +143,8 @@ void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, st SHPDestroyObject(hSHPObject); // de-allocate SHPObject } - _geoObjects->addPointVec(std::move(pnts), listName); - GeoLib::PointVec const& points(*(_geoObjects->getPointVecObj(listName))); + _geoObjects.addPointVec(std::move(pnts), listName); + GeoLib::PointVec const& points(*(_geoObjects.getPointVecObj(listName))); std::vector<std::size_t> const& pnt_id_map(points.getIDMap()); pnt_id = 0; @@ -170,14 +170,14 @@ void SHPInterface::readPolylines(const SHPHandle &hSHP, int numberOfElements, st } SHPDestroyObject(hSHPObject); // de-allocate SHPObject } - _geoObjects->addPolylineVec(std::move(lines), listName); + _geoObjects.addPolylineVec(std::move(lines), listName); } void SHPInterface::readPolygons(const SHPHandle &hSHP, int numberOfElements, const std::string &listName) { readPolylines(hSHP, numberOfElements, listName); - auto const polylines = _geoObjects->getPolylineVec(listName); + auto const polylines = _geoObjects.getPolylineVec(listName); auto sfc_vec = std::unique_ptr<std::vector<GeoLib::Surface*>>( new std::vector<GeoLib::Surface*>); @@ -191,7 +191,7 @@ void SHPInterface::readPolygons(const SHPHandle &hSHP, int numberOfElements, con } if (!sfc_vec->empty()) - _geoObjects->addSurfaceVec(std::move(sfc_vec), listName); + _geoObjects.addSurfaceVec(std::move(sfc_vec), listName); } bool SHPInterface::write2dMeshToSHP(const std::string &file_name, const MeshLib::Mesh &mesh) diff --git a/FileIO/SHPInterface.h b/FileIO/SHPInterface.h index 241809c416e859595a2fb01084a612be7b104e3a..be7b3647d4094586ad0cec5e41021154c0c44490 100644 --- a/FileIO/SHPInterface.h +++ b/FileIO/SHPInterface.h @@ -55,7 +55,7 @@ public: }; /// Constructor - SHPInterface(GeoLib::GEOObjects* geoObjects) : _geoObjects(geoObjects) {} + SHPInterface(GeoLib::GEOObjects& geoObjects) : _geoObjects(geoObjects) {} /// Reads the header of the shape file. bool readSHPInfo(const std::string &filename, int &shapeType, int &numberOfEntities); @@ -81,7 +81,7 @@ private: /// Reads lines into a vector of Polyline and Surface objects. void readPolygons (const SHPHandle &hSHP, int numberOfElements, const std::string& listName); - GeoLib::GEOObjects* _geoObjects; + GeoLib::GEOObjects& _geoObjects; }; } diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.cpp b/FileIO/XmlIO/Qt/XmlGspInterface.cpp index eef71acd6cb608177fea1b362960182614a824c1..ee51b8121a5b30f49618d8321c94fa4f5cfd72f9 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.cpp +++ b/FileIO/XmlIO/Qt/XmlGspInterface.cpp @@ -38,15 +38,10 @@ namespace FileIO { -XmlGspInterface::XmlGspInterface( - GeoLib::GEOObjects& geoObjects, - std::vector<MeshLib::Mesh*> const& mesh_vector, - std::function<void(MeshLib::Mesh* const)>&& add_mesh_callback) - : XMLInterface(), - XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysProject.xsd")), - _geoObjects(geoObjects), - _mesh_vector(mesh_vector), - _add_mesh_callback(std::move(add_mesh_callback)) + +XmlGspInterface::XmlGspInterface(DataHolderLib::Project& project) +: XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysProject.xsd")), + _project(project) { } @@ -74,7 +69,7 @@ int XmlGspInterface::readFile(const QString &fileName) const QString file_node(fileList.at(i).nodeName()); if (file_node.compare("geo") == 0) { - XmlGmlInterface gml(_geoObjects); + XmlGmlInterface gml(_project.getGEOObjects()); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) { @@ -91,7 +86,7 @@ int XmlGspInterface::readFile(const QString &fileName) } else if (file_node.compare("stn") == 0) { - XmlStnInterface stn(_geoObjects); + XmlStnInterface stn(_project.getGEOObjects()); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) if (childList.at(j).nodeName().compare("file") == 0) @@ -102,8 +97,9 @@ int XmlGspInterface::readFile(const QString &fileName) { const std::string msh_name = path.toStdString() + fileList.at(i).toElement().text().toStdString(); - MeshLib::Mesh* msh = FileIO::readMeshFromFile(msh_name); - if (msh) _add_mesh_callback(msh); + std::unique_ptr<MeshLib::Mesh> mesh(FileIO::readMeshFromFile(msh_name)); + if (mesh) + _project.addMesh(std::move(mesh)); } } @@ -118,6 +114,7 @@ int XmlGspInterface::writeToFile(const std::string& filename) bool XmlGspInterface::write() { + GeoLib::GEOObjects& geoObjects = _project.getGEOObjects(); QFileInfo fi(QString::fromStdString(_filename)); std::string path((fi.absolutePath()).toStdString() + "/"); @@ -135,11 +132,11 @@ bool XmlGspInterface::write() // GML std::vector<std::string> geoNames; - _geoObjects.getGeometryNames(geoNames); + geoObjects.getGeometryNames(geoNames); for (std::vector<std::string>::const_iterator it(geoNames.begin()); it != geoNames.end(); ++it) { // write GLI file - XmlGmlInterface gml(_geoObjects); + XmlGmlInterface gml(geoObjects); std::string name(*it); gml.setNameForExport(name); if (gml.writeToFile(std::string(path + name + ".gml"))) @@ -156,11 +153,12 @@ bool XmlGspInterface::write() } // MSH - for (auto const& mesh : _mesh_vector) + auto const& mesh_vector = _project.getMeshObjects(); + for (auto const& mesh : mesh_vector) { // write mesh file Legacy::MeshIO meshIO; - meshIO.setMesh(mesh); + meshIO.setMesh((&mesh)->get()); std::string fileName(path + mesh->getName()); meshIO.writeToFile(fileName); @@ -175,11 +173,11 @@ bool XmlGspInterface::write() // STN std::vector<std::string> stnNames; - _geoObjects.getStationVectorNames(stnNames); + geoObjects.getStationVectorNames(stnNames); for (std::vector<std::string>::const_iterator it(stnNames.begin()); it != stnNames.end(); ++it) { // write STN file - XmlStnInterface stn(_geoObjects); + XmlStnInterface stn(geoObjects); std::string name(*it); stn.setNameForExport(name); @@ -202,4 +200,5 @@ bool XmlGspInterface::write() _out << xml; return true; } + } diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.h b/FileIO/XmlIO/Qt/XmlGspInterface.h index f13dce3f2e9d0d37cd04488e2f7e64227f9673fc..02350cf9616de654aa7dd13591a9f837e0a83aab 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.h +++ b/FileIO/XmlIO/Qt/XmlGspInterface.h @@ -15,7 +15,6 @@ #ifndef XMLGSPINTERFACE_H #define XMLGSPINTERFACE_H -#include <functional> #include <vector> #include <string> @@ -24,15 +23,7 @@ #include "../XMLInterface.h" #include "XMLQtInterface.h" -namespace MeshLib -{ -class Mesh; -} - -namespace GeoLib -{ -class GEOObjects; -} +#include "DataHolderLib/Project.h" namespace FileIO { @@ -43,10 +34,7 @@ namespace FileIO class XmlGspInterface : public XMLInterface, public XMLQtInterface { public: - XmlGspInterface( - GeoLib::GEOObjects& geoObjects, - std::vector<MeshLib::Mesh*> const& mesh_vector, - std::function<void(MeshLib::Mesh* const)>&& add_mesh_callback); + XmlGspInterface(DataHolderLib::Project &project); virtual ~XmlGspInterface() {} @@ -63,9 +51,7 @@ protected: private: std::string _filename; - GeoLib::GEOObjects& _geoObjects; - std::vector<MeshLib::Mesh*> const& _mesh_vector; - std::function<void(MeshLib::Mesh* const)> _add_mesh_callback; + DataHolderLib::Project& _project; }; } diff --git a/FileIO/readGeometryFromFile.cpp b/FileIO/readGeometryFromFile.cpp index fe6cc8a6b3508e07216a3e27ae879bc842c6006e..3a84b33fa553fdd26a7bc9a019fc4c4e5370f131 100644 --- a/FileIO/readGeometryFromFile.cpp +++ b/FileIO/readGeometryFromFile.cpp @@ -30,7 +30,7 @@ readGeometryFromFile(std::string const& fname, GeoLib::GEOObjects & geo_objs) } else { std::vector<std::string> errors; std::string geo_name(BaseLib::extractBaseNameWithoutExtension(fname)); - FileIO::Legacy::readGLIFileV4(fname, &geo_objs, geo_name, errors); + FileIO::Legacy::readGLIFileV4(fname, geo_objs, geo_name, errors); } } } diff --git a/Tests/FileIO/TestGLIReader.cpp b/Tests/FileIO/TestGLIReader.cpp index 465e9278426ca9f280691f77b694f7194c9ab39d..12fd2c5813b7d2b29d759d18ff3b9f467b2e36de 100644 --- a/Tests/FileIO/TestGLIReader.cpp +++ b/Tests/FileIO/TestGLIReader.cpp @@ -58,7 +58,7 @@ TEST_F(OGSIOVer4InterfaceTest, SimpleTIN) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -81,7 +81,7 @@ TEST_F(OGSIOVer4InterfaceTest, StillCorrectTINWihtAdditionalValueAtEndOfLine) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -103,7 +103,7 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN_ZeroAreaTri) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -126,7 +126,7 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN_LineDoesNotStartWithID) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -148,7 +148,7 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN_PointIsMissing) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -169,7 +169,7 @@ TEST_F(OGSIOVer4InterfaceTest, InvalidTIN_CoordOfPointIsMissing) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name)); @@ -190,7 +190,7 @@ TEST_F(OGSIOVer4InterfaceTest, SimpleTIN_AdditionalEmptyLinesAtEnd) GeoLib::GEOObjects geometries; std::vector<std::string> errors; std::string geometry_name("TestGeometry"); - FileIO::Legacy::readGLIFileV4(_gli_fname, &geometries, geometry_name, errors); + FileIO::Legacy::readGLIFileV4(_gli_fname, geometries, geometry_name, errors); std::vector<GeoLib::Surface*> const* sfcs(geometries.getSurfaceVec(geometry_name));