diff --git a/GeoLib/CMakeLists.txt b/GeoLib/CMakeLists.txt index c2dc61b9c27c046afd117f38c8227d11f9b9ebb5..a3360c98fdddf2d5eb3d14cd733cd47997856739 100644 --- a/GeoLib/CMakeLists.txt +++ b/GeoLib/CMakeLists.txt @@ -3,7 +3,6 @@ get_source_files(SOURCES) append_source_files(SOURCES IO) -append_source_files(SOURCES IO/XmlIO/Rapid) append_source_files(SOURCES IO/XmlIO/Boost) if(OGS_BUILD_GUI) diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp index 8e561121280d745592c6bc398aa650fb2090b188..1b164185d464c5b1bc47487ca300474c8cf6a1f6 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp +++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.cpp @@ -18,7 +18,7 @@ #include <QFile> #include <QtXml/QDomDocument> - +#include <RapidXML/rapidxml.hpp> #include <logog/include/logog.hpp> #include "BaseLib/BuildInfo.h" @@ -33,6 +33,163 @@ namespace GeoLib { namespace IO { +/// Reads the stratigraphy of a borehole from an xml-file using the RapidXML +/// parser +static void rapidReadStratigraphy(const rapidxml::xml_node<>* strat_root, + GeoLib::StationBorehole* borehole) +{ + double depth_check((*borehole)[2]); + + for (rapidxml::xml_node<>* horizon_node = strat_root->first_node("horizon"); + horizon_node; + horizon_node = horizon_node->next_sibling()) + { + if (horizon_node->first_attribute("id") && + horizon_node->first_attribute("x") && + horizon_node->first_attribute("y") && + horizon_node->first_attribute("z")) + { + std::string horizon_name("[NN]"); + if (horizon_node->first_node("name")) + { + horizon_name = horizon_node->first_node("name")->value(); + } + /* add other horizon features here */ + + double depth( + strtod(horizon_node->first_attribute("z")->value(), nullptr)); + if (fabs(depth - depth_check) > + std::numeric_limits<double>:: + epsilon()) // skip soil-layer if its thickness is zero + { + borehole->addSoilLayer( + strtod(horizon_node->first_attribute("x")->value(), + nullptr), + strtod(horizon_node->first_attribute("y")->value(), + nullptr), + depth, + horizon_name); + depth_check = depth; + } + else + { + WARN( + "XmlStnInterface::rapidReadStratigraphy(): Skipped layer " + "'%s' in borehole '%s' because of thickness 0.0.", + horizon_name.c_str(), + borehole->getName().c_str()); + } + } + else + { + WARN( + "XmlStnInterface::rapidReadStratigraphy(): Attribute missing " + "in <horizon> tag."); + } + } +} + +/// Reads GeoLib::Station- or StationBorehole-objects from an xml-file using the +/// RapidXML parser +static void rapidReadStations(const rapidxml::xml_node<>* station_root, + std::vector<GeoLib::Point*>* stations, + const std::string& file_name) +{ + for (rapidxml::xml_node<>* station_node = station_root->first_node(); + station_node; + station_node = station_node->next_sibling()) + { + if (station_node->first_attribute("id") && + station_node->first_attribute("x") && + station_node->first_attribute("y")) + { + double zVal(0.0); + if (station_node->first_attribute("z")) + { + zVal = strtod(station_node->first_attribute("z")->value(), + nullptr); + } + + std::string station_name; + std::string sensor_data_file_name; + std::string bdate_str("0000-00-00"); + double station_value(0.0); + double borehole_depth(0.0); + if (station_node->first_node("name")) + { + station_name = station_node->first_node("name")->value(); + } + if (station_node->first_node("sensordata")) + { + sensor_data_file_name = + station_node->first_node("sensordata")->value(); + } + if (station_node->first_node("value")) + { + station_value = + strtod(station_node->first_node("value")->value(), nullptr); + } + /* add other station features here */ + + if (std::string(station_node->name()) == "station") + { + auto* s = new GeoLib::Station( + strtod(station_node->first_attribute("x")->value(), + nullptr), + strtod(station_node->first_attribute("y")->value(), + nullptr), + zVal, + station_name); + s->setStationValue(station_value); + if (!sensor_data_file_name.empty()) + { + s->addSensorDataFromCSV(BaseLib::copyPathToFileName( + sensor_data_file_name, file_name)); + } + stations->push_back(s); + } + else if (std::string(station_node->name()) == "borehole") + { + if (station_node->first_node("bdepth")) + { + borehole_depth = strtod( + station_node->first_node("bdepth")->value(), nullptr); + } + if (station_node->first_node("bdate")) + { + bdate_str = station_node->first_node("bdate")->value(); + } + /* add other borehole features here */ + + GeoLib::StationBorehole* s = + GeoLib::StationBorehole::createStation( + station_name, + strtod(station_node->first_attribute("x")->value(), + nullptr), + strtod(station_node->first_attribute("y")->value(), + nullptr), + zVal, + borehole_depth, + bdate_str); + s->setStationValue(station_value); + + if (station_node->first_node("strat")) + { + rapidReadStratigraphy(station_node->first_node("strat"), s); + } + + stations->push_back(s); + } + } + else + { + WARN( + "XmlStnInterface::rapidReadStations(): Attribute missing in " + "<station> tag."); + } + } +} + XmlStnInterface::XmlStnInterface(GeoLib::GEOObjects& geo_objs) : XMLQtInterface("OpenGeoSysSTN.xsd"), _geo_objs(geo_objs) { @@ -401,11 +558,11 @@ int XmlStnInterface::rapidReadFile(const std::string &fileName) std::string b(list_item->name()); if (b == "stations") { - this->rapidReadStations(list_item, stations.get(), fileName); + rapidReadStations(list_item, stations.get(), fileName); } if (b == "boreholes") { - this->rapidReadStations(list_item, stations.get(), fileName); + rapidReadStations(list_item, stations.get(), fileName); } } @@ -421,142 +578,5 @@ int XmlStnInterface::rapidReadFile(const std::string &fileName) return 1; } -void XmlStnInterface::rapidReadStations(const rapidxml::xml_node<>* station_root, - std::vector<GeoLib::Point*>* stations, - const std::string &file_name) -{ - for (rapidxml::xml_node<>* station_node = station_root->first_node(); station_node; - station_node = station_node->next_sibling()) - { - if (station_node->first_attribute("id") && station_node->first_attribute("x") && - station_node->first_attribute("y")) - { - double zVal(0.0); - if (station_node->first_attribute("z")) - { - zVal = strtod(station_node->first_attribute("z")->value(), - nullptr); - } - - std::string station_name; - std::string sensor_data_file_name; - std::string bdate_str("0000-00-00"); - double station_value(0.0); - double borehole_depth(0.0); - if (station_node->first_node("name")) - { - station_name = station_node->first_node("name")->value(); - } - if (station_node->first_node("sensordata")) - { - sensor_data_file_name = - station_node->first_node("sensordata")->value(); - } - if (station_node->first_node("value")) - { - station_value = - strtod(station_node->first_node("value")->value(), nullptr); - } - /* add other station features here */ - - if (std::string(station_node->name()) == "station") - { - auto* s = new GeoLib::Station( - strtod(station_node->first_attribute("x")->value(), - nullptr), - strtod(station_node->first_attribute("y")->value(), - nullptr), - zVal, - station_name); - s->setStationValue(station_value); - if (!sensor_data_file_name.empty()) - { - s->addSensorDataFromCSV(BaseLib::copyPathToFileName( - sensor_data_file_name, file_name)); - } - stations->push_back(s); - } - else if (std::string(station_node->name()) == "borehole") - { - if (station_node->first_node("bdepth")) - { - borehole_depth = strtod( - station_node->first_node("bdepth")->value(), nullptr); - } - if (station_node->first_node("bdate")) - { - bdate_str = station_node->first_node("bdate")->value(); - } - /* add other borehole features here */ - - GeoLib::StationBorehole* s = - GeoLib::StationBorehole::createStation( - station_name, - strtod(station_node->first_attribute("x")->value(), - nullptr), - strtod(station_node->first_attribute("y")->value(), - nullptr), - zVal, - borehole_depth, - bdate_str); - s->setStationValue(station_value); - - if (station_node->first_node("strat")) - { - this->rapidReadStratigraphy( - station_node->first_node("strat"), s); - } - - stations->push_back(s); - } - } - else - WARN("XmlStnInterface::rapidReadStations(): Attribute missing in <station> tag."); - } -} - -void XmlStnInterface::rapidReadStratigraphy( const rapidxml::xml_node<>* strat_root, - GeoLib::StationBorehole* borehole ) -{ - double depth_check((*borehole)[2]); - - for (rapidxml::xml_node<>* horizon_node = strat_root->first_node("horizon"); horizon_node; - horizon_node = horizon_node->next_sibling()) - { - if (horizon_node->first_attribute("id") && horizon_node->first_attribute("x") && - horizon_node->first_attribute("y") && horizon_node->first_attribute("z")) - { - std::string horizon_name("[NN]"); - if (horizon_node->first_node("name")) - { - horizon_name = horizon_node->first_node("name")->value(); - } - /* add other horizon features here */ - - double depth( - strtod(horizon_node->first_attribute("z")->value(), nullptr)); - if (fabs(depth - depth_check) > std::numeric_limits<double>::epsilon()) // skip soil-layer if its thickness is zero - { - borehole->addSoilLayer( - strtod(horizon_node->first_attribute("x")->value(), - nullptr), - strtod(horizon_node->first_attribute("y")->value(), - nullptr), - depth, - horizon_name); - depth_check = depth; - } - else - WARN( - "XmlStnInterface::rapidReadStratigraphy(): Skipped layer " - "'%s' in borehole '%s' because of thickness 0.0.", - horizon_name.c_str(), - borehole->getName().c_str()); - } - else - WARN("XmlStnInterface::rapidReadStratigraphy(): Attribute missing in <horizon> tag."); - } -} - } // end namespace IO } // end namespace GeoLib diff --git a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.h b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.h index 93669a992375a5b7b49ec511c4dcd6ffa689e216..28e99ace701dba7f466ec43b51af8b674a3a09af 100644 --- a/GeoLib/IO/XmlIO/Qt/XmlStnInterface.h +++ b/GeoLib/IO/XmlIO/Qt/XmlStnInterface.h @@ -16,8 +16,6 @@ #include <vector> -#include "RapidXML/rapidxml.hpp" - #include "BaseLib/IO/XmlIO/XMLInterface.h" #include "BaseLib/IO/XmlIO/Qt/XMLQtInterface.h" @@ -64,12 +62,6 @@ private: /// Reads the stratigraphy of a borehole from an xml-file void readStratigraphy( const QDomNode &stratRoot, GeoLib::StationBorehole* borehole ); - /// Reads GeoLib::Station- or StationBorehole-objects from an xml-file using the RapidXML parser - void rapidReadStations(const rapidxml::xml_node<>* station_root, std::vector<GeoLib::Point*> *stations, const std::string &file_name); - - /// Reads the stratigraphy of a borehole from an xml-file using the RapidXML parser - void rapidReadStratigraphy(const rapidxml::xml_node<>* strat_root, GeoLib::StationBorehole* borehole); - GeoLib::GEOObjects& _geo_objs; }; diff --git a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp deleted file mode 100644 index e45cdbfb9a001614a70ab6f6c712ed197c0a0e6e..0000000000000000000000000000000000000000 --- a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-08-16 - * \brief Implementation of the RapidStnInterface class. - * - * \copyright - * Copyright (c) 2012-2019, 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 "RapidStnInterface.h" - -#include <fstream> - -#include "BaseLib/StringTools.h" -#include "BaseLib/FileTools.h" - -#include "GeoLib/Station.h" -#include "GeoLib/StationBorehole.h" - -namespace GeoLib -{ -namespace IO -{ - -std::vector<GeoLib::Point*> *RapidStnInterface::readStationFile(const std::string &fileName) -{ - std::ifstream in(fileName.c_str()); - if (in.fail()) - { - ERR("XmlStnInterface::rapidReadFile() - Can't open xml-file."); - return nullptr; - } - - // read the file in a buffer - std::stringstream sstr; - sstr << in.rdbuf(); - std::string buffer = sstr.str(); - in.close(); - - // build DOM tree - rapidxml::xml_document<> doc; - doc.parse<rapidxml::parse_non_destructive>( - const_cast<char*>(buffer.data())); - - // parse content - if (std::string(doc.first_node()->name()) != "OpenGeoSysSTN") - { - ERR("XmlStnInterface::readFile() - Unexpected XML root."); - return nullptr; - } - - auto* stations = new std::vector<GeoLib::Point*>; - - // iterate over all station lists - for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) - { - std::string stnName("[NN]"); - - stnName = station_list->first_node("name")->value(); - for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling()) - { - std::string b(list_item->name()); - if (b == "stations") - { - RapidStnInterface::readStations(list_item, stations, fileName); - } - if (b == "boreholes") - { - RapidStnInterface::readStations(list_item, stations, fileName); - } - } - } - - doc.clear(); - - return stations; -} -/* -int RapidStnInterface::rapidReadFile(const std::string &fileName) -{ - GEOLIB::GEOObjects* geoObjects = _project->getGEOObjects(); - - std::ifstream in(fileName.c_str()); - if (in.fail()) - { - ERR("XmlStnInterface::rapidReadFile() - Can't open xml-file."); - return 0; - } - - // buffer file - in.seekg(0, std::ios::end); - std::size_t length = in.tellg(); - in.seekg(0, std::ios::beg); - char* buffer = new char[length+1]; - in.read(buffer, length); - buffer[in.gcount()] = '\0'; - in.close(); - - // build DOM tree - rapidxml::xml_document<> doc; - doc.parse<0>(buffer); - - // parse content - if (std::string(doc.first_node()->name()).compare("OpenGeoSysSTN")) - { - ERR("XmlStnInterface::readFile() - Unexpected XML root."); - return 0; - } - - // iterate over all station lists - for (rapidxml::xml_node<>* station_list = doc.first_node()->first_node(); station_list; station_list = station_list->next_sibling()) - { - std::vector<GEOLIB::Point*>* stations = new std::vector<GEOLIB::Point*>; - std::string stnName("[NN]"); - - stnName = station_list->first_node("name")->value(); - for (rapidxml::xml_node<>* list_item = station_list->first_node(); list_item; list_item = list_item->next_sibling()) - { - std::string b(list_item->name()); - if (std::string(list_item->name()).compare("stations") == 0) - XmlStnInterface::rapidReadStations(list_item, stations, fileName); - if (std::string(list_item->name()).compare("boreholes") == 0) - XmlStnInterface::rapidReadStations(list_item, stations, fileName); - } - - if (!stations->empty()) - geoObjects->addStationVec(stations, stnName); - else - delete stations; - } - - doc.clear(); - delete [] buffer; - - return 1; -} -*/ -void RapidStnInterface::readStations(const rapidxml::xml_node<>* station_root, std::vector<GeoLib::Point*> *stations, const std::string &file_name) -{ - for (rapidxml::xml_node<>* station_node = station_root->first_node(); station_node; station_node = station_node->next_sibling()) - { - if (station_node->first_attribute("id") && station_node->first_attribute("x") && station_node->first_attribute("y")) - { - double zVal(0.0); - if (station_node->first_attribute("z")) - { - zVal = strtod(station_node->first_attribute("z")->value(), - nullptr); - } - - std::string station_name; - std::string sensor_data_file_name; - std::string bdate_str("0000-00-00"); - double station_value(0.0); - double borehole_depth(0.0); - if (station_node->first_node("name")) - { - station_name = station_node->first_node("name")->value(); - } - if (station_node->first_node("sensordata")) - { - sensor_data_file_name = - station_node->first_node("sensordata")->value(); - } - if (station_node->first_node("value")) - { - station_value = - strtod(station_node->first_node("value")->value(), nullptr); - } - /* add other station features here */ - - if (std::string(station_node->name()) == "station") - { - auto* s = new GeoLib::Station( - strtod(station_node->first_attribute("x")->value(), - nullptr), - strtod(station_node->first_attribute("y")->value(), - nullptr), - zVal, - station_name); - s->setStationValue(station_value); - if (!sensor_data_file_name.empty()) - { - s->addSensorDataFromCSV(BaseLib::copyPathToFileName( - sensor_data_file_name, file_name)); - } - stations->push_back(s); - } - else if (std::string(station_node->name()) == "borehole") - { - if (station_node->first_node("bdepth")) - { - borehole_depth = strtod( - station_node->first_node("bdepth")->value(), nullptr); - } - if (station_node->first_node("bdate")) - { - bdate_str = station_node->first_node("bdate")->value(); - } - /* add other borehole features here */ - - GeoLib::StationBorehole* s = - GeoLib::StationBorehole::createStation( - station_name, - strtod(station_node->first_attribute("x")->value(), - nullptr), - strtod(station_node->first_attribute("y")->value(), - nullptr), - zVal, - borehole_depth, - bdate_str); - s->setStationValue(station_value); - - if (station_node->first_node("strat")) - { - RapidStnInterface::readStratigraphy( - station_node->first_node("strat"), s); - } - - stations->push_back(s); - - } - } - else - { - ERR( - "XmlStnInterface::rapidReadStations() - Attribute missing in " - "<station> tag ..."); - } - } -} - -void RapidStnInterface::readStratigraphy( const rapidxml::xml_node<>* strat_root, GeoLib::StationBorehole* borehole ) -{ - double depth_check((*borehole)[2]); - - for (rapidxml::xml_node<>* horizon_node = strat_root->first_node("horizon"); horizon_node; horizon_node = horizon_node->next_sibling()) - { - if (horizon_node->first_attribute("id") && horizon_node->first_attribute("x") && - horizon_node->first_attribute("y") && horizon_node->first_attribute("z")) - { - std::string horizon_name("[NN]"); - if (horizon_node->first_node("name")) - { - horizon_name = horizon_node->first_node("name")->value(); - } - /* add other horizon features here */ - - double depth( - strtod(horizon_node->first_attribute("z")->value(), nullptr)); - if (fabs(depth - depth_check) > std::numeric_limits<double>::epsilon()) // skip soil-layer if its thickness is zero - { - borehole->addSoilLayer( - strtod(horizon_node->first_attribute("x")->value(), - nullptr), - strtod(horizon_node->first_attribute("y")->value(), - nullptr), - depth, - horizon_name); - depth_check = depth; - } - else - { - WARN( - "Warning: Skipped layer '%s' in borehole '%s' because " - "of thickness 0.0.", - horizon_name.c_str(), borehole->getName().c_str()); - } - } - else - { - WARN( - "XmlStnInterface::rapidReadStratigraphy() - Attribute missing " - "in <horizon> tag ..."); - } - } -} - -} // namespace IO -} // namespace GeoLib diff --git a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.h b/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.h deleted file mode 100644 index ab3e4bbf0e67957323e84967a7a448dbbdd846d0..0000000000000000000000000000000000000000 --- a/GeoLib/IO/XmlIO/Rapid/RapidStnInterface.h +++ /dev/null @@ -1,52 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2012-08-16 - * \brief Definition of RapidStnInterface class. - * - * \copyright - * Copyright (c) 2012-2019, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -#pragma once - -#include <string> -#include <vector> - -#include "RapidXML/rapidxml.hpp" - - -namespace GeoLib { - class Point; - class StationBorehole; -} - -namespace GeoLib -{ -namespace IO -{ - -/** - * \brief Base class for writing any information to and from XML files. - */ -class RapidStnInterface -{ -public: - /// Reads an xml-file using the RapidXML parser integrated in the source code (i.e. this function is usable without Qt) - //int rapidReadFile(const std::string &fileName); - static std::vector<GeoLib::Point*> *readStationFile(const std::string &fileName); - -private: - /// Reads GEOLIB::Station- or StationBorehole-objects from an xml-file using the RapidXML parser - static void readStations(const rapidxml::xml_node<>* station_root, std::vector<GeoLib::Point*> *stations, const std::string &file_name); - - /// Reads the stratigraphy of a borehole from an xml-file using the RapidXML parser - static void readStratigraphy(const rapidxml::xml_node<>* strat_root, GeoLib::StationBorehole* borehole); -}; - -} // namespace IO -} // namespace GeoLib