17#include <boost/property_tree/xml_parser.hpp>
34 : _geo_objects(geo_objs)
44 doc.ignoreConfigAttribute(
"xmlns:xsi");
45 doc.ignoreConfigAttribute(
"xsi:noNamespaceSchemaLocation");
46 doc.ignoreConfigAttribute(
"xmlns:ogs");
49 auto geo_name = doc.getConfigParameter<std::string>(
"name");
52 OGS_FATAL(
"BoostXmlGmlInterface::readFile(): <name> tag is empty.");
56 for (
auto st : doc.getConfigSubtreeList(
"points"))
58 std::vector<GeoLib::Point*> points;
62 std::move(pnt_names));
65 std::vector<GeoLib::Polyline*> polylines;
68 for (
auto st : doc.getConfigSubtreeList(
"polylines"))
77 std::vector<GeoLib::Surface*> surfaces;
81 for (
auto st : doc.getConfigSubtreeList(
"surfaces"))
88 if (!polylines.empty())
91 std::move(ply_names));
94 if (!surfaces.empty())
97 std::move(sfc_names));
105 std::vector<GeoLib::Point*>& points,
106 std::map<std::string, std::size_t>& pnt_names)
112 auto const p_id = pt.getConfigAttribute<std::size_t>(
"id");
114 auto const p_x = pt.getConfigAttribute<
double>(
"x");
116 auto const p_y = pt.getConfigAttribute<
double>(
"y");
118 auto const p_z = pt.getConfigAttribute<
double>(
"z");
120 auto const p_size = points.size();
122 "The point id is not unique.");
125 if (
auto const p_name =
127 pt.getConfigAttributeOptional<std::string>(
"name"))
131 OGS_FATAL(
"Empty point name found in geometry file.");
135 pnt_names, *p_name, p_size,
"The point name is not unique.");
142 std::vector<GeoLib::Polyline*>& polylines,
143 std::vector<GeoLib::Point*>
const& points,
144 std::vector<std::size_t>
const& pnt_id_map,
145 std::map<std::string, std::size_t>& ply_names)
151 auto const id = pl.getConfigAttribute<std::size_t>(
"id");
158 if (
auto const p_name =
160 pl.getConfigAttributeOptional<std::string>(
"name"))
164 OGS_FATAL(
"Empty polyline name found in geometry file.");
168 ply_names, *p_name, polylines.size() - 1,
169 "The polyline name is not unique.");
171 auto accessOrError = [
this, &p_name](
auto pt_idx)
173 auto search =
_idx_map.find(pt_idx);
177 "Polyline `{:s}' contains the point id `{:d}', but the "
178 "id is not in the point list.",
179 p_name->c_str(), pt_idx);
181 return search->second;
185 for (
auto const pt : pl.getConfigParameterList<std::size_t>(
"pnt"))
187 polylines.back()->addPoint(pnt_id_map[accessOrError(pt)]);
193 pl.ignoreConfigParameterAll(
"pnt");
195 "Polyline name is required! Polylines without a name are "
203 std::vector<GeoLib::Surface*>& surfaces,
204 std::vector<GeoLib::Point*>
const& points,
205 const std::vector<std::size_t>& pnt_id_map,
206 std::map<std::string, std::size_t>& sfc_names)
212 auto const id = sfc.getConfigAttribute<std::size_t>(
"id");
218 if (
auto const s_name =
220 sfc.getConfigAttributeOptional<std::string>(
"name"))
224 OGS_FATAL(
"Empty surface name found in geometry file.");
228 sfc_names, *s_name, surfaces.size() - 1,
229 "The surface name is not unique.");
232 for (
auto const& element : sfc.getConfigParameterList(
"element"))
236 element.getConfigAttribute<std::size_t>(
"p1");
239 element.getConfigAttribute<std::size_t>(
"p2");
242 element.getConfigAttribute<std::size_t>(
"p3");
244 auto accessOrError = [
this, &s_name](std::size_t pt_idx)
246 auto search =
_idx_map.find(pt_idx);
250 "The element list of the surface `{:s}' contains "
251 "the invalid point id `{:d}'.",
252 s_name->c_str(), pt_idx);
254 return search->second;
257 auto const p1 = pnt_id_map[accessOrError(p1_attr)];
258 auto const p2 = pnt_id_map[accessOrError(p2_attr)];
259 auto const p3 = pnt_id_map[accessOrError(p3_attr)];
260 surfaces.back()->addTriangle(p1, p2, p3);
266 sfc.ignoreConfigParameterAll(
"element");
275 ERR(
"BoostXmlGmlInterface::write(): No geometry specified.");
283 ERR(
"BoostXmlGmlInterface::write(): No PointVec within the geometry "
292 ERR(
"BoostXmlGmlInterface::write(): No points within the geometry "
299 boost::property_tree::ptree pt;
302 pt.put(
"<xmlattr>.xmlns:xsi",
"http://www.w3.org/2001/XMLSchema-instance");
303 pt.put(
"<xmlattr>.xmlns:ogs",
"https://www.opengeosys.org");
304 auto& geometry_set = pt.add(
"OpenGeoSysGLI",
"");
307 auto& pnts_tag = geometry_set.add(
"points",
"");
308 for (std::size_t k(0); k < pnts.size(); k++)
310 auto& pnt_tag = pnts_tag.add(
"point",
"");
311 pnt_tag.put(
"<xmlattr>.id", k);
312 pnt_tag.put(
"<xmlattr>.x", (*pnts[k])[0]);
313 pnt_tag.put(
"<xmlattr>.y", (*pnts[k])[1]);
314 pnt_tag.put(
"<xmlattr>.z", (*pnts[k])[2]);
316 if (!point_name.empty())
318 pnt_tag.put(
"<xmlattr>.name", point_name);
325 boost::property_tree::xml_writer_settings<std::string> settings(
'\t', 1);
326 write_xml(
out, pt, settings);
331 boost::property_tree::ptree& geometry_set)
338 "BoostXmlGmlInterface::addSurfacesToPropertyTree(): No surfaces "
339 "within the geometry '{:s}'.",
344 auto const& surfaces(sfc_vec->
getVector());
345 if (surfaces.empty())
348 "BoostXmlGmlInterface::addSurfacesToPropertyTree(): No surfaces "
349 "within the geometry '{:s}'.",
354 auto& surfaces_tag = geometry_set.add(
"surfaces",
"");
355 for (std::size_t i = 0; i < surfaces.size(); ++i)
358 std::string sfc_name;
360 auto& surface_tag = surfaces_tag.add(
"surface",
"");
361 surface_tag.put(
"<xmlattr>.id", i);
362 if (!sfc_name.empty())
364 surface_tag.put(
"<xmlattr>.name", sfc_name);
368 auto& element_tag = surface_tag.add(
"element",
"");
369 element_tag.put(
"<xmlattr>.p1", (*(*surface)[j])[0]);
370 element_tag.put(
"<xmlattr>.p2", (*(*surface)[j])[1]);
371 element_tag.put(
"<xmlattr>.p3", (*(*surface)[j])[2]);
377 boost::property_tree::ptree& geometry_set)
384 "BoostXmlGmlInterface::addPolylinesToPropertyTree(): No polylines "
385 "within the geometry '{:s}'.",
391 if (polylines.empty())
394 "BoostXmlGmlInterface::addPolylinesToPropertyTree(): No polylines "
395 "within the geometry '{:s}'.",
400 auto& polylines_tag = geometry_set.add(
"polylines",
"");
401 for (std::size_t i = 0; i < polylines.size(); ++i)
404 std::string ply_name;
406 auto& polyline_tag = polylines_tag.add(
"polyline",
"");
407 polyline_tag.put(
"<xmlattr>.id", i);
408 if (!ply_name.empty())
410 polyline_tag.put(
"<xmlattr>.name", ply_name);
414 polyline_tag.add(
"pnt", polyline->
getPointID(j));
Definition of the BoostXmlGmlInterface class.
Definition of the GEOObjects class.
Definition of the Point class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the PointVec class.
Definition of the PolyLine class.
Range< SubtreeIterator > getConfigSubtreeList(std::string const &root) const
Range< ValueIterator< T > > getConfigParameterList(std::string const ¶m) const
std::ostringstream out
The stream to write to.
Container class for geometric objects.
void addPolylineVec(std::vector< Polyline * > &&lines, std::string const &name, PolylineVec::NameIdMap &&ply_names)
const std::vector< Point * > * getPointVec(const std::string &name) const
void addPointVec(std::vector< Point * > &&points, std::string &name, PointVec::NameIdMap &&pnt_id_name_map, double const eps=std::sqrt(std::numeric_limits< double >::epsilon()))
const PointVec * getPointVecObj(const std::string &name) const
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
void addSurfaceVec(std::vector< Surface * > &&sfc, const std::string &name, SurfaceVec::NameIdMap &&sfc_names)
const PolylineVec * getPolylineVecObj(const std::string &name) const
bool write() override
Writes the object to the internal stream. This method must be implemented by a subclass....
GeoLib::GEOObjects & _geo_objects
void readPolylines(BaseLib::ConfigTree const &polylinesRoot, std::vector< GeoLib::Polyline * > &polylines, std::vector< GeoLib::Point * > const &points, const std::vector< std::size_t > &pnt_id_map, std::map< std::string, std::size_t > &ply_names)
Reads GeoLib::Polyline-objects from an xml-file.
void addPolylinesToPropertyTree(boost::property_tree::ptree &geometry_set)
void readPoints(BaseLib::ConfigTree const &pointsRoot, std::vector< GeoLib::Point * > &points, std::map< std::string, std::size_t > &pnt_names)
Reads GeoLib::Point-objects from an xml-file.
void readSurfaces(BaseLib::ConfigTree const &surfacesRoot, std::vector< GeoLib::Surface * > &surfaces, std::vector< GeoLib::Point * > const &points, const std::vector< std::size_t > &pnt_id_map, std::map< std::string, std::size_t > &sfc_names)
Reads GeoLib::Surface-objects from an xml-file.
bool readFile(const std::string &fname) override
Reads an xml-file containing OGS geometry.
void addSurfacesToPropertyTree(boost::property_tree::ptree &geometry_set)
std::map< std::size_t, std::size_t > _idx_map
BoostXmlGmlInterface(GeoLib::GEOObjects &geo_objs)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
const std::vector< std::size_t > & getIDMap() const
std::string const & getItemNameByID(std::size_t id) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
std::size_t getPointID(std::size_t const i) const
std::size_t getNumberOfPoints() const
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
std::size_t getNumberOfTriangles() const
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
std::map< std::string, std::size_t > NameIdMap
bool getNameOfElement(const T *data, std::string &name) const
std::vector< T * > const & getVector() const
ConfigTree makeConfigTreeFromFile(const std::string &filepath, const bool be_ruthless, const std::string &toplevel_tag)
void insertIfKeyUniqueElseError(Map &map, Key const &key, Value &&value, std::string const &error_message)