diff --git a/FileIO/XmlIO/XmlCndInterface.cpp b/FileIO/XmlIO/XmlCndInterface.cpp index a59d8521b38382900c940023bb724b17c0f6e587..7afc6d2fd7dbff990520ca8ce0f1fa748fa7144a 100644 --- a/FileIO/XmlIO/XmlCndInterface.cpp +++ b/FileIO/XmlIO/XmlCndInterface.cpp @@ -10,8 +10,8 @@ * Created on 2011-11-23 by Karsten Rink */ -#include "XmlCndInterface.h" #include "FEMCondition.h" +#include "XmlCndInterface.h" #include <QFile> #include <QTextCodec> @@ -20,9 +20,8 @@ #include <QStringList> namespace FileIO { - XmlCndInterface::XmlCndInterface(ProjectData* project, const std::string &schemaFile) -: XMLInterface(project, schemaFile), _type(FEMCondition::UNSPECIFIED) + : XMLInterface(project, schemaFile), _type(FEMCondition::UNSPECIFIED) { } @@ -31,7 +30,7 @@ int XmlCndInterface::readFile(std::vector<FEMCondition*> &conditions, const QStr QFile* file = new QFile(fileName); if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) { - std::cout << "XMLInterface::readFEMCondFile() - Can't open xml-file." << std::endl; + ERR("XMLInterface::readFEMCondFile(): Can't open xml-file %s.", fileName.data()); delete file; return 0; } @@ -46,7 +45,7 @@ int XmlCndInterface::readFile(std::vector<FEMCondition*> &conditions, const QStr QDomElement docElement = doc.documentElement(); //root element, used for identifying file-type if (docElement.nodeName().compare("OpenGeoSysCond")) { - std::cout << "XMLInterface::readFEMCondFile() - Unexpected XML root." << std::endl; + ERR("XMLInterface::readFEMCondFile(): Unexpected XML root."); delete file; return 0; } @@ -64,11 +63,10 @@ int XmlCndInterface::readFile(std::vector<FEMCondition*> &conditions, const QStr readConditions(list_node, conditions, FEMCondition::SOURCE_TERM); } if (!conditions.empty()) - return 1; //do something like _geoObjects->addStationVec(stations, stnName, color); + return 1; //do something like _geoObjects->addStationVec(stations, stnName, color); else { - std::cout << "XMLInterface::readFEMCondFile() - No FEM Conditions found..." << - std::endl; + WARN("XMLInterface::readFEMCondFile(): No FEM Conditions found."); return 0; } @@ -77,18 +75,17 @@ int XmlCndInterface::readFile(std::vector<FEMCondition*> &conditions, const QStr return 1; } -void XmlCndInterface::readConditions( const QDomNode &listRoot, - std::vector<FEMCondition*> &conditions, - FEMCondition::CondType type) +void XmlCndInterface::readConditions(const QDomNode &listRoot, + std::vector<FEMCondition*> &conditions, + FEMCondition::CondType type) { QDomElement cond = listRoot.firstChildElement(); while (!cond.isNull()) { std::string geometry_name ( cond.attribute("geometry").toStdString() ); if (this->_project->getGEOObjects()->exists(geometry_name) >= 0 || - this->_project->meshExists(geometry_name)) + this->_project->meshExists(geometry_name)) { - FEMCondition* c ( new FEMCondition(geometry_name, type) ); QDomNodeList condProperties = cond.childNodes(); @@ -155,7 +152,7 @@ void XmlCndInterface::readConditions( const QDomNode &listRoot, } } else - std::cout << "Error in XmlCndInterface::readConditions() - Distribution type not supported." << std::endl; + ERR("XmlCndInterface::readConditions(): Distribution type not supported."); c->setDisValues(disNodes, disValues); } } @@ -165,7 +162,7 @@ void XmlCndInterface::readConditions( const QDomNode &listRoot, } else { - std::cout << "Error loading FEM Conditions: No geometry \"" << geometry_name << "\" found." << std::endl; + ERR("XmlCndInterface::readConditions(): No geometry \"%s\" found.", geometry_name.c_str()); } cond = cond.nextSiblingElement(); } @@ -182,15 +179,18 @@ int XmlCndInterface::write(std::ostream& stream) root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); root.setAttribute( "xsi:noNamespaceSchemaLocation", "http://141.65.34.25/OpenGeoSysCND.xsd" ); - const std::vector<FEMCondition*> conditions (_project->getConditions(FiniteElement::INVALID_PROCESS, _exportName, _type) ); + const std::vector<FEMCondition*> conditions (_project->getConditions( + FiniteElement::INVALID_PROCESS, + _exportName, + _type) ); - if (conditions.empty()) return 1; + if (conditions.empty()) + return 1; doc.appendChild(root); - size_t nConditions (conditions.size()); - for (size_t i=0; i<nConditions; i++) + for (size_t i = 0; i < nConditions; i++) { FEMCondition::CondType current_type = conditions[i]->getCondType(); if (current_type == _type || _type == FEMCondition::UNSPECIFIED) @@ -215,10 +215,14 @@ int XmlCndInterface::write(std::ostream& stream) } else { - std::cout << "Error in XmlCndInterface::writeFile() - Unspecified FEMConditions found ... Abort writing." << std::endl; + ERR("XmlCndInterface::writeFile(): Unspecified FEMConditions found ... Abort writing."); return 0; } - this->writeCondition(doc, listTag, conditions[i], condText, QString::fromStdString(_exportName)); + this->writeCondition(doc, + listTag, + conditions[i], + condText, + QString::fromStdString(_exportName)); } } std::string xml = doc.toString().toStdString(); @@ -227,13 +231,16 @@ int XmlCndInterface::write(std::ostream& stream) return 1; } -void XmlCndInterface::writeCondition( QDomDocument doc, QDomElement &listTag, const FEMCondition* cond, const QString &condText, const QString &geometryName) const +void XmlCndInterface::writeCondition(QDomDocument doc, QDomElement &listTag, + const FEMCondition* cond, const QString &condText, + const QString &geometryName) const { QString geoName (QString::fromStdString(cond->getAssociatedGeometryName())); - if ((geometryName.length()>0) && (geoName.compare(geometryName) != 0)) + if ((geometryName.length() > 0) && (geoName.compare(geometryName) != 0)) { - std::cout << "Geometry name not matching, skipping condition \"" << cond->getGeoName() << "\"..." << std::endl; + WARN("XmlCndInterface::writeCondition(): Geometry name not matching, skipping condition \"%s\".", + cond->getGeoName().c_str()); return; } @@ -277,30 +284,30 @@ void XmlCndInterface::writeCondition( QDomDocument doc, QDomElement &listTag, co QDomElement disValueTag ( doc.createElement("Value") ); disTag.appendChild(disValueTag); /* - if (cond->getProcessDistributionType() != FiniteElement::DIRECT) - { - double dis_value (cond->getDisValue()[0]); //TODO: do this correctly! - disValueText = doc.createTextNode(QString::number(dis_value)); - } - else - disValueText = doc.createTextNode(QString::fromStdString(cond->getDirectFileName())); - */ + if (cond->getProcessDistributionType() != FiniteElement::DIRECT) + { + double dis_value (cond->getDisValue()[0]); //TODO: do this correctly! + disValueText = doc.createTextNode(QString::number(dis_value)); + } + else + disValueText = doc.createTextNode(QString::fromStdString(cond->getDirectFileName())); + */ const std::vector<size_t> dis_nodes = cond->getDisNodes(); const std::vector<double> dis_values = cond->getDisValues(); const size_t nNodes = dis_nodes.size(); const size_t nValues = dis_values.size(); std::stringstream ss; - if (nNodes==0 && nValues==1) // CONSTANT + if (nNodes == 0 && nValues == 1) // CONSTANT ss << dis_values[0]; - else if ((nValues>0) && (nValues==nNodes)) // LINEAR && DIRECT + else if ((nValues > 0) && (nValues == nNodes)) // LINEAR && DIRECT { ss << "\n\t"; - for (size_t i=0; i<nValues; i++) + for (size_t i = 0; i < nValues; i++) ss << dis_nodes[i] << "\t" << dis_values[i] << "\n\t"; } else { - std::cout << "Error in XmlCndInterface::writeCondition() - Inconsistent length of distribution value array." << std::endl; + ERR("XmlCndInterface::writeCondition(): Inconsistent length of distribution value array."); ss << "-9999"; } std::string dv = ss.str(); @@ -308,16 +315,15 @@ void XmlCndInterface::writeCondition( QDomDocument doc, QDomElement &listTag, co disValueTag.appendChild(disValueText); } -QDomElement XmlCndInterface::getCondListElement( QDomDocument doc, QDomElement &root, const QString &text ) const +QDomElement XmlCndInterface::getCondListElement(QDomDocument doc, QDomElement &root, + const QString &text) const { QDomNodeList list = root.elementsByTagName(text); - if (list.isEmpty()) - { - QDomElement newListTag ( doc.createElement(text) ); + if (list.isEmpty()) { + QDomElement newListTag(doc.createElement(text)); root.appendChild(newListTag); return newListTag; } return list.at(0).toElement(); } - } diff --git a/FileIO/XmlIO/XmlCndInterface.h b/FileIO/XmlIO/XmlCndInterface.h index f79423dc6589812ea7dbe3f734115e2b75f62fa8..37cd0c0fc07865f5642fcb0ebd466e041eae3ded 100644 --- a/FileIO/XmlIO/XmlCndInterface.h +++ b/FileIO/XmlIO/XmlCndInterface.h @@ -15,11 +15,13 @@ #include "XMLInterface.h" +// ThirdParty/logog +#include "logog/include/logog.hpp" + class FEMCondition; namespace FileIO { - /** * \brief Reads and writes FEM Conditions to and from XML files. */ @@ -33,13 +35,13 @@ public: */ XmlCndInterface(ProjectData* project, const std::string &schemaFile); - ~XmlCndInterface() {}; + ~XmlCndInterface() {} /// Dummy function so class hierarchy works. This needs to be implemented later. int readFile(const QString &fileName) { Q_UNUSED(fileName) - std::cout << "There is currently no implementation for XmlCndInterface::readFile(const QString&)." << std::endl; + INFO("There is currently no implementation for XmlCndInterface::readFile(const QString&)."); return 0; } @@ -54,16 +56,16 @@ protected: private: /// Read the details of various FEM Conditions from an xml-file - void readConditions( const QDomNode &condRoot, - std::vector<FEMCondition*> &conditions, - FEMCondition::CondType type); + void readConditions(const QDomNode &condRoot, std::vector<FEMCondition*> &conditions, + FEMCondition::CondType type); - QDomElement getCondListElement( QDomDocument doc, QDomElement &root, const QString &condText ) const; - void writeCondition( QDomDocument doc, QDomElement &listTag, const FEMCondition* cond, const QString &condText, const QString &geoName ) const; + QDomElement getCondListElement(QDomDocument doc, QDomElement &root, + const QString &condText) const; + void writeCondition(QDomDocument doc, QDomElement &listTag, const FEMCondition* cond, + const QString &condText, const QString &geoName) const; FEMCondition::CondType _type; }; - } #endif // XMLCNDINTERFACE_H