From 9042d5e10eac3f17c0aecd22f55a11e9d07d3811 Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Wed, 1 Oct 2014 15:28:48 +0200 Subject: [PATCH] fixed logog-problem and optimised code a little --- .../Utils/OGSFileConverter/FileListDialog.cpp | 47 ++++--- .../Utils/OGSFileConverter/FileListDialog.h | 6 +- .../OGSFileConverter/OGSFileConverter.cpp | 133 +++++++++--------- .../Utils/OGSFileConverter/OGSFileConverter.h | 18 +-- Applications/Utils/OGSFileConverter/main.cpp | 13 ++ 5 files changed, 117 insertions(+), 100 deletions(-) diff --git a/Applications/Utils/OGSFileConverter/FileListDialog.cpp b/Applications/Utils/OGSFileConverter/FileListDialog.cpp index 8fe25487cda..72c9e36c4e5 100644 --- a/Applications/Utils/OGSFileConverter/FileListDialog.cpp +++ b/Applications/Utils/OGSFileConverter/FileListDialog.cpp @@ -29,19 +29,19 @@ void FileListDialog::on_addButton_pressed() dlg.setDirectory(settings.value("lastOpenedOgsFileDirectory").toString()); dlg.setFileMode(QFileDialog::ExistingFiles); dlg.setNameFilter(this->getFileTypeString(_input_file_type)); - QStringList file_names; if (dlg.exec()) { - file_names = dlg.selectedFiles(); - if (!file_names.empty()) - { - QStringList list = _allFiles.stringList(); - list.append(file_names); - _allFiles.setStringList(list); - QDir dir = QDir(file_names[0]); - settings.setValue("lastOpenedOgsFileDirectory", dir.absolutePath()); - } + QStringList const file_names = dlg.selectedFiles(); + + if (file_names.empty()) + return; + + QStringList list = _allFiles.stringList(); + list.append(file_names); + _allFiles.setStringList(list); + QDir const dir = QDir(file_names[0]); + settings.setValue("lastOpenedOgsFileDirectory", dir.absolutePath()); } } @@ -54,24 +54,25 @@ void FileListDialog::on_removeButton_pressed() void FileListDialog::on_browseButton_pressed() { - QSettings settings("UFZ", "OpenGeoSys-5"); - QFileInfo fi(settings.value("lastOpenedOgsFileDirectory").toString()); - const QString dirName = QFileDialog::getExistingDirectory(this, "Save to", fi.absolutePath().append("/")); + QSettings const settings("UFZ", "OpenGeoSys-5"); + QFileInfo const fi(settings.value("lastOpenedOgsFileDirectory").toString()); + QString const dirName = QFileDialog::getExistingDirectory(this, "Save to", fi.absolutePath().append("/")); this->outputDirEdit->setText(dirName); } void FileListDialog::accept() { - if (!_allFiles.stringList().empty()) + if (_allFiles.stringList().empty()) { - _output_dir = this->outputDirEdit->text(); - if (!this->outputDirEdit->text().isEmpty() && QDir(_output_dir).exists()) - this->done(QDialog::Accepted); - else - OGSError::box("Output directory not found."); + OGSError::box("No files selected."); + return; } + + _output_dir = this->outputDirEdit->text(); + if (!this->outputDirEdit->text().isEmpty() && QDir(_output_dir).exists()) + this->done(QDialog::Accepted); else - OGSError::box("No files selected."); + OGSError::box("Output directory not found."); } void FileListDialog::reject() @@ -79,11 +80,11 @@ void FileListDialog::reject() this->done(QDialog::Rejected); } -QString FileListDialog::getFileTypeString(FileType file_type) +const QString FileListDialog::getFileTypeString(FileType file_type) const { - if (file_type==GML) return "OpenGeoSys geometry files (*.gml)"; + if (file_type==GML) return "OpenGeoSys geometry files (*.gml)"; else if (file_type==VTU) return "OpenGeoSys mesh files (*.vtu)"; else if (file_type==GLI) return "GeoSys geometry files (*.gli)"; else if (file_type==MSH) return "GeoSys mesh files (*.msh)"; else return "All files (*.*)"; -} \ No newline at end of file +} diff --git a/Applications/Utils/OGSFileConverter/FileListDialog.h b/Applications/Utils/OGSFileConverter/FileListDialog.h index 0ccd9d8f3ed..3f25a96e58d 100644 --- a/Applications/Utils/OGSFileConverter/FileListDialog.h +++ b/Applications/Utils/OGSFileConverter/FileListDialog.h @@ -28,11 +28,11 @@ public: FileListDialog(FileType input, FileType output, QWidget* parent = NULL); ~FileListDialog(void); - const QStringList getInputFileList() { return _allFiles.stringList(); }; - const QString getOutputDir() { return _output_dir; }; + const QStringList getInputFileList() const { return _allFiles.stringList(); }; + const QString getOutputDir() const { return _output_dir; }; private: - QString getFileTypeString(FileType file_type); + const QString getFileTypeString(FileType file_type) const; QStringListModel _allFiles; QString _output_dir; diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp index 9a6d0642c46..ba5955d7678 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.cpp @@ -34,76 +34,74 @@ OGSFileConverter::~OGSFileConverter() { } -void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &output) +void OGSFileConverter::convertGML2GLI(const QStringList &input, const QString &output) const { if (input.empty()) return; - ProjectData project; - GeoLib::GEOObjects* geo_objects = project.getGEOObjects(); - FileIO::XmlGmlInterface xml(*geo_objects); + GeoLib::GEOObjects geo_objects; + FileIO::XmlGmlInterface xml(geo_objects); for (QStringList::const_iterator it=input.begin(); it!=input.end(); ++it) { const QFileInfo fi(*it); - const std::string file_name = fi.baseName().toStdString(); const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".gli").toStdString(); - if (!fileExists(output_str)) + if (fileExists(output_str)) + continue; + + if (!xml.readFile(*it)) { - xml.readFile(*it); - std::vector<std::string> geo_names; - geo_objects->getGeometryNames(geo_names); - FileIO::Legacy::writeGLIFileV4(output_str, geo_names[0], *geo_objects); - geo_objects->removeSurfaceVec(geo_names[0]); - geo_objects->removePolylineVec(geo_names[0]); - geo_objects->removePointVec(geo_names[0]); + OGSError::box("Error reading geometry " + fi.fileName()); + continue; } + std::vector<std::string> geo_names; + geo_objects.getGeometryNames(geo_names); + FileIO::Legacy::writeGLIFileV4(output_str, geo_names[0], geo_objects); + geo_objects.removeSurfaceVec(geo_names[0]); + geo_objects.removePolylineVec(geo_names[0]); + geo_objects.removePointVec(geo_names[0]); } - - //FileIO::writeAllDataToGLIFileV4(output.toStdString(), *geo_objects); OGSError::box("File conversion finished"); } -void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &output) +void OGSFileConverter::convertGLI2GML(const QStringList &input, const QString &output) const { if (input.empty()) return; - ProjectData project; - GeoLib::GEOObjects* geo_objects = project.getGEOObjects(); - FileIO::XmlGmlInterface xml(*geo_objects); + GeoLib::GEOObjects geo_objects; + FileIO::XmlGmlInterface xml(geo_objects); for (QStringList::const_iterator it=input.begin(); it!=input.end(); ++it) { const QFileInfo fi(*it); const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".gml").toStdString(); - const std::string geo_name = BaseLib::extractBaseName(it->toStdString()); - if (!fileExists(output_str)) + if (fileExists(output_str)) + continue; + + std::string unique_name; + std::vector<std::string> 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 unique_name; - std::vector<std::string> 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)) - { - xml.setNameForExport(geo_name); - xml.writeToFile(output_str); - geo_objects->removeSurfaceVec(geo_name); - geo_objects->removePolylineVec(geo_name); - geo_objects->removePointVec(geo_name); - } - else - for (size_t k(0); k<errors.size(); k++) - OGSError::box(QString::fromStdString(errors[k])); + std::string const geo_name = BaseLib::extractBaseName(it->toStdString()); + xml.setNameForExport(geo_name); + xml.writeToFile(output_str); + geo_objects.removeSurfaceVec(geo_name); + geo_objects.removePolylineVec(geo_name); + geo_objects.removePointVec(geo_name); } + else + for (std::size_t k(0); k<errors.size(); ++k) + OGSError::box(QString::fromStdString(errors[k])); } - OGSError::box("File conversion finished"); } -void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &output) +void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &output) const { if (input.empty()) return; @@ -111,24 +109,27 @@ void OGSFileConverter::convertVTU2MSH(const QStringList &input, const QString &o for (QStringList::const_iterator it=input.begin(); it!=input.end(); ++it) { const QFileInfo fi(*it); - const std::string msh_name = fi.fileName().toStdString(); const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".msh").toStdString(); - if (!fileExists(output_str)) + if (fileExists(output_str)) + continue; + + FileIO::BoostVtuInterface vtu; + MeshLib::Mesh const*const mesh (vtu.readVTUFile(it->toStdString().c_str())); + if (mesh == nullptr) { - FileIO::BoostVtuInterface vtu; - MeshLib::Mesh const*const mesh (vtu.readVTUFile(it->toStdString().c_str())); - FileIO::Legacy::MeshIO meshIO; - meshIO.setMesh(mesh); - meshIO.writeToFile(output_str.c_str()); - delete mesh; + OGSError::box("Error reading mesh " + fi.fileName()); + continue; } + FileIO::Legacy::MeshIO meshIO; + meshIO.setMesh(mesh); + meshIO.writeToFile(output_str.c_str()); + delete mesh; } - OGSError::box("File conversion finished"); } -void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &output) +void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &output) const { if (input.empty()) return; @@ -137,44 +138,47 @@ void OGSFileConverter::convertMSH2VTU(const QStringList &input, const QString &o { const QFileInfo fi(*it); const std::string output_str = QString(output + "/" + fi.completeBaseName() + ".vtu").toStdString(); - const std::string msh_name = BaseLib::extractBaseName(it->toStdString()); - if (!fileExists(output_str)) + if (fileExists(output_str)) + continue; + + FileIO::Legacy::MeshIO meshIO; + MeshLib::Mesh const*const mesh (meshIO.loadMeshFromFile(it->toStdString())); + if (mesh == nullptr) { - FileIO::Legacy::MeshIO meshIO; - MeshLib::Mesh const*const mesh (meshIO.loadMeshFromFile(it->toStdString())); - FileIO::BoostVtuInterface vtu; - vtu.setMesh(mesh); - vtu.writeToFile(output_str); - delete mesh; + OGSError::box("Error reading mesh " + fi.fileName()); + continue; } - } - + FileIO::BoostVtuInterface vtu; + vtu.setMesh(mesh); + vtu.writeToFile(output_str); + delete mesh; + } OGSError::box("File conversion finished"); } -void OGSFileConverter::on_gml2gliButton_pressed() +void OGSFileConverter::on_gml2gliButton_pressed() const { FileListDialog dlg(FileListDialog::GML, FileListDialog::GLI); if (dlg.exec()) convertGML2GLI(dlg.getInputFileList(), dlg.getOutputDir()); } -void OGSFileConverter::on_gli2gmlButton_pressed() +void OGSFileConverter::on_gli2gmlButton_pressed() const { FileListDialog dlg(FileListDialog::GLI, FileListDialog::GML); if (dlg.exec()) convertGLI2GML(dlg.getInputFileList(), dlg.getOutputDir()); } -void OGSFileConverter::on_vtu2mshButton_pressed() +void OGSFileConverter::on_vtu2mshButton_pressed() const { FileListDialog dlg(FileListDialog::VTU, FileListDialog::MSH); if (dlg.exec()) convertVTU2MSH(dlg.getInputFileList(), dlg.getOutputDir()); } -void OGSFileConverter::on_msh2vtuButton_pressed() +void OGSFileConverter::on_msh2vtuButton_pressed() const { FileListDialog dlg(FileListDialog::MSH, FileListDialog::VTU); if (dlg.exec()) @@ -188,12 +192,11 @@ void OGSFileConverter::on_closeDialogButton_pressed() bool OGSFileConverter::fileExists(const std::string &file_name) const { - std::ifstream file(file_name.c_str()); + std::ifstream const file(file_name.c_str()); if (file) { - QString name = QString::fromStdString(BaseLib::extractBaseName(file_name)); + QString const name = QString::fromStdString(BaseLib::extractBaseName(file_name)); return !OGSError::question("The file \'" + name + "\' already exists.\n Do you want to overwrite it?", "Warning"); } return false; } - diff --git a/Applications/Utils/OGSFileConverter/OGSFileConverter.h b/Applications/Utils/OGSFileConverter/OGSFileConverter.h index 0d6c83f1376..413191cd0e8 100644 --- a/Applications/Utils/OGSFileConverter/OGSFileConverter.h +++ b/Applications/Utils/OGSFileConverter/OGSFileConverter.h @@ -21,15 +21,15 @@ private: bool fileExists(const std::string &file_name) const; private slots: - void convertGML2GLI(const QStringList &input, const QString &output); - void convertGLI2GML(const QStringList &input, const QString &output); - void convertVTU2MSH(const QStringList &input, const QString &output); - void convertMSH2VTU(const QStringList &input, const QString &output); - - void on_gml2gliButton_pressed(); - void on_gli2gmlButton_pressed(); - void on_vtu2mshButton_pressed(); - void on_msh2vtuButton_pressed(); + void convertGML2GLI(const QStringList &input, const QString &output) const; + void convertGLI2GML(const QStringList &input, const QString &output) const; + void convertVTU2MSH(const QStringList &input, const QString &output) const; + void convertMSH2VTU(const QStringList &input, const QString &output) const; + + void on_gml2gliButton_pressed() const; + void on_gli2gmlButton_pressed() const; + void on_vtu2mshButton_pressed() const; + void on_msh2vtuButton_pressed() const; void on_closeDialogButton_pressed(); }; diff --git a/Applications/Utils/OGSFileConverter/main.cpp b/Applications/Utils/OGSFileConverter/main.cpp index 914a388330a..d4c7fc14785 100644 --- a/Applications/Utils/OGSFileConverter/main.cpp +++ b/Applications/Utils/OGSFileConverter/main.cpp @@ -1,8 +1,17 @@ #include "OGSFileConverter.h" + +#include "logog/include/logog.hpp" +#include "LogogSimpleFormatter.h" + #include <QtGui/QApplication> int main(int argc, char* argv[]) { + LOGOG_INITIALIZE(); + logog::Cout* logogCout = new logog::Cout; + BaseLib::LogogSimpleFormatter* formatter = new BaseLib::LogogSimpleFormatter; + logogCout->SetFormatter(*formatter); + QApplication app(argc, argv); setlocale(LC_NUMERIC,"C"); OGSFileConverter* fc = new OGSFileConverter(); @@ -11,5 +20,9 @@ int main(int argc, char* argv[]) int returncode = app.exec(); delete fc; + delete formatter; + delete logogCout; + LOGOG_SHUTDOWN(); + return returncode; } -- GitLab