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(const std::string& name) const
108{
109 return _geo_objects.getPointVec(name);
110}
111
112void GEOModels::addPointVec(std::string const& name)
113{
114 _geoModel->addPointList(QString::fromStdString(name),
117}
118
119void GEOModels::removePointVec(std::string const& name)
120{
121 assert(!_geo_objects.isPntVecUsed(name));
122
125}
126
127void GEOModels::addStationVec(std::string const& name)
128{
129 _stationModel->addStationList(QString::fromStdString(name),
132}
133
134void GEOModels::removeStationVec(std::string const& name)
135{
138}
139
140void GEOModels::addPolylineVec(std::string const& name)
141{
142 _geoModel->addPolylineList(QString::fromStdString(name),
145}
146
147void GEOModels::appendPolylineVec(std::string const& name)
148{
149 this->_geoModel->appendPolylines(name,
151}
152
153void GEOModels::removePolylineVec(std::string const& name)
154{
157}
158
159void GEOModels::addSurfaceVec(std::string const& name)
160{
161 _geoModel->addSurfaceList(QString::fromStdString(name),
164}
165
166void GEOModels::appendSurfaceVec(std::string const& name)
167{
169}
170
171void GEOModels::removeSurfaceVec(std::string const& name)
172{
175}
176
177void GEOModels::renameGeometry(std::string const& old_name,
178 std::string const& new_name)
179{
180 _geoModel->renameGeometry(old_name, new_name);
181 updateGeometry(new_name);
182}
183
185 const std::string& geoName, std::vector<std::size_t> const& indexlist,
186 double const proximity, std::string const& ply_name, bool const closePly,
187 bool const triangulatePly)
188{
190
191 if (plyVec)
192 {
193 auto const& polylines = plyVec->getVector();
194 std::vector<GeoLib::Polyline*> ply_list;
195 std::transform(indexlist.begin(), indexlist.end(),
196 std::back_inserter(ply_list),
197 [polylines](auto const& ply_index)
198 { return polylines[ply_index]; });
199
200 // connect polylines
201 GeoLib::Polyline* new_line =
203 proximity);
204
205 if (new_line)
206 {
207 // insert result in a new vector of polylines (because the
208 // GEOObjects::appendPolylines()-method requires a vector)
209 std::vector<GeoLib::Polyline*> connected_ply;
210
211 connected_ply.push_back(new_line);
212 _geo_objects.appendPolylineVec(connected_ply, geoName);
213
214 if (closePly)
215 {
216 new_line->closePolyline();
217
218 if (triangulatePly)
219 {
220 INFO(
221 "Creating a surface by triangulation of the polyline "
222 "...");
223 if (auto sfc =
225 {
226 std::vector<GeoLib::Surface*> new_sfc;
227 new_sfc.push_back(sfc.release());
228 _geo_objects.appendSurfaceVec(new_sfc, geoName);
229 INFO("\t done");
230 }
231 else
232 {
233 WARN(
234 "\t Creating a surface by triangulation of the "
235 "polyline failed.");
236 }
237 plyVec = _geo_objects.getPolylineVecObj(geoName);
238 }
239 }
240
241 if (!ply_name.empty())
242 {
243 plyVec->setNameOfElementByID(polylines.size(), ply_name);
244 }
245 }
246 else
247 {
248 OGSError::box("Error connecting polyines.");
249 }
250 }
251 else
252 {
253 OGSError::box("Corresponding geometry not found.");
254 }
255}
256
257void GEOModels::addNameForElement(std::string const& geometry_name,
258 GeoLib::GEOTYPE const object_type,
259 std::size_t const id,
260 std::string const& new_name)
261{
262 if (object_type == GeoLib::GEOTYPE::POINT)
263 {
264 _geo_objects.getPointVecObj(geometry_name)
265 ->setNameForElement(id, new_name);
266 }
267 else if (object_type == GeoLib::GEOTYPE::POLYLINE)
268 {
269 _geo_objects.getPolylineVecObj(geometry_name)
270 ->setNameForElement(id, new_name);
271 }
272 else if (object_type == GeoLib::GEOTYPE::SURFACE)
273 {
274 _geo_objects.getSurfaceVecObj(geometry_name)
275 ->setNameForElement(id, new_name);
276 }
277 else
278 ERR("GEOModels::addNameForElement() - Unknown GEOTYPE {:s}.",
279 GeoLib::convertGeoTypeToString(object_type));
280}
281
282void GEOModels::addNameForObjectPoints(const std::string& geometry_name,
283 const GeoLib::GEOTYPE object_type,
284 const std::string& geo_object_name,
285 const std::string& new_name)
286{
287 const GeoLib::GeoObject* obj =
288 _geo_objects.getGeoObject(geometry_name, object_type, geo_object_name);
289 GeoLib::PointVec* pnt_vec = _geo_objects.getPointVecObj(geometry_name);
290 if (object_type == GeoLib::GEOTYPE::POLYLINE)
291 {
292 const auto* ply = dynamic_cast<const GeoLib::Polyline*>(obj);
293 std::size_t nPoints = ply->getNumberOfPoints();
294 for (std::size_t i = 0; i < nPoints; i++)
295 {
296 pnt_vec->setNameForElement(
297 ply->getPointID(i),
298 new_name + "_Point" + std::to_string(ply->getPointID(i)));
299 }
300 }
301 else if (object_type == GeoLib::GEOTYPE::SURFACE)
302 {
303 const auto* sfc = dynamic_cast<const GeoLib::Surface*>(obj);
304 std::size_t nTriangles = sfc->getNumberOfTriangles();
305 for (std::size_t i = 0; i < nTriangles; i++)
306 {
307 const GeoLib::Triangle* tri = (*sfc)[i];
308 pnt_vec->setNameForElement(
309 (*tri)[0], new_name + "_Point" + std::to_string((*tri)[0]));
310 pnt_vec->setNameForElement(
311 (*tri)[1], new_name + "_Point" + std::to_string((*tri)[1]));
312 pnt_vec->setNameForElement(
313 (*tri)[2], new_name + "_Point" + std::to_string((*tri)[2]));
314 }
315 }
316 else
317 ERR("GEOModels::addNameForObjectPoints() - Unknown GEOTYPE {:s}.",
318 GeoLib::convertGeoTypeToString(object_type));
319}
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
Definition: GEOModels.cpp:103
GeoLib::GEOObjects & _geo_objects
Definition: GEOModels.h:110
void stationVectorAdded(StationTreeModel *model, std::string name)
void addStationVec(std::string const &name)
Definition: GEOModels.cpp:127
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.
Definition: GEOModels.cpp:282
void appendSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:166
void renameGeometry(std::string const &old_name, std::string const &new_name)
Definition: GEOModels.cpp:177
void addSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:159
void removePointVec(std::string const &name)
Definition: GEOModels.cpp:119
void addPointVec(std::string const &name)
Definition: GEOModels.cpp:112
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)
Definition: GEOModels.cpp:134
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
const std::vector< GeoLib::Point * > * getPointVec(const std::string &name) const
Definition: GEOModels.cpp:107
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.
Definition: GEOModels.cpp:257
~GEOModels() override
Definition: GEOModels.cpp:34
void removePolylineVec(std::string const &name)
Definition: GEOModels.cpp:153
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)
Definition: GEOModels.cpp:184
void appendPolylineVec(std::string const &name)
Definition: GEOModels.cpp:147
void removeSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:171
virtual void removeGeometry(std::string const &geo_name, GeoLib::GEOTYPE const type)
Definition: GEOModels.cpp:86
void addPolylineVec(std::string const &name)
Definition: GEOModels.cpp:140
GeoTreeModel * _geoModel
Definition: GEOModels.h:106
Container class for geometric objects.
Definition: GEOObjects.h:61
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
Definition: GEOObjects.cpp:342
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:249
const std::vector< Point * > * getPointVec(const std::string &name) const
Definition: GEOObjects.cpp:72
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:85
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:98
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:283
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:211
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:298
bool isPntVecUsed(const std::string &name) const
Checks if the point vector with the given name is referenced in a polyline- or surface vector.
Definition: GEOObjects.cpp:324
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:206
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:171
const GeoLib::GeoObject * getGeoObject(const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &geo_obj_name) const
Returns the geo object for a geometric item of the given name and type for the associated geometry.
Definition: GEOObjects.cpp:659
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
Definition: GEOObjects.cpp:133
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:222
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition: PointVec.h:38
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:42
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
void closePolyline()
Definition: Polyline.cpp:302
A Surface is represented by Triangles. It consists of a reference to a vector of (pointers to) points...
Definition: Surface.h:34
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...
Definition: TemplateVec.h:41
void setNameOfElementByID(std::size_t id, std::string const &element_name)
Return the name of an element based on its ID.
Definition: TemplateVec.h:164
virtual void setNameForElement(std::size_t id, std::string const &name)
Sets the given name for the element of the given ID.
Definition: TemplateVec.h:215
std::vector< T * > const & getVector() const
Definition: TemplateVec.h:109
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26
A model for the GeoTreeView implementing a tree as a double-linked list.
Definition: GeoTreeModel.h:41
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)
GEOTYPE
Definition: GeoType.h:25
std::unique_ptr< GeoLib::Surface > createSurfaceWithEarClipping(GeoLib::Polyline const &line)
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition: GeoType.cpp:23