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 
25 GEOModels::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 
40 void 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 
86 void 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  {
99  _geo_objects.removePointVec(geo_name);
100  }
101 }
102 
103 void GEOModels::addPointVec(std::string const& name)
104 {
105  _geoModel->addPointList(QString::fromStdString(name),
108 }
109 
110 void GEOModels::removePointVec(std::string const& name)
111 {
112  assert(!_geo_objects.isPntVecUsed(name));
113 
116 }
117 
118 void GEOModels::addStationVec(std::string const& name)
119 {
120  _stationModel->addStationList(QString::fromStdString(name),
123 }
124 
125 void GEOModels::removeStationVec(std::string const& name)
126 {
129 }
130 
131 void GEOModels::addPolylineVec(std::string const& name)
132 {
133  _geoModel->addPolylineList(QString::fromStdString(name),
136 }
137 
138 void GEOModels::appendPolylineVec(std::string const& name)
139 {
140  this->_geoModel->appendPolylines(name,
142 }
143 
144 void GEOModels::removePolylineVec(std::string const& name)
145 {
148 }
149 
150 void GEOModels::addSurfaceVec(std::string const& name)
151 {
152  _geoModel->addSurfaceList(QString::fromStdString(name),
155 }
156 
157 void GEOModels::appendSurfaceVec(std::string const& name)
158 {
160 }
161 
162 void GEOModels::removeSurfaceVec(std::string const& name)
163 {
166 }
167 
168 void GEOModels::renameGeometry(std::string const& old_name,
169  std::string const& new_name)
170 {
171  _geoModel->renameGeometry(old_name, new_name);
172  updateGeometry(new_name);
173 }
174 
176  const std::string& geoName, std::vector<std::size_t> const& indexlist,
177  double const proximity, std::string const& ply_name, bool const closePly,
178  bool const triangulatePly)
179 {
181 
182  if (plyVec)
183  {
184  auto const& polylines = plyVec->getVector();
185  std::vector<GeoLib::Polyline*> ply_list;
186  std::transform(indexlist.begin(), indexlist.end(),
187  std::back_inserter(ply_list),
188  [polylines](auto const& ply_index)
189  { return polylines[ply_index]; });
190 
191  // connect polylines
192  GeoLib::Polyline* new_line =
194  proximity);
195 
196  if (new_line)
197  {
198  // insert result in a new vector of polylines (because the
199  // GEOObjects::appendPolylines()-method requires a vector)
200  std::vector<GeoLib::Polyline*> connected_ply;
201 
202  connected_ply.push_back(new_line);
203  _geo_objects.appendPolylineVec(connected_ply, geoName);
204 
205  if (closePly)
206  {
207  new_line->closePolyline();
208 
209  if (triangulatePly)
210  {
211  INFO(
212  "Creating a surface by triangulation of the polyline "
213  "...");
214  if (auto sfc =
216  {
217  std::vector<GeoLib::Surface*> new_sfc;
218  new_sfc.push_back(sfc.release());
219  _geo_objects.appendSurfaceVec(new_sfc, geoName);
220  INFO("\t done");
221  }
222  else
223  {
224  WARN(
225  "\t Creating a surface by triangulation of the "
226  "polyline failed.");
227  }
228  plyVec = _geo_objects.getPolylineVecObj(geoName);
229  }
230  }
231 
232  if (!ply_name.empty())
233  {
234  plyVec->setNameOfElementByID(polylines.size(), ply_name);
235  }
236  }
237  else
238  {
239  OGSError::box("Error connecting polyines.");
240  }
241  }
242  else
243  {
244  OGSError::box("Corresponding geometry not found.");
245  }
246 }
247 
248 void GEOModels::addNameForElement(std::string const& geometry_name,
249  GeoLib::GEOTYPE const object_type,
250  std::size_t const id,
251  std::string const& new_name)
252 {
253  if (object_type == GeoLib::GEOTYPE::POINT)
254  {
255  _geo_objects.getPointVecObj(geometry_name)
256  ->setNameForElement(id, new_name);
257  }
258  else if (object_type == GeoLib::GEOTYPE::POLYLINE)
259  {
260  _geo_objects.getPolylineVecObj(geometry_name)
261  ->setNameForElement(id, new_name);
262  }
263  else if (object_type == GeoLib::GEOTYPE::SURFACE)
264  {
265  _geo_objects.getSurfaceVecObj(geometry_name)
266  ->setNameForElement(id, new_name);
267  }
268  else
269  ERR("GEOModels::addNameForElement() - Unknown GEOTYPE {:s}.",
270  GeoLib::convertGeoTypeToString(object_type));
271 }
272 
273 void GEOModels::addNameForObjectPoints(const std::string& geometry_name,
274  const GeoLib::GEOTYPE object_type,
275  const std::string& geo_object_name,
276  const std::string& new_name)
277 {
278  const GeoLib::GeoObject* obj =
279  _geo_objects.getGeoObject(geometry_name, object_type, geo_object_name);
280  GeoLib::PointVec* pnt_vec = _geo_objects.getPointVecObj(geometry_name);
281  if (object_type == GeoLib::GEOTYPE::POLYLINE)
282  {
283  const auto* ply = dynamic_cast<const GeoLib::Polyline*>(obj);
284  std::size_t nPoints = ply->getNumberOfPoints();
285  for (std::size_t i = 0; i < nPoints; i++)
286  {
287  pnt_vec->setNameForElement(
288  ply->getPointID(i),
289  new_name + "_Point" + std::to_string(ply->getPointID(i)));
290  }
291  }
292  else if (object_type == GeoLib::GEOTYPE::SURFACE)
293  {
294  const auto* sfc = dynamic_cast<const GeoLib::Surface*>(obj);
295  std::size_t nTriangles = sfc->getNumberOfTriangles();
296  for (std::size_t i = 0; i < nTriangles; i++)
297  {
298  const GeoLib::Triangle* tri = (*sfc)[i];
299  pnt_vec->setNameForElement(
300  (*tri)[0], new_name + "_Point" + std::to_string((*tri)[0]));
301  pnt_vec->setNameForElement(
302  (*tri)[1], new_name + "_Point" + std::to_string((*tri)[1]));
303  pnt_vec->setNameForElement(
304  (*tri)[2], new_name + "_Point" + std::to_string((*tri)[2]));
305  }
306  }
307  else
308  ERR("GEOModels::addNameForObjectPoints() - Unknown GEOTYPE {:s}.",
309  GeoLib::convertGeoTypeToString(object_type));
310 }
Definition of the GEOModels class.
Definition of the GeoTreeModel class.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of the OGSError class.
Definition of the StationTreeModel class.
GeoLib::GEOObjects & _geo_objects
Definition: GEOModels.h:106
void stationVectorAdded(StationTreeModel *model, std::string name)
void addStationVec(std::string const &name)
Definition: GEOModels.cpp:118
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:273
void appendSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:157
void renameGeometry(std::string const &old_name, std::string const &new_name)
Definition: GEOModels.cpp:168
void addSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:150
void removePointVec(std::string const &name)
Definition: GEOModels.cpp:110
void addPointVec(std::string const &name)
Definition: GEOModels.cpp:103
StationTreeModel * _stationModel
Definition: GEOModels.h:103
void stationVectorRemoved(StationTreeModel *model, std::string name)
void geoDataAdded(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
void removeStationVec(std::string const &name)
Definition: GEOModels.cpp:125
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
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:248
~GEOModels() override
Definition: GEOModels.cpp:34
void removePolylineVec(std::string const &name)
Definition: GEOModels.cpp:144
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:175
void appendPolylineVec(std::string const &name)
Definition: GEOModels.cpp:138
void removeSurfaceVec(std::string const &name)
Definition: GEOModels.cpp:162
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:131
GeoTreeModel * _geoModel
Definition: GEOModels.h:102
Container class for geometric objects.
Definition: GEOObjects.h:61
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:249
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
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:298
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:211
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:663
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:53
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition: Polyline.cpp:197
std::size_t getNumberOfPoints() const
Definition: Polyline.cpp:109
void closePolyline()
Definition: Polyline.cpp:309
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