From c0b66d37f474115e51124c4e65abe6bdf0b28354 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@fz-juelich.de> Date: Fri, 5 Apr 2019 00:15:00 +0200 Subject: [PATCH] Kindly ask for missing geometry file (TXT trajs) --- src/MainWindow.cpp | 38 ++++++++++++++++++++++++++++++++++++-- src/SaxParser.cpp | 6 +++++- src/geometry/Building.cpp | 2 +- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fff3cd5..90a43fb 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -635,7 +635,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) Debug::Messages("Enter MainWindow::addPedestrianGroup with filename <%s>", fileName.toStdString().c_str()); statusBar()->showMessage(tr("Select a file")); - if(fileName.isEmpty()) + if(fileName.isEmpty()) fileName = QFileDialog::getOpenFileName(this, "Select the file containing the data to visualize", QDir::currentPath(), @@ -670,6 +670,38 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) Debug::Messages("MainWindow::addPedestrianGroup: geometry name: <%s>", geometry_file.toStdString().c_str()); + if(geometry_file.isEmpty()) + { + auto fileDir = fileInfo.path(); + if(fileName.endsWith(".txt",Qt::CaseInsensitive)) + { + int res = QMessageBox::warning(this, "Did not find geometry name in TXT file", + "Warning: Did not find geometry name in TXT file\nOpen geometry file?" + , QMessageBox::Yes + | QMessageBox::No, QMessageBox::Yes); + if (res == QMessageBox::No) { + exit(EXIT_FAILURE); + //return false; + } + geometry_file = QFileDialog::getOpenFileName(this, + "Select a geometry file", + fileDir, + "Geometry (*.xml)"); + Debug::Messages("Got geometry file: <%s>", geometry_file.toStdString().c_str()); + QFileInfo check_file(geometry_file); + if( !(check_file.exists() && check_file.isFile()) ) + { + Debug::Error("Geomery file does not exist."); + exit(EXIT_FAILURE); + } + geometry_file = check_file.fileName(); + } + // @todo: check xml file too, although probably xml files + // always have a geometry tag + + } + std::cout << "---> geometry " << geometry_file.toStdString().c_str() << "\n" ; + // if xml is detected, just load and show the geometry then exit if(geometry_file.endsWith(".xml",Qt::CaseInsensitive)) { @@ -690,7 +722,9 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) if (res == QMessageBox::No) { return false; } - SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry); + SaxParser::parseGeometryXMLV04(wd+"/"+geometry_file,geometry);//@todo: + //use + //qt sep } else { //everything was fine. Delete the log file //std::cout << "won't delete logfile\n"; diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index cd0f3ac..1cd0f61 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -1125,7 +1125,11 @@ QString SaxParser::extractGeometryFilenameTXT(QString &filename) }// while } // if open if(extracted_geo_name=="") - Debug::Warning("Could not extracted geometry file!"); + { + Debug::Warning("Could not extract geometry file!"); +// extracted_geo_name = "geo.xml"; + } + else Debug::Messages("Extracted geometry from TXT file <%s>", extracted_geo_name.toStdString().c_str()); return extracted_geo_name; diff --git a/src/geometry/Building.cpp b/src/geometry/Building.cpp index 2abf8e7..a5a00f2 100644 --- a/src/geometry/Building.cpp +++ b/src/geometry/Building.cpp @@ -380,7 +380,7 @@ bool Building::LoadGeometry(const std::string &geometryfile) TiXmlDocument docGeo(geoFilenameWithPath); if (!docGeo.LoadFile()) { Debug::Messages("%s", docGeo.ErrorDesc()); - Debug::Error("LoadGeometry: could not parse the geometry file"); + Debug::Error("LoadGeometry: could not parse the geometry file %s", geoFilenameWithPath.c_str()); return false; } -- GitLab