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 40 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. More...
 
void appendPolylines (const std::string &name, GeoLib::PolylineVec const &polylineVec)
 Appends polylines to the "Polyline"-subtree. More...
 
void addSurfaceList (QString geoName, GeoLib::SurfaceVec const &surfaceVec)
 Adds a subtree "Surfaces" to an existing geometry with the given name. More...
 
void appendSurfaces (const std::string &name, GeoLib::SurfaceVec const &surfaceVec)
 Appends surfaces to the "Surface"-subtree. More...
 
const std::vector< GeoTreeItem * > & getLists ()
 Returns a list of all existing geometries. More...
 
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. More...
 
- 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. More...
 
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. More...
 

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 26 of file GeoTreeModel.cpp.

26  : TreeModel(parent)
27 {
28  QList<QVariant> rootData;
29  delete _rootItem;
30  rootData << "Id"
31  << "x"
32  << "y"
33  << "z"
34  << "name ";
35  _rootItem = new GeoTreeItem(rootData, nullptr, nullptr);
36 }
A TreeItem containing an additional GeoObject.
Definition: GeoTreeItem.h:27
QModelIndex parent(const QModelIndex &index) const override
Definition: TreeModel.cpp:81
TreeModel(QObject *parent=nullptr)
Definition: TreeModel.cpp:26
TreeItem * _rootItem
Definition: TreeModel.h:58

References TreeModel::_rootItem.

◆ ~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 157 of file GeoTreeModel.cpp.

161 {
162  const std::vector<GeoLib::Polyline*> lines = *(polyline_vec.getVector());
163 
164  for (std::size_t i = start_index; i < end_index; i++)
165  {
166  QList<QVariant> line_data;
167  line_data.reserve(4);
168  line_data << "Line " + QString::number(i) << ""
169  << ""
170  << "";
171 
172  const GeoLib::Polyline& line(*(lines[i]));
173  auto* lineItem(new GeoTreeItem(line_data, plyList, &line));
174  plyList->appendChild(lineItem);
175 
176  auto nPoints = static_cast<int>(lines[i]->getNumberOfPoints());
177  for (int j = 0; j < nPoints; j++)
178  {
179  const GeoLib::Point pnt(*(line.getPoint(j)));
180  QList<QVariant> pnt_data;
181  pnt_data.reserve(4);
182  pnt_data << static_cast<int>(line.getPointID(j))
183  << QString::number(pnt[0], 'f')
184  << QString::number(pnt[1], 'f')
185  << QString::number(pnt[2], 'f');
186 
187  lineItem->appendChild(new TreeItem(pnt_data, lineItem));
188  }
189  }
190 
191  for (auto pnt = polyline_vec.getNameIDMapBegin();
192  pnt != polyline_vec.getNameIDMapEnd();
193  ++pnt)
194  {
195  QVariant pnt_data(plyList->child(pnt->second)
196  ->setData(1, QString::fromStdString(pnt->first)));
197  }
198 
199  INFO("{:d} polylines added.", end_index - start_index);
200 }
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
Definition: Polyline.h:51
Objects nodes for the TreeModel.
Definition: TreeItem.h:28
void appendChild(TreeItem *item)
Definition: TreeItem.cpp:42
TreeItem * child(int row) const
Definition: TreeItem.cpp:52
virtual bool setData(int column, const QVariant &value)
Definition: TreeItem.cpp:102

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.

◆ 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 40 of file GeoTreeModel.cpp.

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

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

Referenced by GEOModels::addPointVec(), and GEOModels::updateGeometry().

◆ 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 94 of file GeoTreeModel.cpp.

96 {
97  beginResetModel();
98 
99  int nLists = _rootItem->childCount();
100  TreeItem* geo(nullptr);
101  for (int i = 0; i < nLists; i++)
102  {
103  if (_rootItem->child(i)->data(0).toString().compare(geoName) == 0)
104  {
105  geo = _rootItem->child(i);
106  }
107  }
108 
109  if (geo == nullptr)
110  {
111  ERR("GeoTreeModel::addPolylineList(): No corresponding geometry for "
112  "'{:s}' found.",
113  geoName.toStdString());
114  return;
115  }
116 
117  const std::vector<GeoLib::Polyline*>* lines = polylineVec.getVector();
118 
119  QList<QVariant> plyData;
120  plyData << "Polylines"
121  << ""
122  << ""
123  << "";
124  auto* plyList =
125  new GeoObjectListItem(plyData, geo, lines, GeoLib::GEOTYPE::POLYLINE);
126  geo->appendChild(plyList);
127  this->addChildren(plyList, polylineVec, 0, lines->size());
128 
129  endResetModel();
130 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
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.
virtual int childCount() const
Definition: TreeItem.cpp:65
virtual QVariant data(int column) const
Definition: TreeItem.cpp:94

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

Referenced by GEOModels::addPolylineVec(), and GEOModels::updateGeometry().

◆ 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 202 of file GeoTreeModel.cpp.

204 {
205  beginResetModel();
206 
207  int nLists = _rootItem->childCount();
208  TreeItem* geo(nullptr);
209  for (int i = 0; i < nLists; i++)
210  {
211  if (_rootItem->child(i)->data(0).toString().compare(geoName) == 0)
212  {
213  geo = _rootItem->child(i);
214  }
215  }
216 
217  if (geo == nullptr)
218  {
219  ERR("GeoTreeModel::addSurfaceList(): No corresponding geometry for "
220  "'{:s}' found.",
221  geoName.toStdString());
222  return;
223  }
224 
225  const std::vector<GeoLib::Surface*>* surfaces = surfaceVec.getVector();
226 
227  QList<QVariant> sfcData;
228  sfcData << "Surfaces"
229  << ""
230  << ""
231  << "";
232  auto* sfcList =
233  new GeoObjectListItem(sfcData, geo, surfaces, GeoLib::GEOTYPE::SURFACE);
234  geo->appendChild(sfcList);
235  this->addChildren(sfcList, surfaceVec, 0, surfaces->size());
236 
237  endResetModel();
238 }

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

Referenced by GEOModels::addSurfaceVec(), and GEOModels::updateGeometry().

◆ appendPolylines()

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

Appends polylines to the "Polyline"-subtree.

Definition at line 132 of file GeoTreeModel.cpp.

134 {
135  for (auto& list : _lists)
136  {
137  if (name == list->data(0).toString().toStdString())
138  {
139  for (int j = 0; j < list->childCount(); j++)
140  {
141  auto* parent = static_cast<GeoObjectListItem*>(list->child(j));
142  if (GeoLib::GEOTYPE::POLYLINE == parent->getType())
143  {
144  beginResetModel();
145  this->addChildren(parent, polylineVec, parent->childCount(),
146  polylineVec.getVector()->size());
147  endResetModel();
148  parent->vtkSource()->Modified();
149  return;
150  }
151  }
152  }
153  }
154  OGSError::box("Error adding polyline to geometry.");
155 }
static void box(const QString &e)
Definition: OGSError.cpp:23

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

Referenced by GEOModels::appendPolylineVec().

◆ appendSurfaces()

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

Appends surfaces to the "Surface"-subtree.

Definition at line 240 of file GeoTreeModel.cpp.

242 {
243  for (auto& list : _lists)
244  {
245  if (name == list->data(0).toString().toStdString())
246  {
247  int nChildren = list->childCount();
248  for (int j = 0; j < nChildren; j++)
249  {
250  auto* parent = static_cast<GeoObjectListItem*>(list->child(j));
251  if (GeoLib::GEOTYPE::SURFACE == parent->getType())
252  {
253  beginResetModel();
254  this->addChildren(parent, surfaceVec, parent->childCount(),
255  surfaceVec.getVector()->size());
256  parent->vtkSource()->Modified();
257  endResetModel();
258  return;
259  }
260  }
261  }
262  }
263  OGSError::box("Error adding surface to geometry.");
264 }

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

Referenced by GEOModels::appendSurfaceVec().

◆ getLists()

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

Returns a list of all existing geometries.

Definition at line 63 of file GeoTreeModel.h.

63 { 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 348 of file GeoTreeModel.cpp.

349 {
350  for (std::size_t i = 0; i < _lists.size(); i++)
351  {
352  if (name == _lists[i]->data(0).toString().toStdString())
353  {
354  for (int j = 0; j < _lists[i]->childCount(); j++)
355  {
356  if (type == static_cast<GeoObjectListItem*>(_lists[i]->child(j))
357  ->getType())
358  {
359  QModelIndex index = createIndex(j, 0, _lists[i]->child(j));
360  removeRows(0, _lists[i]->child(j)->childCount(), index);
361  removeRows(j, 1, parent(index));
362  break;
363  }
364  }
365  if (_lists[i]->childCount() == 0)
366  {
367  _lists.erase(_lists.begin() + i);
368  removeRows(i, 1, QModelIndex());
369  }
370  }
371  }
372 }
bool removeRows(int position, int count, const QModelIndex &parent) override
Definition: TreeModel.cpp:215
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: TreeModel.cpp:50
QVariant data(const QModelIndex &index, int role) const override
Definition: TreeModel.cpp:142
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)
Converts MGIS kinematic to a string representation.
Definition: MFront.cpp:103

References _lists, TreeModel::data(), TreeModel::index(), MaterialPropertyLib::name, TreeModel::parent(), TreeModel::removeRows(), and MaterialLib::Solids::MFront::toString().

Referenced by GEOModels::removePointVec(), GEOModels::removePolylineVec(), GEOModels::removeSurfaceVec(), and GEOModels::updateGeometry().

◆ renameGeometry()

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

Definition at line 324 of file GeoTreeModel.cpp.

326 {
327  for (auto tree_item_entry : _lists)
328  {
329  if (old_name == tree_item_entry->data(0).toString().toStdString())
330  {
331  QVariant new_entry(QString::fromStdString(new_name));
332  tree_item_entry->setData(0, new_entry);
333  break;
334  }
335  }
336  for (auto tree_item_entry : _lists)
337  {
338  if (new_name == tree_item_entry->data(0).toString().toStdString())
339  {
340  INFO("Found tree_item_entry with name '{:s}'.", new_name);
341  }
342  }
343 }

References _lists, and INFO().

Referenced by GEOModels::renameGeometry().

◆ setNameForItem()

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

Definition at line 396 of file GeoTreeModel.cpp.

400 {
401  std::string geo_type_str;
402  int col_idx(1);
403 
404  switch (type)
405  {
407  geo_type_str = "Points";
408  col_idx = 4; // for points the name is at a different position
409  break;
411  geo_type_str = "Polylines";
412  break;
414  geo_type_str = "Surfaces";
415  break;
416  default:
417  geo_type_str = "";
418  }
419 
420  auto it =
421  find_if(_lists.begin(), _lists.end(),
422  [&name](GeoTreeItem* geo)
423  { return (name == geo->data(0).toString().toStdString()); });
424 
425  for (int i = 0; i < (*it)->childCount(); i++)
426  {
427  if (geo_type_str == (*it)->child(i)->data(0).toString().toStdString())
428  {
429  TreeItem* item = (*it)->child(i)->child(id);
430  item->setData(col_idx, QString::fromStdString(item_name));
431  break;
432  }
433  }
434 }

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

◆ 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 374 of file GeoTreeModel.cpp.

376 {
377  std::size_t nLists = _lists.size();
378  for (std::size_t i = 0; i < nLists; i++)
379  {
380  if (name == _lists[i]->data(0).toString().toStdString())
381  {
382  for (int j = 0; j < _lists[i]->childCount(); j++)
383  {
384  auto* item =
385  dynamic_cast<GeoObjectListItem*>(_lists[i]->child(j));
386  if (item->getType() == type)
387  {
388  return item->vtkSource();
389  }
390  }
391  }
392  }
393  return nullptr;
394 }
vtkPolyDataAlgorithm * vtkSource() const
Returns the Vtk polydata source object.

References _lists, TreeModel::data(), MaterialPropertyLib::name, MaterialLib::Solids::MFront::toString(), and GeoObjectListItem::vtkSource().

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: