OGS
GEOModels.cpp
Go to the documentation of this file.
1
15// ** INCLUDES **
16#include "GEOModels.h"
17
19#include "Base/OGSError.h"
20#include "BaseLib/Logging.h"
21#include "GeoLib/Triangle.h"
22#include "GeoTreeModel.h"
23#include "StationTreeModel.h"
24
25GEOModels::GEOModels(GeoLib::GEOObjects& geo_objects, QObject* parent /*= 0*/)
26 : QObject(parent), _geo_objects(geo_objects)
27{
28 _geo_objects._callbacks = std::make_unique<GEOModelsCallbacks>(*this);
29
30 _geoModel = new GeoTreeModel();
32}
33
35{
36 delete _stationModel;
37 delete _geoModel;
38}
39
40void GEOModels::updateGeometry(const std::string& geo_name)
41{
42 if (auto const stations = _geo_objects.getStationVec(geo_name);
43 stations != nullptr)
44 {
45 emit stationVectorRemoved(_stationModel, geo_name);
47 _stationModel->addStationList(QString::fromStdString(geo_name),
48 stations);
49 emit stationVectorAdded(_stationModel, geo_name);
50 return;
51 }
52
53 if (auto const points = _geo_objects.getPointVecObj(geo_name);
54 points != nullptr)
55 {
58 _geoModel->addPointList(QString::fromStdString(geo_name), *points);
60
61 if (auto const lines = _geo_objects.getPolylineVecObj(geo_name);
62 lines != nullptr)
63 {
66 _geoModel->addPolylineList(QString::fromStdString(geo_name),
67 *lines);
69 }
70
71 if (auto const surfaces = _geo_objects.getSurfaceVecObj(geo_name);
72 surfaces != nullptr)
73 {
76 _geoModel->addSurfaceList(QString::fromStdString(geo_name),
77 *surfaces);
79 }
80 }
81 else
82 ERR("GEOModels::updateGeometry() - Geometry '{:s}' not found.",
83 geo_name);
84}
85
86void GEOModels::removeGeometry(std::string const& geo_name,
87 GeoLib::GEOTYPE const type)
88{
89 if (type == GeoLib::GEOTYPE::SURFACE)
90 {
92 }
93 if (type == GeoLib::GEOTYPE::POLYLINE)
94 {
96 }
97 if (type == GeoLib::GEOTYPE::POINT)
98 {
100 }
101}
102
103std::vector<std::string> GEOModels::getGeometryNames() const
104{
106}
107const std::vector<GeoLib::Point*>* GEOModels::getPointVec(
108 const std::string& name) const
109{
110 return _geo_objects.getPointVec(name);
111}
112
113void GEOModels::addPointVec(std::string const& name)
114{
115 _geoModel->addPointList(QString::fromStdString(name),
118}
119
120void GEOModels::removePointVec(std::string const& name)
121{
122 assert(!_geo_objects.isPntVecUsed(name));
123
126}
127
128void GEOModels::addStationVec(std::string const& name)
129{
130 _stationModel->addStationList(QString::fromStdString(name),
133}
134
135void GEOModels::removeStationVec(std::string const& name)
136{
139}
140
141void GEOModels::addPolylineVec(std::string const& name)
142{
143 _geoModel->addPolylineList(QString::fromStdString(name),
146}
147
148void GEOModels::appendPolylineVec(std::string const& name)
149{
150 this->_geoModel->appendPolylines(name,
152}
153
159
160void GEOModels::addSurfaceVec(std::string const& name)
161{
162 _geoModel->addSurfaceList(QString::fromStdString(name),
165}
166
167void GEOModels::appendSurfaceVec(std::string const& name)
168{
170}
171
177
178void GEOModels::renameGeometry(std::string const& old_name,
179 std::string const& new_name)
180{
181 _geoModel->renameGeometry(old_name, new_name);
182 updateGeometry(new_name);
183}
184
186 const std::string& geoName, std::vector<std::size_t> const& indexlist,
187 double const proximity, std::string const& ply_name, bool const closePly,
188 bool const triangulatePly)
189{
191
192 if (plyVec)
193 {
194 auto const& polylines = plyVec->getVector();
195 std::vector<GeoLib::Polyline*> ply_list;
196 std::transform(indexlist.begin(), indexlist.end(),
197 std::back_inserter(ply_list),
198 [polylines](auto const& ply_index)
199 { return polylines[ply_index]; });
200
201 // connect polylines
202 GeoLib::Polyline* new_line =
204 proximity);
205
206 if (new_line)
207 {
208 // insert result in a new vector of polylines (because the
209 // GEOObjects::appendPolylines()-method requires a vector)
210 std::vector<GeoLib::Polyline*> connected_ply;
211
212 connected_ply.push_back(new_line);
213 _geo_objects.appendPolylineVec(connected_ply, geoName);
214
215 if (closePly)
216 {
217 new_line->closePolyline();
218
219 if (triangulatePly)
220 {
221 INFO(
222 "Creating a surface by triangulation of the polyline "
223 "...");
224 if (auto sfc =
226 {
227 std::vector<GeoLib::Surface*> new_sfc;
228 new_sfc.push_back(sfc.release());
229 _geo_objects.appendSurfaceVec(new_sfc, geoName);
230 INFO("\t done");
231 }
232 else
233 {
234 WARN(
235 "\t Creating a surface by triangulation of the "
236 "polyline failed.");
237 }
238 plyVec = _geo_objects.getPolylineVecObj(geoName);
239 }
240 }
241
242 if (!ply_name.empty())
243 {
244 plyVec->setNameOfElementByID(polylines.size(), ply_name);
245 }
246 }
247 else
248 {
249 OGSError::box("Error connecting polyines.");
250 }
251 }
252 else
253 {
254 OGSError::box("Corresponding geometry not found.");
255 }
256}
257
258void GEOModels::addNameForElement(std::string const& geometry_name,
259 GeoLib::GEOTYPE const object_type,
260 std::size_t const id,
261 std::string const& new_name)
262{
263 if (object_type == GeoLib::GEOTYPE::POINT)
264 {
265 _geo_objects.getPointVecObj(geometry_name)
266 ->setNameForElement(id, new_name);
267 }
268 else if (object_type == GeoLib::GEOTYPE::POLYLINE)
269 {
270 _geo_objects.getPolylineVecObj(geometry_name)
271 ->setNameForElement(id, new_name);
272 }
273 else if (object_type == GeoLib::GEOTYPE::SURFACE)
274 {
275 _geo_objects.getSurfaceVecObj(geometry_name)
276 ->setNameForElement(id, new_name);
277 }
278 else
279 ERR("GEOModels::addNameForElement() - Unknown GEOTYPE {:s}.",
280 GeoLib::convertGeoTypeToString(object_type));
281}
282
283void GEOModels::addNameForObjectPoints(const std::string& geometry_name,
284 const GeoLib::GEOTYPE object_type,
285 const std::string& geo_object_name,
286 const std::string& new_name)
287{
288 const GeoLib::GeoObject* obj =
289 _geo_objects.getGeoObject(geometry_name, object_type, geo_object_name);
290 GeoLib::PointVec* pnt_vec = _geo_objects.getPointVecObj(geometry_name);
291 if (object_type == GeoLib::GEOTYPE::POLYLINE)
292 {
293 const auto* ply = dynamic_cast<const GeoLib::Polyline*>(obj);
294 std::size_t nPoints = ply->getNumberOfPoints();
295 for (std::size_t i = 0; i < nPoints; i++)
296 {
297 pnt_vec->setNameForElement(
298 ply->getPointID(i),
299 new_name + "_Point" + std::to_string(ply->getPointID(i)));
300 }
301 }
302 else if (object_type == GeoLib::GEOTYPE::SURFACE)
303 {
304 const auto* sfc = dynamic_cast<const GeoLib::Surface*>(obj);
305 std::size_t nTriangles = sfc->getNumberOfTriangles();
306 for (std::size_t i = 0; i < nTriangles; i++)
307 {
308 const GeoLib::Triangle* tri = (*sfc)[i];
309 pnt_vec->setNameForElement(
310 (*tri)[0], new_name + "_Point" + std::to_string((*tri)[0]));
311 pnt_vec->setNameForElement(
312 (*tri)[1], new_name + "_Point" + std::to_string((*tri)[1]));
313 pnt_vec->setNameForElement(
314 (*tri)[2], new_name + "_Point" + std::to_string((*tri)[2]));
315 }
316 }
317 else
318 ERR("GEOModels::addNameForObjectPoints() - Unknown GEOTYPE {:s}.",
319 GeoLib::convertGeoTypeToString(object_type));
320}
Definition of the GEOModels class.
Definition of the GeoTreeModel class.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Definition of the OGSError class.
Definition of the StationTreeModel class.
std::vector< std::string > getGeometryNames() const
GeoLib::GEOObjects & _geo_objects
Definition GEOModels.h:110
void stationVectorAdded(StationTreeModel *model, std::string name)
void addStationVec(std::string const &name)
void addNameForObjectPoints(const std::string &geometry_name, const GeoLib::GEOTYPE object_type, const std::string &geo_object_name, const std::string &new_name)
Adds a generic name to all points that are part of the specified geo-object.
void appendSurfaceVec(std::string const &name)
void renameGeometry(std::string const &old_name, std::string const &new_name)
void addSurfaceVec(std::string const &name)
void removePointVec(std::string const &name)
void addPointVec(std::string const &name)
StationTreeModel * _stationModel
Definition GEOModels.h:107
void stationVectorRemoved(StationTreeModel *model, std::string name)
void geoDataAdded(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
void removeStationVec(std::string const &name)
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
const std::vector< GeoLib::Point * > * getPointVec(const std::string &name) const
void updateGeometry(const std::string &geo_name)
Definition GEOModels.cpp:40
void addNameForElement(std::string const &geometry_name, GeoLib::GEOTYPE const object_type, std::size_t const id, std::string const &new_name)
Adds the name 'new_name' for the geo-object specified by the parameters.
~GEOModels() override
Definition GEOModels.cpp:34
void removePolylineVec(std::string const &name)
GEOModels(GeoLib::GEOObjects &geo_objects, QObject *parent=nullptr)
Definition GEOModels.cpp:25
void connectPolylineSegments(const std::string &geoName, std::vector< std::size_t > const &indexlist, double const proximity, std::string const &ply_name, bool const closePly, bool const triangulatePly)
void appendPolylineVec(std::string const &name)
void removeSurfaceVec(std::string const &name)
virtual void removeGeometry(std::string const &geo_name, GeoLib::GEOTYPE const type)
Definition GEOModels.cpp:86
void addPolylineVec(std::string const &name)
GeoTreeModel * _geoModel
Definition GEOModels.h:106
Container class for geometric objects.
Definition GEOObjects.h:57
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
const std::vector< Point * > * getPointVec(const std::string &name) const
const PointVec * getPointVecObj(const std::string &name) const
bool removePointVec(const std::string &name)
bool removeSurfaceVec(const std::string &name)
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition GEOObjects.h:208
std::unique_ptr< Callbacks > _callbacks
Definition GEOObjects.h:303
bool isPntVecUsed(const std::string &name) const
const PolylineVec * getPolylineVecObj(const std::string &name) const
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
const GeoLib::GeoObject * getGeoObject(const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &geo_obj_name) const
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
bool removePolylineVec(const std::string &name)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition PointVec.h:36
void setNameForElement(std::size_t id, std::string const &name) override
Sets the given name for the element of the given ID.
Definition PointVec.cpp:253
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition Polyline.cpp:190
std::size_t getNumberOfPoints() const
Definition Polyline.cpp:109
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition Surface.h:33
std::size_t getNumberOfTriangles() const
Definition Surface.cpp:82
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
void setNameOfElementByID(std::size_t id, std::string const &element_name)
Return the name of an element based on its ID.
virtual void setNameForElement(std::size_t id, std::string const &name)
Sets the given name for the element of the given ID.
std::vector< T * > const & getVector() const
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition Triangle.h:27
A model for the GeoTreeView implementing a tree as a double-linked list.
void appendPolylines(const std::string &name, GeoLib::PolylineVec const &polylineVec)
Appends polylines to the "Polyline"-subtree.
void addSurfaceList(QString geoName, GeoLib::SurfaceVec const &surfaceVec)
Adds a subtree "Surfaces" to an existing geometry with the given name.
void addPointList(QString geoName, GeoLib::PointVec const &pointVec)
void renameGeometry(std::string const &old_name, std::string const &new_name)
void appendSurfaces(const std::string &name, GeoLib::SurfaceVec const &surfaceVec)
Appends surfaces to the "Surface"-subtree.
void addPolylineList(QString geoName, GeoLib::PolylineVec const &polylineVec)
Adds a subtree "Polylines" to an existing geometry with the given name.
void removeGeoList(const std::string &name, GeoLib::GEOTYPE type)
static void box(const QString &e)
Definition OGSError.cpp:23
A model for the StationTreeView implementing a tree as a double-linked list.
void addStationList(QString listName, const std::vector< GeoLib::Point * > *stations)
void removeStationList(QModelIndex index)
std::unique_ptr< GeoLib::Surface > createSurfaceWithEarClipping(GeoLib::Polyline const &line)
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition GeoType.cpp:23
GEOTYPE
Definition GeoType.h:23