diff --git a/Applications/DataExplorer/mainwindow.cpp b/Applications/DataExplorer/mainwindow.cpp index 86cadd3a068aee9ab79b3cd4065880bbc6360a35..7adef2343e9d611dfdf98495b987e24fbc177604 100644 --- a/Applications/DataExplorer/mainwindow.cpp +++ b/Applications/DataExplorer/mainwindow.cpp @@ -420,7 +420,12 @@ void MainWindow::save() if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(_project); + XmlGspInterface xml(*_project.getGEOObjects(), + _project.getMeshObjects(), + [this](MeshLib::Mesh* const mesh) + { + _project.addMesh(mesh); + }); xml.writeToFile(fileName.toStdString()); } else if (fi.suffix().toLower() == "geo") @@ -467,7 +472,12 @@ void MainWindow::loadFile(ImportFileType::type t, const QString &fileName) } else if (fi.suffix().toLower() == "gsp") { - XmlGspInterface xml(_project); + XmlGspInterface xml(*_project.getGEOObjects(), + _project.getMeshObjects(), + [this](MeshLib::Mesh* const mesh) + { + _project.addMesh(mesh); + }); if (xml.readFile(fileName)) { _meshModel->updateModel(); diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.cpp b/FileIO/XmlIO/Qt/XmlGspInterface.cpp index 360322e7d67410c5b82f697060988f860a8ba4f4..b3ba22b01779252c59c699da9f2e24619b836c34 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.cpp +++ b/FileIO/XmlIO/Qt/XmlGspInterface.cpp @@ -19,7 +19,6 @@ #include <logog/include/logog.hpp> -#include "Applications/ApplicationsLib/ProjectData.h" #include "GeoLib/GEOObjects.h" #include "XmlGmlInterface.h" @@ -39,9 +38,15 @@ namespace FileIO { -XmlGspInterface::XmlGspInterface(ProjectData& project) : - XMLInterface(), XMLQtInterface(BaseLib::FileFinder().getPath("OpenGeoSysProject.xsd")), - _project(project) +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)) { } @@ -69,7 +74,7 @@ int XmlGspInterface::readFile(const QString &fileName) const QString file_node(fileList.at(i).nodeName()); if (file_node.compare("geo") == 0) { - XmlGmlInterface gml(*(_project.getGEOObjects())); + XmlGmlInterface gml(_geoObjects); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) { @@ -86,7 +91,7 @@ int XmlGspInterface::readFile(const QString &fileName) } else if (file_node.compare("stn") == 0) { - XmlStnInterface stn(*(_project.getGEOObjects())); + XmlStnInterface stn(_geoObjects); const QDomNodeList childList = fileList.at(i).childNodes(); for(int j = 0; j < childList.count(); j++) if (childList.at(j).nodeName().compare("file") == 0) @@ -98,8 +103,7 @@ 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) - _project.addMesh(msh); + if (msh) _add_mesh_callback(msh); } } @@ -114,7 +118,6 @@ 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() + "/"); @@ -132,11 +135,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"))) @@ -153,8 +156,9 @@ bool XmlGspInterface::write() } // MSH - 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) + for (std::vector<MeshLib::Mesh*>::const_iterator it(_mesh_vector.begin()); + it != _mesh_vector.end(); + ++it) { // write mesh file Legacy::MeshIO meshIO; @@ -173,11 +177,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); diff --git a/FileIO/XmlIO/Qt/XmlGspInterface.h b/FileIO/XmlIO/Qt/XmlGspInterface.h index 2e441d167bc54e738aed7241bbacc5a9b748b7ac..f13dce3f2e9d0d37cd04488e2f7e64227f9673fc 100644 --- a/FileIO/XmlIO/Qt/XmlGspInterface.h +++ b/FileIO/XmlIO/Qt/XmlGspInterface.h @@ -15,6 +15,8 @@ #ifndef XMLGSPINTERFACE_H #define XMLGSPINTERFACE_H +#include <functional> +#include <vector> #include <string> #include <QString> @@ -22,7 +24,15 @@ #include "../XMLInterface.h" #include "XMLQtInterface.h" -class ProjectData; +namespace MeshLib +{ +class Mesh; +} + +namespace GeoLib +{ +class GEOObjects; +} namespace FileIO { @@ -33,11 +43,10 @@ namespace FileIO class XmlGspInterface : public XMLInterface, public XMLQtInterface { public: - /** - * Constructor - * \param project Project data. - */ - XmlGspInterface(ProjectData &project); + XmlGspInterface( + GeoLib::GEOObjects& geoObjects, + std::vector<MeshLib::Mesh*> const& mesh_vector, + std::function<void(MeshLib::Mesh* const)>&& add_mesh_callback); virtual ~XmlGspInterface() {} @@ -54,8 +63,9 @@ protected: private: std::string _filename; - - ProjectData& _project; + GeoLib::GEOObjects& _geoObjects; + std::vector<MeshLib::Mesh*> const& _mesh_vector; + std::function<void(MeshLib::Mesh* const)> _add_mesh_callback; }; }