11 #include <QDomElement>
13 #include <QtXml/QDomDocument>
14 #include <boost/algorithm/string/trim.hpp>
30 std::ifstream in(filename.c_str());
33 ERR(
"FEFLOWGeoInterface::readFEFLOWFile(): Could not open file {:s}.",
38 unsigned dimension = 0;
39 std::vector<GeoLib::Point*>* points =
nullptr;
40 std::vector<GeoLib::Polyline*>* lines =
nullptr;
42 bool isXZplane =
false;
44 std::string line_string;
45 std::stringstream line_stream;
48 getline(in, line_string);
51 if (line_string.find(
"CLASS") != std::string::npos)
53 getline(in, line_string);
54 line_stream.str(line_string);
57 for (
int i = 0; i < 3; i++)
61 line_stream >> dimension;
66 else if (line_string ==
"GRAVITY")
68 getline(in, line_string);
69 line_stream.str(line_string);
71 line_stream >> vec[0] >> vec[1] >> vec[2];
72 if (vec[0] == 0.0 && vec[1] == -1.0 && vec[2] == 0.0)
81 else if (line_string ==
"SUPERMESH")
89 std::string project_name(
94 std::unique_ptr<std::vector<GeoLib::Point*>>(points), project_name);
99 std::unique_ptr<std::vector<GeoLib::Polyline*>>(lines),
103 if (isXZplane && points)
105 for (
auto* pt : *points)
114 const std::string& tag,
116 std::vector<GeoLib::Point*>& points)
119 nodesEle.firstChildElement(QString::fromStdString(tag));
124 QString str_pt_list1 = xmlEle.text();
125 std::istringstream ss(str_pt_list1.toStdString());
126 std::string line_str;
129 std::getline(ss, line_str);
130 boost::trim_right(line_str);
131 if (line_str.empty())
135 std::istringstream line_ss(line_str);
136 std::size_t pt_id = 0;
137 std::array<double, 3> pt_xyz;
139 for (
int i = 0; i < dim; i++)
141 line_ss >> pt_xyz[i];
149 std::vector<GeoLib::Point*>*& points,
150 std::vector<GeoLib::Polyline*>*& lines)
153 std::ostringstream oss;
154 std::string line_string;
157 getline(in, line_string);
159 oss << line_string <<
"\n";
160 if (line_string.find(
"</supermesh>") != std::string::npos)
165 const QString strXML(oss.str().c_str());
169 if (!doc.setContent(strXML))
171 ERR(
"FEFLOWGeoInterface::readSuperMesh(): Illegal XML format error");
176 QDomElement docElem = doc.documentElement();
178 points =
new std::vector<GeoLib::Point*>();
179 QDomElement nodesEle = docElem.firstChildElement(
"nodes");
180 if (nodesEle.isNull())
186 const QString str = nodesEle.attribute(
"count");
187 const long n_points = str.toLong();
188 points->resize(n_points);
190 readPoints(nodesEle,
"fixed", dimension, *points);
191 readPoints(nodesEle,
"linear", dimension, *points);
192 readPoints(nodesEle,
"parabolic", dimension, *points);
196 lines =
new std::vector<GeoLib::Polyline*>();
197 QDomElement polygonsEle = docElem.firstChildElement(
"polygons");
198 if (polygonsEle.isNull())
204 QDomNode child = polygonsEle.firstChild();
205 while (!child.isNull())
207 if (child.nodeName() !=
"polygon")
209 child = child.nextSibling();
212 QDomElement xmlEle = child.firstChildElement(
"nodes");
217 const QString str = xmlEle.attribute(
"count");
218 const std::size_t n_points = str.toLong();
219 QString str_ptId_list = xmlEle.text().simplified();
222 lines->push_back(line);
223 std::istringstream ss(str_ptId_list.toStdString());
224 for (std::size_t i = 0; i < n_points; i++)
228 line->addPoint(pt_id - 1);
230 line->addPoint(line->getPointID(0));
232 child = child.nextSibling();
Definition of the GEOObjects class.
Definition of the Point class.
void ERR(char const *fmt, Args const &... args)
Definition of the Polygon class.
static void readSuperMesh(std::ifstream &in, unsigned dimension, std::vector< GeoLib::Point * > *&points, std::vector< GeoLib::Polyline * > *&lines)
static void readPoints(QDomElement &nodesEle, const std::string &tag, int dim, std::vector< GeoLib::Point * > &points)
void readFEFLOWFile(const std::string &filename, GeoLib::GEOObjects &geo_objects)
Container class for geometric objects.
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
void trim(std::string &str, char ch)
std::string extractBaseNameWithoutExtension(std::string const &pathname)
TemplateElement< PointRule1 > Point