OGS
GEOModels Class Reference

Detailed Description

GEOModels connects the data management class GEOObjects and the GUI. It inherits from GeoLib::GEOObjects and additionally emits signals when data objects are modified. The GUI connects to these signals. Model instances are created for every data object.

Definition at line 36 of file GEOModels.h.

#include <GEOModels.h>

Inheritance diagram for GEOModels:
[legend]
Collaboration diagram for GEOModels:
[legend]

Public Slots

void updateGeometry (const std::string &geo_name)
 
virtual void removeGeometry (std::string const &geo_name, GeoLib::GEOTYPE const type)
 
void addPointVec (std::string const &name)
 
void removePointVec (std::string const &name)
 
void addStationVec (std::string const &name)
 
void removeStationVec (std::string const &name)
 
void addPolylineVec (std::string const &name)
 
void appendPolylineVec (std::string const &name)
 
void removePolylineVec (std::string const &name)
 
void addSurfaceVec (std::string const &name)
 
std::vector< std::string > getGeometryNames () const
 
const std::vector< GeoLib::Point * > * getPointVec (const std::string &name) const
 
void appendSurfaceVec (std::string const &name)
 
void removeSurfaceVec (std::string const &name)
 
void renameGeometry (std::string const &old_name, std::string const &new_name)
 
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.
 
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 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)
 

Signals

void geoDataAdded (GeoTreeModel *, std::string, GeoLib::GEOTYPE)
 
void geoDataRemoved (GeoTreeModel *, std::string, GeoLib::GEOTYPE)
 
void stationVectorAdded (StationTreeModel *model, std::string name)
 
void stationVectorRemoved (StationTreeModel *model, std::string name)
 

Public Member Functions

 GEOModels (GeoLib::GEOObjects &geo_objects, QObject *parent=nullptr)
 
 ~GEOModels () override
 
GeoTreeModelgetGeoModel ()
 
StationTreeModelgetStationModel ()
 

Protected Attributes

GeoTreeModel_geoModel
 
StationTreeModel_stationModel
 

Private Attributes

GeoLib::GEOObjects_geo_objects
 

Constructor & Destructor Documentation

◆ GEOModels()

GEOModels::GEOModels ( GeoLib::GEOObjects & geo_objects,
QObject * parent = nullptr )
explicit

Definition at line 25 of file GEOModels.cpp.

26 : QObject(parent), _geo_objects(geo_objects)
27{
28 _geo_objects._callbacks = std::make_unique<GEOModelsCallbacks>(*this);
29
30 _geoModel = new GeoTreeModel();
32}
GeoLib::GEOObjects & _geo_objects
Definition GEOModels.h:110
StationTreeModel * _stationModel
Definition GEOModels.h:107
GeoTreeModel * _geoModel
Definition GEOModels.h:106
std::unique_ptr< Callbacks > _callbacks
Definition GEOObjects.h:303
A model for the GeoTreeView implementing a tree as a double-linked list.
A model for the StationTreeView implementing a tree as a double-linked list.

References GeoLib::GEOObjects::_callbacks, _geo_objects, _geoModel, and _stationModel.

◆ ~GEOModels()

GEOModels::~GEOModels ( )
override

Definition at line 34 of file GEOModels.cpp.

35{
36 delete _stationModel;
37 delete _geoModel;
38}

References _geoModel, and _stationModel.

Member Function Documentation

◆ addNameForElement

void GEOModels::addNameForElement ( std::string const & geometry_name,
GeoLib::GEOTYPE const object_type,
std::size_t const id,
std::string const & new_name )
slot

Adds the name 'new_name' for the geo-object specified by the parameters.

Definition at line 258 of file GEOModels.cpp.

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}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
const PointVec * getPointVecObj(const std::string &name) const
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition GEOObjects.h:208
const PolylineVec * getPolylineVecObj(const std::string &name) const
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
virtual void setNameForElement(std::size_t id, std::string const &name)
Sets the given name for the element of the given ID.
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition GeoType.cpp:23

References _geo_objects, GeoLib::convertGeoTypeToString(), ERR(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::GEOObjects::getSurfaceVecObj(), GeoLib::POINT, GeoLib::POLYLINE, GeoLib::TemplateVec< T >::setNameForElement(), GeoLib::PointVec::setNameForElement(), and GeoLib::SURFACE.

◆ addNameForObjectPoints

void GEOModels::addNameForObjectPoints ( const std::string & geometry_name,
const GeoLib::GEOTYPE object_type,
const std::string & geo_object_name,
const std::string & new_name )
slot

Adds a generic name to all points that are part of the specified geo-object.

Definition at line 283 of file GEOModels.cpp.

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}
const GeoLib::GeoObject * getGeoObject(const std::string &geo_name, GeoLib::GEOTYPE type, const std::string &geo_obj_name) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
Definition PointVec.h:36
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition Polyline.h:40
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
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition Triangle.h:27

References _geo_objects, GeoLib::convertGeoTypeToString(), ERR(), GeoLib::GEOObjects::getGeoObject(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Surface::getNumberOfTriangles(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::POLYLINE, GeoLib::PointVec::setNameForElement(), and GeoLib::SURFACE.

◆ addPointVec

void GEOModels::addPointVec ( std::string const & name)
slot

Definition at line 113 of file GEOModels.cpp.

114{
115 _geoModel->addPointList(QString::fromStdString(name),
118}
void geoDataAdded(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
void addPointList(QString geoName, GeoLib::PointVec const &pointVec)

References _geo_objects, _geoModel, GeoTreeModel::addPointList(), geoDataAdded(), GeoLib::GEOObjects::getPointVecObj(), and GeoLib::POINT.

Referenced by GEOModelsCallbacks::addPointVec().

◆ addPolylineVec

void GEOModels::addPolylineVec ( std::string const & name)
slot

Definition at line 141 of file GEOModels.cpp.

142{
143 _geoModel->addPolylineList(QString::fromStdString(name),
146}
void addPolylineList(QString geoName, GeoLib::PolylineVec const &polylineVec)
Adds a subtree "Polylines" to an existing geometry with the given name.

References _geo_objects, _geoModel, GeoTreeModel::addPolylineList(), geoDataAdded(), GeoLib::GEOObjects::getPolylineVecObj(), and GeoLib::POLYLINE.

Referenced by GEOModelsCallbacks::addPolylineVec().

◆ addStationVec

void GEOModels::addStationVec ( std::string const & name)
slot

Definition at line 128 of file GEOModels.cpp.

129{
130 _stationModel->addStationList(QString::fromStdString(name),
133}
void stationVectorAdded(StationTreeModel *model, std::string name)
const std::vector< GeoLib::Point * > * getStationVec(const std::string &name) const
Returns the station vector with the given name.
void addStationList(QString listName, const std::vector< GeoLib::Point * > *stations)

References _geo_objects, _stationModel, StationTreeModel::addStationList(), GeoLib::GEOObjects::getStationVec(), and stationVectorAdded().

Referenced by GEOModelsCallbacks::addStationVec().

◆ addSurfaceVec

void GEOModels::addSurfaceVec ( std::string const & name)
slot

Definition at line 160 of file GEOModels.cpp.

161{
162 _geoModel->addSurfaceList(QString::fromStdString(name),
165}
void addSurfaceList(QString geoName, GeoLib::SurfaceVec const &surfaceVec)
Adds a subtree "Surfaces" to an existing geometry with the given name.

References _geo_objects, _geoModel, GeoTreeModel::addSurfaceList(), geoDataAdded(), GeoLib::GEOObjects::getSurfaceVecObj(), and GeoLib::SURFACE.

Referenced by GEOModelsCallbacks::addSurfaceVec().

◆ appendPolylineVec

void GEOModels::appendPolylineVec ( std::string const & name)
slot

Definition at line 148 of file GEOModels.cpp.

149{
150 this->_geoModel->appendPolylines(name,
152}
void appendPolylines(const std::string &name, GeoLib::PolylineVec const &polylineVec)
Appends polylines to the "Polyline"-subtree.

References _geo_objects, _geoModel, GeoTreeModel::appendPolylines(), and GeoLib::GEOObjects::getPolylineVecObj().

Referenced by GEOModelsCallbacks::appendPolylineVec().

◆ appendSurfaceVec

void GEOModels::appendSurfaceVec ( std::string const & name)
slot

Definition at line 167 of file GEOModels.cpp.

168{
170}
void appendSurfaces(const std::string &name, GeoLib::SurfaceVec const &surfaceVec)
Appends surfaces to the "Surface"-subtree.

References _geo_objects, _geoModel, GeoTreeModel::appendSurfaces(), and GeoLib::GEOObjects::getSurfaceVecObj().

Referenced by GEOModelsCallbacks::appendSurfaceVec().

◆ connectPolylineSegments

void GEOModels::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 )
slot

Calls all necessary functions to connect polyline-segments and update all views and windows.

Definition at line 185 of file GEOModels.cpp.

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}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition Polyline.cpp:190
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition TemplateVec.h:38
void setNameOfElementByID(std::size_t id, std::string const &element_name)
Return the name of an element based on its ID.
std::vector< T * > const & getVector() const
static void box(const QString &e)
Definition OGSError.cpp:23
std::unique_ptr< GeoLib::Surface > createSurfaceWithEarClipping(GeoLib::Polyline const &line)

References _geo_objects, GeoLib::GEOObjects::appendPolylineVec(), GeoLib::GEOObjects::appendSurfaceVec(), OGSError::box(), GeoLib::Polyline::closePolyline(), GeoLib::Polyline::constructPolylineFromSegments(), FileIO::createSurfaceWithEarClipping(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::TemplateVec< T >::getVector(), INFO(), GeoLib::TemplateVec< T >::setNameOfElementByID(), and WARN().

◆ geoDataAdded

void GEOModels::geoDataAdded ( GeoTreeModel * ,
std::string ,
GeoLib::GEOTYPE  )
signal

◆ geoDataRemoved

void GEOModels::geoDataRemoved ( GeoTreeModel * ,
std::string ,
GeoLib::GEOTYPE  )
signal

◆ getGeometryNames

std::vector< std::string > GEOModels::getGeometryNames ( ) const
slot

Definition at line 103 of file GEOModels.cpp.

104{
106}
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.

References _geo_objects, and GeoLib::GEOObjects::getGeometryNames().

Referenced by TranslateDataDialog::TranslateDataDialog(), and TranslateDataDialog::accept().

◆ getGeoModel()

GeoTreeModel * GEOModels::getGeoModel ( )
inline

Definition at line 45 of file GEOModels.h.

45{ return _geoModel; }

References _geoModel.

◆ getPointVec

const std::vector< GeoLib::Point * > * GEOModels::getPointVec ( const std::string & name) const
slot

Definition at line 107 of file GEOModels.cpp.

109{
110 return _geo_objects.getPointVec(name);
111}
const std::vector< Point * > * getPointVec(const std::string &name) const

References _geo_objects, and GeoLib::GEOObjects::getPointVec().

Referenced by TranslateDataDialog::moveGeometry().

◆ getStationModel()

StationTreeModel * GEOModels::getStationModel ( )
inline

Definition at line 46 of file GEOModels.h.

46{ return _stationModel; }

References _stationModel.

◆ removeGeometry

void GEOModels::removeGeometry ( std::string const & geo_name,
GeoLib::GEOTYPE const type )
virtualslot

Removes all parts (points, lines, surfaces) of the geometry with the given name.

Definition at line 86 of file GEOModels.cpp.

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}
bool removePointVec(const std::string &name)
bool removeSurfaceVec(const std::string &name)
bool removePolylineVec(const std::string &name)

References _geo_objects, GeoLib::POINT, GeoLib::POLYLINE, GeoLib::GEOObjects::removePointVec(), GeoLib::GEOObjects::removePolylineVec(), GeoLib::GEOObjects::removeSurfaceVec(), and GeoLib::SURFACE.

◆ removePointVec

void GEOModels::removePointVec ( std::string const & name)
slot

Definition at line 120 of file GEOModels.cpp.

121{
122 assert(!_geo_objects.isPntVecUsed(name));
123
126}
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
bool isPntVecUsed(const std::string &name) const
void removeGeoList(const std::string &name, GeoLib::GEOTYPE type)

References _geo_objects, _geoModel, geoDataRemoved(), GeoLib::GEOObjects::isPntVecUsed(), GeoLib::POINT, and GeoTreeModel::removeGeoList().

Referenced by GEOModelsCallbacks::removePointVec().

◆ removePolylineVec

void GEOModels::removePolylineVec ( std::string const & name)
slot

◆ removeStationVec

void GEOModels::removeStationVec ( std::string const & name)
slot

Definition at line 135 of file GEOModels.cpp.

136{
139}
void stationVectorRemoved(StationTreeModel *model, std::string name)
void removeStationList(QModelIndex index)

References _stationModel, StationTreeModel::removeStationList(), and stationVectorRemoved().

Referenced by GEOModelsCallbacks::removeStationVec().

◆ removeSurfaceVec

void GEOModels::removeSurfaceVec ( std::string const & name)
slot

◆ renameGeometry

void GEOModels::renameGeometry ( std::string const & old_name,
std::string const & new_name )
slot

Definition at line 178 of file GEOModels.cpp.

180{
181 _geoModel->renameGeometry(old_name, new_name);
182 updateGeometry(new_name);
183}
void updateGeometry(const std::string &geo_name)
Definition GEOModels.cpp:40
void renameGeometry(std::string const &old_name, std::string const &new_name)

References _geoModel, GeoTreeModel::renameGeometry(), and updateGeometry().

Referenced by GEOModelsCallbacks::renameGeometry().

◆ stationVectorAdded

void GEOModels::stationVectorAdded ( StationTreeModel * model,
std::string name )
signal

Referenced by addStationVec(), and updateGeometry().

◆ stationVectorRemoved

void GEOModels::stationVectorRemoved ( StationTreeModel * model,
std::string name )
signal

Referenced by removeStationVec(), and updateGeometry().

◆ updateGeometry

void GEOModels::updateGeometry ( const std::string & geo_name)
slot

Updates the tree model if the underlying data in GEOObjects has changed. Technically it removes the geometry from the tree model (but not from GeoObjects) and re-adds the (modified) geometry.

Definition at line 40 of file GEOModels.cpp.

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}

References _geo_objects, _geoModel, _stationModel, GeoTreeModel::addPointList(), GeoTreeModel::addPolylineList(), StationTreeModel::addStationList(), GeoTreeModel::addSurfaceList(), ERR(), geoDataAdded(), geoDataRemoved(), GeoLib::GEOObjects::getPointVecObj(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::GEOObjects::getStationVec(), GeoLib::GEOObjects::getSurfaceVecObj(), GeoLib::POINT, GeoLib::POLYLINE, GeoTreeModel::removeGeoList(), StationTreeModel::removeStationList(), stationVectorAdded(), stationVectorRemoved(), and GeoLib::SURFACE.

Referenced by TranslateDataDialog::moveGeometry(), and renameGeometry().

Member Data Documentation

◆ _geo_objects

◆ _geoModel

◆ _stationModel

StationTreeModel* GEOModels::_stationModel
protected

The documentation for this class was generated from the following files: