OGS
MeshModel Class Reference

Detailed Description

The MeshModel is a Qt model which represents Mesh objects.

Definition at line 37 of file MeshModel.h.

#include <MeshModel.h>

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

Public Slots

void addMesh (MeshLib::Mesh *mesh)
 Adds a new mesh (using no unique_ptr as this interferes with Qt's signal/slot policy)
 
const MeshLib::MeshgetMesh (const QModelIndex &idx) const
 Returns the mesh with the given index.
 
const MeshLib::MeshgetMesh (const std::string &name) const
 Returns the mesh with the given name.
 
bool removeMesh (const QModelIndex &idx)
 Removes the mesh with the given index.
 
bool removeMesh (const std::string &name)
 Removes the mesh with the given name.
 
void updateMesh (MeshLib::Mesh *)
 Updates the model/view for a mesh.
 
void updateModel ()
 Updates the model based on the ProjectData-object.
 
vtkUnstructuredGridAlgorithm * vtkSource (const QModelIndex &idx) const
 Returns the VTK source item for the mesh with the given index.
 
vtkUnstructuredGridAlgorithm * vtkSource (const std::string &name) const
 Returns the VTK source item for the mesh with the given name.
 
- Public Slots inherited from TreeModel
void updateData ()
 

Signals

void meshAdded (MeshModel *, const QModelIndex &)
 
void meshRemoved (MeshModel *, const QModelIndex &)
 

Public Member Functions

 MeshModel (DataHolderLib::Project &project, QObject *parent=nullptr)
 
void addMesh (std::unique_ptr< MeshLib::Mesh > mesh)
 Adds a new mesh.
 
int columnCount (const QModelIndex &parent=QModelIndex()) const override
 Returns the number of columns used for the data list.
 
- 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 addMeshObject (const MeshLib::Mesh *mesh)
 Adds the mesh to the GUI-Mesh-Model und -View.
 

Static Private Member Functions

static std::map< MeshLib::MeshElemType, QVariant > createMeshElemTypeMap ()
 Creates a static map of all element type name-strings in QVariant format.
 

Private Attributes

DataHolderLib::Project_project
 Checks if the name of the mesh is already exists, if so it generates a unique name.
 

Static Private Attributes

static const std::map< MeshLib::MeshElemType, QVariant > elem_type_map
 
static const QVariant element_str = "Element"
 

Additional Inherited Members

- Protected Attributes inherited from TreeModel
TreeItem_rootItem
 

Constructor & Destructor Documentation

◆ MeshModel()

MeshModel::MeshModel ( DataHolderLib::Project & project,
QObject * parent = nullptr )
explicit

Definition at line 34 of file MeshModel.cpp.

35 : TreeModel(parent), _project(project)
36{
37 delete _rootItem;
38 QList<QVariant> rootData;
39 rootData << "Mesh Name"
40 << "#"
41 << "Type";
42 _rootItem = new TreeItem(rootData, nullptr);
43}
DataHolderLib::Project & _project
Checks if the name of the mesh is already exists, if so it generates a unique name.
Definition MeshModel.h:77
Objects nodes for the TreeModel.
Definition TreeItem.h:28
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.

Member Function Documentation

◆ addMesh [1/2]

void MeshModel::addMesh ( MeshLib::Mesh * mesh)
slot

Adds a new mesh (using no unique_ptr as this interferes with Qt's signal/slot policy)

Definition at line 59 of file MeshModel.cpp.

60{
61 _project.addMesh(std::unique_ptr<MeshLib::Mesh>(mesh));
62 auto const& meshes(_project.getMeshObjects());
63 this->addMeshObject(meshes.back().get());
64}
const std::vector< std::unique_ptr< MeshLib::Mesh > > & getMeshObjects() const
Returns all the meshes with their respective names.
Definition Project.h:57
void addMesh(std::unique_ptr< MeshLib::Mesh > mesh)
Definition Project.cpp:21
void addMeshObject(const MeshLib::Mesh *mesh)
Adds the mesh to the GUI-Mesh-Model und -View.
Definition MeshModel.cpp:66

References _project, DataHolderLib::Project::addMesh(), addMeshObject(), and DataHolderLib::Project::getMeshObjects().

◆ addMesh() [2/2]

void MeshModel::addMesh ( std::unique_ptr< MeshLib::Mesh > mesh)

Adds a new mesh.

Definition at line 52 of file MeshModel.cpp.

53{
54 _project.addMesh(std::move(mesh));
55 auto const& meshes(_project.getMeshObjects());
56 this->addMeshObject(meshes.back().get());
57}

References _project, DataHolderLib::Project::addMesh(), addMeshObject(), and DataHolderLib::Project::getMeshObjects().

Referenced by AddFaultsToVoxelGridDialog::accept(), Layers2GridDialog::accept(), and Vtu2GridDialog::accept().

◆ addMeshObject()

void MeshModel::addMeshObject ( const MeshLib::Mesh * mesh)
private

Adds the mesh to the GUI-Mesh-Model und -View.

Definition at line 66 of file MeshModel.cpp.

67{
68 beginResetModel();
69
70 INFO("name: {:s}", mesh->getName());
71 QVariant const display_name(QString::fromStdString(mesh->getName()));
72 QList<QVariant> meshData;
73 meshData << display_name << ""
74 << "";
75 auto* const newMesh = new MeshItem(meshData, _rootItem, mesh);
76 _rootItem->appendChild(newMesh);
77
78 // display elements
79 std::vector<MeshLib::Element*> const& elems = mesh->getElements();
80 auto const nElems(static_cast<int>(elems.size()));
81
82 for (int i = 0; i < nElems; i++)
83 {
84 QList<QVariant> elemData;
85 elemData.reserve(3);
86 elemData << element_str << i
87 << elem_type_map.at(elems[i]->getGeomType());
88 newMesh->appendChild(new TreeItem(elemData, newMesh));
89 }
90
91 endResetModel();
92 emit meshAdded(this,
93 this->index(_rootItem->childCount() - 1, 0, QModelIndex()));
94}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
A TreeItem containing a mesh and the associated vtk object used in the Mesh Model.
Definition MeshItem.h:30
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
void meshAdded(MeshModel *, const QModelIndex &)
static const std::map< MeshLib::MeshElemType, QVariant > elem_type_map
Definition MeshModel.h:82
static const QVariant element_str
Definition MeshModel.h:83
virtual int childCount() const
Definition TreeItem.cpp:65
void appendChild(TreeItem *item)
Definition TreeItem.cpp:42
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition TreeModel.cpp:50

References TreeModel::_rootItem, TreeItem::appendChild(), TreeItem::childCount(), elem_type_map, element_str, MeshLib::Mesh::getElements(), MeshLib::Mesh::getName(), TreeModel::index(), INFO(), and meshAdded().

Referenced by addMesh(), addMesh(), updateMesh(), and updateModel().

◆ columnCount()

int MeshModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
override

Returns the number of columns used for the data list.

Definition at line 45 of file MeshModel.cpp.

46{
47 Q_UNUSED(parent)
48
49 return 3;
50}

References TreeModel::parent().

◆ createMeshElemTypeMap()

std::map< MeshLib::MeshElemType, QVariant > MeshModel::createMeshElemTypeMap ( )
staticprivate

Creates a static map of all element type name-strings in QVariant format.

Definition at line 186 of file MeshModel.cpp.

187{
188 std::vector<MeshLib::MeshElemType> const& elem_types(
190 std::map<MeshLib::MeshElemType, QVariant> elem_map;
191
192 for (MeshLib::MeshElemType t : elem_types)
193 {
194 elem_map[t] =
195 QVariant(QString::fromStdString(MeshLib::MeshElemType2String(t)));
196 }
197
198 return elem_map;
199}
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:21
std::vector< MeshElemType > getMeshElemTypes()
Returns a vector of all mesh element types.
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27

References MeshLib::getMeshElemTypes(), and MeshLib::MeshElemType2String().

◆ getMesh [1/2]

const MeshLib::Mesh * MeshModel::getMesh ( const QModelIndex & idx) const
slot

Returns the mesh with the given index.

Definition at line 96 of file MeshModel.cpp.

97{
98 if (idx.isValid())
99 {
100 auto* item = dynamic_cast<MeshItem*>(this->getItem(idx));
101 if (item)
102 {
103 return item->getMesh();
104 }
105
106 return nullptr;
107 }
108 WARN("MeshModel::getMesh(): Specified index does not exist.");
109 return nullptr;
110}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
MeshLib::Mesh const * getMesh() const
Returns the mesh.
Definition MeshItem.h:42
TreeItem * getItem(const QModelIndex &index) const

References TreeModel::getItem(), MeshItem::getMesh(), and WARN().

Referenced by AddFaultsToVoxelGridDialog::AddFaultsToVoxelGridDialog(), Layers2GridDialog::Layers2GridDialog(), TranslateDataDialog::TranslateDataDialog(), Vtu2GridDialog::Vtu2GridDialog(), AddFaultsToVoxelGridDialog::accept(), Layers2GridDialog::accept(), Vtu2GridDialog::accept(), TranslateDataDialog::moveMesh(), MeshView::openMap2dMeshDialog(), MeshView::openMeshEditDialog(), MeshView::openRasterDataToMeshDialog(), MeshView::openValuesEditDialog(), Layers2GridDialog::updateExpectedVoxel(), Vtu2GridDialog::updateExpectedVoxel(), and updateModel().

◆ getMesh [2/2]

const MeshLib::Mesh * MeshModel::getMesh ( const std::string & name) const
slot

Returns the mesh with the given name.

Definition at line 112 of file MeshModel.cpp.

113{
114 for (int i = 0; i < _rootItem->childCount(); i++)
115 {
116 auto* item = static_cast<MeshItem*>(_rootItem->child(i));
117 if (item->data(0).toString().toStdString() == name)
118 {
119 return item->getMesh();
120 }
121 }
122
123 INFO("MeshModel::getMesh(): No entry found with name \"{:s}\".", name);
124 return nullptr;
125}
TreeItem * child(int row) const
Definition TreeItem.cpp:52

References TreeModel::_rootItem, TreeItem::child(), TreeItem::childCount(), MeshItem::getMesh(), and INFO().

◆ meshAdded

void MeshModel::meshAdded ( MeshModel * ,
const QModelIndex &  )
signal

Referenced by addMeshObject().

◆ meshRemoved

void MeshModel::meshRemoved ( MeshModel * ,
const QModelIndex &  )
signal

Referenced by removeMesh(), and updateMesh().

◆ removeMesh [1/2]

bool MeshModel::removeMesh ( const QModelIndex & idx)
slot

Removes the mesh with the given index.

Definition at line 127 of file MeshModel.cpp.

128{
129 if (idx.isValid())
130 {
131 auto* item = dynamic_cast<MeshItem*>(this->getItem(idx));
132 if (item)
133 {
134 return this->removeMesh(item->getMesh()->getName());
135 }
136 return false;
137 }
138 return false;
139}
bool removeMesh(const QModelIndex &idx)
Removes the mesh with the given index.

References TreeModel::getItem(), and removeMesh().

Referenced by removeMesh().

◆ removeMesh [2/2]

bool MeshModel::removeMesh ( const std::string & name)
slot

Removes the mesh with the given name.

Definition at line 141 of file MeshModel.cpp.

142{
143 for (int i = 0; i < _rootItem->childCount(); i++)
144 {
145 TreeItem* item = _rootItem->child(i);
146 if (item->data(0).toString().toStdString() == name)
147 {
148 beginResetModel();
149 emit meshRemoved(this, this->index(i, 0, QModelIndex()));
151 endResetModel();
152 return _project.removeMesh(name);
153 }
154 }
155
156 INFO("MeshModel::removeMesh(): No entry found with name \"{:s}\".", name);
157 return false;
158}
bool removeMesh(const std::string &name)
Definition Project.cpp:49
void meshRemoved(MeshModel *, const QModelIndex &)
bool removeChildren(int position, int count)
Definition TreeItem.cpp:124
virtual QVariant data(int column) const
Definition TreeItem.cpp:94

References _project, TreeModel::_rootItem, TreeItem::child(), TreeItem::childCount(), TreeItem::data(), TreeModel::index(), INFO(), meshRemoved(), TreeItem::removeChildren(), and DataHolderLib::Project::removeMesh().

◆ updateMesh

void MeshModel::updateMesh ( MeshLib::Mesh * mesh)
slot

Updates the model/view for a mesh.

Definition at line 160 of file MeshModel.cpp.

161{
162 for (int i = 0; i < _rootItem->childCount(); i++)
163 {
164 if (dynamic_cast<MeshItem*>(this->_rootItem->child(i))->getMesh() ==
165 mesh)
166 {
167 emit meshRemoved(this, this->index(i, 0, QModelIndex()));
169 }
170 }
171 this->addMeshObject(mesh);
172}

References TreeModel::_rootItem, addMeshObject(), TreeItem::child(), TreeItem::childCount(), MeshItem::getMesh(), TreeModel::index(), meshRemoved(), and TreeItem::removeChildren().

Referenced by TranslateDataDialog::moveMesh().

◆ updateModel

void MeshModel::updateModel ( )
slot

Updates the model based on the ProjectData-object.

Definition at line 174 of file MeshModel.cpp.

175{
176 auto const& mesh_vec = _project.getMeshObjects();
177 for (auto const& mesh : mesh_vec)
178 {
179 if (!getMesh(mesh->getName()))
180 { // if Mesh is not yet added to GUI, do it now
181 addMeshObject(mesh.get());
182 }
183 }
184}
const MeshLib::Mesh * getMesh(const QModelIndex &idx) const
Returns the mesh with the given index.
Definition MeshModel.cpp:96

References _project, addMeshObject(), getMesh(), and DataHolderLib::Project::getMeshObjects().

◆ vtkSource [1/2]

vtkUnstructuredGridAlgorithm * MeshModel::vtkSource ( const QModelIndex & idx) const
slot

Returns the VTK source item for the mesh with the given index.

Definition at line 201 of file MeshModel.cpp.

202{
203 if (idx.isValid())
204 {
205 auto* item = static_cast<MeshItem*>(this->getItem(idx));
206 return item->vtkSource();
207 }
208
209 INFO("MeshModel::vtkSource(): Specified index does not exist.");
210 return nullptr;
211}
MeshLib::VtkMappedMeshSource * vtkSource() const
Returns the VTK object.
Definition MeshItem.h:44

References TreeModel::getItem(), INFO(), and MeshItem::vtkSource().

◆ vtkSource [2/2]

vtkUnstructuredGridAlgorithm * MeshModel::vtkSource ( const std::string & name) const
slot

Returns the VTK source item for the mesh with the given name.

Definition at line 213 of file MeshModel.cpp.

215{
216 for (int i = 0; i < _rootItem->childCount(); i++)
217 {
218 auto* item = static_cast<MeshItem*>(_rootItem->child(i));
219 if (item->data(0).toString().toStdString() == name)
220 {
221 return item->vtkSource();
222 }
223 }
224
225 INFO("MeshModel::vtkSource(): No entry found with name \"{:s}\".", name);
226 return nullptr;
227}

References TreeModel::_rootItem, TreeItem::child(), TreeItem::childCount(), INFO(), and MeshItem::vtkSource().

Member Data Documentation

◆ _project

DataHolderLib::Project& MeshModel::_project
private

Checks if the name of the mesh is already exists, if so it generates a unique name.

Definition at line 77 of file MeshModel.h.

Referenced by addMesh(), addMesh(), removeMesh(), and updateModel().

◆ elem_type_map

const std::map< MeshLib::MeshElemType, QVariant > MeshModel::elem_type_map
staticprivate
Initial value:
=
static std::map< MeshLib::MeshElemType, QVariant > createMeshElemTypeMap()
Creates a static map of all element type name-strings in QVariant format.

Definition at line 82 of file MeshModel.h.

Referenced by addMeshObject().

◆ element_str

const QVariant MeshModel::element_str = "Element"
staticprivate

Definition at line 83 of file MeshModel.h.

Referenced by addMeshObject().


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