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 25 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 14 of file GEOModels.cpp.

15 : QObject(parent), _geo_objects(geo_objects)
16{
17 _geo_objects._callbacks = std::make_unique<GEOModelsCallbacks>(*this);
18
19 _geoModel = new GeoTreeModel();
20 _stationModel = new StationTreeModel();
21}
GeoLib::GEOObjects & _geo_objects
Definition GEOModels.h:99
StationTreeModel * _stationModel
Definition GEOModels.h:96
GeoTreeModel * _geoModel
Definition GEOModels.h:95

References _geo_objects, _geoModel, and _stationModel.

◆ ~GEOModels()

GEOModels::~GEOModels ( )
override

Definition at line 23 of file GEOModels.cpp.

24{
25 delete _stationModel;
26 delete _geoModel;
27}

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 247 of file GEOModels.cpp.

251{
252 if (object_type == GeoLib::GEOTYPE::POINT)
253 {
254 _geo_objects.getPointVecObj(geometry_name)
255 ->setNameForElement(id, new_name);
256 }
257 else if (object_type == GeoLib::GEOTYPE::POLYLINE)
258 {
259 _geo_objects.getPolylineVecObj(geometry_name)
260 ->setNameForElement(id, new_name);
261 }
262 else if (object_type == GeoLib::GEOTYPE::SURFACE)
263 {
264 _geo_objects.getSurfaceVecObj(geometry_name)
265 ->setNameForElement(id, new_name);
266 }
267 else
268 ERR("GEOModels::addNameForElement() - Unknown GEOTYPE {:s}.",
269 GeoLib::convertGeoTypeToString(object_type));
270}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
std::string convertGeoTypeToString(GEOTYPE geo_type)
Definition GeoType.cpp:12

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 272 of file GEOModels.cpp.

276{
277 const GeoLib::GeoObject* obj =
278 _geo_objects.getGeoObject(geometry_name, object_type, geo_object_name);
279 GeoLib::PointVec* pnt_vec = _geo_objects.getPointVecObj(geometry_name);
280 if (object_type == GeoLib::GEOTYPE::POLYLINE)
281 {
282 const auto* ply = dynamic_cast<const GeoLib::Polyline*>(obj);
283 std::size_t nPoints = ply->getNumberOfPoints();
284 for (std::size_t i = 0; i < nPoints; i++)
285 {
286 pnt_vec->setNameForElement(
287 ply->getPointID(i),
288 new_name + "_Point" + std::to_string(ply->getPointID(i)));
289 }
290 }
291 else if (object_type == GeoLib::GEOTYPE::SURFACE)
292 {
293 const auto* sfc = dynamic_cast<const GeoLib::Surface*>(obj);
294 std::size_t nTriangles = sfc->getNumberOfTriangles();
295 for (std::size_t i = 0; i < nTriangles; i++)
296 {
297 const GeoLib::Triangle* tri = (*sfc)[i];
298 pnt_vec->setNameForElement(
299 (*tri)[0], new_name + "_Point" + std::to_string((*tri)[0]));
300 pnt_vec->setNameForElement(
301 (*tri)[1], new_name + "_Point" + std::to_string((*tri)[1]));
302 pnt_vec->setNameForElement(
303 (*tri)[2], new_name + "_Point" + std::to_string((*tri)[2]));
304 }
305 }
306 else
307 ERR("GEOModels::addNameForObjectPoints() - Unknown GEOTYPE {:s}.",
308 GeoLib::convertGeoTypeToString(object_type));
309}
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:244

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 102 of file GEOModels.cpp.

103{
104 _geoModel->addPointList(QString::fromStdString(name),
105 *_geo_objects.getPointVecObj(name));
107}
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 130 of file GEOModels.cpp.

131{
132 _geoModel->addPolylineList(QString::fromStdString(name),
133 *_geo_objects.getPolylineVecObj(name));
135}

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

◆ addStationVec

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

Definition at line 117 of file GEOModels.cpp.

118{
119 _stationModel->addStationList(QString::fromStdString(name),
120 _geo_objects.getStationVec(name));
122}
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 149 of file GEOModels.cpp.

150{
151 _geoModel->addSurfaceList(QString::fromStdString(name),
152 *_geo_objects.getSurfaceVecObj(name));
154}

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

◆ appendPolylineVec

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

Definition at line 137 of file GEOModels.cpp.

138{
139 this->_geoModel->appendPolylines(name,
140 *_geo_objects.getPolylineVecObj(name));
141}

References _geo_objects, and _geoModel.

◆ appendSurfaceVec

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

Definition at line 156 of file GEOModels.cpp.

157{
158 _geoModel->appendSurfaces(name, *_geo_objects.getSurfaceVecObj(name));
159}

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 174 of file GEOModels.cpp.

178{
179 GeoLib::PolylineVec* plyVec = _geo_objects.getPolylineVecObj(geoName);
180
181 if (plyVec)
182 {
183 auto const& polylines = plyVec->getVector();
184 std::vector<GeoLib::Polyline*> ply_list;
185 std::transform(indexlist.begin(), indexlist.end(),
186 std::back_inserter(ply_list),
187 [polylines](auto const& ply_index)
188 { return polylines[ply_index]; });
189
190 // connect polylines
191 GeoLib::Polyline* new_line =
193 proximity);
194
195 if (new_line)
196 {
197 // insert result in a new vector of polylines (because the
198 // GEOObjects::appendPolylines()-method requires a vector)
199 std::vector<GeoLib::Polyline*> connected_ply;
200
201 connected_ply.push_back(new_line);
202 _geo_objects.appendPolylineVec(connected_ply, geoName);
203
204 if (closePly)
205 {
206 new_line->closePolyline();
207
208 if (triangulatePly)
209 {
210 INFO(
211 "Creating a surface by triangulation of the polyline "
212 "...");
213 if (auto sfc =
215 {
216 std::vector<GeoLib::Surface*> new_sfc;
217 new_sfc.push_back(sfc.release());
218 _geo_objects.appendSurfaceVec(new_sfc, geoName);
219 INFO("\t done");
220 }
221 else
222 {
223 WARN(
224 "\t Creating a surface by triangulation of the "
225 "polyline failed.");
226 }
227 plyVec = _geo_objects.getPolylineVecObj(geoName);
228 }
229 }
230
231 if (!ply_name.empty())
232 {
233 plyVec->setNameOfElementByID(polylines.size(), ply_name);
234 }
235 }
236 else
237 {
238 OGSError::box("Error connecting polyines.");
239 }
240 }
241 else
242 {
243 OGSError::box("Corresponding geometry not found.");
244 }
245}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition Polyline.cpp:179
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
Definition TemplateVec.h:94
static void box(const QString &e)
Definition OGSError.cpp:13
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:16

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 92 of file GEOModels.cpp.

93{
94 return _geo_objects.getGeometryNames();
95}

References _geo_objects.

◆ getGeoModel()

GeoTreeModel * GEOModels::getGeoModel ( )
inline

Definition at line 34 of file GEOModels.h.

34{ return _geoModel; }

References _geoModel.

◆ getPointVec

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

Definition at line 96 of file GEOModels.cpp.

98{
99 return _geo_objects.getPointVec(name);
100}

References _geo_objects.

◆ getStationModel()

StationTreeModel * GEOModels::getStationModel ( )
inline

Definition at line 35 of file GEOModels.h.

35{ 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 75 of file GEOModels.cpp.

77{
78 if (type == GeoLib::GEOTYPE::SURFACE)
79 {
80 _geo_objects.removeSurfaceVec(geo_name);
81 }
82 if (type == GeoLib::GEOTYPE::POLYLINE)
83 {
84 _geo_objects.removePolylineVec(geo_name);
85 }
86 if (type == GeoLib::GEOTYPE::POINT)
87 {
88 _geo_objects.removePointVec(geo_name);
89 }
90}

References _geo_objects, GeoLib::POINT, GeoLib::POLYLINE, and GeoLib::SURFACE.

◆ removePointVec

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

Definition at line 109 of file GEOModels.cpp.

110{
111 assert(!_geo_objects.isPntVecUsed(name));
112
114 this->_geoModel->removeGeoList(name, GeoLib::GEOTYPE::POINT);
115}
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 143 of file GEOModels.cpp.

144{
146 this->_geoModel->removeGeoList(name, GeoLib::GEOTYPE::POLYLINE);
147}

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

◆ removeStationVec

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

Definition at line 124 of file GEOModels.cpp.

125{
127 _stationModel->removeStationList(name);
128}
void stationVectorRemoved(StationTreeModel *model, std::string name)

References _stationModel, and stationVectorRemoved().

◆ removeSurfaceVec

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

Definition at line 161 of file GEOModels.cpp.

162{
164 _geoModel->removeGeoList(name, GeoLib::GEOTYPE::SURFACE);
165}

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

◆ renameGeometry

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

Definition at line 167 of file GEOModels.cpp.

169{
170 _geoModel->renameGeometry(old_name, new_name);
171 updateGeometry(new_name);
172}
void updateGeometry(const std::string &geo_name)
Definition GEOModels.cpp:29

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 29 of file GEOModels.cpp.

30{
31 if (auto const stations = _geo_objects.getStationVec(geo_name);
32 stations != nullptr)
33 {
34 emit stationVectorRemoved(_stationModel, geo_name);
35 _stationModel->removeStationList(geo_name);
36 _stationModel->addStationList(QString::fromStdString(geo_name),
37 stations);
38 emit stationVectorAdded(_stationModel, geo_name);
39 return;
40 }
41
42 if (auto const points = _geo_objects.getPointVecObj(geo_name);
43 points != nullptr)
44 {
46 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::POINT);
47 _geoModel->addPointList(QString::fromStdString(geo_name), *points);
49
50 if (auto const lines = _geo_objects.getPolylineVecObj(geo_name);
51 lines != nullptr)
52 {
54 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::POLYLINE);
55 _geoModel->addPolylineList(QString::fromStdString(geo_name),
56 *lines);
58 }
59
60 if (auto const surfaces = _geo_objects.getSurfaceVecObj(geo_name);
61 surfaces != nullptr)
62 {
64 this->_geoModel->removeGeoList(geo_name, GeoLib::GEOTYPE::SURFACE);
65 _geoModel->addSurfaceList(QString::fromStdString(geo_name),
66 *surfaces);
68 }
69 }
70 else
71 ERR("GEOModels::updateGeometry() - Geometry '{:s}' not found.",
72 geo_name);
73}

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: