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)
 
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. More...
 
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. More...
 
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:106
StationTreeModel * _stationModel
Definition: GEOModels.h:103
GeoTreeModel * _geoModel
Definition: GEOModels.h:102
std::unique_ptr< Callbacks > _callbacks
Definition: GEOObjects.h:302
A model for the GeoTreeView implementing a tree as a double-linked list.
Definition: GeoTreeModel.h:41
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 248 of file GEOModels.cpp.

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 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
const PointVec * getPointVecObj(const std::string &name) const
Definition: GEOObjects.cpp:84
SurfaceVec * getSurfaceVecObj(const std::string &name)
Returns the surface vector with the given name.
Definition: GEOObjects.h:205
const PolylineVec * getPolylineVecObj(const std::string &name) const
Definition: GEOObjects.cpp:227
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:249
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:214
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 273 of file GEOModels.cpp.

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 }
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:746
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
Definition: PointVec.h:39
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
std::size_t getNumberOfPoints() const
Definition: Polyline.cpp:99
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
Class Triangle consists of a reference to a point vector and a vector that stores the indices in the ...
Definition: Triangle.h:26

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

104 {
105  _geoModel->addPointList(QString::fromStdString(name),
108 }
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(), MaterialPropertyLib::name, and GeoLib::POINT.

Referenced by GEOModelsCallbacks::addPointVec().

◆ addPolylineVec

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

Definition at line 131 of file GEOModels.cpp.

132 {
133  _geoModel->addPolylineList(QString::fromStdString(name),
136 }
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(), MaterialPropertyLib::name, and GeoLib::POLYLINE.

Referenced by GEOModelsCallbacks::addPolylineVec().

◆ addStationVec

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

Definition at line 118 of file GEOModels.cpp.

119 {
120  _stationModel->addStationList(QString::fromStdString(name),
123 }
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.
Definition: GEOObjects.cpp:131
void addStationList(QString listName, const std::vector< GeoLib::Point * > *stations)

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

Referenced by GEOModelsCallbacks::addStationVec().

◆ addSurfaceVec

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

Definition at line 150 of file GEOModels.cpp.

151 {
152  _geoModel->addSurfaceList(QString::fromStdString(name),
155 }
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(), MaterialPropertyLib::name, and GeoLib::SURFACE.

Referenced by GEOModelsCallbacks::addSurfaceVec().

◆ appendPolylineVec

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

Definition at line 138 of file GEOModels.cpp.

139 {
142 }
void appendPolylines(const std::string &name, GeoLib::PolylineVec const &polylineVec)
Appends polylines to the "Polyline"-subtree.

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

Referenced by GEOModelsCallbacks::appendPolylineVec().

◆ appendSurfaceVec

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

Definition at line 157 of file GEOModels.cpp.

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

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

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

179 {
181 
182  if (plyVec)
183  {
184  std::vector<GeoLib::Polyline*> 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 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
bool appendSurfaceVec(const std::vector< Surface * > &surfaces, const std::string &name)
Definition: GEOObjects.cpp:272
bool appendPolylineVec(const std::vector< Polyline * > &polylines, const std::string &name)
Definition: GEOObjects.cpp:180
static Polyline * constructPolylineFromSegments(const std::vector< Polyline * > &ply_vec, double prox=0.0)
Definition: Polyline.cpp:187
void closePolyline()
Definition: Polyline.cpp:299
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition: TemplateVec.h:40
void setNameOfElementByID(std::size_t id, std::string const &element_name)
Return the name of an element based on its ID.
Definition: TemplateVec.h:165
const std::vector< T * > * getVector() const
Definition: TemplateVec.h:112
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

◆ getGeoModel()

GeoTreeModel* GEOModels::getGeoModel ( )
inline

Definition at line 45 of file GEOModels.h.

45 { return _geoModel; }

References _geoModel.

◆ 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  {
99  _geo_objects.removePointVec(geo_name);
100  }
101 }
bool removePointVec(const std::string &name)
Definition: GEOObjects.cpp:97
bool removeSurfaceVec(const std::string &name)
Definition: GEOObjects.cpp:323
bool removePolylineVec(const std::string &name)
Definition: GEOObjects.cpp:243

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

111 {
112  assert(!_geo_objects.isPntVecUsed(name));
113 
116 }
void geoDataRemoved(GeoTreeModel *, std::string, GeoLib::GEOTYPE)
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:369
void removeGeoList(const std::string &name, GeoLib::GEOTYPE type)

References _geo_objects, _geoModel, geoDataRemoved(), GeoLib::GEOObjects::isPntVecUsed(), MaterialPropertyLib::name, 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 125 of file GEOModels.cpp.

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

References _stationModel, MaterialPropertyLib::name, 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 168 of file GEOModels.cpp.

170 {
171  _geoModel->renameGeometry(old_name, new_name);
172  updateGeometry(new_name);
173 }
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 renameGeometry().

Member Data Documentation

◆ _geo_objects

◆ _geoModel

◆ _stationModel

StationTreeModel* GEOModels::_stationModel
protected

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