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();
31 _stationModel = new StationTreeModel();
32}
GeoLib::GEOObjects & _geo_objects
Definition GEOModels.h:110
StationTreeModel * _stationModel
Definition GEOModels.h:107
GeoTreeModel * _geoModel
Definition GEOModels.h:106

References _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:48
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition GeoType.cpp:23

References _geo_objects, GeoLib::convertGeoTypeToString(), ERR(), GeoLib::POINT, GeoLib::POLYLINE, 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}
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

References _geo_objects, GeoLib::convertGeoTypeToString(), ERR(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Surface::getNumberOfTriangles(), 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),
116 *_geo_objects.getPointVecObj(name));
118}
void geoDataAdded(GeoTreeModel *, std::string, GeoLib::GEOTYPE)

References _geo_objects, _geoModel, geoDataAdded(), and GeoLib::POINT.

◆ addPolylineVec

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

Definition at line 141 of file GEOModels.cpp.

142{
143 _geoModel->addPolylineList(QString::fromStdString(name),
144 *_geo_objects.getPolylineVecObj(name));
146}

References _geo_objects, _geoModel, geoDataAdded(), and GeoLib::POLYLINE.

◆ addStationVec

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

Definition at line 128 of file GEOModels.cpp.

129{
130 _stationModel->addStationList(QString::fromStdString(name),
131 _geo_objects.getStationVec(name));
133}
void stationVectorAdded(StationTreeModel *model, std::string name)

References _geo_objects, _stationModel, and stationVectorAdded().

◆ addSurfaceVec

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

Definition at line 160 of file GEOModels.cpp.

161{
162 _geoModel->addSurfaceList(QString::fromStdString(name),
163 *_geo_objects.getSurfaceVecObj(name));
165}

References _geo_objects, _geoModel, geoDataAdded(), and GeoLib::SURFACE.

◆ appendPolylineVec

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

Definition at line 148 of file GEOModels.cpp.

149{
150 this->_geoModel->appendPolylines(name,
151 *_geo_objects.getPolylineVecObj(name));
152}

References _geo_objects, and _geoModel.

◆ appendSurfaceVec

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

Definition at line 167 of file GEOModels.cpp.

168{
169 _geoModel->appendSurfaces(name, *_geo_objects.getSurfaceVecObj(name));
170}

References _geo_objects, and _geoModel.

◆ 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{
190 GeoLib::PolylineVec* plyVec = _geo_objects.getPolylineVecObj(geoName);
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:36
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:42
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition Polyline.cpp:190
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)
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
Definition PolylineVec.h:27

References _geo_objects, OGSError::box(), GeoLib::Polyline::closePolyline(), GeoLib::Polyline::constructPolylineFromSegments(), FileIO::createSurfaceWithEarClipping(), 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{
105 return _geo_objects.getGeometryNames();
106}

References _geo_objects.

◆ 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}

References _geo_objects.

◆ 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 {
91 _geo_objects.removeSurfaceVec(geo_name);
92 }
93 if (type == GeoLib::GEOTYPE::POLYLINE)
94 {
95 _geo_objects.removePolylineVec(geo_name);
96 }
97 if (type == GeoLib::GEOTYPE::POINT)
98 {
99 _geo_objects.removePointVec(geo_name);
100 }
101}

References _geo_objects, GeoLib::POINT, GeoLib::POLYLINE, 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
125 this->_geoModel->removeGeoList(name, GeoLib::GEOTYPE::POINT);
126}
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)

References _geo_objects, _geoModel, geoDataRemoved(), and GeoLib::POINT.

◆ removePolylineVec

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

Definition at line 154 of file GEOModels.cpp.

155{
157 this->_geoModel->removeGeoList(name, GeoLib::GEOTYPE::POLYLINE);
158}

References _geoModel, geoDataRemoved(), and GeoLib::POLYLINE.

◆ removeStationVec

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

Definition at line 135 of file GEOModels.cpp.

136{
138 _stationModel->removeStationList(name);
139}
void stationVectorRemoved(StationTreeModel *model, std::string name)

References _stationModel, and stationVectorRemoved().

◆ removeSurfaceVec

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

Definition at line 172 of file GEOModels.cpp.

173{
175 _geoModel->removeGeoList(name, GeoLib::GEOTYPE::SURFACE);
176}

References _geoModel, geoDataRemoved(), and GeoLib::SURFACE.

◆ 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

References _geoModel, and updateGeometry().

◆ 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);
46 _stationModel->removeStationList(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 {
57 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::POINT);
58 _geoModel->addPointList(QString::fromStdString(geo_name), *points);
60
61 if (auto const lines = _geo_objects.getPolylineVecObj(geo_name);
62 lines != nullptr)
63 {
65 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::POLYLINE);
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 {
75 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::SURFACE);
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, ERR(), geoDataAdded(), geoDataRemoved(), GeoLib::POINT, GeoLib::POLYLINE, stationVectorAdded(), stationVectorRemoved(), and GeoLib::SURFACE.

Referenced by renameGeometry().

Member Data Documentation

◆ _geo_objects

◆ _geoModel

◆ _stationModel

StationTreeModel* GEOModels::_stationModel
protected

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