OGS
GeoTreeModel Class Reference

Detailed Description

A model for the GeoTreeView implementing a tree as a double-linked list.

See also
TreeModel, GeoTreeView, TreeItem, GeoTreeItem

Definition at line 29 of file GeoTreeModel.h.

#include <GeoTreeModel.h>

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

Public Member Functions

 GeoTreeModel (QObject *parent=nullptr)
 ~GeoTreeModel () override
void addPointList (QString geoName, GeoLib::PointVec const &pointVec)
void addPolylineList (QString geoName, GeoLib::PolylineVec const &polylineVec)
 Adds a subtree "Polylines" to an existing geometry with the given name.
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 appendSurfaces (const std::string &name, GeoLib::SurfaceVec const &surfaceVec)
 Appends surfaces to the "Surface"-subtree.
const std::vector< GeoTreeItem * > & getLists ()
 Returns a list of all existing geometries.
void removeGeoList (const std::string &name, GeoLib::GEOTYPE type)
void renameGeometry (std::string const &old_name, std::string const &new_name)
void setNameForItem (const std::string &name, GeoLib::GEOTYPE type, std::size_t id, std::string item_name)
vtkPolyDataAlgorithm * vtkSource (const std::string &name, GeoLib::GEOTYPE type) const
 Returns the vtk-object indicated by type of the geometry indicated by name.
Public Member Functions inherited from TreeModel
 TreeModel (QObject *parent=nullptr)
 ~TreeModel () override
QVariant data (const QModelIndex &index, int role) const override
bool setData (const QModelIndex &index, const QVariant &value, int role) override
Qt::ItemFlags flags (const QModelIndex &index) const override
TreeItemgetItem (const QModelIndex &index) const
QVariant headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex()) const override
QModelIndex parent (const QModelIndex &index) const override
bool removeRows (int position, int count, const QModelIndex &parent) override
int rowCount (const QModelIndex &parent=QModelIndex()) const override
int columnCount (const QModelIndex &parent=QModelIndex()) const override
TreeItemrootItem () const

Private Member Functions

void addChildren (GeoObjectListItem *plyList, GeoLib::PolylineVec const &polyline_vec, std::size_t start_index, std::size_t end_index)
 Adds children to the "Polylines" node.
void addChildren (GeoObjectListItem *sfcList, GeoLib::SurfaceVec const &surface_vec, std::size_t start_index, std::size_t end_index)
 Adds children to the "Surfaces" node.

Private Attributes

std::vector< GeoTreeItem * > _lists

Additional Inherited Members

Public Slots inherited from TreeModel
void updateData ()
Protected Attributes inherited from TreeModel
TreeItem_rootItem

Constructor & Destructor Documentation

◆ GeoTreeModel()

GeoTreeModel::GeoTreeModel ( QObject * parent = nullptr)
explicit

Constructor.

Definition at line 15 of file GeoTreeModel.cpp.

16{
17 QList<QVariant> rootData;
18 delete _rootItem;
19 rootData << "Id"
20 << "x"
21 << "y"
22 << "z"
23 << "name ";
24 _rootItem = new GeoTreeItem(rootData, nullptr, nullptr);
25}
QModelIndex parent(const QModelIndex &index) const override
Definition TreeModel.cpp:70
TreeModel(QObject *parent=nullptr)
Definition TreeModel.cpp:15
TreeItem * _rootItem
Definition TreeModel.h:47

References TreeModel::TreeModel(), TreeModel::_rootItem, and TreeModel::parent().

◆ ~GeoTreeModel()

GeoTreeModel::~GeoTreeModel ( )
overridedefault

Member Function Documentation

◆ addChildren() [1/2]

void GeoTreeModel::addChildren ( GeoObjectListItem * plyList,
GeoLib::PolylineVec const & polyline_vec,
std::size_t start_index,
std::size_t end_index )
private

Adds children to the "Polylines" node.

Definition at line 146 of file GeoTreeModel.cpp.

150{
151 auto const& lines = polyline_vec.getVector();
152
153 for (std::size_t i = start_index; i < end_index; i++)
154 {
155 QList<QVariant> line_data;
156 line_data.reserve(4);
157 line_data << "Line " + QString::number(i) << ""
158 << ""
159 << "";
160
161 const GeoLib::Polyline& line(*(lines[i]));
162 auto* lineItem(new GeoTreeItem(line_data, plyList, &line));
163 plyList->appendChild(lineItem);
164
165 auto nPoints = static_cast<int>(lines[i]->getNumberOfPoints());
166 for (int j = 0; j < nPoints; j++)
167 {
168 const GeoLib::Point pnt(*(line.getPoint(j)));
169 QList<QVariant> pnt_data;
170 pnt_data.reserve(4);
171 pnt_data << static_cast<int>(line.getPointID(j))
172 << QString::number(pnt[0], 'f')
173 << QString::number(pnt[1], 'f')
174 << QString::number(pnt[2], 'f');
175
176 lineItem->appendChild(new TreeItem(pnt_data, lineItem));
177 }
178 }
179
180 for (auto pnt = polyline_vec.getNameIDMapBegin();
181 pnt != polyline_vec.getNameIDMapEnd();
182 ++pnt)
183 {
184 QVariant pnt_data(plyList->child(pnt->second)
185 ->setData(1, QString::fromStdString(pnt->first)));
186 }
187
188 INFO("{:d} polylines added.", end_index - start_index);
189}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void appendChild(TreeItem *item)
Definition TreeItem.cpp:31
TreeItem * child(int row) const
Definition TreeItem.cpp:41
virtual bool setData(int column, const QVariant &value)
Definition TreeItem.cpp:91

References TreeItem::appendChild(), TreeItem::child(), GeoLib::TemplateVec< T >::getNameIDMapBegin(), GeoLib::TemplateVec< T >::getNameIDMapEnd(), GeoLib::Polyline::getPoint(), GeoLib::Polyline::getPointID(), GeoLib::TemplateVec< T >::getVector(), INFO(), and TreeItem::setData().

Referenced by addPolylineList(), addSurfaceList(), appendPolylines(), and appendSurfaces().

◆ addChildren() [2/2]

void GeoTreeModel::addChildren ( GeoObjectListItem * sfcList,
GeoLib::SurfaceVec const & surface_vec,
std::size_t start_index,
std::size_t end_index )
private

Adds children to the "Surfaces" node.

Definition at line 255 of file GeoTreeModel.cpp.

259{
260 auto const& surfaces = surface_vec.getVector();
261
262 const std::vector<GeoLib::Point*>& nodesVec(
263 *(surfaces[start_index]->getPointVec()));
264 for (std::size_t i = start_index; i < end_index; i++)
265 {
266 QList<QVariant> surface;
267 surface.reserve(4);
268 surface << "Surface " + QString::number(i) << ""
269 << ""
270 << "";
271
272 const GeoLib::Surface& sfc(*surfaces[i]);
273 auto* surfaceItem(new GeoTreeItem(surface, sfcList, &sfc));
274 sfcList->appendChild(surfaceItem);
275
276 auto nElems = static_cast<int>(surfaces[i]->getNumberOfTriangles());
277 for (int j = 0; j < nElems; j++)
278 {
279 QList<QVariant> elem;
280 elem.reserve(4);
281 const GeoLib::Triangle& triangle(*sfc[j]);
282 elem << j << static_cast<int>(triangle[0])
283 << static_cast<int>(triangle[1])
284 << static_cast<int>(triangle[2]);
285 auto* child(new TreeItem(elem, surfaceItem));
286 surfaceItem->appendChild(child);
287
288 for (int k = 0; k < 3; k++)
289 {
290 QList<QVariant> node;
291 node.reserve(4);
292 const GeoLib::Point& pnt(*(nodesVec[triangle[k]]));
293 node << static_cast<int>(triangle[k])
294 << QString::number(pnt[0], 'f')
295 << QString::number(pnt[1], 'f')
296 << QString::number(pnt[2], 'f');
297 child->appendChild(new TreeItem(node, child));
298 }
299 }
300 }
301
302 for (auto pnt = surface_vec.getNameIDMapBegin();
303 pnt != surface_vec.getNameIDMapEnd();
304 ++pnt)
305 {
306 QVariant pnt_data(sfcList->child(pnt->second)
307 ->setData(1, QString::fromStdString(pnt->first)));
308 }
309
310 INFO("{:d} surfaces added.", end_index - start_index);
311}

References TreeItem::appendChild(), TreeItem::child(), GeoLib::TemplateVec< T >::getNameIDMapBegin(), GeoLib::TemplateVec< T >::getNameIDMapEnd(), GeoLib::TemplateVec< T >::getVector(), INFO(), and TreeItem::setData().

◆ addPointList()

void GeoTreeModel::addPointList ( QString geoName,
GeoLib::PointVec const & pointVec )

Inserts a new subtree under _rootItem for a geometry with the given name along with a subtree named "Points" for that new geometry.

Parameters
geoNameName of the new subtree. If no name is given a default name is assigned.
pointVecThe list of points to be added as children of that subtree (no geometry can be added with a set of points!)

Definition at line 29 of file GeoTreeModel.cpp.

31{
32 beginResetModel();
33
34 auto const& points = pointVec.getVector();
35
36 QList<QVariant> geoData;
37 geoData << QVariant(geoName) << ""
38 << ""
39 << ""
40 << "";
41 auto* geo(new GeoTreeItem(geoData, _rootItem));
42 _lists.push_back(geo);
43 _rootItem->appendChild(geo);
44
45 QList<QVariant> pointData;
46 pointData << "Points"
47 << ""
48 << ""
49 << ""
50 << "";
51 auto* pointList =
52 new GeoObjectListItem(pointData, geo, &points, GeoLib::GEOTYPE::POINT);
53 geo->appendChild(pointList);
54
55 std::size_t nPoints = points.size();
56
57 for (std::size_t j = 0; j < nPoints; j++)
58 {
59 const GeoLib::Point& pnt(*points[j]);
60 QList<QVariant> pnt_data;
61 pnt_data.reserve(5);
62 pnt_data << static_cast<unsigned>(j) << QString::number(pnt[0], 'f')
63 << QString::number(pnt[1], 'f') << QString::number(pnt[2], 'f')
64 << "";
65 pointList->appendChild(new GeoTreeItem(
66 pnt_data, pointList, static_cast<const GeoLib::Point*>(&pnt)));
67 }
68
69 for (auto pnt = pointVec.getNameIDMapBegin();
70 pnt != pointVec.getNameIDMapEnd();
71 ++pnt)
72 {
73 QVariant pnt_data(pointList->child(pnt->second)
74 ->setData(4, QString::fromStdString(pnt->first)));
75 }
76
77 INFO("Geometry '{:s}' built. {:d} points added.", geoName.toStdString(),
78 nPoints);
79
80 endResetModel();
81}
std::vector< GeoTreeItem * > _lists

References _lists, TreeModel::_rootItem, GeoLib::TemplateVec< T >::getNameIDMapBegin(), GeoLib::TemplateVec< T >::getNameIDMapEnd(), GeoLib::TemplateVec< T >::getVector(), INFO(), and GeoLib::POINT.

◆ addPolylineList()

void GeoTreeModel::addPolylineList ( QString geoName,
GeoLib::PolylineVec const & polylineVec )

Adds a subtree "Polylines" to an existing geometry with the given name.

Definition at line 83 of file GeoTreeModel.cpp.

85{
86 beginResetModel();
87
88 int nLists = _rootItem->childCount();
89 TreeItem* geo(nullptr);
90 for (int i = 0; i < nLists; i++)
91 {
92 if (_rootItem->child(i)->data(0).toString().compare(geoName) == 0)
93 {
94 geo = _rootItem->child(i);
95 }
96 }
97
98 if (geo == nullptr)
99 {
100 ERR("GeoTreeModel::addPolylineList(): No corresponding geometry for "
101 "'{:s}' found.",
102 geoName.toStdString());
103 return;
104 }
105
106 auto const& lines = polylineVec.getVector();
107
108 QList<QVariant> plyData;
109 plyData << "Polylines"
110 << ""
111 << ""
112 << "";
113 auto* plyList =
114 new GeoObjectListItem(plyData, geo, &lines, GeoLib::GEOTYPE::POLYLINE);
115 geo->appendChild(plyList);
116 this->addChildren(plyList, polylineVec, 0, lines.size());
117
118 endResetModel();
119}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void addChildren(GeoObjectListItem *plyList, GeoLib::PolylineVec const &polyline_vec, std::size_t start_index, std::size_t end_index)
Adds children to the "Polylines" node.

References TreeModel::_rootItem, addChildren(), TreeItem::appendChild(), ERR(), GeoLib::TemplateVec< T >::getVector(), GeoLib::POLYLINE, and GeoLib::TemplateVec< T >::size().

◆ addSurfaceList()

void GeoTreeModel::addSurfaceList ( QString geoName,
GeoLib::SurfaceVec const & surfaceVec )

Adds a subtree "Surfaces" to an existing geometry with the given name.

Definition at line 191 of file GeoTreeModel.cpp.

193{
194 beginResetModel();
195
196 int nLists = _rootItem->childCount();
197 TreeItem* geo(nullptr);
198 for (int i = 0; i < nLists; i++)
199 {
200 if (_rootItem->child(i)->data(0).toString().compare(geoName) == 0)
201 {
202 geo = _rootItem->child(i);
203 }
204 }
205
206 if (geo == nullptr)
207 {
208 ERR("GeoTreeModel::addSurfaceList(): No corresponding geometry for "
209 "'{:s}' found.",
210 geoName.toStdString());
211 return;
212 }
213
214 auto const& surfaces = surfaceVec.getVector();
215
216 QList<QVariant> sfcData;
217 sfcData << "Surfaces"
218 << ""
219 << ""
220 << "";
221 auto* sfcList = new GeoObjectListItem(sfcData, geo, &surfaces,
223 geo->appendChild(sfcList);
224 this->addChildren(sfcList, surfaceVec, 0, surfaces.size());
225
226 endResetModel();
227}

References TreeModel::_rootItem, addChildren(), TreeItem::appendChild(), ERR(), GeoLib::TemplateVec< T >::getVector(), GeoLib::TemplateVec< T >::size(), and GeoLib::SURFACE.

◆ appendPolylines()

void GeoTreeModel::appendPolylines ( const std::string & name,
GeoLib::PolylineVec const & polylineVec )

Appends polylines to the "Polyline"-subtree.

Definition at line 121 of file GeoTreeModel.cpp.

123{
124 for (auto& list : _lists)
125 {
126 if (name == list->data(0).toString().toStdString())
127 {
128 for (int j = 0; j < list->childCount(); j++)
129 {
130 auto* parent = static_cast<GeoObjectListItem*>(list->child(j));
131 if (GeoLib::GEOTYPE::POLYLINE == parent->getType())
132 {
133 beginResetModel();
134 this->addChildren(parent, polylineVec, parent->childCount(),
135 polylineVec.getVector().size());
136 endResetModel();
137 parent->vtkSource()->Modified();
138 return;
139 }
140 }
141 }
142 }
143 OGSError::box("Error adding polyline to geometry.");
144}
static void box(const QString &e)
Definition OGSError.cpp:13

References _lists, addChildren(), OGSError::box(), GeoLib::TemplateVec< T >::getVector(), TreeModel::parent(), and GeoLib::POLYLINE.

◆ appendSurfaces()

void GeoTreeModel::appendSurfaces ( const std::string & name,
GeoLib::SurfaceVec const & surfaceVec )

Appends surfaces to the "Surface"-subtree.

Definition at line 229 of file GeoTreeModel.cpp.

231{
232 for (auto& list : _lists)
233 {
234 if (name == list->data(0).toString().toStdString())
235 {
236 int nChildren = list->childCount();
237 for (int j = 0; j < nChildren; j++)
238 {
239 auto* parent = static_cast<GeoObjectListItem*>(list->child(j));
240 if (GeoLib::GEOTYPE::SURFACE == parent->getType())
241 {
242 beginResetModel();
243 this->addChildren(parent, surfaceVec, parent->childCount(),
244 surfaceVec.getVector().size());
245 parent->vtkSource()->Modified();
246 endResetModel();
247 return;
248 }
249 }
250 }
251 }
252 OGSError::box("Error adding surface to geometry.");
253}

References _lists, addChildren(), OGSError::box(), GeoLib::TemplateVec< T >::getVector(), TreeModel::parent(), and GeoLib::SURFACE.

◆ getLists()

const std::vector< GeoTreeItem * > & GeoTreeModel::getLists ( )
inline

Returns a list of all existing geometries.

Definition at line 52 of file GeoTreeModel.h.

52{ return _lists; }

References _lists.

◆ removeGeoList()

void GeoTreeModel::removeGeoList ( const std::string & name,
GeoLib::GEOTYPE type )

Removes a geometry (points, polylines & surfaces) or just a specified subtree indicated by type. Note that points cannot be deleted as long as other objects exist that depend on them.

Removes the TreeItem with the given name including all its children

Definition at line 337 of file GeoTreeModel.cpp.

338{
339 for (std::size_t i = 0; i < _lists.size(); i++)
340 {
341 if (name == _lists[i]->data(0).toString().toStdString())
342 {
343 for (int j = 0; j < _lists[i]->childCount(); j++)
344 {
345 if (type == static_cast<GeoObjectListItem*>(_lists[i]->child(j))
346 ->getType())
347 {
348 QModelIndex index = createIndex(j, 0, _lists[i]->child(j));
349 removeRows(0, _lists[i]->child(j)->childCount(), index);
350 removeRows(j, 1, parent(index));
351 break;
352 }
353 }
354 if (_lists[i]->childCount() == 0)
355 {
356 _lists.erase(_lists.begin() + i);
357 removeRows(i, 1, QModelIndex());
358 }
359 }
360 }
361}
bool removeRows(int position, int count, const QModelIndex &parent) override
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:39
QVariant data(const QModelIndex &index, int role) const override
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)

References _lists, TreeModel::data(), TreeModel::index(), TreeModel::parent(), and TreeModel::removeRows().

◆ renameGeometry()

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

Definition at line 313 of file GeoTreeModel.cpp.

315{
316 for (auto tree_item_entry : _lists)
317 {
318 if (old_name == tree_item_entry->data(0).toString().toStdString())
319 {
320 QVariant new_entry(QString::fromStdString(new_name));
321 tree_item_entry->setData(0, new_entry);
322 break;
323 }
324 }
325 for (auto tree_item_entry : _lists)
326 {
327 if (new_name == tree_item_entry->data(0).toString().toStdString())
328 {
329 INFO("Found tree_item_entry with name '{:s}'.", new_name);
330 }
331 }
332}

References _lists, and INFO().

◆ setNameForItem()

void GeoTreeModel::setNameForItem ( const std::string & name,
GeoLib::GEOTYPE type,
std::size_t id,
std::string item_name )

Definition at line 385 of file GeoTreeModel.cpp.

389{
390 std::string geo_type_str;
391 int col_idx(1);
392
393 switch (type)
394 {
396 geo_type_str = "Points";
397 col_idx = 4; // for points the name is at a different position
398 break;
400 geo_type_str = "Polylines";
401 break;
403 geo_type_str = "Surfaces";
404 break;
405 default:
406 geo_type_str = "";
407 }
408
409 auto it =
410 find_if(_lists.begin(), _lists.end(),
411 [&name](GeoTreeItem* geo)
412 { return (name == geo->data(0).toString().toStdString()); });
413
414 for (int i = 0; i < (*it)->childCount(); i++)
415 {
416 if (geo_type_str == (*it)->child(i)->data(0).toString().toStdString())
417 {
418 TreeItem* item = (*it)->child(i)->child(id);
419 item->setData(col_idx, QString::fromStdString(item_name));
420 break;
421 }
422 }
423}

References _lists, TreeItem::child(), GeoLib::POINT, GeoLib::POLYLINE, TreeItem::setData(), and GeoLib::SURFACE.

Referenced by MainWindow::showGeoNameDialog().

◆ vtkSource()

vtkPolyDataAlgorithm * GeoTreeModel::vtkSource ( const std::string & name,
GeoLib::GEOTYPE type ) const

Returns the vtk-object indicated by type of the geometry indicated by name.

Definition at line 363 of file GeoTreeModel.cpp.

365{
366 std::size_t nLists = _lists.size();
367 for (std::size_t i = 0; i < nLists; i++)
368 {
369 if (name == _lists[i]->data(0).toString().toStdString())
370 {
371 for (int j = 0; j < _lists[i]->childCount(); j++)
372 {
373 auto* item =
374 dynamic_cast<GeoObjectListItem*>(_lists[i]->child(j));
375 if (item->getType() == type)
376 {
377 return item->vtkSource();
378 }
379 }
380 }
381 }
382 return nullptr;
383}

References _lists, and TreeModel::data().

Referenced by VtkVisPipeline::addPipelineItem(), and VtkVisPipeline::removeSourceItem().

Member Data Documentation

◆ _lists

std::vector<GeoTreeItem*> GeoTreeModel::_lists
private

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